coretypes.h: Include input.h and as-a.h.
[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 "alias.h"
26 #include "symtab.h"
27 #include "tree.h"
28 #include "fold-const.h"
29 #include "stringpool.h"
30 #include "attribs.h"
31 #include "calls.h"
32 #include "stor-layout.h"
33 #include "varasm.h"
34 #include "tm_p.h"
35 #include "regs.h"
36 #include "hard-reg-set.h"
37 #include "insn-config.h"
38 #include "conditions.h"
39 #include "output.h"
40 #include "insn-codes.h"
41 #include "insn-attr.h"
42 #include "flags.h"
43 #include "except.h"
44 #include "function.h"
45 #include "recog.h"
46 #include "expmed.h"
47 #include "dojump.h"
48 #include "explow.h"
49 #include "emit-rtl.h"
50 #include "stmt.h"
51 #include "expr.h"
52 #include "optabs.h"
53 #include "diagnostic-core.h"
54 #include "toplev.h"
55 #include "predict.h"
56 #include "dominance.h"
57 #include "cfg.h"
58 #include "cfgrtl.h"
59 #include "cfganal.h"
60 #include "lcm.h"
61 #include "cfgbuild.h"
62 #include "cfgcleanup.h"
63 #include "basic-block.h"
64 #include "target.h"
65 #include "target-def.h"
66 #include "common/common-target.h"
67 #include "langhooks.h"
68 #include "reload.h"
69 #include "plugin-api.h"
70 #include "ipa-ref.h"
71 #include "cgraph.h"
72 #include "tree-ssa-alias.h"
73 #include "internal-fn.h"
74 #include "gimple-fold.h"
75 #include "tree-eh.h"
76 #include "gimple-expr.h"
77 #include "gimple.h"
78 #include "gimplify.h"
79 #include "cfgloop.h"
80 #include "dwarf2.h"
81 #include "df.h"
82 #include "tm-constrs.h"
83 #include "params.h"
84 #include "cselib.h"
85 #include "debug.h"
86 #include "sched-int.h"
87 #include "sbitmap.h"
88 #include "fibheap.h"
89 #include "opts.h"
90 #include "diagnostic.h"
91 #include "dumpfile.h"
92 #include "tree-pass.h"
93 #include "context.h"
94 #include "pass_manager.h"
95 #include "target-globals.h"
96 #include "tree-vectorizer.h"
97 #include "shrink-wrap.h"
98 #include "builtins.h"
99 #include "rtl-iter.h"
100 #include "tree-iterator.h"
101 #include "tree-chkp.h"
102 #include "rtl-chkp.h"
103
104 static rtx legitimize_dllimport_symbol (rtx, bool);
105 static rtx legitimize_pe_coff_extern_decl (rtx, bool);
106 static rtx legitimize_pe_coff_symbol (rtx, bool);
107
108 #ifndef CHECK_STACK_LIMIT
109 #define CHECK_STACK_LIMIT (-1)
110 #endif
111
112 /* Return index of given mode in mult and division cost tables.  */
113 #define MODE_INDEX(mode)                                        \
114   ((mode) == QImode ? 0                                         \
115    : (mode) == HImode ? 1                                       \
116    : (mode) == SImode ? 2                                       \
117    : (mode) == DImode ? 3                                       \
118    : 4)
119
120 /* Processor costs (relative to an add) */
121 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
122 #define COSTS_N_BYTES(N) ((N) * 2)
123
124 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall, false}}}
125
126 static stringop_algs ix86_size_memcpy[2] = {
127   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
128   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}}};
129 static stringop_algs ix86_size_memset[2] = {
130   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
131   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}}};
132
133 const
134 struct processor_costs ix86_size_cost = {/* costs for tuning for size */
135   COSTS_N_BYTES (2),                    /* cost of an add instruction */
136   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
137   COSTS_N_BYTES (2),                    /* variable shift costs */
138   COSTS_N_BYTES (3),                    /* constant shift costs */
139   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
140    COSTS_N_BYTES (3),                   /*                               HI */
141    COSTS_N_BYTES (3),                   /*                               SI */
142    COSTS_N_BYTES (3),                   /*                               DI */
143    COSTS_N_BYTES (5)},                  /*                            other */
144   0,                                    /* cost of multiply per each bit set */
145   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
146    COSTS_N_BYTES (3),                   /*                          HI */
147    COSTS_N_BYTES (3),                   /*                          SI */
148    COSTS_N_BYTES (3),                   /*                          DI */
149    COSTS_N_BYTES (5)},                  /*                          other */
150   COSTS_N_BYTES (3),                    /* cost of movsx */
151   COSTS_N_BYTES (3),                    /* cost of movzx */
152   0,                                    /* "large" insn */
153   2,                                    /* MOVE_RATIO */
154   2,                                 /* cost for loading QImode using movzbl */
155   {2, 2, 2},                            /* cost of loading integer registers
156                                            in QImode, HImode and SImode.
157                                            Relative to reg-reg move (2).  */
158   {2, 2, 2},                            /* cost of storing integer registers */
159   2,                                    /* cost of reg,reg fld/fst */
160   {2, 2, 2},                            /* cost of loading fp registers
161                                            in SFmode, DFmode and XFmode */
162   {2, 2, 2},                            /* cost of storing fp registers
163                                            in SFmode, DFmode and XFmode */
164   3,                                    /* cost of moving MMX register */
165   {3, 3},                               /* cost of loading MMX registers
166                                            in SImode and DImode */
167   {3, 3},                               /* cost of storing MMX registers
168                                            in SImode and DImode */
169   3,                                    /* cost of moving SSE register */
170   {3, 3, 3},                            /* cost of loading SSE registers
171                                            in SImode, DImode and TImode */
172   {3, 3, 3},                            /* cost of storing SSE registers
173                                            in SImode, DImode and TImode */
174   3,                                    /* MMX or SSE register to integer */
175   0,                                    /* size of l1 cache  */
176   0,                                    /* size of l2 cache  */
177   0,                                    /* size of prefetch block */
178   0,                                    /* number of parallel prefetches */
179   2,                                    /* Branch cost */
180   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
181   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
182   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
183   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
184   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
185   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
186   ix86_size_memcpy,
187   ix86_size_memset,
188   1,                                    /* scalar_stmt_cost.  */
189   1,                                    /* scalar load_cost.  */
190   1,                                    /* scalar_store_cost.  */
191   1,                                    /* vec_stmt_cost.  */
192   1,                                    /* vec_to_scalar_cost.  */
193   1,                                    /* scalar_to_vec_cost.  */
194   1,                                    /* vec_align_load_cost.  */
195   1,                                    /* vec_unalign_load_cost.  */
196   1,                                    /* vec_store_cost.  */
197   1,                                    /* cond_taken_branch_cost.  */
198   1,                                    /* cond_not_taken_branch_cost.  */
199 };
200
201 /* Processor costs (relative to an add) */
202 static stringop_algs i386_memcpy[2] = {
203   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
204   DUMMY_STRINGOP_ALGS};
205 static stringop_algs i386_memset[2] = {
206   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
207   DUMMY_STRINGOP_ALGS};
208
209 static const
210 struct processor_costs i386_cost = {    /* 386 specific costs */
211   COSTS_N_INSNS (1),                    /* cost of an add instruction */
212   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
213   COSTS_N_INSNS (3),                    /* variable shift costs */
214   COSTS_N_INSNS (2),                    /* constant shift costs */
215   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
216    COSTS_N_INSNS (6),                   /*                               HI */
217    COSTS_N_INSNS (6),                   /*                               SI */
218    COSTS_N_INSNS (6),                   /*                               DI */
219    COSTS_N_INSNS (6)},                  /*                            other */
220   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
221   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
222    COSTS_N_INSNS (23),                  /*                          HI */
223    COSTS_N_INSNS (23),                  /*                          SI */
224    COSTS_N_INSNS (23),                  /*                          DI */
225    COSTS_N_INSNS (23)},                 /*                          other */
226   COSTS_N_INSNS (3),                    /* cost of movsx */
227   COSTS_N_INSNS (2),                    /* cost of movzx */
228   15,                                   /* "large" insn */
229   3,                                    /* MOVE_RATIO */
230   4,                                 /* cost for loading QImode using movzbl */
231   {2, 4, 2},                            /* cost of loading integer registers
232                                            in QImode, HImode and SImode.
233                                            Relative to reg-reg move (2).  */
234   {2, 4, 2},                            /* cost of storing integer registers */
235   2,                                    /* cost of reg,reg fld/fst */
236   {8, 8, 8},                            /* cost of loading fp registers
237                                            in SFmode, DFmode and XFmode */
238   {8, 8, 8},                            /* cost of storing fp registers
239                                            in SFmode, DFmode and XFmode */
240   2,                                    /* cost of moving MMX register */
241   {4, 8},                               /* cost of loading MMX registers
242                                            in SImode and DImode */
243   {4, 8},                               /* cost of storing MMX registers
244                                            in SImode and DImode */
245   2,                                    /* cost of moving SSE register */
246   {4, 8, 16},                           /* cost of loading SSE registers
247                                            in SImode, DImode and TImode */
248   {4, 8, 16},                           /* cost of storing SSE registers
249                                            in SImode, DImode and TImode */
250   3,                                    /* MMX or SSE register to integer */
251   0,                                    /* size of l1 cache  */
252   0,                                    /* size of l2 cache  */
253   0,                                    /* size of prefetch block */
254   0,                                    /* number of parallel prefetches */
255   1,                                    /* Branch cost */
256   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
257   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
258   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
259   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
260   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
261   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
262   i386_memcpy,
263   i386_memset,
264   1,                                    /* scalar_stmt_cost.  */
265   1,                                    /* scalar load_cost.  */
266   1,                                    /* scalar_store_cost.  */
267   1,                                    /* vec_stmt_cost.  */
268   1,                                    /* vec_to_scalar_cost.  */
269   1,                                    /* scalar_to_vec_cost.  */
270   1,                                    /* vec_align_load_cost.  */
271   2,                                    /* vec_unalign_load_cost.  */
272   1,                                    /* vec_store_cost.  */
273   3,                                    /* cond_taken_branch_cost.  */
274   1,                                    /* cond_not_taken_branch_cost.  */
275 };
276
277 static stringop_algs i486_memcpy[2] = {
278   {rep_prefix_4_byte, {{-1, rep_prefix_4_byte, false}}},
279   DUMMY_STRINGOP_ALGS};
280 static stringop_algs i486_memset[2] = {
281   {rep_prefix_4_byte, {{-1, rep_prefix_4_byte, false}}},
282   DUMMY_STRINGOP_ALGS};
283
284 static const
285 struct processor_costs i486_cost = {    /* 486 specific costs */
286   COSTS_N_INSNS (1),                    /* cost of an add instruction */
287   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
288   COSTS_N_INSNS (3),                    /* variable shift costs */
289   COSTS_N_INSNS (2),                    /* constant shift costs */
290   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
291    COSTS_N_INSNS (12),                  /*                               HI */
292    COSTS_N_INSNS (12),                  /*                               SI */
293    COSTS_N_INSNS (12),                  /*                               DI */
294    COSTS_N_INSNS (12)},                 /*                            other */
295   1,                                    /* cost of multiply per each bit set */
296   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
297    COSTS_N_INSNS (40),                  /*                          HI */
298    COSTS_N_INSNS (40),                  /*                          SI */
299    COSTS_N_INSNS (40),                  /*                          DI */
300    COSTS_N_INSNS (40)},                 /*                          other */
301   COSTS_N_INSNS (3),                    /* cost of movsx */
302   COSTS_N_INSNS (2),                    /* cost of movzx */
303   15,                                   /* "large" insn */
304   3,                                    /* MOVE_RATIO */
305   4,                                 /* cost for loading QImode using movzbl */
306   {2, 4, 2},                            /* cost of loading integer registers
307                                            in QImode, HImode and SImode.
308                                            Relative to reg-reg move (2).  */
309   {2, 4, 2},                            /* cost of storing integer registers */
310   2,                                    /* cost of reg,reg fld/fst */
311   {8, 8, 8},                            /* cost of loading fp registers
312                                            in SFmode, DFmode and XFmode */
313   {8, 8, 8},                            /* cost of storing fp registers
314                                            in SFmode, DFmode and XFmode */
315   2,                                    /* cost of moving MMX register */
316   {4, 8},                               /* cost of loading MMX registers
317                                            in SImode and DImode */
318   {4, 8},                               /* cost of storing MMX registers
319                                            in SImode and DImode */
320   2,                                    /* cost of moving SSE register */
321   {4, 8, 16},                           /* cost of loading SSE registers
322                                            in SImode, DImode and TImode */
323   {4, 8, 16},                           /* cost of storing SSE registers
324                                            in SImode, DImode and TImode */
325   3,                                    /* MMX or SSE register to integer */
326   4,                                    /* size of l1 cache.  486 has 8kB cache
327                                            shared for code and data, so 4kB is
328                                            not really precise.  */
329   4,                                    /* size of l2 cache  */
330   0,                                    /* size of prefetch block */
331   0,                                    /* number of parallel prefetches */
332   1,                                    /* Branch cost */
333   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
334   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
335   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
336   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
337   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
338   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
339   i486_memcpy,
340   i486_memset,
341   1,                                    /* scalar_stmt_cost.  */
342   1,                                    /* scalar load_cost.  */
343   1,                                    /* scalar_store_cost.  */
344   1,                                    /* vec_stmt_cost.  */
345   1,                                    /* vec_to_scalar_cost.  */
346   1,                                    /* scalar_to_vec_cost.  */
347   1,                                    /* vec_align_load_cost.  */
348   2,                                    /* vec_unalign_load_cost.  */
349   1,                                    /* vec_store_cost.  */
350   3,                                    /* cond_taken_branch_cost.  */
351   1,                                    /* cond_not_taken_branch_cost.  */
352 };
353
354 static stringop_algs pentium_memcpy[2] = {
355   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
356   DUMMY_STRINGOP_ALGS};
357 static stringop_algs pentium_memset[2] = {
358   {libcall, {{-1, rep_prefix_4_byte, false}}},
359   DUMMY_STRINGOP_ALGS};
360
361 static const
362 struct processor_costs pentium_cost = {
363   COSTS_N_INSNS (1),                    /* cost of an add instruction */
364   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
365   COSTS_N_INSNS (4),                    /* variable shift costs */
366   COSTS_N_INSNS (1),                    /* constant shift costs */
367   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
368    COSTS_N_INSNS (11),                  /*                               HI */
369    COSTS_N_INSNS (11),                  /*                               SI */
370    COSTS_N_INSNS (11),                  /*                               DI */
371    COSTS_N_INSNS (11)},                 /*                            other */
372   0,                                    /* cost of multiply per each bit set */
373   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
374    COSTS_N_INSNS (25),                  /*                          HI */
375    COSTS_N_INSNS (25),                  /*                          SI */
376    COSTS_N_INSNS (25),                  /*                          DI */
377    COSTS_N_INSNS (25)},                 /*                          other */
378   COSTS_N_INSNS (3),                    /* cost of movsx */
379   COSTS_N_INSNS (2),                    /* cost of movzx */
380   8,                                    /* "large" insn */
381   6,                                    /* MOVE_RATIO */
382   6,                                 /* cost for loading QImode using movzbl */
383   {2, 4, 2},                            /* cost of loading integer registers
384                                            in QImode, HImode and SImode.
385                                            Relative to reg-reg move (2).  */
386   {2, 4, 2},                            /* cost of storing integer registers */
387   2,                                    /* cost of reg,reg fld/fst */
388   {2, 2, 6},                            /* cost of loading fp registers
389                                            in SFmode, DFmode and XFmode */
390   {4, 4, 6},                            /* cost of storing fp registers
391                                            in SFmode, DFmode and XFmode */
392   8,                                    /* cost of moving MMX register */
393   {8, 8},                               /* cost of loading MMX registers
394                                            in SImode and DImode */
395   {8, 8},                               /* cost of storing MMX registers
396                                            in SImode and DImode */
397   2,                                    /* cost of moving SSE register */
398   {4, 8, 16},                           /* cost of loading SSE registers
399                                            in SImode, DImode and TImode */
400   {4, 8, 16},                           /* cost of storing SSE registers
401                                            in SImode, DImode and TImode */
402   3,                                    /* MMX or SSE register to integer */
403   8,                                    /* size of l1 cache.  */
404   8,                                    /* size of l2 cache  */
405   0,                                    /* size of prefetch block */
406   0,                                    /* number of parallel prefetches */
407   2,                                    /* Branch cost */
408   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
409   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
410   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
411   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
412   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
413   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
414   pentium_memcpy,
415   pentium_memset,
416   1,                                    /* scalar_stmt_cost.  */
417   1,                                    /* scalar load_cost.  */
418   1,                                    /* scalar_store_cost.  */
419   1,                                    /* vec_stmt_cost.  */
420   1,                                    /* vec_to_scalar_cost.  */
421   1,                                    /* scalar_to_vec_cost.  */
422   1,                                    /* vec_align_load_cost.  */
423   2,                                    /* vec_unalign_load_cost.  */
424   1,                                    /* vec_store_cost.  */
425   3,                                    /* cond_taken_branch_cost.  */
426   1,                                    /* cond_not_taken_branch_cost.  */
427 };
428
429 /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes
430    (we ensure the alignment).  For small blocks inline loop is still a
431    noticeable win, for bigger blocks either rep movsl or rep movsb is
432    way to go.  Rep movsb has apparently more expensive startup time in CPU,
433    but after 4K the difference is down in the noise.  */
434 static stringop_algs pentiumpro_memcpy[2] = {
435   {rep_prefix_4_byte, {{128, loop, false}, {1024, unrolled_loop, false},
436                        {8192, rep_prefix_4_byte, false},
437                        {-1, rep_prefix_1_byte, false}}},
438   DUMMY_STRINGOP_ALGS};
439 static stringop_algs pentiumpro_memset[2] = {
440   {rep_prefix_4_byte, {{1024, unrolled_loop, false},
441                        {8192, rep_prefix_4_byte, false},
442                        {-1, libcall, false}}},
443   DUMMY_STRINGOP_ALGS};
444 static const
445 struct processor_costs pentiumpro_cost = {
446   COSTS_N_INSNS (1),                    /* cost of an add instruction */
447   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
448   COSTS_N_INSNS (1),                    /* variable shift costs */
449   COSTS_N_INSNS (1),                    /* constant shift costs */
450   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
451    COSTS_N_INSNS (4),                   /*                               HI */
452    COSTS_N_INSNS (4),                   /*                               SI */
453    COSTS_N_INSNS (4),                   /*                               DI */
454    COSTS_N_INSNS (4)},                  /*                            other */
455   0,                                    /* cost of multiply per each bit set */
456   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
457    COSTS_N_INSNS (17),                  /*                          HI */
458    COSTS_N_INSNS (17),                  /*                          SI */
459    COSTS_N_INSNS (17),                  /*                          DI */
460    COSTS_N_INSNS (17)},                 /*                          other */
461   COSTS_N_INSNS (1),                    /* cost of movsx */
462   COSTS_N_INSNS (1),                    /* cost of movzx */
463   8,                                    /* "large" insn */
464   6,                                    /* MOVE_RATIO */
465   2,                                 /* cost for loading QImode using movzbl */
466   {4, 4, 4},                            /* cost of loading integer registers
467                                            in QImode, HImode and SImode.
468                                            Relative to reg-reg move (2).  */
469   {2, 2, 2},                            /* cost of storing integer registers */
470   2,                                    /* cost of reg,reg fld/fst */
471   {2, 2, 6},                            /* cost of loading fp registers
472                                            in SFmode, DFmode and XFmode */
473   {4, 4, 6},                            /* cost of storing fp registers
474                                            in SFmode, DFmode and XFmode */
475   2,                                    /* cost of moving MMX register */
476   {2, 2},                               /* cost of loading MMX registers
477                                            in SImode and DImode */
478   {2, 2},                               /* cost of storing MMX registers
479                                            in SImode and DImode */
480   2,                                    /* cost of moving SSE register */
481   {2, 2, 8},                            /* cost of loading SSE registers
482                                            in SImode, DImode and TImode */
483   {2, 2, 8},                            /* cost of storing SSE registers
484                                            in SImode, DImode and TImode */
485   3,                                    /* MMX or SSE register to integer */
486   8,                                    /* size of l1 cache.  */
487   256,                                  /* size of l2 cache  */
488   32,                                   /* size of prefetch block */
489   6,                                    /* number of parallel prefetches */
490   2,                                    /* Branch cost */
491   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
492   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
493   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
494   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
495   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
496   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
497   pentiumpro_memcpy,
498   pentiumpro_memset,
499   1,                                    /* scalar_stmt_cost.  */
500   1,                                    /* scalar load_cost.  */
501   1,                                    /* scalar_store_cost.  */
502   1,                                    /* vec_stmt_cost.  */
503   1,                                    /* vec_to_scalar_cost.  */
504   1,                                    /* scalar_to_vec_cost.  */
505   1,                                    /* vec_align_load_cost.  */
506   2,                                    /* vec_unalign_load_cost.  */
507   1,                                    /* vec_store_cost.  */
508   3,                                    /* cond_taken_branch_cost.  */
509   1,                                    /* cond_not_taken_branch_cost.  */
510 };
511
512 static stringop_algs geode_memcpy[2] = {
513   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
514   DUMMY_STRINGOP_ALGS};
515 static stringop_algs geode_memset[2] = {
516   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
517   DUMMY_STRINGOP_ALGS};
518 static const
519 struct processor_costs geode_cost = {
520   COSTS_N_INSNS (1),                    /* cost of an add instruction */
521   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
522   COSTS_N_INSNS (2),                    /* variable shift costs */
523   COSTS_N_INSNS (1),                    /* constant shift costs */
524   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
525    COSTS_N_INSNS (4),                   /*                               HI */
526    COSTS_N_INSNS (7),                   /*                               SI */
527    COSTS_N_INSNS (7),                   /*                               DI */
528    COSTS_N_INSNS (7)},                  /*                            other */
529   0,                                    /* cost of multiply per each bit set */
530   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
531    COSTS_N_INSNS (23),                  /*                          HI */
532    COSTS_N_INSNS (39),                  /*                          SI */
533    COSTS_N_INSNS (39),                  /*                          DI */
534    COSTS_N_INSNS (39)},                 /*                          other */
535   COSTS_N_INSNS (1),                    /* cost of movsx */
536   COSTS_N_INSNS (1),                    /* cost of movzx */
537   8,                                    /* "large" insn */
538   4,                                    /* MOVE_RATIO */
539   1,                                 /* cost for loading QImode using movzbl */
540   {1, 1, 1},                            /* cost of loading integer registers
541                                            in QImode, HImode and SImode.
542                                            Relative to reg-reg move (2).  */
543   {1, 1, 1},                            /* cost of storing integer registers */
544   1,                                    /* cost of reg,reg fld/fst */
545   {1, 1, 1},                            /* cost of loading fp registers
546                                            in SFmode, DFmode and XFmode */
547   {4, 6, 6},                            /* cost of storing fp registers
548                                            in SFmode, DFmode and XFmode */
549
550   1,                                    /* cost of moving MMX register */
551   {1, 1},                               /* cost of loading MMX registers
552                                            in SImode and DImode */
553   {1, 1},                               /* cost of storing MMX registers
554                                            in SImode and DImode */
555   1,                                    /* cost of moving SSE register */
556   {1, 1, 1},                            /* cost of loading SSE registers
557                                            in SImode, DImode and TImode */
558   {1, 1, 1},                            /* cost of storing SSE registers
559                                            in SImode, DImode and TImode */
560   1,                                    /* MMX or SSE register to integer */
561   64,                                   /* size of l1 cache.  */
562   128,                                  /* size of l2 cache.  */
563   32,                                   /* size of prefetch block */
564   1,                                    /* number of parallel prefetches */
565   1,                                    /* Branch cost */
566   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
567   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
568   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
569   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
570   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
571   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
572   geode_memcpy,
573   geode_memset,
574   1,                                    /* scalar_stmt_cost.  */
575   1,                                    /* scalar load_cost.  */
576   1,                                    /* scalar_store_cost.  */
577   1,                                    /* vec_stmt_cost.  */
578   1,                                    /* vec_to_scalar_cost.  */
579   1,                                    /* scalar_to_vec_cost.  */
580   1,                                    /* vec_align_load_cost.  */
581   2,                                    /* vec_unalign_load_cost.  */
582   1,                                    /* vec_store_cost.  */
583   3,                                    /* cond_taken_branch_cost.  */
584   1,                                    /* cond_not_taken_branch_cost.  */
585 };
586
587 static stringop_algs k6_memcpy[2] = {
588   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
589   DUMMY_STRINGOP_ALGS};
590 static stringop_algs k6_memset[2] = {
591   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
592   DUMMY_STRINGOP_ALGS};
593 static const
594 struct processor_costs k6_cost = {
595   COSTS_N_INSNS (1),                    /* cost of an add instruction */
596   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
597   COSTS_N_INSNS (1),                    /* variable shift costs */
598   COSTS_N_INSNS (1),                    /* constant shift costs */
599   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
600    COSTS_N_INSNS (3),                   /*                               HI */
601    COSTS_N_INSNS (3),                   /*                               SI */
602    COSTS_N_INSNS (3),                   /*                               DI */
603    COSTS_N_INSNS (3)},                  /*                            other */
604   0,                                    /* cost of multiply per each bit set */
605   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
606    COSTS_N_INSNS (18),                  /*                          HI */
607    COSTS_N_INSNS (18),                  /*                          SI */
608    COSTS_N_INSNS (18),                  /*                          DI */
609    COSTS_N_INSNS (18)},                 /*                          other */
610   COSTS_N_INSNS (2),                    /* cost of movsx */
611   COSTS_N_INSNS (2),                    /* cost of movzx */
612   8,                                    /* "large" insn */
613   4,                                    /* MOVE_RATIO */
614   3,                                 /* cost for loading QImode using movzbl */
615   {4, 5, 4},                            /* cost of loading integer registers
616                                            in QImode, HImode and SImode.
617                                            Relative to reg-reg move (2).  */
618   {2, 3, 2},                            /* cost of storing integer registers */
619   4,                                    /* cost of reg,reg fld/fst */
620   {6, 6, 6},                            /* cost of loading fp registers
621                                            in SFmode, DFmode and XFmode */
622   {4, 4, 4},                            /* cost of storing fp registers
623                                            in SFmode, DFmode and XFmode */
624   2,                                    /* cost of moving MMX register */
625   {2, 2},                               /* cost of loading MMX registers
626                                            in SImode and DImode */
627   {2, 2},                               /* cost of storing MMX registers
628                                            in SImode and DImode */
629   2,                                    /* cost of moving SSE register */
630   {2, 2, 8},                            /* cost of loading SSE registers
631                                            in SImode, DImode and TImode */
632   {2, 2, 8},                            /* cost of storing SSE registers
633                                            in SImode, DImode and TImode */
634   6,                                    /* MMX or SSE register to integer */
635   32,                                   /* size of l1 cache.  */
636   32,                                   /* size of l2 cache.  Some models
637                                            have integrated l2 cache, but
638                                            optimizing for k6 is not important
639                                            enough to worry about that.  */
640   32,                                   /* size of prefetch block */
641   1,                                    /* number of parallel prefetches */
642   1,                                    /* Branch cost */
643   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
644   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
645   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
646   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
647   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
648   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
649   k6_memcpy,
650   k6_memset,
651   1,                                    /* scalar_stmt_cost.  */
652   1,                                    /* scalar load_cost.  */
653   1,                                    /* scalar_store_cost.  */
654   1,                                    /* vec_stmt_cost.  */
655   1,                                    /* vec_to_scalar_cost.  */
656   1,                                    /* scalar_to_vec_cost.  */
657   1,                                    /* vec_align_load_cost.  */
658   2,                                    /* vec_unalign_load_cost.  */
659   1,                                    /* vec_store_cost.  */
660   3,                                    /* cond_taken_branch_cost.  */
661   1,                                    /* cond_not_taken_branch_cost.  */
662 };
663
664 /* For some reason, Athlon deals better with REP prefix (relative to loops)
665    compared to K8. Alignment becomes important after 8 bytes for memcpy and
666    128 bytes for memset.  */
667 static stringop_algs athlon_memcpy[2] = {
668   {libcall, {{2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
669   DUMMY_STRINGOP_ALGS};
670 static stringop_algs athlon_memset[2] = {
671   {libcall, {{2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
672   DUMMY_STRINGOP_ALGS};
673 static const
674 struct processor_costs athlon_cost = {
675   COSTS_N_INSNS (1),                    /* cost of an add instruction */
676   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
677   COSTS_N_INSNS (1),                    /* variable shift costs */
678   COSTS_N_INSNS (1),                    /* constant shift costs */
679   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
680    COSTS_N_INSNS (5),                   /*                               HI */
681    COSTS_N_INSNS (5),                   /*                               SI */
682    COSTS_N_INSNS (5),                   /*                               DI */
683    COSTS_N_INSNS (5)},                  /*                            other */
684   0,                                    /* cost of multiply per each bit set */
685   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
686    COSTS_N_INSNS (26),                  /*                          HI */
687    COSTS_N_INSNS (42),                  /*                          SI */
688    COSTS_N_INSNS (74),                  /*                          DI */
689    COSTS_N_INSNS (74)},                 /*                          other */
690   COSTS_N_INSNS (1),                    /* cost of movsx */
691   COSTS_N_INSNS (1),                    /* cost of movzx */
692   8,                                    /* "large" insn */
693   9,                                    /* MOVE_RATIO */
694   4,                                 /* cost for loading QImode using movzbl */
695   {3, 4, 3},                            /* cost of loading integer registers
696                                            in QImode, HImode and SImode.
697                                            Relative to reg-reg move (2).  */
698   {3, 4, 3},                            /* cost of storing integer registers */
699   4,                                    /* cost of reg,reg fld/fst */
700   {4, 4, 12},                           /* cost of loading fp registers
701                                            in SFmode, DFmode and XFmode */
702   {6, 6, 8},                            /* cost of storing fp registers
703                                            in SFmode, DFmode and XFmode */
704   2,                                    /* cost of moving MMX register */
705   {4, 4},                               /* cost of loading MMX registers
706                                            in SImode and DImode */
707   {4, 4},                               /* cost of storing MMX registers
708                                            in SImode and DImode */
709   2,                                    /* cost of moving SSE register */
710   {4, 4, 6},                            /* cost of loading SSE registers
711                                            in SImode, DImode and TImode */
712   {4, 4, 5},                            /* cost of storing SSE registers
713                                            in SImode, DImode and TImode */
714   5,                                    /* MMX or SSE register to integer */
715   64,                                   /* size of l1 cache.  */
716   256,                                  /* size of l2 cache.  */
717   64,                                   /* size of prefetch block */
718   6,                                    /* number of parallel prefetches */
719   5,                                    /* Branch cost */
720   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
721   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
722   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
723   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
724   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
725   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
726   athlon_memcpy,
727   athlon_memset,
728   1,                                    /* scalar_stmt_cost.  */
729   1,                                    /* scalar load_cost.  */
730   1,                                    /* scalar_store_cost.  */
731   1,                                    /* vec_stmt_cost.  */
732   1,                                    /* vec_to_scalar_cost.  */
733   1,                                    /* scalar_to_vec_cost.  */
734   1,                                    /* vec_align_load_cost.  */
735   2,                                    /* vec_unalign_load_cost.  */
736   1,                                    /* vec_store_cost.  */
737   3,                                    /* cond_taken_branch_cost.  */
738   1,                                    /* cond_not_taken_branch_cost.  */
739 };
740
741 /* K8 has optimized REP instruction for medium sized blocks, but for very
742    small blocks it is better to use loop. For large blocks, libcall can
743    do nontemporary accesses and beat inline considerably.  */
744 static stringop_algs k8_memcpy[2] = {
745   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
746              {-1, rep_prefix_4_byte, false}}},
747   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
748              {-1, libcall, false}}}};
749 static stringop_algs k8_memset[2] = {
750   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
751              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
752   {libcall, {{48, unrolled_loop, false},
753              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
754 static const
755 struct processor_costs k8_cost = {
756   COSTS_N_INSNS (1),                    /* cost of an add instruction */
757   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
758   COSTS_N_INSNS (1),                    /* variable shift costs */
759   COSTS_N_INSNS (1),                    /* constant shift costs */
760   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
761    COSTS_N_INSNS (4),                   /*                               HI */
762    COSTS_N_INSNS (3),                   /*                               SI */
763    COSTS_N_INSNS (4),                   /*                               DI */
764    COSTS_N_INSNS (5)},                  /*                            other */
765   0,                                    /* cost of multiply per each bit set */
766   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
767    COSTS_N_INSNS (26),                  /*                          HI */
768    COSTS_N_INSNS (42),                  /*                          SI */
769    COSTS_N_INSNS (74),                  /*                          DI */
770    COSTS_N_INSNS (74)},                 /*                          other */
771   COSTS_N_INSNS (1),                    /* cost of movsx */
772   COSTS_N_INSNS (1),                    /* cost of movzx */
773   8,                                    /* "large" insn */
774   9,                                    /* MOVE_RATIO */
775   4,                                 /* cost for loading QImode using movzbl */
776   {3, 4, 3},                            /* cost of loading integer registers
777                                            in QImode, HImode and SImode.
778                                            Relative to reg-reg move (2).  */
779   {3, 4, 3},                            /* cost of storing integer registers */
780   4,                                    /* cost of reg,reg fld/fst */
781   {4, 4, 12},                           /* cost of loading fp registers
782                                            in SFmode, DFmode and XFmode */
783   {6, 6, 8},                            /* cost of storing fp registers
784                                            in SFmode, DFmode and XFmode */
785   2,                                    /* cost of moving MMX register */
786   {3, 3},                               /* cost of loading MMX registers
787                                            in SImode and DImode */
788   {4, 4},                               /* cost of storing MMX registers
789                                            in SImode and DImode */
790   2,                                    /* cost of moving SSE register */
791   {4, 3, 6},                            /* cost of loading SSE registers
792                                            in SImode, DImode and TImode */
793   {4, 4, 5},                            /* cost of storing SSE registers
794                                            in SImode, DImode and TImode */
795   5,                                    /* MMX or SSE register to integer */
796   64,                                   /* size of l1 cache.  */
797   512,                                  /* size of l2 cache.  */
798   64,                                   /* size of prefetch block */
799   /* New AMD processors never drop prefetches; if they cannot be performed
800      immediately, they are queued.  We set number of simultaneous prefetches
801      to a large constant to reflect this (it probably is not a good idea not
802      to limit number of prefetches at all, as their execution also takes some
803      time).  */
804   100,                                  /* number of parallel prefetches */
805   3,                                    /* Branch cost */
806   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
807   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
808   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
809   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
810   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
811   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
812
813   k8_memcpy,
814   k8_memset,
815   4,                                    /* scalar_stmt_cost.  */
816   2,                                    /* scalar load_cost.  */
817   2,                                    /* scalar_store_cost.  */
818   5,                                    /* vec_stmt_cost.  */
819   0,                                    /* vec_to_scalar_cost.  */
820   2,                                    /* scalar_to_vec_cost.  */
821   2,                                    /* vec_align_load_cost.  */
822   3,                                    /* vec_unalign_load_cost.  */
823   3,                                    /* vec_store_cost.  */
824   3,                                    /* cond_taken_branch_cost.  */
825   2,                                    /* cond_not_taken_branch_cost.  */
826 };
827
828 /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
829    very small blocks it is better to use loop. For large blocks, libcall can
830    do nontemporary accesses and beat inline considerably.  */
831 static stringop_algs amdfam10_memcpy[2] = {
832   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
833              {-1, rep_prefix_4_byte, false}}},
834   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
835              {-1, libcall, false}}}};
836 static stringop_algs amdfam10_memset[2] = {
837   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
838              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
839   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
840              {-1, libcall, false}}}};
841 struct processor_costs amdfam10_cost = {
842   COSTS_N_INSNS (1),                    /* cost of an add instruction */
843   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
844   COSTS_N_INSNS (1),                    /* variable shift costs */
845   COSTS_N_INSNS (1),                    /* constant shift costs */
846   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
847    COSTS_N_INSNS (4),                   /*                               HI */
848    COSTS_N_INSNS (3),                   /*                               SI */
849    COSTS_N_INSNS (4),                   /*                               DI */
850    COSTS_N_INSNS (5)},                  /*                            other */
851   0,                                    /* cost of multiply per each bit set */
852   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
853    COSTS_N_INSNS (35),                  /*                          HI */
854    COSTS_N_INSNS (51),                  /*                          SI */
855    COSTS_N_INSNS (83),                  /*                          DI */
856    COSTS_N_INSNS (83)},                 /*                          other */
857   COSTS_N_INSNS (1),                    /* cost of movsx */
858   COSTS_N_INSNS (1),                    /* cost of movzx */
859   8,                                    /* "large" insn */
860   9,                                    /* MOVE_RATIO */
861   4,                                 /* cost for loading QImode using movzbl */
862   {3, 4, 3},                            /* cost of loading integer registers
863                                            in QImode, HImode and SImode.
864                                            Relative to reg-reg move (2).  */
865   {3, 4, 3},                            /* cost of storing integer registers */
866   4,                                    /* cost of reg,reg fld/fst */
867   {4, 4, 12},                           /* cost of loading fp registers
868                                            in SFmode, DFmode and XFmode */
869   {6, 6, 8},                            /* cost of storing fp registers
870                                            in SFmode, DFmode and XFmode */
871   2,                                    /* cost of moving MMX register */
872   {3, 3},                               /* cost of loading MMX registers
873                                            in SImode and DImode */
874   {4, 4},                               /* cost of storing MMX registers
875                                            in SImode and DImode */
876   2,                                    /* cost of moving SSE register */
877   {4, 4, 3},                            /* cost of loading SSE registers
878                                            in SImode, DImode and TImode */
879   {4, 4, 5},                            /* cost of storing SSE registers
880                                            in SImode, DImode and TImode */
881   3,                                    /* MMX or SSE register to integer */
882                                         /* On K8:
883                                             MOVD reg64, xmmreg Double FSTORE 4
884                                             MOVD reg32, xmmreg Double FSTORE 4
885                                            On AMDFAM10:
886                                             MOVD reg64, xmmreg Double FADD 3
887                                                                1/1  1/1
888                                             MOVD reg32, xmmreg Double FADD 3
889                                                                1/1  1/1 */
890   64,                                   /* size of l1 cache.  */
891   512,                                  /* size of l2 cache.  */
892   64,                                   /* size of prefetch block */
893   /* New AMD processors never drop prefetches; if they cannot be performed
894      immediately, they are queued.  We set number of simultaneous prefetches
895      to a large constant to reflect this (it probably is not a good idea not
896      to limit number of prefetches at all, as their execution also takes some
897      time).  */
898   100,                                  /* number of parallel prefetches */
899   2,                                    /* Branch cost */
900   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
901   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
902   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
903   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
904   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
905   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
906
907   amdfam10_memcpy,
908   amdfam10_memset,
909   4,                                    /* scalar_stmt_cost.  */
910   2,                                    /* scalar load_cost.  */
911   2,                                    /* scalar_store_cost.  */
912   6,                                    /* vec_stmt_cost.  */
913   0,                                    /* vec_to_scalar_cost.  */
914   2,                                    /* scalar_to_vec_cost.  */
915   2,                                    /* vec_align_load_cost.  */
916   2,                                    /* vec_unalign_load_cost.  */
917   2,                                    /* vec_store_cost.  */
918   2,                                    /* cond_taken_branch_cost.  */
919   1,                                    /* cond_not_taken_branch_cost.  */
920 };
921
922 /*  BDVER1 has optimized REP instruction for medium sized blocks, but for
923     very small blocks it is better to use loop. For large blocks, libcall
924     can do nontemporary accesses and beat inline considerably.  */
925 static stringop_algs bdver1_memcpy[2] = {
926   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
927              {-1, rep_prefix_4_byte, false}}},
928   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
929              {-1, libcall, false}}}};
930 static stringop_algs bdver1_memset[2] = {
931   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
932              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
933   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
934              {-1, libcall, false}}}};
935
936 const struct processor_costs bdver1_cost = {
937   COSTS_N_INSNS (1),                    /* cost of an add instruction */
938   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
939   COSTS_N_INSNS (1),                    /* variable shift costs */
940   COSTS_N_INSNS (1),                    /* constant shift costs */
941   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
942    COSTS_N_INSNS (4),                   /*                               HI */
943    COSTS_N_INSNS (4),                   /*                               SI */
944    COSTS_N_INSNS (6),                   /*                               DI */
945    COSTS_N_INSNS (6)},                  /*                            other */
946   0,                                    /* cost of multiply per each bit set */
947   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
948    COSTS_N_INSNS (35),                  /*                          HI */
949    COSTS_N_INSNS (51),                  /*                          SI */
950    COSTS_N_INSNS (83),                  /*                          DI */
951    COSTS_N_INSNS (83)},                 /*                          other */
952   COSTS_N_INSNS (1),                    /* cost of movsx */
953   COSTS_N_INSNS (1),                    /* cost of movzx */
954   8,                                    /* "large" insn */
955   9,                                    /* MOVE_RATIO */
956   4,                                 /* cost for loading QImode using movzbl */
957   {5, 5, 4},                            /* cost of loading integer registers
958                                            in QImode, HImode and SImode.
959                                            Relative to reg-reg move (2).  */
960   {4, 4, 4},                            /* cost of storing integer registers */
961   2,                                    /* cost of reg,reg fld/fst */
962   {5, 5, 12},                           /* cost of loading fp registers
963                                            in SFmode, DFmode and XFmode */
964   {4, 4, 8},                            /* cost of storing fp registers
965                                            in SFmode, DFmode and XFmode */
966   2,                                    /* cost of moving MMX register */
967   {4, 4},                               /* cost of loading MMX registers
968                                            in SImode and DImode */
969   {4, 4},                               /* cost of storing MMX registers
970                                            in SImode and DImode */
971   2,                                    /* cost of moving SSE register */
972   {4, 4, 4},                            /* cost of loading SSE registers
973                                            in SImode, DImode and TImode */
974   {4, 4, 4},                            /* cost of storing SSE registers
975                                            in SImode, DImode and TImode */
976   2,                                    /* MMX or SSE register to integer */
977                                         /* On K8:
978                                             MOVD reg64, xmmreg Double FSTORE 4
979                                             MOVD reg32, xmmreg Double FSTORE 4
980                                            On AMDFAM10:
981                                             MOVD reg64, xmmreg Double FADD 3
982                                                                1/1  1/1
983                                             MOVD reg32, xmmreg Double FADD 3
984                                                                1/1  1/1 */
985   16,                                   /* size of l1 cache.  */
986   2048,                                 /* size of l2 cache.  */
987   64,                                   /* size of prefetch block */
988   /* New AMD processors never drop prefetches; if they cannot be performed
989      immediately, they are queued.  We set number of simultaneous prefetches
990      to a large constant to reflect this (it probably is not a good idea not
991      to limit number of prefetches at all, as their execution also takes some
992      time).  */
993   100,                                  /* number of parallel prefetches */
994   2,                                    /* Branch cost */
995   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
996   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
997   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
998   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
999   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1000   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1001
1002   bdver1_memcpy,
1003   bdver1_memset,
1004   6,                                    /* scalar_stmt_cost.  */
1005   4,                                    /* scalar load_cost.  */
1006   4,                                    /* scalar_store_cost.  */
1007   6,                                    /* vec_stmt_cost.  */
1008   0,                                    /* vec_to_scalar_cost.  */
1009   2,                                    /* scalar_to_vec_cost.  */
1010   4,                                    /* vec_align_load_cost.  */
1011   4,                                    /* vec_unalign_load_cost.  */
1012   4,                                    /* vec_store_cost.  */
1013   4,                                    /* cond_taken_branch_cost.  */
1014   2,                                    /* cond_not_taken_branch_cost.  */
1015 };
1016
1017 /*  BDVER2 has optimized REP instruction for medium sized blocks, but for
1018     very small blocks it is better to use loop. For large blocks, libcall
1019     can do nontemporary accesses and beat inline considerably.  */
1020
1021 static stringop_algs bdver2_memcpy[2] = {
1022   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1023              {-1, rep_prefix_4_byte, false}}},
1024   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1025              {-1, libcall, false}}}};
1026 static stringop_algs bdver2_memset[2] = {
1027   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1028              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1029   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1030              {-1, libcall, false}}}};
1031
1032 const struct processor_costs bdver2_cost = {
1033   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1034   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1035   COSTS_N_INSNS (1),                    /* variable shift costs */
1036   COSTS_N_INSNS (1),                    /* constant shift costs */
1037   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1038    COSTS_N_INSNS (4),                   /*                               HI */
1039    COSTS_N_INSNS (4),                   /*                               SI */
1040    COSTS_N_INSNS (6),                   /*                               DI */
1041    COSTS_N_INSNS (6)},                  /*                            other */
1042   0,                                    /* cost of multiply per each bit set */
1043   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1044    COSTS_N_INSNS (35),                  /*                          HI */
1045    COSTS_N_INSNS (51),                  /*                          SI */
1046    COSTS_N_INSNS (83),                  /*                          DI */
1047    COSTS_N_INSNS (83)},                 /*                          other */
1048   COSTS_N_INSNS (1),                    /* cost of movsx */
1049   COSTS_N_INSNS (1),                    /* cost of movzx */
1050   8,                                    /* "large" insn */
1051   9,                                    /* MOVE_RATIO */
1052   4,                                 /* cost for loading QImode using movzbl */
1053   {5, 5, 4},                            /* cost of loading integer registers
1054                                            in QImode, HImode and SImode.
1055                                            Relative to reg-reg move (2).  */
1056   {4, 4, 4},                            /* cost of storing integer registers */
1057   2,                                    /* cost of reg,reg fld/fst */
1058   {5, 5, 12},                           /* cost of loading fp registers
1059                                            in SFmode, DFmode and XFmode */
1060   {4, 4, 8},                            /* cost of storing fp registers
1061                                            in SFmode, DFmode and XFmode */
1062   2,                                    /* cost of moving MMX register */
1063   {4, 4},                               /* cost of loading MMX registers
1064                                            in SImode and DImode */
1065   {4, 4},                               /* cost of storing MMX registers
1066                                            in SImode and DImode */
1067   2,                                    /* cost of moving SSE register */
1068   {4, 4, 4},                            /* cost of loading SSE registers
1069                                            in SImode, DImode and TImode */
1070   {4, 4, 4},                            /* cost of storing SSE registers
1071                                            in SImode, DImode and TImode */
1072   2,                                    /* MMX or SSE register to integer */
1073                                         /* On K8:
1074                                             MOVD reg64, xmmreg Double FSTORE 4
1075                                             MOVD reg32, xmmreg Double FSTORE 4
1076                                            On AMDFAM10:
1077                                             MOVD reg64, xmmreg Double FADD 3
1078                                                                1/1  1/1
1079                                             MOVD reg32, xmmreg Double FADD 3
1080                                                                1/1  1/1 */
1081   16,                                   /* size of l1 cache.  */
1082   2048,                                 /* size of l2 cache.  */
1083   64,                                   /* size of prefetch block */
1084   /* New AMD processors never drop prefetches; if they cannot be performed
1085      immediately, they are queued.  We set number of simultaneous prefetches
1086      to a large constant to reflect this (it probably is not a good idea not
1087      to limit number of prefetches at all, as their execution also takes some
1088      time).  */
1089   100,                                  /* number of parallel prefetches */
1090   2,                                    /* Branch cost */
1091   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1092   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1093   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1094   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1095   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1096   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1097
1098   bdver2_memcpy,
1099   bdver2_memset,
1100   6,                                    /* scalar_stmt_cost.  */
1101   4,                                    /* scalar load_cost.  */
1102   4,                                    /* scalar_store_cost.  */
1103   6,                                    /* vec_stmt_cost.  */
1104   0,                                    /* vec_to_scalar_cost.  */
1105   2,                                    /* scalar_to_vec_cost.  */
1106   4,                                    /* vec_align_load_cost.  */
1107   4,                                    /* vec_unalign_load_cost.  */
1108   4,                                    /* vec_store_cost.  */
1109   4,                                    /* cond_taken_branch_cost.  */
1110   2,                                    /* cond_not_taken_branch_cost.  */
1111 };
1112
1113
1114   /*  BDVER3 has optimized REP instruction for medium sized blocks, but for
1115       very small blocks it is better to use loop. For large blocks, libcall
1116       can do nontemporary accesses and beat inline considerably.  */
1117 static stringop_algs bdver3_memcpy[2] = {
1118   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1119              {-1, rep_prefix_4_byte, false}}},
1120   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1121              {-1, libcall, false}}}};
1122 static stringop_algs bdver3_memset[2] = {
1123   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1124              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1125   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1126              {-1, libcall, false}}}};
1127 struct processor_costs bdver3_cost = {
1128   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1129   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1130   COSTS_N_INSNS (1),                    /* variable shift costs */
1131   COSTS_N_INSNS (1),                    /* constant shift costs */
1132   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1133    COSTS_N_INSNS (4),                   /*                               HI */
1134    COSTS_N_INSNS (4),                   /*                               SI */
1135    COSTS_N_INSNS (6),                   /*                               DI */
1136    COSTS_N_INSNS (6)},                  /*                            other */
1137   0,                                    /* cost of multiply per each bit set */
1138   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1139    COSTS_N_INSNS (35),                  /*                          HI */
1140    COSTS_N_INSNS (51),                  /*                          SI */
1141    COSTS_N_INSNS (83),                  /*                          DI */
1142    COSTS_N_INSNS (83)},                 /*                          other */
1143   COSTS_N_INSNS (1),                    /* cost of movsx */
1144   COSTS_N_INSNS (1),                    /* cost of movzx */
1145   8,                                    /* "large" insn */
1146   9,                                    /* MOVE_RATIO */
1147   4,                                 /* cost for loading QImode using movzbl */
1148   {5, 5, 4},                            /* cost of loading integer registers
1149                                            in QImode, HImode and SImode.
1150                                            Relative to reg-reg move (2).  */
1151   {4, 4, 4},                            /* cost of storing integer registers */
1152   2,                                    /* cost of reg,reg fld/fst */
1153   {5, 5, 12},                           /* cost of loading fp registers
1154                                            in SFmode, DFmode and XFmode */
1155   {4, 4, 8},                            /* cost of storing fp registers
1156                                            in SFmode, DFmode and XFmode */
1157   2,                                    /* cost of moving MMX register */
1158   {4, 4},                               /* cost of loading MMX registers
1159                                            in SImode and DImode */
1160   {4, 4},                               /* cost of storing MMX registers
1161                                            in SImode and DImode */
1162   2,                                    /* cost of moving SSE register */
1163   {4, 4, 4},                            /* cost of loading SSE registers
1164                                            in SImode, DImode and TImode */
1165   {4, 4, 4},                            /* cost of storing SSE registers
1166                                            in SImode, DImode and TImode */
1167   2,                                    /* MMX or SSE register to integer */
1168   16,                                   /* size of l1 cache.  */
1169   2048,                                 /* size of l2 cache.  */
1170   64,                                   /* size of prefetch block */
1171   /* New AMD processors never drop prefetches; if they cannot be performed
1172      immediately, they are queued.  We set number of simultaneous prefetches
1173      to a large constant to reflect this (it probably is not a good idea not
1174      to limit number of prefetches at all, as their execution also takes some
1175      time).  */
1176   100,                                  /* number of parallel prefetches */
1177   2,                                    /* Branch cost */
1178   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1179   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1180   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1181   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1182   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1183   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1184
1185   bdver3_memcpy,
1186   bdver3_memset,
1187   6,                                    /* scalar_stmt_cost.  */
1188   4,                                    /* scalar load_cost.  */
1189   4,                                    /* scalar_store_cost.  */
1190   6,                                    /* vec_stmt_cost.  */
1191   0,                                    /* vec_to_scalar_cost.  */
1192   2,                                    /* scalar_to_vec_cost.  */
1193   4,                                    /* vec_align_load_cost.  */
1194   4,                                    /* vec_unalign_load_cost.  */
1195   4,                                    /* vec_store_cost.  */
1196   4,                                    /* cond_taken_branch_cost.  */
1197   2,                                    /* cond_not_taken_branch_cost.  */
1198 };
1199
1200 /*  BDVER4 has optimized REP instruction for medium sized blocks, but for
1201     very small blocks it is better to use loop. For large blocks, libcall
1202     can do nontemporary accesses and beat inline considerably.  */
1203 static stringop_algs bdver4_memcpy[2] = {
1204   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1205              {-1, rep_prefix_4_byte, false}}},
1206   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1207              {-1, libcall, false}}}};
1208 static stringop_algs bdver4_memset[2] = {
1209   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1210              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1211   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1212              {-1, libcall, false}}}};
1213 struct processor_costs bdver4_cost = {
1214   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1215   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1216   COSTS_N_INSNS (1),                    /* variable shift costs */
1217   COSTS_N_INSNS (1),                    /* constant shift costs */
1218   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1219    COSTS_N_INSNS (4),                   /*                               HI */
1220    COSTS_N_INSNS (4),                   /*                               SI */
1221    COSTS_N_INSNS (6),                   /*                               DI */
1222    COSTS_N_INSNS (6)},                  /*                            other */
1223   0,                                    /* cost of multiply per each bit set */
1224   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1225    COSTS_N_INSNS (35),                  /*                          HI */
1226    COSTS_N_INSNS (51),                  /*                          SI */
1227    COSTS_N_INSNS (83),                  /*                          DI */
1228    COSTS_N_INSNS (83)},                 /*                          other */
1229   COSTS_N_INSNS (1),                    /* cost of movsx */
1230   COSTS_N_INSNS (1),                    /* cost of movzx */
1231   8,                                    /* "large" insn */
1232   9,                                    /* MOVE_RATIO */
1233   4,                                 /* cost for loading QImode using movzbl */
1234   {5, 5, 4},                            /* cost of loading integer registers
1235                                            in QImode, HImode and SImode.
1236                                            Relative to reg-reg move (2).  */
1237   {4, 4, 4},                            /* cost of storing integer registers */
1238   2,                                    /* cost of reg,reg fld/fst */
1239   {5, 5, 12},                           /* cost of loading fp registers
1240                                            in SFmode, DFmode and XFmode */
1241   {4, 4, 8},                            /* cost of storing fp registers
1242                                            in SFmode, DFmode and XFmode */
1243   2,                                    /* cost of moving MMX register */
1244   {4, 4},                               /* cost of loading MMX registers
1245                                            in SImode and DImode */
1246   {4, 4},                               /* cost of storing MMX registers
1247                                            in SImode and DImode */
1248   2,                                    /* cost of moving SSE register */
1249   {4, 4, 4},                            /* cost of loading SSE registers
1250                                            in SImode, DImode and TImode */
1251   {4, 4, 4},                            /* cost of storing SSE registers
1252                                            in SImode, DImode and TImode */
1253   2,                                    /* MMX or SSE register to integer */
1254   16,                                   /* size of l1 cache.  */
1255   2048,                                 /* size of l2 cache.  */
1256   64,                                   /* size of prefetch block */
1257   /* New AMD processors never drop prefetches; if they cannot be performed
1258      immediately, they are queued.  We set number of simultaneous prefetches
1259      to a large constant to reflect this (it probably is not a good idea not
1260      to limit number of prefetches at all, as their execution also takes some
1261      time).  */
1262   100,                                  /* number of parallel prefetches */
1263   2,                                    /* Branch cost */
1264   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1265   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1266   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1267   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1268   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1269   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1270
1271   bdver4_memcpy,
1272   bdver4_memset,
1273   6,                                    /* scalar_stmt_cost.  */
1274   4,                                    /* scalar load_cost.  */
1275   4,                                    /* scalar_store_cost.  */
1276   6,                                    /* vec_stmt_cost.  */
1277   0,                                    /* vec_to_scalar_cost.  */
1278   2,                                    /* scalar_to_vec_cost.  */
1279   4,                                    /* vec_align_load_cost.  */
1280   4,                                    /* vec_unalign_load_cost.  */
1281   4,                                    /* vec_store_cost.  */
1282   4,                                    /* cond_taken_branch_cost.  */
1283   2,                                    /* cond_not_taken_branch_cost.  */
1284 };
1285
1286   /* BTVER1 has optimized REP instruction for medium sized blocks, but for
1287      very small blocks it is better to use loop. For large blocks, libcall can
1288      do nontemporary accesses and beat inline considerably.  */
1289 static stringop_algs btver1_memcpy[2] = {
1290   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1291              {-1, rep_prefix_4_byte, false}}},
1292   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1293              {-1, libcall, false}}}};
1294 static stringop_algs btver1_memset[2] = {
1295   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1296              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1297   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1298              {-1, libcall, false}}}};
1299 const struct processor_costs btver1_cost = {
1300   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1301   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
1302   COSTS_N_INSNS (1),                    /* variable shift costs */
1303   COSTS_N_INSNS (1),                    /* constant shift costs */
1304   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1305    COSTS_N_INSNS (4),                   /*                               HI */
1306    COSTS_N_INSNS (3),                   /*                               SI */
1307    COSTS_N_INSNS (4),                   /*                               DI */
1308    COSTS_N_INSNS (5)},                  /*                            other */
1309   0,                                    /* cost of multiply per each bit set */
1310   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1311    COSTS_N_INSNS (35),                  /*                          HI */
1312    COSTS_N_INSNS (51),                  /*                          SI */
1313    COSTS_N_INSNS (83),                  /*                          DI */
1314    COSTS_N_INSNS (83)},                 /*                          other */
1315   COSTS_N_INSNS (1),                    /* cost of movsx */
1316   COSTS_N_INSNS (1),                    /* cost of movzx */
1317   8,                                    /* "large" insn */
1318   9,                                    /* MOVE_RATIO */
1319   4,                                 /* cost for loading QImode using movzbl */
1320   {3, 4, 3},                            /* cost of loading integer registers
1321                                            in QImode, HImode and SImode.
1322                                            Relative to reg-reg move (2).  */
1323   {3, 4, 3},                            /* cost of storing integer registers */
1324   4,                                    /* cost of reg,reg fld/fst */
1325   {4, 4, 12},                           /* cost of loading fp registers
1326                                            in SFmode, DFmode and XFmode */
1327   {6, 6, 8},                            /* cost of storing fp registers
1328                                            in SFmode, DFmode and XFmode */
1329   2,                                    /* cost of moving MMX register */
1330   {3, 3},                               /* cost of loading MMX registers
1331                                            in SImode and DImode */
1332   {4, 4},                               /* cost of storing MMX registers
1333                                            in SImode and DImode */
1334   2,                                    /* cost of moving SSE register */
1335   {4, 4, 3},                            /* cost of loading SSE registers
1336                                            in SImode, DImode and TImode */
1337   {4, 4, 5},                            /* cost of storing SSE registers
1338                                            in SImode, DImode and TImode */
1339   3,                                    /* MMX or SSE register to integer */
1340                                         /* On K8:
1341                                            MOVD reg64, xmmreg Double FSTORE 4
1342                                            MOVD reg32, xmmreg Double FSTORE 4
1343                                            On AMDFAM10:
1344                                            MOVD reg64, xmmreg Double FADD 3
1345                                                                1/1  1/1
1346                                             MOVD reg32, xmmreg Double FADD 3
1347                                                                1/1  1/1 */
1348   32,                                   /* size of l1 cache.  */
1349   512,                                  /* size of l2 cache.  */
1350   64,                                   /* size of prefetch block */
1351   100,                                  /* number of parallel prefetches */
1352   2,                                    /* Branch cost */
1353   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
1354   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
1355   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
1356   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1357   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1358   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
1359
1360   btver1_memcpy,
1361   btver1_memset,
1362   4,                                    /* scalar_stmt_cost.  */
1363   2,                                    /* scalar load_cost.  */
1364   2,                                    /* scalar_store_cost.  */
1365   6,                                    /* vec_stmt_cost.  */
1366   0,                                    /* vec_to_scalar_cost.  */
1367   2,                                    /* scalar_to_vec_cost.  */
1368   2,                                    /* vec_align_load_cost.  */
1369   2,                                    /* vec_unalign_load_cost.  */
1370   2,                                    /* vec_store_cost.  */
1371   2,                                    /* cond_taken_branch_cost.  */
1372   1,                                    /* cond_not_taken_branch_cost.  */
1373 };
1374
1375 static stringop_algs btver2_memcpy[2] = {
1376   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1377              {-1, rep_prefix_4_byte, false}}},
1378   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1379              {-1, libcall, false}}}};
1380 static stringop_algs btver2_memset[2] = {
1381   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1382              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1383   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1384              {-1, libcall, false}}}};
1385 const struct processor_costs btver2_cost = {
1386   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1387   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
1388   COSTS_N_INSNS (1),                    /* variable shift costs */
1389   COSTS_N_INSNS (1),                    /* constant shift costs */
1390   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1391    COSTS_N_INSNS (4),                   /*                               HI */
1392    COSTS_N_INSNS (3),                   /*                               SI */
1393    COSTS_N_INSNS (4),                   /*                               DI */
1394    COSTS_N_INSNS (5)},                  /*                            other */
1395   0,                                    /* cost of multiply per each bit set */
1396   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1397    COSTS_N_INSNS (35),                  /*                          HI */
1398    COSTS_N_INSNS (51),                  /*                          SI */
1399    COSTS_N_INSNS (83),                  /*                          DI */
1400    COSTS_N_INSNS (83)},                 /*                          other */
1401   COSTS_N_INSNS (1),                    /* cost of movsx */
1402   COSTS_N_INSNS (1),                    /* cost of movzx */
1403   8,                                    /* "large" insn */
1404   9,                                    /* MOVE_RATIO */
1405   4,                                 /* cost for loading QImode using movzbl */
1406   {3, 4, 3},                            /* cost of loading integer registers
1407                                            in QImode, HImode and SImode.
1408                                            Relative to reg-reg move (2).  */
1409   {3, 4, 3},                            /* cost of storing integer registers */
1410   4,                                    /* cost of reg,reg fld/fst */
1411   {4, 4, 12},                           /* cost of loading fp registers
1412                                            in SFmode, DFmode and XFmode */
1413   {6, 6, 8},                            /* cost of storing fp registers
1414                                            in SFmode, DFmode and XFmode */
1415   2,                                    /* cost of moving MMX register */
1416   {3, 3},                               /* cost of loading MMX registers
1417                                            in SImode and DImode */
1418   {4, 4},                               /* cost of storing MMX registers
1419                                            in SImode and DImode */
1420   2,                                    /* cost of moving SSE register */
1421   {4, 4, 3},                            /* cost of loading SSE registers
1422                                            in SImode, DImode and TImode */
1423   {4, 4, 5},                            /* cost of storing SSE registers
1424                                            in SImode, DImode and TImode */
1425   3,                                    /* MMX or SSE register to integer */
1426                                         /* On K8:
1427                                            MOVD reg64, xmmreg Double FSTORE 4
1428                                            MOVD reg32, xmmreg Double FSTORE 4
1429                                            On AMDFAM10:
1430                                            MOVD reg64, xmmreg Double FADD 3
1431                                                                1/1  1/1
1432                                             MOVD reg32, xmmreg Double FADD 3
1433                                                                1/1  1/1 */
1434   32,                                   /* size of l1 cache.  */
1435   2048,                                 /* size of l2 cache.  */
1436   64,                                   /* size of prefetch block */
1437   100,                                  /* number of parallel prefetches */
1438   2,                                    /* Branch cost */
1439   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
1440   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
1441   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
1442   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1443   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1444   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
1445   btver2_memcpy,
1446   btver2_memset,
1447   4,                                    /* scalar_stmt_cost.  */
1448   2,                                    /* scalar load_cost.  */
1449   2,                                    /* scalar_store_cost.  */
1450   6,                                    /* vec_stmt_cost.  */
1451   0,                                    /* vec_to_scalar_cost.  */
1452   2,                                    /* scalar_to_vec_cost.  */
1453   2,                                    /* vec_align_load_cost.  */
1454   2,                                    /* vec_unalign_load_cost.  */
1455   2,                                    /* vec_store_cost.  */
1456   2,                                    /* cond_taken_branch_cost.  */
1457   1,                                    /* cond_not_taken_branch_cost.  */
1458 };
1459
1460 static stringop_algs pentium4_memcpy[2] = {
1461   {libcall, {{12, loop_1_byte, false}, {-1, rep_prefix_4_byte, false}}},
1462   DUMMY_STRINGOP_ALGS};
1463 static stringop_algs pentium4_memset[2] = {
1464   {libcall, {{6, loop_1_byte, false}, {48, loop, false},
1465              {20480, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1466   DUMMY_STRINGOP_ALGS};
1467
1468 static const
1469 struct processor_costs pentium4_cost = {
1470   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1471   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
1472   COSTS_N_INSNS (4),                    /* variable shift costs */
1473   COSTS_N_INSNS (4),                    /* constant shift costs */
1474   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
1475    COSTS_N_INSNS (15),                  /*                               HI */
1476    COSTS_N_INSNS (15),                  /*                               SI */
1477    COSTS_N_INSNS (15),                  /*                               DI */
1478    COSTS_N_INSNS (15)},                 /*                            other */
1479   0,                                    /* cost of multiply per each bit set */
1480   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
1481    COSTS_N_INSNS (56),                  /*                          HI */
1482    COSTS_N_INSNS (56),                  /*                          SI */
1483    COSTS_N_INSNS (56),                  /*                          DI */
1484    COSTS_N_INSNS (56)},                 /*                          other */
1485   COSTS_N_INSNS (1),                    /* cost of movsx */
1486   COSTS_N_INSNS (1),                    /* cost of movzx */
1487   16,                                   /* "large" insn */
1488   6,                                    /* MOVE_RATIO */
1489   2,                                 /* cost for loading QImode using movzbl */
1490   {4, 5, 4},                            /* cost of loading integer registers
1491                                            in QImode, HImode and SImode.
1492                                            Relative to reg-reg move (2).  */
1493   {2, 3, 2},                            /* cost of storing integer registers */
1494   2,                                    /* cost of reg,reg fld/fst */
1495   {2, 2, 6},                            /* cost of loading fp registers
1496                                            in SFmode, DFmode and XFmode */
1497   {4, 4, 6},                            /* cost of storing fp registers
1498                                            in SFmode, DFmode and XFmode */
1499   2,                                    /* cost of moving MMX register */
1500   {2, 2},                               /* cost of loading MMX registers
1501                                            in SImode and DImode */
1502   {2, 2},                               /* cost of storing MMX registers
1503                                            in SImode and DImode */
1504   12,                                   /* cost of moving SSE register */
1505   {12, 12, 12},                         /* cost of loading SSE registers
1506                                            in SImode, DImode and TImode */
1507   {2, 2, 8},                            /* cost of storing SSE registers
1508                                            in SImode, DImode and TImode */
1509   10,                                   /* MMX or SSE register to integer */
1510   8,                                    /* size of l1 cache.  */
1511   256,                                  /* size of l2 cache.  */
1512   64,                                   /* size of prefetch block */
1513   6,                                    /* number of parallel prefetches */
1514   2,                                    /* Branch cost */
1515   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
1516   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
1517   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
1518   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1519   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1520   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
1521   pentium4_memcpy,
1522   pentium4_memset,
1523   1,                                    /* scalar_stmt_cost.  */
1524   1,                                    /* scalar load_cost.  */
1525   1,                                    /* scalar_store_cost.  */
1526   1,                                    /* vec_stmt_cost.  */
1527   1,                                    /* vec_to_scalar_cost.  */
1528   1,                                    /* scalar_to_vec_cost.  */
1529   1,                                    /* vec_align_load_cost.  */
1530   2,                                    /* vec_unalign_load_cost.  */
1531   1,                                    /* vec_store_cost.  */
1532   3,                                    /* cond_taken_branch_cost.  */
1533   1,                                    /* cond_not_taken_branch_cost.  */
1534 };
1535
1536 static stringop_algs nocona_memcpy[2] = {
1537   {libcall, {{12, loop_1_byte, false}, {-1, rep_prefix_4_byte, false}}},
1538   {libcall, {{32, loop, false}, {20000, rep_prefix_8_byte, false},
1539              {100000, unrolled_loop, false}, {-1, libcall, false}}}};
1540
1541 static stringop_algs nocona_memset[2] = {
1542   {libcall, {{6, loop_1_byte, false}, {48, loop, false},
1543              {20480, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1544   {libcall, {{24, loop, false}, {64, unrolled_loop, false},
1545              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1546
1547 static const
1548 struct processor_costs nocona_cost = {
1549   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1550   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1551   COSTS_N_INSNS (1),                    /* variable shift costs */
1552   COSTS_N_INSNS (1),                    /* constant shift costs */
1553   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
1554    COSTS_N_INSNS (10),                  /*                               HI */
1555    COSTS_N_INSNS (10),                  /*                               SI */
1556    COSTS_N_INSNS (10),                  /*                               DI */
1557    COSTS_N_INSNS (10)},                 /*                            other */
1558   0,                                    /* cost of multiply per each bit set */
1559   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
1560    COSTS_N_INSNS (66),                  /*                          HI */
1561    COSTS_N_INSNS (66),                  /*                          SI */
1562    COSTS_N_INSNS (66),                  /*                          DI */
1563    COSTS_N_INSNS (66)},                 /*                          other */
1564   COSTS_N_INSNS (1),                    /* cost of movsx */
1565   COSTS_N_INSNS (1),                    /* cost of movzx */
1566   16,                                   /* "large" insn */
1567   17,                                   /* MOVE_RATIO */
1568   4,                                 /* cost for loading QImode using movzbl */
1569   {4, 4, 4},                            /* cost of loading integer registers
1570                                            in QImode, HImode and SImode.
1571                                            Relative to reg-reg move (2).  */
1572   {4, 4, 4},                            /* cost of storing integer registers */
1573   3,                                    /* cost of reg,reg fld/fst */
1574   {12, 12, 12},                         /* cost of loading fp registers
1575                                            in SFmode, DFmode and XFmode */
1576   {4, 4, 4},                            /* cost of storing fp registers
1577                                            in SFmode, DFmode and XFmode */
1578   6,                                    /* cost of moving MMX register */
1579   {12, 12},                             /* cost of loading MMX registers
1580                                            in SImode and DImode */
1581   {12, 12},                             /* cost of storing MMX registers
1582                                            in SImode and DImode */
1583   6,                                    /* cost of moving SSE register */
1584   {12, 12, 12},                         /* cost of loading SSE registers
1585                                            in SImode, DImode and TImode */
1586   {12, 12, 12},                         /* cost of storing SSE registers
1587                                            in SImode, DImode and TImode */
1588   8,                                    /* MMX or SSE register to integer */
1589   8,                                    /* size of l1 cache.  */
1590   1024,                                 /* size of l2 cache.  */
1591   64,                                   /* size of prefetch block */
1592   8,                                    /* number of parallel prefetches */
1593   1,                                    /* Branch cost */
1594   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1595   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1596   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
1597   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
1598   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
1599   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
1600   nocona_memcpy,
1601   nocona_memset,
1602   1,                                    /* scalar_stmt_cost.  */
1603   1,                                    /* scalar load_cost.  */
1604   1,                                    /* scalar_store_cost.  */
1605   1,                                    /* vec_stmt_cost.  */
1606   1,                                    /* vec_to_scalar_cost.  */
1607   1,                                    /* scalar_to_vec_cost.  */
1608   1,                                    /* vec_align_load_cost.  */
1609   2,                                    /* vec_unalign_load_cost.  */
1610   1,                                    /* vec_store_cost.  */
1611   3,                                    /* cond_taken_branch_cost.  */
1612   1,                                    /* cond_not_taken_branch_cost.  */
1613 };
1614
1615 static stringop_algs atom_memcpy[2] = {
1616   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1617   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1618              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1619 static stringop_algs atom_memset[2] = {
1620   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1621              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1622   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1623              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1624 static const
1625 struct processor_costs atom_cost = {
1626   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1627   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1628   COSTS_N_INSNS (1),                    /* variable shift costs */
1629   COSTS_N_INSNS (1),                    /* constant shift costs */
1630   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1631    COSTS_N_INSNS (4),                   /*                               HI */
1632    COSTS_N_INSNS (3),                   /*                               SI */
1633    COSTS_N_INSNS (4),                   /*                               DI */
1634    COSTS_N_INSNS (2)},                  /*                            other */
1635   0,                                    /* cost of multiply per each bit set */
1636   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1637    COSTS_N_INSNS (26),                  /*                          HI */
1638    COSTS_N_INSNS (42),                  /*                          SI */
1639    COSTS_N_INSNS (74),                  /*                          DI */
1640    COSTS_N_INSNS (74)},                 /*                          other */
1641   COSTS_N_INSNS (1),                    /* cost of movsx */
1642   COSTS_N_INSNS (1),                    /* cost of movzx */
1643   8,                                    /* "large" insn */
1644   17,                                   /* MOVE_RATIO */
1645   4,                                    /* cost for loading QImode using movzbl */
1646   {4, 4, 4},                            /* cost of loading integer registers
1647                                            in QImode, HImode and SImode.
1648                                            Relative to reg-reg move (2).  */
1649   {4, 4, 4},                            /* cost of storing integer registers */
1650   4,                                    /* cost of reg,reg fld/fst */
1651   {12, 12, 12},                         /* cost of loading fp registers
1652                                            in SFmode, DFmode and XFmode */
1653   {6, 6, 8},                            /* cost of storing fp registers
1654                                            in SFmode, DFmode and XFmode */
1655   2,                                    /* cost of moving MMX register */
1656   {8, 8},                               /* cost of loading MMX registers
1657                                            in SImode and DImode */
1658   {8, 8},                               /* cost of storing MMX registers
1659                                            in SImode and DImode */
1660   2,                                    /* cost of moving SSE register */
1661   {8, 8, 8},                            /* cost of loading SSE registers
1662                                            in SImode, DImode and TImode */
1663   {8, 8, 8},                            /* cost of storing SSE registers
1664                                            in SImode, DImode and TImode */
1665   5,                                    /* MMX or SSE register to integer */
1666   32,                                   /* size of l1 cache.  */
1667   256,                                  /* size of l2 cache.  */
1668   64,                                   /* size of prefetch block */
1669   6,                                    /* number of parallel prefetches */
1670   3,                                    /* Branch cost */
1671   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1672   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1673   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1674   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1675   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1676   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1677   atom_memcpy,
1678   atom_memset,
1679   1,                                    /* scalar_stmt_cost.  */
1680   1,                                    /* scalar load_cost.  */
1681   1,                                    /* scalar_store_cost.  */
1682   1,                                    /* vec_stmt_cost.  */
1683   1,                                    /* vec_to_scalar_cost.  */
1684   1,                                    /* scalar_to_vec_cost.  */
1685   1,                                    /* vec_align_load_cost.  */
1686   2,                                    /* vec_unalign_load_cost.  */
1687   1,                                    /* vec_store_cost.  */
1688   3,                                    /* cond_taken_branch_cost.  */
1689   1,                                    /* cond_not_taken_branch_cost.  */
1690 };
1691
1692 static stringop_algs slm_memcpy[2] = {
1693   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1694   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1695              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1696 static stringop_algs slm_memset[2] = {
1697   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1698              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1699   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1700              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1701 static const
1702 struct processor_costs slm_cost = {
1703   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1704   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1705   COSTS_N_INSNS (1),                    /* variable shift costs */
1706   COSTS_N_INSNS (1),                    /* constant shift costs */
1707   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1708    COSTS_N_INSNS (3),                   /*                               HI */
1709    COSTS_N_INSNS (3),                   /*                               SI */
1710    COSTS_N_INSNS (4),                   /*                               DI */
1711    COSTS_N_INSNS (2)},                  /*                            other */
1712   0,                                    /* cost of multiply per each bit set */
1713   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1714    COSTS_N_INSNS (26),                  /*                          HI */
1715    COSTS_N_INSNS (42),                  /*                          SI */
1716    COSTS_N_INSNS (74),                  /*                          DI */
1717    COSTS_N_INSNS (74)},                 /*                          other */
1718   COSTS_N_INSNS (1),                    /* cost of movsx */
1719   COSTS_N_INSNS (1),                    /* cost of movzx */
1720   8,                                    /* "large" insn */
1721   17,                                   /* MOVE_RATIO */
1722   4,                                    /* cost for loading QImode using movzbl */
1723   {4, 4, 4},                            /* cost of loading integer registers
1724                                            in QImode, HImode and SImode.
1725                                            Relative to reg-reg move (2).  */
1726   {4, 4, 4},                            /* cost of storing integer registers */
1727   4,                                    /* cost of reg,reg fld/fst */
1728   {12, 12, 12},                         /* cost of loading fp registers
1729                                            in SFmode, DFmode and XFmode */
1730   {6, 6, 8},                            /* cost of storing fp registers
1731                                            in SFmode, DFmode and XFmode */
1732   2,                                    /* cost of moving MMX register */
1733   {8, 8},                               /* cost of loading MMX registers
1734                                            in SImode and DImode */
1735   {8, 8},                               /* cost of storing MMX registers
1736                                            in SImode and DImode */
1737   2,                                    /* cost of moving SSE register */
1738   {8, 8, 8},                            /* cost of loading SSE registers
1739                                            in SImode, DImode and TImode */
1740   {8, 8, 8},                            /* cost of storing SSE registers
1741                                            in SImode, DImode and TImode */
1742   5,                                    /* MMX or SSE register to integer */
1743   32,                                   /* size of l1 cache.  */
1744   256,                                  /* size of l2 cache.  */
1745   64,                                   /* size of prefetch block */
1746   6,                                    /* number of parallel prefetches */
1747   3,                                    /* Branch cost */
1748   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1749   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1750   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1751   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1752   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1753   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1754   slm_memcpy,
1755   slm_memset,
1756   1,                                    /* scalar_stmt_cost.  */
1757   1,                                    /* scalar load_cost.  */
1758   1,                                    /* scalar_store_cost.  */
1759   1,                                    /* vec_stmt_cost.  */
1760   4,                                    /* vec_to_scalar_cost.  */
1761   1,                                    /* scalar_to_vec_cost.  */
1762   1,                                    /* vec_align_load_cost.  */
1763   2,                                    /* vec_unalign_load_cost.  */
1764   1,                                    /* vec_store_cost.  */
1765   3,                                    /* cond_taken_branch_cost.  */
1766   1,                                    /* cond_not_taken_branch_cost.  */
1767 };
1768
1769 static stringop_algs intel_memcpy[2] = {
1770   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1771   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1772              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1773 static stringop_algs intel_memset[2] = {
1774   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1775              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1776   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1777              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1778 static const
1779 struct processor_costs intel_cost = {
1780   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1781   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1782   COSTS_N_INSNS (1),                    /* variable shift costs */
1783   COSTS_N_INSNS (1),                    /* constant shift costs */
1784   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1785    COSTS_N_INSNS (3),                   /*                               HI */
1786    COSTS_N_INSNS (3),                   /*                               SI */
1787    COSTS_N_INSNS (4),                   /*                               DI */
1788    COSTS_N_INSNS (2)},                  /*                            other */
1789   0,                                    /* cost of multiply per each bit set */
1790   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1791    COSTS_N_INSNS (26),                  /*                          HI */
1792    COSTS_N_INSNS (42),                  /*                          SI */
1793    COSTS_N_INSNS (74),                  /*                          DI */
1794    COSTS_N_INSNS (74)},                 /*                          other */
1795   COSTS_N_INSNS (1),                    /* cost of movsx */
1796   COSTS_N_INSNS (1),                    /* cost of movzx */
1797   8,                                    /* "large" insn */
1798   17,                                   /* MOVE_RATIO */
1799   4,                                    /* cost for loading QImode using movzbl */
1800   {4, 4, 4},                            /* cost of loading integer registers
1801                                            in QImode, HImode and SImode.
1802                                            Relative to reg-reg move (2).  */
1803   {4, 4, 4},                            /* cost of storing integer registers */
1804   4,                                    /* cost of reg,reg fld/fst */
1805   {12, 12, 12},                         /* cost of loading fp registers
1806                                            in SFmode, DFmode and XFmode */
1807   {6, 6, 8},                            /* cost of storing fp registers
1808                                            in SFmode, DFmode and XFmode */
1809   2,                                    /* cost of moving MMX register */
1810   {8, 8},                               /* cost of loading MMX registers
1811                                            in SImode and DImode */
1812   {8, 8},                               /* cost of storing MMX registers
1813                                            in SImode and DImode */
1814   2,                                    /* cost of moving SSE register */
1815   {8, 8, 8},                            /* cost of loading SSE registers
1816                                            in SImode, DImode and TImode */
1817   {8, 8, 8},                            /* cost of storing SSE registers
1818                                            in SImode, DImode and TImode */
1819   5,                                    /* MMX or SSE register to integer */
1820   32,                                   /* size of l1 cache.  */
1821   256,                                  /* size of l2 cache.  */
1822   64,                                   /* size of prefetch block */
1823   6,                                    /* number of parallel prefetches */
1824   3,                                    /* Branch cost */
1825   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1826   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1827   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1828   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1829   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1830   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1831   intel_memcpy,
1832   intel_memset,
1833   1,                                    /* scalar_stmt_cost.  */
1834   1,                                    /* scalar load_cost.  */
1835   1,                                    /* scalar_store_cost.  */
1836   1,                                    /* vec_stmt_cost.  */
1837   4,                                    /* vec_to_scalar_cost.  */
1838   1,                                    /* scalar_to_vec_cost.  */
1839   1,                                    /* vec_align_load_cost.  */
1840   2,                                    /* vec_unalign_load_cost.  */
1841   1,                                    /* vec_store_cost.  */
1842   3,                                    /* cond_taken_branch_cost.  */
1843   1,                                    /* cond_not_taken_branch_cost.  */
1844 };
1845
1846 /* Generic should produce code tuned for Core-i7 (and newer chips)
1847    and btver1 (and newer chips).  */
1848
1849 static stringop_algs generic_memcpy[2] = {
1850   {libcall, {{32, loop, false}, {8192, rep_prefix_4_byte, false},
1851              {-1, libcall, false}}},
1852   {libcall, {{32, loop, false}, {8192, rep_prefix_8_byte, false},
1853              {-1, libcall, false}}}};
1854 static stringop_algs generic_memset[2] = {
1855   {libcall, {{32, loop, false}, {8192, rep_prefix_4_byte, false},
1856              {-1, libcall, false}}},
1857   {libcall, {{32, loop, false}, {8192, rep_prefix_8_byte, false},
1858              {-1, libcall, false}}}};
1859 static const
1860 struct processor_costs generic_cost = {
1861   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1862   /* On all chips taken into consideration lea is 2 cycles and more.  With
1863      this cost however our current implementation of synth_mult results in
1864      use of unnecessary temporary registers causing regression on several
1865      SPECfp benchmarks.  */
1866   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1867   COSTS_N_INSNS (1),                    /* variable shift costs */
1868   COSTS_N_INSNS (1),                    /* constant shift costs */
1869   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1870    COSTS_N_INSNS (4),                   /*                               HI */
1871    COSTS_N_INSNS (3),                   /*                               SI */
1872    COSTS_N_INSNS (4),                   /*                               DI */
1873    COSTS_N_INSNS (2)},                  /*                            other */
1874   0,                                    /* cost of multiply per each bit set */
1875   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1876    COSTS_N_INSNS (26),                  /*                          HI */
1877    COSTS_N_INSNS (42),                  /*                          SI */
1878    COSTS_N_INSNS (74),                  /*                          DI */
1879    COSTS_N_INSNS (74)},                 /*                          other */
1880   COSTS_N_INSNS (1),                    /* cost of movsx */
1881   COSTS_N_INSNS (1),                    /* cost of movzx */
1882   8,                                    /* "large" insn */
1883   17,                                   /* MOVE_RATIO */
1884   4,                                 /* cost for loading QImode using movzbl */
1885   {4, 4, 4},                            /* cost of loading integer registers
1886                                            in QImode, HImode and SImode.
1887                                            Relative to reg-reg move (2).  */
1888   {4, 4, 4},                            /* cost of storing integer registers */
1889   4,                                    /* cost of reg,reg fld/fst */
1890   {12, 12, 12},                         /* cost of loading fp registers
1891                                            in SFmode, DFmode and XFmode */
1892   {6, 6, 8},                            /* cost of storing fp registers
1893                                            in SFmode, DFmode and XFmode */
1894   2,                                    /* cost of moving MMX register */
1895   {8, 8},                               /* cost of loading MMX registers
1896                                            in SImode and DImode */
1897   {8, 8},                               /* cost of storing MMX registers
1898                                            in SImode and DImode */
1899   2,                                    /* cost of moving SSE register */
1900   {8, 8, 8},                            /* cost of loading SSE registers
1901                                            in SImode, DImode and TImode */
1902   {8, 8, 8},                            /* cost of storing SSE registers
1903                                            in SImode, DImode and TImode */
1904   5,                                    /* MMX or SSE register to integer */
1905   32,                                   /* size of l1 cache.  */
1906   512,                                  /* size of l2 cache.  */
1907   64,                                   /* size of prefetch block */
1908   6,                                    /* number of parallel prefetches */
1909   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this
1910      value is increased to perhaps more appropriate value of 5.  */
1911   3,                                    /* Branch cost */
1912   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1913   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1914   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1915   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1916   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1917   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1918   generic_memcpy,
1919   generic_memset,
1920   1,                                    /* scalar_stmt_cost.  */
1921   1,                                    /* scalar load_cost.  */
1922   1,                                    /* scalar_store_cost.  */
1923   1,                                    /* vec_stmt_cost.  */
1924   1,                                    /* vec_to_scalar_cost.  */
1925   1,                                    /* scalar_to_vec_cost.  */
1926   1,                                    /* vec_align_load_cost.  */
1927   2,                                    /* vec_unalign_load_cost.  */
1928   1,                                    /* vec_store_cost.  */
1929   3,                                    /* cond_taken_branch_cost.  */
1930   1,                                    /* cond_not_taken_branch_cost.  */
1931 };
1932
1933 /* core_cost should produce code tuned for Core familly of CPUs.  */
1934 static stringop_algs core_memcpy[2] = {
1935   {libcall, {{1024, rep_prefix_4_byte, true}, {-1, libcall, false}}},
1936   {libcall, {{24, loop, true}, {128, rep_prefix_8_byte, true},
1937              {-1, libcall, false}}}};
1938 static stringop_algs core_memset[2] = {
1939   {libcall, {{6, loop_1_byte, true},
1940              {24, loop, true},
1941              {8192, rep_prefix_4_byte, true},
1942              {-1, libcall, false}}},
1943   {libcall, {{24, loop, true}, {512, rep_prefix_8_byte, true},
1944              {-1, libcall, false}}}};
1945
1946 static const
1947 struct processor_costs core_cost = {
1948   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1949   /* On all chips taken into consideration lea is 2 cycles and more.  With
1950      this cost however our current implementation of synth_mult results in
1951      use of unnecessary temporary registers causing regression on several
1952      SPECfp benchmarks.  */
1953   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1954   COSTS_N_INSNS (1),                    /* variable shift costs */
1955   COSTS_N_INSNS (1),                    /* constant shift costs */
1956   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1957    COSTS_N_INSNS (4),                   /*                               HI */
1958    COSTS_N_INSNS (3),                   /*                               SI */
1959    COSTS_N_INSNS (4),                   /*                               DI */
1960    COSTS_N_INSNS (2)},                  /*                            other */
1961   0,                                    /* cost of multiply per each bit set */
1962   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1963    COSTS_N_INSNS (26),                  /*                          HI */
1964    COSTS_N_INSNS (42),                  /*                          SI */
1965    COSTS_N_INSNS (74),                  /*                          DI */
1966    COSTS_N_INSNS (74)},                 /*                          other */
1967   COSTS_N_INSNS (1),                    /* cost of movsx */
1968   COSTS_N_INSNS (1),                    /* cost of movzx */
1969   8,                                    /* "large" insn */
1970   17,                                   /* MOVE_RATIO */
1971   4,                                 /* cost for loading QImode using movzbl */
1972   {4, 4, 4},                            /* cost of loading integer registers
1973                                            in QImode, HImode and SImode.
1974                                            Relative to reg-reg move (2).  */
1975   {4, 4, 4},                            /* cost of storing integer registers */
1976   4,                                    /* cost of reg,reg fld/fst */
1977   {12, 12, 12},                         /* cost of loading fp registers
1978                                            in SFmode, DFmode and XFmode */
1979   {6, 6, 8},                            /* cost of storing fp registers
1980                                            in SFmode, DFmode and XFmode */
1981   2,                                    /* cost of moving MMX register */
1982   {8, 8},                               /* cost of loading MMX registers
1983                                            in SImode and DImode */
1984   {8, 8},                               /* cost of storing MMX registers
1985                                            in SImode and DImode */
1986   2,                                    /* cost of moving SSE register */
1987   {8, 8, 8},                            /* cost of loading SSE registers
1988                                            in SImode, DImode and TImode */
1989   {8, 8, 8},                            /* cost of storing SSE registers
1990                                            in SImode, DImode and TImode */
1991   5,                                    /* MMX or SSE register to integer */
1992   64,                                   /* size of l1 cache.  */
1993   512,                                  /* size of l2 cache.  */
1994   64,                                   /* size of prefetch block */
1995   6,                                    /* number of parallel prefetches */
1996   /* FIXME perhaps more appropriate value is 5.  */
1997   3,                                    /* Branch cost */
1998   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1999   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
2000   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
2001   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
2002   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
2003   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
2004   core_memcpy,
2005   core_memset,
2006   1,                                    /* scalar_stmt_cost.  */
2007   1,                                    /* scalar load_cost.  */
2008   1,                                    /* scalar_store_cost.  */
2009   1,                                    /* vec_stmt_cost.  */
2010   1,                                    /* vec_to_scalar_cost.  */
2011   1,                                    /* scalar_to_vec_cost.  */
2012   1,                                    /* vec_align_load_cost.  */
2013   2,                                    /* vec_unalign_load_cost.  */
2014   1,                                    /* vec_store_cost.  */
2015   3,                                    /* cond_taken_branch_cost.  */
2016   1,                                    /* cond_not_taken_branch_cost.  */
2017 };
2018
2019
2020 /* Set by -mtune.  */
2021 const struct processor_costs *ix86_tune_cost = &pentium_cost;
2022
2023 /* Set by -mtune or -Os.  */
2024 const struct processor_costs *ix86_cost = &pentium_cost;
2025
2026 /* Processor feature/optimization bitmasks.  */
2027 #define m_386 (1<<PROCESSOR_I386)
2028 #define m_486 (1<<PROCESSOR_I486)
2029 #define m_PENT (1<<PROCESSOR_PENTIUM)
2030 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
2031 #define m_PENT4 (1<<PROCESSOR_PENTIUM4)
2032 #define m_NOCONA (1<<PROCESSOR_NOCONA)
2033 #define m_P4_NOCONA (m_PENT4 | m_NOCONA)
2034 #define m_CORE2 (1<<PROCESSOR_CORE2)
2035 #define m_NEHALEM (1<<PROCESSOR_NEHALEM)
2036 #define m_SANDYBRIDGE (1<<PROCESSOR_SANDYBRIDGE)
2037 #define m_HASWELL (1<<PROCESSOR_HASWELL)
2038 #define m_CORE_ALL (m_CORE2 | m_NEHALEM  | m_SANDYBRIDGE | m_HASWELL)
2039 #define m_BONNELL (1<<PROCESSOR_BONNELL)
2040 #define m_SILVERMONT (1<<PROCESSOR_SILVERMONT)
2041 #define m_KNL (1<<PROCESSOR_KNL)
2042 #define m_INTEL (1<<PROCESSOR_INTEL)
2043
2044 #define m_GEODE (1<<PROCESSOR_GEODE)
2045 #define m_K6 (1<<PROCESSOR_K6)
2046 #define m_K6_GEODE (m_K6 | m_GEODE)
2047 #define m_K8 (1<<PROCESSOR_K8)
2048 #define m_ATHLON (1<<PROCESSOR_ATHLON)
2049 #define m_ATHLON_K8 (m_K8 | m_ATHLON)
2050 #define m_AMDFAM10 (1<<PROCESSOR_AMDFAM10)
2051 #define m_BDVER1 (1<<PROCESSOR_BDVER1)
2052 #define m_BDVER2 (1<<PROCESSOR_BDVER2)
2053 #define m_BDVER3 (1<<PROCESSOR_BDVER3)
2054 #define m_BDVER4 (1<<PROCESSOR_BDVER4)
2055 #define m_BTVER1 (1<<PROCESSOR_BTVER1)
2056 #define m_BTVER2 (1<<PROCESSOR_BTVER2)
2057 #define m_BDVER (m_BDVER1 | m_BDVER2 | m_BDVER3 | m_BDVER4)
2058 #define m_BTVER (m_BTVER1 | m_BTVER2)
2059 #define m_AMD_MULTIPLE (m_ATHLON_K8 | m_AMDFAM10 | m_BDVER | m_BTVER)
2060
2061 #define m_GENERIC (1<<PROCESSOR_GENERIC)
2062
2063 const char* ix86_tune_feature_names[X86_TUNE_LAST] = {
2064 #undef DEF_TUNE
2065 #define DEF_TUNE(tune, name, selector) name,
2066 #include "x86-tune.def"
2067 #undef DEF_TUNE
2068 };
2069
2070 /* Feature tests against the various tunings.  */
2071 unsigned char ix86_tune_features[X86_TUNE_LAST];
2072
2073 /* Feature tests against the various tunings used to create ix86_tune_features
2074    based on the processor mask.  */
2075 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
2076 #undef DEF_TUNE
2077 #define DEF_TUNE(tune, name, selector) selector,
2078 #include "x86-tune.def"
2079 #undef DEF_TUNE
2080 };
2081
2082 /* Feature tests against the various architecture variations.  */
2083 unsigned char ix86_arch_features[X86_ARCH_LAST];
2084
2085 /* Feature tests against the various architecture variations, used to create
2086    ix86_arch_features based on the processor mask.  */
2087 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
2088   /* X86_ARCH_CMOV: Conditional move was added for pentiumpro.  */
2089   ~(m_386 | m_486 | m_PENT | m_K6),
2090
2091   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
2092   ~m_386,
2093
2094   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
2095   ~(m_386 | m_486),
2096
2097   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
2098   ~m_386,
2099
2100   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
2101   ~m_386,
2102 };
2103
2104 /* In case the average insn count for single function invocation is
2105    lower than this constant, emit fast (but longer) prologue and
2106    epilogue code.  */
2107 #define FAST_PROLOGUE_INSN_COUNT 20
2108
2109 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
2110 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
2111 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
2112 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
2113
2114 /* Array of the smallest class containing reg number REGNO, indexed by
2115    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
2116
2117 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
2118 {
2119   /* ax, dx, cx, bx */
2120   AREG, DREG, CREG, BREG,
2121   /* si, di, bp, sp */
2122   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
2123   /* FP registers */
2124   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
2125   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
2126   /* arg pointer */
2127   NON_Q_REGS,
2128   /* flags, fpsr, fpcr, frame */
2129   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
2130   /* SSE registers */
2131   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
2132   SSE_REGS, SSE_REGS,
2133   /* MMX registers */
2134   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
2135   MMX_REGS, MMX_REGS,
2136   /* REX registers */
2137   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
2138   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
2139   /* SSE REX registers */
2140   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
2141   SSE_REGS, SSE_REGS,
2142   /* AVX-512 SSE registers */
2143   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2144   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2145   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2146   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2147   /* Mask registers.  */
2148   MASK_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS,
2149   MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS,
2150   /* MPX bound registers */
2151   BND_REGS, BND_REGS, BND_REGS, BND_REGS,
2152 };
2153
2154 /* The "default" register map used in 32bit mode.  */
2155
2156 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
2157 {
2158   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
2159   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
2160   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
2161   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
2162   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
2163   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
2164   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
2165   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 16-23*/
2166   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 24-31*/
2167   93, 94, 95, 96, 97, 98, 99, 100,      /* Mask registers */
2168   101, 102, 103, 104,                   /* bound registers */
2169 };
2170
2171 /* The "default" register map used in 64bit mode.  */
2172
2173 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
2174 {
2175   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
2176   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
2177   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
2178   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
2179   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
2180   8,9,10,11,12,13,14,15,                /* extended integer registers */
2181   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
2182   67, 68, 69, 70, 71, 72, 73, 74,       /* AVX-512 registers 16-23 */
2183   75, 76, 77, 78, 79, 80, 81, 82,       /* AVX-512 registers 24-31 */
2184   118, 119, 120, 121, 122, 123, 124, 125, /* Mask registers */
2185   126, 127, 128, 129,                   /* bound registers */
2186 };
2187
2188 /* Define the register numbers to be used in Dwarf debugging information.
2189    The SVR4 reference port C compiler uses the following register numbers
2190    in its Dwarf output code:
2191         0 for %eax (gcc regno = 0)
2192         1 for %ecx (gcc regno = 2)
2193         2 for %edx (gcc regno = 1)
2194         3 for %ebx (gcc regno = 3)
2195         4 for %esp (gcc regno = 7)
2196         5 for %ebp (gcc regno = 6)
2197         6 for %esi (gcc regno = 4)
2198         7 for %edi (gcc regno = 5)
2199    The following three DWARF register numbers are never generated by
2200    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
2201    believes these numbers have these meanings.
2202         8  for %eip    (no gcc equivalent)
2203         9  for %eflags (gcc regno = 17)
2204         10 for %trapno (no gcc equivalent)
2205    It is not at all clear how we should number the FP stack registers
2206    for the x86 architecture.  If the version of SDB on x86/svr4 were
2207    a bit less brain dead with respect to floating-point then we would
2208    have a precedent to follow with respect to DWARF register numbers
2209    for x86 FP registers, but the SDB on x86/svr4 is so completely
2210    broken with respect to FP registers that it is hardly worth thinking
2211    of it as something to strive for compatibility with.
2212    The version of x86/svr4 SDB I have at the moment does (partially)
2213    seem to believe that DWARF register number 11 is associated with
2214    the x86 register %st(0), but that's about all.  Higher DWARF
2215    register numbers don't seem to be associated with anything in
2216    particular, and even for DWARF regno 11, SDB only seems to under-
2217    stand that it should say that a variable lives in %st(0) (when
2218    asked via an `=' command) if we said it was in DWARF regno 11,
2219    but SDB still prints garbage when asked for the value of the
2220    variable in question (via a `/' command).
2221    (Also note that the labels SDB prints for various FP stack regs
2222    when doing an `x' command are all wrong.)
2223    Note that these problems generally don't affect the native SVR4
2224    C compiler because it doesn't allow the use of -O with -g and
2225    because when it is *not* optimizing, it allocates a memory
2226    location for each floating-point variable, and the memory
2227    location is what gets described in the DWARF AT_location
2228    attribute for the variable in question.
2229    Regardless of the severe mental illness of the x86/svr4 SDB, we
2230    do something sensible here and we use the following DWARF
2231    register numbers.  Note that these are all stack-top-relative
2232    numbers.
2233         11 for %st(0) (gcc regno = 8)
2234         12 for %st(1) (gcc regno = 9)
2235         13 for %st(2) (gcc regno = 10)
2236         14 for %st(3) (gcc regno = 11)
2237         15 for %st(4) (gcc regno = 12)
2238         16 for %st(5) (gcc regno = 13)
2239         17 for %st(6) (gcc regno = 14)
2240         18 for %st(7) (gcc regno = 15)
2241 */
2242 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
2243 {
2244   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
2245   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
2246   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
2247   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
2248   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
2249   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
2250   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
2251   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 16-23*/
2252   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 24-31*/
2253   93, 94, 95, 96, 97, 98, 99, 100,      /* Mask registers */
2254   101, 102, 103, 104,                   /* bound registers */
2255 };
2256
2257 /* Define parameter passing and return registers.  */
2258
2259 static int const x86_64_int_parameter_registers[6] =
2260 {
2261   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
2262 };
2263
2264 static int const x86_64_ms_abi_int_parameter_registers[4] =
2265 {
2266   CX_REG, DX_REG, R8_REG, R9_REG
2267 };
2268
2269 static int const x86_64_int_return_registers[4] =
2270 {
2271   AX_REG, DX_REG, DI_REG, SI_REG
2272 };
2273
2274 /* Additional registers that are clobbered by SYSV calls.  */
2275
2276 int const x86_64_ms_sysv_extra_clobbered_registers[12] =
2277 {
2278   SI_REG, DI_REG,
2279   XMM6_REG, XMM7_REG,
2280   XMM8_REG, XMM9_REG, XMM10_REG, XMM11_REG,
2281   XMM12_REG, XMM13_REG, XMM14_REG, XMM15_REG
2282 };
2283
2284 /* Define the structure for the machine field in struct function.  */
2285
2286 struct GTY(()) stack_local_entry {
2287   unsigned short mode;
2288   unsigned short n;
2289   rtx rtl;
2290   struct stack_local_entry *next;
2291 };
2292
2293 /* Structure describing stack frame layout.
2294    Stack grows downward:
2295
2296    [arguments]
2297                                         <- ARG_POINTER
2298    saved pc
2299
2300    saved static chain                   if ix86_static_chain_on_stack
2301
2302    saved frame pointer                  if frame_pointer_needed
2303                                         <- HARD_FRAME_POINTER
2304    [saved regs]
2305                                         <- regs_save_offset
2306    [padding0]
2307
2308    [saved SSE regs]
2309                                         <- sse_regs_save_offset
2310    [padding1]          |
2311                        |                <- FRAME_POINTER
2312    [va_arg registers]  |
2313                        |
2314    [frame]             |
2315                        |
2316    [padding2]          | = to_allocate
2317                                         <- STACK_POINTER
2318   */
2319 struct ix86_frame
2320 {
2321   int nsseregs;
2322   int nregs;
2323   int va_arg_size;
2324   int red_zone_size;
2325   int outgoing_arguments_size;
2326
2327   /* The offsets relative to ARG_POINTER.  */
2328   HOST_WIDE_INT frame_pointer_offset;
2329   HOST_WIDE_INT hard_frame_pointer_offset;
2330   HOST_WIDE_INT stack_pointer_offset;
2331   HOST_WIDE_INT hfp_save_offset;
2332   HOST_WIDE_INT reg_save_offset;
2333   HOST_WIDE_INT sse_reg_save_offset;
2334
2335   /* When save_regs_using_mov is set, emit prologue using
2336      move instead of push instructions.  */
2337   bool save_regs_using_mov;
2338 };
2339
2340 /* Which cpu are we scheduling for.  */
2341 enum attr_cpu ix86_schedule;
2342
2343 /* Which cpu are we optimizing for.  */
2344 enum processor_type ix86_tune;
2345
2346 /* Which instruction set architecture to use.  */
2347 enum processor_type ix86_arch;
2348
2349 /* True if processor has SSE prefetch instruction.  */
2350 unsigned char x86_prefetch_sse;
2351
2352 /* -mstackrealign option */
2353 static const char ix86_force_align_arg_pointer_string[]
2354   = "force_align_arg_pointer";
2355
2356 static rtx (*ix86_gen_leave) (void);
2357 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
2358 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
2359 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx, rtx);
2360 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
2361 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
2362 static rtx (*ix86_gen_monitorx) (rtx, rtx, rtx);
2363 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
2364 static rtx (*ix86_gen_allocate_stack_worker) (rtx, rtx);
2365 static rtx (*ix86_gen_adjust_stack_and_probe) (rtx, rtx, rtx);
2366 static rtx (*ix86_gen_probe_stack_range) (rtx, rtx, rtx);
2367 static rtx (*ix86_gen_tls_global_dynamic_64) (rtx, rtx, rtx);
2368 static rtx (*ix86_gen_tls_local_dynamic_base_64) (rtx, rtx);
2369
2370 /* Preferred alignment for stack boundary in bits.  */
2371 unsigned int ix86_preferred_stack_boundary;
2372
2373 /* Alignment for incoming stack boundary in bits specified at
2374    command line.  */
2375 static unsigned int ix86_user_incoming_stack_boundary;
2376
2377 /* Default alignment for incoming stack boundary in bits.  */
2378 static unsigned int ix86_default_incoming_stack_boundary;
2379
2380 /* Alignment for incoming stack boundary in bits.  */
2381 unsigned int ix86_incoming_stack_boundary;
2382
2383 /* Calling abi specific va_list type nodes.  */
2384 static GTY(()) tree sysv_va_list_type_node;
2385 static GTY(()) tree ms_va_list_type_node;
2386
2387 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
2388 char internal_label_prefix[16];
2389 int internal_label_prefix_len;
2390
2391 /* Fence to use after loop using movnt.  */
2392 tree x86_mfence;
2393
2394 /* Register class used for passing given 64bit part of the argument.
2395    These represent classes as documented by the PS ABI, with the exception
2396    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
2397    use SF or DFmode move instead of DImode to avoid reformatting penalties.
2398
2399    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
2400    whenever possible (upper half does contain padding).  */
2401 enum x86_64_reg_class
2402   {
2403     X86_64_NO_CLASS,
2404     X86_64_INTEGER_CLASS,
2405     X86_64_INTEGERSI_CLASS,
2406     X86_64_SSE_CLASS,
2407     X86_64_SSESF_CLASS,
2408     X86_64_SSEDF_CLASS,
2409     X86_64_SSEUP_CLASS,
2410     X86_64_X87_CLASS,
2411     X86_64_X87UP_CLASS,
2412     X86_64_COMPLEX_X87_CLASS,
2413     X86_64_MEMORY_CLASS
2414   };
2415
2416 #define MAX_CLASSES 8
2417
2418 /* Table of constants used by fldpi, fldln2, etc....  */
2419 static REAL_VALUE_TYPE ext_80387_constants_table [5];
2420 static bool ext_80387_constants_init = 0;
2421
2422 \f
2423 static struct machine_function * ix86_init_machine_status (void);
2424 static rtx ix86_function_value (const_tree, const_tree, bool);
2425 static bool ix86_function_value_regno_p (const unsigned int);
2426 static unsigned int ix86_function_arg_boundary (machine_mode,
2427                                                 const_tree);
2428 static rtx ix86_static_chain (const_tree, bool);
2429 static int ix86_function_regparm (const_tree, const_tree);
2430 static void ix86_compute_frame_layout (struct ix86_frame *);
2431 static bool ix86_expand_vector_init_one_nonzero (bool, machine_mode,
2432                                                  rtx, rtx, int);
2433 static void ix86_add_new_builtins (HOST_WIDE_INT);
2434 static tree ix86_canonical_va_list_type (tree);
2435 static void predict_jump (int);
2436 static unsigned int split_stack_prologue_scratch_regno (void);
2437 static bool i386_asm_output_addr_const_extra (FILE *, rtx);
2438
2439 enum ix86_function_specific_strings
2440 {
2441   IX86_FUNCTION_SPECIFIC_ARCH,
2442   IX86_FUNCTION_SPECIFIC_TUNE,
2443   IX86_FUNCTION_SPECIFIC_MAX
2444 };
2445
2446 static char *ix86_target_string (HOST_WIDE_INT, int, const char *,
2447                                  const char *, enum fpmath_unit, bool);
2448 static void ix86_function_specific_save (struct cl_target_option *,
2449                                          struct gcc_options *opts);
2450 static void ix86_function_specific_restore (struct gcc_options *opts,
2451                                             struct cl_target_option *);
2452 static void ix86_function_specific_post_stream_in (struct cl_target_option *);
2453 static void ix86_function_specific_print (FILE *, int,
2454                                           struct cl_target_option *);
2455 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
2456 static bool ix86_valid_target_attribute_inner_p (tree, char *[],
2457                                                  struct gcc_options *,
2458                                                  struct gcc_options *,
2459                                                  struct gcc_options *);
2460 static bool ix86_can_inline_p (tree, tree);
2461 static void ix86_set_current_function (tree);
2462 static unsigned int ix86_minimum_incoming_stack_boundary (bool);
2463
2464 static enum calling_abi ix86_function_abi (const_tree);
2465
2466 \f
2467 #ifndef SUBTARGET32_DEFAULT_CPU
2468 #define SUBTARGET32_DEFAULT_CPU "i386"
2469 #endif
2470
2471 /* Whether -mtune= or -march= were specified */
2472 static int ix86_tune_defaulted;
2473 static int ix86_arch_specified;
2474
2475 /* Vectorization library interface and handlers.  */
2476 static tree (*ix86_veclib_handler) (enum built_in_function, tree, tree);
2477
2478 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
2479 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
2480
2481 /* Processor target table, indexed by processor number */
2482 struct ptt
2483 {
2484   const char *const name;                       /* processor name  */
2485   const struct processor_costs *cost;           /* Processor costs */
2486   const int align_loop;                         /* Default alignments.  */
2487   const int align_loop_max_skip;
2488   const int align_jump;
2489   const int align_jump_max_skip;
2490   const int align_func;
2491 };
2492
2493 /* This table must be in sync with enum processor_type in i386.h.  */ 
2494 static const struct ptt processor_target_table[PROCESSOR_max] =
2495 {
2496   {"generic", &generic_cost, 16, 10, 16, 10, 16},
2497   {"i386", &i386_cost, 4, 3, 4, 3, 4},
2498   {"i486", &i486_cost, 16, 15, 16, 15, 16},
2499   {"pentium", &pentium_cost, 16, 7, 16, 7, 16},
2500   {"pentiumpro", &pentiumpro_cost, 16, 15, 16, 10, 16},
2501   {"pentium4", &pentium4_cost, 0, 0, 0, 0, 0},
2502   {"nocona", &nocona_cost, 0, 0, 0, 0, 0},
2503   {"core2", &core_cost, 16, 10, 16, 10, 16},
2504   {"nehalem", &core_cost, 16, 10, 16, 10, 16},
2505   {"sandybridge", &core_cost, 16, 10, 16, 10, 16},
2506   {"haswell", &core_cost, 16, 10, 16, 10, 16},
2507   {"bonnell", &atom_cost, 16, 15, 16, 7, 16},
2508   {"silvermont", &slm_cost, 16, 15, 16, 7, 16},
2509   {"knl", &slm_cost, 16, 15, 16, 7, 16},
2510   {"intel", &intel_cost, 16, 15, 16, 7, 16},
2511   {"geode", &geode_cost, 0, 0, 0, 0, 0},
2512   {"k6", &k6_cost, 32, 7, 32, 7, 32},
2513   {"athlon", &athlon_cost, 16, 7, 16, 7, 16},
2514   {"k8", &k8_cost, 16, 7, 16, 7, 16},
2515   {"amdfam10", &amdfam10_cost, 32, 24, 32, 7, 32},
2516   {"bdver1", &bdver1_cost, 16, 10, 16, 7, 11},
2517   {"bdver2", &bdver2_cost, 16, 10, 16, 7, 11},
2518   {"bdver3", &bdver3_cost, 16, 10, 16, 7, 11},
2519   {"bdver4", &bdver4_cost, 16, 10, 16, 7, 11},
2520   {"btver1", &btver1_cost, 16, 10, 16, 7, 11},
2521   {"btver2", &btver2_cost, 16, 10, 16, 7, 11}
2522 };
2523 \f
2524 static unsigned int
2525 rest_of_handle_insert_vzeroupper (void)
2526 {
2527   int i;
2528
2529   /* vzeroupper instructions are inserted immediately after reload to
2530      account for possible spills from 256bit registers.  The pass
2531      reuses mode switching infrastructure by re-running mode insertion
2532      pass, so disable entities that have already been processed.  */
2533   for (i = 0; i < MAX_386_ENTITIES; i++)
2534     ix86_optimize_mode_switching[i] = 0;
2535
2536   ix86_optimize_mode_switching[AVX_U128] = 1;
2537
2538   /* Call optimize_mode_switching.  */
2539   g->get_passes ()->execute_pass_mode_switching ();
2540   return 0;
2541 }
2542
2543 namespace {
2544
2545 const pass_data pass_data_insert_vzeroupper =
2546 {
2547   RTL_PASS, /* type */
2548   "vzeroupper", /* name */
2549   OPTGROUP_NONE, /* optinfo_flags */
2550   TV_NONE, /* tv_id */
2551   0, /* properties_required */
2552   0, /* properties_provided */
2553   0, /* properties_destroyed */
2554   0, /* todo_flags_start */
2555   TODO_df_finish, /* todo_flags_finish */
2556 };
2557
2558 class pass_insert_vzeroupper : public rtl_opt_pass
2559 {
2560 public:
2561   pass_insert_vzeroupper(gcc::context *ctxt)
2562     : rtl_opt_pass(pass_data_insert_vzeroupper, ctxt)
2563   {}
2564
2565   /* opt_pass methods: */
2566   virtual bool gate (function *)
2567     {
2568       return TARGET_AVX && !TARGET_AVX512F
2569              && TARGET_VZEROUPPER && flag_expensive_optimizations
2570              && !optimize_size;
2571     }
2572
2573   virtual unsigned int execute (function *)
2574     {
2575       return rest_of_handle_insert_vzeroupper ();
2576     }
2577
2578 }; // class pass_insert_vzeroupper
2579
2580 } // anon namespace
2581
2582 rtl_opt_pass *
2583 make_pass_insert_vzeroupper (gcc::context *ctxt)
2584 {
2585   return new pass_insert_vzeroupper (ctxt);
2586 }
2587
2588 /* Return true if a red-zone is in use.  */
2589
2590 static inline bool
2591 ix86_using_red_zone (void)
2592 {
2593   return TARGET_RED_ZONE && !TARGET_64BIT_MS_ABI;
2594 }
2595 \f
2596 /* Return a string that documents the current -m options.  The caller is
2597    responsible for freeing the string.  */
2598
2599 static char *
2600 ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch,
2601                     const char *tune, enum fpmath_unit fpmath,
2602                     bool add_nl_p)
2603 {
2604   struct ix86_target_opts
2605   {
2606     const char *option;         /* option string */
2607     HOST_WIDE_INT mask;         /* isa mask options */
2608   };
2609
2610   /* This table is ordered so that options like -msse4.2 that imply
2611      preceding options while match those first.  */
2612   static struct ix86_target_opts isa_opts[] =
2613   {
2614     { "-mfma4",         OPTION_MASK_ISA_FMA4 },
2615     { "-mfma",          OPTION_MASK_ISA_FMA },
2616     { "-mxop",          OPTION_MASK_ISA_XOP },
2617     { "-mlwp",          OPTION_MASK_ISA_LWP },
2618     { "-mavx512f",      OPTION_MASK_ISA_AVX512F },
2619     { "-mavx512er",     OPTION_MASK_ISA_AVX512ER },
2620     { "-mavx512cd",     OPTION_MASK_ISA_AVX512CD },
2621     { "-mavx512pf",     OPTION_MASK_ISA_AVX512PF },
2622     { "-mavx512dq",     OPTION_MASK_ISA_AVX512DQ },
2623     { "-mavx512bw",     OPTION_MASK_ISA_AVX512BW },
2624     { "-mavx512vl",     OPTION_MASK_ISA_AVX512VL },
2625     { "-mavx512ifma",   OPTION_MASK_ISA_AVX512IFMA },
2626     { "-mavx512vbmi",   OPTION_MASK_ISA_AVX512VBMI },
2627     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2628     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2629     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2630     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2631     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2632     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2633     { "-msse",          OPTION_MASK_ISA_SSE },
2634     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2635     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2636     { "-mmmx",          OPTION_MASK_ISA_MMX },
2637     { "-mabm",          OPTION_MASK_ISA_ABM },
2638     { "-mbmi",          OPTION_MASK_ISA_BMI },
2639     { "-mbmi2",         OPTION_MASK_ISA_BMI2 },
2640     { "-mlzcnt",        OPTION_MASK_ISA_LZCNT },
2641     { "-mhle",          OPTION_MASK_ISA_HLE },
2642     { "-mfxsr",         OPTION_MASK_ISA_FXSR },
2643     { "-mrdseed",       OPTION_MASK_ISA_RDSEED },
2644     { "-mprfchw",       OPTION_MASK_ISA_PRFCHW },
2645     { "-madx",          OPTION_MASK_ISA_ADX },
2646     { "-mtbm",          OPTION_MASK_ISA_TBM },
2647     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2648     { "-mmovbe",        OPTION_MASK_ISA_MOVBE },
2649     { "-mcrc32",        OPTION_MASK_ISA_CRC32 },
2650     { "-maes",          OPTION_MASK_ISA_AES },
2651     { "-msha",          OPTION_MASK_ISA_SHA },
2652     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2653     { "-mfsgsbase",     OPTION_MASK_ISA_FSGSBASE },
2654     { "-mrdrnd",        OPTION_MASK_ISA_RDRND },
2655     { "-mf16c",         OPTION_MASK_ISA_F16C },
2656     { "-mrtm",          OPTION_MASK_ISA_RTM },
2657     { "-mxsave",        OPTION_MASK_ISA_XSAVE },
2658     { "-mxsaveopt",     OPTION_MASK_ISA_XSAVEOPT },
2659     { "-mprefetchwt1",  OPTION_MASK_ISA_PREFETCHWT1 },
2660     { "-mclflushopt",   OPTION_MASK_ISA_CLFLUSHOPT },
2661     { "-mxsavec",       OPTION_MASK_ISA_XSAVEC },
2662     { "-mxsaves",       OPTION_MASK_ISA_XSAVES },
2663     { "-mmpx",          OPTION_MASK_ISA_MPX },
2664     { "-mclwb",         OPTION_MASK_ISA_CLWB },
2665     { "-mpcommit",      OPTION_MASK_ISA_PCOMMIT },
2666     { "-mmwaitx",       OPTION_MASK_ISA_MWAITX  },
2667   };
2668
2669   /* Flag options.  */
2670   static struct ix86_target_opts flag_opts[] =
2671   {
2672     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2673     { "-mlong-double-128",              MASK_LONG_DOUBLE_128 },
2674     { "-mlong-double-64",               MASK_LONG_DOUBLE_64 },
2675     { "-m80387",                        MASK_80387 },
2676     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2677     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2678     { "-mcld",                          MASK_CLD },
2679     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2680     { "-mieee-fp",                      MASK_IEEE_FP },
2681     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2682     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2683     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2684     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2685     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2686     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2687     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2688     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2689     { "-mrecip",                        MASK_RECIP },
2690     { "-mrtd",                          MASK_RTD },
2691     { "-msseregparm",                   MASK_SSEREGPARM },
2692     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2693     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2694     { "-mvect8-ret-in-mem",             MASK_VECT8_RETURNS },
2695     { "-m8bit-idiv",                    MASK_USE_8BIT_IDIV },
2696     { "-mvzeroupper",                   MASK_VZEROUPPER },
2697     { "-mavx256-split-unaligned-load",  MASK_AVX256_SPLIT_UNALIGNED_LOAD},
2698     { "-mavx256-split-unaligned-store", MASK_AVX256_SPLIT_UNALIGNED_STORE},
2699     { "-mprefer-avx128",                MASK_PREFER_AVX128},
2700   };
2701
2702   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (flag_opts) + 6][2];
2703
2704   char isa_other[40];
2705   char target_other[40];
2706   unsigned num = 0;
2707   unsigned i, j;
2708   char *ret;
2709   char *ptr;
2710   size_t len;
2711   size_t line_len;
2712   size_t sep_len;
2713   const char *abi;
2714
2715   memset (opts, '\0', sizeof (opts));
2716
2717   /* Add -march= option.  */
2718   if (arch)
2719     {
2720       opts[num][0] = "-march=";
2721       opts[num++][1] = arch;
2722     }
2723
2724   /* Add -mtune= option.  */
2725   if (tune)
2726     {
2727       opts[num][0] = "-mtune=";
2728       opts[num++][1] = tune;
2729     }
2730
2731   /* Add -m32/-m64/-mx32.  */
2732   if ((isa & OPTION_MASK_ISA_64BIT) != 0)
2733     {
2734       if ((isa & OPTION_MASK_ABI_64) != 0)
2735         abi = "-m64";
2736       else
2737         abi = "-mx32";
2738       isa &= ~ (OPTION_MASK_ISA_64BIT
2739                 | OPTION_MASK_ABI_64
2740                 | OPTION_MASK_ABI_X32);
2741     }
2742   else
2743     abi = "-m32";
2744   opts[num++][0] = abi;
2745
2746   /* Pick out the options in isa options.  */
2747   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
2748     {
2749       if ((isa & isa_opts[i].mask) != 0)
2750         {
2751           opts[num++][0] = isa_opts[i].option;
2752           isa &= ~ isa_opts[i].mask;
2753         }
2754     }
2755
2756   if (isa && add_nl_p)
2757     {
2758       opts[num++][0] = isa_other;
2759       sprintf (isa_other, "(other isa: %#" HOST_WIDE_INT_PRINT "x)",
2760                isa);
2761     }
2762
2763   /* Add flag options.  */
2764   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
2765     {
2766       if ((flags & flag_opts[i].mask) != 0)
2767         {
2768           opts[num++][0] = flag_opts[i].option;
2769           flags &= ~ flag_opts[i].mask;
2770         }
2771     }
2772
2773   if (flags && add_nl_p)
2774     {
2775       opts[num++][0] = target_other;
2776       sprintf (target_other, "(other flags: %#x)", flags);
2777     }
2778
2779   /* Add -fpmath= option.  */
2780   if (fpmath)
2781     {
2782       opts[num][0] = "-mfpmath=";
2783       switch ((int) fpmath)
2784         {
2785         case FPMATH_387:
2786           opts[num++][1] = "387";
2787           break;
2788
2789         case FPMATH_SSE:
2790           opts[num++][1] = "sse";
2791           break;
2792
2793         case FPMATH_387 | FPMATH_SSE:
2794           opts[num++][1] = "sse+387";
2795           break;
2796
2797         default:
2798           gcc_unreachable ();
2799         }
2800     }
2801
2802   /* Any options?  */
2803   if (num == 0)
2804     return NULL;
2805
2806   gcc_assert (num < ARRAY_SIZE (opts));
2807
2808   /* Size the string.  */
2809   len = 0;
2810   sep_len = (add_nl_p) ? 3 : 1;
2811   for (i = 0; i < num; i++)
2812     {
2813       len += sep_len;
2814       for (j = 0; j < 2; j++)
2815         if (opts[i][j])
2816           len += strlen (opts[i][j]);
2817     }
2818
2819   /* Build the string.  */
2820   ret = ptr = (char *) xmalloc (len);
2821   line_len = 0;
2822
2823   for (i = 0; i < num; i++)
2824     {
2825       size_t len2[2];
2826
2827       for (j = 0; j < 2; j++)
2828         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2829
2830       if (i != 0)
2831         {
2832           *ptr++ = ' ';
2833           line_len++;
2834
2835           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2836             {
2837               *ptr++ = '\\';
2838               *ptr++ = '\n';
2839               line_len = 0;
2840             }
2841         }
2842
2843       for (j = 0; j < 2; j++)
2844         if (opts[i][j])
2845           {
2846             memcpy (ptr, opts[i][j], len2[j]);
2847             ptr += len2[j];
2848             line_len += len2[j];
2849           }
2850     }
2851
2852   *ptr = '\0';
2853   gcc_assert (ret + len >= ptr);
2854
2855   return ret;
2856 }
2857
2858 /* Return true, if profiling code should be emitted before
2859    prologue. Otherwise it returns false.
2860    Note: For x86 with "hotfix" it is sorried.  */
2861 static bool
2862 ix86_profile_before_prologue (void)
2863 {
2864   return flag_fentry != 0;
2865 }
2866
2867 /* Function that is callable from the debugger to print the current
2868    options.  */
2869 void ATTRIBUTE_UNUSED
2870 ix86_debug_options (void)
2871 {
2872   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2873                                    ix86_arch_string, ix86_tune_string,
2874                                    ix86_fpmath, true);
2875
2876   if (opts)
2877     {
2878       fprintf (stderr, "%s\n\n", opts);
2879       free (opts);
2880     }
2881   else
2882     fputs ("<no options>\n\n", stderr);
2883
2884   return;
2885 }
2886
2887 static const char *stringop_alg_names[] = {
2888 #define DEF_ENUM
2889 #define DEF_ALG(alg, name) #name,
2890 #include "stringop.def"
2891 #undef DEF_ENUM
2892 #undef DEF_ALG
2893 };
2894
2895 /* Parse parameter string passed to -mmemcpy-strategy= or -mmemset-strategy=.
2896    The string is of the following form (or comma separated list of it):
2897
2898      strategy_alg:max_size:[align|noalign]
2899
2900    where the full size range for the strategy is either [0, max_size] or
2901    [min_size, max_size], in which min_size is the max_size + 1 of the
2902    preceding range.  The last size range must have max_size == -1.
2903
2904    Examples:
2905
2906     1.
2907        -mmemcpy-strategy=libcall:-1:noalign
2908
2909       this is equivalent to (for known size memcpy) -mstringop-strategy=libcall
2910
2911
2912    2.
2913       -mmemset-strategy=rep_8byte:16:noalign,vector_loop:2048:align,libcall:-1:noalign
2914
2915       This is to tell the compiler to use the following strategy for memset
2916       1) when the expected size is between [1, 16], use rep_8byte strategy;
2917       2) when the size is between [17, 2048], use vector_loop;
2918       3) when the size is > 2048, use libcall.  */
2919
2920 struct stringop_size_range
2921 {
2922   int max;
2923   stringop_alg alg;
2924   bool noalign;
2925 };
2926
2927 static void
2928 ix86_parse_stringop_strategy_string (char *strategy_str, bool is_memset)
2929 {
2930   const struct stringop_algs *default_algs;
2931   stringop_size_range input_ranges[MAX_STRINGOP_ALGS];
2932   char *curr_range_str, *next_range_str;
2933   int i = 0, n = 0;
2934
2935   if (is_memset)
2936     default_algs = &ix86_cost->memset[TARGET_64BIT != 0];
2937   else
2938     default_algs = &ix86_cost->memcpy[TARGET_64BIT != 0];
2939
2940   curr_range_str = strategy_str;
2941
2942   do
2943     {
2944       int maxs;
2945       char alg_name[128];
2946       char align[16];
2947       next_range_str = strchr (curr_range_str, ',');
2948       if (next_range_str)
2949         *next_range_str++ = '\0';
2950
2951       if (3 != sscanf (curr_range_str, "%20[^:]:%d:%10s",
2952                        alg_name, &maxs, align))
2953         {
2954           error ("wrong arg %s to option %s", curr_range_str,
2955                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2956           return;
2957         }
2958
2959       if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1))
2960         {
2961           error ("size ranges of option %s should be increasing",
2962                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2963           return;
2964         }
2965
2966       for (i = 0; i < last_alg; i++)
2967         if (!strcmp (alg_name, stringop_alg_names[i]))
2968           break;
2969
2970       if (i == last_alg)
2971         {
2972           error ("wrong stringop strategy name %s specified for option %s",
2973                  alg_name,
2974                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2975           return;
2976         }
2977
2978       if ((stringop_alg) i == rep_prefix_8_byte
2979           && !TARGET_64BIT)
2980         {
2981           /* rep; movq isn't available in 32-bit code.  */
2982           error ("stringop strategy name %s specified for option %s "
2983                  "not supported for 32-bit code",
2984                  alg_name,
2985                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2986           return;
2987         }
2988
2989       input_ranges[n].max = maxs;
2990       input_ranges[n].alg = (stringop_alg) i;
2991       if (!strcmp (align, "align"))
2992         input_ranges[n].noalign = false;
2993       else if (!strcmp (align, "noalign"))
2994         input_ranges[n].noalign = true;
2995       else
2996         {
2997           error ("unknown alignment %s specified for option %s",
2998                  align, is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2999           return;
3000         }
3001       n++;
3002       curr_range_str = next_range_str;
3003     }
3004   while (curr_range_str);
3005
3006   if (input_ranges[n - 1].max != -1)
3007     {
3008       error ("the max value for the last size range should be -1"
3009              " for option %s",
3010              is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3011       return;
3012     }
3013
3014   if (n > MAX_STRINGOP_ALGS)
3015     {
3016       error ("too many size ranges specified in option %s",
3017              is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3018       return;
3019     }
3020
3021   /* Now override the default algs array.  */
3022   for (i = 0; i < n; i++)
3023     {
3024       *const_cast<int *>(&default_algs->size[i].max) = input_ranges[i].max;
3025       *const_cast<stringop_alg *>(&default_algs->size[i].alg)
3026           = input_ranges[i].alg;
3027       *const_cast<int *>(&default_algs->size[i].noalign)
3028           = input_ranges[i].noalign;
3029     }
3030 }
3031
3032 \f
3033 /* parse -mtune-ctrl= option. When DUMP is true,
3034    print the features that are explicitly set.  */
3035
3036 static void
3037 parse_mtune_ctrl_str (bool dump)
3038 {
3039   if (!ix86_tune_ctrl_string)
3040     return;
3041
3042   char *next_feature_string = NULL;
3043   char *curr_feature_string = xstrdup (ix86_tune_ctrl_string);
3044   char *orig = curr_feature_string;
3045   int i;
3046   do
3047     {
3048       bool clear = false;
3049
3050       next_feature_string = strchr (curr_feature_string, ',');
3051       if (next_feature_string)
3052         *next_feature_string++ = '\0';
3053       if (*curr_feature_string == '^')
3054         {
3055           curr_feature_string++;
3056           clear = true;
3057         }
3058       for (i = 0; i < X86_TUNE_LAST; i++)
3059         {
3060           if (!strcmp (curr_feature_string, ix86_tune_feature_names[i]))
3061             {
3062               ix86_tune_features[i] = !clear;
3063               if (dump)
3064                 fprintf (stderr, "Explicitly %s feature %s\n",
3065                          clear ? "clear" : "set", ix86_tune_feature_names[i]);
3066               break;
3067             }
3068         }
3069       if (i == X86_TUNE_LAST)
3070         error ("Unknown parameter to option -mtune-ctrl: %s",
3071                clear ? curr_feature_string - 1 : curr_feature_string);
3072       curr_feature_string = next_feature_string;
3073     }
3074   while (curr_feature_string);
3075   free (orig);
3076 }
3077
3078 /* Helper function to set ix86_tune_features. IX86_TUNE is the
3079    processor type.  */
3080
3081 static void
3082 set_ix86_tune_features (enum processor_type ix86_tune, bool dump)
3083 {
3084   unsigned int ix86_tune_mask = 1u << ix86_tune;
3085   int i;
3086
3087   for (i = 0; i < X86_TUNE_LAST; ++i)
3088     {
3089       if (ix86_tune_no_default)
3090         ix86_tune_features[i] = 0;
3091       else
3092         ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3093     }
3094
3095   if (dump)
3096     {
3097       fprintf (stderr, "List of x86 specific tuning parameter names:\n");
3098       for (i = 0; i < X86_TUNE_LAST; i++)
3099         fprintf (stderr, "%s : %s\n", ix86_tune_feature_names[i],
3100                  ix86_tune_features[i] ? "on" : "off");
3101     }
3102
3103   parse_mtune_ctrl_str (dump);
3104 }
3105
3106
3107 /* Default align_* from the processor table.  */
3108
3109 static void
3110 ix86_default_align (struct gcc_options *opts)
3111 {
3112   if (opts->x_align_loops == 0)
3113     {
3114       opts->x_align_loops = processor_target_table[ix86_tune].align_loop;
3115       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
3116     }
3117   if (opts->x_align_jumps == 0)
3118     {
3119       opts->x_align_jumps = processor_target_table[ix86_tune].align_jump;
3120       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
3121     }
3122   if (opts->x_align_functions == 0)
3123     {
3124       opts->x_align_functions = processor_target_table[ix86_tune].align_func;
3125     }
3126 }
3127
3128 /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook.  */
3129
3130 static void
3131 ix86_override_options_after_change (void)
3132 {
3133   ix86_default_align (&global_options);
3134 }
3135
3136 /* Override various settings based on options.  If MAIN_ARGS_P, the
3137    options are from the command line, otherwise they are from
3138    attributes.  */
3139
3140 static void
3141 ix86_option_override_internal (bool main_args_p,
3142                                struct gcc_options *opts,
3143                                struct gcc_options *opts_set)
3144 {
3145   int i;
3146   unsigned int ix86_arch_mask;
3147   const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL);
3148   const char *prefix;
3149   const char *suffix;
3150   const char *sw;
3151
3152 #define PTA_3DNOW               (HOST_WIDE_INT_1 << 0)
3153 #define PTA_3DNOW_A             (HOST_WIDE_INT_1 << 1)
3154 #define PTA_64BIT               (HOST_WIDE_INT_1 << 2)
3155 #define PTA_ABM                 (HOST_WIDE_INT_1 << 3)
3156 #define PTA_AES                 (HOST_WIDE_INT_1 << 4)
3157 #define PTA_AVX                 (HOST_WIDE_INT_1 << 5)
3158 #define PTA_BMI                 (HOST_WIDE_INT_1 << 6)
3159 #define PTA_CX16                (HOST_WIDE_INT_1 << 7)
3160 #define PTA_F16C                (HOST_WIDE_INT_1 << 8)
3161 #define PTA_FMA                 (HOST_WIDE_INT_1 << 9)
3162 #define PTA_FMA4                (HOST_WIDE_INT_1 << 10)
3163 #define PTA_FSGSBASE            (HOST_WIDE_INT_1 << 11)
3164 #define PTA_LWP                 (HOST_WIDE_INT_1 << 12)
3165 #define PTA_LZCNT               (HOST_WIDE_INT_1 << 13)
3166 #define PTA_MMX                 (HOST_WIDE_INT_1 << 14)
3167 #define PTA_MOVBE               (HOST_WIDE_INT_1 << 15)
3168 #define PTA_NO_SAHF             (HOST_WIDE_INT_1 << 16)
3169 #define PTA_PCLMUL              (HOST_WIDE_INT_1 << 17)
3170 #define PTA_POPCNT              (HOST_WIDE_INT_1 << 18)
3171 #define PTA_PREFETCH_SSE        (HOST_WIDE_INT_1 << 19)
3172 #define PTA_RDRND               (HOST_WIDE_INT_1 << 20)
3173 #define PTA_SSE                 (HOST_WIDE_INT_1 << 21)
3174 #define PTA_SSE2                (HOST_WIDE_INT_1 << 22)
3175 #define PTA_SSE3                (HOST_WIDE_INT_1 << 23)
3176 #define PTA_SSE4_1              (HOST_WIDE_INT_1 << 24)
3177 #define PTA_SSE4_2              (HOST_WIDE_INT_1 << 25)
3178 #define PTA_SSE4A               (HOST_WIDE_INT_1 << 26)
3179 #define PTA_SSSE3               (HOST_WIDE_INT_1 << 27)
3180 #define PTA_TBM                 (HOST_WIDE_INT_1 << 28)
3181 #define PTA_XOP                 (HOST_WIDE_INT_1 << 29)
3182 #define PTA_AVX2                (HOST_WIDE_INT_1 << 30)
3183 #define PTA_BMI2                (HOST_WIDE_INT_1 << 31)
3184 #define PTA_RTM                 (HOST_WIDE_INT_1 << 32)
3185 #define PTA_HLE                 (HOST_WIDE_INT_1 << 33)
3186 #define PTA_PRFCHW              (HOST_WIDE_INT_1 << 34)
3187 #define PTA_RDSEED              (HOST_WIDE_INT_1 << 35)
3188 #define PTA_ADX                 (HOST_WIDE_INT_1 << 36)
3189 #define PTA_FXSR                (HOST_WIDE_INT_1 << 37)
3190 #define PTA_XSAVE               (HOST_WIDE_INT_1 << 38)
3191 #define PTA_XSAVEOPT            (HOST_WIDE_INT_1 << 39)
3192 #define PTA_AVX512F             (HOST_WIDE_INT_1 << 40)
3193 #define PTA_AVX512ER            (HOST_WIDE_INT_1 << 41)
3194 #define PTA_AVX512PF            (HOST_WIDE_INT_1 << 42)
3195 #define PTA_AVX512CD            (HOST_WIDE_INT_1 << 43)
3196 #define PTA_MPX                 (HOST_WIDE_INT_1 << 44)
3197 #define PTA_SHA                 (HOST_WIDE_INT_1 << 45)
3198 #define PTA_PREFETCHWT1         (HOST_WIDE_INT_1 << 46)
3199 #define PTA_CLFLUSHOPT          (HOST_WIDE_INT_1 << 47)
3200 #define PTA_XSAVEC              (HOST_WIDE_INT_1 << 48)
3201 #define PTA_XSAVES              (HOST_WIDE_INT_1 << 49)
3202 #define PTA_AVX512DQ            (HOST_WIDE_INT_1 << 50)
3203 #define PTA_AVX512BW            (HOST_WIDE_INT_1 << 51)
3204 #define PTA_AVX512VL            (HOST_WIDE_INT_1 << 52)
3205 #define PTA_AVX512IFMA          (HOST_WIDE_INT_1 << 53)
3206 #define PTA_AVX512VBMI          (HOST_WIDE_INT_1 << 54)
3207 #define PTA_CLWB                (HOST_WIDE_INT_1 << 55)
3208 #define PTA_PCOMMIT             (HOST_WIDE_INT_1 << 56)
3209 #define PTA_MWAITX              (HOST_WIDE_INT_1 << 57)
3210
3211 #define PTA_CORE2 \
3212   (PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_SSSE3 \
3213    | PTA_CX16 | PTA_FXSR)
3214 #define PTA_NEHALEM \
3215   (PTA_CORE2 | PTA_SSE4_1 | PTA_SSE4_2 | PTA_POPCNT)
3216 #define PTA_WESTMERE \
3217   (PTA_NEHALEM | PTA_AES | PTA_PCLMUL)
3218 #define PTA_SANDYBRIDGE \
3219   (PTA_WESTMERE | PTA_AVX | PTA_XSAVE | PTA_XSAVEOPT)
3220 #define PTA_IVYBRIDGE \
3221   (PTA_SANDYBRIDGE | PTA_FSGSBASE | PTA_RDRND | PTA_F16C)
3222 #define PTA_HASWELL \
3223   (PTA_IVYBRIDGE | PTA_AVX2 | PTA_BMI | PTA_BMI2 | PTA_LZCNT \
3224    | PTA_FMA | PTA_MOVBE | PTA_HLE)
3225 #define PTA_BROADWELL \
3226   (PTA_HASWELL | PTA_ADX | PTA_PRFCHW | PTA_RDSEED)
3227 #define PTA_KNL \
3228   (PTA_BROADWELL | PTA_AVX512PF | PTA_AVX512ER | PTA_AVX512F | PTA_AVX512CD)
3229 #define PTA_BONNELL \
3230   (PTA_CORE2 | PTA_MOVBE)
3231 #define PTA_SILVERMONT \
3232   (PTA_WESTMERE | PTA_MOVBE)
3233
3234 /* if this reaches 64, need to widen struct pta flags below */
3235
3236   static struct pta
3237     {
3238       const char *const name;           /* processor name or nickname.  */
3239       const enum processor_type processor;
3240       const enum attr_cpu schedule;
3241       const unsigned HOST_WIDE_INT flags;
3242     }
3243   const processor_alias_table[] =
3244     {
3245       {"i386", PROCESSOR_I386, CPU_NONE, 0},
3246       {"i486", PROCESSOR_I486, CPU_NONE, 0},
3247       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
3248       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
3249       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
3250       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
3251       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3252       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3253       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3254         PTA_MMX | PTA_SSE | PTA_FXSR},
3255       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
3256       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
3257       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_FXSR},
3258       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3259         PTA_MMX | PTA_SSE | PTA_FXSR},
3260       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3261         PTA_MMX | PTA_SSE | PTA_FXSR},
3262       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3263         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_FXSR},
3264       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
3265         PTA_MMX |PTA_SSE | PTA_SSE2 | PTA_FXSR},
3266       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
3267         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_FXSR},
3268       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
3269         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_FXSR},
3270       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
3271         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3272         | PTA_CX16 | PTA_NO_SAHF | PTA_FXSR},
3273       {"core2", PROCESSOR_CORE2, CPU_CORE2, PTA_CORE2},
3274       {"nehalem", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_NEHALEM},
3275       {"corei7", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_NEHALEM},
3276       {"westmere", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_WESTMERE},
3277       {"sandybridge", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3278         PTA_SANDYBRIDGE},
3279       {"corei7-avx", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3280         PTA_SANDYBRIDGE},
3281       {"ivybridge", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3282         PTA_IVYBRIDGE},
3283       {"core-avx-i", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3284         PTA_IVYBRIDGE},
3285       {"haswell", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_HASWELL},
3286       {"core-avx2", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_HASWELL},
3287       {"broadwell", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_BROADWELL},
3288       {"bonnell", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL},
3289       {"atom", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL},
3290       {"silvermont", PROCESSOR_SILVERMONT, CPU_SLM, PTA_SILVERMONT},
3291       {"slm", PROCESSOR_SILVERMONT, CPU_SLM, PTA_SILVERMONT},
3292       {"knl", PROCESSOR_KNL, CPU_KNL, PTA_KNL},
3293       {"intel", PROCESSOR_INTEL, CPU_SLM, PTA_NEHALEM},
3294       {"geode", PROCESSOR_GEODE, CPU_GEODE,
3295         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3296       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
3297       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3298       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3299       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
3300         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3301       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
3302         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3303       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
3304         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3305       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
3306         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3307       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
3308         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3309       {"x86-64", PROCESSOR_K8, CPU_K8,
3310         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF | PTA_FXSR},
3311       {"k8", PROCESSOR_K8, CPU_K8,
3312         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3313         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3314       {"k8-sse3", PROCESSOR_K8, CPU_K8,
3315         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3316         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3317       {"opteron", PROCESSOR_K8, CPU_K8,
3318         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3319         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3320       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
3321         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3322         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3323       {"athlon64", PROCESSOR_K8, CPU_K8,
3324         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3325         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3326       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
3327         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3328         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3329       {"athlon-fx", PROCESSOR_K8, CPU_K8,
3330         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3331         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3332       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
3333         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_SSE2
3334         | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_PRFCHW | PTA_FXSR},
3335       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
3336         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_SSE2
3337         | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_PRFCHW | PTA_FXSR},
3338       {"bdver1", PROCESSOR_BDVER1, CPU_BDVER1,
3339         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3340         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3341         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3342         | PTA_XOP | PTA_LWP | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE},
3343       {"bdver2", PROCESSOR_BDVER2, CPU_BDVER2,
3344         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3345         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3346         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3347         | PTA_XOP | PTA_LWP | PTA_BMI | PTA_TBM | PTA_F16C
3348         | PTA_FMA | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE},
3349       {"bdver3", PROCESSOR_BDVER3, CPU_BDVER3,
3350         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3351         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3352         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3353         | PTA_XOP | PTA_LWP | PTA_BMI | PTA_TBM | PTA_F16C
3354         | PTA_FMA | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE 
3355         | PTA_XSAVEOPT | PTA_FSGSBASE},
3356      {"bdver4", PROCESSOR_BDVER4, CPU_BDVER4,
3357         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3358         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3359         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_AVX2 
3360         | PTA_FMA4 | PTA_XOP | PTA_LWP | PTA_BMI | PTA_BMI2 
3361         | PTA_TBM | PTA_F16C | PTA_FMA | PTA_PRFCHW | PTA_FXSR 
3362         | PTA_XSAVE | PTA_XSAVEOPT | PTA_FSGSBASE | PTA_RDRND
3363         | PTA_MOVBE | PTA_MWAITX},
3364       {"btver1", PROCESSOR_BTVER1, CPU_GENERIC,
3365         PTA_64BIT | PTA_MMX |  PTA_SSE  | PTA_SSE2 | PTA_SSE3
3366         | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16 | PTA_PRFCHW
3367         | PTA_FXSR | PTA_XSAVE},
3368       {"btver2", PROCESSOR_BTVER2, CPU_BTVER2,
3369         PTA_64BIT | PTA_MMX |  PTA_SSE  | PTA_SSE2 | PTA_SSE3
3370         | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16 | PTA_SSE4_1
3371         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX
3372         | PTA_BMI | PTA_F16C | PTA_MOVBE | PTA_PRFCHW
3373         | PTA_FXSR | PTA_XSAVE | PTA_XSAVEOPT},
3374
3375       {"generic", PROCESSOR_GENERIC, CPU_GENERIC,
3376         PTA_64BIT
3377         | PTA_HLE /* flags are only used for -march switch.  */ },
3378     };
3379
3380   /* -mrecip options.  */
3381   static struct
3382     {
3383       const char *string;           /* option name */
3384       unsigned int mask;            /* mask bits to set */
3385     }
3386   const recip_options[] =
3387     {
3388       { "all",       RECIP_MASK_ALL },
3389       { "none",      RECIP_MASK_NONE },
3390       { "div",       RECIP_MASK_DIV },
3391       { "sqrt",      RECIP_MASK_SQRT },
3392       { "vec-div",   RECIP_MASK_VEC_DIV },
3393       { "vec-sqrt",  RECIP_MASK_VEC_SQRT },
3394     };
3395
3396   int const pta_size = ARRAY_SIZE (processor_alias_table);
3397
3398   /* Set up prefix/suffix so the error messages refer to either the command
3399      line argument, or the attribute(target).  */
3400   if (main_args_p)
3401     {
3402       prefix = "-m";
3403       suffix = "";
3404       sw = "switch";
3405     }
3406   else
3407     {
3408       prefix = "option(\"";
3409       suffix = "\")";
3410       sw = "attribute";
3411     }
3412
3413   /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if
3414      TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false.  */
3415   if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
3416     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
3417 #ifdef TARGET_BI_ARCH
3418   else
3419     {
3420 #if TARGET_BI_ARCH == 1
3421       /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
3422          is on and OPTION_MASK_ABI_X32 is off.  We turn off
3423          OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
3424          -mx32.  */
3425       if (TARGET_X32_P (opts->x_ix86_isa_flags))
3426         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
3427 #else
3428       /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
3429          on and OPTION_MASK_ABI_64 is off.  We turn off
3430          OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
3431          -m64 or OPTION_MASK_CODE16 is turned on by -m16.  */
3432       if (TARGET_LP64_P (opts->x_ix86_isa_flags)
3433           || TARGET_16BIT_P (opts->x_ix86_isa_flags))
3434         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
3435 #endif
3436     }
3437 #endif
3438
3439   if (TARGET_X32_P (opts->x_ix86_isa_flags))
3440     {
3441       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
3442          OPTION_MASK_ABI_64 for TARGET_X32.  */
3443       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
3444       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
3445     }
3446   else if (TARGET_16BIT_P (opts->x_ix86_isa_flags))
3447     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ISA_64BIT
3448                                 | OPTION_MASK_ABI_X32
3449                                 | OPTION_MASK_ABI_64);
3450   else if (TARGET_LP64_P (opts->x_ix86_isa_flags))
3451     {
3452       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
3453          OPTION_MASK_ABI_X32 for TARGET_LP64.  */
3454       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
3455       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
3456     }
3457
3458 #ifdef SUBTARGET_OVERRIDE_OPTIONS
3459   SUBTARGET_OVERRIDE_OPTIONS;
3460 #endif
3461
3462 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
3463   SUBSUBTARGET_OVERRIDE_OPTIONS;
3464 #endif
3465
3466   /* -fPIC is the default for x86_64.  */
3467   if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags))
3468     opts->x_flag_pic = 2;
3469
3470   /* Need to check -mtune=generic first.  */
3471   if (opts->x_ix86_tune_string)
3472     {
3473       /* As special support for cross compilers we read -mtune=native
3474              as -mtune=generic.  With native compilers we won't see the
3475              -mtune=native, as it was changed by the driver.  */
3476       if (!strcmp (opts->x_ix86_tune_string, "native"))
3477         {
3478           opts->x_ix86_tune_string = "generic";
3479         }
3480       else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
3481         warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated; use "
3482                  "%stune=k8%s or %stune=generic%s instead as appropriate",
3483                  prefix, suffix, prefix, suffix, prefix, suffix);
3484     }
3485   else
3486     {
3487       if (opts->x_ix86_arch_string)
3488         opts->x_ix86_tune_string = opts->x_ix86_arch_string;
3489       if (!opts->x_ix86_tune_string)
3490         {
3491           opts->x_ix86_tune_string
3492             = processor_target_table[TARGET_CPU_DEFAULT].name;
3493           ix86_tune_defaulted = 1;
3494         }
3495
3496       /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
3497          or defaulted.  We need to use a sensible tune option.  */
3498       if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
3499         {
3500           opts->x_ix86_tune_string = "generic";
3501         }
3502     }
3503
3504   if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
3505       && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
3506     {
3507       /* rep; movq isn't available in 32-bit code.  */
3508       error ("-mstringop-strategy=rep_8byte not supported for 32-bit code");
3509       opts->x_ix86_stringop_alg = no_stringop;
3510     }
3511
3512   if (!opts->x_ix86_arch_string)
3513     opts->x_ix86_arch_string
3514       = TARGET_64BIT_P (opts->x_ix86_isa_flags)
3515         ? "x86-64" : SUBTARGET32_DEFAULT_CPU;
3516   else
3517     ix86_arch_specified = 1;
3518
3519   if (opts_set->x_ix86_pmode)
3520     {
3521       if ((TARGET_LP64_P (opts->x_ix86_isa_flags)
3522            && opts->x_ix86_pmode == PMODE_SI)
3523           || (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
3524                && opts->x_ix86_pmode == PMODE_DI))
3525         error ("address mode %qs not supported in the %s bit mode",
3526                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "short" : "long",
3527                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "64" : "32");
3528     }
3529   else
3530     opts->x_ix86_pmode = TARGET_LP64_P (opts->x_ix86_isa_flags)
3531                          ? PMODE_DI : PMODE_SI;
3532
3533   if (!opts_set->x_ix86_abi)
3534     opts->x_ix86_abi = DEFAULT_ABI;
3535
3536   /* For targets using ms ABI enable ms-extensions, if not
3537      explicit turned off.  For non-ms ABI we turn off this
3538      option.  */
3539   if (!opts_set->x_flag_ms_extensions)
3540     opts->x_flag_ms_extensions = (MS_ABI == DEFAULT_ABI);
3541
3542   if (opts_set->x_ix86_cmodel)
3543     {
3544       switch (opts->x_ix86_cmodel)
3545         {
3546         case CM_SMALL:
3547         case CM_SMALL_PIC:
3548           if (opts->x_flag_pic)
3549             opts->x_ix86_cmodel = CM_SMALL_PIC;
3550           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3551             error ("code model %qs not supported in the %s bit mode",
3552                    "small", "32");
3553           break;
3554
3555         case CM_MEDIUM:
3556         case CM_MEDIUM_PIC:
3557           if (opts->x_flag_pic)
3558             opts->x_ix86_cmodel = CM_MEDIUM_PIC;
3559           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3560             error ("code model %qs not supported in the %s bit mode",
3561                    "medium", "32");
3562           else if (TARGET_X32_P (opts->x_ix86_isa_flags))
3563             error ("code model %qs not supported in x32 mode",
3564                    "medium");
3565           break;
3566
3567         case CM_LARGE:
3568         case CM_LARGE_PIC:
3569           if (opts->x_flag_pic)
3570             opts->x_ix86_cmodel = CM_LARGE_PIC;
3571           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3572             error ("code model %qs not supported in the %s bit mode",
3573                    "large", "32");
3574           else if (TARGET_X32_P (opts->x_ix86_isa_flags))
3575             error ("code model %qs not supported in x32 mode",
3576                    "large");
3577           break;
3578
3579         case CM_32:
3580           if (opts->x_flag_pic)
3581             error ("code model %s does not support PIC mode", "32");
3582           if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3583             error ("code model %qs not supported in the %s bit mode",
3584                    "32", "64");
3585           break;
3586
3587         case CM_KERNEL:
3588           if (opts->x_flag_pic)
3589             {
3590               error ("code model %s does not support PIC mode", "kernel");
3591               opts->x_ix86_cmodel = CM_32;
3592             }
3593           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3594             error ("code model %qs not supported in the %s bit mode",
3595                    "kernel", "32");
3596           break;
3597
3598         default:
3599           gcc_unreachable ();
3600         }
3601     }
3602   else
3603     {
3604       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
3605          use of rip-relative addressing.  This eliminates fixups that
3606          would otherwise be needed if this object is to be placed in a
3607          DLL, and is essentially just as efficient as direct addressing.  */
3608       if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3609           && (TARGET_RDOS || TARGET_PECOFF))
3610         opts->x_ix86_cmodel = CM_MEDIUM_PIC, opts->x_flag_pic = 1;
3611       else if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3612         opts->x_ix86_cmodel = opts->x_flag_pic ? CM_SMALL_PIC : CM_SMALL;
3613       else
3614         opts->x_ix86_cmodel = CM_32;
3615     }
3616   if (TARGET_MACHO && opts->x_ix86_asm_dialect == ASM_INTEL)
3617     {
3618       error ("-masm=intel not supported in this configuration");
3619       opts->x_ix86_asm_dialect = ASM_ATT;
3620     }
3621   if ((TARGET_64BIT_P (opts->x_ix86_isa_flags) != 0)
3622       != ((opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
3623     sorry ("%i-bit mode not compiled in",
3624            (opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
3625
3626   for (i = 0; i < pta_size; i++)
3627     if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name))
3628       {
3629         ix86_schedule = processor_alias_table[i].schedule;
3630         ix86_arch = processor_alias_table[i].processor;
3631         /* Default cpu tuning to the architecture.  */
3632         ix86_tune = ix86_arch;
3633
3634         if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3635             && !(processor_alias_table[i].flags & PTA_64BIT))
3636           error ("CPU you selected does not support x86-64 "
3637                  "instruction set");
3638
3639         if (processor_alias_table[i].flags & PTA_MMX
3640             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
3641           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MMX;
3642         if (processor_alias_table[i].flags & PTA_3DNOW
3643             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
3644           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
3645         if (processor_alias_table[i].flags & PTA_3DNOW_A
3646             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
3647           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
3648         if (processor_alias_table[i].flags & PTA_SSE
3649             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
3650           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE;
3651         if (processor_alias_table[i].flags & PTA_SSE2
3652             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
3653           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
3654         if (processor_alias_table[i].flags & PTA_SSE3
3655             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
3656           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
3657         if (processor_alias_table[i].flags & PTA_SSSE3
3658             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
3659           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
3660         if (processor_alias_table[i].flags & PTA_SSE4_1
3661             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
3662           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
3663         if (processor_alias_table[i].flags & PTA_SSE4_2
3664             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
3665           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
3666         if (processor_alias_table[i].flags & PTA_AVX
3667             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
3668           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX;
3669         if (processor_alias_table[i].flags & PTA_AVX2
3670             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX2))
3671           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX2;
3672         if (processor_alias_table[i].flags & PTA_FMA
3673             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
3674           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA;
3675         if (processor_alias_table[i].flags & PTA_SSE4A
3676             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
3677           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
3678         if (processor_alias_table[i].flags & PTA_FMA4
3679             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA4))
3680           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA4;
3681         if (processor_alias_table[i].flags & PTA_XOP
3682             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XOP))
3683           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XOP;
3684         if (processor_alias_table[i].flags & PTA_LWP
3685             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LWP))
3686           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LWP;
3687         if (processor_alias_table[i].flags & PTA_ABM
3688             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
3689           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ABM;
3690         if (processor_alias_table[i].flags & PTA_BMI
3691             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_BMI))
3692           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_BMI;
3693         if (processor_alias_table[i].flags & (PTA_LZCNT | PTA_ABM)
3694             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LZCNT))
3695           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LZCNT;
3696         if (processor_alias_table[i].flags & PTA_TBM
3697             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_TBM))
3698           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_TBM;
3699         if (processor_alias_table[i].flags & PTA_BMI2
3700             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_BMI2))
3701           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_BMI2;
3702         if (processor_alias_table[i].flags & PTA_CX16
3703             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
3704           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CX16;
3705         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
3706             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
3707           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
3708         if (!(TARGET_64BIT_P (opts->x_ix86_isa_flags)
3709             && (processor_alias_table[i].flags & PTA_NO_SAHF))
3710             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
3711           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
3712         if (processor_alias_table[i].flags & PTA_MOVBE
3713             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MOVBE))
3714           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MOVBE;
3715         if (processor_alias_table[i].flags & PTA_AES
3716             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
3717           ix86_isa_flags |= OPTION_MASK_ISA_AES;
3718         if (processor_alias_table[i].flags & PTA_SHA
3719             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SHA))
3720           ix86_isa_flags |= OPTION_MASK_ISA_SHA;
3721         if (processor_alias_table[i].flags & PTA_PCLMUL
3722             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
3723           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
3724         if (processor_alias_table[i].flags & PTA_FSGSBASE
3725             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FSGSBASE))
3726           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FSGSBASE;
3727         if (processor_alias_table[i].flags & PTA_RDRND
3728             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RDRND))
3729           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RDRND;
3730         if (processor_alias_table[i].flags & PTA_F16C
3731             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_F16C))
3732           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_F16C;
3733         if (processor_alias_table[i].flags & PTA_RTM
3734             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RTM))
3735           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RTM;
3736         if (processor_alias_table[i].flags & PTA_HLE
3737             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_HLE))
3738           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_HLE;
3739         if (processor_alias_table[i].flags & PTA_PRFCHW
3740             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PRFCHW))
3741           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PRFCHW;
3742         if (processor_alias_table[i].flags & PTA_RDSEED
3743             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RDSEED))
3744           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RDSEED;
3745         if (processor_alias_table[i].flags & PTA_ADX
3746             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ADX))
3747           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ADX;
3748         if (processor_alias_table[i].flags & PTA_FXSR
3749             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FXSR))
3750           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FXSR;
3751         if (processor_alias_table[i].flags & PTA_XSAVE
3752             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVE))
3753           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVE;
3754         if (processor_alias_table[i].flags & PTA_XSAVEOPT
3755             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVEOPT))
3756           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVEOPT;
3757         if (processor_alias_table[i].flags & PTA_AVX512F
3758             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512F))
3759           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512F;
3760         if (processor_alias_table[i].flags & PTA_AVX512ER
3761             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512ER))
3762           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512ER;
3763         if (processor_alias_table[i].flags & PTA_AVX512PF
3764             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512PF))
3765           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512PF;
3766         if (processor_alias_table[i].flags & PTA_AVX512CD
3767             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512CD))
3768           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512CD;
3769         if (processor_alias_table[i].flags & PTA_PREFETCHWT1
3770             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PREFETCHWT1))
3771           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PREFETCHWT1;
3772         if (processor_alias_table[i].flags & PTA_PCOMMIT
3773             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PCOMMIT))
3774           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCOMMIT;
3775         if (processor_alias_table[i].flags & PTA_CLWB
3776             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CLWB))
3777           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CLWB;
3778         if (processor_alias_table[i].flags & PTA_CLFLUSHOPT
3779             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CLFLUSHOPT))
3780           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CLFLUSHOPT;
3781         if (processor_alias_table[i].flags & PTA_XSAVEC
3782             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVEC))
3783           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVEC;
3784         if (processor_alias_table[i].flags & PTA_XSAVES
3785             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVES))
3786           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVES;
3787         if (processor_alias_table[i].flags & PTA_AVX512DQ
3788             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512DQ))
3789           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512DQ;
3790         if (processor_alias_table[i].flags & PTA_AVX512BW
3791             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512BW))
3792           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512BW;
3793         if (processor_alias_table[i].flags & PTA_AVX512VL
3794             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512VL))
3795           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512VL;
3796         if (processor_alias_table[i].flags & PTA_MPX
3797             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MPX))
3798           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MPX;
3799         if (processor_alias_table[i].flags & PTA_AVX512VBMI
3800             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512VBMI))
3801           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512VBMI;
3802         if (processor_alias_table[i].flags & PTA_AVX512IFMA
3803             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512IFMA))
3804           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512IFMA;
3805         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
3806           x86_prefetch_sse = true;
3807         if (processor_alias_table[i].flags & PTA_MWAITX
3808             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MWAITX))
3809           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MWAITX;
3810
3811         break;
3812       }
3813
3814   if (TARGET_X32 && (opts->x_ix86_isa_flags & OPTION_MASK_ISA_MPX))
3815     error ("Intel MPX does not support x32");
3816
3817   if (TARGET_X32 && (ix86_isa_flags & OPTION_MASK_ISA_MPX))
3818     error ("Intel MPX does not support x32");
3819
3820   if (!strcmp (opts->x_ix86_arch_string, "generic"))
3821     error ("generic CPU can be used only for %stune=%s %s",
3822            prefix, suffix, sw);
3823   else if (!strcmp (opts->x_ix86_arch_string, "intel"))
3824     error ("intel CPU can be used only for %stune=%s %s",
3825            prefix, suffix, sw);
3826   else if (i == pta_size)
3827     error ("bad value (%s) for %sarch=%s %s",
3828            opts->x_ix86_arch_string, prefix, suffix, sw);
3829
3830   ix86_arch_mask = 1u << ix86_arch;
3831   for (i = 0; i < X86_ARCH_LAST; ++i)
3832     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3833
3834   for (i = 0; i < pta_size; i++)
3835     if (! strcmp (opts->x_ix86_tune_string, processor_alias_table[i].name))
3836       {
3837         ix86_schedule = processor_alias_table[i].schedule;
3838         ix86_tune = processor_alias_table[i].processor;
3839         if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3840           {
3841             if (!(processor_alias_table[i].flags & PTA_64BIT))
3842               {
3843                 if (ix86_tune_defaulted)
3844                   {
3845                     opts->x_ix86_tune_string = "x86-64";
3846                     for (i = 0; i < pta_size; i++)
3847                       if (! strcmp (opts->x_ix86_tune_string,
3848                                     processor_alias_table[i].name))
3849                         break;
3850                     ix86_schedule = processor_alias_table[i].schedule;
3851                     ix86_tune = processor_alias_table[i].processor;
3852                   }
3853                 else
3854                   error ("CPU you selected does not support x86-64 "
3855                          "instruction set");
3856               }
3857           }
3858         /* Intel CPUs have always interpreted SSE prefetch instructions as
3859            NOPs; so, we can enable SSE prefetch instructions even when
3860            -mtune (rather than -march) points us to a processor that has them.
3861            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
3862            higher processors.  */
3863         if (TARGET_CMOV
3864             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
3865           x86_prefetch_sse = true;
3866         break;
3867       }
3868
3869   if (ix86_tune_specified && i == pta_size)
3870     error ("bad value (%s) for %stune=%s %s",
3871            opts->x_ix86_tune_string, prefix, suffix, sw);
3872
3873   set_ix86_tune_features (ix86_tune, opts->x_ix86_dump_tunes);
3874
3875 #ifndef USE_IX86_FRAME_POINTER
3876 #define USE_IX86_FRAME_POINTER 0
3877 #endif
3878
3879 #ifndef USE_X86_64_FRAME_POINTER
3880 #define USE_X86_64_FRAME_POINTER 0
3881 #endif
3882
3883   /* Set the default values for switches whose default depends on TARGET_64BIT
3884      in case they weren't overwritten by command line options.  */
3885   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3886     {
3887       if (opts->x_optimize >= 1 && !opts_set->x_flag_omit_frame_pointer)
3888         opts->x_flag_omit_frame_pointer = !USE_X86_64_FRAME_POINTER;
3889       if (opts->x_flag_asynchronous_unwind_tables
3890           && !opts_set->x_flag_unwind_tables
3891           && TARGET_64BIT_MS_ABI)
3892         opts->x_flag_unwind_tables = 1;
3893       if (opts->x_flag_asynchronous_unwind_tables == 2)
3894         opts->x_flag_unwind_tables
3895           = opts->x_flag_asynchronous_unwind_tables = 1;
3896       if (opts->x_flag_pcc_struct_return == 2)
3897         opts->x_flag_pcc_struct_return = 0;
3898     }
3899   else
3900     {
3901       if (opts->x_optimize >= 1 && !opts_set->x_flag_omit_frame_pointer)
3902         opts->x_flag_omit_frame_pointer
3903           = !(USE_IX86_FRAME_POINTER || opts->x_optimize_size);
3904       if (opts->x_flag_asynchronous_unwind_tables == 2)
3905         opts->x_flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
3906       if (opts->x_flag_pcc_struct_return == 2)
3907         opts->x_flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
3908     }
3909
3910   ix86_tune_cost = processor_target_table[ix86_tune].cost;
3911   /* TODO: ix86_cost should be chosen at instruction or function granuality
3912      so for cold code we use size_cost even in !optimize_size compilation.  */
3913   if (opts->x_optimize_size)
3914     ix86_cost = &ix86_size_cost;
3915   else
3916     ix86_cost = ix86_tune_cost;
3917
3918   /* Arrange to set up i386_stack_locals for all functions.  */
3919   init_machine_status = ix86_init_machine_status;
3920
3921   /* Validate -mregparm= value.  */
3922   if (opts_set->x_ix86_regparm)
3923     {
3924       if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3925         warning (0, "-mregparm is ignored in 64-bit mode");
3926       if (opts->x_ix86_regparm > REGPARM_MAX)
3927         {
3928           error ("-mregparm=%d is not between 0 and %d",
3929                  opts->x_ix86_regparm, REGPARM_MAX);
3930           opts->x_ix86_regparm = 0;
3931         }
3932     }
3933   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3934     opts->x_ix86_regparm = REGPARM_MAX;
3935
3936   /* Default align_* from the processor table.  */
3937   ix86_default_align (opts);
3938
3939   /* Provide default for -mbranch-cost= value.  */
3940   if (!opts_set->x_ix86_branch_cost)
3941     opts->x_ix86_branch_cost = ix86_tune_cost->branch_cost;
3942
3943   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3944     {
3945       opts->x_target_flags
3946         |= TARGET_SUBTARGET64_DEFAULT & ~opts_set->x_target_flags;
3947
3948       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3949          explicitly disable any of these.  In particular, disabling SSE and
3950          MMX for kernel code is extremely useful.  */
3951       if (!ix86_arch_specified)
3952       opts->x_ix86_isa_flags
3953         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3954              | TARGET_SUBTARGET64_ISA_DEFAULT)
3955             & ~opts->x_ix86_isa_flags_explicit);
3956
3957       if (TARGET_RTD_P (opts->x_target_flags))
3958         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3959     }
3960   else
3961     {
3962       opts->x_target_flags
3963         |= TARGET_SUBTARGET32_DEFAULT & ~opts_set->x_target_flags;
3964
3965       if (!ix86_arch_specified)
3966         opts->x_ix86_isa_flags
3967           |= TARGET_SUBTARGET32_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit;
3968
3969       /* i386 ABI does not specify red zone.  It still makes sense to use it
3970          when programmer takes care to stack from being destroyed.  */
3971       if (!(opts_set->x_target_flags & MASK_NO_RED_ZONE))
3972         opts->x_target_flags |= MASK_NO_RED_ZONE;
3973     }
3974
3975   /* Keep nonleaf frame pointers.  */
3976   if (opts->x_flag_omit_frame_pointer)
3977     opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3978   else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags))
3979     opts->x_flag_omit_frame_pointer = 1;
3980
3981   /* If we're doing fast math, we don't care about comparison order
3982      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3983   if (opts->x_flag_finite_math_only)
3984     opts->x_target_flags &= ~MASK_IEEE_FP;
3985
3986   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3987      since the insns won't need emulation.  */
3988   if (ix86_tune_features [X86_TUNE_ALWAYS_FANCY_MATH_387])
3989     opts->x_target_flags &= ~MASK_NO_FANCY_MATH_387;
3990
3991   /* Likewise, if the target doesn't have a 387, or we've specified
3992      software floating point, don't use 387 inline intrinsics.  */
3993   if (!TARGET_80387_P (opts->x_target_flags))
3994     opts->x_target_flags |= MASK_NO_FANCY_MATH_387;
3995
3996   /* Turn on MMX builtins for -msse.  */
3997   if (TARGET_SSE_P (opts->x_ix86_isa_flags))
3998     opts->x_ix86_isa_flags
3999       |= OPTION_MASK_ISA_MMX & ~opts->x_ix86_isa_flags_explicit;
4000
4001   /* Enable SSE prefetch.  */
4002   if (TARGET_SSE_P (opts->x_ix86_isa_flags)
4003       || (TARGET_PRFCHW && !TARGET_3DNOW_P (opts->x_ix86_isa_flags)))
4004     x86_prefetch_sse = true;
4005
4006   /* Enable prefetch{,w} instructions for -m3dnow and -mprefetchwt1.  */
4007   if (TARGET_3DNOW_P (opts->x_ix86_isa_flags)
4008       || TARGET_PREFETCHWT1_P (opts->x_ix86_isa_flags))
4009     opts->x_ix86_isa_flags
4010       |= OPTION_MASK_ISA_PRFCHW & ~opts->x_ix86_isa_flags_explicit;
4011
4012   /* Enable popcnt instruction for -msse4.2 or -mabm.  */
4013   if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags)
4014       || TARGET_ABM_P (opts->x_ix86_isa_flags))
4015     opts->x_ix86_isa_flags
4016       |= OPTION_MASK_ISA_POPCNT & ~opts->x_ix86_isa_flags_explicit;
4017
4018   /* Enable lzcnt instruction for -mabm.  */
4019   if (TARGET_ABM_P(opts->x_ix86_isa_flags))
4020     opts->x_ix86_isa_flags
4021       |= OPTION_MASK_ISA_LZCNT & ~opts->x_ix86_isa_flags_explicit;
4022
4023   /* Validate -mpreferred-stack-boundary= value or default it to
4024      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
4025   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
4026   if (opts_set->x_ix86_preferred_stack_boundary_arg)
4027     {
4028       int min = (TARGET_64BIT_P (opts->x_ix86_isa_flags)
4029                  ? (TARGET_SSE_P (opts->x_ix86_isa_flags) ? 4 : 3) : 2);
4030       int max = (TARGET_SEH ? 4 : 12);
4031
4032       if (opts->x_ix86_preferred_stack_boundary_arg < min
4033           || opts->x_ix86_preferred_stack_boundary_arg > max)
4034         {
4035           if (min == max)
4036             error ("-mpreferred-stack-boundary is not supported "
4037                    "for this target");
4038           else
4039             error ("-mpreferred-stack-boundary=%d is not between %d and %d",
4040                    opts->x_ix86_preferred_stack_boundary_arg, min, max);
4041         }
4042       else
4043         ix86_preferred_stack_boundary
4044           = (1 << opts->x_ix86_preferred_stack_boundary_arg) * BITS_PER_UNIT;
4045     }
4046
4047   /* Set the default value for -mstackrealign.  */
4048   if (opts->x_ix86_force_align_arg_pointer == -1)
4049     opts->x_ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
4050
4051   ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
4052
4053   /* Validate -mincoming-stack-boundary= value or default it to
4054      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
4055   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
4056   if (opts_set->x_ix86_incoming_stack_boundary_arg)
4057     {
4058       if (opts->x_ix86_incoming_stack_boundary_arg
4059           < (TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 4 : 2)
4060           || opts->x_ix86_incoming_stack_boundary_arg > 12)
4061         error ("-mincoming-stack-boundary=%d is not between %d and 12",
4062                opts->x_ix86_incoming_stack_boundary_arg,
4063                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 4 : 2);
4064       else
4065         {
4066           ix86_user_incoming_stack_boundary
4067             = (1 << opts->x_ix86_incoming_stack_boundary_arg) * BITS_PER_UNIT;
4068           ix86_incoming_stack_boundary
4069             = ix86_user_incoming_stack_boundary;
4070         }
4071     }
4072
4073 #ifndef NO_PROFILE_COUNTERS
4074   if (flag_nop_mcount)
4075     error ("-mnop-mcount is not compatible with this target");
4076 #endif
4077   if (flag_nop_mcount && flag_pic)
4078     error ("-mnop-mcount is not implemented for -fPIC");
4079
4080   /* Accept -msseregparm only if at least SSE support is enabled.  */
4081   if (TARGET_SSEREGPARM_P (opts->x_target_flags)
4082       && ! TARGET_SSE_P (opts->x_ix86_isa_flags))
4083     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
4084
4085   if (opts_set->x_ix86_fpmath)
4086     {
4087       if (opts->x_ix86_fpmath & FPMATH_SSE)
4088         {
4089           if (!TARGET_SSE_P (opts->x_ix86_isa_flags))
4090             {
4091               warning (0, "SSE instruction set disabled, using 387 arithmetics");
4092               opts->x_ix86_fpmath = FPMATH_387;
4093             }
4094           else if ((opts->x_ix86_fpmath & FPMATH_387)
4095                    && !TARGET_80387_P (opts->x_target_flags))
4096             {
4097               warning (0, "387 instruction set disabled, using SSE arithmetics");
4098               opts->x_ix86_fpmath = FPMATH_SSE;
4099             }
4100         }
4101     }
4102   /* For all chips supporting SSE2, -mfpmath=sse performs better than
4103      fpmath=387.  The second is however default at many targets since the
4104      extra 80bit precision of temporaries is considered to be part of ABI.
4105      Overwrite the default at least for -ffast-math. 
4106      TODO: -mfpmath=both seems to produce same performing code with bit
4107      smaller binaries.  It is however not clear if register allocation is
4108      ready for this setting.
4109      Also -mfpmath=387 is overall a lot more compact (bout 4-5%) than SSE
4110      codegen.  We may switch to 387 with -ffast-math for size optimized
4111      functions. */
4112   else if (fast_math_flags_set_p (&global_options)
4113            && TARGET_SSE2_P (opts->x_ix86_isa_flags))
4114     opts->x_ix86_fpmath = FPMATH_SSE;
4115   else
4116     opts->x_ix86_fpmath = TARGET_FPMATH_DEFAULT_P (opts->x_ix86_isa_flags);
4117
4118   /* If the i387 is disabled, then do not return values in it. */
4119   if (!TARGET_80387_P (opts->x_target_flags))
4120     opts->x_target_flags &= ~MASK_FLOAT_RETURNS;
4121
4122   /* Use external vectorized library in vectorizing intrinsics.  */
4123   if (opts_set->x_ix86_veclibabi_type)
4124     switch (opts->x_ix86_veclibabi_type)
4125       {
4126       case ix86_veclibabi_type_svml:
4127         ix86_veclib_handler = ix86_veclibabi_svml;
4128         break;
4129
4130       case ix86_veclibabi_type_acml:
4131         ix86_veclib_handler = ix86_veclibabi_acml;
4132         break;
4133
4134       default:
4135         gcc_unreachable ();
4136       }
4137
4138   if (ix86_tune_features [X86_TUNE_ACCUMULATE_OUTGOING_ARGS]
4139       && !(opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
4140     opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
4141
4142   /* If stack probes are required, the space used for large function
4143      arguments on the stack must also be probed, so enable
4144      -maccumulate-outgoing-args so this happens in the prologue.  */
4145   if (TARGET_STACK_PROBE_P (opts->x_target_flags)
4146       && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
4147     {
4148       if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)
4149         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
4150                  "for correctness", prefix, suffix);
4151       opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
4152     }
4153
4154   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
4155   {
4156     char *p;
4157     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
4158     p = strchr (internal_label_prefix, 'X');
4159     internal_label_prefix_len = p - internal_label_prefix;
4160     *p = '\0';
4161   }
4162
4163   /* When scheduling description is not available, disable scheduler pass
4164      so it won't slow down the compilation and make x87 code slower.  */
4165   if (!TARGET_SCHEDULE)
4166     opts->x_flag_schedule_insns_after_reload = opts->x_flag_schedule_insns = 0;
4167
4168   maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
4169                          ix86_tune_cost->simultaneous_prefetches,
4170                          opts->x_param_values,
4171                          opts_set->x_param_values);
4172   maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
4173                          ix86_tune_cost->prefetch_block,
4174                          opts->x_param_values,
4175                          opts_set->x_param_values);
4176   maybe_set_param_value (PARAM_L1_CACHE_SIZE,
4177                          ix86_tune_cost->l1_cache_size,
4178                          opts->x_param_values,
4179                          opts_set->x_param_values);
4180   maybe_set_param_value (PARAM_L2_CACHE_SIZE,
4181                          ix86_tune_cost->l2_cache_size,
4182                          opts->x_param_values,
4183                          opts_set->x_param_values);
4184
4185   /* Enable sw prefetching at -O3 for CPUS that prefetching is helpful.  */
4186   if (opts->x_flag_prefetch_loop_arrays < 0
4187       && HAVE_prefetch
4188       && (opts->x_optimize >= 3 || opts->x_flag_profile_use)
4189       && !opts->x_optimize_size
4190       && TARGET_SOFTWARE_PREFETCHING_BENEFICIAL)
4191     opts->x_flag_prefetch_loop_arrays = 1;
4192
4193   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
4194      can be opts->x_optimized to ap = __builtin_next_arg (0).  */
4195   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && !opts->x_flag_split_stack)
4196     targetm.expand_builtin_va_start = NULL;
4197
4198   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
4199     {
4200       ix86_gen_leave = gen_leave_rex64;
4201       if (Pmode == DImode)
4202         {
4203           ix86_gen_tls_global_dynamic_64 = gen_tls_global_dynamic_64_di;
4204           ix86_gen_tls_local_dynamic_base_64
4205             = gen_tls_local_dynamic_base_64_di;
4206         }
4207       else
4208         {
4209           ix86_gen_tls_global_dynamic_64 = gen_tls_global_dynamic_64_si;
4210           ix86_gen_tls_local_dynamic_base_64
4211             = gen_tls_local_dynamic_base_64_si;
4212         }
4213     }
4214   else
4215     ix86_gen_leave = gen_leave;
4216
4217   if (Pmode == DImode)
4218     {
4219       ix86_gen_add3 = gen_adddi3;
4220       ix86_gen_sub3 = gen_subdi3;
4221       ix86_gen_sub3_carry = gen_subdi3_carry;
4222       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
4223       ix86_gen_andsp = gen_anddi3;
4224       ix86_gen_allocate_stack_worker = gen_allocate_stack_worker_probe_di;
4225       ix86_gen_adjust_stack_and_probe = gen_adjust_stack_and_probedi;
4226       ix86_gen_probe_stack_range = gen_probe_stack_rangedi;
4227       ix86_gen_monitor = gen_sse3_monitor_di;
4228       ix86_gen_monitorx = gen_monitorx_di;
4229     }
4230   else
4231     {
4232       ix86_gen_add3 = gen_addsi3;
4233       ix86_gen_sub3 = gen_subsi3;
4234       ix86_gen_sub3_carry = gen_subsi3_carry;
4235       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
4236       ix86_gen_andsp = gen_andsi3;
4237       ix86_gen_allocate_stack_worker = gen_allocate_stack_worker_probe_si;
4238       ix86_gen_adjust_stack_and_probe = gen_adjust_stack_and_probesi;
4239       ix86_gen_probe_stack_range = gen_probe_stack_rangesi;
4240       ix86_gen_monitor = gen_sse3_monitor_si;
4241       ix86_gen_monitorx = gen_monitorx_si;
4242     }
4243
4244 #ifdef USE_IX86_CLD
4245   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
4246   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
4247     opts->x_target_flags |= MASK_CLD & ~opts_set->x_target_flags;
4248 #endif
4249
4250   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && opts->x_flag_pic)
4251     {
4252       if (opts->x_flag_fentry > 0)
4253         sorry ("-mfentry isn%'t supported for 32-bit in combination "
4254                "with -fpic");
4255       opts->x_flag_fentry = 0;
4256     }
4257   else if (TARGET_SEH)
4258     {
4259       if (opts->x_flag_fentry == 0)
4260         sorry ("-mno-fentry isn%'t compatible with SEH");
4261       opts->x_flag_fentry = 1;
4262     }
4263   else if (opts->x_flag_fentry < 0)
4264    {
4265 #if defined(PROFILE_BEFORE_PROLOGUE)
4266      opts->x_flag_fentry = 1;
4267 #else
4268      opts->x_flag_fentry = 0;
4269 #endif
4270    }
4271
4272   if (!(opts_set->x_target_flags & MASK_VZEROUPPER))
4273     opts->x_target_flags |= MASK_VZEROUPPER;
4274   if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL]
4275       && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_LOAD))
4276     opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_LOAD;
4277   if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL]
4278       && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_STORE))
4279     opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_STORE;
4280   /* Enable 128-bit AVX instruction generation
4281      for the auto-vectorizer.  */
4282   if (TARGET_AVX128_OPTIMAL
4283       && !(opts_set->x_target_flags & MASK_PREFER_AVX128))
4284     opts->x_target_flags |= MASK_PREFER_AVX128;
4285
4286   if (opts->x_ix86_recip_name)
4287     {
4288       char *p = ASTRDUP (opts->x_ix86_recip_name);
4289       char *q;
4290       unsigned int mask, i;
4291       bool invert;
4292
4293       while ((q = strtok (p, ",")) != NULL)
4294         {
4295           p = NULL;
4296           if (*q == '!')
4297             {
4298               invert = true;
4299               q++;
4300             }
4301           else
4302             invert = false;
4303
4304           if (!strcmp (q, "default"))
4305             mask = RECIP_MASK_ALL;
4306           else
4307             {
4308               for (i = 0; i < ARRAY_SIZE (recip_options); i++)
4309                 if (!strcmp (q, recip_options[i].string))
4310                   {
4311                     mask = recip_options[i].mask;
4312                     break;
4313                   }
4314
4315               if (i == ARRAY_SIZE (recip_options))
4316                 {
4317                   error ("unknown option for -mrecip=%s", q);
4318                   invert = false;
4319                   mask = RECIP_MASK_NONE;
4320                 }
4321             }
4322
4323           opts->x_recip_mask_explicit |= mask;
4324           if (invert)
4325             opts->x_recip_mask &= ~mask;
4326           else
4327             opts->x_recip_mask |= mask;
4328         }
4329     }
4330
4331   if (TARGET_RECIP_P (opts->x_target_flags))
4332     opts->x_recip_mask |= RECIP_MASK_ALL & ~opts->x_recip_mask_explicit;
4333   else if (opts_set->x_target_flags & MASK_RECIP)
4334     opts->x_recip_mask &= ~(RECIP_MASK_ALL & ~opts->x_recip_mask_explicit);
4335
4336   /* Default long double to 64-bit for 32-bit Bionic and to __float128
4337      for 64-bit Bionic.  */
4338   if (TARGET_HAS_BIONIC
4339       && !(opts_set->x_target_flags
4340            & (MASK_LONG_DOUBLE_64 | MASK_LONG_DOUBLE_128)))
4341     opts->x_target_flags |= (TARGET_64BIT
4342                              ? MASK_LONG_DOUBLE_128
4343                              : MASK_LONG_DOUBLE_64);
4344
4345   /* Only one of them can be active.  */
4346   gcc_assert ((opts->x_target_flags & MASK_LONG_DOUBLE_64) == 0
4347               || (opts->x_target_flags & MASK_LONG_DOUBLE_128) == 0);
4348
4349   /* Save the initial options in case the user does function specific
4350      options.  */
4351   if (main_args_p)
4352     target_option_default_node = target_option_current_node
4353       = build_target_option_node (opts);
4354
4355   /* Handle stack protector */
4356   if (!opts_set->x_ix86_stack_protector_guard)
4357     opts->x_ix86_stack_protector_guard
4358       = TARGET_HAS_BIONIC ? SSP_GLOBAL : SSP_TLS;
4359
4360   /* Handle -mmemcpy-strategy= and -mmemset-strategy=  */
4361   if (opts->x_ix86_tune_memcpy_strategy)
4362     {
4363       char *str = xstrdup (opts->x_ix86_tune_memcpy_strategy);
4364       ix86_parse_stringop_strategy_string (str, false);
4365       free (str);
4366     }
4367
4368   if (opts->x_ix86_tune_memset_strategy)
4369     {
4370       char *str = xstrdup (opts->x_ix86_tune_memset_strategy);
4371       ix86_parse_stringop_strategy_string (str, true);
4372       free (str);
4373     }
4374 }
4375
4376 /* Implement the TARGET_OPTION_OVERRIDE hook.  */
4377
4378 static void
4379 ix86_option_override (void)
4380 {
4381   opt_pass *pass_insert_vzeroupper = make_pass_insert_vzeroupper (g);
4382   struct register_pass_info insert_vzeroupper_info
4383     = { pass_insert_vzeroupper, "reload",
4384         1, PASS_POS_INSERT_AFTER
4385       };
4386
4387   ix86_option_override_internal (true, &global_options, &global_options_set);
4388
4389
4390   /* This needs to be done at start up.  It's convenient to do it here.  */
4391   register_pass (&insert_vzeroupper_info);
4392 }
4393
4394 /* Implement the TARGET_OFFLOAD_OPTIONS hook.  */
4395 static char *
4396 ix86_offload_options (void)
4397 {
4398   if (TARGET_LP64)
4399     return xstrdup ("-foffload-abi=lp64");
4400   return xstrdup ("-foffload-abi=ilp32");
4401 }
4402
4403 /* Update register usage after having seen the compiler flags.  */
4404
4405 static void
4406 ix86_conditional_register_usage (void)
4407 {
4408   int i, c_mask;
4409
4410   /* For 32-bit targets, squash the REX registers.  */
4411   if (! TARGET_64BIT)
4412     {
4413       for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
4414         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4415       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
4416         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4417       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
4418         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4419     }
4420
4421   /*  See the definition of CALL_USED_REGISTERS in i386.h.  */
4422   c_mask = (TARGET_64BIT_MS_ABI ? (1 << 3)
4423             : TARGET_64BIT ? (1 << 2)
4424             : (1 << 1));
4425   
4426   CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
4427
4428   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4429     {
4430       /* Set/reset conditionally defined registers from
4431          CALL_USED_REGISTERS initializer.  */
4432       if (call_used_regs[i] > 1)
4433         call_used_regs[i] = !!(call_used_regs[i] & c_mask);
4434
4435       /* Calculate registers of CLOBBERED_REGS register set
4436          as call used registers from GENERAL_REGS register set.  */
4437       if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
4438           && call_used_regs[i])
4439         SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
4440     }
4441
4442   /* If MMX is disabled, squash the registers.  */
4443   if (! TARGET_MMX)
4444     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4445       if (TEST_HARD_REG_BIT (reg_class_contents[(int)MMX_REGS], i))
4446         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4447
4448   /* If SSE is disabled, squash the registers.  */
4449   if (! TARGET_SSE)
4450     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4451       if (TEST_HARD_REG_BIT (reg_class_contents[(int)SSE_REGS], i))
4452         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4453
4454   /* If the FPU is disabled, squash the registers.  */
4455   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
4456     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4457       if (TEST_HARD_REG_BIT (reg_class_contents[(int)FLOAT_REGS], i))
4458         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4459
4460   /* If AVX512F is disabled, squash the registers.  */
4461   if (! TARGET_AVX512F)
4462     {
4463       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
4464         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4465
4466       for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
4467         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4468     }
4469
4470   /* If MPX is disabled, squash the registers.  */
4471   if (! TARGET_MPX)
4472     for (i = FIRST_BND_REG; i <= LAST_BND_REG; i++)
4473       fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4474 }
4475
4476 \f
4477 /* Save the current options */
4478
4479 static void
4480 ix86_function_specific_save (struct cl_target_option *ptr,
4481                              struct gcc_options *opts)
4482 {
4483   ptr->arch = ix86_arch;
4484   ptr->schedule = ix86_schedule;
4485   ptr->prefetch_sse = x86_prefetch_sse;
4486   ptr->tune = ix86_tune;
4487   ptr->branch_cost = ix86_branch_cost;
4488   ptr->tune_defaulted = ix86_tune_defaulted;
4489   ptr->arch_specified = ix86_arch_specified;
4490   ptr->x_ix86_isa_flags_explicit = opts->x_ix86_isa_flags_explicit;
4491   ptr->x_ix86_target_flags_explicit = opts->x_ix86_target_flags_explicit;
4492   ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit;
4493   ptr->x_ix86_arch_string = opts->x_ix86_arch_string;
4494   ptr->x_ix86_tune_string = opts->x_ix86_tune_string;
4495   ptr->x_ix86_cmodel = opts->x_ix86_cmodel;
4496   ptr->x_ix86_abi = opts->x_ix86_abi;
4497   ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect;
4498   ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost;
4499   ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes;
4500   ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer;
4501   ptr->x_ix86_force_drap = opts->x_ix86_force_drap;
4502   ptr->x_ix86_incoming_stack_boundary_arg = opts->x_ix86_incoming_stack_boundary_arg;
4503   ptr->x_ix86_pmode = opts->x_ix86_pmode;
4504   ptr->x_ix86_preferred_stack_boundary_arg = opts->x_ix86_preferred_stack_boundary_arg;
4505   ptr->x_ix86_recip_name = opts->x_ix86_recip_name;
4506   ptr->x_ix86_regparm = opts->x_ix86_regparm;
4507   ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold;
4508   ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx;
4509   ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard;
4510   ptr->x_ix86_stringop_alg = opts->x_ix86_stringop_alg;
4511   ptr->x_ix86_tls_dialect = opts->x_ix86_tls_dialect;
4512   ptr->x_ix86_tune_ctrl_string = opts->x_ix86_tune_ctrl_string;
4513   ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy;
4514   ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy;
4515   ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default;
4516   ptr->x_ix86_veclibabi_type = opts->x_ix86_veclibabi_type;
4517
4518   /* The fields are char but the variables are not; make sure the
4519      values fit in the fields.  */
4520   gcc_assert (ptr->arch == ix86_arch);
4521   gcc_assert (ptr->schedule == ix86_schedule);
4522   gcc_assert (ptr->tune == ix86_tune);
4523   gcc_assert (ptr->branch_cost == ix86_branch_cost);
4524 }
4525
4526 /* Restore the current options */
4527
4528 static void
4529 ix86_function_specific_restore (struct gcc_options *opts,
4530                                 struct cl_target_option *ptr)
4531 {
4532   enum processor_type old_tune = ix86_tune;
4533   enum processor_type old_arch = ix86_arch;
4534   unsigned int ix86_arch_mask;
4535   int i;
4536
4537   /* We don't change -fPIC.  */
4538   opts->x_flag_pic = flag_pic;
4539
4540   ix86_arch = (enum processor_type) ptr->arch;
4541   ix86_schedule = (enum attr_cpu) ptr->schedule;
4542   ix86_tune = (enum processor_type) ptr->tune;
4543   x86_prefetch_sse = ptr->prefetch_sse;
4544   opts->x_ix86_branch_cost = ptr->branch_cost;
4545   ix86_tune_defaulted = ptr->tune_defaulted;
4546   ix86_arch_specified = ptr->arch_specified;
4547   opts->x_ix86_isa_flags_explicit = ptr->x_ix86_isa_flags_explicit;
4548   opts->x_ix86_target_flags_explicit = ptr->x_ix86_target_flags_explicit;
4549   opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit;
4550   opts->x_ix86_arch_string = ptr->x_ix86_arch_string;
4551   opts->x_ix86_tune_string = ptr->x_ix86_tune_string;
4552   opts->x_ix86_cmodel = ptr->x_ix86_cmodel;
4553   opts->x_ix86_abi = ptr->x_ix86_abi;
4554   opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect;
4555   opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost;
4556   opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes;
4557   opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer;
4558   opts->x_ix86_force_drap = ptr->x_ix86_force_drap;
4559   opts->x_ix86_incoming_stack_boundary_arg = ptr->x_ix86_incoming_stack_boundary_arg;
4560   opts->x_ix86_pmode = ptr->x_ix86_pmode;
4561   opts->x_ix86_preferred_stack_boundary_arg = ptr->x_ix86_preferred_stack_boundary_arg;
4562   opts->x_ix86_recip_name = ptr->x_ix86_recip_name;
4563   opts->x_ix86_regparm = ptr->x_ix86_regparm;
4564   opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold;
4565   opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx;
4566   opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard;
4567   opts->x_ix86_stringop_alg = ptr->x_ix86_stringop_alg;
4568   opts->x_ix86_tls_dialect = ptr->x_ix86_tls_dialect;
4569   opts->x_ix86_tune_ctrl_string = ptr->x_ix86_tune_ctrl_string;
4570   opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy;
4571   opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy;
4572   opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default;
4573   opts->x_ix86_veclibabi_type = ptr->x_ix86_veclibabi_type;
4574   ix86_tune_cost = processor_target_table[ix86_tune].cost;
4575   /* TODO: ix86_cost should be chosen at instruction or function granuality
4576      so for cold code we use size_cost even in !optimize_size compilation.  */
4577   if (opts->x_optimize_size)
4578     ix86_cost = &ix86_size_cost;
4579   else
4580     ix86_cost = ix86_tune_cost;
4581
4582   /* Recreate the arch feature tests if the arch changed */
4583   if (old_arch != ix86_arch)
4584     {
4585       ix86_arch_mask = 1u << ix86_arch;
4586       for (i = 0; i < X86_ARCH_LAST; ++i)
4587         ix86_arch_features[i]
4588           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
4589     }
4590
4591   /* Recreate the tune optimization tests */
4592   if (old_tune != ix86_tune)
4593     set_ix86_tune_features (ix86_tune, false);
4594 }
4595
4596 /* Adjust target options after streaming them in.  This is mainly about
4597    reconciling them with global options.  */
4598
4599 static void
4600 ix86_function_specific_post_stream_in (struct cl_target_option *ptr)
4601 {
4602   /* flag_pic is a global option, but ix86_cmodel is target saved option
4603      partly computed from flag_pic.  If flag_pic is on, adjust x_ix86_cmodel
4604      for PIC, or error out.  */
4605   if (flag_pic)
4606     switch (ptr->x_ix86_cmodel)
4607       {
4608       case CM_SMALL:
4609         ptr->x_ix86_cmodel = CM_SMALL_PIC;
4610         break;
4611
4612       case CM_MEDIUM:
4613         ptr->x_ix86_cmodel = CM_MEDIUM_PIC;
4614         break;
4615
4616       case CM_LARGE:
4617         ptr->x_ix86_cmodel = CM_LARGE_PIC;
4618         break;
4619
4620       case CM_KERNEL:
4621         error ("code model %s does not support PIC mode", "kernel");
4622         break;
4623
4624       default:
4625         break;
4626       }
4627   else
4628     switch (ptr->x_ix86_cmodel)
4629       {
4630       case CM_SMALL_PIC:
4631         ptr->x_ix86_cmodel = CM_SMALL;
4632         break;
4633
4634       case CM_MEDIUM_PIC:
4635         ptr->x_ix86_cmodel = CM_MEDIUM;
4636         break;
4637
4638       case CM_LARGE_PIC:
4639         ptr->x_ix86_cmodel = CM_LARGE;
4640         break;
4641
4642       default:
4643         break;
4644       }
4645 }
4646
4647 /* Print the current options */
4648
4649 static void
4650 ix86_function_specific_print (FILE *file, int indent,
4651                               struct cl_target_option *ptr)
4652 {
4653   char *target_string
4654     = ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_target_flags,
4655                           NULL, NULL, ptr->x_ix86_fpmath, false);
4656
4657   gcc_assert (ptr->arch < PROCESSOR_max);
4658   fprintf (file, "%*sarch = %d (%s)\n",
4659            indent, "",
4660            ptr->arch, processor_target_table[ptr->arch].name);
4661
4662   gcc_assert (ptr->tune < PROCESSOR_max);
4663   fprintf (file, "%*stune = %d (%s)\n",
4664            indent, "",
4665            ptr->tune, processor_target_table[ptr->tune].name);
4666
4667   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
4668
4669   if (target_string)
4670     {
4671       fprintf (file, "%*s%s\n", indent, "", target_string);
4672       free (target_string);
4673     }
4674 }
4675
4676 \f
4677 /* Inner function to process the attribute((target(...))), take an argument and
4678    set the current options from the argument. If we have a list, recursively go
4679    over the list.  */
4680
4681 static bool
4682 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
4683                                      struct gcc_options *opts,
4684                                      struct gcc_options *opts_set,
4685                                      struct gcc_options *enum_opts_set)
4686 {
4687   char *next_optstr;
4688   bool ret = true;
4689
4690 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
4691 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
4692 #define IX86_ATTR_ENUM(S,O)  { S, sizeof (S)-1, ix86_opt_enum, O, 0 }
4693 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
4694 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
4695
4696   enum ix86_opt_type
4697   {
4698     ix86_opt_unknown,
4699     ix86_opt_yes,
4700     ix86_opt_no,
4701     ix86_opt_str,
4702     ix86_opt_enum,
4703     ix86_opt_isa
4704   };
4705
4706   static const struct
4707   {
4708     const char *string;
4709     size_t len;
4710     enum ix86_opt_type type;
4711     int opt;
4712     int mask;
4713   } attrs[] = {
4714     /* isa options */
4715     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
4716     IX86_ATTR_ISA ("abm",       OPT_mabm),
4717     IX86_ATTR_ISA ("bmi",       OPT_mbmi),
4718     IX86_ATTR_ISA ("bmi2",      OPT_mbmi2),
4719     IX86_ATTR_ISA ("lzcnt",     OPT_mlzcnt),
4720     IX86_ATTR_ISA ("tbm",       OPT_mtbm),
4721     IX86_ATTR_ISA ("aes",       OPT_maes),
4722     IX86_ATTR_ISA ("sha",       OPT_msha),
4723     IX86_ATTR_ISA ("avx",       OPT_mavx),
4724     IX86_ATTR_ISA ("avx2",      OPT_mavx2),
4725     IX86_ATTR_ISA ("avx512f",   OPT_mavx512f),
4726     IX86_ATTR_ISA ("avx512pf",  OPT_mavx512pf),
4727     IX86_ATTR_ISA ("avx512er",  OPT_mavx512er),
4728     IX86_ATTR_ISA ("avx512cd",  OPT_mavx512cd),
4729     IX86_ATTR_ISA ("avx512dq",  OPT_mavx512dq),
4730     IX86_ATTR_ISA ("avx512bw",  OPT_mavx512bw),
4731     IX86_ATTR_ISA ("avx512vl",  OPT_mavx512vl),
4732     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
4733     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
4734     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
4735     IX86_ATTR_ISA ("sse",       OPT_msse),
4736     IX86_ATTR_ISA ("sse2",      OPT_msse2),
4737     IX86_ATTR_ISA ("sse3",      OPT_msse3),
4738     IX86_ATTR_ISA ("sse4",      OPT_msse4),
4739     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
4740     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
4741     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
4742     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
4743     IX86_ATTR_ISA ("fma4",      OPT_mfma4),
4744     IX86_ATTR_ISA ("fma",       OPT_mfma),
4745     IX86_ATTR_ISA ("xop",       OPT_mxop),
4746     IX86_ATTR_ISA ("lwp",       OPT_mlwp),
4747     IX86_ATTR_ISA ("fsgsbase",  OPT_mfsgsbase),
4748     IX86_ATTR_ISA ("rdrnd",     OPT_mrdrnd),
4749     IX86_ATTR_ISA ("f16c",      OPT_mf16c),
4750     IX86_ATTR_ISA ("rtm",       OPT_mrtm),
4751     IX86_ATTR_ISA ("hle",       OPT_mhle),
4752     IX86_ATTR_ISA ("prfchw",    OPT_mprfchw),
4753     IX86_ATTR_ISA ("rdseed",    OPT_mrdseed),
4754     IX86_ATTR_ISA ("adx",       OPT_madx),
4755     IX86_ATTR_ISA ("fxsr",      OPT_mfxsr),
4756     IX86_ATTR_ISA ("xsave",     OPT_mxsave),
4757     IX86_ATTR_ISA ("xsaveopt",  OPT_mxsaveopt),
4758     IX86_ATTR_ISA ("prefetchwt1", OPT_mprefetchwt1),
4759     IX86_ATTR_ISA ("clflushopt",        OPT_mclflushopt),
4760     IX86_ATTR_ISA ("xsavec",    OPT_mxsavec),
4761     IX86_ATTR_ISA ("xsaves",    OPT_mxsaves),
4762     IX86_ATTR_ISA ("avx512vbmi",        OPT_mavx512vbmi),
4763     IX86_ATTR_ISA ("avx512ifma",        OPT_mavx512ifma),
4764     IX86_ATTR_ISA ("clwb",      OPT_mclwb),
4765     IX86_ATTR_ISA ("pcommit",   OPT_mpcommit),
4766     IX86_ATTR_ISA ("mwaitx",    OPT_mmwaitx),
4767
4768     /* enum options */
4769     IX86_ATTR_ENUM ("fpmath=",  OPT_mfpmath_),
4770
4771     /* string options */
4772     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
4773     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
4774
4775     /* flag options */
4776     IX86_ATTR_YES ("cld",
4777                    OPT_mcld,
4778                    MASK_CLD),
4779
4780     IX86_ATTR_NO ("fancy-math-387",
4781                   OPT_mfancy_math_387,
4782                   MASK_NO_FANCY_MATH_387),
4783
4784     IX86_ATTR_YES ("ieee-fp",
4785                    OPT_mieee_fp,
4786                    MASK_IEEE_FP),
4787
4788     IX86_ATTR_YES ("inline-all-stringops",
4789                    OPT_minline_all_stringops,
4790                    MASK_INLINE_ALL_STRINGOPS),
4791
4792     IX86_ATTR_YES ("inline-stringops-dynamically",
4793                    OPT_minline_stringops_dynamically,
4794                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
4795
4796     IX86_ATTR_NO ("align-stringops",
4797                   OPT_mno_align_stringops,
4798                   MASK_NO_ALIGN_STRINGOPS),
4799
4800     IX86_ATTR_YES ("recip",
4801                    OPT_mrecip,
4802                    MASK_RECIP),
4803
4804   };
4805
4806   /* If this is a list, recurse to get the options.  */
4807   if (TREE_CODE (args) == TREE_LIST)
4808     {
4809       bool ret = true;
4810
4811       for (; args; args = TREE_CHAIN (args))
4812         if (TREE_VALUE (args)
4813             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args),
4814                                                      p_strings, opts, opts_set,
4815                                                      enum_opts_set))
4816           ret = false;
4817
4818       return ret;
4819     }
4820
4821   else if (TREE_CODE (args) != STRING_CST)
4822     {
4823       error ("attribute %<target%> argument not a string");
4824       return false;
4825     }
4826
4827   /* Handle multiple arguments separated by commas.  */
4828   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
4829
4830   while (next_optstr && *next_optstr != '\0')
4831     {
4832       char *p = next_optstr;
4833       char *orig_p = p;
4834       char *comma = strchr (next_optstr, ',');
4835       const char *opt_string;
4836       size_t len, opt_len;
4837       int opt;
4838       bool opt_set_p;
4839       char ch;
4840       unsigned i;
4841       enum ix86_opt_type type = ix86_opt_unknown;
4842       int mask = 0;
4843
4844       if (comma)
4845         {
4846           *comma = '\0';
4847           len = comma - next_optstr;
4848           next_optstr = comma + 1;
4849         }
4850       else
4851         {
4852           len = strlen (p);
4853           next_optstr = NULL;
4854         }
4855
4856       /* Recognize no-xxx.  */
4857       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
4858         {
4859           opt_set_p = false;
4860           p += 3;
4861           len -= 3;
4862         }
4863       else
4864         opt_set_p = true;
4865
4866       /* Find the option.  */
4867       ch = *p;
4868       opt = N_OPTS;
4869       for (i = 0; i < ARRAY_SIZE (attrs); i++)
4870         {
4871           type = attrs[i].type;
4872           opt_len = attrs[i].len;
4873           if (ch == attrs[i].string[0]
4874               && ((type != ix86_opt_str && type != ix86_opt_enum)
4875                   ? len == opt_len
4876                   : len > opt_len)
4877               && memcmp (p, attrs[i].string, opt_len) == 0)
4878             {
4879               opt = attrs[i].opt;
4880               mask = attrs[i].mask;
4881               opt_string = attrs[i].string;
4882               break;
4883             }
4884         }
4885
4886       /* Process the option.  */
4887       if (opt == N_OPTS)
4888         {
4889           error ("attribute(target(\"%s\")) is unknown", orig_p);
4890           ret = false;
4891         }
4892
4893       else if (type == ix86_opt_isa)
4894         {
4895           struct cl_decoded_option decoded;
4896
4897           generate_option (opt, NULL, opt_set_p, CL_TARGET, &decoded);
4898           ix86_handle_option (opts, opts_set,
4899                               &decoded, input_location);
4900         }
4901
4902       else if (type == ix86_opt_yes || type == ix86_opt_no)
4903         {
4904           if (type == ix86_opt_no)
4905             opt_set_p = !opt_set_p;
4906
4907           if (opt_set_p)
4908             opts->x_target_flags |= mask;
4909           else
4910             opts->x_target_flags &= ~mask;
4911         }
4912
4913       else if (type == ix86_opt_str)
4914         {
4915           if (p_strings[opt])
4916             {
4917               error ("option(\"%s\") was already specified", opt_string);
4918               ret = false;
4919             }
4920           else
4921             p_strings[opt] = xstrdup (p + opt_len);
4922         }
4923
4924       else if (type == ix86_opt_enum)
4925         {
4926           bool arg_ok;
4927           int value;
4928
4929           arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET);
4930           if (arg_ok)
4931             set_option (opts, enum_opts_set, opt, value,
4932                         p + opt_len, DK_UNSPECIFIED, input_location,
4933                         global_dc);
4934           else
4935             {
4936               error ("attribute(target(\"%s\")) is unknown", orig_p);
4937               ret = false;
4938             }
4939         }
4940
4941       else
4942         gcc_unreachable ();
4943     }
4944
4945   return ret;
4946 }
4947
4948 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
4949
4950 tree
4951 ix86_valid_target_attribute_tree (tree args,
4952                                   struct gcc_options *opts,
4953                                   struct gcc_options *opts_set)
4954 {
4955   const char *orig_arch_string = opts->x_ix86_arch_string;
4956   const char *orig_tune_string = opts->x_ix86_tune_string;
4957   enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath;
4958   int orig_tune_defaulted = ix86_tune_defaulted;
4959   int orig_arch_specified = ix86_arch_specified;
4960   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL };
4961   tree t = NULL_TREE;
4962   int i;
4963   struct cl_target_option *def
4964     = TREE_TARGET_OPTION (target_option_default_node);
4965   struct gcc_options enum_opts_set;
4966
4967   memset (&enum_opts_set, 0, sizeof (enum_opts_set));
4968
4969   /* Process each of the options on the chain.  */
4970   if (! ix86_valid_target_attribute_inner_p (args, option_strings, opts,
4971                                              opts_set, &enum_opts_set))
4972     return error_mark_node;
4973
4974   /* If the changed options are different from the default, rerun
4975      ix86_option_override_internal, and then save the options away.
4976      The string options are are attribute options, and will be undone
4977      when we copy the save structure.  */
4978   if (opts->x_ix86_isa_flags != def->x_ix86_isa_flags
4979       || opts->x_target_flags != def->x_target_flags
4980       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
4981       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
4982       || enum_opts_set.x_ix86_fpmath)
4983     {
4984       /* If we are using the default tune= or arch=, undo the string assigned,
4985          and use the default.  */
4986       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
4987         opts->x_ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
4988       else if (!orig_arch_specified)
4989         opts->x_ix86_arch_string = NULL;
4990
4991       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
4992         opts->x_ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
4993       else if (orig_tune_defaulted)
4994         opts->x_ix86_tune_string = NULL;
4995
4996       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
4997       if (enum_opts_set.x_ix86_fpmath)
4998         opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
4999       else if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
5000                && TARGET_SSE_P (opts->x_ix86_isa_flags))
5001         {
5002           opts->x_ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
5003           opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
5004         }
5005
5006       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
5007       ix86_option_override_internal (false, opts, opts_set);
5008
5009       /* Add any builtin functions with the new isa if any.  */
5010       ix86_add_new_builtins (opts->x_ix86_isa_flags);
5011
5012       /* Save the current options unless we are validating options for
5013          #pragma.  */
5014       t = build_target_option_node (opts);
5015
5016       opts->x_ix86_arch_string = orig_arch_string;
5017       opts->x_ix86_tune_string = orig_tune_string;
5018       opts_set->x_ix86_fpmath = orig_fpmath_set;
5019
5020       /* Free up memory allocated to hold the strings */
5021       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
5022         free (option_strings[i]);
5023     }
5024
5025   return t;
5026 }
5027
5028 /* Hook to validate attribute((target("string"))).  */
5029
5030 static bool
5031 ix86_valid_target_attribute_p (tree fndecl,
5032                                tree ARG_UNUSED (name),
5033                                tree args,
5034                                int ARG_UNUSED (flags))
5035 {
5036   struct gcc_options func_options;
5037   tree new_target, new_optimize;
5038   bool ret = true;
5039
5040   /* attribute((target("default"))) does nothing, beyond
5041      affecting multi-versioning.  */
5042   if (TREE_VALUE (args)
5043       && TREE_CODE (TREE_VALUE (args)) == STRING_CST
5044       && TREE_CHAIN (args) == NULL_TREE
5045       && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0)
5046     return true;
5047
5048   tree old_optimize = build_optimization_node (&global_options);
5049
5050   /* Get the optimization options of the current function.  */  
5051   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
5052  
5053   if (!func_optimize)
5054     func_optimize = old_optimize;
5055
5056   /* Init func_options.  */
5057   memset (&func_options, 0, sizeof (func_options));
5058   init_options_struct (&func_options, NULL);
5059   lang_hooks.init_options_struct (&func_options);
5060  
5061   cl_optimization_restore (&func_options,
5062                            TREE_OPTIMIZATION (func_optimize));
5063
5064   /* Initialize func_options to the default before its target options can
5065      be set.  */
5066   cl_target_option_restore (&func_options,
5067                             TREE_TARGET_OPTION (target_option_default_node));
5068
5069   new_target = ix86_valid_target_attribute_tree (args, &func_options,
5070                                                  &global_options_set);
5071
5072   new_optimize = build_optimization_node (&func_options);
5073
5074   if (new_target == error_mark_node)
5075     ret = false;
5076
5077   else if (fndecl && new_target)
5078     {
5079       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
5080
5081       if (old_optimize != new_optimize)
5082         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
5083     }
5084
5085   return ret;
5086 }
5087
5088 \f
5089 /* Hook to determine if one function can safely inline another.  */
5090
5091 static bool
5092 ix86_can_inline_p (tree caller, tree callee)
5093 {
5094   bool ret = false;
5095   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
5096   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
5097
5098   /* If callee has no option attributes, then it is ok to inline.  */
5099   if (!callee_tree)
5100     ret = true;
5101
5102   /* If caller has no option attributes, but callee does then it is not ok to
5103      inline.  */
5104   else if (!caller_tree)
5105     ret = false;
5106
5107   else
5108     {
5109       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
5110       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
5111
5112       /* Callee's isa options should a subset of the caller's, i.e. a SSE4 function
5113          can inline a SSE2 function but a SSE2 function can't inline a SSE4
5114          function.  */
5115       if ((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags)
5116           != callee_opts->x_ix86_isa_flags)
5117         ret = false;
5118
5119       /* See if we have the same non-isa options.  */
5120       else if (caller_opts->x_target_flags != callee_opts->x_target_flags)
5121         ret = false;
5122
5123       /* See if arch, tune, etc. are the same.  */
5124       else if (caller_opts->arch != callee_opts->arch)
5125         ret = false;
5126
5127       else if (caller_opts->tune != callee_opts->tune)
5128         ret = false;
5129
5130       else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath)
5131         ret = false;
5132
5133       else if (caller_opts->branch_cost != callee_opts->branch_cost)
5134         ret = false;
5135
5136       else
5137         ret = true;
5138     }
5139
5140   return ret;
5141 }
5142
5143 \f
5144 /* Remember the last target of ix86_set_current_function.  */
5145 static GTY(()) tree ix86_previous_fndecl;
5146
5147 /* Set targets globals to the default (or current #pragma GCC target
5148    if active).  Invalidate ix86_previous_fndecl cache.  */
5149
5150 void
5151 ix86_reset_previous_fndecl (void)
5152 {
5153   tree new_tree = target_option_current_node;
5154   cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree));
5155   if (TREE_TARGET_GLOBALS (new_tree))
5156     restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
5157   else if (new_tree == target_option_default_node)
5158     restore_target_globals (&default_target_globals);
5159   else
5160     TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
5161   ix86_previous_fndecl = NULL_TREE;
5162 }
5163
5164 /* Establish appropriate back-end context for processing the function
5165    FNDECL.  The argument might be NULL to indicate processing at top
5166    level, outside of any function scope.  */
5167 static void
5168 ix86_set_current_function (tree fndecl)
5169 {
5170   /* Only change the context if the function changes.  This hook is called
5171      several times in the course of compiling a function, and we don't want to
5172      slow things down too much or call target_reinit when it isn't safe.  */
5173   if (fndecl == ix86_previous_fndecl)
5174     return;
5175
5176   tree old_tree;
5177   if (ix86_previous_fndecl == NULL_TREE)
5178     old_tree = target_option_current_node;
5179   else if (DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl))
5180     old_tree = DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl);
5181   else
5182     old_tree = target_option_default_node;
5183
5184   if (fndecl == NULL_TREE)
5185     {
5186       if (old_tree != target_option_current_node)
5187         ix86_reset_previous_fndecl ();
5188       return;
5189     }
5190
5191   tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
5192   if (new_tree == NULL_TREE)
5193     new_tree = target_option_default_node;
5194
5195   if (old_tree != new_tree)
5196     {
5197       cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree));
5198       if (TREE_TARGET_GLOBALS (new_tree))
5199         restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
5200       else if (new_tree == target_option_default_node)
5201         restore_target_globals (&default_target_globals);
5202       else
5203         TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
5204     }
5205   ix86_previous_fndecl = fndecl;
5206 }
5207
5208 \f
5209 /* Return true if this goes in large data/bss.  */
5210
5211 static bool
5212 ix86_in_large_data_p (tree exp)
5213 {
5214   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
5215     return false;
5216
5217   /* Functions are never large data.  */
5218   if (TREE_CODE (exp) == FUNCTION_DECL)
5219     return false;
5220
5221   /* Automatic variables are never large data.  */
5222   if (TREE_CODE (exp) == VAR_DECL && !is_global_var (exp))
5223     return false;
5224
5225   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
5226     {
5227       const char *section = DECL_SECTION_NAME (exp);
5228       if (strcmp (section, ".ldata") == 0
5229           || strcmp (section, ".lbss") == 0)
5230         return true;
5231       return false;
5232     }
5233   else
5234     {
5235       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
5236
5237       /* If this is an incomplete type with size 0, then we can't put it
5238          in data because it might be too big when completed.  Also,
5239          int_size_in_bytes returns -1 if size can vary or is larger than
5240          an integer in which case also it is safer to assume that it goes in
5241          large data.  */
5242       if (size <= 0 || size > ix86_section_threshold)
5243         return true;
5244     }
5245
5246   return false;
5247 }
5248
5249 /* Switch to the appropriate section for output of DECL.
5250    DECL is either a `VAR_DECL' node or a constant of some sort.
5251    RELOC indicates whether forming the initial value of DECL requires
5252    link-time relocations.  */
5253
5254 ATTRIBUTE_UNUSED static section *
5255 x86_64_elf_select_section (tree decl, int reloc,
5256                            unsigned HOST_WIDE_INT align)
5257 {
5258   if (ix86_in_large_data_p (decl))
5259     {
5260       const char *sname = NULL;
5261       unsigned int flags = SECTION_WRITE;
5262       switch (categorize_decl_for_section (decl, reloc))
5263         {
5264         case SECCAT_DATA:
5265           sname = ".ldata";
5266           break;
5267         case SECCAT_DATA_REL:
5268           sname = ".ldata.rel";
5269           break;
5270         case SECCAT_DATA_REL_LOCAL:
5271           sname = ".ldata.rel.local";
5272           break;
5273         case SECCAT_DATA_REL_RO:
5274           sname = ".ldata.rel.ro";
5275           break;
5276         case SECCAT_DATA_REL_RO_LOCAL:
5277           sname = ".ldata.rel.ro.local";
5278           break;
5279         case SECCAT_BSS:
5280           sname = ".lbss";
5281           flags |= SECTION_BSS;
5282           break;
5283         case SECCAT_RODATA:
5284         case SECCAT_RODATA_MERGE_STR:
5285         case SECCAT_RODATA_MERGE_STR_INIT:
5286         case SECCAT_RODATA_MERGE_CONST:
5287           sname = ".lrodata";
5288           flags = 0;
5289           break;
5290         case SECCAT_SRODATA:
5291         case SECCAT_SDATA:
5292         case SECCAT_SBSS:
5293           gcc_unreachable ();
5294         case SECCAT_TEXT:
5295         case SECCAT_TDATA:
5296         case SECCAT_TBSS:
5297           /* We don't split these for medium model.  Place them into
5298              default sections and hope for best.  */
5299           break;
5300         }
5301       if (sname)
5302         {
5303           /* We might get called with string constants, but get_named_section
5304              doesn't like them as they are not DECLs.  Also, we need to set
5305              flags in that case.  */
5306           if (!DECL_P (decl))
5307             return get_section (sname, flags, NULL);
5308           return get_named_section (decl, sname, reloc);
5309         }
5310     }
5311   return default_elf_select_section (decl, reloc, align);
5312 }
5313
5314 /* Select a set of attributes for section NAME based on the properties
5315    of DECL and whether or not RELOC indicates that DECL's initializer
5316    might contain runtime relocations.  */
5317
5318 static unsigned int ATTRIBUTE_UNUSED
5319 x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
5320 {
5321   unsigned int flags = default_section_type_flags (decl, name, reloc);
5322
5323   if (decl == NULL_TREE
5324       && (strcmp (name, ".ldata.rel.ro") == 0
5325           || strcmp (name, ".ldata.rel.ro.local") == 0))
5326     flags |= SECTION_RELRO;
5327
5328   if (strcmp (name, ".lbss") == 0
5329       || strncmp (name, ".lbss.", 5) == 0
5330       || strncmp (name, ".gnu.linkonce.lb.", 16) == 0)
5331     flags |= SECTION_BSS;
5332
5333   return flags;
5334 }
5335
5336 /* Build up a unique section name, expressed as a
5337    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
5338    RELOC indicates whether the initial value of EXP requires
5339    link-time relocations.  */
5340
5341 static void ATTRIBUTE_UNUSED
5342 x86_64_elf_unique_section (tree decl, int reloc)
5343 {
5344   if (ix86_in_large_data_p (decl))
5345     {
5346       const char *prefix = NULL;
5347       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
5348       bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP;
5349
5350       switch (categorize_decl_for_section (decl, reloc))
5351         {
5352         case SECCAT_DATA:
5353         case SECCAT_DATA_REL:
5354         case SECCAT_DATA_REL_LOCAL:
5355         case SECCAT_DATA_REL_RO:
5356         case SECCAT_DATA_REL_RO_LOCAL:
5357           prefix = one_only ? ".ld" : ".ldata";
5358           break;
5359         case SECCAT_BSS:
5360           prefix = one_only ? ".lb" : ".lbss";
5361           break;
5362         case SECCAT_RODATA:
5363         case SECCAT_RODATA_MERGE_STR:
5364         case SECCAT_RODATA_MERGE_STR_INIT:
5365         case SECCAT_RODATA_MERGE_CONST:
5366           prefix = one_only ? ".lr" : ".lrodata";
5367           break;
5368         case SECCAT_SRODATA:
5369         case SECCAT_SDATA:
5370         case SECCAT_SBSS:
5371           gcc_unreachable ();
5372         case SECCAT_TEXT:
5373         case SECCAT_TDATA:
5374         case SECCAT_TBSS:
5375           /* We don't split these for medium model.  Place them into
5376              default sections and hope for best.  */
5377           break;
5378         }
5379       if (prefix)
5380         {
5381           const char *name, *linkonce;
5382           char *string;
5383
5384           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5385           name = targetm.strip_name_encoding (name);
5386
5387           /* If we're using one_only, then there needs to be a .gnu.linkonce
5388              prefix to the section name.  */
5389           linkonce = one_only ? ".gnu.linkonce" : "";
5390
5391           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
5392
5393           set_decl_section_name (decl, string);
5394           return;
5395         }
5396     }
5397   default_unique_section (decl, reloc);
5398 }
5399
5400 #ifdef COMMON_ASM_OP
5401 /* This says how to output assembler code to declare an
5402    uninitialized external linkage data object.
5403
5404    For medium model x86-64 we need to use .largecomm opcode for
5405    large objects.  */
5406 void
5407 x86_elf_aligned_common (FILE *file,
5408                         const char *name, unsigned HOST_WIDE_INT size,
5409                         int align)
5410 {
5411   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
5412       && size > (unsigned int)ix86_section_threshold)
5413     fputs ("\t.largecomm\t", file);
5414   else
5415     fputs (COMMON_ASM_OP, file);
5416   assemble_name (file, name);
5417   fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
5418            size, align / BITS_PER_UNIT);
5419 }
5420 #endif
5421
5422 /* Utility function for targets to use in implementing
5423    ASM_OUTPUT_ALIGNED_BSS.  */
5424
5425 void
5426 x86_output_aligned_bss (FILE *file, tree decl, const char *name,
5427                         unsigned HOST_WIDE_INT size, int align)
5428 {
5429   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
5430       && size > (unsigned int)ix86_section_threshold)
5431     switch_to_section (get_named_section (decl, ".lbss", 0));
5432   else
5433     switch_to_section (bss_section);
5434   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
5435 #ifdef ASM_DECLARE_OBJECT_NAME
5436   last_assemble_variable_decl = decl;
5437   ASM_DECLARE_OBJECT_NAME (file, name, decl);
5438 #else
5439   /* Standard thing is just output label for the object.  */
5440   ASM_OUTPUT_LABEL (file, name);
5441 #endif /* ASM_DECLARE_OBJECT_NAME */
5442   ASM_OUTPUT_SKIP (file, size ? size : 1);
5443 }
5444 \f
5445 /* Decide whether we must probe the stack before any space allocation
5446    on this target.  It's essentially TARGET_STACK_PROBE except when
5447    -fstack-check causes the stack to be already probed differently.  */
5448
5449 bool
5450 ix86_target_stack_probe (void)
5451 {
5452   /* Do not probe the stack twice if static stack checking is enabled.  */
5453   if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5454     return false;
5455
5456   return TARGET_STACK_PROBE;
5457 }
5458 \f
5459 /* Decide whether we can make a sibling call to a function.  DECL is the
5460    declaration of the function being targeted by the call and EXP is the
5461    CALL_EXPR representing the call.  */
5462
5463 static bool
5464 ix86_function_ok_for_sibcall (tree decl, tree exp)
5465 {
5466   tree type, decl_or_type;
5467   rtx a, b;
5468
5469   /* If we are generating position-independent code, we cannot sibcall
5470      optimize direct calls to global functions, as the PLT requires
5471      %ebx be live. (Darwin does not have a PLT.)  */
5472   if (!TARGET_MACHO
5473       && !TARGET_64BIT
5474       && flag_pic
5475       && flag_plt
5476       && decl && !targetm.binds_local_p (decl))
5477     return false;
5478
5479   /* If we need to align the outgoing stack, then sibcalling would
5480      unalign the stack, which may break the called function.  */
5481   if (ix86_minimum_incoming_stack_boundary (true)
5482       < PREFERRED_STACK_BOUNDARY)
5483     return false;
5484
5485   if (decl)
5486     {
5487       decl_or_type = decl;
5488       type = TREE_TYPE (decl);
5489     }
5490   else
5491     {
5492       /* We're looking at the CALL_EXPR, we need the type of the function.  */
5493       type = CALL_EXPR_FN (exp);                /* pointer expression */
5494       type = TREE_TYPE (type);                  /* pointer type */
5495       type = TREE_TYPE (type);                  /* function type */
5496       decl_or_type = type;
5497     }
5498
5499   /* Check that the return value locations are the same.  Like
5500      if we are returning floats on the 80387 register stack, we cannot
5501      make a sibcall from a function that doesn't return a float to a
5502      function that does or, conversely, from a function that does return
5503      a float to a function that doesn't; the necessary stack adjustment
5504      would not be executed.  This is also the place we notice
5505      differences in the return value ABI.  Note that it is ok for one
5506      of the functions to have void return type as long as the return
5507      value of the other is passed in a register.  */
5508   a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
5509   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
5510                            cfun->decl, false);
5511   if (STACK_REG_P (a) || STACK_REG_P (b))
5512     {
5513       if (!rtx_equal_p (a, b))
5514         return false;
5515     }
5516   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
5517     ;
5518   else if (!rtx_equal_p (a, b))
5519     return false;
5520
5521   if (TARGET_64BIT)
5522     {
5523       /* The SYSV ABI has more call-clobbered registers;
5524          disallow sibcalls from MS to SYSV.  */
5525       if (cfun->machine->call_abi == MS_ABI
5526           && ix86_function_type_abi (type) == SYSV_ABI)
5527         return false;
5528     }
5529   else
5530     {
5531       /* If this call is indirect, we'll need to be able to use a
5532          call-clobbered register for the address of the target function.
5533          Make sure that all such registers are not used for passing
5534          parameters.  Note that DLLIMPORT functions are indirect.  */
5535       if (!decl
5536           || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)))
5537         {
5538           if (ix86_function_regparm (type, NULL) >= 3)
5539             {
5540               /* ??? Need to count the actual number of registers to be used,
5541                  not the possible number of registers.  Fix later.  */
5542               return false;
5543             }
5544         }
5545     }
5546
5547   /* Otherwise okay.  That also includes certain types of indirect calls.  */
5548   return true;
5549 }
5550
5551 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
5552    and "sseregparm" calling convention attributes;
5553    arguments as in struct attribute_spec.handler.  */
5554
5555 static tree
5556 ix86_handle_cconv_attribute (tree *node, tree name,
5557                                    tree args,
5558                                    int,
5559                                    bool *no_add_attrs)
5560 {
5561   if (TREE_CODE (*node) != FUNCTION_TYPE
5562       && TREE_CODE (*node) != METHOD_TYPE
5563       && TREE_CODE (*node) != FIELD_DECL
5564       && TREE_CODE (*node) != TYPE_DECL)
5565     {
5566       warning (OPT_Wattributes, "%qE attribute only applies to functions",
5567                name);
5568       *no_add_attrs = true;
5569       return NULL_TREE;
5570     }
5571
5572   /* Can combine regparm with all attributes but fastcall, and thiscall.  */
5573   if (is_attribute_p ("regparm", name))
5574     {
5575       tree cst;
5576
5577       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5578         {
5579           error ("fastcall and regparm attributes are not compatible");
5580         }
5581
5582       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5583         {
5584           error ("regparam and thiscall attributes are not compatible");
5585         }
5586
5587       cst = TREE_VALUE (args);
5588       if (TREE_CODE (cst) != INTEGER_CST)
5589         {
5590           warning (OPT_Wattributes,
5591                    "%qE attribute requires an integer constant argument",
5592                    name);
5593           *no_add_attrs = true;
5594         }
5595       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
5596         {
5597           warning (OPT_Wattributes, "argument to %qE attribute larger than %d",
5598                    name, REGPARM_MAX);
5599           *no_add_attrs = true;
5600         }
5601
5602       return NULL_TREE;
5603     }
5604
5605   if (TARGET_64BIT)
5606     {
5607       /* Do not warn when emulating the MS ABI.  */
5608       if ((TREE_CODE (*node) != FUNCTION_TYPE
5609            && TREE_CODE (*node) != METHOD_TYPE)
5610           || ix86_function_type_abi (*node) != MS_ABI)
5611         warning (OPT_Wattributes, "%qE attribute ignored",
5612                  name);
5613       *no_add_attrs = true;
5614       return NULL_TREE;
5615     }
5616
5617   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
5618   if (is_attribute_p ("fastcall", name))
5619     {
5620       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5621         {
5622           error ("fastcall and cdecl attributes are not compatible");
5623         }
5624       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5625         {
5626           error ("fastcall and stdcall attributes are not compatible");
5627         }
5628       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
5629         {
5630           error ("fastcall and regparm attributes are not compatible");
5631         }
5632       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5633         {
5634           error ("fastcall and thiscall attributes are not compatible");
5635         }
5636     }
5637
5638   /* Can combine stdcall with fastcall (redundant), regparm and
5639      sseregparm.  */
5640   else if (is_attribute_p ("stdcall", name))
5641     {
5642       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5643         {
5644           error ("stdcall and cdecl attributes are not compatible");
5645         }
5646       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5647         {
5648           error ("stdcall and fastcall attributes are not compatible");
5649         }
5650       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5651         {
5652           error ("stdcall and thiscall attributes are not compatible");
5653         }
5654     }
5655
5656   /* Can combine cdecl with regparm and sseregparm.  */
5657   else if (is_attribute_p ("cdecl", name))
5658     {
5659       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5660         {
5661           error ("stdcall and cdecl attributes are not compatible");
5662         }
5663       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5664         {
5665           error ("fastcall and cdecl attributes are not compatible");
5666         }
5667       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5668         {
5669           error ("cdecl and thiscall attributes are not compatible");
5670         }
5671     }
5672   else if (is_attribute_p ("thiscall", name))
5673     {
5674       if (TREE_CODE (*node) != METHOD_TYPE && pedantic)
5675         warning (OPT_Wattributes, "%qE attribute is used for non-class method",
5676                  name);
5677       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5678         {
5679           error ("stdcall and thiscall attributes are not compatible");
5680         }
5681       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5682         {
5683           error ("fastcall and thiscall attributes are not compatible");
5684         }
5685       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5686         {
5687           error ("cdecl and thiscall attributes are not compatible");
5688         }
5689     }
5690
5691   /* Can combine sseregparm with all attributes.  */
5692
5693   return NULL_TREE;
5694 }
5695
5696 /* The transactional memory builtins are implicitly regparm or fastcall
5697    depending on the ABI.  Override the generic do-nothing attribute that
5698    these builtins were declared with, and replace it with one of the two
5699    attributes that we expect elsewhere.  */
5700
5701 static tree
5702 ix86_handle_tm_regparm_attribute (tree *node, tree, tree,
5703                                   int flags, bool *no_add_attrs)
5704 {
5705   tree alt;
5706
5707   /* In no case do we want to add the placeholder attribute.  */
5708   *no_add_attrs = true;
5709
5710   /* The 64-bit ABI is unchanged for transactional memory.  */
5711   if (TARGET_64BIT)
5712     return NULL_TREE;
5713
5714   /* ??? Is there a better way to validate 32-bit windows?  We have
5715      cfun->machine->call_abi, but that seems to be set only for 64-bit.  */
5716   if (CHECK_STACK_LIMIT > 0)
5717     alt = tree_cons (get_identifier ("fastcall"), NULL, NULL);
5718   else
5719     {
5720       alt = tree_cons (NULL, build_int_cst (NULL, 2), NULL);
5721       alt = tree_cons (get_identifier ("regparm"), alt, NULL);
5722     }
5723   decl_attributes (node, alt, flags);
5724
5725   return NULL_TREE;
5726 }
5727
5728 /* This function determines from TYPE the calling-convention.  */
5729
5730 unsigned int
5731 ix86_get_callcvt (const_tree type)
5732 {
5733   unsigned int ret = 0;
5734   bool is_stdarg;
5735   tree attrs;
5736
5737   if (TARGET_64BIT)
5738     return IX86_CALLCVT_CDECL;
5739
5740   attrs = TYPE_ATTRIBUTES (type);
5741   if (attrs != NULL_TREE)
5742     {
5743       if (lookup_attribute ("cdecl", attrs))
5744         ret |= IX86_CALLCVT_CDECL;
5745       else if (lookup_attribute ("stdcall", attrs))
5746         ret |= IX86_CALLCVT_STDCALL;
5747       else if (lookup_attribute ("fastcall", attrs))
5748         ret |= IX86_CALLCVT_FASTCALL;
5749       else if (lookup_attribute ("thiscall", attrs))
5750         ret |= IX86_CALLCVT_THISCALL;
5751
5752       /* Regparam isn't allowed for thiscall and fastcall.  */
5753       if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
5754         {
5755           if (lookup_attribute ("regparm", attrs))
5756             ret |= IX86_CALLCVT_REGPARM;
5757           if (lookup_attribute ("sseregparm", attrs))
5758             ret |= IX86_CALLCVT_SSEREGPARM;
5759         }
5760
5761       if (IX86_BASE_CALLCVT(ret) != 0)
5762         return ret;
5763     }
5764
5765   is_stdarg = stdarg_p (type);
5766   if (TARGET_RTD && !is_stdarg)
5767     return IX86_CALLCVT_STDCALL | ret;
5768
5769   if (ret != 0
5770       || is_stdarg
5771       || TREE_CODE (type) != METHOD_TYPE
5772       || ix86_function_type_abi (type) != MS_ABI)
5773     return IX86_CALLCVT_CDECL | ret;
5774
5775   return IX86_CALLCVT_THISCALL;
5776 }
5777
5778 /* Return 0 if the attributes for two types are incompatible, 1 if they
5779    are compatible, and 2 if they are nearly compatible (which causes a
5780    warning to be generated).  */
5781
5782 static int
5783 ix86_comp_type_attributes (const_tree type1, const_tree type2)
5784 {
5785   unsigned int ccvt1, ccvt2;
5786
5787   if (TREE_CODE (type1) != FUNCTION_TYPE
5788       && TREE_CODE (type1) != METHOD_TYPE)
5789     return 1;
5790
5791   ccvt1 = ix86_get_callcvt (type1);
5792   ccvt2 = ix86_get_callcvt (type2);
5793   if (ccvt1 != ccvt2)
5794     return 0;
5795   if (ix86_function_regparm (type1, NULL)
5796       != ix86_function_regparm (type2, NULL))
5797     return 0;
5798
5799   return 1;
5800 }
5801 \f
5802 /* Return the regparm value for a function with the indicated TYPE and DECL.
5803    DECL may be NULL when calling function indirectly
5804    or considering a libcall.  */
5805
5806 static int
5807 ix86_function_regparm (const_tree type, const_tree decl)
5808 {
5809   tree attr;
5810   int regparm;
5811   unsigned int ccvt;
5812
5813   if (TARGET_64BIT)
5814     return (ix86_function_type_abi (type) == SYSV_ABI
5815             ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
5816   ccvt = ix86_get_callcvt (type);
5817   regparm = ix86_regparm;
5818
5819   if ((ccvt & IX86_CALLCVT_REGPARM) != 0)
5820     {
5821       attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
5822       if (attr)
5823         {
5824           regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
5825           return regparm;
5826         }
5827     }
5828   else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
5829     return 2;
5830   else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
5831     return 1;
5832
5833   /* Use register calling convention for local functions when possible.  */
5834   if (decl
5835       && TREE_CODE (decl) == FUNCTION_DECL)
5836     {
5837       cgraph_node *target = cgraph_node::get (decl);
5838       if (target)
5839         target = target->function_symbol ();
5840
5841       /* Caller and callee must agree on the calling convention, so
5842          checking here just optimize means that with
5843          __attribute__((optimize (...))) caller could use regparm convention
5844          and callee not, or vice versa.  Instead look at whether the callee
5845          is optimized or not.  */
5846       if (target && opt_for_fn (target->decl, optimize)
5847           && !(profile_flag && !flag_fentry))
5848         {
5849           cgraph_local_info *i = &target->local;
5850           if (i && i->local && i->can_change_signature)
5851             {
5852               int local_regparm, globals = 0, regno;
5853
5854               /* Make sure no regparm register is taken by a
5855                  fixed register variable.  */
5856               for (local_regparm = 0; local_regparm < REGPARM_MAX;
5857                    local_regparm++)
5858                 if (fixed_regs[local_regparm])
5859                   break;
5860
5861               /* We don't want to use regparm(3) for nested functions as
5862                  these use a static chain pointer in the third argument.  */
5863               if (local_regparm == 3 && DECL_STATIC_CHAIN (target->decl))
5864                 local_regparm = 2;
5865
5866               /* Save a register for the split stack.  */
5867               if (local_regparm == 3 && flag_split_stack)
5868                 local_regparm = 2;
5869
5870               /* Each fixed register usage increases register pressure,
5871                  so less registers should be used for argument passing.
5872                  This functionality can be overriden by an explicit
5873                  regparm value.  */
5874               for (regno = AX_REG; regno <= DI_REG; regno++)
5875                 if (fixed_regs[regno])
5876                   globals++;
5877
5878               local_regparm
5879                 = globals < local_regparm ? local_regparm - globals : 0;
5880
5881               if (local_regparm > regparm)
5882                 regparm = local_regparm;
5883             }
5884         }
5885     }
5886
5887   return regparm;
5888 }
5889
5890 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
5891    DFmode (2) arguments in SSE registers for a function with the
5892    indicated TYPE and DECL.  DECL may be NULL when calling function
5893    indirectly or considering a libcall.  Return -1 if any FP parameter
5894    should be rejected by error.  This is used in siutation we imply SSE
5895    calling convetion but the function is called from another function with
5896    SSE disabled. Otherwise return 0.  */
5897
5898 static int
5899 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
5900 {
5901   gcc_assert (!TARGET_64BIT);
5902
5903   /* Use SSE registers to pass SFmode and DFmode arguments if requested
5904      by the sseregparm attribute.  */
5905   if (TARGET_SSEREGPARM
5906       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
5907     {
5908       if (!TARGET_SSE)
5909         {
5910           if (warn)
5911             {
5912               if (decl)
5913                 error ("calling %qD with attribute sseregparm without "
5914                        "SSE/SSE2 enabled", decl);
5915               else
5916                 error ("calling %qT with attribute sseregparm without "
5917                        "SSE/SSE2 enabled", type);
5918             }
5919           return 0;
5920         }
5921
5922       return 2;
5923     }
5924
5925   if (!decl)
5926     return 0;
5927
5928   cgraph_node *target = cgraph_node::get (decl);
5929   if (target)
5930     target = target->function_symbol ();
5931
5932   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
5933      (and DFmode for SSE2) arguments in SSE registers.  */
5934   if (target
5935       /* TARGET_SSE_MATH */
5936       && (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE)
5937       && opt_for_fn (target->decl, optimize)
5938       && !(profile_flag && !flag_fentry))
5939     {
5940       cgraph_local_info *i = &target->local;
5941       if (i && i->local && i->can_change_signature)
5942         {
5943           /* Refuse to produce wrong code when local function with SSE enabled
5944              is called from SSE disabled function.
5945              FIXME: We need a way to detect these cases cross-ltrans partition
5946              and avoid using SSE calling conventions on local functions called
5947              from function with SSE disabled.  For now at least delay the
5948              warning until we know we are going to produce wrong code.
5949              See PR66047  */
5950           if (!TARGET_SSE && warn)
5951             return -1;
5952           return TARGET_SSE2_P (target_opts_for_fn (target->decl)
5953                                 ->x_ix86_isa_flags) ? 2 : 1;
5954         }
5955     }
5956
5957   return 0;
5958 }
5959
5960 /* Return true if EAX is live at the start of the function.  Used by
5961    ix86_expand_prologue to determine if we need special help before
5962    calling allocate_stack_worker.  */
5963
5964 static bool
5965 ix86_eax_live_at_start_p (void)
5966 {
5967   /* Cheat.  Don't bother working forward from ix86_function_regparm
5968      to the function type to whether an actual argument is located in
5969      eax.  Instead just look at cfg info, which is still close enough
5970      to correct at this point.  This gives false positives for broken
5971      functions that might use uninitialized data that happens to be
5972      allocated in eax, but who cares?  */
5973   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0);
5974 }
5975
5976 static bool
5977 ix86_keep_aggregate_return_pointer (tree fntype)
5978 {
5979   tree attr;
5980
5981   if (!TARGET_64BIT)
5982     {
5983       attr = lookup_attribute ("callee_pop_aggregate_return",
5984                                TYPE_ATTRIBUTES (fntype));
5985       if (attr)
5986         return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0);
5987
5988       /* For 32-bit MS-ABI the default is to keep aggregate
5989          return pointer.  */
5990       if (ix86_function_type_abi (fntype) == MS_ABI)
5991         return true;
5992     }
5993   return KEEP_AGGREGATE_RETURN_POINTER != 0;
5994 }
5995
5996 /* Value is the number of bytes of arguments automatically
5997    popped when returning from a subroutine call.
5998    FUNDECL is the declaration node of the function (as a tree),
5999    FUNTYPE is the data type of the function (as a tree),
6000    or for a library call it is an identifier node for the subroutine name.
6001    SIZE is the number of bytes of arguments passed on the stack.
6002
6003    On the 80386, the RTD insn may be used to pop them if the number
6004      of args is fixed, but if the number is variable then the caller
6005      must pop them all.  RTD can't be used for library calls now
6006      because the library is compiled with the Unix compiler.
6007    Use of RTD is a selectable option, since it is incompatible with
6008    standard Unix calling sequences.  If the option is not selected,
6009    the caller must always pop the args.
6010
6011    The attribute stdcall is equivalent to RTD on a per module basis.  */
6012
6013 static int
6014 ix86_return_pops_args (tree fundecl, tree funtype, int size)
6015 {
6016   unsigned int ccvt;
6017
6018   /* None of the 64-bit ABIs pop arguments.  */
6019   if (TARGET_64BIT)
6020     return 0;
6021
6022   ccvt = ix86_get_callcvt (funtype);
6023
6024   if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL
6025                | IX86_CALLCVT_THISCALL)) != 0
6026       && ! stdarg_p (funtype))
6027     return size;
6028
6029   /* Lose any fake structure return argument if it is passed on the stack.  */
6030   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
6031       && !ix86_keep_aggregate_return_pointer (funtype))
6032     {
6033       int nregs = ix86_function_regparm (funtype, fundecl);
6034       if (nregs == 0)
6035         return GET_MODE_SIZE (Pmode);
6036     }
6037
6038   return 0;
6039 }
6040
6041 /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook.  */
6042
6043 static bool
6044 ix86_legitimate_combined_insn (rtx_insn *insn)
6045 {
6046   /* Check operand constraints in case hard registers were propagated
6047      into insn pattern.  This check prevents combine pass from
6048      generating insn patterns with invalid hard register operands.
6049      These invalid insns can eventually confuse reload to error out
6050      with a spill failure.  See also PRs 46829 and 46843.  */
6051   if ((INSN_CODE (insn) = recog (PATTERN (insn), insn, 0)) >= 0)
6052     {
6053       int i;
6054
6055       extract_insn (insn);
6056       preprocess_constraints (insn);
6057
6058       int n_operands = recog_data.n_operands;
6059       int n_alternatives = recog_data.n_alternatives;
6060       for (i = 0; i < n_operands; i++)
6061         {
6062           rtx op = recog_data.operand[i];
6063           machine_mode mode = GET_MODE (op);
6064           const operand_alternative *op_alt;
6065           int offset = 0;
6066           bool win;
6067           int j;
6068
6069           /* For pre-AVX disallow unaligned loads/stores where the
6070              instructions don't support it.  */
6071           if (!TARGET_AVX
6072               && VECTOR_MODE_P (GET_MODE (op))
6073               && misaligned_operand (op, GET_MODE (op)))
6074             {
6075               int min_align = get_attr_ssememalign (insn);
6076               if (min_align == 0)
6077                 return false;
6078             }
6079
6080           /* A unary operator may be accepted by the predicate, but it
6081              is irrelevant for matching constraints.  */
6082           if (UNARY_P (op))
6083             op = XEXP (op, 0);
6084
6085           if (GET_CODE (op) == SUBREG)
6086             {
6087               if (REG_P (SUBREG_REG (op))
6088                   && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
6089                 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
6090                                               GET_MODE (SUBREG_REG (op)),
6091                                               SUBREG_BYTE (op),
6092                                               GET_MODE (op));
6093               op = SUBREG_REG (op);
6094             }
6095
6096           if (!(REG_P (op) && HARD_REGISTER_P (op)))
6097             continue;
6098
6099           op_alt = recog_op_alt;
6100
6101           /* Operand has no constraints, anything is OK.  */
6102           win = !n_alternatives;
6103
6104           alternative_mask preferred = get_preferred_alternatives (insn);
6105           for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
6106             {
6107               if (!TEST_BIT (preferred, j))
6108                 continue;
6109               if (op_alt[i].anything_ok
6110                   || (op_alt[i].matches != -1
6111                       && operands_match_p
6112                           (recog_data.operand[i],
6113                            recog_data.operand[op_alt[i].matches]))
6114                   || reg_fits_class_p (op, op_alt[i].cl, offset, mode))
6115                 {
6116                   win = true;
6117                   break;
6118                 }
6119             }
6120
6121           if (!win)
6122             return false;
6123         }
6124     }
6125
6126   return true;
6127 }
6128 \f
6129 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook.  */
6130
6131 static unsigned HOST_WIDE_INT
6132 ix86_asan_shadow_offset (void)
6133 {
6134   return TARGET_LP64 ? (TARGET_MACHO ? (HOST_WIDE_INT_1 << 44)
6135                                      : HOST_WIDE_INT_C (0x7fff8000))
6136                      : (HOST_WIDE_INT_1 << 29);
6137 }
6138 \f
6139 /* Argument support functions.  */
6140
6141 /* Return true when register may be used to pass function parameters.  */
6142 bool
6143 ix86_function_arg_regno_p (int regno)
6144 {
6145   int i;
6146   enum calling_abi call_abi;
6147   const int *parm_regs;
6148
6149   if (TARGET_MPX && BND_REGNO_P (regno))
6150     return true;
6151
6152   if (!TARGET_64BIT)
6153     {
6154       if (TARGET_MACHO)
6155         return (regno < REGPARM_MAX
6156                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
6157       else
6158         return (regno < REGPARM_MAX
6159                 || (TARGET_MMX && MMX_REGNO_P (regno)
6160                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
6161                 || (TARGET_SSE && SSE_REGNO_P (regno)
6162                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
6163     }
6164
6165   if (TARGET_SSE && SSE_REGNO_P (regno)
6166       && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
6167     return true;
6168
6169   /* TODO: The function should depend on current function ABI but
6170      builtins.c would need updating then. Therefore we use the
6171      default ABI.  */
6172   call_abi = ix86_cfun_abi ();
6173
6174   /* RAX is used as hidden argument to va_arg functions.  */
6175   if (call_abi == SYSV_ABI && regno == AX_REG)
6176     return true;
6177
6178   if (call_abi == MS_ABI)
6179     parm_regs = x86_64_ms_abi_int_parameter_registers;
6180   else
6181     parm_regs = x86_64_int_parameter_registers;
6182
6183   for (i = 0; i < (call_abi == MS_ABI
6184                    ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
6185     if (regno == parm_regs[i])
6186       return true;
6187   return false;
6188 }
6189
6190 /* Return if we do not know how to pass TYPE solely in registers.  */
6191
6192 static bool
6193 ix86_must_pass_in_stack (machine_mode mode, const_tree type)
6194 {
6195   if (must_pass_in_stack_var_size_or_pad (mode, type))
6196     return true;
6197
6198   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
6199      The layout_type routine is crafty and tries to trick us into passing
6200      currently unsupported vector types on the stack by using TImode.  */
6201   return (!TARGET_64BIT && mode == TImode
6202           && type && TREE_CODE (type) != VECTOR_TYPE);
6203 }
6204
6205 /* It returns the size, in bytes, of the area reserved for arguments passed
6206    in registers for the function represented by fndecl dependent to the used
6207    abi format.  */
6208 int
6209 ix86_reg_parm_stack_space (const_tree fndecl)
6210 {
6211   enum calling_abi call_abi = SYSV_ABI;
6212   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
6213     call_abi = ix86_function_abi (fndecl);
6214   else
6215     call_abi = ix86_function_type_abi (fndecl);
6216   if (TARGET_64BIT && call_abi == MS_ABI)
6217     return 32;
6218   return 0;
6219 }
6220
6221 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
6222    call abi used.  */
6223 enum calling_abi
6224 ix86_function_type_abi (const_tree fntype)
6225 {
6226   if (fntype != NULL_TREE && TYPE_ATTRIBUTES (fntype) != NULL_TREE)
6227     {
6228       enum calling_abi abi = ix86_abi;
6229       if (abi == SYSV_ABI)
6230         {
6231           if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
6232             {
6233               if (TARGET_X32)
6234                 {
6235                   static bool warned = false;
6236                   if (!warned)
6237                     {
6238                       error ("X32 does not support ms_abi attribute");
6239                       warned = true;
6240                     }
6241                 }
6242               abi = MS_ABI;
6243             }
6244         }
6245       else if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
6246         abi = SYSV_ABI;
6247       return abi;
6248     }
6249   return ix86_abi;
6250 }
6251
6252 /* We add this as a workaround in order to use libc_has_function
6253    hook in i386.md.  */
6254 bool
6255 ix86_libc_has_function (enum function_class fn_class)
6256 {
6257   return targetm.libc_has_function (fn_class);
6258 }
6259
6260 static bool
6261 ix86_function_ms_hook_prologue (const_tree fn)
6262 {
6263   if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn)))
6264     {
6265       if (decl_function_context (fn) != NULL_TREE)
6266         error_at (DECL_SOURCE_LOCATION (fn),
6267                   "ms_hook_prologue is not compatible with nested function");
6268       else
6269         return true;
6270     }
6271   return false;
6272 }
6273
6274 static enum calling_abi
6275 ix86_function_abi (const_tree fndecl)
6276 {
6277   if (! fndecl)
6278     return ix86_abi;
6279   return ix86_function_type_abi (TREE_TYPE (fndecl));
6280 }
6281
6282 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
6283    call abi used.  */
6284 enum calling_abi
6285 ix86_cfun_abi (void)
6286 {
6287   if (! cfun)
6288     return ix86_abi;
6289   return cfun->machine->call_abi;
6290 }
6291
6292 /* Write the extra assembler code needed to declare a function properly.  */
6293
6294 void
6295 ix86_asm_output_function_label (FILE *asm_out_file, const char *fname,
6296                                 tree decl)
6297 {
6298   bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
6299
6300   if (is_ms_hook)
6301     {
6302       int i, filler_count = (TARGET_64BIT ? 32 : 16);
6303       unsigned int filler_cc = 0xcccccccc;
6304
6305       for (i = 0; i < filler_count; i += 4)
6306         fprintf (asm_out_file, ASM_LONG " %#x\n", filler_cc);
6307     }
6308
6309 #ifdef SUBTARGET_ASM_UNWIND_INIT
6310   SUBTARGET_ASM_UNWIND_INIT (asm_out_file);
6311 #endif
6312
6313   ASM_OUTPUT_LABEL (asm_out_file, fname);
6314
6315   /* Output magic byte marker, if hot-patch attribute is set.  */
6316   if (is_ms_hook)
6317     {
6318       if (TARGET_64BIT)
6319         {
6320           /* leaq [%rsp + 0], %rsp  */
6321           asm_fprintf (asm_out_file, ASM_BYTE
6322                        "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n");
6323         }
6324       else
6325         {
6326           /* movl.s %edi, %edi
6327              push   %ebp
6328              movl.s %esp, %ebp */
6329           asm_fprintf (asm_out_file, ASM_BYTE
6330                        "0x8b, 0xff, 0x55, 0x8b, 0xec\n");
6331         }
6332     }
6333 }
6334
6335 /* regclass.c  */
6336 extern void init_regs (void);
6337
6338 /* Implementation of call abi switching target hook. Specific to FNDECL
6339    the specific call register sets are set.  See also
6340    ix86_conditional_register_usage for more details.  */
6341 void
6342 ix86_call_abi_override (const_tree fndecl)
6343 {
6344   if (fndecl == NULL_TREE)
6345     cfun->machine->call_abi = ix86_abi;
6346   else
6347     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
6348 }
6349
6350 /* 64-bit MS and SYSV ABI have different set of call used registers.  Avoid
6351    expensive re-initialization of init_regs each time we switch function context
6352    since this is needed only during RTL expansion.  */
6353 static void
6354 ix86_maybe_switch_abi (void)
6355 {
6356   if (TARGET_64BIT &&
6357       call_used_regs[SI_REG] == (cfun->machine->call_abi == MS_ABI))
6358     reinit_regs ();
6359 }
6360
6361 /* Return 1 if pseudo register should be created and used to hold
6362    GOT address for PIC code.  */
6363 bool
6364 ix86_use_pseudo_pic_reg (void)
6365 {
6366   if ((TARGET_64BIT
6367        && (ix86_cmodel == CM_SMALL_PIC
6368            || TARGET_PECOFF))
6369       || !flag_pic)
6370     return false;
6371   return true;
6372 }
6373
6374 /* Initialize large model PIC register.  */
6375
6376 static void
6377 ix86_init_large_pic_reg (unsigned int tmp_regno)
6378 {
6379   rtx_code_label *label;
6380   rtx tmp_reg;
6381
6382   gcc_assert (Pmode == DImode);
6383   label = gen_label_rtx ();
6384   emit_label (label);
6385   LABEL_PRESERVE_P (label) = 1;
6386   tmp_reg = gen_rtx_REG (Pmode, tmp_regno);
6387   gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno);
6388   emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx,
6389                                 label));
6390   emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
6391   emit_insn (ix86_gen_add3 (pic_offset_table_rtx,
6392                             pic_offset_table_rtx, tmp_reg));
6393 }
6394
6395 /* Create and initialize PIC register if required.  */
6396 static void
6397 ix86_init_pic_reg (void)
6398 {
6399   edge entry_edge;
6400   rtx_insn *seq;
6401
6402   if (!ix86_use_pseudo_pic_reg ())
6403     return;
6404
6405   start_sequence ();
6406
6407   if (TARGET_64BIT)
6408     {
6409       if (ix86_cmodel == CM_LARGE_PIC)
6410         ix86_init_large_pic_reg (R11_REG);
6411       else
6412         emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
6413     }
6414   else
6415     {
6416       /*  If there is future mcount call in the function it is more profitable
6417           to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM.  */
6418       rtx reg = crtl->profile
6419                 ? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM)
6420                 : pic_offset_table_rtx;
6421       rtx_insn *insn = emit_insn (gen_set_got (reg));
6422       RTX_FRAME_RELATED_P (insn) = 1;
6423       if (crtl->profile)
6424         emit_move_insn (pic_offset_table_rtx, reg);
6425       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
6426     }
6427
6428   seq = get_insns ();
6429   end_sequence ();
6430
6431   entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6432   insert_insn_on_edge (seq, entry_edge);
6433   commit_one_edge_insertion (entry_edge);
6434 }
6435
6436 /* Initialize a variable CUM of type CUMULATIVE_ARGS
6437    for a call to a function whose data type is FNTYPE.
6438    For a library call, FNTYPE is 0.  */
6439
6440 void
6441 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
6442                       tree fntype,      /* tree ptr for function decl */
6443                       rtx libname,      /* SYMBOL_REF of library name or 0 */
6444                       tree fndecl,
6445                       int caller)
6446 {
6447   struct cgraph_local_info *i = NULL;
6448   struct cgraph_node *target = NULL;
6449
6450   memset (cum, 0, sizeof (*cum));
6451
6452   if (fndecl)
6453     {
6454       target = cgraph_node::get (fndecl);
6455       if (target)
6456         {
6457           target = target->function_symbol ();
6458           i = cgraph_node::local_info (target->decl);
6459           cum->call_abi = ix86_function_abi (target->decl);
6460         }
6461       else
6462         cum->call_abi = ix86_function_abi (fndecl);
6463     }
6464   else
6465     cum->call_abi = ix86_function_type_abi (fntype);
6466
6467   cum->caller = caller;
6468
6469   /* Set up the number of registers to use for passing arguments.  */
6470   cum->nregs = ix86_regparm;
6471   if (TARGET_64BIT)
6472     {
6473       cum->nregs = (cum->call_abi == SYSV_ABI
6474                    ? X86_64_REGPARM_MAX
6475                    : X86_64_MS_REGPARM_MAX);
6476     }
6477   if (TARGET_SSE)
6478     {
6479       cum->sse_nregs = SSE_REGPARM_MAX;
6480       if (TARGET_64BIT)
6481         {
6482           cum->sse_nregs = (cum->call_abi == SYSV_ABI
6483                            ? X86_64_SSE_REGPARM_MAX
6484                            : X86_64_MS_SSE_REGPARM_MAX);
6485         }
6486     }
6487   if (TARGET_MMX)
6488     cum->mmx_nregs = MMX_REGPARM_MAX;
6489   cum->warn_avx512f = true;
6490   cum->warn_avx = true;
6491   cum->warn_sse = true;
6492   cum->warn_mmx = true;
6493
6494   /* Because type might mismatch in between caller and callee, we need to
6495      use actual type of function for local calls.
6496      FIXME: cgraph_analyze can be told to actually record if function uses
6497      va_start so for local functions maybe_vaarg can be made aggressive
6498      helping K&R code.
6499      FIXME: once typesytem is fixed, we won't need this code anymore.  */
6500   if (i && i->local && i->can_change_signature)
6501     fntype = TREE_TYPE (target->decl);
6502   cum->stdarg = stdarg_p (fntype);
6503   cum->maybe_vaarg = (fntype
6504                       ? (!prototype_p (fntype) || stdarg_p (fntype))
6505                       : !libname);
6506
6507   cum->bnd_regno = FIRST_BND_REG;
6508   cum->bnds_in_bt = 0;
6509   cum->force_bnd_pass = 0;
6510   cum->decl = fndecl;
6511
6512   if (!TARGET_64BIT)
6513     {
6514       /* If there are variable arguments, then we won't pass anything
6515          in registers in 32-bit mode. */
6516       if (stdarg_p (fntype))
6517         {
6518           cum->nregs = 0;
6519           cum->sse_nregs = 0;
6520           cum->mmx_nregs = 0;
6521           cum->warn_avx512f = false;
6522           cum->warn_avx = false;
6523           cum->warn_sse = false;
6524           cum->warn_mmx = false;
6525           return;
6526         }
6527
6528       /* Use ecx and edx registers if function has fastcall attribute,
6529          else look for regparm information.  */
6530       if (fntype)
6531         {
6532           unsigned int ccvt = ix86_get_callcvt (fntype);
6533           if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
6534             {
6535               cum->nregs = 1;
6536               cum->fastcall = 1; /* Same first register as in fastcall.  */
6537             }
6538           else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
6539             {
6540               cum->nregs = 2;
6541               cum->fastcall = 1;
6542             }
6543           else
6544             cum->nregs = ix86_function_regparm (fntype, fndecl);
6545         }
6546
6547       /* Set up the number of SSE registers used for passing SFmode
6548          and DFmode arguments.  Warn for mismatching ABI.  */
6549       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
6550     }
6551 }
6552
6553 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
6554    But in the case of vector types, it is some vector mode.
6555
6556    When we have only some of our vector isa extensions enabled, then there
6557    are some modes for which vector_mode_supported_p is false.  For these
6558    modes, the generic vector support in gcc will choose some non-vector mode
6559    in order to implement the type.  By computing the natural mode, we'll
6560    select the proper ABI location for the operand and not depend on whatever
6561    the middle-end decides to do with these vector types.
6562
6563    The midde-end can't deal with the vector types > 16 bytes.  In this
6564    case, we return the original mode and warn ABI change if CUM isn't
6565    NULL. 
6566
6567    If INT_RETURN is true, warn ABI change if the vector mode isn't
6568    available for function return value.  */
6569
6570 static machine_mode
6571 type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum,
6572                    bool in_return)
6573 {
6574   machine_mode mode = TYPE_MODE (type);
6575
6576   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
6577     {
6578       HOST_WIDE_INT size = int_size_in_bytes (type);
6579       if ((size == 8 || size == 16 || size == 32 || size == 64)
6580           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
6581           && TYPE_VECTOR_SUBPARTS (type) > 1)
6582         {
6583           machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
6584
6585           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6586             mode = MIN_MODE_VECTOR_FLOAT;
6587           else
6588             mode = MIN_MODE_VECTOR_INT;
6589
6590           /* Get the mode which has this inner mode and number of units.  */
6591           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
6592             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
6593                 && GET_MODE_INNER (mode) == innermode)
6594               {
6595                 if (size == 64 && !TARGET_AVX512F)
6596                   {
6597                     static bool warnedavx512f;
6598                     static bool warnedavx512f_ret;
6599
6600                     if (cum && cum->warn_avx512f && !warnedavx512f)
6601                       {
6602                         if (warning (OPT_Wpsabi, "AVX512F vector argument "
6603                                      "without AVX512F enabled changes the ABI"))
6604                           warnedavx512f = true;
6605                       }
6606                     else if (in_return && !warnedavx512f_ret)
6607                       {
6608                         if (warning (OPT_Wpsabi, "AVX512F vector return "
6609                                      "without AVX512F enabled changes the ABI"))
6610                           warnedavx512f_ret = true;
6611                       }
6612
6613                     return TYPE_MODE (type);
6614                   }
6615                 else if (size == 32 && !TARGET_AVX)
6616                   {
6617                     static bool warnedavx;
6618                     static bool warnedavx_ret;
6619
6620                     if (cum && cum->warn_avx && !warnedavx)
6621                       {
6622                         if (warning (OPT_Wpsabi, "AVX vector argument "
6623                                      "without AVX enabled changes the ABI"))
6624                           warnedavx = true;
6625                       }
6626                     else if (in_return && !warnedavx_ret)
6627                       {
6628                         if (warning (OPT_Wpsabi, "AVX vector return "
6629                                      "without AVX enabled changes the ABI"))
6630                           warnedavx_ret = true;
6631                       }
6632
6633                     return TYPE_MODE (type);
6634                   }
6635                 else if (((size == 8 && TARGET_64BIT) || size == 16)
6636                          && !TARGET_SSE)
6637                   {
6638                     static bool warnedsse;
6639                     static bool warnedsse_ret;
6640
6641                     if (cum && cum->warn_sse && !warnedsse)
6642                       {
6643                         if (warning (OPT_Wpsabi, "SSE vector argument "
6644                                      "without SSE enabled changes the ABI"))
6645                           warnedsse = true;
6646                       }
6647                     else if (!TARGET_64BIT && in_return && !warnedsse_ret)
6648                       {
6649                         if (warning (OPT_Wpsabi, "SSE vector return "
6650                                      "without SSE enabled changes the ABI"))
6651                           warnedsse_ret = true;
6652                       }
6653                   }
6654                 else if ((size == 8 && !TARGET_64BIT) && !TARGET_MMX)
6655                   {
6656                     static bool warnedmmx;
6657                     static bool warnedmmx_ret;
6658
6659                     if (cum && cum->warn_mmx && !warnedmmx)
6660                       {
6661                         if (warning (OPT_Wpsabi, "MMX vector argument "
6662                                      "without MMX enabled changes the ABI"))
6663                           warnedmmx = true;
6664                       }
6665                     else if (in_return && !warnedmmx_ret)
6666                       {
6667                         if (warning (OPT_Wpsabi, "MMX vector return "
6668                                      "without MMX enabled changes the ABI"))
6669                           warnedmmx_ret = true;
6670                       }
6671                   }
6672                 return mode;
6673               }
6674
6675           gcc_unreachable ();
6676         }
6677     }
6678
6679   return mode;
6680 }
6681
6682 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
6683    this may not agree with the mode that the type system has chosen for the
6684    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
6685    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
6686
6687 static rtx
6688 gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode,
6689                      unsigned int regno)
6690 {
6691   rtx tmp;
6692
6693   if (orig_mode != BLKmode)
6694     tmp = gen_rtx_REG (orig_mode, regno);
6695   else
6696     {
6697       tmp = gen_rtx_REG (mode, regno);
6698       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
6699       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
6700     }
6701
6702   return tmp;
6703 }
6704
6705 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
6706    of this code is to classify each 8bytes of incoming argument by the register
6707    class and assign registers accordingly.  */
6708
6709 /* Return the union class of CLASS1 and CLASS2.
6710    See the x86-64 PS ABI for details.  */
6711
6712 static enum x86_64_reg_class
6713 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
6714 {
6715   /* Rule #1: If both classes are equal, this is the resulting class.  */
6716   if (class1 == class2)
6717     return class1;
6718
6719   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
6720      the other class.  */
6721   if (class1 == X86_64_NO_CLASS)
6722     return class2;
6723   if (class2 == X86_64_NO_CLASS)
6724     return class1;
6725
6726   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
6727   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
6728     return X86_64_MEMORY_CLASS;
6729
6730   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
6731   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
6732       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
6733     return X86_64_INTEGERSI_CLASS;
6734   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
6735       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
6736     return X86_64_INTEGER_CLASS;
6737
6738   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
6739      MEMORY is used.  */
6740   if (class1 == X86_64_X87_CLASS
6741       || class1 == X86_64_X87UP_CLASS
6742       || class1 == X86_64_COMPLEX_X87_CLASS
6743       || class2 == X86_64_X87_CLASS
6744       || class2 == X86_64_X87UP_CLASS
6745       || class2 == X86_64_COMPLEX_X87_CLASS)
6746     return X86_64_MEMORY_CLASS;
6747
6748   /* Rule #6: Otherwise class SSE is used.  */
6749   return X86_64_SSE_CLASS;
6750 }
6751
6752 /* Classify the argument of type TYPE and mode MODE.
6753    CLASSES will be filled by the register class used to pass each word
6754    of the operand.  The number of words is returned.  In case the parameter
6755    should be passed in memory, 0 is returned. As a special case for zero
6756    sized containers, classes[0] will be NO_CLASS and 1 is returned.
6757
6758    BIT_OFFSET is used internally for handling records and specifies offset
6759    of the offset in bits modulo 512 to avoid overflow cases.
6760
6761    See the x86-64 PS ABI for details.
6762 */
6763
6764 static int
6765 classify_argument (machine_mode mode, const_tree type,
6766                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
6767 {
6768   HOST_WIDE_INT bytes =
6769     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
6770   int words
6771     = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6772
6773   /* Variable sized entities are always passed/returned in memory.  */
6774   if (bytes < 0)
6775     return 0;
6776
6777   if (mode != VOIDmode
6778       && targetm.calls.must_pass_in_stack (mode, type))
6779     return 0;
6780
6781   if (type && AGGREGATE_TYPE_P (type))
6782     {
6783       int i;
6784       tree field;
6785       enum x86_64_reg_class subclasses[MAX_CLASSES];
6786
6787       /* On x86-64 we pass structures larger than 64 bytes on the stack.  */
6788       if (bytes > 64)
6789         return 0;
6790
6791       for (i = 0; i < words; i++)
6792         classes[i] = X86_64_NO_CLASS;
6793
6794       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
6795          signalize memory class, so handle it as special case.  */
6796       if (!words)
6797         {
6798           classes[0] = X86_64_NO_CLASS;
6799           return 1;
6800         }
6801
6802       /* Classify each field of record and merge classes.  */
6803       switch (TREE_CODE (type))
6804         {
6805         case RECORD_TYPE:
6806           /* And now merge the fields of structure.  */
6807           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6808             {
6809               if (TREE_CODE (field) == FIELD_DECL)
6810                 {
6811                   int num;
6812
6813                   if (TREE_TYPE (field) == error_mark_node)
6814                     continue;
6815
6816                   /* Bitfields are always classified as integer.  Handle them
6817                      early, since later code would consider them to be
6818                      misaligned integers.  */
6819                   if (DECL_BIT_FIELD (field))
6820                     {
6821                       for (i = (int_bit_position (field)
6822                                 + (bit_offset % 64)) / 8 / 8;
6823                            i < ((int_bit_position (field) + (bit_offset % 64))
6824                                 + tree_to_shwi (DECL_SIZE (field))
6825                                 + 63) / 8 / 8; i++)
6826                         classes[i] =
6827                           merge_classes (X86_64_INTEGER_CLASS,
6828                                          classes[i]);
6829                     }
6830                   else
6831                     {
6832                       int pos;
6833
6834                       type = TREE_TYPE (field);
6835
6836                       /* Flexible array member is ignored.  */
6837                       if (TYPE_MODE (type) == BLKmode
6838                           && TREE_CODE (type) == ARRAY_TYPE
6839                           && TYPE_SIZE (type) == NULL_TREE
6840                           && TYPE_DOMAIN (type) != NULL_TREE
6841                           && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6842                               == NULL_TREE))
6843                         {
6844                           static bool warned;
6845
6846                           if (!warned && warn_psabi)
6847                             {
6848                               warned = true;
6849                               inform (input_location,
6850                                       "the ABI of passing struct with"
6851                                       " a flexible array member has"
6852                                       " changed in GCC 4.4");
6853                             }
6854                           continue;
6855                         }
6856                       num = classify_argument (TYPE_MODE (type), type,
6857                                                subclasses,
6858                                                (int_bit_position (field)
6859                                                 + bit_offset) % 512);
6860                       if (!num)
6861                         return 0;
6862                       pos = (int_bit_position (field)
6863                              + (bit_offset % 64)) / 8 / 8;
6864                       for (i = 0; i < num && (i + pos) < words; i++)
6865                         classes[i + pos] =
6866                           merge_classes (subclasses[i], classes[i + pos]);
6867                     }
6868                 }
6869             }
6870           break;
6871
6872         case ARRAY_TYPE:
6873           /* Arrays are handled as small records.  */
6874           {
6875             int num;
6876             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
6877                                      TREE_TYPE (type), subclasses, bit_offset);
6878             if (!num)
6879               return 0;
6880
6881             /* The partial classes are now full classes.  */
6882             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
6883               subclasses[0] = X86_64_SSE_CLASS;
6884             if (subclasses[0] == X86_64_INTEGERSI_CLASS
6885                 && !((bit_offset % 64) == 0 && bytes == 4))
6886               subclasses[0] = X86_64_INTEGER_CLASS;
6887
6888             for (i = 0; i < words; i++)
6889               classes[i] = subclasses[i % num];
6890
6891             break;
6892           }
6893         case UNION_TYPE:
6894         case QUAL_UNION_TYPE:
6895           /* Unions are similar to RECORD_TYPE but offset is always 0.
6896              */
6897           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6898             {
6899               if (TREE_CODE (field) == FIELD_DECL)
6900                 {
6901                   int num;
6902
6903                   if (TREE_TYPE (field) == error_mark_node)
6904                     continue;
6905
6906                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
6907                                            TREE_TYPE (field), subclasses,
6908                                            bit_offset);
6909                   if (!num)
6910                     return 0;
6911                   for (i = 0; i < num && i < words; i++)
6912                     classes[i] = merge_classes (subclasses[i], classes[i]);
6913                 }
6914             }
6915           break;
6916
6917         default:
6918           gcc_unreachable ();
6919         }
6920
6921       if (words > 2)
6922         {
6923           /* When size > 16 bytes, if the first one isn't
6924              X86_64_SSE_CLASS or any other ones aren't
6925              X86_64_SSEUP_CLASS, everything should be passed in
6926              memory.  */
6927           if (classes[0] != X86_64_SSE_CLASS)
6928               return 0;
6929
6930           for (i = 1; i < words; i++)
6931             if (classes[i] != X86_64_SSEUP_CLASS)
6932               return 0;
6933         }
6934
6935       /* Final merger cleanup.  */
6936       for (i = 0; i < words; i++)
6937         {
6938           /* If one class is MEMORY, everything should be passed in
6939              memory.  */
6940           if (classes[i] == X86_64_MEMORY_CLASS)
6941             return 0;
6942
6943           /* The X86_64_SSEUP_CLASS should be always preceded by
6944              X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
6945           if (classes[i] == X86_64_SSEUP_CLASS
6946               && classes[i - 1] != X86_64_SSE_CLASS
6947               && classes[i - 1] != X86_64_SSEUP_CLASS)
6948             {
6949               /* The first one should never be X86_64_SSEUP_CLASS.  */
6950               gcc_assert (i != 0);
6951               classes[i] = X86_64_SSE_CLASS;
6952             }
6953
6954           /*  If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
6955                everything should be passed in memory.  */
6956           if (classes[i] == X86_64_X87UP_CLASS
6957               && (classes[i - 1] != X86_64_X87_CLASS))
6958             {
6959               static bool warned;
6960
6961               /* The first one should never be X86_64_X87UP_CLASS.  */
6962               gcc_assert (i != 0);
6963               if (!warned && warn_psabi)
6964                 {
6965                   warned = true;
6966                   inform (input_location,
6967                           "the ABI of passing union with long double"
6968                           " has changed in GCC 4.4");
6969                 }
6970               return 0;
6971             }
6972         }
6973       return words;
6974     }
6975
6976   /* Compute alignment needed.  We align all types to natural boundaries with
6977      exception of XFmode that is aligned to 64bits.  */
6978   if (mode != VOIDmode && mode != BLKmode)
6979     {
6980       int mode_alignment = GET_MODE_BITSIZE (mode);
6981
6982       if (mode == XFmode)
6983         mode_alignment = 128;
6984       else if (mode == XCmode)
6985         mode_alignment = 256;
6986       if (COMPLEX_MODE_P (mode))
6987         mode_alignment /= 2;
6988       /* Misaligned fields are always returned in memory.  */
6989       if (bit_offset % mode_alignment)
6990         return 0;
6991     }
6992
6993   /* for V1xx modes, just use the base mode */
6994   if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode
6995       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
6996     mode = GET_MODE_INNER (mode);
6997
6998   /* Classification of atomic types.  */
6999   switch (mode)
7000     {
7001     case SDmode:
7002     case DDmode:
7003       classes[0] = X86_64_SSE_CLASS;
7004       return 1;
7005     case TDmode:
7006       classes[0] = X86_64_SSE_CLASS;
7007       classes[1] = X86_64_SSEUP_CLASS;
7008       return 2;
7009     case DImode:
7010     case SImode:
7011     case HImode:
7012     case QImode:
7013     case CSImode:
7014     case CHImode:
7015     case CQImode:
7016       {
7017         int size = bit_offset + (int) GET_MODE_BITSIZE (mode);
7018
7019         /* Analyze last 128 bits only.  */
7020         size = (size - 1) & 0x7f;
7021
7022         if (size < 32)
7023           {
7024             classes[0] = X86_64_INTEGERSI_CLASS;
7025             return 1;
7026           }
7027         else if (size < 64)
7028           {
7029             classes[0] = X86_64_INTEGER_CLASS;
7030             return 1;
7031           }
7032         else if (size < 64+32)
7033           {
7034             classes[0] = X86_64_INTEGER_CLASS;
7035             classes[1] = X86_64_INTEGERSI_CLASS;
7036             return 2;
7037           }
7038         else if (size < 64+64)
7039           {
7040             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
7041             return 2;
7042           }
7043         else
7044           gcc_unreachable ();
7045       }
7046     case CDImode:
7047     case TImode:
7048       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
7049       return 2;
7050     case COImode:
7051     case OImode:
7052       /* OImode shouldn't be used directly.  */
7053       gcc_unreachable ();
7054     case CTImode:
7055       return 0;
7056     case SFmode:
7057       if (!(bit_offset % 64))
7058         classes[0] = X86_64_SSESF_CLASS;
7059       else
7060         classes[0] = X86_64_SSE_CLASS;
7061       return 1;
7062     case DFmode:
7063       classes[0] = X86_64_SSEDF_CLASS;
7064       return 1;
7065     case XFmode:
7066       classes[0] = X86_64_X87_CLASS;
7067       classes[1] = X86_64_X87UP_CLASS;
7068       return 2;
7069     case TFmode:
7070       classes[0] = X86_64_SSE_CLASS;
7071       classes[1] = X86_64_SSEUP_CLASS;
7072       return 2;
7073     case SCmode:
7074       classes[0] = X86_64_SSE_CLASS;
7075       if (!(bit_offset % 64))
7076         return 1;
7077       else
7078         {
7079           static bool warned;
7080
7081           if (!warned && warn_psabi)
7082             {
7083               warned = true;
7084               inform (input_location,
7085                       "the ABI of passing structure with complex float"
7086                       " member has changed in GCC 4.4");
7087             }
7088           classes[1] = X86_64_SSESF_CLASS;
7089           return 2;
7090         }
7091     case DCmode:
7092       classes[0] = X86_64_SSEDF_CLASS;
7093       classes[1] = X86_64_SSEDF_CLASS;
7094       return 2;
7095     case XCmode:
7096       classes[0] = X86_64_COMPLEX_X87_CLASS;
7097       return 1;
7098     case TCmode:
7099       /* This modes is larger than 16 bytes.  */
7100       return 0;
7101     case V8SFmode:
7102     case V8SImode:
7103     case V32QImode:
7104     case V16HImode:
7105     case V4DFmode:
7106     case V4DImode:
7107       classes[0] = X86_64_SSE_CLASS;
7108       classes[1] = X86_64_SSEUP_CLASS;
7109       classes[2] = X86_64_SSEUP_CLASS;
7110       classes[3] = X86_64_SSEUP_CLASS;
7111       return 4;
7112     case V8DFmode:
7113     case V16SFmode:
7114     case V8DImode:
7115     case V16SImode:
7116     case V32HImode:
7117     case V64QImode:
7118       classes[0] = X86_64_SSE_CLASS;
7119       classes[1] = X86_64_SSEUP_CLASS;
7120       classes[2] = X86_64_SSEUP_CLASS;
7121       classes[3] = X86_64_SSEUP_CLASS;
7122       classes[4] = X86_64_SSEUP_CLASS;
7123       classes[5] = X86_64_SSEUP_CLASS;
7124       classes[6] = X86_64_SSEUP_CLASS;
7125       classes[7] = X86_64_SSEUP_CLASS;
7126       return 8;
7127     case V4SFmode:
7128     case V4SImode:
7129     case V16QImode:
7130     case V8HImode:
7131     case V2DFmode:
7132     case V2DImode:
7133       classes[0] = X86_64_SSE_CLASS;
7134       classes[1] = X86_64_SSEUP_CLASS;
7135       return 2;
7136     case V1TImode:
7137     case V1DImode:
7138     case V2SFmode:
7139     case V2SImode:
7140     case V4HImode:
7141     case V8QImode:
7142       classes[0] = X86_64_SSE_CLASS;
7143       return 1;
7144     case BLKmode:
7145     case VOIDmode:
7146       return 0;
7147     default:
7148       gcc_assert (VECTOR_MODE_P (mode));
7149
7150       if (bytes > 16)
7151         return 0;
7152
7153       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
7154
7155       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
7156         classes[0] = X86_64_INTEGERSI_CLASS;
7157       else
7158         classes[0] = X86_64_INTEGER_CLASS;
7159       classes[1] = X86_64_INTEGER_CLASS;
7160       return 1 + (bytes > 8);
7161     }
7162 }
7163
7164 /* Examine the argument and return set number of register required in each
7165    class.  Return true iff parameter should be passed in memory.  */
7166
7167 static bool
7168 examine_argument (machine_mode mode, const_tree type, int in_return,
7169                   int *int_nregs, int *sse_nregs)
7170 {
7171   enum x86_64_reg_class regclass[MAX_CLASSES];
7172   int n = classify_argument (mode, type, regclass, 0);
7173
7174   *int_nregs = 0;
7175   *sse_nregs = 0;
7176
7177   if (!n)
7178     return true;
7179   for (n--; n >= 0; n--)
7180     switch (regclass[n])
7181       {
7182       case X86_64_INTEGER_CLASS:
7183       case X86_64_INTEGERSI_CLASS:
7184         (*int_nregs)++;
7185         break;
7186       case X86_64_SSE_CLASS:
7187       case X86_64_SSESF_CLASS:
7188       case X86_64_SSEDF_CLASS:
7189         (*sse_nregs)++;
7190         break;
7191       case X86_64_NO_CLASS:
7192       case X86_64_SSEUP_CLASS:
7193         break;
7194       case X86_64_X87_CLASS:
7195       case X86_64_X87UP_CLASS:
7196       case X86_64_COMPLEX_X87_CLASS:
7197         if (!in_return)
7198           return true;
7199         break;
7200       case X86_64_MEMORY_CLASS:
7201         gcc_unreachable ();
7202       }
7203
7204   return false;
7205 }
7206
7207 /* Construct container for the argument used by GCC interface.  See
7208    FUNCTION_ARG for the detailed description.  */
7209
7210 static rtx
7211 construct_container (machine_mode mode, machine_mode orig_mode,
7212                      const_tree type, int in_return, int nintregs, int nsseregs,
7213                      const int *intreg, int sse_regno)
7214 {
7215   /* The following variables hold the static issued_error state.  */
7216   static bool issued_sse_arg_error;
7217   static bool issued_sse_ret_error;
7218   static bool issued_x87_ret_error;
7219
7220   machine_mode tmpmode;
7221   int bytes =
7222     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
7223   enum x86_64_reg_class regclass[MAX_CLASSES];
7224   int n;
7225   int i;
7226   int nexps = 0;
7227   int needed_sseregs, needed_intregs;
7228   rtx exp[MAX_CLASSES];
7229   rtx ret;
7230
7231   n = classify_argument (mode, type, regclass, 0);
7232   if (!n)
7233     return NULL;
7234   if (examine_argument (mode, type, in_return, &needed_intregs,
7235                         &needed_sseregs))
7236     return NULL;
7237   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
7238     return NULL;
7239
7240   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
7241      some less clueful developer tries to use floating-point anyway.  */
7242   if (needed_sseregs && !TARGET_SSE)
7243     {
7244       if (in_return)
7245         {
7246           if (!issued_sse_ret_error)
7247             {
7248               error ("SSE register return with SSE disabled");
7249               issued_sse_ret_error = true;
7250             }
7251         }
7252       else if (!issued_sse_arg_error)
7253         {
7254           error ("SSE register argument with SSE disabled");
7255           issued_sse_arg_error = true;
7256         }
7257       return NULL;
7258     }
7259
7260   /* Likewise, error if the ABI requires us to return values in the
7261      x87 registers and the user specified -mno-80387.  */
7262   if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return)
7263     for (i = 0; i < n; i++)
7264       if (regclass[i] == X86_64_X87_CLASS
7265           || regclass[i] == X86_64_X87UP_CLASS
7266           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
7267         {
7268           if (!issued_x87_ret_error)
7269             {
7270               error ("x87 register return with x87 disabled");
7271               issued_x87_ret_error = true;
7272             }
7273           return NULL;
7274         }
7275
7276   /* First construct simple cases.  Avoid SCmode, since we want to use
7277      single register to pass this type.  */
7278   if (n == 1 && mode != SCmode)
7279     switch (regclass[0])
7280       {
7281       case X86_64_INTEGER_CLASS:
7282       case X86_64_INTEGERSI_CLASS:
7283         return gen_rtx_REG (mode, intreg[0]);
7284       case X86_64_SSE_CLASS:
7285       case X86_64_SSESF_CLASS:
7286       case X86_64_SSEDF_CLASS:
7287         if (mode != BLKmode)
7288           return gen_reg_or_parallel (mode, orig_mode,
7289                                       SSE_REGNO (sse_regno));
7290         break;
7291       case X86_64_X87_CLASS:
7292       case X86_64_COMPLEX_X87_CLASS:
7293         return gen_rtx_REG (mode, FIRST_STACK_REG);
7294       case X86_64_NO_CLASS:
7295         /* Zero sized array, struct or class.  */
7296         return NULL;
7297       default:
7298         gcc_unreachable ();
7299       }
7300   if (n == 2
7301       && regclass[0] == X86_64_SSE_CLASS
7302       && regclass[1] == X86_64_SSEUP_CLASS
7303       && mode != BLKmode)
7304     return gen_reg_or_parallel (mode, orig_mode,
7305                                 SSE_REGNO (sse_regno));
7306   if (n == 4
7307       && regclass[0] == X86_64_SSE_CLASS
7308       && regclass[1] == X86_64_SSEUP_CLASS
7309       && regclass[2] == X86_64_SSEUP_CLASS
7310       && regclass[3] == X86_64_SSEUP_CLASS
7311       && mode != BLKmode)
7312     return gen_reg_or_parallel (mode, orig_mode,
7313                                 SSE_REGNO (sse_regno));
7314   if (n == 8
7315       && regclass[0] == X86_64_SSE_CLASS
7316       && regclass[1] == X86_64_SSEUP_CLASS
7317       && regclass[2] == X86_64_SSEUP_CLASS
7318       && regclass[3] == X86_64_SSEUP_CLASS
7319       && regclass[4] == X86_64_SSEUP_CLASS
7320       && regclass[5] == X86_64_SSEUP_CLASS
7321       && regclass[6] == X86_64_SSEUP_CLASS
7322       && regclass[7] == X86_64_SSEUP_CLASS
7323       && mode != BLKmode)
7324     return gen_reg_or_parallel (mode, orig_mode,
7325                                 SSE_REGNO (sse_regno));
7326   if (n == 2
7327       && regclass[0] == X86_64_X87_CLASS
7328       && regclass[1] == X86_64_X87UP_CLASS)
7329     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
7330
7331   if (n == 2
7332       && regclass[0] == X86_64_INTEGER_CLASS
7333       && regclass[1] == X86_64_INTEGER_CLASS
7334       && (mode == CDImode || mode == TImode)
7335       && intreg[0] + 1 == intreg[1])
7336     return gen_rtx_REG (mode, intreg[0]);
7337
7338   /* Otherwise figure out the entries of the PARALLEL.  */
7339   for (i = 0; i < n; i++)
7340     {
7341       int pos;
7342
7343       switch (regclass[i])
7344         {
7345           case X86_64_NO_CLASS:
7346             break;
7347           case X86_64_INTEGER_CLASS:
7348           case X86_64_INTEGERSI_CLASS:
7349             /* Merge TImodes on aligned occasions here too.  */
7350             if (i * 8 + 8 > bytes)
7351               tmpmode
7352                 = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
7353             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
7354               tmpmode = SImode;
7355             else
7356               tmpmode = DImode;
7357             /* We've requested 24 bytes we
7358                don't have mode for.  Use DImode.  */
7359             if (tmpmode == BLKmode)
7360               tmpmode = DImode;
7361             exp [nexps++]
7362               = gen_rtx_EXPR_LIST (VOIDmode,
7363                                    gen_rtx_REG (tmpmode, *intreg),
7364                                    GEN_INT (i*8));
7365             intreg++;
7366             break;
7367           case X86_64_SSESF_CLASS:
7368             exp [nexps++]
7369               = gen_rtx_EXPR_LIST (VOIDmode,
7370                                    gen_rtx_REG (SFmode,
7371                                                 SSE_REGNO (sse_regno)),
7372                                    GEN_INT (i*8));
7373             sse_regno++;
7374             break;
7375           case X86_64_SSEDF_CLASS:
7376             exp [nexps++]
7377               = gen_rtx_EXPR_LIST (VOIDmode,
7378                                    gen_rtx_REG (DFmode,
7379                                                 SSE_REGNO (sse_regno)),
7380                                    GEN_INT (i*8));
7381             sse_regno++;
7382             break;
7383           case X86_64_SSE_CLASS:
7384             pos = i;
7385             switch (n)
7386               {
7387               case 1:
7388                 tmpmode = DImode;
7389                 break;
7390               case 2:
7391                 if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
7392                   {
7393                     tmpmode = TImode;
7394                     i++;
7395                   }
7396                 else
7397                   tmpmode = DImode;
7398                 break;
7399               case 4:
7400                 gcc_assert (i == 0
7401                             && regclass[1] == X86_64_SSEUP_CLASS
7402                             && regclass[2] == X86_64_SSEUP_CLASS
7403                             && regclass[3] == X86_64_SSEUP_CLASS);
7404                 tmpmode = OImode;
7405                 i += 3;
7406                 break;
7407               case 8:
7408                 gcc_assert (i == 0
7409                             && regclass[1] == X86_64_SSEUP_CLASS
7410                             && regclass[2] == X86_64_SSEUP_CLASS
7411                             && regclass[3] == X86_64_SSEUP_CLASS
7412                             && regclass[4] == X86_64_SSEUP_CLASS
7413                             && regclass[5] == X86_64_SSEUP_CLASS
7414                             && regclass[6] == X86_64_SSEUP_CLASS
7415                             && regclass[7] == X86_64_SSEUP_CLASS);
7416                 tmpmode = XImode;
7417                 i += 7;
7418                 break;
7419               default:
7420                 gcc_unreachable ();
7421               }
7422             exp [nexps++]
7423               = gen_rtx_EXPR_LIST (VOIDmode,
7424                                    gen_rtx_REG (tmpmode,
7425                                                 SSE_REGNO (sse_regno)),
7426                                    GEN_INT (pos*8));
7427             sse_regno++;
7428             break;
7429           default:
7430             gcc_unreachable ();
7431         }
7432     }
7433
7434   /* Empty aligned struct, union or class.  */
7435   if (nexps == 0)
7436     return NULL;
7437
7438   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
7439   for (i = 0; i < nexps; i++)
7440     XVECEXP (ret, 0, i) = exp [i];
7441   return ret;
7442 }
7443
7444 /* Update the data in CUM to advance over an argument of mode MODE
7445    and data type TYPE.  (TYPE is null for libcalls where that information
7446    may not be available.)
7447
7448    Return a number of integer regsiters advanced over.  */
7449
7450 static int
7451 function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
7452                          const_tree type, HOST_WIDE_INT bytes,
7453                          HOST_WIDE_INT words)
7454 {
7455   int res = 0;
7456   bool error_p = NULL;
7457
7458   switch (mode)
7459     {
7460     default:
7461       break;
7462
7463     case BLKmode:
7464       if (bytes < 0)
7465         break;
7466       /* FALLTHRU */
7467
7468     case DImode:
7469     case SImode:
7470     case HImode:
7471     case QImode:
7472       cum->words += words;
7473       cum->nregs -= words;
7474       cum->regno += words;
7475       if (cum->nregs >= 0)
7476         res = words;
7477       if (cum->nregs <= 0)
7478         {
7479           cum->nregs = 0;
7480           cum->regno = 0;
7481         }
7482       break;
7483
7484     case OImode:
7485       /* OImode shouldn't be used directly.  */
7486       gcc_unreachable ();
7487
7488     case DFmode:
7489       if (cum->float_in_sse == -1)
7490         error_p = 1;
7491       if (cum->float_in_sse < 2)
7492         break;
7493     case SFmode:
7494       if (cum->float_in_sse == -1)
7495         error_p = 1;
7496       if (cum->float_in_sse < 1)
7497         break;
7498       /* FALLTHRU */
7499
7500     case V8SFmode:
7501     case V8SImode:
7502     case V64QImode:
7503     case V32HImode:
7504     case V16SImode:
7505     case V8DImode:
7506     case V16SFmode:
7507     case V8DFmode:
7508     case V32QImode:
7509     case V16HImode:
7510     case V4DFmode:
7511     case V4DImode:
7512     case TImode:
7513     case V16QImode:
7514     case V8HImode:
7515     case V4SImode:
7516     case V2DImode:
7517     case V4SFmode:
7518     case V2DFmode:
7519       if (!type || !AGGREGATE_TYPE_P (type))
7520         {
7521           cum->sse_words += words;
7522           cum->sse_nregs -= 1;
7523           cum->sse_regno += 1;
7524           if (cum->sse_nregs <= 0)
7525             {
7526               cum->sse_nregs = 0;
7527               cum->sse_regno = 0;
7528             }
7529         }
7530       break;
7531
7532     case V8QImode:
7533     case V4HImode:
7534     case V2SImode:
7535     case V2SFmode:
7536     case V1TImode:
7537     case V1DImode:
7538       if (!type || !AGGREGATE_TYPE_P (type))
7539         {
7540           cum->mmx_words += words;
7541           cum->mmx_nregs -= 1;
7542           cum->mmx_regno += 1;
7543           if (cum->mmx_nregs <= 0)
7544             {
7545               cum->mmx_nregs = 0;
7546               cum->mmx_regno = 0;
7547             }
7548         }
7549       break;
7550     }
7551   if (error_p)
7552     {
7553       cum->float_in_sse = 0;
7554       error ("calling %qD with SSE calling convention without "
7555              "SSE/SSE2 enabled", cum->decl);
7556       sorry ("this is a GCC bug that can be worked around by adding "
7557              "attribute used to function called");
7558     }
7559
7560   return res;
7561 }
7562
7563 static int
7564 function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode,
7565                          const_tree type, HOST_WIDE_INT words, bool named)
7566 {
7567   int int_nregs, sse_nregs;
7568
7569   /* Unnamed 512 and 256bit vector mode parameters are passed on stack.  */
7570   if (!named && (VALID_AVX512F_REG_MODE (mode)
7571                  || VALID_AVX256_REG_MODE (mode)))
7572     return 0;
7573
7574   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
7575       && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
7576     {
7577       cum->nregs -= int_nregs;
7578       cum->sse_nregs -= sse_nregs;
7579       cum->regno += int_nregs;
7580       cum->sse_regno += sse_nregs;
7581       return int_nregs;
7582     }
7583   else
7584     {
7585       int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
7586       cum->words = (cum->words + align - 1) & ~(align - 1);
7587       cum->words += words;
7588       return 0;
7589     }
7590 }
7591
7592 static int
7593 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
7594                             HOST_WIDE_INT words)
7595 {
7596   /* Otherwise, this should be passed indirect.  */
7597   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
7598
7599   cum->words += words;
7600   if (cum->nregs > 0)
7601     {
7602       cum->nregs -= 1;
7603       cum->regno += 1;
7604       return 1;
7605     }
7606   return 0;
7607 }
7608
7609 /* Update the data in CUM to advance over an argument of mode MODE and
7610    data type TYPE.  (TYPE is null for libcalls where that information
7611    may not be available.)  */
7612
7613 static void
7614 ix86_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
7615                            const_tree type, bool named)
7616 {
7617   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7618   HOST_WIDE_INT bytes, words;
7619   int nregs;
7620
7621   if (mode == BLKmode)
7622     bytes = int_size_in_bytes (type);
7623   else
7624     bytes = GET_MODE_SIZE (mode);
7625   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7626
7627   if (type)
7628     mode = type_natural_mode (type, NULL, false);
7629
7630   if ((type && POINTER_BOUNDS_TYPE_P (type))
7631       || POINTER_BOUNDS_MODE_P (mode))
7632     {
7633       /* If we pass bounds in BT then just update remained bounds count.  */
7634       if (cum->bnds_in_bt)
7635         {
7636           cum->bnds_in_bt--;
7637           return;
7638         }
7639
7640       /* Update remained number of bounds to force.  */
7641       if (cum->force_bnd_pass)
7642         cum->force_bnd_pass--;
7643
7644       cum->bnd_regno++;
7645
7646       return;
7647     }
7648
7649   /* The first arg not going to Bounds Tables resets this counter.  */
7650   cum->bnds_in_bt = 0;
7651   /* For unnamed args we always pass bounds to avoid bounds mess when
7652      passed and received types do not match.  If bounds do not follow
7653      unnamed arg, still pretend required number of bounds were passed.  */
7654   if (cum->force_bnd_pass)
7655     {
7656       cum->bnd_regno += cum->force_bnd_pass;
7657       cum->force_bnd_pass = 0;
7658     }
7659
7660   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7661     nregs = function_arg_advance_ms_64 (cum, bytes, words);
7662   else if (TARGET_64BIT)
7663     nregs = function_arg_advance_64 (cum, mode, type, words, named);
7664   else
7665     nregs = function_arg_advance_32 (cum, mode, type, bytes, words);
7666
7667   /* For stdarg we expect bounds to be passed for each value passed
7668      in register.  */
7669   if (cum->stdarg)
7670     cum->force_bnd_pass = nregs;
7671   /* For pointers passed in memory we expect bounds passed in Bounds
7672      Table.  */
7673   if (!nregs)
7674     cum->bnds_in_bt = chkp_type_bounds_count (type);
7675 }
7676
7677 /* Define where to put the arguments to a function.
7678    Value is zero to push the argument on the stack,
7679    or a hard register in which to store the argument.
7680
7681    MODE is the argument's machine mode.
7682    TYPE is the data type of the argument (as a tree).
7683     This is null for libcalls where that information may
7684     not be available.
7685    CUM is a variable of type CUMULATIVE_ARGS which gives info about
7686     the preceding args and about the function being called.
7687    NAMED is nonzero if this argument is a named parameter
7688     (otherwise it is an extra parameter matching an ellipsis).  */
7689
7690 static rtx
7691 function_arg_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
7692                  machine_mode orig_mode, const_tree type,
7693                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
7694 {
7695   bool error_p = false;
7696   /* Avoid the AL settings for the Unix64 ABI.  */
7697   if (mode == VOIDmode)
7698     return constm1_rtx;
7699
7700   switch (mode)
7701     {
7702     default:
7703       break;
7704
7705     case BLKmode:
7706       if (bytes < 0)
7707         break;
7708       /* FALLTHRU */
7709     case DImode:
7710     case SImode:
7711     case HImode:
7712     case QImode:
7713       if (words <= cum->nregs)
7714         {
7715           int regno = cum->regno;
7716
7717           /* Fastcall allocates the first two DWORD (SImode) or
7718             smaller arguments to ECX and EDX if it isn't an
7719             aggregate type .  */
7720           if (cum->fastcall)
7721             {
7722               if (mode == BLKmode
7723                   || mode == DImode
7724                   || (type && AGGREGATE_TYPE_P (type)))
7725                 break;
7726
7727               /* ECX not EAX is the first allocated register.  */
7728               if (regno == AX_REG)
7729                 regno = CX_REG;
7730             }
7731           return gen_rtx_REG (mode, regno);
7732         }
7733       break;
7734
7735     case DFmode:
7736       if (cum->float_in_sse == -1)
7737         error_p = 1;
7738       if (cum->float_in_sse < 2)
7739         break;
7740     case SFmode:
7741       if (cum->float_in_sse == -1)
7742         error_p = 1;
7743       if (cum->float_in_sse < 1)
7744         break;
7745       /* FALLTHRU */
7746     case TImode:
7747       /* In 32bit, we pass TImode in xmm registers.  */
7748     case V16QImode:
7749     case V8HImode:
7750     case V4SImode:
7751     case V2DImode:
7752     case V4SFmode:
7753     case V2DFmode:
7754       if (!type || !AGGREGATE_TYPE_P (type))
7755         {
7756           if (cum->sse_nregs)
7757             return gen_reg_or_parallel (mode, orig_mode,
7758                                         cum->sse_regno + FIRST_SSE_REG);
7759         }
7760       break;
7761
7762     case OImode:
7763     case XImode:
7764       /* OImode and XImode shouldn't be used directly.  */
7765       gcc_unreachable ();
7766
7767     case V64QImode:
7768     case V32HImode:
7769     case V16SImode:
7770     case V8DImode:
7771     case V16SFmode:
7772     case V8DFmode:
7773     case V8SFmode:
7774     case V8SImode:
7775     case V32QImode:
7776     case V16HImode:
7777     case V4DFmode:
7778     case V4DImode:
7779       if (!type || !AGGREGATE_TYPE_P (type))
7780         {
7781           if (cum->sse_nregs)
7782             return gen_reg_or_parallel (mode, orig_mode,
7783                                         cum->sse_regno + FIRST_SSE_REG);
7784         }
7785       break;
7786
7787     case V8QImode:
7788     case V4HImode:
7789     case V2SImode:
7790     case V2SFmode:
7791     case V1TImode:
7792     case V1DImode:
7793       if (!type || !AGGREGATE_TYPE_P (type))
7794         {
7795           if (cum->mmx_nregs)
7796             return gen_reg_or_parallel (mode, orig_mode,
7797                                         cum->mmx_regno + FIRST_MMX_REG);
7798         }
7799       break;
7800     }
7801   if (error_p)
7802     {
7803       cum->float_in_sse = 0;
7804       error ("calling %qD with SSE calling convention without "
7805              "SSE/SSE2 enabled", cum->decl);
7806       sorry ("this is a GCC bug that can be worked around by adding "
7807              "attribute used to function called");
7808     }
7809
7810   return NULL_RTX;
7811 }
7812
7813 static rtx
7814 function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7815                  machine_mode orig_mode, const_tree type, bool named)
7816 {
7817   /* Handle a hidden AL argument containing number of registers
7818      for varargs x86-64 functions.  */
7819   if (mode == VOIDmode)
7820     return GEN_INT (cum->maybe_vaarg
7821                     ? (cum->sse_nregs < 0
7822                        ? X86_64_SSE_REGPARM_MAX
7823                        : cum->sse_regno)
7824                     : -1);
7825
7826   switch (mode)
7827     {
7828     default:
7829       break;
7830
7831     case V8SFmode:
7832     case V8SImode:
7833     case V32QImode:
7834     case V16HImode:
7835     case V4DFmode:
7836     case V4DImode:
7837     case V16SFmode:
7838     case V16SImode:
7839     case V64QImode:
7840     case V32HImode:
7841     case V8DFmode:
7842     case V8DImode:
7843       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
7844       if (!named)
7845         return NULL;
7846       break;
7847     }
7848
7849   return construct_container (mode, orig_mode, type, 0, cum->nregs,
7850                               cum->sse_nregs,
7851                               &x86_64_int_parameter_registers [cum->regno],
7852                               cum->sse_regno);
7853 }
7854
7855 static rtx
7856 function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7857                     machine_mode orig_mode, bool named,
7858                     HOST_WIDE_INT bytes)
7859 {
7860   unsigned int regno;
7861
7862   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
7863      We use value of -2 to specify that current function call is MSABI.  */
7864   if (mode == VOIDmode)
7865     return GEN_INT (-2);
7866
7867   /* If we've run out of registers, it goes on the stack.  */
7868   if (cum->nregs == 0)
7869     return NULL_RTX;
7870
7871   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
7872
7873   /* Only floating point modes are passed in anything but integer regs.  */
7874   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
7875     {
7876       if (named)
7877         regno = cum->regno + FIRST_SSE_REG;
7878       else
7879         {
7880           rtx t1, t2;
7881
7882           /* Unnamed floating parameters are passed in both the
7883              SSE and integer registers.  */
7884           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
7885           t2 = gen_rtx_REG (mode, regno);
7886           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
7887           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
7888           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
7889         }
7890     }
7891   /* Handle aggregated types passed in register.  */
7892   if (orig_mode == BLKmode)
7893     {
7894       if (bytes > 0 && bytes <= 8)
7895         mode = (bytes > 4 ? DImode : SImode);
7896       if (mode == BLKmode)
7897         mode = DImode;
7898     }
7899
7900   return gen_reg_or_parallel (mode, orig_mode, regno);
7901 }
7902
7903 /* Return where to put the arguments to a function.
7904    Return zero to push the argument on the stack, or a hard register in which to store the argument.
7905
7906    MODE is the argument's machine mode.  TYPE is the data type of the
7907    argument.  It is null for libcalls where that information may not be
7908    available.  CUM gives information about the preceding args and about
7909    the function being called.  NAMED is nonzero if this argument is a
7910    named parameter (otherwise it is an extra parameter matching an
7911    ellipsis).  */
7912
7913 static rtx
7914 ix86_function_arg (cumulative_args_t cum_v, machine_mode omode,
7915                    const_tree type, bool named)
7916 {
7917   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7918   machine_mode mode = omode;
7919   HOST_WIDE_INT bytes, words;
7920   rtx arg;
7921
7922   /* All pointer bounds argumntas are handled separately here.  */
7923   if ((type && POINTER_BOUNDS_TYPE_P (type))
7924       || POINTER_BOUNDS_MODE_P (mode))
7925     {
7926       /* Return NULL if bounds are forced to go in Bounds Table.  */
7927       if (cum->bnds_in_bt)
7928         arg = NULL;
7929       /* Return the next available bound reg if any.  */
7930       else if (cum->bnd_regno <= LAST_BND_REG)
7931         arg = gen_rtx_REG (BNDmode, cum->bnd_regno);
7932       /* Return the next special slot number otherwise.  */
7933       else
7934         arg = GEN_INT (cum->bnd_regno - LAST_BND_REG - 1);
7935
7936       return arg;
7937     }
7938
7939   if (mode == BLKmode)
7940     bytes = int_size_in_bytes (type);
7941   else
7942     bytes = GET_MODE_SIZE (mode);
7943   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7944
7945   /* To simplify the code below, represent vector types with a vector mode
7946      even if MMX/SSE are not active.  */
7947   if (type && TREE_CODE (type) == VECTOR_TYPE)
7948     mode = type_natural_mode (type, cum, false);
7949
7950   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7951     arg = function_arg_ms_64 (cum, mode, omode, named, bytes);
7952   else if (TARGET_64BIT)
7953     arg = function_arg_64 (cum, mode, omode, type, named);
7954   else
7955     arg = function_arg_32 (cum, mode, omode, type, bytes, words);
7956
7957   return arg;
7958 }
7959
7960 /* A C expression that indicates when an argument must be passed by
7961    reference.  If nonzero for an argument, a copy of that argument is
7962    made in memory and a pointer to the argument is passed instead of
7963    the argument itself.  The pointer is passed in whatever way is
7964    appropriate for passing a pointer to that type.  */
7965
7966 static bool
7967 ix86_pass_by_reference (cumulative_args_t cum_v, machine_mode mode,
7968                         const_tree type, bool)
7969 {
7970   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7971
7972   /* Bounds are never passed by reference.  */
7973   if ((type && POINTER_BOUNDS_TYPE_P (type))
7974       || POINTER_BOUNDS_MODE_P (mode))
7975     return false;
7976
7977   /* See Windows x64 Software Convention.  */
7978   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7979     {
7980       int msize = (int) GET_MODE_SIZE (mode);
7981       if (type)
7982         {
7983           /* Arrays are passed by reference.  */
7984           if (TREE_CODE (type) == ARRAY_TYPE)
7985             return true;
7986
7987           if (AGGREGATE_TYPE_P (type))
7988             {
7989               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
7990                  are passed by reference.  */
7991               msize = int_size_in_bytes (type);
7992             }
7993         }
7994
7995       /* __m128 is passed by reference.  */
7996       switch (msize) {
7997       case 1: case 2: case 4: case 8:
7998         break;
7999       default:
8000         return true;
8001       }
8002     }
8003   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
8004     return 1;
8005
8006   return 0;
8007 }
8008
8009 /* Return true when TYPE should be 128bit aligned for 32bit argument
8010    passing ABI.  XXX: This function is obsolete and is only used for
8011    checking psABI compatibility with previous versions of GCC.  */
8012
8013 static bool
8014 ix86_compat_aligned_value_p (const_tree type)
8015 {
8016   machine_mode mode = TYPE_MODE (type);
8017   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
8018        || mode == TDmode
8019        || mode == TFmode
8020        || mode == TCmode)
8021       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
8022     return true;
8023   if (TYPE_ALIGN (type) < 128)
8024     return false;
8025
8026   if (AGGREGATE_TYPE_P (type))
8027     {
8028       /* Walk the aggregates recursively.  */
8029       switch (TREE_CODE (type))
8030         {
8031         case RECORD_TYPE:
8032         case UNION_TYPE:
8033         case QUAL_UNION_TYPE:
8034           {
8035             tree field;
8036
8037             /* Walk all the structure fields.  */
8038             for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
8039               {
8040                 if (TREE_CODE (field) == FIELD_DECL
8041                     && ix86_compat_aligned_value_p (TREE_TYPE (field)))
8042                   return true;
8043               }
8044             break;
8045           }
8046
8047         case ARRAY_TYPE:
8048           /* Just for use if some languages passes arrays by value.  */
8049           if (ix86_compat_aligned_value_p (TREE_TYPE (type)))
8050             return true;
8051           break;
8052
8053         default:
8054           gcc_unreachable ();
8055         }
8056     }
8057   return false;
8058 }
8059
8060 /* Return the alignment boundary for MODE and TYPE with alignment ALIGN.
8061    XXX: This function is obsolete and is only used for checking psABI
8062    compatibility with previous versions of GCC.  */
8063
8064 static unsigned int
8065 ix86_compat_function_arg_boundary (machine_mode mode,
8066                                    const_tree type, unsigned int align)
8067 {
8068   /* In 32bit, only _Decimal128 and __float128 are aligned to their
8069      natural boundaries.  */
8070   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
8071     {
8072       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
8073          make an exception for SSE modes since these require 128bit
8074          alignment.
8075
8076          The handling here differs from field_alignment.  ICC aligns MMX
8077          arguments to 4 byte boundaries, while structure fields are aligned
8078          to 8 byte boundaries.  */
8079       if (!type)
8080         {
8081           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
8082             align = PARM_BOUNDARY;
8083         }
8084       else
8085         {
8086           if (!ix86_compat_aligned_value_p (type))
8087             align = PARM_BOUNDARY;
8088         }
8089     }
8090   if (align > BIGGEST_ALIGNMENT)
8091     align = BIGGEST_ALIGNMENT;
8092   return align;
8093 }
8094
8095 /* Return true when TYPE should be 128bit aligned for 32bit argument
8096    passing ABI.  */
8097
8098 static bool
8099 ix86_contains_aligned_value_p (const_tree type)
8100 {
8101   machine_mode mode = TYPE_MODE (type);
8102
8103   if (mode == XFmode || mode == XCmode)
8104     return false;
8105
8106   if (TYPE_ALIGN (type) < 128)
8107     return false;
8108
8109   if (AGGREGATE_TYPE_P (type))
8110     {
8111       /* Walk the aggregates recursively.  */
8112       switch (TREE_CODE (type))
8113         {
8114         case RECORD_TYPE:
8115         case UNION_TYPE:
8116         case QUAL_UNION_TYPE:
8117           {
8118             tree field;
8119
8120             /* Walk all the structure fields.  */
8121             for (field = TYPE_FIELDS (type);
8122                  field;
8123                  field = DECL_CHAIN (field))
8124               {
8125                 if (TREE_CODE (field) == FIELD_DECL
8126                     && ix86_contains_aligned_value_p (TREE_TYPE (field)))
8127                   return true;
8128               }
8129             break;
8130           }
8131
8132         case ARRAY_TYPE:
8133           /* Just for use if some languages passes arrays by value.  */
8134           if (ix86_contains_aligned_value_p (TREE_TYPE (type)))
8135             return true;
8136           break;
8137
8138         default:
8139           gcc_unreachable ();
8140         }
8141     }
8142   else
8143     return TYPE_ALIGN (type) >= 128;
8144
8145   return false;
8146 }
8147
8148 /* Gives the alignment boundary, in bits, of an argument with the
8149    specified mode and type.  */
8150
8151 static unsigned int
8152 ix86_function_arg_boundary (machine_mode mode, const_tree type)
8153 {
8154   unsigned int align;
8155   if (type)
8156     {
8157       /* Since the main variant type is used for call, we convert it to
8158          the main variant type.  */
8159       type = TYPE_MAIN_VARIANT (type);
8160       align = TYPE_ALIGN (type);
8161     }
8162   else
8163     align = GET_MODE_ALIGNMENT (mode);
8164   if (align < PARM_BOUNDARY)
8165     align = PARM_BOUNDARY;
8166   else
8167     {
8168       static bool warned;
8169       unsigned int saved_align = align;
8170
8171       if (!TARGET_64BIT)
8172         {
8173           /* i386 ABI defines XFmode arguments to be 4 byte aligned.  */
8174           if (!type)
8175             {
8176               if (mode == XFmode || mode == XCmode)
8177                 align = PARM_BOUNDARY;
8178             }
8179           else if (!ix86_contains_aligned_value_p (type))
8180             align = PARM_BOUNDARY;
8181
8182           if (align < 128)
8183             align = PARM_BOUNDARY;
8184         }
8185
8186       if (warn_psabi
8187           && !warned
8188           && align != ix86_compat_function_arg_boundary (mode, type,
8189                                                          saved_align))
8190         {
8191           warned = true;
8192           inform (input_location,
8193                   "The ABI for passing parameters with %d-byte"
8194                   " alignment has changed in GCC 4.6",
8195                   align / BITS_PER_UNIT);
8196         }
8197     }
8198
8199   return align;
8200 }
8201
8202 /* Return true if N is a possible register number of function value.  */
8203
8204 static bool
8205 ix86_function_value_regno_p (const unsigned int regno)
8206 {
8207   switch (regno)
8208     {
8209     case AX_REG:
8210       return true;
8211     case DX_REG:
8212       return (!TARGET_64BIT || ix86_cfun_abi () != MS_ABI);
8213     case DI_REG:
8214     case SI_REG:
8215       return TARGET_64BIT && ix86_cfun_abi () != MS_ABI;
8216
8217     case BND0_REG:
8218     case BND1_REG:
8219       return chkp_function_instrumented_p (current_function_decl);
8220
8221       /* Complex values are returned in %st(0)/%st(1) pair.  */
8222     case ST0_REG:
8223     case ST1_REG:
8224       /* TODO: The function should depend on current function ABI but
8225        builtins.c would need updating then. Therefore we use the
8226        default ABI.  */
8227       if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
8228         return false;
8229       return TARGET_FLOAT_RETURNS_IN_80387;
8230
8231       /* Complex values are returned in %xmm0/%xmm1 pair.  */
8232     case XMM0_REG:
8233     case XMM1_REG:
8234       return TARGET_SSE;
8235
8236     case MM0_REG:
8237       if (TARGET_MACHO || TARGET_64BIT)
8238         return false;
8239       return TARGET_MMX;
8240     }
8241
8242   return false;
8243 }
8244
8245 /* Define how to find the value returned by a function.
8246    VALTYPE is the data type of the value (as a tree).
8247    If the precise function being called is known, FUNC is its FUNCTION_DECL;
8248    otherwise, FUNC is 0.  */
8249
8250 static rtx
8251 function_value_32 (machine_mode orig_mode, machine_mode mode,
8252                    const_tree fntype, const_tree fn)
8253 {
8254   unsigned int regno;
8255
8256   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
8257      we normally prevent this case when mmx is not available.  However
8258      some ABIs may require the result to be returned like DImode.  */
8259   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
8260     regno = FIRST_MMX_REG;
8261
8262   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
8263      we prevent this case when sse is not available.  However some ABIs
8264      may require the result to be returned like integer TImode.  */
8265   else if (mode == TImode
8266            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
8267     regno = FIRST_SSE_REG;
8268
8269   /* 32-byte vector modes in %ymm0.   */
8270   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
8271     regno = FIRST_SSE_REG;
8272
8273   /* 64-byte vector modes in %zmm0.   */
8274   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
8275     regno = FIRST_SSE_REG;
8276
8277   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
8278   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
8279     regno = FIRST_FLOAT_REG;
8280   else
8281     /* Most things go in %eax.  */
8282     regno = AX_REG;
8283
8284   /* Override FP return register with %xmm0 for local functions when
8285      SSE math is enabled or for functions with sseregparm attribute.  */
8286   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
8287     {
8288       int sse_level = ix86_function_sseregparm (fntype, fn, false);
8289       if (sse_level == -1)
8290         {
8291           error ("calling %qD with SSE caling convention without "
8292                  "SSE/SSE2 enabled", fn);
8293           sorry ("this is a GCC bug that can be worked around by adding "
8294                  "attribute used to function called");
8295         }
8296       else if ((sse_level >= 1 && mode == SFmode)
8297                || (sse_level == 2 && mode == DFmode))
8298         regno = FIRST_SSE_REG;
8299     }
8300
8301   /* OImode shouldn't be used directly.  */
8302   gcc_assert (mode != OImode);
8303
8304   return gen_rtx_REG (orig_mode, regno);
8305 }
8306
8307 static rtx
8308 function_value_64 (machine_mode orig_mode, machine_mode mode,
8309                    const_tree valtype)
8310 {
8311   rtx ret;
8312
8313   /* Handle libcalls, which don't provide a type node.  */
8314   if (valtype == NULL)
8315     {
8316       unsigned int regno;
8317
8318       switch (mode)
8319         {
8320         case SFmode:
8321         case SCmode:
8322         case DFmode:
8323         case DCmode:
8324         case TFmode:
8325         case SDmode:
8326         case DDmode:
8327         case TDmode:
8328           regno = FIRST_SSE_REG;
8329           break;
8330         case XFmode:
8331         case XCmode:
8332           regno = FIRST_FLOAT_REG;
8333           break;
8334         case TCmode:
8335           return NULL;
8336         default:
8337           regno = AX_REG;
8338         }
8339
8340       return gen_rtx_REG (mode, regno);
8341     }
8342   else if (POINTER_TYPE_P (valtype))
8343     {
8344       /* Pointers are always returned in word_mode.  */
8345       mode = word_mode;
8346     }
8347
8348   ret = construct_container (mode, orig_mode, valtype, 1,
8349                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
8350                              x86_64_int_return_registers, 0);
8351
8352   /* For zero sized structures, construct_container returns NULL, but we
8353      need to keep rest of compiler happy by returning meaningful value.  */
8354   if (!ret)
8355     ret = gen_rtx_REG (orig_mode, AX_REG);
8356
8357   return ret;
8358 }
8359
8360 static rtx
8361 function_value_ms_64 (machine_mode orig_mode, machine_mode mode,
8362                       const_tree valtype)
8363 {
8364   unsigned int regno = AX_REG;
8365
8366   if (TARGET_SSE)
8367     {
8368       switch (GET_MODE_SIZE (mode))
8369         {
8370         case 16:
8371           if (valtype != NULL_TREE
8372               && !VECTOR_INTEGER_TYPE_P (valtype)
8373               && !VECTOR_INTEGER_TYPE_P (valtype)
8374               && !INTEGRAL_TYPE_P (valtype)
8375               && !VECTOR_FLOAT_TYPE_P (valtype))
8376             break;
8377           if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
8378               && !COMPLEX_MODE_P (mode))
8379             regno = FIRST_SSE_REG;
8380           break;
8381         case 8:
8382         case 4:
8383           if (mode == SFmode || mode == DFmode)
8384             regno = FIRST_SSE_REG;
8385           break;
8386         default:
8387           break;
8388         }
8389     }
8390   return gen_rtx_REG (orig_mode, regno);
8391 }
8392
8393 static rtx
8394 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
8395                        machine_mode orig_mode, machine_mode mode)
8396 {
8397   const_tree fn, fntype;
8398
8399   fn = NULL_TREE;
8400   if (fntype_or_decl && DECL_P (fntype_or_decl))
8401     fn = fntype_or_decl;
8402   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
8403
8404   if ((valtype && POINTER_BOUNDS_TYPE_P (valtype))
8405       || POINTER_BOUNDS_MODE_P (mode))
8406     return gen_rtx_REG (BNDmode, FIRST_BND_REG);
8407   else if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
8408     return function_value_ms_64 (orig_mode, mode, valtype);
8409   else if (TARGET_64BIT)
8410     return function_value_64 (orig_mode, mode, valtype);
8411   else
8412     return function_value_32 (orig_mode, mode, fntype, fn);
8413 }
8414
8415 static rtx
8416 ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool)
8417 {
8418   machine_mode mode, orig_mode;
8419
8420   orig_mode = TYPE_MODE (valtype);
8421   mode = type_natural_mode (valtype, NULL, true);
8422   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
8423 }
8424
8425 /*  Return an RTX representing a place where a function returns
8426     or recieves pointer bounds or NULL if no bounds are returned.
8427
8428     VALTYPE is a data type of a value returned by the function.
8429
8430     FN_DECL_OR_TYPE is a tree node representing FUNCTION_DECL
8431     or FUNCTION_TYPE of the function.
8432
8433     If OUTGOING is false, return a place in which the caller will
8434     see the return value.  Otherwise, return a place where a
8435     function returns a value.  */
8436
8437 static rtx
8438 ix86_function_value_bounds (const_tree valtype,
8439                             const_tree fntype_or_decl ATTRIBUTE_UNUSED,
8440                             bool outgoing ATTRIBUTE_UNUSED)
8441 {
8442   rtx res = NULL_RTX;
8443
8444   if (BOUNDED_TYPE_P (valtype))
8445     res = gen_rtx_REG (BNDmode, FIRST_BND_REG);
8446   else if (chkp_type_has_pointer (valtype))
8447     {
8448       bitmap slots;
8449       rtx bounds[2];
8450       bitmap_iterator bi;
8451       unsigned i, bnd_no = 0;
8452
8453       bitmap_obstack_initialize (NULL);
8454       slots = BITMAP_ALLOC (NULL);
8455       chkp_find_bound_slots (valtype, slots);
8456
8457       EXECUTE_IF_SET_IN_BITMAP (slots, 0, i, bi)
8458         {
8459           rtx reg = gen_rtx_REG (BNDmode, FIRST_BND_REG + bnd_no);
8460           rtx offs = GEN_INT (i * POINTER_SIZE / BITS_PER_UNIT);
8461           gcc_assert (bnd_no < 2);
8462           bounds[bnd_no++] = gen_rtx_EXPR_LIST (VOIDmode, reg, offs);
8463         }
8464
8465       res = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (bnd_no, bounds));
8466
8467       BITMAP_FREE (slots);
8468       bitmap_obstack_release (NULL);
8469     }
8470   else
8471     res = NULL_RTX;
8472
8473   return res;
8474 }
8475
8476 /* Pointer function arguments and return values are promoted to
8477    word_mode.  */
8478
8479 static machine_mode
8480 ix86_promote_function_mode (const_tree type, machine_mode mode,
8481                             int *punsignedp, const_tree fntype,
8482                             int for_return)
8483 {
8484   if (type != NULL_TREE && POINTER_TYPE_P (type))
8485     {
8486       *punsignedp = POINTERS_EXTEND_UNSIGNED;
8487       return word_mode;
8488     }
8489   return default_promote_function_mode (type, mode, punsignedp, fntype,
8490                                         for_return);
8491 }
8492
8493 /* Return true if a structure, union or array with MODE containing FIELD
8494    should be accessed using BLKmode.  */
8495
8496 static bool
8497 ix86_member_type_forces_blk (const_tree field, machine_mode mode)
8498 {
8499   /* Union with XFmode must be in BLKmode.  */
8500   return (mode == XFmode
8501           && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE
8502               || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE));
8503 }
8504
8505 rtx
8506 ix86_libcall_value (machine_mode mode)
8507 {
8508   return ix86_function_value_1 (NULL, NULL, mode, mode);
8509 }
8510
8511 /* Return true iff type is returned in memory.  */
8512
8513 static bool
8514 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
8515 {
8516 #ifdef SUBTARGET_RETURN_IN_MEMORY
8517   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
8518 #else
8519   const machine_mode mode = type_natural_mode (type, NULL, true);
8520   HOST_WIDE_INT size;
8521
8522   if (POINTER_BOUNDS_TYPE_P (type))
8523     return false;
8524
8525   if (TARGET_64BIT)
8526     {
8527       if (ix86_function_type_abi (fntype) == MS_ABI)
8528         {
8529           size = int_size_in_bytes (type);
8530
8531           /* __m128 is returned in xmm0.  */
8532           if ((!type || VECTOR_INTEGER_TYPE_P (type)
8533                || INTEGRAL_TYPE_P (type)
8534                || VECTOR_FLOAT_TYPE_P (type))
8535               && (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
8536               && !COMPLEX_MODE_P (mode)
8537               && (GET_MODE_SIZE (mode) == 16 || size == 16))
8538             return false;
8539
8540           /* Otherwise, the size must be exactly in [1248]. */
8541           return size != 1 && size != 2 && size != 4 && size != 8;
8542         }
8543       else
8544         {
8545           int needed_intregs, needed_sseregs;
8546
8547           return examine_argument (mode, type, 1,
8548                                    &needed_intregs, &needed_sseregs);
8549         }
8550     }
8551   else
8552     {
8553       if (mode == BLKmode)
8554         return true;
8555
8556       size = int_size_in_bytes (type);
8557
8558       if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
8559         return false;
8560
8561       if (VECTOR_MODE_P (mode) || mode == TImode)
8562         {
8563           /* User-created vectors small enough to fit in EAX.  */
8564           if (size < 8)
8565             return false;
8566
8567           /* Unless ABI prescibes otherwise,
8568              MMX/3dNow values are returned in MM0 if available.  */
8569              
8570           if (size == 8)
8571             return TARGET_VECT8_RETURNS || !TARGET_MMX;
8572
8573           /* SSE values are returned in XMM0 if available.  */
8574           if (size == 16)
8575             return !TARGET_SSE;
8576
8577           /* AVX values are returned in YMM0 if available.  */
8578           if (size == 32)
8579             return !TARGET_AVX;
8580
8581           /* AVX512F values are returned in ZMM0 if available.  */
8582           if (size == 64)
8583             return !TARGET_AVX512F;
8584         }
8585
8586       if (mode == XFmode)
8587         return false;
8588
8589       if (size > 12)
8590         return true;
8591
8592       /* OImode shouldn't be used directly.  */
8593       gcc_assert (mode != OImode);
8594
8595       return false;
8596     }
8597 #endif
8598 }
8599
8600 \f
8601 /* Create the va_list data type.  */
8602
8603 /* Returns the calling convention specific va_list date type.
8604    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
8605
8606 static tree
8607 ix86_build_builtin_va_list_abi (enum calling_abi abi)
8608 {
8609   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
8610
8611   /* For i386 we use plain pointer to argument area.  */
8612   if (!TARGET_64BIT || abi == MS_ABI)
8613     return build_pointer_type (char_type_node);
8614
8615   record = lang_hooks.types.make_type (RECORD_TYPE);
8616   type_decl = build_decl (BUILTINS_LOCATION,
8617                           TYPE_DECL, get_identifier ("__va_list_tag"), record);
8618
8619   f_gpr = build_decl (BUILTINS_LOCATION,
8620                       FIELD_DECL, get_identifier ("gp_offset"),
8621                       unsigned_type_node);
8622   f_fpr = build_decl (BUILTINS_LOCATION,
8623                       FIELD_DECL, get_identifier ("fp_offset"),
8624                       unsigned_type_node);
8625   f_ovf = build_decl (BUILTINS_LOCATION,
8626                       FIELD_DECL, get_identifier ("overflow_arg_area"),
8627                       ptr_type_node);
8628   f_sav = build_decl (BUILTINS_LOCATION,
8629                       FIELD_DECL, get_identifier ("reg_save_area"),
8630                       ptr_type_node);
8631
8632   va_list_gpr_counter_field = f_gpr;
8633   va_list_fpr_counter_field = f_fpr;
8634
8635   DECL_FIELD_CONTEXT (f_gpr) = record;
8636   DECL_FIELD_CONTEXT (f_fpr) = record;
8637   DECL_FIELD_CONTEXT (f_ovf) = record;
8638   DECL_FIELD_CONTEXT (f_sav) = record;
8639
8640   TYPE_STUB_DECL (record) = type_decl;
8641   TYPE_NAME (record) = type_decl;
8642   TYPE_FIELDS (record) = f_gpr;
8643   DECL_CHAIN (f_gpr) = f_fpr;
8644   DECL_CHAIN (f_fpr) = f_ovf;
8645   DECL_CHAIN (f_ovf) = f_sav;
8646
8647   layout_type (record);
8648
8649   /* The correct type is an array type of one element.  */
8650   return build_array_type (record, build_index_type (size_zero_node));
8651 }
8652
8653 /* Setup the builtin va_list data type and for 64-bit the additional
8654    calling convention specific va_list data types.  */
8655
8656 static tree
8657 ix86_build_builtin_va_list (void)
8658 {
8659   tree ret = ix86_build_builtin_va_list_abi (ix86_abi);
8660
8661   /* Initialize abi specific va_list builtin types.  */
8662   if (TARGET_64BIT)
8663     {
8664       tree t;
8665       if (ix86_abi == MS_ABI)
8666         {
8667           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
8668           if (TREE_CODE (t) != RECORD_TYPE)
8669             t = build_variant_type_copy (t);
8670           sysv_va_list_type_node = t;
8671         }
8672       else
8673         {
8674           t = ret;
8675           if (TREE_CODE (t) != RECORD_TYPE)
8676             t = build_variant_type_copy (t);
8677           sysv_va_list_type_node = t;
8678         }
8679       if (ix86_abi != MS_ABI)
8680         {
8681           t = ix86_build_builtin_va_list_abi (MS_ABI);
8682           if (TREE_CODE (t) != RECORD_TYPE)
8683             t = build_variant_type_copy (t);
8684           ms_va_list_type_node = t;
8685         }
8686       else
8687         {
8688           t = ret;
8689           if (TREE_CODE (t) != RECORD_TYPE)
8690             t = build_variant_type_copy (t);
8691           ms_va_list_type_node = t;
8692         }
8693     }
8694
8695   return ret;
8696 }
8697
8698 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
8699
8700 static void
8701 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
8702 {
8703   rtx save_area, mem;
8704   alias_set_type set;
8705   int i, max;
8706
8707   /* GPR size of varargs save area.  */
8708   if (cfun->va_list_gpr_size)
8709     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
8710   else
8711     ix86_varargs_gpr_size = 0;
8712
8713   /* FPR size of varargs save area.  We don't need it if we don't pass
8714      anything in SSE registers.  */
8715   if (TARGET_SSE && cfun->va_list_fpr_size)
8716     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
8717   else
8718     ix86_varargs_fpr_size = 0;
8719
8720   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
8721     return;
8722
8723   save_area = frame_pointer_rtx;
8724   set = get_varargs_alias_set ();
8725
8726   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
8727   if (max > X86_64_REGPARM_MAX)
8728     max = X86_64_REGPARM_MAX;
8729
8730   for (i = cum->regno; i < max; i++)
8731     {
8732       mem = gen_rtx_MEM (word_mode,
8733                          plus_constant (Pmode, save_area, i * UNITS_PER_WORD));
8734       MEM_NOTRAP_P (mem) = 1;
8735       set_mem_alias_set (mem, set);
8736       emit_move_insn (mem,
8737                       gen_rtx_REG (word_mode,
8738                                    x86_64_int_parameter_registers[i]));
8739     }
8740
8741   if (ix86_varargs_fpr_size)
8742     {
8743       machine_mode smode;
8744       rtx_code_label *label;
8745       rtx test;
8746
8747       /* Now emit code to save SSE registers.  The AX parameter contains number
8748          of SSE parameter registers used to call this function, though all we
8749          actually check here is the zero/non-zero status.  */
8750
8751       label = gen_label_rtx ();
8752       test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx);
8753       emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1),
8754                                       label));
8755
8756       /* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if
8757          we used movdqa (i.e. TImode) instead?  Perhaps even better would
8758          be if we could determine the real mode of the data, via a hook
8759          into pass_stdarg.  Ignore all that for now.  */
8760       smode = V4SFmode;
8761       if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode))
8762         crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode);
8763
8764       max = cum->sse_regno + cfun->va_list_fpr_size / 16;
8765       if (max > X86_64_SSE_REGPARM_MAX)
8766         max = X86_64_SSE_REGPARM_MAX;
8767
8768       for (i = cum->sse_regno; i < max; ++i)
8769         {
8770           mem = plus_constant (Pmode, save_area,
8771                                i * 16 + ix86_varargs_gpr_size);
8772           mem = gen_rtx_MEM (smode, mem);
8773           MEM_NOTRAP_P (mem) = 1;
8774           set_mem_alias_set (mem, set);
8775           set_mem_align (mem, GET_MODE_ALIGNMENT (smode));
8776
8777           emit_move_insn (mem, gen_rtx_REG (smode, SSE_REGNO (i)));
8778         }
8779
8780       emit_label (label);
8781     }
8782 }
8783
8784 static void
8785 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
8786 {
8787   alias_set_type set = get_varargs_alias_set ();
8788   int i;
8789
8790   /* Reset to zero, as there might be a sysv vaarg used
8791      before.  */
8792   ix86_varargs_gpr_size = 0;
8793   ix86_varargs_fpr_size = 0;
8794
8795   for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
8796     {
8797       rtx reg, mem;
8798
8799       mem = gen_rtx_MEM (Pmode,
8800                          plus_constant (Pmode, virtual_incoming_args_rtx,
8801                                         i * UNITS_PER_WORD));
8802       MEM_NOTRAP_P (mem) = 1;
8803       set_mem_alias_set (mem, set);
8804
8805       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
8806       emit_move_insn (mem, reg);
8807     }
8808 }
8809
8810 static void
8811 ix86_setup_incoming_varargs (cumulative_args_t cum_v, machine_mode mode,
8812                              tree type, int *, int no_rtl)
8813 {
8814   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
8815   CUMULATIVE_ARGS next_cum;
8816   tree fntype;
8817
8818   /* This argument doesn't appear to be used anymore.  Which is good,
8819      because the old code here didn't suppress rtl generation.  */
8820   gcc_assert (!no_rtl);
8821
8822   if (!TARGET_64BIT)
8823     return;
8824
8825   fntype = TREE_TYPE (current_function_decl);
8826
8827   /* For varargs, we do not want to skip the dummy va_dcl argument.
8828      For stdargs, we do want to skip the last named argument.  */
8829   next_cum = *cum;
8830   if (stdarg_p (fntype))
8831     ix86_function_arg_advance (pack_cumulative_args (&next_cum), mode, type,
8832                                true);
8833
8834   if (cum->call_abi == MS_ABI)
8835     setup_incoming_varargs_ms_64 (&next_cum);
8836   else
8837     setup_incoming_varargs_64 (&next_cum);
8838 }
8839
8840 static void
8841 ix86_setup_incoming_vararg_bounds (cumulative_args_t cum_v,
8842                                    enum machine_mode mode,
8843                                    tree type,
8844                                    int *pretend_size ATTRIBUTE_UNUSED,
8845                                    int no_rtl)
8846 {
8847   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
8848   CUMULATIVE_ARGS next_cum;
8849   tree fntype;
8850   rtx save_area;
8851   int bnd_reg, i, max;
8852
8853   gcc_assert (!no_rtl);
8854
8855   /* Do nothing if we use plain pointer to argument area.  */
8856   if (!TARGET_64BIT || cum->call_abi == MS_ABI)
8857     return;
8858
8859   fntype = TREE_TYPE (current_function_decl);
8860
8861   /* For varargs, we do not want to skip the dummy va_dcl argument.
8862      For stdargs, we do want to skip the last named argument.  */
8863   next_cum = *cum;
8864   if (stdarg_p (fntype))
8865     ix86_function_arg_advance (pack_cumulative_args (&next_cum), mode, type,
8866                                true);
8867   save_area = frame_pointer_rtx;
8868
8869   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
8870   if (max > X86_64_REGPARM_MAX)
8871     max = X86_64_REGPARM_MAX;
8872
8873   bnd_reg = cum->bnd_regno + cum->force_bnd_pass;
8874   if (chkp_function_instrumented_p (current_function_decl))
8875     for (i = cum->regno; i < max; i++)
8876       {
8877         rtx addr = plus_constant (Pmode, save_area, i * UNITS_PER_WORD);
8878         rtx reg = gen_rtx_REG (DImode,
8879                                x86_64_int_parameter_registers[i]);
8880         rtx ptr = reg;
8881         rtx bounds;
8882
8883         if (bnd_reg <= LAST_BND_REG)
8884           bounds = gen_rtx_REG (BNDmode, bnd_reg);
8885         else
8886           {
8887             rtx ldx_addr =
8888               plus_constant (Pmode, arg_pointer_rtx,
8889                              (LAST_BND_REG - bnd_reg) * GET_MODE_SIZE (Pmode));
8890             bounds = gen_reg_rtx (BNDmode);
8891             emit_insn (BNDmode == BND64mode
8892                        ? gen_bnd64_ldx (bounds, ldx_addr, ptr)
8893                        : gen_bnd32_ldx (bounds, ldx_addr, ptr));
8894           }
8895
8896         emit_insn (BNDmode == BND64mode
8897                    ? gen_bnd64_stx (addr, ptr, bounds)
8898                    : gen_bnd32_stx (addr, ptr, bounds));
8899
8900         bnd_reg++;
8901       }
8902 }
8903
8904
8905 /* Checks if TYPE is of kind va_list char *.  */
8906
8907 static bool
8908 is_va_list_char_pointer (tree type)
8909 {
8910   tree canonic;
8911
8912   /* For 32-bit it is always true.  */
8913   if (!TARGET_64BIT)
8914     return true;
8915   canonic = ix86_canonical_va_list_type (type);
8916   return (canonic == ms_va_list_type_node
8917           || (ix86_abi == MS_ABI && canonic == va_list_type_node));
8918 }
8919
8920 /* Implement va_start.  */
8921
8922 static void
8923 ix86_va_start (tree valist, rtx nextarg)
8924 {
8925   HOST_WIDE_INT words, n_gpr, n_fpr;
8926   tree f_gpr, f_fpr, f_ovf, f_sav;
8927   tree gpr, fpr, ovf, sav, t;
8928   tree type;
8929   rtx ovf_rtx;
8930
8931   if (flag_split_stack
8932       && cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8933     {
8934       unsigned int scratch_regno;
8935
8936       /* When we are splitting the stack, we can't refer to the stack
8937          arguments using internal_arg_pointer, because they may be on
8938          the old stack.  The split stack prologue will arrange to
8939          leave a pointer to the old stack arguments in a scratch
8940          register, which we here copy to a pseudo-register.  The split
8941          stack prologue can't set the pseudo-register directly because
8942          it (the prologue) runs before any registers have been saved.  */
8943
8944       scratch_regno = split_stack_prologue_scratch_regno ();
8945       if (scratch_regno != INVALID_REGNUM)
8946         {
8947           rtx reg;
8948           rtx_insn *seq;
8949
8950           reg = gen_reg_rtx (Pmode);
8951           cfun->machine->split_stack_varargs_pointer = reg;
8952
8953           start_sequence ();
8954           emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno));
8955           seq = get_insns ();
8956           end_sequence ();
8957
8958           push_topmost_sequence ();
8959           emit_insn_after (seq, entry_of_function ());
8960           pop_topmost_sequence ();
8961         }
8962     }
8963
8964   /* Only 64bit target needs something special.  */
8965   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
8966     {
8967       if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8968         std_expand_builtin_va_start (valist, nextarg);
8969       else
8970         {
8971           rtx va_r, next;
8972
8973           va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
8974           next = expand_binop (ptr_mode, add_optab,
8975                                cfun->machine->split_stack_varargs_pointer,
8976                                crtl->args.arg_offset_rtx,
8977                                NULL_RTX, 0, OPTAB_LIB_WIDEN);
8978           convert_move (va_r, next, 0);
8979
8980           /* Store zero bounds for va_list.  */
8981           if (chkp_function_instrumented_p (current_function_decl))
8982             chkp_expand_bounds_reset_for_mem (valist,
8983                                               make_tree (TREE_TYPE (valist),
8984                                                          next));
8985
8986         }
8987       return;
8988     }
8989
8990   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
8991   f_fpr = DECL_CHAIN (f_gpr);
8992   f_ovf = DECL_CHAIN (f_fpr);
8993   f_sav = DECL_CHAIN (f_ovf);
8994
8995   valist = build_simple_mem_ref (valist);
8996   TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node);
8997   /* The following should be folded into the MEM_REF offset.  */
8998   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist),
8999                 f_gpr, NULL_TREE);
9000   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
9001                 f_fpr, NULL_TREE);
9002   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
9003                 f_ovf, NULL_TREE);
9004   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
9005                 f_sav, NULL_TREE);
9006
9007   /* Count number of gp and fp argument registers used.  */
9008   words = crtl->args.info.words;
9009   n_gpr = crtl->args.info.regno;
9010   n_fpr = crtl->args.info.sse_regno;
9011
9012   if (cfun->va_list_gpr_size)
9013     {
9014       type = TREE_TYPE (gpr);
9015       t = build2 (MODIFY_EXPR, type,
9016                   gpr, build_int_cst (type, n_gpr * 8));
9017       TREE_SIDE_EFFECTS (t) = 1;
9018       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
9019     }
9020
9021   if (TARGET_SSE && cfun->va_list_fpr_size)
9022     {
9023       type = TREE_TYPE (fpr);
9024       t = build2 (MODIFY_EXPR, type, fpr,
9025                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
9026       TREE_SIDE_EFFECTS (t) = 1;
9027       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
9028     }
9029
9030   /* Find the overflow area.  */
9031   type = TREE_TYPE (ovf);
9032   if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
9033     ovf_rtx = crtl->args.internal_arg_pointer;
9034   else
9035     ovf_rtx = cfun->machine->split_stack_varargs_pointer;
9036   t = make_tree (type, ovf_rtx);
9037   if (words != 0)
9038     t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD);
9039
9040   /* Store zero bounds for overflow area pointer.  */
9041   if (chkp_function_instrumented_p (current_function_decl))
9042     chkp_expand_bounds_reset_for_mem (ovf, t);
9043
9044   t = build2 (MODIFY_EXPR, type, ovf, t);
9045   TREE_SIDE_EFFECTS (t) = 1;
9046   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
9047
9048   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
9049     {
9050       /* Find the register save area.
9051          Prologue of the function save it right above stack frame.  */
9052       type = TREE_TYPE (sav);
9053       t = make_tree (type, frame_pointer_rtx);
9054       if (!ix86_varargs_gpr_size)
9055         t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX);
9056
9057       /* Store zero bounds for save area pointer.  */
9058       if (chkp_function_instrumented_p (current_function_decl))
9059         chkp_expand_bounds_reset_for_mem (sav, t);
9060
9061       t = build2 (MODIFY_EXPR, type, sav, t);
9062       TREE_SIDE_EFFECTS (t) = 1;
9063       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
9064     }
9065 }
9066
9067 /* Implement va_arg.  */
9068
9069 static tree
9070 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
9071                       gimple_seq *post_p)
9072 {
9073   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
9074   tree f_gpr, f_fpr, f_ovf, f_sav;
9075   tree gpr, fpr, ovf, sav, t;
9076   int size, rsize;
9077   tree lab_false, lab_over = NULL_TREE;
9078   tree addr, t2;
9079   rtx container;
9080   int indirect_p = 0;
9081   tree ptrtype;
9082   machine_mode nat_mode;
9083   unsigned int arg_boundary;
9084
9085   /* Only 64bit target needs something special.  */
9086   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
9087     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
9088
9089   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
9090   f_fpr = DECL_CHAIN (f_gpr);
9091   f_ovf = DECL_CHAIN (f_fpr);
9092   f_sav = DECL_CHAIN (f_ovf);
9093
9094   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
9095                 valist, f_gpr, NULL_TREE);
9096
9097   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
9098   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
9099   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
9100
9101   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
9102   if (indirect_p)
9103     type = build_pointer_type (type);
9104   size = int_size_in_bytes (type);
9105   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
9106
9107   nat_mode = type_natural_mode (type, NULL, false);
9108   switch (nat_mode)
9109     {
9110     case V8SFmode:
9111     case V8SImode:
9112     case V32QImode:
9113     case V16HImode:
9114     case V4DFmode:
9115     case V4DImode:
9116     case V16SFmode:
9117     case V16SImode:
9118     case V64QImode:
9119     case V32HImode:
9120     case V8DFmode:
9121     case V8DImode:
9122       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
9123       if (!TARGET_64BIT_MS_ABI)
9124         {
9125           container = NULL;
9126           break;
9127         }
9128
9129     default:
9130       container = construct_container (nat_mode, TYPE_MODE (type),
9131                                        type, 0, X86_64_REGPARM_MAX,
9132                                        X86_64_SSE_REGPARM_MAX, intreg,
9133                                        0);
9134       break;
9135     }
9136
9137   /* Pull the value out of the saved registers.  */
9138
9139   addr = create_tmp_var (ptr_type_node, "addr");
9140
9141   if (container)
9142     {
9143       int needed_intregs, needed_sseregs;
9144       bool need_temp;
9145       tree int_addr, sse_addr;
9146
9147       lab_false = create_artificial_label (UNKNOWN_LOCATION);
9148       lab_over = create_artificial_label (UNKNOWN_LOCATION);
9149
9150       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
9151
9152       need_temp = (!REG_P (container)
9153                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
9154                        || TYPE_ALIGN (type) > 128));
9155
9156       /* In case we are passing structure, verify that it is consecutive block
9157          on the register save area.  If not we need to do moves.  */
9158       if (!need_temp && !REG_P (container))
9159         {
9160           /* Verify that all registers are strictly consecutive  */
9161           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
9162             {
9163               int i;
9164
9165               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
9166                 {
9167                   rtx slot = XVECEXP (container, 0, i);
9168                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
9169                       || INTVAL (XEXP (slot, 1)) != i * 16)
9170                     need_temp = true;
9171                 }
9172             }
9173           else
9174             {
9175               int i;
9176
9177               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
9178                 {
9179                   rtx slot = XVECEXP (container, 0, i);
9180                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
9181                       || INTVAL (XEXP (slot, 1)) != i * 8)
9182                     need_temp = true;
9183                 }
9184             }
9185         }
9186       if (!need_temp)
9187         {
9188           int_addr = addr;
9189           sse_addr = addr;
9190         }
9191       else
9192         {
9193           int_addr = create_tmp_var (ptr_type_node, "int_addr");
9194           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
9195         }
9196
9197       /* First ensure that we fit completely in registers.  */
9198       if (needed_intregs)
9199         {
9200           t = build_int_cst (TREE_TYPE (gpr),
9201                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
9202           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
9203           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
9204           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
9205           gimplify_and_add (t, pre_p);
9206         }
9207       if (needed_sseregs)
9208         {
9209           t = build_int_cst (TREE_TYPE (fpr),
9210                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
9211                              + X86_64_REGPARM_MAX * 8);
9212           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
9213           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
9214           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
9215           gimplify_and_add (t, pre_p);
9216         }
9217
9218       /* Compute index to start of area used for integer regs.  */
9219       if (needed_intregs)
9220         {
9221           /* int_addr = gpr + sav; */
9222           t = fold_build_pointer_plus (sav, gpr);
9223           gimplify_assign (int_addr, t, pre_p);
9224         }
9225       if (needed_sseregs)
9226         {
9227           /* sse_addr = fpr + sav; */
9228           t = fold_build_pointer_plus (sav, fpr);
9229           gimplify_assign (sse_addr, t, pre_p);
9230         }
9231       if (need_temp)
9232         {
9233           int i, prev_size = 0;
9234           tree temp = create_tmp_var (type, "va_arg_tmp");
9235
9236           /* addr = &temp; */
9237           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
9238           gimplify_assign (addr, t, pre_p);
9239
9240           for (i = 0; i < XVECLEN (container, 0); i++)
9241             {
9242               rtx slot = XVECEXP (container, 0, i);
9243               rtx reg = XEXP (slot, 0);
9244               machine_mode mode = GET_MODE (reg);
9245               tree piece_type;
9246               tree addr_type;
9247               tree daddr_type;
9248               tree src_addr, src;
9249               int src_offset;
9250               tree dest_addr, dest;
9251               int cur_size = GET_MODE_SIZE (mode);
9252
9253               gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
9254               prev_size = INTVAL (XEXP (slot, 1));
9255               if (prev_size + cur_size > size)
9256                 {
9257                   cur_size = size - prev_size;
9258                   mode = mode_for_size (cur_size * BITS_PER_UNIT, MODE_INT, 1);
9259                   if (mode == BLKmode)
9260                     mode = QImode;
9261                 }
9262               piece_type = lang_hooks.types.type_for_mode (mode, 1);
9263               if (mode == GET_MODE (reg))
9264                 addr_type = build_pointer_type (piece_type);
9265               else
9266                 addr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
9267                                                          true);
9268               daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
9269                                                         true);
9270
9271               if (SSE_REGNO_P (REGNO (reg)))
9272                 {
9273                   src_addr = sse_addr;
9274                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
9275                 }
9276               else
9277                 {
9278                   src_addr = int_addr;
9279                   src_offset = REGNO (reg) * 8;
9280                 }
9281               src_addr = fold_convert (addr_type, src_addr);
9282               src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset);
9283
9284               dest_addr = fold_convert (daddr_type, addr);
9285               dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size);
9286               if (cur_size == GET_MODE_SIZE (mode))
9287                 {
9288                   src = build_va_arg_indirect_ref (src_addr);
9289                   dest = build_va_arg_indirect_ref (dest_addr);
9290
9291                   gimplify_assign (dest, src, pre_p);
9292                 }
9293               else
9294                 {
9295                   tree copy
9296                     = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
9297                                        3, dest_addr, src_addr,
9298                                        size_int (cur_size));
9299                   gimplify_and_add (copy, pre_p);
9300                 }
9301               prev_size += cur_size;
9302             }
9303         }
9304
9305       if (needed_intregs)
9306         {
9307           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
9308                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
9309           gimplify_assign (gpr, t, pre_p);
9310         }
9311
9312       if (needed_sseregs)
9313         {
9314           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
9315                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
9316           gimplify_assign (unshare_expr (fpr), t, pre_p);
9317         }
9318
9319       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
9320
9321       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
9322     }
9323
9324   /* ... otherwise out of the overflow area.  */
9325
9326   /* When we align parameter on stack for caller, if the parameter
9327      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
9328      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
9329      here with caller.  */
9330   arg_boundary = ix86_function_arg_boundary (VOIDmode, type);
9331   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
9332     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
9333
9334   /* Care for on-stack alignment if needed.  */
9335   if (arg_boundary <= 64 || size == 0)
9336     t = ovf;
9337  else
9338     {
9339       HOST_WIDE_INT align = arg_boundary / 8;
9340       t = fold_build_pointer_plus_hwi (ovf, align - 1);
9341       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
9342                   build_int_cst (TREE_TYPE (t), -align));
9343     }
9344
9345   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
9346   gimplify_assign (addr, t, pre_p);
9347
9348   t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD);
9349   gimplify_assign (unshare_expr (ovf), t, pre_p);
9350
9351   if (container)
9352     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
9353
9354   ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
9355   addr = fold_convert (ptrtype, addr);
9356
9357   if (indirect_p)
9358     addr = build_va_arg_indirect_ref (addr);
9359   return build_va_arg_indirect_ref (addr);
9360 }
9361 \f
9362 /* Return true if OPNUM's MEM should be matched
9363    in movabs* patterns.  */
9364
9365 bool
9366 ix86_check_movabs (rtx insn, int opnum)
9367 {
9368   rtx set, mem;
9369
9370   set = PATTERN (insn);
9371   if (GET_CODE (set) == PARALLEL)
9372     set = XVECEXP (set, 0, 0);
9373   gcc_assert (GET_CODE (set) == SET);
9374   mem = XEXP (set, opnum);
9375   while (GET_CODE (mem) == SUBREG)
9376     mem = SUBREG_REG (mem);
9377   gcc_assert (MEM_P (mem));
9378   return volatile_ok || !MEM_VOLATILE_P (mem);
9379 }
9380 \f
9381 /* Initialize the table of extra 80387 mathematical constants.  */
9382
9383 static void
9384 init_ext_80387_constants (void)
9385 {
9386   static const char * cst[5] =
9387   {
9388     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
9389     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
9390     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
9391     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
9392     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
9393   };
9394   int i;
9395
9396   for (i = 0; i < 5; i++)
9397     {
9398       real_from_string (&ext_80387_constants_table[i], cst[i]);
9399       /* Ensure each constant is rounded to XFmode precision.  */
9400       real_convert (&ext_80387_constants_table[i],
9401                     XFmode, &ext_80387_constants_table[i]);
9402     }
9403
9404   ext_80387_constants_init = 1;
9405 }
9406
9407 /* Return non-zero if the constant is something that
9408    can be loaded with a special instruction.  */
9409
9410 int
9411 standard_80387_constant_p (rtx x)
9412 {
9413   machine_mode mode = GET_MODE (x);
9414
9415   REAL_VALUE_TYPE r;
9416
9417   if (!(CONST_DOUBLE_P (x) && X87_FLOAT_MODE_P (mode)))
9418     return -1;
9419
9420   if (x == CONST0_RTX (mode))
9421     return 1;
9422   if (x == CONST1_RTX (mode))
9423     return 2;
9424
9425   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
9426
9427   /* For XFmode constants, try to find a special 80387 instruction when
9428      optimizing for size or on those CPUs that benefit from them.  */
9429   if (mode == XFmode
9430       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
9431     {
9432       int i;
9433
9434       if (! ext_80387_constants_init)
9435         init_ext_80387_constants ();
9436
9437       for (i = 0; i < 5; i++)
9438         if (real_identical (&r, &ext_80387_constants_table[i]))
9439           return i + 3;
9440     }
9441
9442   /* Load of the constant -0.0 or -1.0 will be split as
9443      fldz;fchs or fld1;fchs sequence.  */
9444   if (real_isnegzero (&r))
9445     return 8;
9446   if (real_identical (&r, &dconstm1))
9447     return 9;
9448
9449   return 0;
9450 }
9451
9452 /* Return the opcode of the special instruction to be used to load
9453    the constant X.  */
9454
9455 const char *
9456 standard_80387_constant_opcode (rtx x)
9457 {
9458   switch (standard_80387_constant_p (x))
9459     {
9460     case 1:
9461       return "fldz";
9462     case 2:
9463       return "fld1";
9464     case 3:
9465       return "fldlg2";
9466     case 4:
9467       return "fldln2";
9468     case 5:
9469       return "fldl2e";
9470     case 6:
9471       return "fldl2t";
9472     case 7:
9473       return "fldpi";
9474     case 8:
9475     case 9:
9476       return "#";
9477     default:
9478       gcc_unreachable ();
9479     }
9480 }
9481
9482 /* Return the CONST_DOUBLE representing the 80387 constant that is
9483    loaded by the specified special instruction.  The argument IDX
9484    matches the return value from standard_80387_constant_p.  */
9485
9486 rtx
9487 standard_80387_constant_rtx (int idx)
9488 {
9489   int i;
9490
9491   if (! ext_80387_constants_init)
9492     init_ext_80387_constants ();
9493
9494   switch (idx)
9495     {
9496     case 3:
9497     case 4:
9498     case 5:
9499     case 6:
9500     case 7:
9501       i = idx - 3;
9502       break;
9503
9504     default:
9505       gcc_unreachable ();
9506     }
9507
9508   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
9509                                        XFmode);
9510 }
9511
9512 /* Return 1 if X is all 0s and 2 if x is all 1s
9513    in supported SSE/AVX vector mode.  */
9514
9515 int
9516 standard_sse_constant_p (rtx x)
9517 {
9518   machine_mode mode;
9519
9520   if (!TARGET_SSE)
9521     return 0;
9522
9523   mode = GET_MODE (x);
9524   
9525   if (x == const0_rtx || x == CONST0_RTX (mode))
9526     return 1;
9527   if (vector_all_ones_operand (x, mode))
9528     switch (mode)
9529       {
9530       case V16QImode:
9531       case V8HImode:
9532       case V4SImode:
9533       case V2DImode:
9534         if (TARGET_SSE2)
9535           return 2;
9536       case V32QImode:
9537       case V16HImode:
9538       case V8SImode:
9539       case V4DImode:
9540         if (TARGET_AVX2)
9541           return 2;
9542       case V64QImode:
9543       case V32HImode:
9544       case V16SImode:
9545       case V8DImode:
9546         if (TARGET_AVX512F)
9547           return 2;
9548       default:
9549         break;
9550       }
9551
9552   return 0;
9553 }
9554
9555 /* Return the opcode of the special instruction to be used to load
9556    the constant X.  */
9557
9558 const char *
9559 standard_sse_constant_opcode (rtx_insn *insn, rtx x)
9560 {
9561   switch (standard_sse_constant_p (x))
9562     {
9563     case 1:
9564       switch (get_attr_mode (insn))
9565         {
9566         case MODE_XI:
9567           return "vpxord\t%g0, %g0, %g0";
9568         case MODE_V16SF:
9569           return TARGET_AVX512DQ ? "vxorps\t%g0, %g0, %g0"
9570                                  : "vpxord\t%g0, %g0, %g0";
9571         case MODE_V8DF:
9572           return TARGET_AVX512DQ ? "vxorpd\t%g0, %g0, %g0"
9573                                  : "vpxorq\t%g0, %g0, %g0";
9574         case MODE_TI:
9575           return TARGET_AVX512VL ? "vpxord\t%t0, %t0, %t0"
9576                                  : "%vpxor\t%0, %d0";
9577         case MODE_V2DF:
9578           return "%vxorpd\t%0, %d0";
9579         case MODE_V4SF:
9580           return "%vxorps\t%0, %d0";
9581
9582         case MODE_OI:
9583           return TARGET_AVX512VL ? "vpxord\t%x0, %x0, %x0"
9584                                  : "vpxor\t%x0, %x0, %x0";
9585         case MODE_V4DF:
9586           return "vxorpd\t%x0, %x0, %x0";
9587         case MODE_V8SF:
9588           return "vxorps\t%x0, %x0, %x0";
9589
9590         default:
9591           break;
9592         }
9593
9594     case 2:
9595       if (TARGET_AVX512VL
9596           || get_attr_mode (insn) == MODE_XI
9597           || get_attr_mode (insn) == MODE_V8DF
9598           || get_attr_mode (insn) == MODE_V16SF)
9599         return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
9600       if (TARGET_AVX)
9601         return "vpcmpeqd\t%0, %0, %0";
9602       else
9603         return "pcmpeqd\t%0, %0";
9604
9605     default:
9606       break;
9607     }
9608   gcc_unreachable ();
9609 }
9610
9611 /* Returns true if OP contains a symbol reference */
9612
9613 bool
9614 symbolic_reference_mentioned_p (rtx op)
9615 {
9616   const char *fmt;
9617   int i;
9618
9619   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
9620     return true;
9621
9622   fmt = GET_RTX_FORMAT (GET_CODE (op));
9623   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
9624     {
9625       if (fmt[i] == 'E')
9626         {
9627           int j;
9628
9629           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
9630             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
9631               return true;
9632         }
9633
9634       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
9635         return true;
9636     }
9637
9638   return false;
9639 }
9640
9641 /* Return true if it is appropriate to emit `ret' instructions in the
9642    body of a function.  Do this only if the epilogue is simple, needing a
9643    couple of insns.  Prior to reloading, we can't tell how many registers
9644    must be saved, so return false then.  Return false if there is no frame
9645    marker to de-allocate.  */
9646
9647 bool
9648 ix86_can_use_return_insn_p (void)
9649 {
9650   struct ix86_frame frame;
9651
9652   if (! reload_completed || frame_pointer_needed)
9653     return 0;
9654
9655   /* Don't allow more than 32k pop, since that's all we can do
9656      with one instruction.  */
9657   if (crtl->args.pops_args && crtl->args.size >= 32768)
9658     return 0;
9659
9660   ix86_compute_frame_layout (&frame);
9661   return (frame.stack_pointer_offset == UNITS_PER_WORD
9662           && (frame.nregs + frame.nsseregs) == 0);
9663 }
9664 \f
9665 /* Value should be nonzero if functions must have frame pointers.
9666    Zero means the frame pointer need not be set up (and parms may
9667    be accessed via the stack pointer) in functions that seem suitable.  */
9668
9669 static bool
9670 ix86_frame_pointer_required (void)
9671 {
9672   /* If we accessed previous frames, then the generated code expects
9673      to be able to access the saved ebp value in our frame.  */
9674   if (cfun->machine->accesses_prev_frame)
9675     return true;
9676
9677   /* Several x86 os'es need a frame pointer for other reasons,
9678      usually pertaining to setjmp.  */
9679   if (SUBTARGET_FRAME_POINTER_REQUIRED)
9680     return true;
9681
9682   /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
9683   if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
9684     return true;
9685
9686   /* Win64 SEH, very large frames need a frame-pointer as maximum stack
9687      allocation is 4GB.  */
9688   if (TARGET_64BIT_MS_ABI && get_frame_size () > SEH_MAX_FRAME_SIZE)
9689     return true;
9690
9691   /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
9692      turns off the frame pointer by default.  Turn it back on now if
9693      we've not got a leaf function.  */
9694   if (TARGET_OMIT_LEAF_FRAME_POINTER
9695       && (!crtl->is_leaf
9696           || ix86_current_function_calls_tls_descriptor))
9697     return true;
9698
9699   if (crtl->profile && !flag_fentry)
9700     return true;
9701
9702   return false;
9703 }
9704
9705 /* Record that the current function accesses previous call frames.  */
9706
9707 void
9708 ix86_setup_frame_addresses (void)
9709 {
9710   cfun->machine->accesses_prev_frame = 1;
9711 }
9712 \f
9713 #ifndef USE_HIDDEN_LINKONCE
9714 # if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)
9715 #  define USE_HIDDEN_LINKONCE 1
9716 # else
9717 #  define USE_HIDDEN_LINKONCE 0
9718 # endif
9719 #endif
9720
9721 static int pic_labels_used;
9722
9723 /* Fills in the label name that should be used for a pc thunk for
9724    the given register.  */
9725
9726 static void
9727 get_pc_thunk_name (char name[32], unsigned int regno)
9728 {
9729   gcc_assert (!TARGET_64BIT);
9730
9731   if (USE_HIDDEN_LINKONCE)
9732     sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]);
9733   else
9734     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
9735 }
9736
9737
9738 /* This function generates code for -fpic that loads %ebx with
9739    the return address of the caller and then returns.  */
9740
9741 static void
9742 ix86_code_end (void)
9743 {
9744   rtx xops[2];
9745   int regno;
9746
9747   for (regno = AX_REG; regno <= SP_REG; regno++)
9748     {
9749       char name[32];
9750       tree decl;
9751
9752       if (!(pic_labels_used & (1 << regno)))
9753         continue;
9754
9755       get_pc_thunk_name (name, regno);
9756
9757       decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
9758                          get_identifier (name),
9759                          build_function_type_list (void_type_node, NULL_TREE));
9760       DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
9761                                        NULL_TREE, void_type_node);
9762       TREE_PUBLIC (decl) = 1;
9763       TREE_STATIC (decl) = 1;
9764       DECL_IGNORED_P (decl) = 1;
9765
9766 #if TARGET_MACHO
9767       if (TARGET_MACHO)
9768         {
9769           switch_to_section (darwin_sections[text_coal_section]);
9770           fputs ("\t.weak_definition\t", asm_out_file);
9771           assemble_name (asm_out_file, name);
9772           fputs ("\n\t.private_extern\t", asm_out_file);
9773           assemble_name (asm_out_file, name);
9774           putc ('\n', asm_out_file);
9775           ASM_OUTPUT_LABEL (asm_out_file, name);
9776           DECL_WEAK (decl) = 1;
9777         }
9778       else
9779 #endif
9780       if (USE_HIDDEN_LINKONCE)
9781         {
9782           cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
9783
9784           targetm.asm_out.unique_section (decl, 0);
9785           switch_to_section (get_named_section (decl, NULL, 0));
9786
9787           targetm.asm_out.globalize_label (asm_out_file, name);
9788           fputs ("\t.hidden\t", asm_out_file);
9789           assemble_name (asm_out_file, name);
9790           putc ('\n', asm_out_file);
9791           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
9792         }
9793       else
9794         {
9795           switch_to_section (text_section);
9796           ASM_OUTPUT_LABEL (asm_out_file, name);
9797         }
9798
9799       DECL_INITIAL (decl) = make_node (BLOCK);
9800       current_function_decl = decl;
9801       init_function_start (decl);
9802       first_function_block_is_cold = false;
9803       /* Make sure unwind info is emitted for the thunk if needed.  */
9804       final_start_function (emit_barrier (), asm_out_file, 1);
9805
9806       /* Pad stack IP move with 4 instructions (two NOPs count
9807          as one instruction).  */
9808       if (TARGET_PAD_SHORT_FUNCTION)
9809         {
9810           int i = 8;
9811
9812           while (i--)
9813             fputs ("\tnop\n", asm_out_file);
9814         }
9815
9816       xops[0] = gen_rtx_REG (Pmode, regno);
9817       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9818       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
9819       output_asm_insn ("%!ret", NULL);
9820       final_end_function ();
9821       init_insn_lengths ();
9822       free_after_compilation (cfun);
9823       set_cfun (NULL);
9824       current_function_decl = NULL;
9825     }
9826
9827   if (flag_split_stack)
9828     file_end_indicate_split_stack ();
9829 }
9830
9831 /* Emit code for the SET_GOT patterns.  */
9832
9833 const char *
9834 output_set_got (rtx dest, rtx label)
9835 {
9836   rtx xops[3];
9837
9838   xops[0] = dest;
9839
9840   if (TARGET_VXWORKS_RTP && flag_pic)
9841     {
9842       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
9843       xops[2] = gen_rtx_MEM (Pmode,
9844                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
9845       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
9846
9847       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
9848          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
9849          an unadorned address.  */
9850       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
9851       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
9852       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
9853       return "";
9854     }
9855
9856   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
9857
9858   if (!flag_pic)
9859     {
9860       if (TARGET_MACHO)
9861         /* We don't need a pic base, we're not producing pic.  */
9862         gcc_unreachable ();
9863
9864       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
9865       output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
9866       targetm.asm_out.internal_label (asm_out_file, "L",
9867                                       CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
9868     }
9869   else
9870     {
9871       char name[32];
9872       get_pc_thunk_name (name, REGNO (dest));
9873       pic_labels_used |= 1 << REGNO (dest);
9874
9875       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
9876       xops[2] = gen_rtx_MEM (QImode, xops[2]);
9877       output_asm_insn ("%!call\t%X2", xops);
9878
9879 #if TARGET_MACHO
9880       /* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here.
9881          This is what will be referenced by the Mach-O PIC subsystem.  */
9882       if (machopic_should_output_picbase_label () || !label)
9883         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
9884
9885       /* When we are restoring the pic base at the site of a nonlocal label,
9886          and we decided to emit the pic base above, we will still output a
9887          local label used for calculating the correction offset (even though
9888          the offset will be 0 in that case).  */
9889       if (label)
9890         targetm.asm_out.internal_label (asm_out_file, "L",
9891                                            CODE_LABEL_NUMBER (label));
9892 #endif
9893     }
9894
9895   if (!TARGET_MACHO)
9896     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
9897
9898   return "";
9899 }
9900
9901 /* Generate an "push" pattern for input ARG.  */
9902
9903 static rtx
9904 gen_push (rtx arg)
9905 {
9906   struct machine_function *m = cfun->machine;
9907
9908   if (m->fs.cfa_reg == stack_pointer_rtx)
9909     m->fs.cfa_offset += UNITS_PER_WORD;
9910   m->fs.sp_offset += UNITS_PER_WORD;
9911
9912   if (REG_P (arg) && GET_MODE (arg) != word_mode)
9913     arg = gen_rtx_REG (word_mode, REGNO (arg));
9914
9915   return gen_rtx_SET (gen_rtx_MEM (word_mode,
9916                                    gen_rtx_PRE_DEC (Pmode,
9917                                                     stack_pointer_rtx)),
9918                       arg);
9919 }
9920
9921 /* Generate an "pop" pattern for input ARG.  */
9922
9923 static rtx
9924 gen_pop (rtx arg)
9925 {
9926   if (REG_P (arg) && GET_MODE (arg) != word_mode)
9927     arg = gen_rtx_REG (word_mode, REGNO (arg));
9928
9929   return gen_rtx_SET (arg,
9930                       gen_rtx_MEM (word_mode,
9931                                    gen_rtx_POST_INC (Pmode,
9932                                                      stack_pointer_rtx)));
9933 }
9934
9935 /* Return >= 0 if there is an unused call-clobbered register available
9936    for the entire function.  */
9937
9938 static unsigned int
9939 ix86_select_alt_pic_regnum (void)
9940 {
9941   if (ix86_use_pseudo_pic_reg ())
9942     return INVALID_REGNUM;
9943
9944   if (crtl->is_leaf
9945       && !crtl->profile
9946       && !ix86_current_function_calls_tls_descriptor)
9947     {
9948       int i, drap;
9949       /* Can't use the same register for both PIC and DRAP.  */
9950       if (crtl->drap_reg)
9951         drap = REGNO (crtl->drap_reg);
9952       else
9953         drap = -1;
9954       for (i = 2; i >= 0; --i)
9955         if (i != drap && !df_regs_ever_live_p (i))
9956           return i;
9957     }
9958
9959   return INVALID_REGNUM;
9960 }
9961
9962 /* Return TRUE if we need to save REGNO.  */
9963
9964 static bool
9965 ix86_save_reg (unsigned int regno, bool maybe_eh_return)
9966 {
9967   if (regno == REAL_PIC_OFFSET_TABLE_REGNUM
9968       && pic_offset_table_rtx)
9969     {
9970       if (ix86_use_pseudo_pic_reg ())
9971         {
9972           /* REAL_PIC_OFFSET_TABLE_REGNUM used by call to
9973           _mcount in prologue.  */
9974           if (!TARGET_64BIT && flag_pic && crtl->profile)
9975             return true;
9976         }
9977       else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
9978                || crtl->profile
9979                || crtl->calls_eh_return
9980                || crtl->uses_const_pool
9981                || cfun->has_nonlocal_label)
9982         return ix86_select_alt_pic_regnum () == INVALID_REGNUM;
9983     }
9984
9985   if (crtl->calls_eh_return && maybe_eh_return)
9986     {
9987       unsigned i;
9988       for (i = 0; ; i++)
9989         {
9990           unsigned test = EH_RETURN_DATA_REGNO (i);
9991           if (test == INVALID_REGNUM)
9992             break;
9993           if (test == regno)
9994             return true;
9995         }
9996     }
9997
9998   if (crtl->drap_reg
9999       && regno == REGNO (crtl->drap_reg)
10000       && !cfun->machine->no_drap_save_restore)
10001     return true;
10002
10003   return (df_regs_ever_live_p (regno)
10004           && !call_used_regs[regno]
10005           && !fixed_regs[regno]
10006           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
10007 }
10008
10009 /* Return number of saved general prupose registers.  */
10010
10011 static int
10012 ix86_nsaved_regs (void)
10013 {
10014   int nregs = 0;
10015   int regno;
10016
10017   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10018     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10019       nregs ++;
10020   return nregs;
10021 }
10022
10023 /* Return number of saved SSE registrers.  */
10024
10025 static int
10026 ix86_nsaved_sseregs (void)
10027 {
10028   int nregs = 0;
10029   int regno;
10030
10031   if (!TARGET_64BIT_MS_ABI)
10032     return 0;
10033   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10034     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10035       nregs ++;
10036   return nregs;
10037 }
10038
10039 /* Given FROM and TO register numbers, say whether this elimination is
10040    allowed.  If stack alignment is needed, we can only replace argument
10041    pointer with hard frame pointer, or replace frame pointer with stack
10042    pointer.  Otherwise, frame pointer elimination is automatically
10043    handled and all other eliminations are valid.  */
10044
10045 static bool
10046 ix86_can_eliminate (const int from, const int to)
10047 {
10048   if (stack_realign_fp)
10049     return ((from == ARG_POINTER_REGNUM
10050              && to == HARD_FRAME_POINTER_REGNUM)
10051             || (from == FRAME_POINTER_REGNUM
10052                 && to == STACK_POINTER_REGNUM));
10053   else
10054     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true;
10055 }
10056
10057 /* Return the offset between two registers, one to be eliminated, and the other
10058    its replacement, at the start of a routine.  */
10059
10060 HOST_WIDE_INT
10061 ix86_initial_elimination_offset (int from, int to)
10062 {
10063   struct ix86_frame frame;
10064   ix86_compute_frame_layout (&frame);
10065
10066   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
10067     return frame.hard_frame_pointer_offset;
10068   else if (from == FRAME_POINTER_REGNUM
10069            && to == HARD_FRAME_POINTER_REGNUM)
10070     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
10071   else
10072     {
10073       gcc_assert (to == STACK_POINTER_REGNUM);
10074
10075       if (from == ARG_POINTER_REGNUM)
10076         return frame.stack_pointer_offset;
10077
10078       gcc_assert (from == FRAME_POINTER_REGNUM);
10079       return frame.stack_pointer_offset - frame.frame_pointer_offset;
10080     }
10081 }
10082
10083 /* In a dynamically-aligned function, we can't know the offset from
10084    stack pointer to frame pointer, so we must ensure that setjmp
10085    eliminates fp against the hard fp (%ebp) rather than trying to
10086    index from %esp up to the top of the frame across a gap that is
10087    of unknown (at compile-time) size.  */
10088 static rtx
10089 ix86_builtin_setjmp_frame_value (void)
10090 {
10091   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
10092 }
10093
10094 /* When using -fsplit-stack, the allocation routines set a field in
10095    the TCB to the bottom of the stack plus this much space, measured
10096    in bytes.  */
10097
10098 #define SPLIT_STACK_AVAILABLE 256
10099
10100 /* Fill structure ix86_frame about frame of currently computed function.  */
10101
10102 static void
10103 ix86_compute_frame_layout (struct ix86_frame *frame)
10104 {
10105   unsigned HOST_WIDE_INT stack_alignment_needed;
10106   HOST_WIDE_INT offset;
10107   unsigned HOST_WIDE_INT preferred_alignment;
10108   HOST_WIDE_INT size = get_frame_size ();
10109   HOST_WIDE_INT to_allocate;
10110
10111   frame->nregs = ix86_nsaved_regs ();
10112   frame->nsseregs = ix86_nsaved_sseregs ();
10113
10114   /* 64-bit MS ABI seem to require stack alignment to be always 16 except for
10115      function prologues and leaf.  */
10116   if ((TARGET_64BIT_MS_ABI && crtl->preferred_stack_boundary < 128)
10117       && (!crtl->is_leaf || cfun->calls_alloca != 0
10118           || ix86_current_function_calls_tls_descriptor))
10119     {
10120       crtl->preferred_stack_boundary = 128;
10121       crtl->stack_alignment_needed = 128;
10122     }
10123   /* preferred_stack_boundary is never updated for call
10124      expanded from tls descriptor. Update it here. We don't update it in
10125      expand stage because according to the comments before
10126      ix86_current_function_calls_tls_descriptor, tls calls may be optimized
10127      away.  */
10128   else if (ix86_current_function_calls_tls_descriptor
10129            && crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
10130     {
10131       crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
10132       if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
10133         crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
10134     }
10135
10136   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
10137   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
10138
10139   gcc_assert (!size || stack_alignment_needed);
10140   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
10141   gcc_assert (preferred_alignment <= stack_alignment_needed);
10142
10143   /* For SEH we have to limit the amount of code movement into the prologue.
10144      At present we do this via a BLOCKAGE, at which point there's very little
10145      scheduling that can be done, which means that there's very little point
10146      in doing anything except PUSHs.  */
10147   if (TARGET_SEH)
10148     cfun->machine->use_fast_prologue_epilogue = false;
10149
10150   /* During reload iteration the amount of registers saved can change.
10151      Recompute the value as needed.  Do not recompute when amount of registers
10152      didn't change as reload does multiple calls to the function and does not
10153      expect the decision to change within single iteration.  */
10154   else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun))
10155            && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
10156     {
10157       int count = frame->nregs;
10158       struct cgraph_node *node = cgraph_node::get (current_function_decl);
10159
10160       cfun->machine->use_fast_prologue_epilogue_nregs = count;
10161
10162       /* The fast prologue uses move instead of push to save registers.  This
10163          is significantly longer, but also executes faster as modern hardware
10164          can execute the moves in parallel, but can't do that for push/pop.
10165
10166          Be careful about choosing what prologue to emit:  When function takes
10167          many instructions to execute we may use slow version as well as in
10168          case function is known to be outside hot spot (this is known with
10169          feedback only).  Weight the size of function by number of registers
10170          to save as it is cheap to use one or two push instructions but very
10171          slow to use many of them.  */
10172       if (count)
10173         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
10174       if (node->frequency < NODE_FREQUENCY_NORMAL
10175           || (flag_branch_probabilities
10176               && node->frequency < NODE_FREQUENCY_HOT))
10177         cfun->machine->use_fast_prologue_epilogue = false;
10178       else
10179         cfun->machine->use_fast_prologue_epilogue
10180            = !expensive_function_p (count);
10181     }
10182
10183   frame->save_regs_using_mov
10184     = (TARGET_PROLOGUE_USING_MOVE && cfun->machine->use_fast_prologue_epilogue
10185        /* If static stack checking is enabled and done with probes,
10186           the registers need to be saved before allocating the frame.  */
10187        && flag_stack_check != STATIC_BUILTIN_STACK_CHECK);
10188
10189   /* Skip return address.  */
10190   offset = UNITS_PER_WORD;
10191
10192   /* Skip pushed static chain.  */
10193   if (ix86_static_chain_on_stack)
10194     offset += UNITS_PER_WORD;
10195
10196   /* Skip saved base pointer.  */
10197   if (frame_pointer_needed)
10198     offset += UNITS_PER_WORD;
10199   frame->hfp_save_offset = offset;
10200
10201   /* The traditional frame pointer location is at the top of the frame.  */
10202   frame->hard_frame_pointer_offset = offset;
10203
10204   /* Register save area */
10205   offset += frame->nregs * UNITS_PER_WORD;
10206   frame->reg_save_offset = offset;
10207
10208   /* On SEH target, registers are pushed just before the frame pointer
10209      location.  */
10210   if (TARGET_SEH)
10211     frame->hard_frame_pointer_offset = offset;
10212
10213   /* Align and set SSE register save area.  */
10214   if (frame->nsseregs)
10215     {
10216       /* The only ABI that has saved SSE registers (Win64) also has a
10217          16-byte aligned default stack, and thus we don't need to be
10218          within the re-aligned local stack frame to save them.  */
10219       gcc_assert (INCOMING_STACK_BOUNDARY >= 128);
10220       offset = (offset + 16 - 1) & -16;
10221       offset += frame->nsseregs * 16;
10222     }
10223   frame->sse_reg_save_offset = offset;
10224
10225   /* The re-aligned stack starts here.  Values before this point are not
10226      directly comparable with values below this point.  In order to make
10227      sure that no value happens to be the same before and after, force
10228      the alignment computation below to add a non-zero value.  */
10229   if (stack_realign_fp)
10230     offset = (offset + stack_alignment_needed) & -stack_alignment_needed;
10231
10232   /* Va-arg area */
10233   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
10234   offset += frame->va_arg_size;
10235
10236   /* Align start of frame for local function.  */
10237   if (stack_realign_fp
10238       || offset != frame->sse_reg_save_offset
10239       || size != 0
10240       || !crtl->is_leaf
10241       || cfun->calls_alloca
10242       || ix86_current_function_calls_tls_descriptor)
10243     offset = (offset + stack_alignment_needed - 1) & -stack_alignment_needed;
10244
10245   /* Frame pointer points here.  */
10246   frame->frame_pointer_offset = offset;
10247
10248   offset += size;
10249
10250   /* Add outgoing arguments area.  Can be skipped if we eliminated
10251      all the function calls as dead code.
10252      Skipping is however impossible when function calls alloca.  Alloca
10253      expander assumes that last crtl->outgoing_args_size
10254      of stack frame are unused.  */
10255   if (ACCUMULATE_OUTGOING_ARGS
10256       && (!crtl->is_leaf || cfun->calls_alloca
10257           || ix86_current_function_calls_tls_descriptor))
10258     {
10259       offset += crtl->outgoing_args_size;
10260       frame->outgoing_arguments_size = crtl->outgoing_args_size;
10261     }
10262   else
10263     frame->outgoing_arguments_size = 0;
10264
10265   /* Align stack boundary.  Only needed if we're calling another function
10266      or using alloca.  */
10267   if (!crtl->is_leaf || cfun->calls_alloca
10268       || ix86_current_function_calls_tls_descriptor)
10269     offset = (offset + preferred_alignment - 1) & -preferred_alignment;
10270
10271   /* We've reached end of stack frame.  */
10272   frame->stack_pointer_offset = offset;
10273
10274   /* Size prologue needs to allocate.  */
10275   to_allocate = offset - frame->sse_reg_save_offset;
10276
10277   if ((!to_allocate && frame->nregs <= 1)
10278       || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000))
10279     frame->save_regs_using_mov = false;
10280
10281   if (ix86_using_red_zone ()
10282       && crtl->sp_is_unchanging
10283       && crtl->is_leaf
10284       && !ix86_current_function_calls_tls_descriptor)
10285     {
10286       frame->red_zone_size = to_allocate;
10287       if (frame->save_regs_using_mov)
10288         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
10289       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
10290         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
10291     }
10292   else
10293     frame->red_zone_size = 0;
10294   frame->stack_pointer_offset -= frame->red_zone_size;
10295
10296   /* The SEH frame pointer location is near the bottom of the frame.
10297      This is enforced by the fact that the difference between the
10298      stack pointer and the frame pointer is limited to 240 bytes in
10299      the unwind data structure.  */
10300   if (TARGET_SEH)
10301     {
10302       HOST_WIDE_INT diff;
10303
10304       /* If we can leave the frame pointer where it is, do so.  Also, returns
10305          the establisher frame for __builtin_frame_address (0).  */
10306       diff = frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
10307       if (diff <= SEH_MAX_FRAME_SIZE
10308           && (diff > 240 || (diff & 15) != 0)
10309           && !crtl->accesses_prior_frames)
10310         {
10311           /* Ideally we'd determine what portion of the local stack frame
10312              (within the constraint of the lowest 240) is most heavily used.
10313              But without that complication, simply bias the frame pointer
10314              by 128 bytes so as to maximize the amount of the local stack
10315              frame that is addressable with 8-bit offsets.  */
10316           frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128;
10317         }
10318     }
10319 }
10320
10321 /* This is semi-inlined memory_address_length, but simplified
10322    since we know that we're always dealing with reg+offset, and
10323    to avoid having to create and discard all that rtl.  */
10324
10325 static inline int
10326 choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
10327 {
10328   int len = 4;
10329
10330   if (offset == 0)
10331     {
10332       /* EBP and R13 cannot be encoded without an offset.  */
10333       len = (regno == BP_REG || regno == R13_REG);
10334     }
10335   else if (IN_RANGE (offset, -128, 127))
10336     len = 1;
10337
10338   /* ESP and R12 must be encoded with a SIB byte.  */
10339   if (regno == SP_REG || regno == R12_REG)
10340     len++;
10341
10342   return len;
10343 }
10344
10345 /* Return an RTX that points to CFA_OFFSET within the stack frame.
10346    The valid base registers are taken from CFUN->MACHINE->FS.  */
10347
10348 static rtx
10349 choose_baseaddr (HOST_WIDE_INT cfa_offset)
10350 {
10351   const struct machine_function *m = cfun->machine;
10352   rtx base_reg = NULL;
10353   HOST_WIDE_INT base_offset = 0;
10354
10355   if (m->use_fast_prologue_epilogue)
10356     {
10357       /* Choose the base register most likely to allow the most scheduling
10358          opportunities.  Generally FP is valid throughout the function,
10359          while DRAP must be reloaded within the epilogue.  But choose either
10360          over the SP due to increased encoding size.  */
10361
10362       if (m->fs.fp_valid)
10363         {
10364           base_reg = hard_frame_pointer_rtx;
10365           base_offset = m->fs.fp_offset - cfa_offset;
10366         }
10367       else if (m->fs.drap_valid)
10368         {
10369           base_reg = crtl->drap_reg;
10370           base_offset = 0 - cfa_offset;
10371         }
10372       else if (m->fs.sp_valid)
10373         {
10374           base_reg = stack_pointer_rtx;
10375           base_offset = m->fs.sp_offset - cfa_offset;
10376         }
10377     }
10378   else
10379     {
10380       HOST_WIDE_INT toffset;
10381       int len = 16, tlen;
10382
10383       /* Choose the base register with the smallest address encoding.
10384          With a tie, choose FP > DRAP > SP.  */
10385       if (m->fs.sp_valid)
10386         {
10387           base_reg = stack_pointer_rtx;
10388           base_offset = m->fs.sp_offset - cfa_offset;
10389           len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset);
10390         }
10391       if (m->fs.drap_valid)
10392         {
10393           toffset = 0 - cfa_offset;
10394           tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset);
10395           if (tlen <= len)
10396             {
10397               base_reg = crtl->drap_reg;
10398               base_offset = toffset;
10399               len = tlen;
10400             }
10401         }
10402       if (m->fs.fp_valid)
10403         {
10404           toffset = m->fs.fp_offset - cfa_offset;
10405           tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset);
10406           if (tlen <= len)
10407             {
10408               base_reg = hard_frame_pointer_rtx;
10409               base_offset = toffset;
10410               len = tlen;
10411             }
10412         }
10413     }
10414   gcc_assert (base_reg != NULL);
10415
10416   return plus_constant (Pmode, base_reg, base_offset);
10417 }
10418
10419 /* Emit code to save registers in the prologue.  */
10420
10421 static void
10422 ix86_emit_save_regs (void)
10423 {
10424   unsigned int regno;
10425   rtx_insn *insn;
10426
10427   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
10428     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10429       {
10430         insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno)));
10431         RTX_FRAME_RELATED_P (insn) = 1;
10432       }
10433 }
10434
10435 /* Emit a single register save at CFA - CFA_OFFSET.  */
10436
10437 static void
10438 ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
10439                               HOST_WIDE_INT cfa_offset)
10440 {
10441   struct machine_function *m = cfun->machine;
10442   rtx reg = gen_rtx_REG (mode, regno);
10443   rtx mem, addr, base, insn;
10444
10445   addr = choose_baseaddr (cfa_offset);
10446   mem = gen_frame_mem (mode, addr);
10447
10448   /* For SSE saves, we need to indicate the 128-bit alignment.  */
10449   set_mem_align (mem, GET_MODE_ALIGNMENT (mode));
10450
10451   insn = emit_move_insn (mem, reg);
10452   RTX_FRAME_RELATED_P (insn) = 1;
10453
10454   base = addr;
10455   if (GET_CODE (base) == PLUS)
10456     base = XEXP (base, 0);
10457   gcc_checking_assert (REG_P (base));
10458
10459   /* When saving registers into a re-aligned local stack frame, avoid
10460      any tricky guessing by dwarf2out.  */
10461   if (m->fs.realigned)
10462     {
10463       gcc_checking_assert (stack_realign_drap);
10464
10465       if (regno == REGNO (crtl->drap_reg))
10466         {
10467           /* A bit of a hack.  We force the DRAP register to be saved in
10468              the re-aligned stack frame, which provides us with a copy
10469              of the CFA that will last past the prologue.  Install it.  */
10470           gcc_checking_assert (cfun->machine->fs.fp_valid);
10471           addr = plus_constant (Pmode, hard_frame_pointer_rtx,
10472                                 cfun->machine->fs.fp_offset - cfa_offset);
10473           mem = gen_rtx_MEM (mode, addr);
10474           add_reg_note (insn, REG_CFA_DEF_CFA, mem);
10475         }
10476       else
10477         {
10478           /* The frame pointer is a stable reference within the
10479              aligned frame.  Use it.  */
10480           gcc_checking_assert (cfun->machine->fs.fp_valid);
10481           addr = plus_constant (Pmode, hard_frame_pointer_rtx,
10482                                 cfun->machine->fs.fp_offset - cfa_offset);
10483           mem = gen_rtx_MEM (mode, addr);
10484           add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
10485         }
10486     }
10487
10488   /* The memory may not be relative to the current CFA register,
10489      which means that we may need to generate a new pattern for
10490      use by the unwind info.  */
10491   else if (base != m->fs.cfa_reg)
10492     {
10493       addr = plus_constant (Pmode, m->fs.cfa_reg,
10494                             m->fs.cfa_offset - cfa_offset);
10495       mem = gen_rtx_MEM (mode, addr);
10496       add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (mem, reg));
10497     }
10498 }
10499
10500 /* Emit code to save registers using MOV insns.
10501    First register is stored at CFA - CFA_OFFSET.  */
10502 static void
10503 ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
10504 {
10505   unsigned int regno;
10506
10507   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10508     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10509       {
10510         ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
10511         cfa_offset -= UNITS_PER_WORD;
10512       }
10513 }
10514
10515 /* Emit code to save SSE registers using MOV insns.
10516    First register is stored at CFA - CFA_OFFSET.  */
10517 static void
10518 ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
10519 {
10520   unsigned int regno;
10521
10522   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10523     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10524       {
10525         ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
10526         cfa_offset -= 16;
10527       }
10528 }
10529
10530 static GTY(()) rtx queued_cfa_restores;
10531
10532 /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
10533    manipulation insn.  The value is on the stack at CFA - CFA_OFFSET.
10534    Don't add the note if the previously saved value will be left untouched
10535    within stack red-zone till return, as unwinders can find the same value
10536    in the register and on the stack.  */
10537
10538 static void
10539 ix86_add_cfa_restore_note (rtx_insn *insn, rtx reg, HOST_WIDE_INT cfa_offset)
10540 {
10541   if (!crtl->shrink_wrapped
10542       && cfa_offset <= cfun->machine->fs.red_zone_offset)
10543     return;
10544
10545   if (insn)
10546     {
10547       add_reg_note (insn, REG_CFA_RESTORE, reg);
10548       RTX_FRAME_RELATED_P (insn) = 1;
10549     }
10550   else
10551     queued_cfa_restores
10552       = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
10553 }
10554
10555 /* Add queued REG_CFA_RESTORE notes if any to INSN.  */
10556
10557 static void
10558 ix86_add_queued_cfa_restore_notes (rtx insn)
10559 {
10560   rtx last;
10561   if (!queued_cfa_restores)
10562     return;
10563   for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
10564     ;
10565   XEXP (last, 1) = REG_NOTES (insn);
10566   REG_NOTES (insn) = queued_cfa_restores;
10567   queued_cfa_restores = NULL_RTX;
10568   RTX_FRAME_RELATED_P (insn) = 1;
10569 }
10570
10571 /* Expand prologue or epilogue stack adjustment.
10572    The pattern exist to put a dependency on all ebp-based memory accesses.
10573    STYLE should be negative if instructions should be marked as frame related,
10574    zero if %r11 register is live and cannot be freely used and positive
10575    otherwise.  */
10576
10577 static void
10578 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
10579                            int style, bool set_cfa)
10580 {
10581   struct machine_function *m = cfun->machine;
10582   rtx insn;
10583   bool add_frame_related_expr = false;
10584
10585   if (Pmode == SImode)
10586     insn = gen_pro_epilogue_adjust_stack_si_add (dest, src, offset);
10587   else if (x86_64_immediate_operand (offset, DImode))
10588     insn = gen_pro_epilogue_adjust_stack_di_add (dest, src, offset);
10589   else
10590     {
10591       rtx tmp;
10592       /* r11 is used by indirect sibcall return as well, set before the
10593          epilogue and used after the epilogue.  */
10594       if (style)
10595         tmp = gen_rtx_REG (DImode, R11_REG);
10596       else
10597         {
10598           gcc_assert (src != hard_frame_pointer_rtx
10599                       && dest != hard_frame_pointer_rtx);
10600           tmp = hard_frame_pointer_rtx;
10601         }
10602       insn = emit_insn (gen_rtx_SET (tmp, offset));
10603       if (style < 0)
10604         add_frame_related_expr = true;
10605
10606       insn = gen_pro_epilogue_adjust_stack_di_add (dest, src, tmp);
10607     }
10608
10609   insn = emit_insn (insn);
10610   if (style >= 0)
10611     ix86_add_queued_cfa_restore_notes (insn);
10612
10613   if (set_cfa)
10614     {
10615       rtx r;
10616
10617       gcc_assert (m->fs.cfa_reg == src);
10618       m->fs.cfa_offset += INTVAL (offset);
10619       m->fs.cfa_reg = dest;
10620
10621       r = gen_rtx_PLUS (Pmode, src, offset);
10622       r = gen_rtx_SET (dest, r);
10623       add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
10624       RTX_FRAME_RELATED_P (insn) = 1;
10625     }
10626   else if (style < 0)
10627     {
10628       RTX_FRAME_RELATED_P (insn) = 1;
10629       if (add_frame_related_expr)
10630         {
10631           rtx r = gen_rtx_PLUS (Pmode, src, offset);
10632           r = gen_rtx_SET (dest, r);
10633           add_reg_note (insn, REG_FRAME_RELATED_EXPR, r);
10634         }
10635     }
10636
10637   if (dest == stack_pointer_rtx)
10638     {
10639       HOST_WIDE_INT ooffset = m->fs.sp_offset;
10640       bool valid = m->fs.sp_valid;
10641
10642       if (src == hard_frame_pointer_rtx)
10643         {
10644           valid = m->fs.fp_valid;
10645           ooffset = m->fs.fp_offset;
10646         }
10647       else if (src == crtl->drap_reg)
10648         {
10649           valid = m->fs.drap_valid;
10650           ooffset = 0;
10651         }
10652       else
10653         {
10654           /* Else there are two possibilities: SP itself, which we set
10655              up as the default above.  Or EH_RETURN_STACKADJ_RTX, which is
10656              taken care of this by hand along the eh_return path.  */
10657           gcc_checking_assert (src == stack_pointer_rtx
10658                                || offset == const0_rtx);
10659         }
10660
10661       m->fs.sp_offset = ooffset - INTVAL (offset);
10662       m->fs.sp_valid = valid;
10663     }
10664 }
10665
10666 /* Find an available register to be used as dynamic realign argument
10667    pointer regsiter.  Such a register will be written in prologue and
10668    used in begin of body, so it must not be
10669         1. parameter passing register.
10670         2. GOT pointer.
10671    We reuse static-chain register if it is available.  Otherwise, we
10672    use DI for i386 and R13 for x86-64.  We chose R13 since it has
10673    shorter encoding.
10674
10675    Return: the regno of chosen register.  */
10676
10677 static unsigned int
10678 find_drap_reg (void)
10679 {
10680   tree decl = cfun->decl;
10681
10682   if (TARGET_64BIT)
10683     {
10684       /* Use R13 for nested function or function need static chain.
10685          Since function with tail call may use any caller-saved
10686          registers in epilogue, DRAP must not use caller-saved
10687          register in such case.  */
10688       if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
10689         return R13_REG;
10690
10691       return R10_REG;
10692     }
10693   else
10694     {
10695       /* Use DI for nested function or function need static chain.
10696          Since function with tail call may use any caller-saved
10697          registers in epilogue, DRAP must not use caller-saved
10698          register in such case.  */
10699       if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
10700         return DI_REG;
10701
10702       /* Reuse static chain register if it isn't used for parameter
10703          passing.  */
10704       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2)
10705         {
10706           unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl));
10707           if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0)
10708             return CX_REG;
10709         }
10710       return DI_REG;
10711     }
10712 }
10713
10714 /* Return minimum incoming stack alignment.  */
10715
10716 static unsigned int
10717 ix86_minimum_incoming_stack_boundary (bool sibcall)
10718 {
10719   unsigned int incoming_stack_boundary;
10720
10721   /* Prefer the one specified at command line. */
10722   if (ix86_user_incoming_stack_boundary)
10723     incoming_stack_boundary = ix86_user_incoming_stack_boundary;
10724   /* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary
10725      if -mstackrealign is used, it isn't used for sibcall check and
10726      estimated stack alignment is 128bit.  */
10727   else if (!sibcall
10728            && !TARGET_64BIT
10729            && ix86_force_align_arg_pointer
10730            && crtl->stack_alignment_estimated == 128)
10731     incoming_stack_boundary = MIN_STACK_BOUNDARY;
10732   else
10733     incoming_stack_boundary = ix86_default_incoming_stack_boundary;
10734
10735   /* Incoming stack alignment can be changed on individual functions
10736      via force_align_arg_pointer attribute.  We use the smallest
10737      incoming stack boundary.  */
10738   if (incoming_stack_boundary > MIN_STACK_BOUNDARY
10739       && lookup_attribute (ix86_force_align_arg_pointer_string,
10740                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
10741     incoming_stack_boundary = MIN_STACK_BOUNDARY;
10742
10743   /* The incoming stack frame has to be aligned at least at
10744      parm_stack_boundary.  */
10745   if (incoming_stack_boundary < crtl->parm_stack_boundary)
10746     incoming_stack_boundary = crtl->parm_stack_boundary;
10747
10748   /* Stack at entrance of main is aligned by runtime.  We use the
10749      smallest incoming stack boundary. */
10750   if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
10751       && DECL_NAME (current_function_decl)
10752       && MAIN_NAME_P (DECL_NAME (current_function_decl))
10753       && DECL_FILE_SCOPE_P (current_function_decl))
10754     incoming_stack_boundary = MAIN_STACK_BOUNDARY;
10755
10756   return incoming_stack_boundary;
10757 }
10758
10759 /* Update incoming stack boundary and estimated stack alignment.  */
10760
10761 static void
10762 ix86_update_stack_boundary (void)
10763 {
10764   ix86_incoming_stack_boundary
10765     = ix86_minimum_incoming_stack_boundary (false);
10766
10767   /* x86_64 vararg needs 16byte stack alignment for register save
10768      area.  */
10769   if (TARGET_64BIT
10770       && cfun->stdarg
10771       && crtl->stack_alignment_estimated < 128)
10772     crtl->stack_alignment_estimated = 128;
10773 }
10774
10775 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
10776    needed or an rtx for DRAP otherwise.  */
10777
10778 static rtx
10779 ix86_get_drap_rtx (void)
10780 {
10781   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
10782     crtl->need_drap = true;
10783
10784   if (stack_realign_drap)
10785     {
10786       /* Assign DRAP to vDRAP and returns vDRAP */
10787       unsigned int regno = find_drap_reg ();
10788       rtx drap_vreg;
10789       rtx arg_ptr;
10790       rtx_insn *seq, *insn;
10791
10792       arg_ptr = gen_rtx_REG (Pmode, regno);
10793       crtl->drap_reg = arg_ptr;
10794
10795       start_sequence ();
10796       drap_vreg = copy_to_reg (arg_ptr);
10797       seq = get_insns ();
10798       end_sequence ();
10799
10800       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
10801       if (!optimize)
10802         {
10803           add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg);
10804           RTX_FRAME_RELATED_P (insn) = 1;
10805         }
10806       return drap_vreg;
10807     }
10808   else
10809     return NULL;
10810 }
10811
10812 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
10813
10814 static rtx
10815 ix86_internal_arg_pointer (void)
10816 {
10817   return virtual_incoming_args_rtx;
10818 }
10819
10820 struct scratch_reg {
10821   rtx reg;
10822   bool saved;
10823 };
10824
10825 /* Return a short-lived scratch register for use on function entry.
10826    In 32-bit mode, it is valid only after the registers are saved
10827    in the prologue.  This register must be released by means of
10828    release_scratch_register_on_entry once it is dead.  */
10829
10830 static void
10831 get_scratch_register_on_entry (struct scratch_reg *sr)
10832 {
10833   int regno;
10834
10835   sr->saved = false;
10836
10837   if (TARGET_64BIT)
10838     {
10839       /* We always use R11 in 64-bit mode.  */
10840       regno = R11_REG;
10841     }
10842   else
10843     {
10844       tree decl = current_function_decl, fntype = TREE_TYPE (decl);
10845       bool fastcall_p
10846         = lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
10847       bool thiscall_p
10848         = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
10849       bool static_chain_p = DECL_STATIC_CHAIN (decl);
10850       int regparm = ix86_function_regparm (fntype, decl);
10851       int drap_regno
10852         = crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM;
10853
10854       /* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax
10855           for the static chain register.  */
10856       if ((regparm < 1 || (fastcall_p && !static_chain_p))
10857           && drap_regno != AX_REG)
10858         regno = AX_REG;
10859       /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
10860           for the static chain register.  */
10861       else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
10862         regno = AX_REG;
10863       else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
10864         regno = DX_REG;
10865       /* ecx is the static chain register.  */
10866       else if (regparm < 3 && !fastcall_p && !thiscall_p
10867                && !static_chain_p
10868                && drap_regno != CX_REG)
10869         regno = CX_REG;
10870       else if (ix86_save_reg (BX_REG, true))
10871         regno = BX_REG;
10872       /* esi is the static chain register.  */
10873       else if (!(regparm == 3 && static_chain_p)
10874                && ix86_save_reg (SI_REG, true))
10875         regno = SI_REG;
10876       else if (ix86_save_reg (DI_REG, true))
10877         regno = DI_REG;
10878       else
10879         {
10880           regno = (drap_regno == AX_REG ? DX_REG : AX_REG);
10881           sr->saved = true;
10882         }
10883     }
10884
10885   sr->reg = gen_rtx_REG (Pmode, regno);
10886   if (sr->saved)
10887     {
10888       rtx_insn *insn = emit_insn (gen_push (sr->reg));
10889       RTX_FRAME_RELATED_P (insn) = 1;
10890     }
10891 }
10892
10893 /* Release a scratch register obtained from the preceding function.  */
10894
10895 static void
10896 release_scratch_register_on_entry (struct scratch_reg *sr)
10897 {
10898   if (sr->saved)
10899     {
10900       struct machine_function *m = cfun->machine;
10901       rtx x, insn = emit_insn (gen_pop (sr->reg));
10902
10903       /* The RTX_FRAME_RELATED_P mechanism doesn't know about pop.  */
10904       RTX_FRAME_RELATED_P (insn) = 1;
10905       x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
10906       x = gen_rtx_SET (stack_pointer_rtx, x);
10907       add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
10908       m->fs.sp_offset -= UNITS_PER_WORD;
10909     }
10910 }
10911
10912 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
10913
10914 /* Emit code to adjust the stack pointer by SIZE bytes while probing it.  */
10915
10916 static void
10917 ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
10918 {
10919   /* We skip the probe for the first interval + a small dope of 4 words and
10920      probe that many bytes past the specified size to maintain a protection
10921      area at the botton of the stack.  */
10922   const int dope = 4 * UNITS_PER_WORD;
10923   rtx size_rtx = GEN_INT (size), last;
10924
10925   /* See if we have a constant small number of probes to generate.  If so,
10926      that's the easy case.  The run-time loop is made up of 11 insns in the
10927      generic case while the compile-time loop is made up of 3+2*(n-1) insns
10928      for n # of intervals.  */
10929   if (size <= 5 * PROBE_INTERVAL)
10930     {
10931       HOST_WIDE_INT i, adjust;
10932       bool first_probe = true;
10933
10934       /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for
10935          values of N from 1 until it exceeds SIZE.  If only one probe is
10936          needed, this will not generate any code.  Then adjust and probe
10937          to PROBE_INTERVAL + SIZE.  */
10938       for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
10939         {
10940           if (first_probe)
10941             {
10942               adjust = 2 * PROBE_INTERVAL + dope;
10943               first_probe = false;
10944             }
10945           else
10946             adjust = PROBE_INTERVAL;
10947
10948           emit_insn (gen_rtx_SET (stack_pointer_rtx,
10949                                   plus_constant (Pmode, stack_pointer_rtx,
10950                                                  -adjust)));
10951           emit_stack_probe (stack_pointer_rtx);
10952         }
10953
10954       if (first_probe)
10955         adjust = size + PROBE_INTERVAL + dope;
10956       else
10957         adjust = size + PROBE_INTERVAL - i;
10958
10959       emit_insn (gen_rtx_SET (stack_pointer_rtx,
10960                               plus_constant (Pmode, stack_pointer_rtx,
10961                                              -adjust)));
10962       emit_stack_probe (stack_pointer_rtx);
10963
10964       /* Adjust back to account for the additional first interval.  */
10965       last = emit_insn (gen_rtx_SET (stack_pointer_rtx,
10966                                      plus_constant (Pmode, stack_pointer_rtx,
10967                                                     PROBE_INTERVAL + dope)));
10968     }
10969
10970   /* Otherwise, do the same as above, but in a loop.  Note that we must be
10971      extra careful with variables wrapping around because we might be at
10972      the very top (or the very bottom) of the address space and we have
10973      to be able to handle this case properly; in particular, we use an
10974      equality test for the loop condition.  */
10975   else
10976     {
10977       HOST_WIDE_INT rounded_size;
10978       struct scratch_reg sr;
10979
10980       get_scratch_register_on_entry (&sr);
10981
10982
10983       /* Step 1: round SIZE to the previous multiple of the interval.  */
10984
10985       rounded_size = size & -PROBE_INTERVAL;
10986
10987
10988       /* Step 2: compute initial and final value of the loop counter.  */
10989
10990       /* SP = SP_0 + PROBE_INTERVAL.  */
10991       emit_insn (gen_rtx_SET (stack_pointer_rtx,
10992                               plus_constant (Pmode, stack_pointer_rtx,
10993                                              - (PROBE_INTERVAL + dope))));
10994
10995       /* LAST_ADDR = SP_0 + PROBE_INTERVAL + ROUNDED_SIZE.  */
10996       emit_move_insn (sr.reg, GEN_INT (-rounded_size));
10997       emit_insn (gen_rtx_SET (sr.reg,
10998                               gen_rtx_PLUS (Pmode, sr.reg,
10999                                             stack_pointer_rtx)));
11000
11001
11002       /* Step 3: the loop
11003
11004          while (SP != LAST_ADDR)
11005            {
11006              SP = SP + PROBE_INTERVAL
11007              probe at SP
11008            }
11009
11010          adjusts SP and probes to PROBE_INTERVAL + N * PROBE_INTERVAL for
11011          values of N from 1 until it is equal to ROUNDED_SIZE.  */
11012
11013       emit_insn (ix86_gen_adjust_stack_and_probe (sr.reg, sr.reg, size_rtx));
11014
11015
11016       /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot
11017          assert at compile-time that SIZE is equal to ROUNDED_SIZE.  */
11018
11019       if (size != rounded_size)
11020         {
11021           emit_insn (gen_rtx_SET (stack_pointer_rtx,
11022                                   plus_constant (Pmode, stack_pointer_rtx,
11023                                                  rounded_size - size)));
11024           emit_stack_probe (stack_pointer_rtx);
11025         }
11026
11027       /* Adjust back to account for the additional first interval.  */
11028       last = emit_insn (gen_rtx_SET (stack_pointer_rtx,
11029                                      plus_constant (Pmode, stack_pointer_rtx,
11030                                                     PROBE_INTERVAL + dope)));
11031
11032       release_scratch_register_on_entry (&sr);
11033     }
11034
11035   gcc_assert (cfun->machine->fs.cfa_reg != stack_pointer_rtx);
11036
11037   /* Even if the stack pointer isn't the CFA register, we need to correctly
11038      describe the adjustments made to it, in particular differentiate the
11039      frame-related ones from the frame-unrelated ones.  */
11040   if (size > 0)
11041     {
11042       rtx expr = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
11043       XVECEXP (expr, 0, 0)
11044         = gen_rtx_SET (stack_pointer_rtx,
11045                        plus_constant (Pmode, stack_pointer_rtx, -size));
11046       XVECEXP (expr, 0, 1)
11047         = gen_rtx_SET (stack_pointer_rtx,
11048                        plus_constant (Pmode, stack_pointer_rtx,
11049                                       PROBE_INTERVAL + dope + size));
11050       add_reg_note (last, REG_FRAME_RELATED_EXPR, expr);
11051       RTX_FRAME_RELATED_P (last) = 1;
11052
11053       cfun->machine->fs.sp_offset += size;
11054     }
11055
11056   /* Make sure nothing is scheduled before we are done.  */
11057   emit_insn (gen_blockage ());
11058 }
11059
11060 /* Adjust the stack pointer up to REG while probing it.  */
11061
11062 const char *
11063 output_adjust_stack_and_probe (rtx reg)
11064 {
11065   static int labelno = 0;
11066   char loop_lab[32], end_lab[32];
11067   rtx xops[2];
11068
11069   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
11070   ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
11071
11072   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
11073
11074   /* Jump to END_LAB if SP == LAST_ADDR.  */
11075   xops[0] = stack_pointer_rtx;
11076   xops[1] = reg;
11077   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
11078   fputs ("\tje\t", asm_out_file);
11079   assemble_name_raw (asm_out_file, end_lab);
11080   fputc ('\n', asm_out_file);
11081
11082   /* SP = SP + PROBE_INTERVAL.  */
11083   xops[1] = GEN_INT (PROBE_INTERVAL);
11084   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
11085
11086   /* Probe at SP.  */
11087   xops[1] = const0_rtx;
11088   output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops);
11089
11090   fprintf (asm_out_file, "\tjmp\t");
11091   assemble_name_raw (asm_out_file, loop_lab);
11092   fputc ('\n', asm_out_file);
11093
11094   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
11095
11096   return "";
11097 }
11098
11099 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
11100    inclusive.  These are offsets from the current stack pointer.  */
11101
11102 static void
11103 ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
11104 {
11105   /* See if we have a constant small number of probes to generate.  If so,
11106      that's the easy case.  The run-time loop is made up of 7 insns in the
11107      generic case while the compile-time loop is made up of n insns for n #
11108      of intervals.  */
11109   if (size <= 7 * PROBE_INTERVAL)
11110     {
11111       HOST_WIDE_INT i;
11112
11113       /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
11114          it exceeds SIZE.  If only one probe is needed, this will not
11115          generate any code.  Then probe at FIRST + SIZE.  */
11116       for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
11117         emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
11118                                          -(first + i)));
11119
11120       emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
11121                                        -(first + size)));
11122     }
11123
11124   /* Otherwise, do the same as above, but in a loop.  Note that we must be
11125      extra careful with variables wrapping around because we might be at
11126      the very top (or the very bottom) of the address space and we have
11127      to be able to handle this case properly; in particular, we use an
11128      equality test for the loop condition.  */
11129   else
11130     {
11131       HOST_WIDE_INT rounded_size, last;
11132       struct scratch_reg sr;
11133
11134       get_scratch_register_on_entry (&sr);
11135
11136
11137       /* Step 1: round SIZE to the previous multiple of the interval.  */
11138
11139       rounded_size = size & -PROBE_INTERVAL;
11140
11141
11142       /* Step 2: compute initial and final value of the loop counter.  */
11143
11144       /* TEST_OFFSET = FIRST.  */
11145       emit_move_insn (sr.reg, GEN_INT (-first));
11146
11147       /* LAST_OFFSET = FIRST + ROUNDED_SIZE.  */
11148       last = first + rounded_size;
11149
11150
11151       /* Step 3: the loop
11152
11153          while (TEST_ADDR != LAST_ADDR)
11154            {
11155              TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
11156              probe at TEST_ADDR
11157            }
11158
11159          probes at FIRST + N * PROBE_INTERVAL for values of N from 1
11160          until it is equal to ROUNDED_SIZE.  */
11161
11162       emit_insn (ix86_gen_probe_stack_range (sr.reg, sr.reg, GEN_INT (-last)));
11163
11164
11165       /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
11166          that SIZE is equal to ROUNDED_SIZE.  */
11167
11168       if (size != rounded_size)
11169         emit_stack_probe (plus_constant (Pmode,
11170                                          gen_rtx_PLUS (Pmode,
11171                                                        stack_pointer_rtx,
11172                                                        sr.reg),
11173                                          rounded_size - size));
11174
11175       release_scratch_register_on_entry (&sr);
11176     }
11177
11178   /* Make sure nothing is scheduled before we are done.  */
11179   emit_insn (gen_blockage ());
11180 }
11181
11182 /* Probe a range of stack addresses from REG to END, inclusive.  These are
11183    offsets from the current stack pointer.  */
11184
11185 const char *
11186 output_probe_stack_range (rtx reg, rtx end)
11187 {
11188   static int labelno = 0;
11189   char loop_lab[32], end_lab[32];
11190   rtx xops[3];
11191
11192   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
11193   ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
11194
11195   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
11196
11197   /* Jump to END_LAB if TEST_ADDR == LAST_ADDR.  */
11198   xops[0] = reg;
11199   xops[1] = end;
11200   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
11201   fputs ("\tje\t", asm_out_file);
11202   assemble_name_raw (asm_out_file, end_lab);
11203   fputc ('\n', asm_out_file);
11204
11205   /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL.  */
11206   xops[1] = GEN_INT (PROBE_INTERVAL);
11207   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
11208
11209   /* Probe at TEST_ADDR.  */
11210   xops[0] = stack_pointer_rtx;
11211   xops[1] = reg;
11212   xops[2] = const0_rtx;
11213   output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops);
11214
11215   fprintf (asm_out_file, "\tjmp\t");
11216   assemble_name_raw (asm_out_file, loop_lab);
11217   fputc ('\n', asm_out_file);
11218
11219   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
11220
11221   return "";
11222 }
11223
11224 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
11225    to be generated in correct form.  */
11226 static void
11227 ix86_finalize_stack_realign_flags (void)
11228 {
11229   /* Check if stack realign is really needed after reload, and
11230      stores result in cfun */
11231   unsigned int incoming_stack_boundary
11232     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
11233        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
11234   unsigned int stack_realign = (incoming_stack_boundary
11235                                 < (crtl->is_leaf
11236                                    ? crtl->max_used_stack_slot_alignment
11237                                    : crtl->stack_alignment_needed));
11238
11239   if (crtl->stack_realign_finalized)
11240     {
11241       /* After stack_realign_needed is finalized, we can't no longer
11242          change it.  */
11243       gcc_assert (crtl->stack_realign_needed == stack_realign);
11244       return;
11245     }
11246
11247   /* If the only reason for frame_pointer_needed is that we conservatively
11248      assumed stack realignment might be needed, but in the end nothing that
11249      needed the stack alignment had been spilled, clear frame_pointer_needed
11250      and say we don't need stack realignment.  */
11251   if (stack_realign
11252       && frame_pointer_needed
11253       && crtl->is_leaf
11254       && flag_omit_frame_pointer
11255       && crtl->sp_is_unchanging
11256       && !ix86_current_function_calls_tls_descriptor
11257       && !crtl->accesses_prior_frames
11258       && !cfun->calls_alloca
11259       && !crtl->calls_eh_return
11260       && !(flag_stack_check && STACK_CHECK_MOVING_SP)
11261       && !ix86_frame_pointer_required ()
11262       && get_frame_size () == 0
11263       && ix86_nsaved_sseregs () == 0
11264       && ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0)
11265     {
11266       HARD_REG_SET set_up_by_prologue, prologue_used;
11267       basic_block bb;
11268
11269       CLEAR_HARD_REG_SET (prologue_used);
11270       CLEAR_HARD_REG_SET (set_up_by_prologue);
11271       add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM);
11272       add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM);
11273       add_to_hard_reg_set (&set_up_by_prologue, Pmode,
11274                            HARD_FRAME_POINTER_REGNUM);
11275       FOR_EACH_BB_FN (bb, cfun)
11276         {
11277           rtx_insn *insn;
11278           FOR_BB_INSNS (bb, insn)
11279             if (NONDEBUG_INSN_P (insn)
11280                 && requires_stack_frame_p (insn, prologue_used,
11281                                            set_up_by_prologue))
11282               {
11283                 crtl->stack_realign_needed = stack_realign;
11284                 crtl->stack_realign_finalized = true;
11285                 return;
11286               }
11287         }
11288
11289       /* If drap has been set, but it actually isn't live at the start
11290          of the function, there is no reason to set it up.  */
11291       if (crtl->drap_reg)
11292         {
11293           basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
11294           if (! REGNO_REG_SET_P (DF_LR_IN (bb), REGNO (crtl->drap_reg)))
11295             {
11296               crtl->drap_reg = NULL_RTX;
11297               crtl->need_drap = false;
11298             }
11299         }
11300       else
11301         cfun->machine->no_drap_save_restore = true;
11302
11303       frame_pointer_needed = false;
11304       stack_realign = false;
11305       crtl->max_used_stack_slot_alignment = incoming_stack_boundary;
11306       crtl->stack_alignment_needed = incoming_stack_boundary;
11307       crtl->stack_alignment_estimated = incoming_stack_boundary;
11308       if (crtl->preferred_stack_boundary > incoming_stack_boundary)
11309         crtl->preferred_stack_boundary = incoming_stack_boundary;
11310       df_finish_pass (true);
11311       df_scan_alloc (NULL);
11312       df_scan_blocks ();
11313       df_compute_regs_ever_live (true);
11314       df_analyze ();
11315     }
11316
11317   crtl->stack_realign_needed = stack_realign;
11318   crtl->stack_realign_finalized = true;
11319 }
11320
11321 /* Delete SET_GOT right after entry block if it is allocated to reg.  */
11322
11323 static void
11324 ix86_elim_entry_set_got (rtx reg)
11325 {
11326   basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
11327   rtx_insn *c_insn = BB_HEAD (bb);
11328   if (!NONDEBUG_INSN_P (c_insn))
11329     c_insn = next_nonnote_nondebug_insn (c_insn);
11330   if (c_insn && NONJUMP_INSN_P (c_insn))
11331     {
11332       rtx pat = PATTERN (c_insn);
11333       if (GET_CODE (pat) == PARALLEL)
11334         {
11335           rtx vec = XVECEXP (pat, 0, 0);
11336           if (GET_CODE (vec) == SET
11337               && XINT (XEXP (vec, 1), 1) == UNSPEC_SET_GOT
11338               && REGNO (XEXP (vec, 0)) == REGNO (reg))
11339             delete_insn (c_insn);
11340         }
11341     }
11342 }
11343
11344 /* Expand the prologue into a bunch of separate insns.  */
11345
11346 void
11347 ix86_expand_prologue (void)
11348 {
11349   struct machine_function *m = cfun->machine;
11350   rtx insn, t;
11351   struct ix86_frame frame;
11352   HOST_WIDE_INT allocate;
11353   bool int_registers_saved;
11354   bool sse_registers_saved;
11355
11356   ix86_finalize_stack_realign_flags ();
11357
11358   /* DRAP should not coexist with stack_realign_fp */
11359   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
11360
11361   memset (&m->fs, 0, sizeof (m->fs));
11362
11363   /* Initialize CFA state for before the prologue.  */
11364   m->fs.cfa_reg = stack_pointer_rtx;
11365   m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET;
11366
11367   /* Track SP offset to the CFA.  We continue tracking this after we've
11368      swapped the CFA register away from SP.  In the case of re-alignment
11369      this is fudged; we're interested to offsets within the local frame.  */
11370   m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
11371   m->fs.sp_valid = true;
11372
11373   ix86_compute_frame_layout (&frame);
11374
11375   if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
11376     {
11377       /* We should have already generated an error for any use of
11378          ms_hook on a nested function.  */
11379       gcc_checking_assert (!ix86_static_chain_on_stack);
11380
11381       /* Check if profiling is active and we shall use profiling before
11382          prologue variant. If so sorry.  */
11383       if (crtl->profile && flag_fentry != 0)
11384         sorry ("ms_hook_prologue attribute isn%'t compatible "
11385                "with -mfentry for 32-bit");
11386
11387       /* In ix86_asm_output_function_label we emitted:
11388          8b ff     movl.s %edi,%edi
11389          55        push   %ebp
11390          8b ec     movl.s %esp,%ebp
11391
11392          This matches the hookable function prologue in Win32 API
11393          functions in Microsoft Windows XP Service Pack 2 and newer.
11394          Wine uses this to enable Windows apps to hook the Win32 API
11395          functions provided by Wine.
11396
11397          What that means is that we've already set up the frame pointer.  */
11398
11399       if (frame_pointer_needed
11400           && !(crtl->drap_reg && crtl->stack_realign_needed))
11401         {
11402           rtx push, mov;
11403
11404           /* We've decided to use the frame pointer already set up.
11405              Describe this to the unwinder by pretending that both
11406              push and mov insns happen right here.
11407
11408              Putting the unwind info here at the end of the ms_hook
11409              is done so that we can make absolutely certain we get
11410              the required byte sequence at the start of the function,
11411              rather than relying on an assembler that can produce
11412              the exact encoding required.
11413
11414              However it does mean (in the unpatched case) that we have
11415              a 1 insn window where the asynchronous unwind info is
11416              incorrect.  However, if we placed the unwind info at
11417              its correct location we would have incorrect unwind info
11418              in the patched case.  Which is probably all moot since
11419              I don't expect Wine generates dwarf2 unwind info for the
11420              system libraries that use this feature.  */
11421
11422           insn = emit_insn (gen_blockage ());
11423
11424           push = gen_push (hard_frame_pointer_rtx);
11425           mov = gen_rtx_SET (hard_frame_pointer_rtx,
11426                              stack_pointer_rtx);
11427           RTX_FRAME_RELATED_P (push) = 1;
11428           RTX_FRAME_RELATED_P (mov) = 1;
11429
11430           RTX_FRAME_RELATED_P (insn) = 1;
11431           add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11432                         gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov)));
11433
11434           /* Note that gen_push incremented m->fs.cfa_offset, even
11435              though we didn't emit the push insn here.  */
11436           m->fs.cfa_reg = hard_frame_pointer_rtx;
11437           m->fs.fp_offset = m->fs.cfa_offset;
11438           m->fs.fp_valid = true;
11439         }
11440       else
11441         {
11442           /* The frame pointer is not needed so pop %ebp again.
11443              This leaves us with a pristine state.  */
11444           emit_insn (gen_pop (hard_frame_pointer_rtx));
11445         }
11446     }
11447
11448   /* The first insn of a function that accepts its static chain on the
11449      stack is to push the register that would be filled in by a direct
11450      call.  This insn will be skipped by the trampoline.  */
11451   else if (ix86_static_chain_on_stack)
11452     {
11453       insn = emit_insn (gen_push (ix86_static_chain (cfun->decl, false)));
11454       emit_insn (gen_blockage ());
11455
11456       /* We don't want to interpret this push insn as a register save,
11457          only as a stack adjustment.  The real copy of the register as
11458          a save will be done later, if needed.  */
11459       t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
11460       t = gen_rtx_SET (stack_pointer_rtx, t);
11461       add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
11462       RTX_FRAME_RELATED_P (insn) = 1;
11463     }
11464
11465   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
11466      of DRAP is needed and stack realignment is really needed after reload */
11467   if (stack_realign_drap)
11468     {
11469       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
11470
11471       /* Only need to push parameter pointer reg if it is caller saved.  */
11472       if (!call_used_regs[REGNO (crtl->drap_reg)])
11473         {
11474           /* Push arg pointer reg */
11475           insn = emit_insn (gen_push (crtl->drap_reg));
11476           RTX_FRAME_RELATED_P (insn) = 1;
11477         }
11478
11479       /* Grab the argument pointer.  */
11480       t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
11481       insn = emit_insn (gen_rtx_SET (crtl->drap_reg, t));
11482       RTX_FRAME_RELATED_P (insn) = 1;
11483       m->fs.cfa_reg = crtl->drap_reg;
11484       m->fs.cfa_offset = 0;
11485
11486       /* Align the stack.  */
11487       insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
11488                                         stack_pointer_rtx,
11489                                         GEN_INT (-align_bytes)));
11490       RTX_FRAME_RELATED_P (insn) = 1;
11491
11492       /* Replicate the return address on the stack so that return
11493          address can be reached via (argp - 1) slot.  This is needed
11494          to implement macro RETURN_ADDR_RTX and intrinsic function
11495          expand_builtin_return_addr etc.  */
11496       t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
11497       t = gen_frame_mem (word_mode, t);
11498       insn = emit_insn (gen_push (t));
11499       RTX_FRAME_RELATED_P (insn) = 1;
11500
11501       /* For the purposes of frame and register save area addressing,
11502          we've started over with a new frame.  */
11503       m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
11504       m->fs.realigned = true;
11505     }
11506
11507   int_registers_saved = (frame.nregs == 0);
11508   sse_registers_saved = (frame.nsseregs == 0);
11509
11510   if (frame_pointer_needed && !m->fs.fp_valid)
11511     {
11512       /* Note: AT&T enter does NOT have reversed args.  Enter is probably
11513          slower on all targets.  Also sdb doesn't like it.  */
11514       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
11515       RTX_FRAME_RELATED_P (insn) = 1;
11516
11517       /* Push registers now, before setting the frame pointer
11518          on SEH target.  */
11519       if (!int_registers_saved
11520           && TARGET_SEH
11521           && !frame.save_regs_using_mov)
11522         {
11523           ix86_emit_save_regs ();
11524           int_registers_saved = true;
11525           gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
11526         }
11527
11528       if (m->fs.sp_offset == frame.hard_frame_pointer_offset)
11529         {
11530           insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
11531           RTX_FRAME_RELATED_P (insn) = 1;
11532
11533           if (m->fs.cfa_reg == stack_pointer_rtx)
11534             m->fs.cfa_reg = hard_frame_pointer_rtx;
11535           m->fs.fp_offset = m->fs.sp_offset;
11536           m->fs.fp_valid = true;
11537         }
11538     }
11539
11540   if (!int_registers_saved)
11541     {
11542       /* If saving registers via PUSH, do so now.  */
11543       if (!frame.save_regs_using_mov)
11544         {
11545           ix86_emit_save_regs ();
11546           int_registers_saved = true;
11547           gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
11548         }
11549
11550       /* When using red zone we may start register saving before allocating
11551          the stack frame saving one cycle of the prologue.  However, avoid
11552          doing this if we have to probe the stack; at least on x86_64 the
11553          stack probe can turn into a call that clobbers a red zone location. */
11554       else if (ix86_using_red_zone ()
11555                && (! TARGET_STACK_PROBE
11556                    || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
11557         {
11558           ix86_emit_save_regs_using_mov (frame.reg_save_offset);
11559           int_registers_saved = true;
11560         }
11561     }
11562
11563   if (stack_realign_fp)
11564     {
11565       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
11566       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
11567
11568       /* The computation of the size of the re-aligned stack frame means
11569          that we must allocate the size of the register save area before
11570          performing the actual alignment.  Otherwise we cannot guarantee
11571          that there's enough storage above the realignment point.  */
11572       if (m->fs.sp_offset != frame.sse_reg_save_offset)
11573         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11574                                    GEN_INT (m->fs.sp_offset
11575                                             - frame.sse_reg_save_offset),
11576                                    -1, false);
11577
11578       /* Align the stack.  */
11579       insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
11580                                         stack_pointer_rtx,
11581                                         GEN_INT (-align_bytes)));
11582
11583       /* For the purposes of register save area addressing, the stack
11584          pointer is no longer valid.  As for the value of sp_offset,
11585          see ix86_compute_frame_layout, which we need to match in order
11586          to pass verification of stack_pointer_offset at the end.  */
11587       m->fs.sp_offset = (m->fs.sp_offset + align_bytes) & -align_bytes;
11588       m->fs.sp_valid = false;
11589     }
11590
11591   allocate = frame.stack_pointer_offset - m->fs.sp_offset;
11592
11593   if (flag_stack_usage_info)
11594     {
11595       /* We start to count from ARG_POINTER.  */
11596       HOST_WIDE_INT stack_size = frame.stack_pointer_offset;
11597
11598       /* If it was realigned, take into account the fake frame.  */
11599       if (stack_realign_drap)
11600         {
11601           if (ix86_static_chain_on_stack)
11602             stack_size += UNITS_PER_WORD;
11603
11604           if (!call_used_regs[REGNO (crtl->drap_reg)])
11605             stack_size += UNITS_PER_WORD;
11606
11607           /* This over-estimates by 1 minimal-stack-alignment-unit but
11608              mitigates that by counting in the new return address slot.  */
11609           current_function_dynamic_stack_size
11610             += crtl->stack_alignment_needed / BITS_PER_UNIT;
11611         }
11612
11613       current_function_static_stack_size = stack_size;
11614     }
11615
11616   /* On SEH target with very large frame size, allocate an area to save
11617      SSE registers (as the very large allocation won't be described).  */
11618   if (TARGET_SEH
11619       && frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE
11620       && !sse_registers_saved)
11621     {
11622       HOST_WIDE_INT sse_size =
11623         frame.sse_reg_save_offset - frame.reg_save_offset;
11624
11625       gcc_assert (int_registers_saved);
11626
11627       /* No need to do stack checking as the area will be immediately
11628          written.  */
11629       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11630                                  GEN_INT (-sse_size), -1,
11631                                  m->fs.cfa_reg == stack_pointer_rtx);
11632       allocate -= sse_size;
11633       ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
11634       sse_registers_saved = true;
11635     }
11636
11637   /* The stack has already been decremented by the instruction calling us
11638      so probe if the size is non-negative to preserve the protection area.  */
11639   if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
11640     {
11641       /* We expect the registers to be saved when probes are used.  */
11642       gcc_assert (int_registers_saved);
11643
11644       if (STACK_CHECK_MOVING_SP)
11645         {
11646           if (!(crtl->is_leaf && !cfun->calls_alloca
11647                 && allocate <= PROBE_INTERVAL))
11648             {
11649               ix86_adjust_stack_and_probe (allocate);
11650               allocate = 0;
11651             }
11652         }
11653       else
11654         {
11655           HOST_WIDE_INT size = allocate;
11656
11657           if (TARGET_64BIT && size >= (HOST_WIDE_INT) 0x80000000)
11658             size = 0x80000000 - STACK_CHECK_PROTECT - 1;
11659
11660           if (TARGET_STACK_PROBE)
11661             {
11662               if (crtl->is_leaf && !cfun->calls_alloca)
11663                 {
11664                   if (size > PROBE_INTERVAL)
11665                     ix86_emit_probe_stack_range (0, size);
11666                 }
11667               else
11668                 ix86_emit_probe_stack_range (0, size + STACK_CHECK_PROTECT);
11669             }
11670           else
11671             {
11672               if (crtl->is_leaf && !cfun->calls_alloca)
11673                 {
11674                   if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
11675                     ix86_emit_probe_stack_range (STACK_CHECK_PROTECT,
11676                                                  size - STACK_CHECK_PROTECT);
11677                 }
11678               else
11679                 ix86_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
11680             }
11681         }
11682     }
11683
11684   if (allocate == 0)
11685     ;
11686   else if (!ix86_target_stack_probe ()
11687            || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
11688     {
11689       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11690                                  GEN_INT (-allocate), -1,
11691                                  m->fs.cfa_reg == stack_pointer_rtx);
11692     }
11693   else
11694     {
11695       rtx eax = gen_rtx_REG (Pmode, AX_REG);
11696       rtx r10 = NULL;
11697       rtx (*adjust_stack_insn)(rtx, rtx, rtx);
11698       const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx);
11699       bool eax_live = ix86_eax_live_at_start_p ();
11700       bool r10_live = false;
11701
11702       if (TARGET_64BIT)
11703         r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0);
11704
11705       if (eax_live)
11706         {
11707           insn = emit_insn (gen_push (eax));
11708           allocate -= UNITS_PER_WORD;
11709           /* Note that SEH directives need to continue tracking the stack
11710              pointer even after the frame pointer has been set up.  */
11711           if (sp_is_cfa_reg || TARGET_SEH)
11712             {
11713               if (sp_is_cfa_reg)
11714                 m->fs.cfa_offset += UNITS_PER_WORD;
11715               RTX_FRAME_RELATED_P (insn) = 1;
11716               add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11717                             gen_rtx_SET (stack_pointer_rtx,
11718                                          plus_constant (Pmode, stack_pointer_rtx,
11719                                                         -UNITS_PER_WORD)));
11720             }
11721         }
11722
11723       if (r10_live)
11724         {
11725           r10 = gen_rtx_REG (Pmode, R10_REG);
11726           insn = emit_insn (gen_push (r10));
11727           allocate -= UNITS_PER_WORD;
11728           if (sp_is_cfa_reg || TARGET_SEH)
11729             {
11730               if (sp_is_cfa_reg)
11731                 m->fs.cfa_offset += UNITS_PER_WORD;
11732               RTX_FRAME_RELATED_P (insn) = 1;
11733               add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11734                             gen_rtx_SET (stack_pointer_rtx,
11735                                          plus_constant (Pmode, stack_pointer_rtx,
11736                                                         -UNITS_PER_WORD)));
11737             }
11738         }
11739
11740       emit_move_insn (eax, GEN_INT (allocate));
11741       emit_insn (ix86_gen_allocate_stack_worker (eax, eax));
11742
11743       /* Use the fact that AX still contains ALLOCATE.  */
11744       adjust_stack_insn = (Pmode == DImode
11745                            ? gen_pro_epilogue_adjust_stack_di_sub
11746                            : gen_pro_epilogue_adjust_stack_si_sub);
11747
11748       insn = emit_insn (adjust_stack_insn (stack_pointer_rtx,
11749                                            stack_pointer_rtx, eax));
11750
11751       if (sp_is_cfa_reg || TARGET_SEH)
11752         {
11753           if (sp_is_cfa_reg)
11754             m->fs.cfa_offset += allocate;
11755           RTX_FRAME_RELATED_P (insn) = 1;
11756           add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11757                         gen_rtx_SET (stack_pointer_rtx,
11758                                      plus_constant (Pmode, stack_pointer_rtx,
11759                                                     -allocate)));
11760         }
11761       m->fs.sp_offset += allocate;
11762
11763       /* Use stack_pointer_rtx for relative addressing so that code
11764          works for realigned stack, too.  */
11765       if (r10_live && eax_live)
11766         {
11767           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
11768           emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
11769                           gen_frame_mem (word_mode, t));
11770           t = plus_constant (Pmode, t, UNITS_PER_WORD);
11771           emit_move_insn (gen_rtx_REG (word_mode, AX_REG),
11772                           gen_frame_mem (word_mode, t));
11773         }
11774       else if (eax_live || r10_live)
11775         {
11776           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
11777           emit_move_insn (gen_rtx_REG (word_mode,
11778                                        (eax_live ? AX_REG : R10_REG)),
11779                           gen_frame_mem (word_mode, t));
11780         }
11781     }
11782   gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset);
11783
11784   /* If we havn't already set up the frame pointer, do so now.  */
11785   if (frame_pointer_needed && !m->fs.fp_valid)
11786     {
11787       insn = ix86_gen_add3 (hard_frame_pointer_rtx, stack_pointer_rtx,
11788                             GEN_INT (frame.stack_pointer_offset
11789                                      - frame.hard_frame_pointer_offset));
11790       insn = emit_insn (insn);
11791       RTX_FRAME_RELATED_P (insn) = 1;
11792       add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL);
11793
11794       if (m->fs.cfa_reg == stack_pointer_rtx)
11795         m->fs.cfa_reg = hard_frame_pointer_rtx;
11796       m->fs.fp_offset = frame.hard_frame_pointer_offset;
11797       m->fs.fp_valid = true;
11798     }
11799
11800   if (!int_registers_saved)
11801     ix86_emit_save_regs_using_mov (frame.reg_save_offset);
11802   if (!sse_registers_saved)
11803     ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
11804
11805   /* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT
11806      in PROLOGUE.  */
11807   if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry)
11808     {
11809       rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM);
11810       insn = emit_insn (gen_set_got (pic));
11811       RTX_FRAME_RELATED_P (insn) = 1;
11812       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
11813       emit_insn (gen_prologue_use (pic));
11814       /* Deleting already emmitted SET_GOT if exist and allocated to
11815          REAL_PIC_OFFSET_TABLE_REGNUM.  */
11816       ix86_elim_entry_set_got (pic);
11817     }
11818
11819   if (crtl->drap_reg && !crtl->stack_realign_needed)
11820     {
11821       /* vDRAP is setup but after reload it turns out stack realign
11822          isn't necessary, here we will emit prologue to setup DRAP
11823          without stack realign adjustment */
11824       t = choose_baseaddr (0);
11825       emit_insn (gen_rtx_SET (crtl->drap_reg, t));
11826     }
11827
11828   /* Prevent instructions from being scheduled into register save push
11829      sequence when access to the redzone area is done through frame pointer.
11830      The offset between the frame pointer and the stack pointer is calculated
11831      relative to the value of the stack pointer at the end of the function
11832      prologue, and moving instructions that access redzone area via frame
11833      pointer inside push sequence violates this assumption.  */
11834   if (frame_pointer_needed && frame.red_zone_size)
11835     emit_insn (gen_memory_blockage ());
11836
11837   /* Emit cld instruction if stringops are used in the function.  */
11838   if (TARGET_CLD && ix86_current_function_needs_cld)
11839     emit_insn (gen_cld ());
11840
11841   /* SEH requires that the prologue end within 256 bytes of the start of
11842      the function.  Prevent instruction schedules that would extend that.
11843      Further, prevent alloca modifications to the stack pointer from being
11844      combined with prologue modifications.  */
11845   if (TARGET_SEH)
11846     emit_insn (gen_prologue_use (stack_pointer_rtx));
11847 }
11848
11849 /* Emit code to restore REG using a POP insn.  */
11850
11851 static void
11852 ix86_emit_restore_reg_using_pop (rtx reg)
11853 {
11854   struct machine_function *m = cfun->machine;
11855   rtx_insn *insn = emit_insn (gen_pop (reg));
11856
11857   ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset);
11858   m->fs.sp_offset -= UNITS_PER_WORD;
11859
11860   if (m->fs.cfa_reg == crtl->drap_reg
11861       && REGNO (reg) == REGNO (crtl->drap_reg))
11862     {
11863       /* Previously we'd represented the CFA as an expression
11864          like *(%ebp - 8).  We've just popped that value from
11865          the stack, which means we need to reset the CFA to
11866          the drap register.  This will remain until we restore
11867          the stack pointer.  */
11868       add_reg_note (insn, REG_CFA_DEF_CFA, reg);
11869       RTX_FRAME_RELATED_P (insn) = 1;
11870
11871       /* This means that the DRAP register is valid for addressing too.  */
11872       m->fs.drap_valid = true;
11873       return;
11874     }
11875
11876   if (m->fs.cfa_reg == stack_pointer_rtx)
11877     {
11878       rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
11879       x = gen_rtx_SET (stack_pointer_rtx, x);
11880       add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
11881       RTX_FRAME_RELATED_P (insn) = 1;
11882
11883       m->fs.cfa_offset -= UNITS_PER_WORD;
11884     }
11885
11886   /* When the frame pointer is the CFA, and we pop it, we are
11887      swapping back to the stack pointer as the CFA.  This happens
11888      for stack frames that don't allocate other data, so we assume
11889      the stack pointer is now pointing at the return address, i.e.
11890      the function entry state, which makes the offset be 1 word.  */
11891   if (reg == hard_frame_pointer_rtx)
11892     {
11893       m->fs.fp_valid = false;
11894       if (m->fs.cfa_reg == hard_frame_pointer_rtx)
11895         {
11896           m->fs.cfa_reg = stack_pointer_rtx;
11897           m->fs.cfa_offset -= UNITS_PER_WORD;
11898
11899           add_reg_note (insn, REG_CFA_DEF_CFA,
11900                         gen_rtx_PLUS (Pmode, stack_pointer_rtx,
11901                                       GEN_INT (m->fs.cfa_offset)));
11902           RTX_FRAME_RELATED_P (insn) = 1;
11903         }
11904     }
11905 }
11906
11907 /* Emit code to restore saved registers using POP insns.  */
11908
11909 static void
11910 ix86_emit_restore_regs_using_pop (void)
11911 {
11912   unsigned int regno;
11913
11914   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11915     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
11916       ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno));
11917 }
11918
11919 /* Emit code and notes for the LEAVE instruction.  */
11920
11921 static void
11922 ix86_emit_leave (void)
11923 {
11924   struct machine_function *m = cfun->machine;
11925   rtx_insn *insn = emit_insn (ix86_gen_leave ());
11926
11927   ix86_add_queued_cfa_restore_notes (insn);
11928
11929   gcc_assert (m->fs.fp_valid);
11930   m->fs.sp_valid = true;
11931   m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD;
11932   m->fs.fp_valid = false;
11933
11934   if (m->fs.cfa_reg == hard_frame_pointer_rtx)
11935     {
11936       m->fs.cfa_reg = stack_pointer_rtx;
11937       m->fs.cfa_offset = m->fs.sp_offset;
11938
11939       add_reg_note (insn, REG_CFA_DEF_CFA,
11940                     plus_constant (Pmode, stack_pointer_rtx,
11941                                    m->fs.sp_offset));
11942       RTX_FRAME_RELATED_P (insn) = 1;
11943     }
11944   ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx,
11945                              m->fs.fp_offset);
11946 }
11947
11948 /* Emit code to restore saved registers using MOV insns.
11949    First register is restored from CFA - CFA_OFFSET.  */
11950 static void
11951 ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
11952                                   bool maybe_eh_return)
11953 {
11954   struct machine_function *m = cfun->machine;
11955   unsigned int regno;
11956
11957   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11958     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
11959       {
11960         rtx reg = gen_rtx_REG (word_mode, regno);
11961         rtx mem;
11962         rtx_insn *insn;
11963
11964         mem = choose_baseaddr (cfa_offset);
11965         mem = gen_frame_mem (word_mode, mem);
11966         insn = emit_move_insn (reg, mem);
11967
11968         if (m->fs.cfa_reg == crtl->drap_reg && regno == REGNO (crtl->drap_reg))
11969           {
11970             /* Previously we'd represented the CFA as an expression
11971                like *(%ebp - 8).  We've just popped that value from
11972                the stack, which means we need to reset the CFA to
11973                the drap register.  This will remain until we restore
11974                the stack pointer.  */
11975             add_reg_note (insn, REG_CFA_DEF_CFA, reg);
11976             RTX_FRAME_RELATED_P (insn) = 1;
11977
11978             /* This means that the DRAP register is valid for addressing.  */
11979             m->fs.drap_valid = true;
11980           }
11981         else
11982           ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
11983
11984         cfa_offset -= UNITS_PER_WORD;
11985       }
11986 }
11987
11988 /* Emit code to restore saved registers using MOV insns.
11989    First register is restored from CFA - CFA_OFFSET.  */
11990 static void
11991 ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
11992                                       bool maybe_eh_return)
11993 {
11994   unsigned int regno;
11995
11996   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11997     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
11998       {
11999         rtx reg = gen_rtx_REG (V4SFmode, regno);
12000         rtx mem;
12001
12002         mem = choose_baseaddr (cfa_offset);
12003         mem = gen_rtx_MEM (V4SFmode, mem);
12004         set_mem_align (mem, 128);
12005         emit_move_insn (reg, mem);
12006
12007         ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
12008
12009         cfa_offset -= 16;
12010       }
12011 }
12012
12013 /* Restore function stack, frame, and registers.  */
12014
12015 void
12016 ix86_expand_epilogue (int style)
12017 {
12018   struct machine_function *m = cfun->machine;
12019   struct machine_frame_state frame_state_save = m->fs;
12020   struct ix86_frame frame;
12021   bool restore_regs_via_mov;
12022   bool using_drap;
12023
12024   ix86_finalize_stack_realign_flags ();
12025   ix86_compute_frame_layout (&frame);
12026
12027   m->fs.sp_valid = (!frame_pointer_needed
12028                     || (crtl->sp_is_unchanging
12029                         && !stack_realign_fp));
12030   gcc_assert (!m->fs.sp_valid
12031               || m->fs.sp_offset == frame.stack_pointer_offset);
12032
12033   /* The FP must be valid if the frame pointer is present.  */
12034   gcc_assert (frame_pointer_needed == m->fs.fp_valid);
12035   gcc_assert (!m->fs.fp_valid
12036               || m->fs.fp_offset == frame.hard_frame_pointer_offset);
12037
12038   /* We must have *some* valid pointer to the stack frame.  */
12039   gcc_assert (m->fs.sp_valid || m->fs.fp_valid);
12040
12041   /* The DRAP is never valid at this point.  */
12042   gcc_assert (!m->fs.drap_valid);
12043
12044   /* See the comment about red zone and frame
12045      pointer usage in ix86_expand_prologue.  */
12046   if (frame_pointer_needed && frame.red_zone_size)
12047     emit_insn (gen_memory_blockage ());
12048
12049   using_drap = crtl->drap_reg && crtl->stack_realign_needed;
12050   gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg);
12051
12052   /* Determine the CFA offset of the end of the red-zone.  */
12053   m->fs.red_zone_offset = 0;
12054   if (ix86_using_red_zone () && crtl->args.pops_args < 65536)
12055     {
12056       /* The red-zone begins below the return address.  */
12057       m->fs.red_zone_offset = RED_ZONE_SIZE + UNITS_PER_WORD;
12058
12059       /* When the register save area is in the aligned portion of
12060          the stack, determine the maximum runtime displacement that
12061          matches up with the aligned frame.  */
12062       if (stack_realign_drap)
12063         m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT
12064                                   + UNITS_PER_WORD);
12065     }
12066
12067   /* Special care must be taken for the normal return case of a function
12068      using eh_return: the eax and edx registers are marked as saved, but
12069      not restored along this path.  Adjust the save location to match.  */
12070   if (crtl->calls_eh_return && style != 2)
12071     frame.reg_save_offset -= 2 * UNITS_PER_WORD;
12072
12073   /* EH_RETURN requires the use of moves to function properly.  */
12074   if (crtl->calls_eh_return)
12075     restore_regs_via_mov = true;
12076   /* SEH requires the use of pops to identify the epilogue.  */
12077   else if (TARGET_SEH)
12078     restore_regs_via_mov = false;
12079   /* If we're only restoring one register and sp is not valid then
12080      using a move instruction to restore the register since it's
12081      less work than reloading sp and popping the register.  */
12082   else if (!m->fs.sp_valid && frame.nregs <= 1)
12083     restore_regs_via_mov = true;
12084   else if (TARGET_EPILOGUE_USING_MOVE
12085            && cfun->machine->use_fast_prologue_epilogue
12086            && (frame.nregs > 1
12087                || m->fs.sp_offset != frame.reg_save_offset))
12088     restore_regs_via_mov = true;
12089   else if (frame_pointer_needed
12090            && !frame.nregs
12091            && m->fs.sp_offset != frame.reg_save_offset)
12092     restore_regs_via_mov = true;
12093   else if (frame_pointer_needed
12094            && TARGET_USE_LEAVE
12095            && cfun->machine->use_fast_prologue_epilogue
12096            && frame.nregs == 1)
12097     restore_regs_via_mov = true;
12098   else
12099     restore_regs_via_mov = false;
12100
12101   if (restore_regs_via_mov || frame.nsseregs)
12102     {
12103       /* Ensure that the entire register save area is addressable via
12104          the stack pointer, if we will restore via sp.  */
12105       if (TARGET_64BIT
12106           && m->fs.sp_offset > 0x7fffffff
12107           && !(m->fs.fp_valid || m->fs.drap_valid)
12108           && (frame.nsseregs + frame.nregs) != 0)
12109         {
12110           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12111                                      GEN_INT (m->fs.sp_offset
12112                                               - frame.sse_reg_save_offset),
12113                                      style,
12114                                      m->fs.cfa_reg == stack_pointer_rtx);
12115         }
12116     }
12117
12118   /* If there are any SSE registers to restore, then we have to do it
12119      via moves, since there's obviously no pop for SSE regs.  */
12120   if (frame.nsseregs)
12121     ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset,
12122                                           style == 2);
12123
12124   if (restore_regs_via_mov)
12125     {
12126       rtx t;
12127
12128       if (frame.nregs)
12129         ix86_emit_restore_regs_using_mov (frame.reg_save_offset, style == 2);
12130
12131       /* eh_return epilogues need %ecx added to the stack pointer.  */
12132       if (style == 2)
12133         {
12134           rtx sa = EH_RETURN_STACKADJ_RTX;
12135           rtx_insn *insn;
12136
12137           /* Stack align doesn't work with eh_return.  */
12138           gcc_assert (!stack_realign_drap);
12139           /* Neither does regparm nested functions.  */
12140           gcc_assert (!ix86_static_chain_on_stack);
12141
12142           if (frame_pointer_needed)
12143             {
12144               t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
12145               t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
12146               emit_insn (gen_rtx_SET (sa, t));
12147
12148               t = gen_frame_mem (Pmode, hard_frame_pointer_rtx);
12149               insn = emit_move_insn (hard_frame_pointer_rtx, t);
12150
12151               /* Note that we use SA as a temporary CFA, as the return
12152                  address is at the proper place relative to it.  We
12153                  pretend this happens at the FP restore insn because
12154                  prior to this insn the FP would be stored at the wrong
12155                  offset relative to SA, and after this insn we have no
12156                  other reasonable register to use for the CFA.  We don't
12157                  bother resetting the CFA to the SP for the duration of
12158                  the return insn.  */
12159               add_reg_note (insn, REG_CFA_DEF_CFA,
12160                             plus_constant (Pmode, sa, UNITS_PER_WORD));
12161               ix86_add_queued_cfa_restore_notes (insn);
12162               add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx);
12163               RTX_FRAME_RELATED_P (insn) = 1;
12164
12165               m->fs.cfa_reg = sa;
12166               m->fs.cfa_offset = UNITS_PER_WORD;
12167               m->fs.fp_valid = false;
12168
12169               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
12170                                          const0_rtx, style, false);
12171             }
12172           else
12173             {
12174               t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
12175               t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD);
12176               insn = emit_insn (gen_rtx_SET (stack_pointer_rtx, t));
12177               ix86_add_queued_cfa_restore_notes (insn);
12178
12179               gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
12180               if (m->fs.cfa_offset != UNITS_PER_WORD)
12181                 {
12182                   m->fs.cfa_offset = UNITS_PER_WORD;
12183                   add_reg_note (insn, REG_CFA_DEF_CFA,
12184                                 plus_constant (Pmode, stack_pointer_rtx,
12185                                                UNITS_PER_WORD));
12186                   RTX_FRAME_RELATED_P (insn) = 1;
12187                 }
12188             }
12189           m->fs.sp_offset = UNITS_PER_WORD;
12190           m->fs.sp_valid = true;
12191         }
12192     }
12193   else
12194     {
12195       /* SEH requires that the function end with (1) a stack adjustment
12196          if necessary, (2) a sequence of pops, and (3) a return or
12197          jump instruction.  Prevent insns from the function body from
12198          being scheduled into this sequence.  */
12199       if (TARGET_SEH)
12200         {
12201           /* Prevent a catch region from being adjacent to the standard
12202              epilogue sequence.  Unfortuantely crtl->uses_eh_lsda nor
12203              several other flags that would be interesting to test are
12204              not yet set up.  */
12205           if (flag_non_call_exceptions)
12206             emit_insn (gen_nops (const1_rtx));
12207           else
12208             emit_insn (gen_blockage ());
12209         }
12210
12211       /* First step is to deallocate the stack frame so that we can
12212          pop the registers.  Also do it on SEH target for very large
12213          frame as the emitted instructions aren't allowed by the ABI in
12214          epilogues.  */
12215       if (!m->fs.sp_valid
12216           || (TARGET_SEH
12217               && (m->fs.sp_offset - frame.reg_save_offset
12218                   >= SEH_MAX_FRAME_SIZE)))
12219         {
12220           pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx,
12221                                      GEN_INT (m->fs.fp_offset
12222                                               - frame.reg_save_offset),
12223                                      style, false);
12224         }
12225       else if (m->fs.sp_offset != frame.reg_save_offset)
12226         {
12227           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12228                                      GEN_INT (m->fs.sp_offset
12229                                               - frame.reg_save_offset),
12230                                      style,
12231                                      m->fs.cfa_reg == stack_pointer_rtx);
12232         }
12233
12234       ix86_emit_restore_regs_using_pop ();
12235     }
12236
12237   /* If we used a stack pointer and haven't already got rid of it,
12238      then do so now.  */
12239   if (m->fs.fp_valid)
12240     {
12241       /* If the stack pointer is valid and pointing at the frame
12242          pointer store address, then we only need a pop.  */
12243       if (m->fs.sp_valid && m->fs.sp_offset == frame.hfp_save_offset)
12244         ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
12245       /* Leave results in shorter dependency chains on CPUs that are
12246          able to grok it fast.  */
12247       else if (TARGET_USE_LEAVE
12248                || optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun))
12249                || !cfun->machine->use_fast_prologue_epilogue)
12250         ix86_emit_leave ();
12251       else
12252         {
12253           pro_epilogue_adjust_stack (stack_pointer_rtx,
12254                                      hard_frame_pointer_rtx,
12255                                      const0_rtx, style, !using_drap);
12256           ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
12257         }
12258     }
12259
12260   if (using_drap)
12261     {
12262       int param_ptr_offset = UNITS_PER_WORD;
12263       rtx_insn *insn;
12264
12265       gcc_assert (stack_realign_drap);
12266
12267       if (ix86_static_chain_on_stack)
12268         param_ptr_offset += UNITS_PER_WORD;
12269       if (!call_used_regs[REGNO (crtl->drap_reg)])
12270         param_ptr_offset += UNITS_PER_WORD;
12271
12272       insn = emit_insn (gen_rtx_SET
12273                         (stack_pointer_rtx,
12274                          gen_rtx_PLUS (Pmode,
12275                                        crtl->drap_reg,
12276                                        GEN_INT (-param_ptr_offset))));
12277       m->fs.cfa_reg = stack_pointer_rtx;
12278       m->fs.cfa_offset = param_ptr_offset;
12279       m->fs.sp_offset = param_ptr_offset;
12280       m->fs.realigned = false;
12281
12282       add_reg_note (insn, REG_CFA_DEF_CFA,
12283                     gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12284                                   GEN_INT (param_ptr_offset)));
12285       RTX_FRAME_RELATED_P (insn) = 1;
12286
12287       if (!call_used_regs[REGNO (crtl->drap_reg)])
12288         ix86_emit_restore_reg_using_pop (crtl->drap_reg);
12289     }
12290
12291   /* At this point the stack pointer must be valid, and we must have
12292      restored all of the registers.  We may not have deallocated the
12293      entire stack frame.  We've delayed this until now because it may
12294      be possible to merge the local stack deallocation with the
12295      deallocation forced by ix86_static_chain_on_stack.   */
12296   gcc_assert (m->fs.sp_valid);
12297   gcc_assert (!m->fs.fp_valid);
12298   gcc_assert (!m->fs.realigned);
12299   if (m->fs.sp_offset != UNITS_PER_WORD)
12300     {
12301       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12302                                  GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
12303                                  style, true);
12304     }
12305   else
12306     ix86_add_queued_cfa_restore_notes (get_last_insn ());
12307
12308   /* Sibcall epilogues don't want a return instruction.  */
12309   if (style == 0)
12310     {
12311       m->fs = frame_state_save;
12312       return;
12313     }
12314
12315   if (crtl->args.pops_args && crtl->args.size)
12316     {
12317       rtx popc = GEN_INT (crtl->args.pops_args);
12318
12319       /* i386 can only pop 64K bytes.  If asked to pop more, pop return
12320          address, do explicit add, and jump indirectly to the caller.  */
12321
12322       if (crtl->args.pops_args >= 65536)
12323         {
12324           rtx ecx = gen_rtx_REG (SImode, CX_REG);
12325           rtx_insn *insn;
12326
12327           /* There is no "pascal" calling convention in any 64bit ABI.  */
12328           gcc_assert (!TARGET_64BIT);
12329
12330           insn = emit_insn (gen_pop (ecx));
12331           m->fs.cfa_offset -= UNITS_PER_WORD;
12332           m->fs.sp_offset -= UNITS_PER_WORD;
12333
12334           rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
12335           x = gen_rtx_SET (stack_pointer_rtx, x);
12336           add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
12337           add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
12338           RTX_FRAME_RELATED_P (insn) = 1;
12339
12340           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12341                                      popc, -1, true);
12342           emit_jump_insn (gen_simple_return_indirect_internal (ecx));
12343         }
12344       else
12345         emit_jump_insn (gen_simple_return_pop_internal (popc));
12346     }
12347   else
12348     emit_jump_insn (gen_simple_return_internal ());
12349
12350   /* Restore the state back to the state from the prologue,
12351      so that it's correct for the next epilogue.  */
12352   m->fs = frame_state_save;
12353 }
12354
12355 /* Reset from the function's potential modifications.  */
12356
12357 static void
12358 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED, HOST_WIDE_INT)
12359 {
12360   if (pic_offset_table_rtx
12361       && !ix86_use_pseudo_pic_reg ())
12362     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
12363 #if TARGET_MACHO
12364   /* Mach-O doesn't support labels at the end of objects, so if
12365      it looks like we might want one, insert a NOP.  */
12366   {
12367     rtx_insn *insn = get_last_insn ();
12368     rtx_insn *deleted_debug_label = NULL;
12369     while (insn
12370            && NOTE_P (insn)
12371            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
12372       {
12373         /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
12374            notes only, instead set their CODE_LABEL_NUMBER to -1,
12375            otherwise there would be code generation differences
12376            in between -g and -g0.  */
12377         if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
12378           deleted_debug_label = insn;
12379         insn = PREV_INSN (insn);
12380       }
12381     if (insn
12382         && (LABEL_P (insn)
12383             || (NOTE_P (insn)
12384                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
12385       fputs ("\tnop\n", file);
12386     else if (deleted_debug_label)
12387       for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
12388         if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
12389           CODE_LABEL_NUMBER (insn) = -1;
12390   }
12391 #endif
12392
12393 }
12394
12395 /* Return a scratch register to use in the split stack prologue.  The
12396    split stack prologue is used for -fsplit-stack.  It is the first
12397    instructions in the function, even before the regular prologue.
12398    The scratch register can be any caller-saved register which is not
12399    used for parameters or for the static chain.  */
12400
12401 static unsigned int
12402 split_stack_prologue_scratch_regno (void)
12403 {
12404   if (TARGET_64BIT)
12405     return R11_REG;
12406   else
12407     {
12408       bool is_fastcall, is_thiscall;
12409       int regparm;
12410
12411       is_fastcall = (lookup_attribute ("fastcall",
12412                                        TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
12413                      != NULL);
12414       is_thiscall = (lookup_attribute ("thiscall",
12415                                        TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
12416                      != NULL);
12417       regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
12418
12419       if (is_fastcall)
12420         {
12421           if (DECL_STATIC_CHAIN (cfun->decl))
12422             {
12423               sorry ("-fsplit-stack does not support fastcall with "
12424                      "nested function");
12425               return INVALID_REGNUM;
12426             }
12427           return AX_REG;
12428         }
12429       else if (is_thiscall)
12430         {
12431           if (!DECL_STATIC_CHAIN (cfun->decl))
12432             return DX_REG;
12433           return AX_REG;
12434         }
12435       else if (regparm < 3)
12436         {
12437           if (!DECL_STATIC_CHAIN (cfun->decl))
12438             return CX_REG;
12439           else
12440             {
12441               if (regparm >= 2)
12442                 {
12443                   sorry ("-fsplit-stack does not support 2 register "
12444                          "parameters for a nested function");
12445                   return INVALID_REGNUM;
12446                 }
12447               return DX_REG;
12448             }
12449         }
12450       else
12451         {
12452           /* FIXME: We could make this work by pushing a register
12453              around the addition and comparison.  */
12454           sorry ("-fsplit-stack does not support 3 register parameters");
12455           return INVALID_REGNUM;
12456         }
12457     }
12458 }
12459
12460 /* A SYMBOL_REF for the function which allocates new stackspace for
12461    -fsplit-stack.  */
12462
12463 static GTY(()) rtx split_stack_fn;
12464
12465 /* A SYMBOL_REF for the more stack function when using the large
12466    model.  */
12467
12468 static GTY(()) rtx split_stack_fn_large;
12469
12470 /* Handle -fsplit-stack.  These are the first instructions in the
12471    function, even before the regular prologue.  */
12472
12473 void
12474 ix86_expand_split_stack_prologue (void)
12475 {
12476   struct ix86_frame frame;
12477   HOST_WIDE_INT allocate;
12478   unsigned HOST_WIDE_INT args_size;
12479   rtx_code_label *label;
12480   rtx limit, current, jump_insn, allocate_rtx, call_insn, call_fusage;
12481   rtx scratch_reg = NULL_RTX;
12482   rtx_code_label *varargs_label = NULL;
12483   rtx fn;
12484
12485   gcc_assert (flag_split_stack && reload_completed);
12486
12487   ix86_finalize_stack_realign_flags ();
12488   ix86_compute_frame_layout (&frame);
12489   allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
12490
12491   /* This is the label we will branch to if we have enough stack
12492      space.  We expect the basic block reordering pass to reverse this
12493      branch if optimizing, so that we branch in the unlikely case.  */
12494   label = gen_label_rtx ();
12495
12496   /* We need to compare the stack pointer minus the frame size with
12497      the stack boundary in the TCB.  The stack boundary always gives
12498      us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we
12499      can compare directly.  Otherwise we need to do an addition.  */
12500
12501   limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12502                           UNSPEC_STACK_CHECK);
12503   limit = gen_rtx_CONST (Pmode, limit);
12504   limit = gen_rtx_MEM (Pmode, limit);
12505   if (allocate < SPLIT_STACK_AVAILABLE)
12506     current = stack_pointer_rtx;
12507   else
12508     {
12509       unsigned int scratch_regno;
12510       rtx offset;
12511
12512       /* We need a scratch register to hold the stack pointer minus
12513          the required frame size.  Since this is the very start of the
12514          function, the scratch register can be any caller-saved
12515          register which is not used for parameters.  */
12516       offset = GEN_INT (- allocate);
12517       scratch_regno = split_stack_prologue_scratch_regno ();
12518       if (scratch_regno == INVALID_REGNUM)
12519         return;
12520       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
12521       if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode))
12522         {
12523           /* We don't use ix86_gen_add3 in this case because it will
12524              want to split to lea, but when not optimizing the insn
12525              will not be split after this point.  */
12526           emit_insn (gen_rtx_SET (scratch_reg,
12527                                   gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12528                                                 offset)));
12529         }
12530       else
12531         {
12532           emit_move_insn (scratch_reg, offset);
12533           emit_insn (ix86_gen_add3 (scratch_reg, scratch_reg,
12534                                     stack_pointer_rtx));
12535         }
12536       current = scratch_reg;
12537     }
12538
12539   ix86_expand_branch (GEU, current, limit, label);
12540   jump_insn = get_last_insn ();
12541   JUMP_LABEL (jump_insn) = label;
12542
12543   /* Mark the jump as very likely to be taken.  */
12544   add_int_reg_note (jump_insn, REG_BR_PROB,
12545                     REG_BR_PROB_BASE - REG_BR_PROB_BASE / 100);
12546
12547   if (split_stack_fn == NULL_RTX)
12548     {
12549       split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack");
12550       SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL;
12551     }
12552   fn = split_stack_fn;
12553
12554   /* Get more stack space.  We pass in the desired stack space and the
12555      size of the arguments to copy to the new stack.  In 32-bit mode
12556      we push the parameters; __morestack will return on a new stack
12557      anyhow.  In 64-bit mode we pass the parameters in r10 and
12558      r11.  */
12559   allocate_rtx = GEN_INT (allocate);
12560   args_size = crtl->args.size >= 0 ? crtl->args.size : 0;
12561   call_fusage = NULL_RTX;
12562   if (TARGET_64BIT)
12563     {
12564       rtx reg10, reg11;
12565
12566       reg10 = gen_rtx_REG (Pmode, R10_REG);
12567       reg11 = gen_rtx_REG (Pmode, R11_REG);
12568
12569       /* If this function uses a static chain, it will be in %r10.
12570          Preserve it across the call to __morestack.  */
12571       if (DECL_STATIC_CHAIN (cfun->decl))
12572         {
12573           rtx rax;
12574
12575           rax = gen_rtx_REG (word_mode, AX_REG);
12576           emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG));
12577           use_reg (&call_fusage, rax);
12578         }
12579
12580       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
12581           && !TARGET_PECOFF)
12582         {
12583           HOST_WIDE_INT argval;
12584
12585           gcc_assert (Pmode == DImode);
12586           /* When using the large model we need to load the address
12587              into a register, and we've run out of registers.  So we
12588              switch to a different calling convention, and we call a
12589              different function: __morestack_large.  We pass the
12590              argument size in the upper 32 bits of r10 and pass the
12591              frame size in the lower 32 bits.  */
12592           gcc_assert ((allocate & (HOST_WIDE_INT) 0xffffffff) == allocate);
12593           gcc_assert ((args_size & 0xffffffff) == args_size);
12594
12595           if (split_stack_fn_large == NULL_RTX)
12596             {
12597               split_stack_fn_large =
12598                 gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model");
12599               SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL;
12600             }
12601           if (ix86_cmodel == CM_LARGE_PIC)
12602             {
12603               rtx_code_label *label;
12604               rtx x;
12605
12606               label = gen_label_rtx ();
12607               emit_label (label);
12608               LABEL_PRESERVE_P (label) = 1;
12609               emit_insn (gen_set_rip_rex64 (reg10, label));
12610               emit_insn (gen_set_got_offset_rex64 (reg11, label));
12611               emit_insn (ix86_gen_add3 (reg10, reg10, reg11));
12612               x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn_large),
12613                                   UNSPEC_GOT);
12614               x = gen_rtx_CONST (Pmode, x);
12615               emit_move_insn (reg11, x);
12616               x = gen_rtx_PLUS (Pmode, reg10, reg11);
12617               x = gen_const_mem (Pmode, x);
12618               emit_move_insn (reg11, x);
12619             }
12620           else
12621             emit_move_insn (reg11, split_stack_fn_large);
12622
12623           fn = reg11;
12624
12625           argval = ((args_size << 16) << 16) + allocate;
12626           emit_move_insn (reg10, GEN_INT (argval));
12627         }
12628       else
12629         {
12630           emit_move_insn (reg10, allocate_rtx);
12631           emit_move_insn (reg11, GEN_INT (args_size));
12632           use_reg (&call_fusage, reg11);
12633         }
12634
12635       use_reg (&call_fusage, reg10);
12636     }
12637   else
12638     {
12639       emit_insn (gen_push (GEN_INT (args_size)));
12640       emit_insn (gen_push (allocate_rtx));
12641     }
12642   call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn),
12643                                 GEN_INT (UNITS_PER_WORD), constm1_rtx,
12644                                 NULL_RTX, false);
12645   add_function_usage_to (call_insn, call_fusage);
12646
12647   /* In order to make call/return prediction work right, we now need
12648      to execute a return instruction.  See
12649      libgcc/config/i386/morestack.S for the details on how this works.
12650
12651      For flow purposes gcc must not see this as a return
12652      instruction--we need control flow to continue at the subsequent
12653      label.  Therefore, we use an unspec.  */
12654   gcc_assert (crtl->args.pops_args < 65536);
12655   emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args)));
12656
12657   /* If we are in 64-bit mode and this function uses a static chain,
12658      we saved %r10 in %rax before calling _morestack.  */
12659   if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl))
12660     emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
12661                     gen_rtx_REG (word_mode, AX_REG));
12662
12663   /* If this function calls va_start, we need to store a pointer to
12664      the arguments on the old stack, because they may not have been
12665      all copied to the new stack.  At this point the old stack can be
12666      found at the frame pointer value used by __morestack, because
12667      __morestack has set that up before calling back to us.  Here we
12668      store that pointer in a scratch register, and in
12669      ix86_expand_prologue we store the scratch register in a stack
12670      slot.  */
12671   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12672     {
12673       unsigned int scratch_regno;
12674       rtx frame_reg;
12675       int words;
12676
12677       scratch_regno = split_stack_prologue_scratch_regno ();
12678       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
12679       frame_reg = gen_rtx_REG (Pmode, BP_REG);
12680
12681       /* 64-bit:
12682          fp -> old fp value
12683                return address within this function
12684                return address of caller of this function
12685                stack arguments
12686          So we add three words to get to the stack arguments.
12687
12688          32-bit:
12689          fp -> old fp value
12690                return address within this function
12691                first argument to __morestack
12692                second argument to __morestack
12693                return address of caller of this function
12694                stack arguments
12695          So we add five words to get to the stack arguments.
12696       */
12697       words = TARGET_64BIT ? 3 : 5;
12698       emit_insn (gen_rtx_SET (scratch_reg,
12699                               gen_rtx_PLUS (Pmode, frame_reg,
12700                                             GEN_INT (words * UNITS_PER_WORD))));
12701
12702       varargs_label = gen_label_rtx ();
12703       emit_jump_insn (gen_jump (varargs_label));
12704       JUMP_LABEL (get_last_insn ()) = varargs_label;
12705
12706       emit_barrier ();
12707     }
12708
12709   emit_label (label);
12710   LABEL_NUSES (label) = 1;
12711
12712   /* If this function calls va_start, we now have to set the scratch
12713      register for the case where we do not call __morestack.  In this
12714      case we need to set it based on the stack pointer.  */
12715   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12716     {
12717       emit_insn (gen_rtx_SET (scratch_reg,
12718                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12719                                             GEN_INT (UNITS_PER_WORD))));
12720
12721       emit_label (varargs_label);
12722       LABEL_NUSES (varargs_label) = 1;
12723     }
12724 }
12725
12726 /* We may have to tell the dataflow pass that the split stack prologue
12727    is initializing a scratch register.  */
12728
12729 static void
12730 ix86_live_on_entry (bitmap regs)
12731 {
12732   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12733     {
12734       gcc_assert (flag_split_stack);
12735       bitmap_set_bit (regs, split_stack_prologue_scratch_regno ());
12736     }
12737 }
12738 \f
12739 /* Extract the parts of an RTL expression that is a valid memory address
12740    for an instruction.  Return 0 if the structure of the address is
12741    grossly off.  Return -1 if the address contains ASHIFT, so it is not
12742    strictly valid, but still used for computing length of lea instruction.  */
12743
12744 int
12745 ix86_decompose_address (rtx addr, struct ix86_address *out)
12746 {
12747   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
12748   rtx base_reg, index_reg;
12749   HOST_WIDE_INT scale = 1;
12750   rtx scale_rtx = NULL_RTX;
12751   rtx tmp;
12752   int retval = 1;
12753   enum ix86_address_seg seg = SEG_DEFAULT;
12754
12755   /* Allow zero-extended SImode addresses,
12756      they will be emitted with addr32 prefix.  */
12757   if (TARGET_64BIT && GET_MODE (addr) == DImode)
12758     {
12759       if (GET_CODE (addr) == ZERO_EXTEND
12760           && GET_MODE (XEXP (addr, 0)) == SImode)
12761         {
12762           addr = XEXP (addr, 0);
12763           if (CONST_INT_P (addr))
12764             return 0;
12765         }             
12766       else if (GET_CODE (addr) == AND
12767                && const_32bit_mask (XEXP (addr, 1), DImode))
12768         {
12769           addr = simplify_gen_subreg (SImode, XEXP (addr, 0), DImode, 0);
12770           if (addr == NULL_RTX)
12771             return 0;
12772
12773           if (CONST_INT_P (addr))
12774             return 0;
12775         }
12776     }
12777
12778   /* Allow SImode subregs of DImode addresses,
12779      they will be emitted with addr32 prefix.  */
12780   if (TARGET_64BIT && GET_MODE (addr) == SImode)
12781     {
12782       if (GET_CODE (addr) == SUBREG
12783           && GET_MODE (SUBREG_REG (addr)) == DImode)
12784         {
12785           addr = SUBREG_REG (addr);
12786           if (CONST_INT_P (addr))
12787             return 0;
12788         }
12789     }
12790
12791   if (REG_P (addr))
12792     base = addr;
12793   else if (GET_CODE (addr) == SUBREG)
12794     {
12795       if (REG_P (SUBREG_REG (addr)))
12796         base = addr;
12797       else
12798         return 0;
12799     }
12800   else if (GET_CODE (addr) == PLUS)
12801     {
12802       rtx addends[4], op;
12803       int n = 0, i;
12804
12805       op = addr;
12806       do
12807         {
12808           if (n >= 4)
12809             return 0;
12810           addends[n++] = XEXP (op, 1);
12811           op = XEXP (op, 0);
12812         }
12813       while (GET_CODE (op) == PLUS);
12814       if (n >= 4)
12815         return 0;
12816       addends[n] = op;
12817
12818       for (i = n; i >= 0; --i)
12819         {
12820           op = addends[i];
12821           switch (GET_CODE (op))
12822             {
12823             case MULT:
12824               if (index)
12825                 return 0;
12826               index = XEXP (op, 0);
12827               scale_rtx = XEXP (op, 1);
12828               break;
12829
12830             case ASHIFT:
12831               if (index)
12832                 return 0;
12833               index = XEXP (op, 0);
12834               tmp = XEXP (op, 1);
12835               if (!CONST_INT_P (tmp))
12836                 return 0;
12837               scale = INTVAL (tmp);
12838               if ((unsigned HOST_WIDE_INT) scale > 3)
12839                 return 0;
12840               scale = 1 << scale;
12841               break;
12842
12843             case ZERO_EXTEND:
12844               op = XEXP (op, 0);
12845               if (GET_CODE (op) != UNSPEC)
12846                 return 0;
12847               /* FALLTHRU */
12848
12849             case UNSPEC:
12850               if (XINT (op, 1) == UNSPEC_TP
12851                   && TARGET_TLS_DIRECT_SEG_REFS
12852                   && seg == SEG_DEFAULT)
12853                 seg = DEFAULT_TLS_SEG_REG;
12854               else
12855                 return 0;
12856               break;
12857
12858             case SUBREG:
12859               if (!REG_P (SUBREG_REG (op)))
12860                 return 0;
12861               /* FALLTHRU */
12862
12863             case REG:
12864               if (!base)
12865                 base = op;
12866               else if (!index)
12867                 index = op;
12868               else
12869                 return 0;
12870               break;
12871
12872             case CONST:
12873             case CONST_INT:
12874             case SYMBOL_REF:
12875             case LABEL_REF:
12876               if (disp)
12877                 return 0;
12878               disp = op;
12879               break;
12880
12881             default:
12882               return 0;
12883             }
12884         }
12885     }
12886   else if (GET_CODE (addr) == MULT)
12887     {
12888       index = XEXP (addr, 0);           /* index*scale */
12889       scale_rtx = XEXP (addr, 1);
12890     }
12891   else if (GET_CODE (addr) == ASHIFT)
12892     {
12893       /* We're called for lea too, which implements ashift on occasion.  */
12894       index = XEXP (addr, 0);
12895       tmp = XEXP (addr, 1);
12896       if (!CONST_INT_P (tmp))
12897         return 0;
12898       scale = INTVAL (tmp);
12899       if ((unsigned HOST_WIDE_INT) scale > 3)
12900         return 0;
12901       scale = 1 << scale;
12902       retval = -1;
12903     }
12904   else
12905     disp = addr;                        /* displacement */
12906
12907   if (index)
12908     {
12909       if (REG_P (index))
12910         ;
12911       else if (GET_CODE (index) == SUBREG
12912                && REG_P (SUBREG_REG (index)))
12913         ;
12914       else
12915         return 0;
12916     }
12917
12918   /* Extract the integral value of scale.  */
12919   if (scale_rtx)
12920     {
12921       if (!CONST_INT_P (scale_rtx))
12922         return 0;
12923       scale = INTVAL (scale_rtx);
12924     }
12925
12926   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
12927   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
12928
12929   /* Avoid useless 0 displacement.  */
12930   if (disp == const0_rtx && (base || index))
12931     disp = NULL_RTX;
12932
12933   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
12934   if (base_reg && index_reg && scale == 1
12935       && (index_reg == arg_pointer_rtx
12936           || index_reg == frame_pointer_rtx
12937           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
12938     {
12939       std::swap (base, index);
12940       std::swap (base_reg, index_reg);
12941     }
12942
12943   /* Special case: %ebp cannot be encoded as a base without a displacement.
12944      Similarly %r13.  */
12945   if (!disp
12946       && base_reg
12947       && (base_reg == hard_frame_pointer_rtx
12948           || base_reg == frame_pointer_rtx
12949           || base_reg == arg_pointer_rtx
12950           || (REG_P (base_reg)
12951               && (REGNO (base_reg) == HARD_FRAME_POINTER_REGNUM
12952                   || REGNO (base_reg) == R13_REG))))
12953     disp = const0_rtx;
12954
12955   /* Special case: on K6, [%esi] makes the instruction vector decoded.
12956      Avoid this by transforming to [%esi+0].
12957      Reload calls address legitimization without cfun defined, so we need
12958      to test cfun for being non-NULL. */
12959   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
12960       && base_reg && !index_reg && !disp
12961       && REG_P (base_reg) && REGNO (base_reg) == SI_REG)
12962     disp = const0_rtx;
12963
12964   /* Special case: encode reg+reg instead of reg*2.  */
12965   if (!base && index && scale == 2)
12966     base = index, base_reg = index_reg, scale = 1;
12967
12968   /* Special case: scaling cannot be encoded without base or displacement.  */
12969   if (!base && !disp && index && scale != 1)
12970     disp = const0_rtx;
12971
12972   out->base = base;
12973   out->index = index;
12974   out->disp = disp;
12975   out->scale = scale;
12976   out->seg = seg;
12977
12978   return retval;
12979 }
12980 \f
12981 /* Return cost of the memory address x.
12982    For i386, it is better to use a complex address than let gcc copy
12983    the address into a reg and make a new pseudo.  But not if the address
12984    requires to two regs - that would mean more pseudos with longer
12985    lifetimes.  */
12986 static int
12987 ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
12988 {
12989   struct ix86_address parts;
12990   int cost = 1;
12991   int ok = ix86_decompose_address (x, &parts);
12992
12993   gcc_assert (ok);
12994
12995   if (parts.base && GET_CODE (parts.base) == SUBREG)
12996     parts.base = SUBREG_REG (parts.base);
12997   if (parts.index && GET_CODE (parts.index) == SUBREG)
12998     parts.index = SUBREG_REG (parts.index);
12999
13000   /* Attempt to minimize number of registers in the address by increasing
13001      address cost for each used register.  We don't increase address cost
13002      for "pic_offset_table_rtx".  When a memopt with "pic_offset_table_rtx"
13003      is not invariant itself it most likely means that base or index is not
13004      invariant.  Therefore only "pic_offset_table_rtx" could be hoisted out,
13005      which is not profitable for x86.  */
13006   if (parts.base
13007       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
13008       && (current_pass->type == GIMPLE_PASS
13009           || !pic_offset_table_rtx
13010           || !REG_P (parts.base)
13011           || REGNO (pic_offset_table_rtx) != REGNO (parts.base)))
13012     cost++;
13013
13014   if (parts.index
13015       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
13016       && (current_pass->type == GIMPLE_PASS
13017           || !pic_offset_table_rtx
13018           || !REG_P (parts.index)
13019           || REGNO (pic_offset_table_rtx) != REGNO (parts.index)))
13020     cost++;
13021
13022   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
13023      since it's predecode logic can't detect the length of instructions
13024      and it degenerates to vector decoded.  Increase cost of such
13025      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
13026      to split such addresses or even refuse such addresses at all.
13027
13028      Following addressing modes are affected:
13029       [base+scale*index]
13030       [scale*index+disp]
13031       [base+index]
13032
13033      The first and last case  may be avoidable by explicitly coding the zero in
13034      memory address, but I don't have AMD-K6 machine handy to check this
13035      theory.  */
13036
13037   if (TARGET_K6
13038       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
13039           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
13040           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
13041     cost += 10;
13042
13043   return cost;
13044 }
13045 \f
13046 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
13047    this is used for to form addresses to local data when -fPIC is in
13048    use.  */
13049
13050 static bool
13051 darwin_local_data_pic (rtx disp)
13052 {
13053   return (GET_CODE (disp) == UNSPEC
13054           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
13055 }
13056
13057 /* Determine if a given RTX is a valid constant.  We already know this
13058    satisfies CONSTANT_P.  */
13059
13060 static bool
13061 ix86_legitimate_constant_p (machine_mode, rtx x)
13062 {
13063   /* Pointer bounds constants are not valid.  */
13064   if (POINTER_BOUNDS_MODE_P (GET_MODE (x)))
13065     return false;
13066
13067   switch (GET_CODE (x))
13068     {
13069     case CONST:
13070       x = XEXP (x, 0);
13071
13072       if (GET_CODE (x) == PLUS)
13073         {
13074           if (!CONST_INT_P (XEXP (x, 1)))
13075             return false;
13076           x = XEXP (x, 0);
13077         }
13078
13079       if (TARGET_MACHO && darwin_local_data_pic (x))
13080         return true;
13081
13082       /* Only some unspecs are valid as "constants".  */
13083       if (GET_CODE (x) == UNSPEC)
13084         switch (XINT (x, 1))
13085           {
13086           case UNSPEC_GOT:
13087           case UNSPEC_GOTOFF:
13088           case UNSPEC_PLTOFF:
13089             return TARGET_64BIT;
13090           case UNSPEC_TPOFF:
13091           case UNSPEC_NTPOFF:
13092             x = XVECEXP (x, 0, 0);
13093             return (GET_CODE (x) == SYMBOL_REF
13094                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
13095           case UNSPEC_DTPOFF:
13096             x = XVECEXP (x, 0, 0);
13097             return (GET_CODE (x) == SYMBOL_REF
13098                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
13099           default:
13100             return false;
13101           }
13102
13103       /* We must have drilled down to a symbol.  */
13104       if (GET_CODE (x) == LABEL_REF)
13105         return true;
13106       if (GET_CODE (x) != SYMBOL_REF)
13107         return false;
13108       /* FALLTHRU */
13109
13110     case SYMBOL_REF:
13111       /* TLS symbols are never valid.  */
13112       if (SYMBOL_REF_TLS_MODEL (x))
13113         return false;
13114
13115       /* DLLIMPORT symbols are never valid.  */
13116       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
13117           && SYMBOL_REF_DLLIMPORT_P (x))
13118         return false;
13119
13120 #if TARGET_MACHO
13121       /* mdynamic-no-pic */
13122       if (MACHO_DYNAMIC_NO_PIC_P)
13123         return machopic_symbol_defined_p (x);
13124 #endif
13125       break;
13126
13127     case CONST_WIDE_INT:
13128       if (!TARGET_64BIT && !standard_sse_constant_p (x))
13129         return false;
13130       break;
13131
13132     case CONST_VECTOR:
13133       if (!standard_sse_constant_p (x))
13134         return false;
13135
13136     default:
13137       break;
13138     }
13139
13140   /* Otherwise we handle everything else in the move patterns.  */
13141   return true;
13142 }
13143
13144 /* Determine if it's legal to put X into the constant pool.  This
13145    is not possible for the address of thread-local symbols, which
13146    is checked above.  */
13147
13148 static bool
13149 ix86_cannot_force_const_mem (machine_mode mode, rtx x)
13150 {
13151   /* We can always put integral constants and vectors in memory.  */
13152   switch (GET_CODE (x))
13153     {
13154     case CONST_INT:
13155     case CONST_WIDE_INT:
13156     case CONST_DOUBLE:
13157     case CONST_VECTOR:
13158       return false;
13159
13160     default:
13161       break;
13162     }
13163   return !ix86_legitimate_constant_p (mode, x);
13164 }
13165
13166 /*  Nonzero if the symbol is marked as dllimport, or as stub-variable,
13167     otherwise zero.  */
13168
13169 static bool
13170 is_imported_p (rtx x)
13171 {
13172   if (!TARGET_DLLIMPORT_DECL_ATTRIBUTES
13173       || GET_CODE (x) != SYMBOL_REF)
13174     return false;
13175
13176   return SYMBOL_REF_DLLIMPORT_P (x) || SYMBOL_REF_STUBVAR_P (x);
13177 }
13178
13179
13180 /* Nonzero if the constant value X is a legitimate general operand
13181    when generating PIC code.  It is given that flag_pic is on and
13182    that X satisfies CONSTANT_P.  */
13183
13184 bool
13185 legitimate_pic_operand_p (rtx x)
13186 {
13187   rtx inner;
13188
13189   switch (GET_CODE (x))
13190     {
13191     case CONST:
13192       inner = XEXP (x, 0);
13193       if (GET_CODE (inner) == PLUS
13194           && CONST_INT_P (XEXP (inner, 1)))
13195         inner = XEXP (inner, 0);
13196
13197       /* Only some unspecs are valid as "constants".  */
13198       if (GET_CODE (inner) == UNSPEC)
13199         switch (XINT (inner, 1))
13200           {
13201           case UNSPEC_GOT:
13202           case UNSPEC_GOTOFF:
13203           case UNSPEC_PLTOFF:
13204             return TARGET_64BIT;
13205           case UNSPEC_TPOFF:
13206             x = XVECEXP (inner, 0, 0);
13207             return (GET_CODE (x) == SYMBOL_REF
13208                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
13209           case UNSPEC_MACHOPIC_OFFSET:
13210             return legitimate_pic_address_disp_p (x);
13211           default:
13212             return false;
13213           }
13214       /* FALLTHRU */
13215
13216     case SYMBOL_REF:
13217     case LABEL_REF:
13218       return legitimate_pic_address_disp_p (x);
13219
13220     default:
13221       return true;
13222     }
13223 }
13224
13225 /* Determine if a given CONST RTX is a valid memory displacement
13226    in PIC mode.  */
13227
13228 bool
13229 legitimate_pic_address_disp_p (rtx disp)
13230 {
13231   bool saw_plus;
13232
13233   /* In 64bit mode we can allow direct addresses of symbols and labels
13234      when they are not dynamic symbols.  */
13235   if (TARGET_64BIT)
13236     {
13237       rtx op0 = disp, op1;
13238
13239       switch (GET_CODE (disp))
13240         {
13241         case LABEL_REF:
13242           return true;
13243
13244         case CONST:
13245           if (GET_CODE (XEXP (disp, 0)) != PLUS)
13246             break;
13247           op0 = XEXP (XEXP (disp, 0), 0);
13248           op1 = XEXP (XEXP (disp, 0), 1);
13249           if (!CONST_INT_P (op1)
13250               || INTVAL (op1) >= 16*1024*1024
13251               || INTVAL (op1) < -16*1024*1024)
13252             break;
13253           if (GET_CODE (op0) == LABEL_REF)
13254             return true;
13255           if (GET_CODE (op0) == CONST
13256               && GET_CODE (XEXP (op0, 0)) == UNSPEC
13257               && XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL)
13258             return true;
13259           if (GET_CODE (op0) == UNSPEC
13260               && XINT (op0, 1) == UNSPEC_PCREL)
13261             return true;
13262           if (GET_CODE (op0) != SYMBOL_REF)
13263             break;
13264           /* FALLTHRU */
13265
13266         case SYMBOL_REF:
13267           /* TLS references should always be enclosed in UNSPEC.
13268              The dllimported symbol needs always to be resolved.  */
13269           if (SYMBOL_REF_TLS_MODEL (op0)
13270               || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0)))
13271             return false;
13272
13273           if (TARGET_PECOFF)
13274             {
13275               if (is_imported_p (op0))
13276                 return true;
13277
13278               if (SYMBOL_REF_FAR_ADDR_P (op0)
13279                   || !SYMBOL_REF_LOCAL_P (op0))
13280                 break;
13281
13282               /* Function-symbols need to be resolved only for
13283                  large-model.
13284                  For the small-model we don't need to resolve anything
13285                  here.  */
13286               if ((ix86_cmodel != CM_LARGE_PIC
13287                    && SYMBOL_REF_FUNCTION_P (op0))
13288                   || ix86_cmodel == CM_SMALL_PIC)
13289                 return true;
13290               /* Non-external symbols don't need to be resolved for
13291                  large, and medium-model.  */
13292               if ((ix86_cmodel == CM_LARGE_PIC
13293                    || ix86_cmodel == CM_MEDIUM_PIC)
13294                   && !SYMBOL_REF_EXTERNAL_P (op0))
13295                 return true;
13296             }
13297           else if (!SYMBOL_REF_FAR_ADDR_P (op0)
13298                    && (SYMBOL_REF_LOCAL_P (op0)
13299                        || (HAVE_LD_PIE_COPYRELOC
13300                            && flag_pie
13301                            && !SYMBOL_REF_WEAK (op0)
13302                            && !SYMBOL_REF_FUNCTION_P (op0)))
13303                    && ix86_cmodel != CM_LARGE_PIC)
13304             return true;
13305           break;
13306
13307         default:
13308           break;
13309         }
13310     }
13311   if (GET_CODE (disp) != CONST)
13312     return false;
13313   disp = XEXP (disp, 0);
13314
13315   if (TARGET_64BIT)
13316     {
13317       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
13318          of GOT tables.  We should not need these anyway.  */
13319       if (GET_CODE (disp) != UNSPEC
13320           || (XINT (disp, 1) != UNSPEC_GOTPCREL
13321               && XINT (disp, 1) != UNSPEC_GOTOFF
13322               && XINT (disp, 1) != UNSPEC_PCREL
13323               && XINT (disp, 1) != UNSPEC_PLTOFF))
13324         return false;
13325
13326       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
13327           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
13328         return false;
13329       return true;
13330     }
13331
13332   saw_plus = false;
13333   if (GET_CODE (disp) == PLUS)
13334     {
13335       if (!CONST_INT_P (XEXP (disp, 1)))
13336         return false;
13337       disp = XEXP (disp, 0);
13338       saw_plus = true;
13339     }
13340
13341   if (TARGET_MACHO && darwin_local_data_pic (disp))
13342     return true;
13343
13344   if (GET_CODE (disp) != UNSPEC)
13345     return false;
13346
13347   switch (XINT (disp, 1))
13348     {
13349     case UNSPEC_GOT:
13350       if (saw_plus)
13351         return false;
13352       /* We need to check for both symbols and labels because VxWorks loads
13353          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
13354          details.  */
13355       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
13356               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
13357     case UNSPEC_GOTOFF:
13358       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
13359          While ABI specify also 32bit relocation but we don't produce it in
13360          small PIC model at all.  */
13361       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
13362            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
13363           && !TARGET_64BIT)
13364         return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
13365       return false;
13366     case UNSPEC_GOTTPOFF:
13367     case UNSPEC_GOTNTPOFF:
13368     case UNSPEC_INDNTPOFF:
13369       if (saw_plus)
13370         return false;
13371       disp = XVECEXP (disp, 0, 0);
13372       return (GET_CODE (disp) == SYMBOL_REF
13373               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
13374     case UNSPEC_NTPOFF:
13375       disp = XVECEXP (disp, 0, 0);
13376       return (GET_CODE (disp) == SYMBOL_REF
13377               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
13378     case UNSPEC_DTPOFF:
13379       disp = XVECEXP (disp, 0, 0);
13380       return (GET_CODE (disp) == SYMBOL_REF
13381               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
13382     }
13383
13384   return false;
13385 }
13386
13387 /* Determine if op is suitable RTX for an address register.
13388    Return naked register if a register or a register subreg is
13389    found, otherwise return NULL_RTX.  */
13390
13391 static rtx
13392 ix86_validate_address_register (rtx op)
13393 {
13394   machine_mode mode = GET_MODE (op);
13395
13396   /* Only SImode or DImode registers can form the address.  */
13397   if (mode != SImode && mode != DImode)
13398     return NULL_RTX;
13399
13400   if (REG_P (op))
13401     return op;
13402   else if (GET_CODE (op) == SUBREG)
13403     {
13404       rtx reg = SUBREG_REG (op);
13405
13406       if (!REG_P (reg))
13407         return NULL_RTX;
13408
13409       mode = GET_MODE (reg);
13410
13411       /* Don't allow SUBREGs that span more than a word.  It can
13412          lead to spill failures when the register is one word out
13413          of a two word structure.  */
13414       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
13415         return NULL_RTX;
13416
13417       /* Allow only SUBREGs of non-eliminable hard registers.  */
13418       if (register_no_elim_operand (reg, mode))
13419         return reg;
13420     }
13421
13422   /* Op is not a register.  */
13423   return NULL_RTX;
13424 }
13425
13426 /* Recognizes RTL expressions that are valid memory addresses for an
13427    instruction.  The MODE argument is the machine mode for the MEM
13428    expression that wants to use this address.
13429
13430    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
13431    convert common non-canonical forms to canonical form so that they will
13432    be recognized.  */
13433
13434 static bool
13435 ix86_legitimate_address_p (machine_mode, rtx addr, bool strict)
13436 {
13437   struct ix86_address parts;
13438   rtx base, index, disp;
13439   HOST_WIDE_INT scale;
13440   enum ix86_address_seg seg;
13441
13442   if (ix86_decompose_address (addr, &parts) <= 0)
13443     /* Decomposition failed.  */
13444     return false;
13445
13446   base = parts.base;
13447   index = parts.index;
13448   disp = parts.disp;
13449   scale = parts.scale;
13450   seg = parts.seg;
13451
13452   /* Validate base register.  */
13453   if (base)
13454     {
13455       rtx reg = ix86_validate_address_register (base);
13456
13457       if (reg == NULL_RTX)
13458         return false;
13459
13460       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
13461           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
13462         /* Base is not valid.  */
13463         return false;
13464     }
13465
13466   /* Validate index register.  */
13467   if (index)
13468     {
13469       rtx reg = ix86_validate_address_register (index);
13470
13471       if (reg == NULL_RTX)
13472         return false;
13473
13474       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
13475           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
13476         /* Index is not valid.  */
13477         return false;
13478     }
13479
13480   /* Index and base should have the same mode.  */
13481   if (base && index
13482       && GET_MODE (base) != GET_MODE (index))
13483     return false;
13484
13485   /* Address override works only on the (%reg) part of %fs:(%reg).  */
13486   if (seg != SEG_DEFAULT
13487       && ((base && GET_MODE (base) != word_mode)
13488           || (index && GET_MODE (index) != word_mode)))
13489     return false;
13490
13491   /* Validate scale factor.  */
13492   if (scale != 1)
13493     {
13494       if (!index)
13495         /* Scale without index.  */
13496         return false;
13497
13498       if (scale != 2 && scale != 4 && scale != 8)
13499         /* Scale is not a valid multiplier.  */
13500         return false;
13501     }
13502
13503   /* Validate displacement.  */
13504   if (disp)
13505     {
13506       if (GET_CODE (disp) == CONST
13507           && GET_CODE (XEXP (disp, 0)) == UNSPEC
13508           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
13509         switch (XINT (XEXP (disp, 0), 1))
13510           {
13511           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
13512              used.  While ABI specify also 32bit relocations, we don't produce
13513              them at all and use IP relative instead.  */
13514           case UNSPEC_GOT:
13515           case UNSPEC_GOTOFF:
13516             gcc_assert (flag_pic);
13517             if (!TARGET_64BIT)
13518               goto is_legitimate_pic;
13519
13520             /* 64bit address unspec.  */
13521             return false;
13522
13523           case UNSPEC_GOTPCREL:
13524           case UNSPEC_PCREL:
13525             gcc_assert (flag_pic);
13526             goto is_legitimate_pic;
13527
13528           case UNSPEC_GOTTPOFF:
13529           case UNSPEC_GOTNTPOFF:
13530           case UNSPEC_INDNTPOFF:
13531           case UNSPEC_NTPOFF:
13532           case UNSPEC_DTPOFF:
13533             break;
13534
13535           case UNSPEC_STACK_CHECK:
13536             gcc_assert (flag_split_stack);
13537             break;
13538
13539           default:
13540             /* Invalid address unspec.  */
13541             return false;
13542           }
13543
13544       else if (SYMBOLIC_CONST (disp)
13545                && (flag_pic
13546                    || (TARGET_MACHO
13547 #if TARGET_MACHO
13548                        && MACHOPIC_INDIRECT
13549                        && !machopic_operand_p (disp)
13550 #endif
13551                )))
13552         {
13553
13554         is_legitimate_pic:
13555           if (TARGET_64BIT && (index || base))
13556             {
13557               /* foo@dtpoff(%rX) is ok.  */
13558               if (GET_CODE (disp) != CONST
13559                   || GET_CODE (XEXP (disp, 0)) != PLUS
13560                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
13561                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
13562                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
13563                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
13564                 /* Non-constant pic memory reference.  */
13565                 return false;
13566             }
13567           else if ((!TARGET_MACHO || flag_pic)
13568                     && ! legitimate_pic_address_disp_p (disp))
13569             /* Displacement is an invalid pic construct.  */
13570             return false;
13571 #if TARGET_MACHO
13572           else if (MACHO_DYNAMIC_NO_PIC_P
13573                    && !ix86_legitimate_constant_p (Pmode, disp))
13574             /* displacment must be referenced via non_lazy_pointer */
13575             return false;
13576 #endif
13577
13578           /* This code used to verify that a symbolic pic displacement
13579              includes the pic_offset_table_rtx register.
13580
13581              While this is good idea, unfortunately these constructs may
13582              be created by "adds using lea" optimization for incorrect
13583              code like:
13584
13585              int a;
13586              int foo(int i)
13587                {
13588                  return *(&a+i);
13589                }
13590
13591              This code is nonsensical, but results in addressing
13592              GOT table with pic_offset_table_rtx base.  We can't
13593              just refuse it easily, since it gets matched by
13594              "addsi3" pattern, that later gets split to lea in the
13595              case output register differs from input.  While this
13596              can be handled by separate addsi pattern for this case
13597              that never results in lea, this seems to be easier and
13598              correct fix for crash to disable this test.  */
13599         }
13600       else if (GET_CODE (disp) != LABEL_REF
13601                && !CONST_INT_P (disp)
13602                && (GET_CODE (disp) != CONST
13603                    || !ix86_legitimate_constant_p (Pmode, disp))
13604                && (GET_CODE (disp) != SYMBOL_REF
13605                    || !ix86_legitimate_constant_p (Pmode, disp)))
13606         /* Displacement is not constant.  */
13607         return false;
13608       else if (TARGET_64BIT
13609                && !x86_64_immediate_operand (disp, VOIDmode))
13610         /* Displacement is out of range.  */
13611         return false;
13612       /* In x32 mode, constant addresses are sign extended to 64bit, so
13613          we have to prevent addresses from 0x80000000 to 0xffffffff.  */
13614       else if (TARGET_X32 && !(index || base)
13615                && CONST_INT_P (disp)
13616                && val_signbit_known_set_p (SImode, INTVAL (disp)))
13617         return false;
13618     }
13619
13620   /* Everything looks valid.  */
13621   return true;
13622 }
13623
13624 /* Determine if a given RTX is a valid constant address.  */
13625
13626 bool
13627 constant_address_p (rtx x)
13628 {
13629   return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
13630 }
13631 \f
13632 /* Return a unique alias set for the GOT.  */
13633
13634 static alias_set_type
13635 ix86_GOT_alias_set (void)
13636 {
13637   static alias_set_type set = -1;
13638   if (set == -1)
13639     set = new_alias_set ();
13640   return set;
13641 }
13642
13643 /* Return a legitimate reference for ORIG (an address) using the
13644    register REG.  If REG is 0, a new pseudo is generated.
13645
13646    There are two types of references that must be handled:
13647
13648    1. Global data references must load the address from the GOT, via
13649       the PIC reg.  An insn is emitted to do this load, and the reg is
13650       returned.
13651
13652    2. Static data references, constant pool addresses, and code labels
13653       compute the address as an offset from the GOT, whose base is in
13654       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
13655       differentiate them from global data objects.  The returned
13656       address is the PIC reg + an unspec constant.
13657
13658    TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
13659    reg also appears in the address.  */
13660
13661 static rtx
13662 legitimize_pic_address (rtx orig, rtx reg)
13663 {
13664   rtx addr = orig;
13665   rtx new_rtx = orig;
13666
13667 #if TARGET_MACHO
13668   if (TARGET_MACHO && !TARGET_64BIT)
13669     {
13670       if (reg == 0)
13671         reg = gen_reg_rtx (Pmode);
13672       /* Use the generic Mach-O PIC machinery.  */
13673       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
13674     }
13675 #endif
13676
13677   if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES)
13678     {
13679       rtx tmp = legitimize_pe_coff_symbol (addr, true);
13680       if (tmp)
13681         return tmp;
13682     }
13683
13684   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
13685     new_rtx = addr;
13686   else if (TARGET_64BIT && !TARGET_PECOFF
13687            && ix86_cmodel != CM_SMALL_PIC && gotoff_operand (addr, Pmode))
13688     {
13689       rtx tmpreg;
13690       /* This symbol may be referenced via a displacement from the PIC
13691          base address (@GOTOFF).  */
13692
13693       if (GET_CODE (addr) == CONST)
13694         addr = XEXP (addr, 0);
13695       if (GET_CODE (addr) == PLUS)
13696           {
13697             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
13698                                       UNSPEC_GOTOFF);
13699             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
13700           }
13701         else
13702           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
13703       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13704       if (!reg)
13705         tmpreg = gen_reg_rtx (Pmode);
13706       else
13707         tmpreg = reg;
13708       emit_move_insn (tmpreg, new_rtx);
13709
13710       if (reg != 0)
13711         {
13712           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
13713                                          tmpreg, 1, OPTAB_DIRECT);
13714           new_rtx = reg;
13715         }
13716       else
13717         new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
13718     }
13719   else if (!TARGET_64BIT && !TARGET_PECOFF && gotoff_operand (addr, Pmode))
13720     {
13721       /* This symbol may be referenced via a displacement from the PIC
13722          base address (@GOTOFF).  */
13723
13724       if (GET_CODE (addr) == CONST)
13725         addr = XEXP (addr, 0);
13726       if (GET_CODE (addr) == PLUS)
13727           {
13728             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
13729                                       UNSPEC_GOTOFF);
13730             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
13731           }
13732         else
13733           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
13734       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13735       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13736
13737       if (reg != 0)
13738         {
13739           emit_move_insn (reg, new_rtx);
13740           new_rtx = reg;
13741         }
13742     }
13743   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
13744            /* We can't use @GOTOFF for text labels on VxWorks;
13745               see gotoff_operand.  */
13746            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
13747     {
13748       rtx tmp = legitimize_pe_coff_symbol (addr, true);
13749       if (tmp)
13750         return tmp;
13751
13752       /* For x64 PE-COFF there is no GOT table.  So we use address
13753          directly.  */
13754       if (TARGET_64BIT && TARGET_PECOFF)
13755         {
13756           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
13757           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13758
13759           if (reg == 0)
13760             reg = gen_reg_rtx (Pmode);
13761           emit_move_insn (reg, new_rtx);
13762           new_rtx = reg;
13763         }
13764       else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
13765         {
13766           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
13767           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13768           new_rtx = gen_const_mem (Pmode, new_rtx);
13769           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
13770
13771           if (reg == 0)
13772             reg = gen_reg_rtx (Pmode);
13773           /* Use directly gen_movsi, otherwise the address is loaded
13774              into register for CSE.  We don't want to CSE this addresses,
13775              instead we CSE addresses from the GOT table, so skip this.  */
13776           emit_insn (gen_movsi (reg, new_rtx));
13777           new_rtx = reg;
13778         }
13779       else
13780         {
13781           /* This symbol must be referenced via a load from the
13782              Global Offset Table (@GOT).  */
13783
13784           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
13785           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13786           if (TARGET_64BIT)
13787             new_rtx = force_reg (Pmode, new_rtx);
13788           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13789           new_rtx = gen_const_mem (Pmode, new_rtx);
13790           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
13791
13792           if (reg == 0)
13793             reg = gen_reg_rtx (Pmode);
13794           emit_move_insn (reg, new_rtx);
13795           new_rtx = reg;
13796         }
13797     }
13798   else
13799     {
13800       if (CONST_INT_P (addr)
13801           && !x86_64_immediate_operand (addr, VOIDmode))
13802         {
13803           if (reg)
13804             {
13805               emit_move_insn (reg, addr);
13806               new_rtx = reg;
13807             }
13808           else
13809             new_rtx = force_reg (Pmode, addr);
13810         }
13811       else if (GET_CODE (addr) == CONST)
13812         {
13813           addr = XEXP (addr, 0);
13814
13815           /* We must match stuff we generate before.  Assume the only
13816              unspecs that can get here are ours.  Not that we could do
13817              anything with them anyway....  */
13818           if (GET_CODE (addr) == UNSPEC
13819               || (GET_CODE (addr) == PLUS
13820                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
13821             return orig;
13822           gcc_assert (GET_CODE (addr) == PLUS);
13823         }
13824       if (GET_CODE (addr) == PLUS)
13825         {
13826           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
13827
13828           /* Check first to see if this is a constant offset from a @GOTOFF
13829              symbol reference.  */
13830           if (!TARGET_PECOFF && gotoff_operand (op0, Pmode)
13831               && CONST_INT_P (op1))
13832             {
13833               if (!TARGET_64BIT)
13834                 {
13835                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
13836                                             UNSPEC_GOTOFF);
13837                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
13838                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13839                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13840
13841                   if (reg != 0)
13842                     {
13843                       emit_move_insn (reg, new_rtx);
13844                       new_rtx = reg;
13845                     }
13846                 }
13847               else
13848                 {
13849                   if (INTVAL (op1) < -16*1024*1024
13850                       || INTVAL (op1) >= 16*1024*1024)
13851                     {
13852                       if (!x86_64_immediate_operand (op1, Pmode))
13853                         op1 = force_reg (Pmode, op1);
13854                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
13855                     }
13856                 }
13857             }
13858           else
13859             {
13860               rtx base = legitimize_pic_address (op0, reg);
13861               machine_mode mode = GET_MODE (base);
13862               new_rtx
13863                 = legitimize_pic_address (op1, base == reg ? NULL_RTX : reg);
13864
13865               if (CONST_INT_P (new_rtx))
13866                 {
13867                   if (INTVAL (new_rtx) < -16*1024*1024
13868                       || INTVAL (new_rtx) >= 16*1024*1024)
13869                     {
13870                       if (!x86_64_immediate_operand (new_rtx, mode))
13871                         new_rtx = force_reg (mode, new_rtx);
13872                       new_rtx
13873                         = gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx);
13874                     }
13875                   else
13876                     new_rtx = plus_constant (mode, base, INTVAL (new_rtx));
13877                 }
13878               else
13879                 {
13880                   /* For %rip addressing, we have to use just disp32, not
13881                      base nor index.  */
13882                   if (TARGET_64BIT
13883                       && (GET_CODE (base) == SYMBOL_REF
13884                           || GET_CODE (base) == LABEL_REF))
13885                     base = force_reg (mode, base);
13886                   if (GET_CODE (new_rtx) == PLUS
13887                       && CONSTANT_P (XEXP (new_rtx, 1)))
13888                     {
13889                       base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0));
13890                       new_rtx = XEXP (new_rtx, 1);
13891                     }
13892                   new_rtx = gen_rtx_PLUS (mode, base, new_rtx);
13893                 }
13894             }
13895         }
13896     }
13897   return new_rtx;
13898 }
13899 \f
13900 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
13901
13902 static rtx
13903 get_thread_pointer (machine_mode tp_mode, bool to_reg)
13904 {
13905   rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
13906
13907   if (GET_MODE (tp) != tp_mode)
13908     {
13909       gcc_assert (GET_MODE (tp) == SImode);
13910       gcc_assert (tp_mode == DImode);
13911
13912       tp = gen_rtx_ZERO_EXTEND (tp_mode, tp);
13913     }
13914
13915   if (to_reg)
13916     tp = copy_to_mode_reg (tp_mode, tp);
13917
13918   return tp;
13919 }
13920
13921 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
13922
13923 static GTY(()) rtx ix86_tls_symbol;
13924
13925 static rtx
13926 ix86_tls_get_addr (void)
13927 {
13928   if (!ix86_tls_symbol)
13929     {
13930       const char *sym
13931         = ((TARGET_ANY_GNU_TLS && !TARGET_64BIT)
13932            ? "___tls_get_addr" : "__tls_get_addr");
13933
13934       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym);
13935     }
13936
13937   if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF)
13938     {
13939       rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol),
13940                                    UNSPEC_PLTOFF);
13941       return gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
13942                            gen_rtx_CONST (Pmode, unspec));
13943     }
13944
13945   return ix86_tls_symbol;
13946 }
13947
13948 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
13949
13950 static GTY(()) rtx ix86_tls_module_base_symbol;
13951
13952 rtx
13953 ix86_tls_module_base (void)
13954 {
13955   if (!ix86_tls_module_base_symbol)
13956     {
13957       ix86_tls_module_base_symbol
13958         = gen_rtx_SYMBOL_REF (Pmode, "_TLS_MODULE_BASE_");
13959
13960       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
13961         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
13962     }
13963
13964   return ix86_tls_module_base_symbol;
13965 }
13966
13967 /* A subroutine of ix86_legitimize_address and ix86_expand_move.  FOR_MOV is
13968    false if we expect this to be used for a memory address and true if
13969    we expect to load the address into a register.  */
13970
13971 static rtx
13972 legitimize_tls_address (rtx x, enum tls_model model, bool for_mov)
13973 {
13974   rtx dest, base, off;
13975   rtx pic = NULL_RTX, tp = NULL_RTX;
13976   machine_mode tp_mode = Pmode;
13977   int type;
13978
13979   /* Fall back to global dynamic model if tool chain cannot support local
13980      dynamic.  */
13981   if (TARGET_SUN_TLS && !TARGET_64BIT
13982       && !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM
13983       && model == TLS_MODEL_LOCAL_DYNAMIC)
13984     model = TLS_MODEL_GLOBAL_DYNAMIC;
13985
13986   switch (model)
13987     {
13988     case TLS_MODEL_GLOBAL_DYNAMIC:
13989       dest = gen_reg_rtx (Pmode);
13990
13991       if (!TARGET_64BIT)
13992         {
13993           if (flag_pic && !TARGET_PECOFF)
13994             pic = pic_offset_table_rtx;
13995           else
13996             {
13997               pic = gen_reg_rtx (Pmode);
13998               emit_insn (gen_set_got (pic));
13999             }
14000         }
14001
14002       if (TARGET_GNU2_TLS)
14003         {
14004           if (TARGET_64BIT)
14005             emit_insn (gen_tls_dynamic_gnu2_64 (dest, x));
14006           else
14007             emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic));
14008
14009           tp = get_thread_pointer (Pmode, true);
14010           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
14011
14012           if (GET_MODE (x) != Pmode)
14013             x = gen_rtx_ZERO_EXTEND (Pmode, x);
14014
14015           set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
14016         }
14017       else
14018         {
14019           rtx caddr = ix86_tls_get_addr ();
14020
14021           if (TARGET_64BIT)
14022             {
14023               rtx rax = gen_rtx_REG (Pmode, AX_REG);
14024               rtx_insn *insns;
14025
14026               start_sequence ();
14027               emit_call_insn
14028                 (ix86_gen_tls_global_dynamic_64 (rax, x, caddr));
14029               insns = get_insns ();
14030               end_sequence ();
14031
14032               if (GET_MODE (x) != Pmode)
14033                 x = gen_rtx_ZERO_EXTEND (Pmode, x);
14034
14035               RTL_CONST_CALL_P (insns) = 1;
14036               emit_libcall_block (insns, dest, rax, x);
14037             }
14038           else
14039             emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr));
14040         }
14041       break;
14042
14043     case TLS_MODEL_LOCAL_DYNAMIC:
14044       base = gen_reg_rtx (Pmode);
14045
14046       if (!TARGET_64BIT)
14047         {
14048           if (flag_pic)
14049             pic = pic_offset_table_rtx;
14050           else
14051             {
14052               pic = gen_reg_rtx (Pmode);
14053               emit_insn (gen_set_got (pic));
14054             }
14055         }
14056
14057       if (TARGET_GNU2_TLS)
14058         {
14059           rtx tmp = ix86_tls_module_base ();
14060
14061           if (TARGET_64BIT)
14062             emit_insn (gen_tls_dynamic_gnu2_64 (base, tmp));
14063           else
14064             emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic));
14065
14066           tp = get_thread_pointer (Pmode, true);
14067           set_unique_reg_note (get_last_insn (), REG_EQUAL,
14068                                gen_rtx_MINUS (Pmode, tmp, tp));
14069         }
14070       else
14071         {
14072           rtx caddr = ix86_tls_get_addr ();
14073
14074           if (TARGET_64BIT)
14075             {
14076               rtx rax = gen_rtx_REG (Pmode, AX_REG);
14077               rtx_insn *insns;
14078               rtx eqv;
14079
14080               start_sequence ();
14081               emit_call_insn
14082                 (ix86_gen_tls_local_dynamic_base_64 (rax, caddr));
14083               insns = get_insns ();
14084               end_sequence ();
14085
14086               /* Attach a unique REG_EQUAL, to allow the RTL optimizers to
14087                  share the LD_BASE result with other LD model accesses.  */
14088               eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
14089                                     UNSPEC_TLS_LD_BASE);
14090
14091               RTL_CONST_CALL_P (insns) = 1;
14092               emit_libcall_block (insns, base, rax, eqv);
14093             }
14094           else
14095             emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr));
14096         }
14097
14098       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
14099       off = gen_rtx_CONST (Pmode, off);
14100
14101       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
14102
14103       if (TARGET_GNU2_TLS)
14104         {
14105           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
14106
14107           if (GET_MODE (x) != Pmode)
14108             x = gen_rtx_ZERO_EXTEND (Pmode, x);
14109
14110           set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
14111         }
14112       break;
14113
14114     case TLS_MODEL_INITIAL_EXEC:
14115       if (TARGET_64BIT)
14116         {
14117           if (TARGET_SUN_TLS && !TARGET_X32)
14118             {
14119               /* The Sun linker took the AMD64 TLS spec literally
14120                  and can only handle %rax as destination of the
14121                  initial executable code sequence.  */
14122
14123               dest = gen_reg_rtx (DImode);
14124               emit_insn (gen_tls_initial_exec_64_sun (dest, x));
14125               return dest;
14126             }
14127
14128           /* Generate DImode references to avoid %fs:(%reg32)
14129              problems and linker IE->LE relaxation bug.  */
14130           tp_mode = DImode;
14131           pic = NULL;
14132           type = UNSPEC_GOTNTPOFF;
14133         }
14134       else if (flag_pic)
14135         {
14136           pic = pic_offset_table_rtx;
14137           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
14138         }
14139       else if (!TARGET_ANY_GNU_TLS)
14140         {
14141           pic = gen_reg_rtx (Pmode);
14142           emit_insn (gen_set_got (pic));
14143           type = UNSPEC_GOTTPOFF;
14144         }
14145       else
14146         {
14147           pic = NULL;
14148           type = UNSPEC_INDNTPOFF;
14149         }
14150
14151       off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type);
14152       off = gen_rtx_CONST (tp_mode, off);
14153       if (pic)
14154         off = gen_rtx_PLUS (tp_mode, pic, off);
14155       off = gen_const_mem (tp_mode, off);
14156       set_mem_alias_set (off, ix86_GOT_alias_set ());
14157
14158       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14159         {
14160           base = get_thread_pointer (tp_mode,
14161                                      for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
14162           off = force_reg (tp_mode, off);
14163           return gen_rtx_PLUS (tp_mode, base, off);
14164         }
14165       else
14166         {
14167           base = get_thread_pointer (Pmode, true);
14168           dest = gen_reg_rtx (Pmode);
14169           emit_insn (ix86_gen_sub3 (dest, base, off));
14170         }
14171       break;
14172
14173     case TLS_MODEL_LOCAL_EXEC:
14174       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
14175                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14176                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
14177       off = gen_rtx_CONST (Pmode, off);
14178
14179       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14180         {
14181           base = get_thread_pointer (Pmode,
14182                                      for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
14183           return gen_rtx_PLUS (Pmode, base, off);
14184         }
14185       else
14186         {
14187           base = get_thread_pointer (Pmode, true);
14188           dest = gen_reg_rtx (Pmode);
14189           emit_insn (ix86_gen_sub3 (dest, base, off));
14190         }
14191       break;
14192
14193     default:
14194       gcc_unreachable ();
14195     }
14196
14197   return dest;
14198 }
14199
14200 /* Create or return the unique __imp_DECL dllimport symbol corresponding
14201    to symbol DECL if BEIMPORT is true.  Otherwise create or return the
14202    unique refptr-DECL symbol corresponding to symbol DECL.  */
14203
14204 struct dllimport_hasher : ggc_cache_hasher<tree_map *>
14205 {
14206   static inline hashval_t hash (tree_map *m) { return m->hash; }
14207   static inline bool
14208   equal (tree_map *a, tree_map *b)
14209   {
14210     return a->base.from == b->base.from;
14211   }
14212
14213   static void
14214   handle_cache_entry (tree_map *&m)
14215   {
14216     extern void gt_ggc_mx (tree_map *&);
14217     if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY)
14218       return;
14219     else if (ggc_marked_p (m->base.from))
14220       gt_ggc_mx (m);
14221     else
14222       m = static_cast<tree_map *> (HTAB_DELETED_ENTRY);
14223   }
14224 };
14225
14226 static GTY((cache)) hash_table<dllimport_hasher> *dllimport_map;
14227
14228 static tree
14229 get_dllimport_decl (tree decl, bool beimport)
14230 {
14231   struct tree_map *h, in;
14232   const char *name;
14233   const char *prefix;
14234   size_t namelen, prefixlen;
14235   char *imp_name;
14236   tree to;
14237   rtx rtl;
14238
14239   if (!dllimport_map)
14240     dllimport_map = hash_table<dllimport_hasher>::create_ggc (512);
14241
14242   in.hash = htab_hash_pointer (decl);
14243   in.base.from = decl;
14244   tree_map **loc = dllimport_map->find_slot_with_hash (&in, in.hash, INSERT);
14245   h = *loc;
14246   if (h)
14247     return h->to;
14248
14249   *loc = h = ggc_alloc<tree_map> ();
14250   h->hash = in.hash;
14251   h->base.from = decl;
14252   h->to = to = build_decl (DECL_SOURCE_LOCATION (decl),
14253                            VAR_DECL, NULL, ptr_type_node);
14254   DECL_ARTIFICIAL (to) = 1;
14255   DECL_IGNORED_P (to) = 1;
14256   DECL_EXTERNAL (to) = 1;
14257   TREE_READONLY (to) = 1;
14258
14259   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
14260   name = targetm.strip_name_encoding (name);
14261   if (beimport)
14262     prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
14263       ? "*__imp_" : "*__imp__";
14264   else
14265     prefix = user_label_prefix[0] == 0 ? "*.refptr." : "*refptr.";
14266   namelen = strlen (name);
14267   prefixlen = strlen (prefix);
14268   imp_name = (char *) alloca (namelen + prefixlen + 1);
14269   memcpy (imp_name, prefix, prefixlen);
14270   memcpy (imp_name + prefixlen, name, namelen + 1);
14271
14272   name = ggc_alloc_string (imp_name, namelen + prefixlen);
14273   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
14274   SET_SYMBOL_REF_DECL (rtl, to);
14275   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_STUBVAR;
14276   if (!beimport)
14277     {
14278       SYMBOL_REF_FLAGS (rtl) |= SYMBOL_FLAG_EXTERNAL;
14279 #ifdef SUB_TARGET_RECORD_STUB
14280       SUB_TARGET_RECORD_STUB (name);
14281 #endif
14282     }      
14283
14284   rtl = gen_const_mem (Pmode, rtl);
14285   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
14286
14287   SET_DECL_RTL (to, rtl);
14288   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
14289
14290   return to;
14291 }
14292
14293 /* Expand SYMBOL into its corresponding far-addresse symbol.
14294    WANT_REG is true if we require the result be a register.  */
14295
14296 static rtx
14297 legitimize_pe_coff_extern_decl (rtx symbol, bool want_reg)
14298 {
14299   tree imp_decl;
14300   rtx x;
14301
14302   gcc_assert (SYMBOL_REF_DECL (symbol));
14303   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), false);
14304
14305   x = DECL_RTL (imp_decl);
14306   if (want_reg)
14307     x = force_reg (Pmode, x);
14308   return x;
14309 }
14310
14311 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
14312    true if we require the result be a register.  */
14313
14314 static rtx
14315 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
14316 {
14317   tree imp_decl;
14318   rtx x;
14319
14320   gcc_assert (SYMBOL_REF_DECL (symbol));
14321   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), true);
14322
14323   x = DECL_RTL (imp_decl);
14324   if (want_reg)
14325     x = force_reg (Pmode, x);
14326   return x;
14327 }
14328
14329 /* Expand SYMBOL into its corresponding dllimport or refptr symbol.  WANT_REG 
14330    is true if we require the result be a register.  */
14331
14332 static rtx
14333 legitimize_pe_coff_symbol (rtx addr, bool inreg)
14334 {
14335   if (!TARGET_PECOFF)
14336     return NULL_RTX;
14337
14338   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
14339     {
14340       if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
14341         return legitimize_dllimport_symbol (addr, inreg);
14342       if (GET_CODE (addr) == CONST
14343           && GET_CODE (XEXP (addr, 0)) == PLUS
14344           && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
14345           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
14346         {
14347           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), inreg);
14348           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
14349         }
14350     }
14351
14352   if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC)
14353     return NULL_RTX;
14354   if (GET_CODE (addr) == SYMBOL_REF
14355       && !is_imported_p (addr)
14356       && SYMBOL_REF_EXTERNAL_P (addr)
14357       && SYMBOL_REF_DECL (addr))
14358     return legitimize_pe_coff_extern_decl (addr, inreg);
14359
14360   if (GET_CODE (addr) == CONST
14361       && GET_CODE (XEXP (addr, 0)) == PLUS
14362       && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
14363       && !is_imported_p (XEXP (XEXP (addr, 0), 0))
14364       && SYMBOL_REF_EXTERNAL_P (XEXP (XEXP (addr, 0), 0))
14365       && SYMBOL_REF_DECL (XEXP (XEXP (addr, 0), 0)))
14366     {
14367       rtx t = legitimize_pe_coff_extern_decl (XEXP (XEXP (addr, 0), 0), inreg);
14368       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
14369     }
14370   return NULL_RTX;
14371 }
14372
14373 /* Try machine-dependent ways of modifying an illegitimate address
14374    to be legitimate.  If we find one, return the new, valid address.
14375    This macro is used in only one place: `memory_address' in explow.c.
14376
14377    OLDX is the address as it was before break_out_memory_refs was called.
14378    In some cases it is useful to look at this to decide what needs to be done.
14379
14380    It is always safe for this macro to do nothing.  It exists to recognize
14381    opportunities to optimize the output.
14382
14383    For the 80386, we handle X+REG by loading X into a register R and
14384    using R+REG.  R will go in a general reg and indexing will be used.
14385    However, if REG is a broken-out memory address or multiplication,
14386    nothing needs to be done because REG can certainly go in a general reg.
14387
14388    When -fpic is used, special handling is needed for symbolic references.
14389    See comments by legitimize_pic_address in i386.c for details.  */
14390
14391 static rtx
14392 ix86_legitimize_address (rtx x, rtx, machine_mode mode)
14393 {
14394   bool changed = false;
14395   unsigned log;
14396
14397   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
14398   if (log)
14399     return legitimize_tls_address (x, (enum tls_model) log, false);
14400   if (GET_CODE (x) == CONST
14401       && GET_CODE (XEXP (x, 0)) == PLUS
14402       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
14403       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
14404     {
14405       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
14406                                       (enum tls_model) log, false);
14407       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
14408     }
14409
14410   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
14411     {
14412       rtx tmp = legitimize_pe_coff_symbol (x, true);
14413       if (tmp)
14414         return tmp;
14415     }
14416
14417   if (flag_pic && SYMBOLIC_CONST (x))
14418     return legitimize_pic_address (x, 0);
14419
14420 #if TARGET_MACHO
14421   if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x))
14422     return machopic_indirect_data_reference (x, 0);
14423 #endif
14424
14425   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
14426   if (GET_CODE (x) == ASHIFT
14427       && CONST_INT_P (XEXP (x, 1))
14428       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
14429     {
14430       changed = true;
14431       log = INTVAL (XEXP (x, 1));
14432       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
14433                         GEN_INT (1 << log));
14434     }
14435
14436   if (GET_CODE (x) == PLUS)
14437     {
14438       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
14439
14440       if (GET_CODE (XEXP (x, 0)) == ASHIFT
14441           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
14442           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
14443         {
14444           changed = true;
14445           log = INTVAL (XEXP (XEXP (x, 0), 1));
14446           XEXP (x, 0) = gen_rtx_MULT (Pmode,
14447                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
14448                                       GEN_INT (1 << log));
14449         }
14450
14451       if (GET_CODE (XEXP (x, 1)) == ASHIFT
14452           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
14453           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
14454         {
14455           changed = true;
14456           log = INTVAL (XEXP (XEXP (x, 1), 1));
14457           XEXP (x, 1) = gen_rtx_MULT (Pmode,
14458                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
14459                                       GEN_INT (1 << log));
14460         }
14461
14462       /* Put multiply first if it isn't already.  */
14463       if (GET_CODE (XEXP (x, 1)) == MULT)
14464         {
14465           std::swap (XEXP (x, 0), XEXP (x, 1));
14466           changed = true;
14467         }
14468
14469       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
14470          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
14471          created by virtual register instantiation, register elimination, and
14472          similar optimizations.  */
14473       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
14474         {
14475           changed = true;
14476           x = gen_rtx_PLUS (Pmode,
14477                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
14478                                           XEXP (XEXP (x, 1), 0)),
14479                             XEXP (XEXP (x, 1), 1));
14480         }
14481
14482       /* Canonicalize
14483          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
14484          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
14485       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
14486                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
14487                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
14488                && CONSTANT_P (XEXP (x, 1)))
14489         {
14490           rtx constant;
14491           rtx other = NULL_RTX;
14492
14493           if (CONST_INT_P (XEXP (x, 1)))
14494             {
14495               constant = XEXP (x, 1);
14496               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
14497             }
14498           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
14499             {
14500               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
14501               other = XEXP (x, 1);
14502             }
14503           else
14504             constant = 0;
14505
14506           if (constant)
14507             {
14508               changed = true;
14509               x = gen_rtx_PLUS (Pmode,
14510                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
14511                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
14512                                 plus_constant (Pmode, other,
14513                                                INTVAL (constant)));
14514             }
14515         }
14516
14517       if (changed && ix86_legitimate_address_p (mode, x, false))
14518         return x;
14519
14520       if (GET_CODE (XEXP (x, 0)) == MULT)
14521         {
14522           changed = true;
14523           XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0));
14524         }
14525
14526       if (GET_CODE (XEXP (x, 1)) == MULT)
14527         {
14528           changed = true;
14529           XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1));
14530         }
14531
14532       if (changed
14533           && REG_P (XEXP (x, 1))
14534           && REG_P (XEXP (x, 0)))
14535         return x;
14536
14537       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
14538         {
14539           changed = true;
14540           x = legitimize_pic_address (x, 0);
14541         }
14542
14543       if (changed && ix86_legitimate_address_p (mode, x, false))
14544         return x;
14545
14546       if (REG_P (XEXP (x, 0)))
14547         {
14548           rtx temp = gen_reg_rtx (Pmode);
14549           rtx val  = force_operand (XEXP (x, 1), temp);
14550           if (val != temp)
14551             {
14552               val = convert_to_mode (Pmode, val, 1);
14553               emit_move_insn (temp, val);
14554             }
14555
14556           XEXP (x, 1) = temp;
14557           return x;
14558         }
14559
14560       else if (REG_P (XEXP (x, 1)))
14561         {
14562           rtx temp = gen_reg_rtx (Pmode);
14563           rtx val  = force_operand (XEXP (x, 0), temp);
14564           if (val != temp)
14565             {
14566               val = convert_to_mode (Pmode, val, 1);
14567               emit_move_insn (temp, val);
14568             }
14569
14570           XEXP (x, 0) = temp;
14571           return x;
14572         }
14573     }
14574
14575   return x;
14576 }
14577 \f
14578 /* Print an integer constant expression in assembler syntax.  Addition
14579    and subtraction are the only arithmetic that may appear in these
14580    expressions.  FILE is the stdio stream to write to, X is the rtx, and
14581    CODE is the operand print code from the output string.  */
14582
14583 static void
14584 output_pic_addr_const (FILE *file, rtx x, int code)
14585 {
14586   char buf[256];
14587
14588   switch (GET_CODE (x))
14589     {
14590     case PC:
14591       gcc_assert (flag_pic);
14592       putc ('.', file);
14593       break;
14594
14595     case SYMBOL_REF:
14596       if (TARGET_64BIT || ! TARGET_MACHO_BRANCH_ISLANDS)
14597         output_addr_const (file, x);
14598       else
14599         {
14600           const char *name = XSTR (x, 0);
14601
14602           /* Mark the decl as referenced so that cgraph will
14603              output the function.  */
14604           if (SYMBOL_REF_DECL (x))
14605             mark_decl_referenced (SYMBOL_REF_DECL (x));
14606
14607 #if TARGET_MACHO
14608           if (MACHOPIC_INDIRECT
14609               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
14610             name = machopic_indirection_name (x, /*stub_p=*/true);
14611 #endif
14612           assemble_name (file, name);
14613         }
14614       if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
14615           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
14616         fputs ("@PLT", file);
14617       break;
14618
14619     case LABEL_REF:
14620       x = XEXP (x, 0);
14621       /* FALLTHRU */
14622     case CODE_LABEL:
14623       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
14624       assemble_name (asm_out_file, buf);
14625       break;
14626
14627     case CONST_INT:
14628       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
14629       break;
14630
14631     case CONST:
14632       /* This used to output parentheses around the expression,
14633          but that does not work on the 386 (either ATT or BSD assembler).  */
14634       output_pic_addr_const (file, XEXP (x, 0), code);
14635       break;
14636
14637     case CONST_DOUBLE:
14638       /* We can't handle floating point constants;
14639          TARGET_PRINT_OPERAND must handle them.  */
14640       output_operand_lossage ("floating constant misused");
14641       break;
14642
14643     case PLUS:
14644       /* Some assemblers need integer constants to appear first.  */
14645       if (CONST_INT_P (XEXP (x, 0)))
14646         {
14647           output_pic_addr_const (file, XEXP (x, 0), code);
14648           putc ('+', file);
14649           output_pic_addr_const (file, XEXP (x, 1), code);
14650         }
14651       else
14652         {
14653           gcc_assert (CONST_INT_P (XEXP (x, 1)));
14654           output_pic_addr_const (file, XEXP (x, 1), code);
14655           putc ('+', file);
14656           output_pic_addr_const (file, XEXP (x, 0), code);
14657         }
14658       break;
14659
14660     case MINUS:
14661       if (!TARGET_MACHO)
14662         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
14663       output_pic_addr_const (file, XEXP (x, 0), code);
14664       putc ('-', file);
14665       output_pic_addr_const (file, XEXP (x, 1), code);
14666       if (!TARGET_MACHO)
14667         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
14668       break;
14669
14670      case UNSPEC:
14671        if (XINT (x, 1) == UNSPEC_STACK_CHECK)
14672          {
14673            bool f = i386_asm_output_addr_const_extra (file, x);
14674            gcc_assert (f);
14675            break;
14676          }
14677
14678        gcc_assert (XVECLEN (x, 0) == 1);
14679        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
14680        switch (XINT (x, 1))
14681         {
14682         case UNSPEC_GOT:
14683           fputs ("@GOT", file);
14684           break;
14685         case UNSPEC_GOTOFF:
14686           fputs ("@GOTOFF", file);
14687           break;
14688         case UNSPEC_PLTOFF:
14689           fputs ("@PLTOFF", file);
14690           break;
14691         case UNSPEC_PCREL:
14692           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14693                  "(%rip)" : "[rip]", file);
14694           break;
14695         case UNSPEC_GOTPCREL:
14696           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14697                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
14698           break;
14699         case UNSPEC_GOTTPOFF:
14700           /* FIXME: This might be @TPOFF in Sun ld too.  */
14701           fputs ("@gottpoff", file);
14702           break;
14703         case UNSPEC_TPOFF:
14704           fputs ("@tpoff", file);
14705           break;
14706         case UNSPEC_NTPOFF:
14707           if (TARGET_64BIT)
14708             fputs ("@tpoff", file);
14709           else
14710             fputs ("@ntpoff", file);
14711           break;
14712         case UNSPEC_DTPOFF:
14713           fputs ("@dtpoff", file);
14714           break;
14715         case UNSPEC_GOTNTPOFF:
14716           if (TARGET_64BIT)
14717             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14718                    "@gottpoff(%rip)": "@gottpoff[rip]", file);
14719           else
14720             fputs ("@gotntpoff", file);
14721           break;
14722         case UNSPEC_INDNTPOFF:
14723           fputs ("@indntpoff", file);
14724           break;
14725 #if TARGET_MACHO
14726         case UNSPEC_MACHOPIC_OFFSET:
14727           putc ('-', file);
14728           machopic_output_function_base_name (file);
14729           break;
14730 #endif
14731         default:
14732           output_operand_lossage ("invalid UNSPEC as operand");
14733           break;
14734         }
14735        break;
14736
14737     default:
14738       output_operand_lossage ("invalid expression as operand");
14739     }
14740 }
14741
14742 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
14743    We need to emit DTP-relative relocations.  */
14744
14745 static void ATTRIBUTE_UNUSED
14746 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
14747 {
14748   fputs (ASM_LONG, file);
14749   output_addr_const (file, x);
14750   fputs ("@dtpoff", file);
14751   switch (size)
14752     {
14753     case 4:
14754       break;
14755     case 8:
14756       fputs (", 0", file);
14757       break;
14758     default:
14759       gcc_unreachable ();
14760    }
14761 }
14762
14763 /* Return true if X is a representation of the PIC register.  This copes
14764    with calls from ix86_find_base_term, where the register might have
14765    been replaced by a cselib value.  */
14766
14767 static bool
14768 ix86_pic_register_p (rtx x)
14769 {
14770   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
14771     return (pic_offset_table_rtx
14772             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
14773   else if (!REG_P (x))
14774     return false;
14775   else if (pic_offset_table_rtx)
14776     {
14777       if (REGNO (x) == REGNO (pic_offset_table_rtx))
14778         return true;
14779       if (HARD_REGISTER_P (x)
14780           && !HARD_REGISTER_P (pic_offset_table_rtx)
14781           && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
14782         return true;
14783       return false;
14784     }
14785   else
14786     return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
14787 }
14788
14789 /* Helper function for ix86_delegitimize_address.
14790    Attempt to delegitimize TLS local-exec accesses.  */
14791
14792 static rtx
14793 ix86_delegitimize_tls_address (rtx orig_x)
14794 {
14795   rtx x = orig_x, unspec;
14796   struct ix86_address addr;
14797
14798   if (!TARGET_TLS_DIRECT_SEG_REFS)
14799     return orig_x;
14800   if (MEM_P (x))
14801     x = XEXP (x, 0);
14802   if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
14803     return orig_x;
14804   if (ix86_decompose_address (x, &addr) == 0
14805       || addr.seg != DEFAULT_TLS_SEG_REG
14806       || addr.disp == NULL_RTX
14807       || GET_CODE (addr.disp) != CONST)
14808     return orig_x;
14809   unspec = XEXP (addr.disp, 0);
14810   if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
14811     unspec = XEXP (unspec, 0);
14812   if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF)
14813     return orig_x;
14814   x = XVECEXP (unspec, 0, 0);
14815   gcc_assert (GET_CODE (x) == SYMBOL_REF);
14816   if (unspec != XEXP (addr.disp, 0))
14817     x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1));
14818   if (addr.index)
14819     {
14820       rtx idx = addr.index;
14821       if (addr.scale != 1)
14822         idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
14823       x = gen_rtx_PLUS (Pmode, idx, x);
14824     }
14825   if (addr.base)
14826     x = gen_rtx_PLUS (Pmode, addr.base, x);
14827   if (MEM_P (orig_x))
14828     x = replace_equiv_address_nv (orig_x, x);
14829   return x;
14830 }
14831
14832 /* In the name of slightly smaller debug output, and to cater to
14833    general assembler lossage, recognize PIC+GOTOFF and turn it back
14834    into a direct symbol reference.
14835
14836    On Darwin, this is necessary to avoid a crash, because Darwin
14837    has a different PIC label for each routine but the DWARF debugging
14838    information is not associated with any particular routine, so it's
14839    necessary to remove references to the PIC label from RTL stored by
14840    the DWARF output code.  */
14841
14842 static rtx
14843 ix86_delegitimize_address (rtx x)
14844 {
14845   rtx orig_x = delegitimize_mem_from_attrs (x);
14846   /* addend is NULL or some rtx if x is something+GOTOFF where
14847      something doesn't include the PIC register.  */
14848   rtx addend = NULL_RTX;
14849   /* reg_addend is NULL or a multiple of some register.  */
14850   rtx reg_addend = NULL_RTX;
14851   /* const_addend is NULL or a const_int.  */
14852   rtx const_addend = NULL_RTX;
14853   /* This is the result, or NULL.  */
14854   rtx result = NULL_RTX;
14855
14856   x = orig_x;
14857
14858   if (MEM_P (x))
14859     x = XEXP (x, 0);
14860
14861   if (TARGET_64BIT)
14862     {
14863       if (GET_CODE (x) == CONST
14864           && GET_CODE (XEXP (x, 0)) == PLUS
14865           && GET_MODE (XEXP (x, 0)) == Pmode
14866           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
14867           && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC
14868           && XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL)
14869         {
14870           rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0);
14871           x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2);
14872           if (MEM_P (orig_x))
14873             x = replace_equiv_address_nv (orig_x, x);
14874           return x;
14875         }
14876
14877       if (GET_CODE (x) == CONST
14878           && GET_CODE (XEXP (x, 0)) == UNSPEC
14879           && (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL
14880               || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)
14881           && (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL))
14882         {
14883           x = XVECEXP (XEXP (x, 0), 0, 0);
14884           if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x))
14885             {
14886               x = simplify_gen_subreg (GET_MODE (orig_x), x,
14887                                        GET_MODE (x), 0);
14888               if (x == NULL_RTX)
14889                 return orig_x;
14890             }
14891           return x;
14892         }
14893
14894       if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC)
14895         return ix86_delegitimize_tls_address (orig_x);
14896
14897       /* Fall thru into the code shared with -m32 for -mcmodel=large -fpic
14898          and -mcmodel=medium -fpic.  */
14899     }
14900
14901   if (GET_CODE (x) != PLUS
14902       || GET_CODE (XEXP (x, 1)) != CONST)
14903     return ix86_delegitimize_tls_address (orig_x);
14904
14905   if (ix86_pic_register_p (XEXP (x, 0)))
14906     /* %ebx + GOT/GOTOFF */
14907     ;
14908   else if (GET_CODE (XEXP (x, 0)) == PLUS)
14909     {
14910       /* %ebx + %reg * scale + GOT/GOTOFF */
14911       reg_addend = XEXP (x, 0);
14912       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
14913         reg_addend = XEXP (reg_addend, 1);
14914       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
14915         reg_addend = XEXP (reg_addend, 0);
14916       else
14917         {
14918           reg_addend = NULL_RTX;
14919           addend = XEXP (x, 0);
14920         }
14921     }
14922   else
14923     addend = XEXP (x, 0);
14924
14925   x = XEXP (XEXP (x, 1), 0);
14926   if (GET_CODE (x) == PLUS
14927       && CONST_INT_P (XEXP (x, 1)))
14928     {
14929       const_addend = XEXP (x, 1);
14930       x = XEXP (x, 0);
14931     }
14932
14933   if (GET_CODE (x) == UNSPEC
14934       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend)
14935           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))
14936           || (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC
14937               && !MEM_P (orig_x) && !addend)))
14938     result = XVECEXP (x, 0, 0);
14939
14940   if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x)
14941       && !MEM_P (orig_x))
14942     result = XVECEXP (x, 0, 0);
14943
14944   if (! result)
14945     return ix86_delegitimize_tls_address (orig_x);
14946
14947   if (const_addend)
14948     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
14949   if (reg_addend)
14950     result = gen_rtx_PLUS (Pmode, reg_addend, result);
14951   if (addend)
14952     {
14953       /* If the rest of original X doesn't involve the PIC register, add
14954          addend and subtract pic_offset_table_rtx.  This can happen e.g.
14955          for code like:
14956          leal (%ebx, %ecx, 4), %ecx
14957          ...
14958          movl foo@GOTOFF(%ecx), %edx
14959          in which case we return (%ecx - %ebx) + foo
14960          or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
14961          and reload has completed.  */
14962       if (pic_offset_table_rtx
14963           && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
14964         result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
14965                                                      pic_offset_table_rtx),
14966                                result);
14967       else if (pic_offset_table_rtx && !TARGET_MACHO && !TARGET_VXWORKS_RTP)
14968         {
14969           rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
14970           tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
14971           result = gen_rtx_PLUS (Pmode, tmp, result);
14972         }
14973       else
14974         return orig_x;
14975     }
14976   if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x))
14977     {
14978       result = simplify_gen_subreg (GET_MODE (orig_x), result, Pmode, 0);
14979       if (result == NULL_RTX)
14980         return orig_x;
14981     }
14982   return result;
14983 }
14984
14985 /* If X is a machine specific address (i.e. a symbol or label being
14986    referenced as a displacement from the GOT implemented using an
14987    UNSPEC), then return the base term.  Otherwise return X.  */
14988
14989 rtx
14990 ix86_find_base_term (rtx x)
14991 {
14992   rtx term;
14993
14994   if (TARGET_64BIT)
14995     {
14996       if (GET_CODE (x) != CONST)
14997         return x;
14998       term = XEXP (x, 0);
14999       if (GET_CODE (term) == PLUS
15000           && CONST_INT_P (XEXP (term, 1)))
15001         term = XEXP (term, 0);
15002       if (GET_CODE (term) != UNSPEC
15003           || (XINT (term, 1) != UNSPEC_GOTPCREL
15004               && XINT (term, 1) != UNSPEC_PCREL))
15005         return x;
15006
15007       return XVECEXP (term, 0, 0);
15008     }
15009
15010   return ix86_delegitimize_address (x);
15011 }
15012 \f
15013 static void
15014 put_condition_code (enum rtx_code code, machine_mode mode, bool reverse,
15015                     bool fp, FILE *file)
15016 {
15017   const char *suffix;
15018
15019   if (mode == CCFPmode || mode == CCFPUmode)
15020     {
15021       code = ix86_fp_compare_code_to_integer (code);
15022       mode = CCmode;
15023     }
15024   if (reverse)
15025     code = reverse_condition (code);
15026
15027   switch (code)
15028     {
15029     case EQ:
15030       switch (mode)
15031         {
15032         case CCAmode:
15033           suffix = "a";
15034           break;
15035         case CCCmode:
15036           suffix = "c";
15037           break;
15038         case CCOmode:
15039           suffix = "o";
15040           break;
15041         case CCPmode:
15042           suffix = "p";
15043           break;
15044         case CCSmode:
15045           suffix = "s";
15046           break;
15047         default:
15048           suffix = "e";
15049           break;
15050         }
15051       break;
15052     case NE:
15053       switch (mode)
15054         {
15055         case CCAmode:
15056           suffix = "na";
15057           break;
15058         case CCCmode:
15059           suffix = "nc";
15060           break;
15061         case CCOmode:
15062           suffix = "no";
15063           break;
15064         case CCPmode:
15065           suffix = "np";
15066           break;
15067         case CCSmode:
15068           suffix = "ns";
15069           break;
15070         default:
15071           suffix = "ne";
15072           break;
15073         }
15074       break;
15075     case GT:
15076       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
15077       suffix = "g";
15078       break;
15079     case GTU:
15080       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
15081          Those same assemblers have the same but opposite lossage on cmov.  */
15082       if (mode == CCmode)
15083         suffix = fp ? "nbe" : "a";
15084       else
15085         gcc_unreachable ();
15086       break;
15087     case LT:
15088       switch (mode)
15089         {
15090         case CCNOmode:
15091         case CCGOCmode:
15092           suffix = "s";
15093           break;
15094
15095         case CCmode:
15096         case CCGCmode:
15097           suffix = "l";
15098           break;
15099
15100         default:
15101           gcc_unreachable ();
15102         }
15103       break;
15104     case LTU:
15105       if (mode == CCmode)
15106         suffix = "b";
15107       else if (mode == CCCmode)
15108         suffix = fp ? "b" : "c";
15109       else
15110         gcc_unreachable ();
15111       break;
15112     case GE:
15113       switch (mode)
15114         {
15115         case CCNOmode:
15116         case CCGOCmode:
15117           suffix = "ns";
15118           break;
15119
15120         case CCmode:
15121         case CCGCmode:
15122           suffix = "ge";
15123           break;
15124
15125         default:
15126           gcc_unreachable ();
15127         }
15128       break;
15129     case GEU:
15130       if (mode == CCmode)
15131         suffix = "nb";
15132       else if (mode == CCCmode)
15133         suffix = fp ? "nb" : "nc";
15134       else
15135         gcc_unreachable ();
15136       break;
15137     case LE:
15138       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
15139       suffix = "le";
15140       break;
15141     case LEU:
15142       if (mode == CCmode)
15143         suffix = "be";
15144       else
15145         gcc_unreachable ();
15146       break;
15147     case UNORDERED:
15148       suffix = fp ? "u" : "p";
15149       break;
15150     case ORDERED:
15151       suffix = fp ? "nu" : "np";
15152       break;
15153     default:
15154       gcc_unreachable ();
15155     }
15156   fputs (suffix, file);
15157 }
15158
15159 /* Print the name of register X to FILE based on its machine mode and number.
15160    If CODE is 'w', pretend the mode is HImode.
15161    If CODE is 'b', pretend the mode is QImode.
15162    If CODE is 'k', pretend the mode is SImode.
15163    If CODE is 'q', pretend the mode is DImode.
15164    If CODE is 'x', pretend the mode is V4SFmode.
15165    If CODE is 't', pretend the mode is V8SFmode.
15166    If CODE is 'g', pretend the mode is V16SFmode.
15167    If CODE is 'h', pretend the reg is the 'high' byte register.
15168    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
15169    If CODE is 'd', duplicate the operand for AVX instruction.
15170  */
15171
15172 void
15173 print_reg (rtx x, int code, FILE *file)
15174 {
15175   const char *reg;
15176   int msize;
15177   unsigned int regno;
15178   bool duplicated;
15179
15180   if (ASSEMBLER_DIALECT == ASM_ATT)
15181     putc ('%', file);
15182
15183   if (x == pc_rtx)
15184     {
15185       gcc_assert (TARGET_64BIT);
15186       fputs ("rip", file);
15187       return;
15188     }
15189
15190   if (code == 'y' && STACK_TOP_P (x))
15191     {
15192       fputs ("st(0)", file);
15193       return;
15194     }
15195
15196   if (code == 'w')
15197     msize = 2;
15198   else if (code == 'b')
15199     msize = 1;
15200   else if (code == 'k')
15201     msize = 4;
15202   else if (code == 'q')
15203     msize = 8;
15204   else if (code == 'h')
15205     msize = 0;
15206   else if (code == 'x')
15207     msize = 16;
15208   else if (code == 't')
15209     msize = 32;
15210   else if (code == 'g')
15211     msize = 64;
15212   else
15213     msize = GET_MODE_SIZE (GET_MODE (x));
15214
15215   regno = true_regnum (x);
15216
15217   gcc_assert (regno != ARG_POINTER_REGNUM
15218               && regno != FRAME_POINTER_REGNUM
15219               && regno != FLAGS_REG
15220               && regno != FPSR_REG
15221               && regno != FPCR_REG);
15222
15223   duplicated = code == 'd' && TARGET_AVX;
15224
15225   switch (msize)
15226     {
15227     case 8:
15228     case 4:
15229       if (LEGACY_INT_REGNO_P (regno))
15230         putc (msize == 8 && TARGET_64BIT ? 'r' : 'e', file);
15231     case 16:
15232     case 12:
15233     case 2:
15234     normal:
15235       reg = hi_reg_name[regno];
15236       break;
15237     case 1:
15238       if (regno >= ARRAY_SIZE (qi_reg_name))
15239         goto normal;
15240       reg = qi_reg_name[regno];
15241       break;
15242     case 0:
15243       if (regno >= ARRAY_SIZE (qi_high_reg_name))
15244         goto normal;
15245       reg = qi_high_reg_name[regno];
15246       break;
15247     case 32:
15248     case 64:
15249       if (SSE_REGNO_P (regno))
15250         {
15251           gcc_assert (!duplicated);
15252           putc (msize == 32 ? 'y' : 'z', file);
15253           reg = hi_reg_name[regno] + 1;
15254           break;
15255         }
15256       goto normal;
15257     default:
15258       gcc_unreachable ();
15259     }
15260
15261   fputs (reg, file);
15262
15263   /* Irritatingly, AMD extended registers use
15264      different naming convention: "r%d[bwd]"  */
15265   if (REX_INT_REGNO_P (regno))
15266     {
15267       gcc_assert (TARGET_64BIT);
15268       switch (msize)
15269         {
15270           case 0:
15271             error ("extended registers have no high halves");
15272             break;
15273           case 1:
15274             putc ('b', file);
15275             break;
15276           case 2:
15277             putc ('w', file);
15278             break;
15279           case 4:
15280             putc ('d', file);
15281             break;
15282           case 8:
15283             /* no suffix */
15284             break;
15285           default:
15286             error ("unsupported operand size for extended register");
15287             break;
15288         }
15289       return;
15290     }
15291
15292   if (duplicated)
15293     {
15294       if (ASSEMBLER_DIALECT == ASM_ATT)
15295         fprintf (file, ", %%%s", reg);
15296       else
15297         fprintf (file, ", %s", reg);
15298     }
15299 }
15300
15301 /* Meaning of CODE:
15302    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
15303    C -- print opcode suffix for set/cmov insn.
15304    c -- like C, but print reversed condition
15305    F,f -- likewise, but for floating-point.
15306    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
15307         otherwise nothing
15308    R -- print embeded rounding and sae.
15309    r -- print only sae.
15310    z -- print the opcode suffix for the size of the current operand.
15311    Z -- likewise, with special suffixes for x87 instructions.
15312    * -- print a star (in certain assembler syntax)
15313    A -- print an absolute memory reference.
15314    E -- print address with DImode register names if TARGET_64BIT.
15315    w -- print the operand as if it's a "word" (HImode) even if it isn't.
15316    s -- print a shift double count, followed by the assemblers argument
15317         delimiter.
15318    b -- print the QImode name of the register for the indicated operand.
15319         %b0 would print %al if operands[0] is reg 0.
15320    w --  likewise, print the HImode name of the register.
15321    k --  likewise, print the SImode name of the register.
15322    q --  likewise, print the DImode name of the register.
15323    x --  likewise, print the V4SFmode name of the register.
15324    t --  likewise, print the V8SFmode name of the register.
15325    g --  likewise, print the V16SFmode name of the register.
15326    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
15327    y -- print "st(0)" instead of "st" as a register.
15328    d -- print duplicated register operand for AVX instruction.
15329    D -- print condition for SSE cmp instruction.
15330    P -- if PIC, print an @PLT suffix.
15331    p -- print raw symbol name.
15332    X -- don't print any sort of PIC '@' suffix for a symbol.
15333    & -- print some in-use local-dynamic symbol name.
15334    H -- print a memory address offset by 8; used for sse high-parts
15335    Y -- print condition for XOP pcom* instruction.
15336    + -- print a branch hint as 'cs' or 'ds' prefix
15337    ; -- print a semicolon (after prefixes due to bug in older gas).
15338    ~ -- print "i" if TARGET_AVX2, "f" otherwise.
15339    @ -- print a segment register of thread base pointer load
15340    ^ -- print addr32 prefix if TARGET_64BIT and Pmode != word_mode
15341    ! -- print MPX prefix for jxx/call/ret instructions if required.
15342  */
15343
15344 void
15345 ix86_print_operand (FILE *file, rtx x, int code)
15346 {
15347   if (code)
15348     {
15349       switch (code)
15350         {
15351         case 'A':
15352           switch (ASSEMBLER_DIALECT)
15353             {
15354             case ASM_ATT:
15355               putc ('*', file);
15356               break;
15357
15358             case ASM_INTEL:
15359               /* Intel syntax. For absolute addresses, registers should not
15360                  be surrounded by braces.  */
15361               if (!REG_P (x))
15362                 {
15363                   putc ('[', file);
15364                   ix86_print_operand (file, x, 0);
15365                   putc (']', file);
15366                   return;
15367                 }
15368               break;
15369
15370             default:
15371               gcc_unreachable ();
15372             }
15373
15374           ix86_print_operand (file, x, 0);
15375           return;
15376
15377         case 'E':
15378           /* Wrap address in an UNSPEC to declare special handling.  */
15379           if (TARGET_64BIT)
15380             x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR);
15381
15382           output_address (x);
15383           return;
15384
15385         case 'L':
15386           if (ASSEMBLER_DIALECT == ASM_ATT)
15387             putc ('l', file);
15388           return;
15389
15390         case 'W':
15391           if (ASSEMBLER_DIALECT == ASM_ATT)
15392             putc ('w', file);
15393           return;
15394
15395         case 'B':
15396           if (ASSEMBLER_DIALECT == ASM_ATT)
15397             putc ('b', file);
15398           return;
15399
15400         case 'Q':
15401           if (ASSEMBLER_DIALECT == ASM_ATT)
15402             putc ('l', file);
15403           return;
15404
15405         case 'S':
15406           if (ASSEMBLER_DIALECT == ASM_ATT)
15407             putc ('s', file);
15408           return;
15409
15410         case 'T':
15411           if (ASSEMBLER_DIALECT == ASM_ATT)
15412             putc ('t', file);
15413           return;
15414
15415         case 'O':
15416 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
15417           if (ASSEMBLER_DIALECT != ASM_ATT)
15418             return;
15419
15420           switch (GET_MODE_SIZE (GET_MODE (x)))
15421             {
15422             case 2:
15423               putc ('w', file);
15424               break;
15425   
15426             case 4:
15427               putc ('l', file);
15428               break;
15429
15430             case 8:
15431               putc ('q', file);
15432               break;
15433
15434             default:
15435               output_operand_lossage
15436                 ("invalid operand size for operand code 'O'");
15437               return;
15438             }
15439
15440           putc ('.', file);
15441 #endif
15442           return;
15443
15444         case 'z':
15445           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
15446             {
15447               /* Opcodes don't get size suffixes if using Intel opcodes.  */
15448               if (ASSEMBLER_DIALECT == ASM_INTEL)
15449                 return;
15450
15451               switch (GET_MODE_SIZE (GET_MODE (x)))
15452                 {
15453                 case 1:
15454                   putc ('b', file);
15455                   return;
15456
15457                 case 2:
15458                   putc ('w', file);
15459                   return;
15460
15461                 case 4:
15462                   putc ('l', file);
15463                   return;
15464
15465                 case 8:
15466                   putc ('q', file);
15467                   return;
15468
15469                 default:
15470                   output_operand_lossage
15471                     ("invalid operand size for operand code 'z'");
15472                   return;
15473                 }
15474             }
15475
15476           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
15477             warning
15478               (0, "non-integer operand used with operand code 'z'");
15479           /* FALLTHRU */
15480
15481         case 'Z':
15482           /* 387 opcodes don't get size suffixes if using Intel opcodes.  */
15483           if (ASSEMBLER_DIALECT == ASM_INTEL)
15484             return;
15485
15486           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
15487             {
15488               switch (GET_MODE_SIZE (GET_MODE (x)))
15489                 {
15490                 case 2:
15491 #ifdef HAVE_AS_IX86_FILDS
15492                   putc ('s', file);
15493 #endif
15494                   return;
15495
15496                 case 4:
15497                   putc ('l', file);
15498                   return;
15499
15500                 case 8:
15501 #ifdef HAVE_AS_IX86_FILDQ
15502                   putc ('q', file);
15503 #else
15504                   fputs ("ll", file);
15505 #endif
15506                   return;
15507
15508                 default:
15509                   break;
15510                 }
15511             }
15512           else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
15513             {
15514               /* 387 opcodes don't get size suffixes
15515                  if the operands are registers.  */
15516               if (STACK_REG_P (x))
15517                 return;
15518
15519               switch (GET_MODE_SIZE (GET_MODE (x)))
15520                 {
15521                 case 4:
15522                   putc ('s', file);
15523                   return;
15524
15525                 case 8:
15526                   putc ('l', file);
15527                   return;
15528
15529                 case 12:
15530                 case 16:
15531                   putc ('t', file);
15532                   return;
15533
15534                 default:
15535                   break;
15536                 }
15537             }
15538           else
15539             {
15540               output_operand_lossage
15541                 ("invalid operand type used with operand code 'Z'");
15542               return;
15543             }
15544
15545           output_operand_lossage
15546             ("invalid operand size for operand code 'Z'");
15547           return;
15548
15549         case 'd':
15550         case 'b':
15551         case 'w':
15552         case 'k':
15553         case 'q':
15554         case 'h':
15555         case 't':
15556         case 'g':
15557         case 'y':
15558         case 'x':
15559         case 'X':
15560         case 'P':
15561         case 'p':
15562           break;
15563
15564         case 's':
15565           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
15566             {
15567               ix86_print_operand (file, x, 0);
15568               fputs (", ", file);
15569             }
15570           return;
15571
15572         case 'Y':
15573           switch (GET_CODE (x))
15574             {
15575             case NE:
15576               fputs ("neq", file);
15577               break;
15578             case EQ:
15579               fputs ("eq", file);
15580               break;
15581             case GE:
15582             case GEU:
15583               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
15584               break;
15585             case GT:
15586             case GTU:
15587               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
15588               break;
15589             case LE:
15590             case LEU:
15591               fputs ("le", file);
15592               break;
15593             case LT:
15594             case LTU:
15595               fputs ("lt", file);
15596               break;
15597             case UNORDERED:
15598               fputs ("unord", file);
15599               break;
15600             case ORDERED:
15601               fputs ("ord", file);
15602               break;
15603             case UNEQ:
15604               fputs ("ueq", file);
15605               break;
15606             case UNGE:
15607               fputs ("nlt", file);
15608               break;
15609             case UNGT:
15610               fputs ("nle", file);
15611               break;
15612             case UNLE:
15613               fputs ("ule", file);
15614               break;
15615             case UNLT:
15616               fputs ("ult", file);
15617               break;
15618             case LTGT:
15619               fputs ("une", file);
15620               break;
15621             default:
15622               output_operand_lossage ("operand is not a condition code, "
15623                                       "invalid operand code 'Y'");
15624               return;
15625             }
15626           return;
15627
15628         case 'D':
15629           /* Little bit of braindamage here.  The SSE compare instructions
15630              does use completely different names for the comparisons that the
15631              fp conditional moves.  */
15632           switch (GET_CODE (x))
15633             {
15634             case UNEQ:
15635               if (TARGET_AVX)
15636                 {
15637                   fputs ("eq_us", file);
15638                   break;
15639                 }
15640             case EQ:
15641               fputs ("eq", file);
15642               break;
15643             case UNLT:
15644               if (TARGET_AVX)
15645                 {
15646                   fputs ("nge", file);
15647                   break;
15648                 }
15649             case LT:
15650               fputs ("lt", file);
15651               break;
15652             case UNLE:
15653               if (TARGET_AVX)
15654                 {
15655                   fputs ("ngt", file);
15656                   break;
15657                 }
15658             case LE:
15659               fputs ("le", file);
15660               break;
15661             case UNORDERED:
15662               fputs ("unord", file);
15663               break;
15664             case LTGT:
15665               if (TARGET_AVX)
15666                 {
15667                   fputs ("neq_oq", file);
15668                   break;
15669                 }
15670             case NE:
15671               fputs ("neq", file);
15672               break;
15673             case GE:
15674               if (TARGET_AVX)
15675                 {
15676                   fputs ("ge", file);
15677                   break;
15678                 }
15679             case UNGE:
15680               fputs ("nlt", file);
15681               break;
15682             case GT:
15683               if (TARGET_AVX)
15684                 {
15685                   fputs ("gt", file);
15686                   break;
15687                 }
15688             case UNGT:
15689               fputs ("nle", file);
15690               break;
15691             case ORDERED:
15692               fputs ("ord", file);
15693               break;
15694             default:
15695               output_operand_lossage ("operand is not a condition code, "
15696                                       "invalid operand code 'D'");
15697               return;
15698             }
15699           return;
15700
15701         case 'F':
15702         case 'f':
15703 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
15704           if (ASSEMBLER_DIALECT == ASM_ATT)
15705             putc ('.', file);
15706 #endif
15707
15708         case 'C':
15709         case 'c':
15710           if (!COMPARISON_P (x))
15711             {
15712               output_operand_lossage ("operand is not a condition code, "
15713                                       "invalid operand code '%c'", code);
15714               return;
15715             }
15716           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
15717                               code == 'c' || code == 'f',
15718                               code == 'F' || code == 'f',
15719                               file);
15720           return;
15721
15722         case 'H':
15723           if (!offsettable_memref_p (x))
15724             {
15725               output_operand_lossage ("operand is not an offsettable memory "
15726                                       "reference, invalid operand code 'H'");
15727               return;
15728             }
15729           /* It doesn't actually matter what mode we use here, as we're
15730              only going to use this for printing.  */
15731           x = adjust_address_nv (x, DImode, 8);
15732           /* Output 'qword ptr' for intel assembler dialect.  */
15733           if (ASSEMBLER_DIALECT == ASM_INTEL)
15734             code = 'q';
15735           break;
15736
15737         case 'K':
15738           gcc_assert (CONST_INT_P (x));
15739
15740           if (INTVAL (x) & IX86_HLE_ACQUIRE)
15741 #ifdef HAVE_AS_IX86_HLE
15742             fputs ("xacquire ", file);
15743 #else
15744             fputs ("\n" ASM_BYTE "0xf2\n\t", file);
15745 #endif
15746           else if (INTVAL (x) & IX86_HLE_RELEASE)
15747 #ifdef HAVE_AS_IX86_HLE
15748             fputs ("xrelease ", file);
15749 #else
15750             fputs ("\n" ASM_BYTE "0xf3\n\t", file);
15751 #endif
15752           /* We do not want to print value of the operand.  */
15753           return;
15754
15755         case 'N':
15756           if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
15757             fputs ("{z}", file);
15758           return;
15759
15760         case 'r':
15761           gcc_assert (CONST_INT_P (x));
15762           gcc_assert (INTVAL (x) == ROUND_SAE);
15763
15764           if (ASSEMBLER_DIALECT == ASM_INTEL)
15765             fputs (", ", file);
15766
15767           fputs ("{sae}", file);
15768
15769           if (ASSEMBLER_DIALECT == ASM_ATT)
15770             fputs (", ", file);
15771
15772           return;
15773
15774         case 'R':
15775           gcc_assert (CONST_INT_P (x));
15776
15777           if (ASSEMBLER_DIALECT == ASM_INTEL)
15778             fputs (", ", file);
15779
15780           switch (INTVAL (x))
15781             {
15782             case ROUND_NEAREST_INT | ROUND_SAE:
15783               fputs ("{rn-sae}", file);
15784               break;
15785             case ROUND_NEG_INF | ROUND_SAE:
15786               fputs ("{rd-sae}", file);
15787               break;
15788             case ROUND_POS_INF | ROUND_SAE:
15789               fputs ("{ru-sae}", file);
15790               break;
15791             case ROUND_ZERO | ROUND_SAE:
15792               fputs ("{rz-sae}", file);
15793               break;
15794             default:
15795               gcc_unreachable ();
15796             }
15797
15798           if (ASSEMBLER_DIALECT == ASM_ATT)
15799             fputs (", ", file);
15800
15801           return;
15802
15803         case '*':
15804           if (ASSEMBLER_DIALECT == ASM_ATT)
15805             putc ('*', file);
15806           return;
15807
15808         case '&':
15809           {
15810             const char *name = get_some_local_dynamic_name ();
15811             if (name == NULL)
15812               output_operand_lossage ("'%%&' used without any "
15813                                       "local dynamic TLS references");
15814             else
15815               assemble_name (file, name);
15816             return;
15817           }
15818
15819         case '+':
15820           {
15821             rtx x;
15822
15823             if (!optimize
15824                 || optimize_function_for_size_p (cfun)
15825                 || !TARGET_BRANCH_PREDICTION_HINTS)
15826               return;
15827
15828             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
15829             if (x)
15830               {
15831                 int pred_val = XINT (x, 0);
15832
15833                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
15834                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
15835                   {
15836                     bool taken = pred_val > REG_BR_PROB_BASE / 2;
15837                     bool cputaken
15838                       = final_forward_branch_p (current_output_insn) == 0;
15839
15840                     /* Emit hints only in the case default branch prediction
15841                        heuristics would fail.  */
15842                     if (taken != cputaken)
15843                       {
15844                         /* We use 3e (DS) prefix for taken branches and
15845                            2e (CS) prefix for not taken branches.  */
15846                         if (taken)
15847                           fputs ("ds ; ", file);
15848                         else
15849                           fputs ("cs ; ", file);
15850                       }
15851                   }
15852               }
15853             return;
15854           }
15855
15856         case ';':
15857 #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
15858           putc (';', file);
15859 #endif
15860           return;
15861
15862         case '@':
15863           if (ASSEMBLER_DIALECT == ASM_ATT)
15864             putc ('%', file);
15865
15866           /* The kernel uses a different segment register for performance
15867              reasons; a system call would not have to trash the userspace
15868              segment register, which would be expensive.  */
15869           if (TARGET_64BIT && ix86_cmodel != CM_KERNEL)
15870             fputs ("fs", file);
15871           else
15872             fputs ("gs", file);
15873           return;
15874
15875         case '~':
15876           putc (TARGET_AVX2 ? 'i' : 'f', file);
15877           return;
15878
15879         case '^':
15880           if (TARGET_64BIT && Pmode != word_mode)
15881             fputs ("addr32 ", file);
15882           return;
15883
15884         case '!':
15885           if (ix86_bnd_prefixed_insn_p (current_output_insn))
15886             fputs ("bnd ", file);
15887           return;
15888
15889         default:
15890             output_operand_lossage ("invalid operand code '%c'", code);
15891         }
15892     }
15893
15894   if (REG_P (x))
15895     print_reg (x, code, file);
15896
15897   else if (MEM_P (x))
15898     {
15899       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
15900       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
15901           && GET_MODE (x) != BLKmode)
15902         {
15903           const char * size;
15904           switch (GET_MODE_SIZE (GET_MODE (x)))
15905             {
15906             case 1: size = "BYTE"; break;
15907             case 2: size = "WORD"; break;
15908             case 4: size = "DWORD"; break;
15909             case 8: size = "QWORD"; break;
15910             case 12: size = "TBYTE"; break;
15911             case 16:
15912               if (GET_MODE (x) == XFmode)
15913                 size = "TBYTE";
15914               else
15915                 size = "XMMWORD";
15916               break;
15917             case 32: size = "YMMWORD"; break;
15918             case 64: size = "ZMMWORD"; break;
15919             default:
15920               gcc_unreachable ();
15921             }
15922
15923           /* Check for explicit size override (codes 'b', 'w', 'k',
15924              'q' and 'x')  */
15925           if (code == 'b')
15926             size = "BYTE";
15927           else if (code == 'w')
15928             size = "WORD";
15929           else if (code == 'k')
15930             size = "DWORD";
15931           else if (code == 'q')
15932             size = "QWORD";
15933           else if (code == 'x')
15934             size = "XMMWORD";
15935
15936           fputs (size, file);
15937           fputs (" PTR ", file);
15938         }
15939
15940       x = XEXP (x, 0);
15941       /* Avoid (%rip) for call operands.  */
15942       if (CONSTANT_ADDRESS_P (x) && code == 'P'
15943           && !CONST_INT_P (x))
15944         output_addr_const (file, x);
15945       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
15946         output_operand_lossage ("invalid constraints for operand");
15947       else
15948         output_address (x);
15949     }
15950
15951   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode)
15952     {
15953       REAL_VALUE_TYPE r;
15954       long l;
15955
15956       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
15957       REAL_VALUE_TO_TARGET_SINGLE (r, l);
15958
15959       if (ASSEMBLER_DIALECT == ASM_ATT)
15960         putc ('$', file);
15961       /* Sign extend 32bit SFmode immediate to 8 bytes.  */
15962       if (code == 'q')
15963         fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x",
15964                  (unsigned long long) (int) l);
15965       else
15966         fprintf (file, "0x%08x", (unsigned int) l);
15967     }
15968
15969   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == DFmode)
15970     {
15971       REAL_VALUE_TYPE r;
15972       long l[2];
15973
15974       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
15975       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15976
15977       if (ASSEMBLER_DIALECT == ASM_ATT)
15978         putc ('$', file);
15979       fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff);
15980     }
15981
15982   /* These float cases don't actually occur as immediate operands.  */
15983   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == XFmode)
15984     {
15985       char dstr[30];
15986
15987       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
15988       fputs (dstr, file);
15989     }
15990
15991   else
15992     {
15993       /* We have patterns that allow zero sets of memory, for instance.
15994          In 64-bit mode, we should probably support all 8-byte vectors,
15995          since we can in fact encode that into an immediate.  */
15996       if (GET_CODE (x) == CONST_VECTOR)
15997         {
15998           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
15999           x = const0_rtx;
16000         }
16001
16002       if (code != 'P' && code != 'p')
16003         {
16004           if (CONST_INT_P (x))
16005             {
16006               if (ASSEMBLER_DIALECT == ASM_ATT)
16007                 putc ('$', file);
16008             }
16009           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
16010                    || GET_CODE (x) == LABEL_REF)
16011             {
16012               if (ASSEMBLER_DIALECT == ASM_ATT)
16013                 putc ('$', file);
16014               else
16015                 fputs ("OFFSET FLAT:", file);
16016             }
16017         }
16018       if (CONST_INT_P (x))
16019         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
16020       else if (flag_pic || MACHOPIC_INDIRECT)
16021         output_pic_addr_const (file, x, code);
16022       else
16023         output_addr_const (file, x);
16024     }
16025 }
16026
16027 static bool
16028 ix86_print_operand_punct_valid_p (unsigned char code)
16029 {
16030   return (code == '@' || code == '*' || code == '+' || code == '&'
16031           || code == ';' || code == '~' || code == '^' || code == '!');
16032 }
16033 \f
16034 /* Print a memory operand whose address is ADDR.  */
16035
16036 static void
16037 ix86_print_operand_address (FILE *file, rtx addr)
16038 {
16039   struct ix86_address parts;
16040   rtx base, index, disp;
16041   int scale;
16042   int ok;
16043   bool vsib = false;
16044   int code = 0;
16045
16046   if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR)
16047     {
16048       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
16049       gcc_assert (parts.index == NULL_RTX);
16050       parts.index = XVECEXP (addr, 0, 1);
16051       parts.scale = INTVAL (XVECEXP (addr, 0, 2));
16052       addr = XVECEXP (addr, 0, 0);
16053       vsib = true;
16054     }
16055   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR)
16056     {
16057       gcc_assert (TARGET_64BIT);
16058       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
16059       code = 'q';
16060     }
16061   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_BNDMK_ADDR)
16062     {
16063       ok = ix86_decompose_address (XVECEXP (addr, 0, 1), &parts);
16064       gcc_assert (parts.base == NULL_RTX || parts.index == NULL_RTX);
16065       if (parts.base != NULL_RTX)
16066         {
16067           parts.index = parts.base;
16068           parts.scale = 1;
16069         }
16070       parts.base = XVECEXP (addr, 0, 0);
16071       addr = XVECEXP (addr, 0, 0);
16072     }
16073   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_BNDLDX_ADDR)
16074     {
16075       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
16076       gcc_assert (parts.index == NULL_RTX);
16077       parts.index = XVECEXP (addr, 0, 1);
16078       addr = XVECEXP (addr, 0, 0);
16079     }
16080   else
16081     ok = ix86_decompose_address (addr, &parts);
16082
16083   gcc_assert (ok);
16084
16085   base = parts.base;
16086   index = parts.index;
16087   disp = parts.disp;
16088   scale = parts.scale;
16089
16090   switch (parts.seg)
16091     {
16092     case SEG_DEFAULT:
16093       break;
16094     case SEG_FS:
16095     case SEG_GS:
16096       if (ASSEMBLER_DIALECT == ASM_ATT)
16097         putc ('%', file);
16098       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
16099       break;
16100     default:
16101       gcc_unreachable ();
16102     }
16103
16104   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
16105   if (TARGET_64BIT && !base && !index)
16106     {
16107       rtx symbol = disp;
16108
16109       if (GET_CODE (disp) == CONST
16110           && GET_CODE (XEXP (disp, 0)) == PLUS
16111           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
16112         symbol = XEXP (XEXP (disp, 0), 0);
16113
16114       if (GET_CODE (symbol) == LABEL_REF
16115           || (GET_CODE (symbol) == SYMBOL_REF
16116               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
16117         base = pc_rtx;
16118     }
16119   if (!base && !index)
16120     {
16121       /* Displacement only requires special attention.  */
16122
16123       if (CONST_INT_P (disp))
16124         {
16125           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
16126             fputs ("ds:", file);
16127           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
16128         }
16129       else if (flag_pic)
16130         output_pic_addr_const (file, disp, 0);
16131       else
16132         output_addr_const (file, disp);
16133     }
16134   else
16135     {
16136       /* Print SImode register names to force addr32 prefix.  */
16137       if (SImode_address_operand (addr, VOIDmode))
16138         {
16139 #ifdef ENABLE_CHECKING
16140           gcc_assert (TARGET_64BIT);
16141           switch (GET_CODE (addr))
16142             {
16143             case SUBREG:
16144               gcc_assert (GET_MODE (addr) == SImode);
16145               gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode);
16146               break;
16147             case ZERO_EXTEND:
16148             case AND:
16149               gcc_assert (GET_MODE (addr) == DImode);
16150               break;
16151             default:
16152               gcc_unreachable ();
16153             }
16154 #endif
16155           gcc_assert (!code);
16156           code = 'k';
16157         }
16158       else if (code == 0
16159                && TARGET_X32
16160                && disp
16161                && CONST_INT_P (disp)
16162                && INTVAL (disp) < -16*1024*1024)
16163         {
16164           /* X32 runs in 64-bit mode, where displacement, DISP, in
16165              address DISP(%r64), is encoded as 32-bit immediate sign-
16166              extended from 32-bit to 64-bit.  For -0x40000300(%r64),
16167              address is %r64 + 0xffffffffbffffd00.  When %r64 <
16168              0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64,
16169              which is invalid for x32.  The correct address is %r64
16170              - 0x40000300 == 0xf7ffdd64.  To properly encode
16171              -0x40000300(%r64) for x32, we zero-extend negative
16172              displacement by forcing addr32 prefix which truncates
16173              0xfffffffff7ffdd64 to 0xf7ffdd64.  In theory, we should
16174              zero-extend all negative displacements, including -1(%rsp).
16175              However, for small negative displacements, sign-extension
16176              won't cause overflow.  We only zero-extend negative
16177              displacements if they < -16*1024*1024, which is also used
16178              to check legitimate address displacements for PIC.  */
16179           code = 'k';
16180         }
16181
16182       if (ASSEMBLER_DIALECT == ASM_ATT)
16183         {
16184           if (disp)
16185             {
16186               if (flag_pic)
16187                 output_pic_addr_const (file, disp, 0);
16188               else if (GET_CODE (disp) == LABEL_REF)
16189                 output_asm_label (disp);
16190               else
16191                 output_addr_const (file, disp);
16192             }
16193
16194           putc ('(', file);
16195           if (base)
16196             print_reg (base, code, file);
16197           if (index)
16198             {
16199               putc (',', file);
16200               print_reg (index, vsib ? 0 : code, file);
16201               if (scale != 1 || vsib)
16202                 fprintf (file, ",%d", scale);
16203             }
16204           putc (')', file);
16205         }
16206       else
16207         {
16208           rtx offset = NULL_RTX;
16209
16210           if (disp)
16211             {
16212               /* Pull out the offset of a symbol; print any symbol itself.  */
16213               if (GET_CODE (disp) == CONST
16214                   && GET_CODE (XEXP (disp, 0)) == PLUS
16215                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
16216                 {
16217                   offset = XEXP (XEXP (disp, 0), 1);
16218                   disp = gen_rtx_CONST (VOIDmode,
16219                                         XEXP (XEXP (disp, 0), 0));
16220                 }
16221
16222               if (flag_pic)
16223                 output_pic_addr_const (file, disp, 0);
16224               else if (GET_CODE (disp) == LABEL_REF)
16225                 output_asm_label (disp);
16226               else if (CONST_INT_P (disp))
16227                 offset = disp;
16228               else
16229                 output_addr_const (file, disp);
16230             }
16231
16232           putc ('[', file);
16233           if (base)
16234             {
16235               print_reg (base, code, file);
16236               if (offset)
16237                 {
16238                   if (INTVAL (offset) >= 0)
16239                     putc ('+', file);
16240                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
16241                 }
16242             }
16243           else if (offset)
16244             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
16245           else
16246             putc ('0', file);
16247
16248           if (index)
16249             {
16250               putc ('+', file);
16251               print_reg (index, vsib ? 0 : code, file);
16252               if (scale != 1 || vsib)
16253                 fprintf (file, "*%d", scale);
16254             }
16255           putc (']', file);
16256         }
16257     }
16258 }
16259
16260 /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
16261
16262 static bool
16263 i386_asm_output_addr_const_extra (FILE *file, rtx x)
16264 {
16265   rtx op;
16266
16267   if (GET_CODE (x) != UNSPEC)
16268     return false;
16269
16270   op = XVECEXP (x, 0, 0);
16271   switch (XINT (x, 1))
16272     {
16273     case UNSPEC_GOTTPOFF:
16274       output_addr_const (file, op);
16275       /* FIXME: This might be @TPOFF in Sun ld.  */
16276       fputs ("@gottpoff", file);
16277       break;
16278     case UNSPEC_TPOFF:
16279       output_addr_const (file, op);
16280       fputs ("@tpoff", file);
16281       break;
16282     case UNSPEC_NTPOFF:
16283       output_addr_const (file, op);
16284       if (TARGET_64BIT)
16285         fputs ("@tpoff", file);
16286       else
16287         fputs ("@ntpoff", file);
16288       break;
16289     case UNSPEC_DTPOFF:
16290       output_addr_const (file, op);
16291       fputs ("@dtpoff", file);
16292       break;
16293     case UNSPEC_GOTNTPOFF:
16294       output_addr_const (file, op);
16295       if (TARGET_64BIT)
16296         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
16297                "@gottpoff(%rip)" : "@gottpoff[rip]", file);
16298       else
16299         fputs ("@gotntpoff", file);
16300       break;
16301     case UNSPEC_INDNTPOFF:
16302       output_addr_const (file, op);
16303       fputs ("@indntpoff", file);
16304       break;
16305 #if TARGET_MACHO
16306     case UNSPEC_MACHOPIC_OFFSET:
16307       output_addr_const (file, op);
16308       putc ('-', file);
16309       machopic_output_function_base_name (file);
16310       break;
16311 #endif
16312
16313     case UNSPEC_STACK_CHECK:
16314       {
16315         int offset;
16316
16317         gcc_assert (flag_split_stack);
16318
16319 #ifdef TARGET_THREAD_SPLIT_STACK_OFFSET
16320         offset = TARGET_THREAD_SPLIT_STACK_OFFSET;
16321 #else
16322         gcc_unreachable ();
16323 #endif
16324
16325         fprintf (file, "%s:%d", TARGET_64BIT ? "%fs" : "%gs", offset);
16326       }
16327       break;
16328
16329     default:
16330       return false;
16331     }
16332
16333   return true;
16334 }
16335 \f
16336 /* Split one or more double-mode RTL references into pairs of half-mode
16337    references.  The RTL can be REG, offsettable MEM, integer constant, or
16338    CONST_DOUBLE.  "operands" is a pointer to an array of double-mode RTLs to
16339    split and "num" is its length.  lo_half and hi_half are output arrays
16340    that parallel "operands".  */
16341
16342 void
16343 split_double_mode (machine_mode mode, rtx operands[],
16344                    int num, rtx lo_half[], rtx hi_half[])
16345 {
16346   machine_mode half_mode;
16347   unsigned int byte;
16348
16349   switch (mode)
16350     {
16351     case TImode:
16352       half_mode = DImode;
16353       break;
16354     case DImode:
16355       half_mode = SImode;
16356       break;
16357     default:
16358       gcc_unreachable ();
16359     }
16360
16361   byte = GET_MODE_SIZE (half_mode);
16362
16363   while (num--)
16364     {
16365       rtx op = operands[num];
16366
16367       /* simplify_subreg refuse to split volatile memory addresses,
16368          but we still have to handle it.  */
16369       if (MEM_P (op))
16370         {
16371           lo_half[num] = adjust_address (op, half_mode, 0);
16372           hi_half[num] = adjust_address (op, half_mode, byte);
16373         }
16374       else
16375         {
16376           lo_half[num] = simplify_gen_subreg (half_mode, op,
16377                                               GET_MODE (op) == VOIDmode
16378                                               ? mode : GET_MODE (op), 0);
16379           hi_half[num] = simplify_gen_subreg (half_mode, op,
16380                                               GET_MODE (op) == VOIDmode
16381                                               ? mode : GET_MODE (op), byte);
16382         }
16383     }
16384 }
16385 \f
16386 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
16387    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
16388    is the expression of the binary operation.  The output may either be
16389    emitted here, or returned to the caller, like all output_* functions.
16390
16391    There is no guarantee that the operands are the same mode, as they
16392    might be within FLOAT or FLOAT_EXTEND expressions.  */
16393
16394 #ifndef SYSV386_COMPAT
16395 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
16396    wants to fix the assemblers because that causes incompatibility
16397    with gcc.  No-one wants to fix gcc because that causes
16398    incompatibility with assemblers...  You can use the option of
16399    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
16400 #define SYSV386_COMPAT 1
16401 #endif
16402
16403 const char *
16404 output_387_binary_op (rtx insn, rtx *operands)
16405 {
16406   static char buf[40];
16407   const char *p;
16408   const char *ssep;
16409   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
16410
16411 #ifdef ENABLE_CHECKING
16412   /* Even if we do not want to check the inputs, this documents input
16413      constraints.  Which helps in understanding the following code.  */
16414   if (STACK_REG_P (operands[0])
16415       && ((REG_P (operands[1])
16416            && REGNO (operands[0]) == REGNO (operands[1])
16417            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
16418           || (REG_P (operands[2])
16419               && REGNO (operands[0]) == REGNO (operands[2])
16420               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
16421       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
16422     ; /* ok */
16423   else
16424     gcc_assert (is_sse);
16425 #endif
16426
16427   switch (GET_CODE (operands[3]))
16428     {
16429     case PLUS:
16430       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16431           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16432         p = "fiadd";
16433       else
16434         p = "fadd";
16435       ssep = "vadd";
16436       break;
16437
16438     case MINUS:
16439       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16440           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16441         p = "fisub";
16442       else
16443         p = "fsub";
16444       ssep = "vsub";
16445       break;
16446
16447     case MULT:
16448       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16449           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16450         p = "fimul";
16451       else
16452         p = "fmul";
16453       ssep = "vmul";
16454       break;
16455
16456     case DIV:
16457       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16458           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16459         p = "fidiv";
16460       else
16461         p = "fdiv";
16462       ssep = "vdiv";
16463       break;
16464
16465     default:
16466       gcc_unreachable ();
16467     }
16468
16469   if (is_sse)
16470    {
16471      if (TARGET_AVX)
16472        {
16473          strcpy (buf, ssep);
16474          if (GET_MODE (operands[0]) == SFmode)
16475            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
16476          else
16477            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
16478        }
16479      else
16480        {
16481          strcpy (buf, ssep + 1);
16482          if (GET_MODE (operands[0]) == SFmode)
16483            strcat (buf, "ss\t{%2, %0|%0, %2}");
16484          else
16485            strcat (buf, "sd\t{%2, %0|%0, %2}");
16486        }
16487       return buf;
16488    }
16489   strcpy (buf, p);
16490
16491   switch (GET_CODE (operands[3]))
16492     {
16493     case MULT:
16494     case PLUS:
16495       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
16496         std::swap (operands[1], operands[2]);
16497
16498       /* know operands[0] == operands[1].  */
16499
16500       if (MEM_P (operands[2]))
16501         {
16502           p = "%Z2\t%2";
16503           break;
16504         }
16505
16506       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
16507         {
16508           if (STACK_TOP_P (operands[0]))
16509             /* How is it that we are storing to a dead operand[2]?
16510                Well, presumably operands[1] is dead too.  We can't
16511                store the result to st(0) as st(0) gets popped on this
16512                instruction.  Instead store to operands[2] (which I
16513                think has to be st(1)).  st(1) will be popped later.
16514                gcc <= 2.8.1 didn't have this check and generated
16515                assembly code that the Unixware assembler rejected.  */
16516             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
16517           else
16518             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
16519           break;
16520         }
16521
16522       if (STACK_TOP_P (operands[0]))
16523         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
16524       else
16525         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
16526       break;
16527
16528     case MINUS:
16529     case DIV:
16530       if (MEM_P (operands[1]))
16531         {
16532           p = "r%Z1\t%1";
16533           break;
16534         }
16535
16536       if (MEM_P (operands[2]))
16537         {
16538           p = "%Z2\t%2";
16539           break;
16540         }
16541
16542       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
16543         {
16544 #if SYSV386_COMPAT
16545           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
16546              derived assemblers, confusingly reverse the direction of
16547              the operation for fsub{r} and fdiv{r} when the
16548              destination register is not st(0).  The Intel assembler
16549              doesn't have this brain damage.  Read !SYSV386_COMPAT to
16550              figure out what the hardware really does.  */
16551           if (STACK_TOP_P (operands[0]))
16552             p = "{p\t%0, %2|rp\t%2, %0}";
16553           else
16554             p = "{rp\t%2, %0|p\t%0, %2}";
16555 #else
16556           if (STACK_TOP_P (operands[0]))
16557             /* As above for fmul/fadd, we can't store to st(0).  */
16558             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
16559           else
16560             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
16561 #endif
16562           break;
16563         }
16564
16565       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
16566         {
16567 #if SYSV386_COMPAT
16568           if (STACK_TOP_P (operands[0]))
16569             p = "{rp\t%0, %1|p\t%1, %0}";
16570           else
16571             p = "{p\t%1, %0|rp\t%0, %1}";
16572 #else
16573           if (STACK_TOP_P (operands[0]))
16574             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
16575           else
16576             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
16577 #endif
16578           break;
16579         }
16580
16581       if (STACK_TOP_P (operands[0]))
16582         {
16583           if (STACK_TOP_P (operands[1]))
16584             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
16585           else
16586             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
16587           break;
16588         }
16589       else if (STACK_TOP_P (operands[1]))
16590         {
16591 #if SYSV386_COMPAT
16592           p = "{\t%1, %0|r\t%0, %1}";
16593 #else
16594           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
16595 #endif
16596         }
16597       else
16598         {
16599 #if SYSV386_COMPAT
16600           p = "{r\t%2, %0|\t%0, %2}";
16601 #else
16602           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
16603 #endif
16604         }
16605       break;
16606
16607     default:
16608       gcc_unreachable ();
16609     }
16610
16611   strcat (buf, p);
16612   return buf;
16613 }
16614
16615 /* Check if a 256bit AVX register is referenced inside of EXP.   */
16616
16617 static bool
16618 ix86_check_avx256_register (const_rtx exp)
16619 {
16620   if (GET_CODE (exp) == SUBREG)
16621     exp = SUBREG_REG (exp);
16622
16623   return (REG_P (exp)
16624           && VALID_AVX256_REG_OR_OI_MODE (GET_MODE (exp)));
16625 }
16626
16627 /* Return needed mode for entity in optimize_mode_switching pass.  */
16628
16629 static int
16630 ix86_avx_u128_mode_needed (rtx_insn *insn)
16631 {
16632   if (CALL_P (insn))
16633     {
16634       rtx link;
16635
16636       /* Needed mode is set to AVX_U128_CLEAN if there are
16637          no 256bit modes used in function arguments.  */
16638       for (link = CALL_INSN_FUNCTION_USAGE (insn);
16639            link;
16640            link = XEXP (link, 1))
16641         {
16642           if (GET_CODE (XEXP (link, 0)) == USE)
16643             {
16644               rtx arg = XEXP (XEXP (link, 0), 0);
16645
16646               if (ix86_check_avx256_register (arg))
16647                 return AVX_U128_DIRTY;
16648             }
16649         }
16650
16651       return AVX_U128_CLEAN;
16652     }
16653
16654   /* Require DIRTY mode if a 256bit AVX register is referenced.  Hardware
16655      changes state only when a 256bit register is written to, but we need
16656      to prevent the compiler from moving optimal insertion point above
16657      eventual read from 256bit register.  */
16658   subrtx_iterator::array_type array;
16659   FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
16660     if (ix86_check_avx256_register (*iter))
16661       return AVX_U128_DIRTY;
16662
16663   return AVX_U128_ANY;
16664 }
16665
16666 /* Return mode that i387 must be switched into
16667    prior to the execution of insn.  */
16668
16669 static int
16670 ix86_i387_mode_needed (int entity, rtx_insn *insn)
16671 {
16672   enum attr_i387_cw mode;
16673
16674   /* The mode UNINITIALIZED is used to store control word after a
16675      function call or ASM pattern.  The mode ANY specify that function
16676      has no requirements on the control word and make no changes in the
16677      bits we are interested in.  */
16678
16679   if (CALL_P (insn)
16680       || (NONJUMP_INSN_P (insn)
16681           && (asm_noperands (PATTERN (insn)) >= 0
16682               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
16683     return I387_CW_UNINITIALIZED;
16684
16685   if (recog_memoized (insn) < 0)
16686     return I387_CW_ANY;
16687
16688   mode = get_attr_i387_cw (insn);
16689
16690   switch (entity)
16691     {
16692     case I387_TRUNC:
16693       if (mode == I387_CW_TRUNC)
16694         return mode;
16695       break;
16696
16697     case I387_FLOOR:
16698       if (mode == I387_CW_FLOOR)
16699         return mode;
16700       break;
16701
16702     case I387_CEIL:
16703       if (mode == I387_CW_CEIL)
16704         return mode;
16705       break;
16706
16707     case I387_MASK_PM:
16708       if (mode == I387_CW_MASK_PM)
16709         return mode;
16710       break;
16711
16712     default:
16713       gcc_unreachable ();
16714     }
16715
16716   return I387_CW_ANY;
16717 }
16718
16719 /* Return mode that entity must be switched into
16720    prior to the execution of insn.  */
16721
16722 static int
16723 ix86_mode_needed (int entity, rtx_insn *insn)
16724 {
16725   switch (entity)
16726     {
16727     case AVX_U128:
16728       return ix86_avx_u128_mode_needed (insn);
16729     case I387_TRUNC:
16730     case I387_FLOOR:
16731     case I387_CEIL:
16732     case I387_MASK_PM:
16733       return ix86_i387_mode_needed (entity, insn);
16734     default:
16735       gcc_unreachable ();
16736     }
16737   return 0;
16738 }
16739
16740 /* Check if a 256bit AVX register is referenced in stores.   */
16741  
16742 static void
16743 ix86_check_avx256_stores (rtx dest, const_rtx, void *data)
16744  {
16745    if (ix86_check_avx256_register (dest))
16746     {
16747       bool *used = (bool *) data;
16748       *used = true;
16749     }
16750  } 
16751
16752 /* Calculate mode of upper 128bit AVX registers after the insn.  */
16753
16754 static int
16755 ix86_avx_u128_mode_after (int mode, rtx_insn *insn)
16756 {
16757   rtx pat = PATTERN (insn);
16758
16759   if (vzeroupper_operation (pat, VOIDmode)
16760       || vzeroall_operation (pat, VOIDmode))
16761     return AVX_U128_CLEAN;
16762
16763   /* We know that state is clean after CALL insn if there are no
16764      256bit registers used in the function return register.  */
16765   if (CALL_P (insn))
16766     {
16767       bool avx_reg256_found = false;
16768       note_stores (pat, ix86_check_avx256_stores, &avx_reg256_found);
16769
16770       return avx_reg256_found ? AVX_U128_DIRTY : AVX_U128_CLEAN;
16771     }
16772
16773   /* Otherwise, return current mode.  Remember that if insn
16774      references AVX 256bit registers, the mode was already changed
16775      to DIRTY from MODE_NEEDED.  */
16776   return mode;
16777 }
16778
16779 /* Return the mode that an insn results in.  */
16780
16781 static int
16782 ix86_mode_after (int entity, int mode, rtx_insn *insn)
16783 {
16784   switch (entity)
16785     {
16786     case AVX_U128:
16787       return ix86_avx_u128_mode_after (mode, insn);
16788     case I387_TRUNC:
16789     case I387_FLOOR:
16790     case I387_CEIL:
16791     case I387_MASK_PM:
16792       return mode;
16793     default:
16794       gcc_unreachable ();
16795     }
16796 }
16797
16798 static int
16799 ix86_avx_u128_mode_entry (void)
16800 {
16801   tree arg;
16802
16803   /* Entry mode is set to AVX_U128_DIRTY if there are
16804      256bit modes used in function arguments.  */
16805   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
16806        arg = TREE_CHAIN (arg))
16807     {
16808       rtx incoming = DECL_INCOMING_RTL (arg);
16809
16810       if (incoming && ix86_check_avx256_register (incoming))
16811         return AVX_U128_DIRTY;
16812     }
16813
16814   return AVX_U128_CLEAN;
16815 }
16816
16817 /* Return a mode that ENTITY is assumed to be
16818    switched to at function entry.  */
16819
16820 static int
16821 ix86_mode_entry (int entity)
16822 {
16823   switch (entity)
16824     {
16825     case AVX_U128:
16826       return ix86_avx_u128_mode_entry ();
16827     case I387_TRUNC:
16828     case I387_FLOOR:
16829     case I387_CEIL:
16830     case I387_MASK_PM:
16831       return I387_CW_ANY;
16832     default:
16833       gcc_unreachable ();
16834     }
16835 }
16836
16837 static int
16838 ix86_avx_u128_mode_exit (void)
16839 {
16840   rtx reg = crtl->return_rtx;
16841
16842   /* Exit mode is set to AVX_U128_DIRTY if there are
16843      256bit modes used in the function return register.  */
16844   if (reg && ix86_check_avx256_register (reg))
16845     return AVX_U128_DIRTY;
16846
16847   return AVX_U128_CLEAN;
16848 }
16849
16850 /* Return a mode that ENTITY is assumed to be
16851    switched to at function exit.  */
16852
16853 static int
16854 ix86_mode_exit (int entity)
16855 {
16856   switch (entity)
16857     {
16858     case AVX_U128:
16859       return ix86_avx_u128_mode_exit ();
16860     case I387_TRUNC:
16861     case I387_FLOOR:
16862     case I387_CEIL:
16863     case I387_MASK_PM:
16864       return I387_CW_ANY;
16865     default:
16866       gcc_unreachable ();
16867     }
16868 }
16869
16870 static int
16871 ix86_mode_priority (int, int n)
16872 {
16873   return n;
16874 }
16875
16876 /* Output code to initialize control word copies used by trunc?f?i and
16877    rounding patterns.  CURRENT_MODE is set to current control word,
16878    while NEW_MODE is set to new control word.  */
16879
16880 static void
16881 emit_i387_cw_initialization (int mode)
16882 {
16883   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
16884   rtx new_mode;
16885
16886   enum ix86_stack_slot slot;
16887
16888   rtx reg = gen_reg_rtx (HImode);
16889
16890   emit_insn (gen_x86_fnstcw_1 (stored_mode));
16891   emit_move_insn (reg, copy_rtx (stored_mode));
16892
16893   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
16894       || optimize_insn_for_size_p ())
16895     {
16896       switch (mode)
16897         {
16898         case I387_CW_TRUNC:
16899           /* round toward zero (truncate) */
16900           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
16901           slot = SLOT_CW_TRUNC;
16902           break;
16903
16904         case I387_CW_FLOOR:
16905           /* round down toward -oo */
16906           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
16907           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
16908           slot = SLOT_CW_FLOOR;
16909           break;
16910
16911         case I387_CW_CEIL:
16912           /* round up toward +oo */
16913           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
16914           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
16915           slot = SLOT_CW_CEIL;
16916           break;
16917
16918         case I387_CW_MASK_PM:
16919           /* mask precision exception for nearbyint() */
16920           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
16921           slot = SLOT_CW_MASK_PM;
16922           break;
16923
16924         default:
16925           gcc_unreachable ();
16926         }
16927     }
16928   else
16929     {
16930       switch (mode)
16931         {
16932         case I387_CW_TRUNC:
16933           /* round toward zero (truncate) */
16934           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
16935           slot = SLOT_CW_TRUNC;
16936           break;
16937
16938         case I387_CW_FLOOR:
16939           /* round down toward -oo */
16940           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
16941           slot = SLOT_CW_FLOOR;
16942           break;
16943
16944         case I387_CW_CEIL:
16945           /* round up toward +oo */
16946           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
16947           slot = SLOT_CW_CEIL;
16948           break;
16949
16950         case I387_CW_MASK_PM:
16951           /* mask precision exception for nearbyint() */
16952           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
16953           slot = SLOT_CW_MASK_PM;
16954           break;
16955
16956         default:
16957           gcc_unreachable ();
16958         }
16959     }
16960
16961   gcc_assert (slot < MAX_386_STACK_LOCALS);
16962
16963   new_mode = assign_386_stack_local (HImode, slot);
16964   emit_move_insn (new_mode, reg);
16965 }
16966
16967 /* Emit vzeroupper.  */
16968
16969 void
16970 ix86_avx_emit_vzeroupper (HARD_REG_SET regs_live)
16971 {
16972   int i;
16973
16974   /* Cancel automatic vzeroupper insertion if there are
16975      live call-saved SSE registers at the insertion point.  */
16976
16977   for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
16978     if (TEST_HARD_REG_BIT (regs_live, i) && !call_used_regs[i])
16979       return;
16980
16981   if (TARGET_64BIT)
16982     for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
16983       if (TEST_HARD_REG_BIT (regs_live, i) && !call_used_regs[i])
16984         return;
16985
16986   emit_insn (gen_avx_vzeroupper ());
16987 }
16988
16989 /* Generate one or more insns to set ENTITY to MODE.  */
16990
16991 /* Generate one or more insns to set ENTITY to MODE.  HARD_REG_LIVE
16992    is the set of hard registers live at the point where the insn(s)
16993    are to be inserted.  */
16994
16995 static void
16996 ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
16997                     HARD_REG_SET regs_live)
16998 {
16999   switch (entity)
17000     {
17001     case AVX_U128:
17002       if (mode == AVX_U128_CLEAN)
17003         ix86_avx_emit_vzeroupper (regs_live);
17004       break;
17005     case I387_TRUNC:
17006     case I387_FLOOR:
17007     case I387_CEIL:
17008     case I387_MASK_PM:
17009       if (mode != I387_CW_ANY
17010           && mode != I387_CW_UNINITIALIZED)
17011         emit_i387_cw_initialization (mode);
17012       break;
17013     default:
17014       gcc_unreachable ();
17015     }
17016 }
17017
17018 /* Output code for INSN to convert a float to a signed int.  OPERANDS
17019    are the insn operands.  The output may be [HSD]Imode and the input
17020    operand may be [SDX]Fmode.  */
17021
17022 const char *
17023 output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp)
17024 {
17025   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
17026   int dimode_p = GET_MODE (operands[0]) == DImode;
17027   int round_mode = get_attr_i387_cw (insn);
17028
17029   /* Jump through a hoop or two for DImode, since the hardware has no
17030      non-popping instruction.  We used to do this a different way, but
17031      that was somewhat fragile and broke with post-reload splitters.  */
17032   if ((dimode_p || fisttp) && !stack_top_dies)
17033     output_asm_insn ("fld\t%y1", operands);
17034
17035   gcc_assert (STACK_TOP_P (operands[1]));
17036   gcc_assert (MEM_P (operands[0]));
17037   gcc_assert (GET_MODE (operands[1]) != TFmode);
17038
17039   if (fisttp)
17040       output_asm_insn ("fisttp%Z0\t%0", operands);
17041   else
17042     {
17043       if (round_mode != I387_CW_ANY)
17044         output_asm_insn ("fldcw\t%3", operands);
17045       if (stack_top_dies || dimode_p)
17046         output_asm_insn ("fistp%Z0\t%0", operands);
17047       else
17048         output_asm_insn ("fist%Z0\t%0", operands);
17049       if (round_mode != I387_CW_ANY)
17050         output_asm_insn ("fldcw\t%2", operands);
17051     }
17052
17053   return "";
17054 }
17055
17056 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
17057    have the values zero or one, indicates the ffreep insn's operand
17058    from the OPERANDS array.  */
17059
17060 static const char *
17061 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
17062 {
17063   if (TARGET_USE_FFREEP)
17064 #ifdef HAVE_AS_IX86_FFREEP
17065     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
17066 #else
17067     {
17068       static char retval[32];
17069       int regno = REGNO (operands[opno]);
17070
17071       gcc_assert (STACK_REGNO_P (regno));
17072
17073       regno -= FIRST_STACK_REG;
17074
17075       snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
17076       return retval;
17077     }
17078 #endif
17079
17080   return opno ? "fstp\t%y1" : "fstp\t%y0";
17081 }
17082
17083
17084 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
17085    should be used.  UNORDERED_P is true when fucom should be used.  */
17086
17087 const char *
17088 output_fp_compare (rtx insn, rtx *operands, bool eflags_p, bool unordered_p)
17089 {
17090   int stack_top_dies;
17091   rtx cmp_op0, cmp_op1;
17092   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
17093
17094   if (eflags_p)
17095     {
17096       cmp_op0 = operands[0];
17097       cmp_op1 = operands[1];
17098     }
17099   else
17100     {
17101       cmp_op0 = operands[1];
17102       cmp_op1 = operands[2];
17103     }
17104
17105   if (is_sse)
17106     {
17107       if (GET_MODE (operands[0]) == SFmode)
17108         if (unordered_p)
17109           return "%vucomiss\t{%1, %0|%0, %1}";
17110         else
17111           return "%vcomiss\t{%1, %0|%0, %1}";
17112       else
17113         if (unordered_p)
17114           return "%vucomisd\t{%1, %0|%0, %1}";
17115         else
17116           return "%vcomisd\t{%1, %0|%0, %1}";
17117     }
17118
17119   gcc_assert (STACK_TOP_P (cmp_op0));
17120
17121   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
17122
17123   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
17124     {
17125       if (stack_top_dies)
17126         {
17127           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
17128           return output_387_ffreep (operands, 1);
17129         }
17130       else
17131         return "ftst\n\tfnstsw\t%0";
17132     }
17133
17134   if (STACK_REG_P (cmp_op1)
17135       && stack_top_dies
17136       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
17137       && REGNO (cmp_op1) != FIRST_STACK_REG)
17138     {
17139       /* If both the top of the 387 stack dies, and the other operand
17140          is also a stack register that dies, then this must be a
17141          `fcompp' float compare */
17142
17143       if (eflags_p)
17144         {
17145           /* There is no double popping fcomi variant.  Fortunately,
17146              eflags is immune from the fstp's cc clobbering.  */
17147           if (unordered_p)
17148             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
17149           else
17150             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
17151           return output_387_ffreep (operands, 0);
17152         }
17153       else
17154         {
17155           if (unordered_p)
17156             return "fucompp\n\tfnstsw\t%0";
17157           else
17158             return "fcompp\n\tfnstsw\t%0";
17159         }
17160     }
17161   else
17162     {
17163       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
17164
17165       static const char * const alt[16] =
17166       {
17167         "fcom%Z2\t%y2\n\tfnstsw\t%0",
17168         "fcomp%Z2\t%y2\n\tfnstsw\t%0",
17169         "fucom%Z2\t%y2\n\tfnstsw\t%0",
17170         "fucomp%Z2\t%y2\n\tfnstsw\t%0",
17171
17172         "ficom%Z2\t%y2\n\tfnstsw\t%0",
17173         "ficomp%Z2\t%y2\n\tfnstsw\t%0",
17174         NULL,
17175         NULL,
17176
17177         "fcomi\t{%y1, %0|%0, %y1}",
17178         "fcomip\t{%y1, %0|%0, %y1}",
17179         "fucomi\t{%y1, %0|%0, %y1}",
17180         "fucomip\t{%y1, %0|%0, %y1}",
17181
17182         NULL,
17183         NULL,
17184         NULL,
17185         NULL
17186       };
17187
17188       int mask;
17189       const char *ret;
17190
17191       mask  = eflags_p << 3;
17192       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
17193       mask |= unordered_p << 1;
17194       mask |= stack_top_dies;
17195
17196       gcc_assert (mask < 16);
17197       ret = alt[mask];
17198       gcc_assert (ret);
17199
17200       return ret;
17201     }
17202 }
17203
17204 void
17205 ix86_output_addr_vec_elt (FILE *file, int value)
17206 {
17207   const char *directive = ASM_LONG;
17208
17209 #ifdef ASM_QUAD
17210   if (TARGET_LP64)
17211     directive = ASM_QUAD;
17212 #else
17213   gcc_assert (!TARGET_64BIT);
17214 #endif
17215
17216   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
17217 }
17218
17219 void
17220 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
17221 {
17222   const char *directive = ASM_LONG;
17223
17224 #ifdef ASM_QUAD
17225   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
17226     directive = ASM_QUAD;
17227 #else
17228   gcc_assert (!TARGET_64BIT);
17229 #endif
17230   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
17231   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
17232     fprintf (file, "%s%s%d-%s%d\n",
17233              directive, LPREFIX, value, LPREFIX, rel);
17234   else if (HAVE_AS_GOTOFF_IN_DATA)
17235     fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
17236 #if TARGET_MACHO
17237   else if (TARGET_MACHO)
17238     {
17239       fprintf (file, ASM_LONG "%s%d-", LPREFIX, value);
17240       machopic_output_function_base_name (file);
17241       putc ('\n', file);
17242     }
17243 #endif
17244   else
17245     asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
17246                  GOT_SYMBOL_NAME, LPREFIX, value);
17247 }
17248 \f
17249 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
17250    for the target.  */
17251
17252 void
17253 ix86_expand_clear (rtx dest)
17254 {
17255   rtx tmp;
17256
17257   /* We play register width games, which are only valid after reload.  */
17258   gcc_assert (reload_completed);
17259
17260   /* Avoid HImode and its attendant prefix byte.  */
17261   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
17262     dest = gen_rtx_REG (SImode, REGNO (dest));
17263   tmp = gen_rtx_SET (dest, const0_rtx);
17264
17265   if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17266     {
17267       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
17268       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
17269     }
17270
17271   emit_insn (tmp);
17272 }
17273
17274 /* X is an unchanging MEM.  If it is a constant pool reference, return
17275    the constant pool rtx, else NULL.  */
17276
17277 rtx
17278 maybe_get_pool_constant (rtx x)
17279 {
17280   x = ix86_delegitimize_address (XEXP (x, 0));
17281
17282   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
17283     return get_pool_constant (x);
17284
17285   return NULL_RTX;
17286 }
17287
17288 void
17289 ix86_expand_move (machine_mode mode, rtx operands[])
17290 {
17291   rtx op0, op1;
17292   enum tls_model model;
17293
17294   op0 = operands[0];
17295   op1 = operands[1];
17296
17297   if (GET_CODE (op1) == SYMBOL_REF)
17298     {
17299       rtx tmp;
17300
17301       model = SYMBOL_REF_TLS_MODEL (op1);
17302       if (model)
17303         {
17304           op1 = legitimize_tls_address (op1, model, true);
17305           op1 = force_operand (op1, op0);
17306           if (op1 == op0)
17307             return;
17308           op1 = convert_to_mode (mode, op1, 1);
17309         }
17310       else if ((tmp = legitimize_pe_coff_symbol (op1, false)) != NULL_RTX)
17311         op1 = tmp;
17312     }
17313   else if (GET_CODE (op1) == CONST
17314            && GET_CODE (XEXP (op1, 0)) == PLUS
17315            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
17316     {
17317       rtx addend = XEXP (XEXP (op1, 0), 1);
17318       rtx symbol = XEXP (XEXP (op1, 0), 0);
17319       rtx tmp;
17320
17321       model = SYMBOL_REF_TLS_MODEL (symbol);
17322       if (model)
17323         tmp = legitimize_tls_address (symbol, model, true);
17324       else
17325         tmp = legitimize_pe_coff_symbol (symbol, true);
17326
17327       if (tmp)
17328         {
17329           tmp = force_operand (tmp, NULL);
17330           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
17331                                      op0, 1, OPTAB_DIRECT);
17332           if (tmp == op0)
17333             return;
17334           op1 = convert_to_mode (mode, tmp, 1);
17335         }
17336     }
17337
17338   if ((flag_pic || MACHOPIC_INDIRECT)
17339       && symbolic_operand (op1, mode))
17340     {
17341       if (TARGET_MACHO && !TARGET_64BIT)
17342         {
17343 #if TARGET_MACHO
17344           /* dynamic-no-pic */
17345           if (MACHOPIC_INDIRECT)
17346             {
17347               rtx temp = (op0 && REG_P (op0) && mode == Pmode)
17348                          ? op0 : gen_reg_rtx (Pmode);
17349               op1 = machopic_indirect_data_reference (op1, temp);
17350               if (MACHOPIC_PURE)
17351                 op1 = machopic_legitimize_pic_address (op1, mode,
17352                                                        temp == op1 ? 0 : temp);
17353             }
17354           if (op0 != op1 && GET_CODE (op0) != MEM)
17355             {
17356               rtx insn = gen_rtx_SET (op0, op1);
17357               emit_insn (insn);
17358               return;
17359             }
17360           if (GET_CODE (op0) == MEM)
17361             op1 = force_reg (Pmode, op1);
17362           else
17363             {
17364               rtx temp = op0;
17365               if (GET_CODE (temp) != REG)
17366                 temp = gen_reg_rtx (Pmode);
17367               temp = legitimize_pic_address (op1, temp);
17368               if (temp == op0)
17369             return;
17370               op1 = temp;
17371             }
17372       /* dynamic-no-pic */
17373 #endif
17374         }
17375       else
17376         {
17377           if (MEM_P (op0))
17378             op1 = force_reg (mode, op1);
17379           else if (!(TARGET_64BIT && x86_64_movabs_operand (op1, DImode)))
17380             {
17381               rtx reg = can_create_pseudo_p () ? NULL_RTX : op0;
17382               op1 = legitimize_pic_address (op1, reg);
17383               if (op0 == op1)
17384                 return;
17385               op1 = convert_to_mode (mode, op1, 1);
17386             }
17387         }
17388     }
17389   else
17390     {
17391       if (MEM_P (op0)
17392           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
17393               || !push_operand (op0, mode))
17394           && MEM_P (op1))
17395         op1 = force_reg (mode, op1);
17396
17397       if (push_operand (op0, mode)
17398           && ! general_no_elim_operand (op1, mode))
17399         op1 = copy_to_mode_reg (mode, op1);
17400
17401       /* Force large constants in 64bit compilation into register
17402          to get them CSEed.  */
17403       if (can_create_pseudo_p ()
17404           && (mode == DImode) && TARGET_64BIT
17405           && immediate_operand (op1, mode)
17406           && !x86_64_zext_immediate_operand (op1, VOIDmode)
17407           && !register_operand (op0, mode)
17408           && optimize)
17409         op1 = copy_to_mode_reg (mode, op1);
17410
17411       if (can_create_pseudo_p ()
17412           && CONST_DOUBLE_P (op1))
17413         {
17414           /* If we are loading a floating point constant to a register,
17415              force the value to memory now, since we'll get better code
17416              out the back end.  */
17417
17418           op1 = validize_mem (force_const_mem (mode, op1));
17419           if (!register_operand (op0, mode))
17420             {
17421               rtx temp = gen_reg_rtx (mode);
17422               emit_insn (gen_rtx_SET (temp, op1));
17423               emit_move_insn (op0, temp);
17424               return;
17425             }
17426         }
17427     }
17428
17429   emit_insn (gen_rtx_SET (op0, op1));
17430 }
17431
17432 void
17433 ix86_expand_vector_move (machine_mode mode, rtx operands[])
17434 {
17435   rtx op0 = operands[0], op1 = operands[1];
17436   unsigned int align = GET_MODE_ALIGNMENT (mode);
17437
17438   if (push_operand (op0, VOIDmode))
17439     op0 = emit_move_resolve_push (mode, op0);
17440
17441   /* Force constants other than zero into memory.  We do not know how
17442      the instructions used to build constants modify the upper 64 bits
17443      of the register, once we have that information we may be able
17444      to handle some of them more efficiently.  */
17445   if (can_create_pseudo_p ()
17446       && register_operand (op0, mode)
17447       && (CONSTANT_P (op1)
17448           || (GET_CODE (op1) == SUBREG
17449               && CONSTANT_P (SUBREG_REG (op1))))
17450       && !standard_sse_constant_p (op1))
17451     op1 = validize_mem (force_const_mem (mode, op1));
17452
17453   /* We need to check memory alignment for SSE mode since attribute
17454      can make operands unaligned.  */
17455   if (can_create_pseudo_p ()
17456       && SSE_REG_MODE_P (mode)
17457       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
17458           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
17459     {
17460       rtx tmp[2];
17461
17462       /* ix86_expand_vector_move_misalign() does not like constants ... */
17463       if (CONSTANT_P (op1)
17464           || (GET_CODE (op1) == SUBREG
17465               && CONSTANT_P (SUBREG_REG (op1))))
17466         op1 = validize_mem (force_const_mem (mode, op1));
17467
17468       /* ... nor both arguments in memory.  */
17469       if (!register_operand (op0, mode)
17470           && !register_operand (op1, mode))
17471         op1 = force_reg (mode, op1);
17472
17473       tmp[0] = op0; tmp[1] = op1;
17474       ix86_expand_vector_move_misalign (mode, tmp);
17475       return;
17476     }
17477
17478   /* Make operand1 a register if it isn't already.  */
17479   if (can_create_pseudo_p ()
17480       && !register_operand (op0, mode)
17481       && !register_operand (op1, mode))
17482     {
17483       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
17484       return;
17485     }
17486
17487   emit_insn (gen_rtx_SET (op0, op1));
17488 }
17489
17490 /* Split 32-byte AVX unaligned load and store if needed.  */
17491
17492 static void
17493 ix86_avx256_split_vector_move_misalign (rtx op0, rtx op1)
17494 {
17495   rtx m;
17496   rtx (*extract) (rtx, rtx, rtx);
17497   rtx (*load_unaligned) (rtx, rtx);
17498   rtx (*store_unaligned) (rtx, rtx);
17499   machine_mode mode;
17500
17501   switch (GET_MODE (op0))
17502     {
17503     default:
17504       gcc_unreachable ();
17505     case V32QImode:
17506       extract = gen_avx_vextractf128v32qi;
17507       load_unaligned = gen_avx_loaddquv32qi;
17508       store_unaligned = gen_avx_storedquv32qi;
17509       mode = V16QImode;
17510       break;
17511     case V8SFmode:
17512       extract = gen_avx_vextractf128v8sf;
17513       load_unaligned = gen_avx_loadups256;
17514       store_unaligned = gen_avx_storeups256;
17515       mode = V4SFmode;
17516       break;
17517     case V4DFmode:
17518       extract = gen_avx_vextractf128v4df;
17519       load_unaligned = gen_avx_loadupd256;
17520       store_unaligned = gen_avx_storeupd256;
17521       mode = V2DFmode;
17522       break;
17523     }
17524
17525   if (MEM_P (op1))
17526     {
17527       if (TARGET_AVX256_SPLIT_UNALIGNED_LOAD
17528           && optimize_insn_for_speed_p ())
17529         {
17530           rtx r = gen_reg_rtx (mode);
17531           m = adjust_address (op1, mode, 0);
17532           emit_move_insn (r, m);
17533           m = adjust_address (op1, mode, 16);
17534           r = gen_rtx_VEC_CONCAT (GET_MODE (op0), r, m);
17535           emit_move_insn (op0, r);
17536         }
17537       /* Normal *mov<mode>_internal pattern will handle
17538          unaligned loads just fine if misaligned_operand
17539          is true, and without the UNSPEC it can be combined
17540          with arithmetic instructions.  */
17541       else if (misaligned_operand (op1, GET_MODE (op1)))
17542         emit_insn (gen_rtx_SET (op0, op1));
17543       else
17544         emit_insn (load_unaligned (op0, op1));
17545     }
17546   else if (MEM_P (op0))
17547     {
17548       if (TARGET_AVX256_SPLIT_UNALIGNED_STORE
17549           && optimize_insn_for_speed_p ())
17550         {
17551           m = adjust_address (op0, mode, 0);
17552           emit_insn (extract (m, op1, const0_rtx));
17553           m = adjust_address (op0, mode, 16);
17554           emit_insn (extract (m, op1, const1_rtx));
17555         }
17556       else
17557         emit_insn (store_unaligned (op0, op1));
17558     }
17559   else
17560     gcc_unreachable ();
17561 }
17562
17563 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
17564    straight to ix86_expand_vector_move.  */
17565 /* Code generation for scalar reg-reg moves of single and double precision data:
17566      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
17567        movaps reg, reg
17568      else
17569        movss reg, reg
17570      if (x86_sse_partial_reg_dependency == true)
17571        movapd reg, reg
17572      else
17573        movsd reg, reg
17574
17575    Code generation for scalar loads of double precision data:
17576      if (x86_sse_split_regs == true)
17577        movlpd mem, reg      (gas syntax)
17578      else
17579        movsd mem, reg
17580
17581    Code generation for unaligned packed loads of single precision data
17582    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
17583      if (x86_sse_unaligned_move_optimal)
17584        movups mem, reg
17585
17586      if (x86_sse_partial_reg_dependency == true)
17587        {
17588          xorps  reg, reg
17589          movlps mem, reg
17590          movhps mem+8, reg
17591        }
17592      else
17593        {
17594          movlps mem, reg
17595          movhps mem+8, reg
17596        }
17597
17598    Code generation for unaligned packed loads of double precision data
17599    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
17600      if (x86_sse_unaligned_move_optimal)
17601        movupd mem, reg
17602
17603      if (x86_sse_split_regs == true)
17604        {
17605          movlpd mem, reg
17606          movhpd mem+8, reg
17607        }
17608      else
17609        {
17610          movsd  mem, reg
17611          movhpd mem+8, reg
17612        }
17613  */
17614
17615 void
17616 ix86_expand_vector_move_misalign (machine_mode mode, rtx operands[])
17617 {
17618   rtx op0, op1, orig_op0 = NULL_RTX, m;
17619   rtx (*load_unaligned) (rtx, rtx);
17620   rtx (*store_unaligned) (rtx, rtx);
17621
17622   op0 = operands[0];
17623   op1 = operands[1];
17624
17625   if (GET_MODE_SIZE (mode) == 64)
17626     {
17627       switch (GET_MODE_CLASS (mode))
17628         {
17629         case MODE_VECTOR_INT:
17630         case MODE_INT:
17631           if (GET_MODE (op0) != V16SImode)
17632             {
17633               if (!MEM_P (op0))
17634                 {
17635                   orig_op0 = op0;
17636                   op0 = gen_reg_rtx (V16SImode);
17637                 }
17638               else
17639                 op0 = gen_lowpart (V16SImode, op0);
17640             }
17641           op1 = gen_lowpart (V16SImode, op1);
17642           /* FALLTHRU */
17643
17644         case MODE_VECTOR_FLOAT:
17645           switch (GET_MODE (op0))
17646             {
17647             default:
17648               gcc_unreachable ();
17649             case V16SImode:
17650               load_unaligned = gen_avx512f_loaddquv16si;
17651               store_unaligned = gen_avx512f_storedquv16si;
17652               break;
17653             case V16SFmode:
17654               load_unaligned = gen_avx512f_loadups512;
17655               store_unaligned = gen_avx512f_storeups512;
17656               break;
17657             case V8DFmode:
17658               load_unaligned = gen_avx512f_loadupd512;
17659               store_unaligned = gen_avx512f_storeupd512;
17660               break;
17661             }
17662
17663           if (MEM_P (op1))
17664             emit_insn (load_unaligned (op0, op1));
17665           else if (MEM_P (op0))
17666             emit_insn (store_unaligned (op0, op1));
17667           else
17668             gcc_unreachable ();
17669           if (orig_op0)
17670             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17671           break;
17672
17673         default:
17674           gcc_unreachable ();
17675         }
17676
17677       return;
17678     }
17679
17680   if (TARGET_AVX
17681       && GET_MODE_SIZE (mode) == 32)
17682     {
17683       switch (GET_MODE_CLASS (mode))
17684         {
17685         case MODE_VECTOR_INT:
17686         case MODE_INT:
17687           if (GET_MODE (op0) != V32QImode)
17688             {
17689               if (!MEM_P (op0))
17690                 {
17691                   orig_op0 = op0;
17692                   op0 = gen_reg_rtx (V32QImode);
17693                 }
17694               else
17695                 op0 = gen_lowpart (V32QImode, op0);
17696             }
17697           op1 = gen_lowpart (V32QImode, op1);
17698           /* FALLTHRU */
17699
17700         case MODE_VECTOR_FLOAT:
17701           ix86_avx256_split_vector_move_misalign (op0, op1);
17702           if (orig_op0)
17703             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17704           break;
17705
17706         default:
17707           gcc_unreachable ();
17708         }
17709
17710       return;
17711     }
17712
17713   if (MEM_P (op1))
17714     {
17715       /* Normal *mov<mode>_internal pattern will handle
17716          unaligned loads just fine if misaligned_operand
17717          is true, and without the UNSPEC it can be combined
17718          with arithmetic instructions.  */
17719       if (TARGET_AVX
17720           && (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
17721               || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
17722           && misaligned_operand (op1, GET_MODE (op1)))
17723         emit_insn (gen_rtx_SET (op0, op1));
17724       /* ??? If we have typed data, then it would appear that using
17725          movdqu is the only way to get unaligned data loaded with
17726          integer type.  */
17727       else if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
17728         {
17729           if (GET_MODE (op0) != V16QImode)
17730             {
17731               orig_op0 = op0;
17732               op0 = gen_reg_rtx (V16QImode);
17733             }
17734           op1 = gen_lowpart (V16QImode, op1);
17735           /* We will eventually emit movups based on insn attributes.  */
17736           emit_insn (gen_sse2_loaddquv16qi (op0, op1));
17737           if (orig_op0)
17738             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17739         }
17740       else if (TARGET_SSE2 && mode == V2DFmode)
17741         {
17742           rtx zero;
17743
17744           if (TARGET_AVX
17745               || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
17746               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17747               || optimize_insn_for_size_p ())
17748             {
17749               /* We will eventually emit movups based on insn attributes.  */
17750               emit_insn (gen_sse2_loadupd (op0, op1));
17751               return;
17752             }
17753
17754           /* When SSE registers are split into halves, we can avoid
17755              writing to the top half twice.  */
17756           if (TARGET_SSE_SPLIT_REGS)
17757             {
17758               emit_clobber (op0);
17759               zero = op0;
17760             }
17761           else
17762             {
17763               /* ??? Not sure about the best option for the Intel chips.
17764                  The following would seem to satisfy; the register is
17765                  entirely cleared, breaking the dependency chain.  We
17766                  then store to the upper half, with a dependency depth
17767                  of one.  A rumor has it that Intel recommends two movsd
17768                  followed by an unpacklpd, but this is unconfirmed.  And
17769                  given that the dependency depth of the unpacklpd would
17770                  still be one, I'm not sure why this would be better.  */
17771               zero = CONST0_RTX (V2DFmode);
17772             }
17773
17774           m = adjust_address (op1, DFmode, 0);
17775           emit_insn (gen_sse2_loadlpd (op0, zero, m));
17776           m = adjust_address (op1, DFmode, 8);
17777           emit_insn (gen_sse2_loadhpd (op0, op0, m));
17778         }
17779       else
17780         {
17781           rtx t;
17782
17783           if (TARGET_AVX
17784               || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
17785               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17786               || optimize_insn_for_size_p ())
17787             {
17788               if (GET_MODE (op0) != V4SFmode)
17789                 {
17790                   orig_op0 = op0;
17791                   op0 = gen_reg_rtx (V4SFmode);
17792                 }
17793               op1 = gen_lowpart (V4SFmode, op1);
17794               emit_insn (gen_sse_loadups (op0, op1));
17795               if (orig_op0)
17796                 emit_move_insn (orig_op0,
17797                                 gen_lowpart (GET_MODE (orig_op0), op0));
17798               return;
17799             }
17800
17801           if (mode != V4SFmode)
17802             t = gen_reg_rtx (V4SFmode);
17803           else
17804             t = op0;
17805             
17806           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
17807             emit_move_insn (t, CONST0_RTX (V4SFmode));
17808           else
17809             emit_clobber (t);
17810
17811           m = adjust_address (op1, V2SFmode, 0);
17812           emit_insn (gen_sse_loadlps (t, t, m));
17813           m = adjust_address (op1, V2SFmode, 8);
17814           emit_insn (gen_sse_loadhps (t, t, m));
17815           if (mode != V4SFmode)
17816             emit_move_insn (op0, gen_lowpart (mode, t));
17817         }
17818     }
17819   else if (MEM_P (op0))
17820     {
17821       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
17822         {
17823           op0 = gen_lowpart (V16QImode, op0);
17824           op1 = gen_lowpart (V16QImode, op1);
17825           /* We will eventually emit movups based on insn attributes.  */
17826           emit_insn (gen_sse2_storedquv16qi (op0, op1));
17827         }
17828       else if (TARGET_SSE2 && mode == V2DFmode)
17829         {
17830           if (TARGET_AVX
17831               || TARGET_SSE_UNALIGNED_STORE_OPTIMAL
17832               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17833               || optimize_insn_for_size_p ())
17834             /* We will eventually emit movups based on insn attributes.  */
17835             emit_insn (gen_sse2_storeupd (op0, op1));
17836           else
17837             {
17838               m = adjust_address (op0, DFmode, 0);
17839               emit_insn (gen_sse2_storelpd (m, op1));
17840               m = adjust_address (op0, DFmode, 8);
17841               emit_insn (gen_sse2_storehpd (m, op1));
17842             }
17843         }
17844       else
17845         {
17846           if (mode != V4SFmode)
17847             op1 = gen_lowpart (V4SFmode, op1);
17848
17849           if (TARGET_AVX
17850               || TARGET_SSE_UNALIGNED_STORE_OPTIMAL
17851               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17852               || optimize_insn_for_size_p ())
17853             {
17854               op0 = gen_lowpart (V4SFmode, op0);
17855               emit_insn (gen_sse_storeups (op0, op1));
17856             }
17857           else
17858             {
17859               m = adjust_address (op0, V2SFmode, 0);
17860               emit_insn (gen_sse_storelps (m, op1));
17861               m = adjust_address (op0, V2SFmode, 8);
17862               emit_insn (gen_sse_storehps (m, op1));
17863             }
17864         }
17865     }
17866   else
17867     gcc_unreachable ();
17868 }
17869
17870 /* Helper function of ix86_fixup_binary_operands to canonicalize
17871    operand order.  Returns true if the operands should be swapped.  */
17872
17873 static bool
17874 ix86_swap_binary_operands_p (enum rtx_code code, machine_mode mode,
17875                              rtx operands[])
17876 {
17877   rtx dst = operands[0];
17878   rtx src1 = operands[1];
17879   rtx src2 = operands[2];
17880
17881   /* If the operation is not commutative, we can't do anything.  */
17882   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
17883     return false;
17884
17885   /* Highest priority is that src1 should match dst.  */
17886   if (rtx_equal_p (dst, src1))
17887     return false;
17888   if (rtx_equal_p (dst, src2))
17889     return true;
17890
17891   /* Next highest priority is that immediate constants come second.  */
17892   if (immediate_operand (src2, mode))
17893     return false;
17894   if (immediate_operand (src1, mode))
17895     return true;
17896
17897   /* Lowest priority is that memory references should come second.  */
17898   if (MEM_P (src2))
17899     return false;
17900   if (MEM_P (src1))
17901     return true;
17902
17903   return false;
17904 }
17905
17906
17907 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
17908    destination to use for the operation.  If different from the true
17909    destination in operands[0], a copy operation will be required.  */
17910
17911 rtx
17912 ix86_fixup_binary_operands (enum rtx_code code, machine_mode mode,
17913                             rtx operands[])
17914 {
17915   rtx dst = operands[0];
17916   rtx src1 = operands[1];
17917   rtx src2 = operands[2];
17918
17919   /* Canonicalize operand order.  */
17920   if (ix86_swap_binary_operands_p (code, mode, operands))
17921     {
17922       /* It is invalid to swap operands of different modes.  */
17923       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
17924
17925       std::swap (src1, src2);
17926     }
17927
17928   /* Both source operands cannot be in memory.  */
17929   if (MEM_P (src1) && MEM_P (src2))
17930     {
17931       /* Optimization: Only read from memory once.  */
17932       if (rtx_equal_p (src1, src2))
17933         {
17934           src2 = force_reg (mode, src2);
17935           src1 = src2;
17936         }
17937       else if (rtx_equal_p (dst, src1))
17938         src2 = force_reg (mode, src2);
17939       else
17940         src1 = force_reg (mode, src1);
17941     }
17942
17943   /* If the destination is memory, and we do not have matching source
17944      operands, do things in registers.  */
17945   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
17946     dst = gen_reg_rtx (mode);
17947
17948   /* Source 1 cannot be a constant.  */
17949   if (CONSTANT_P (src1))
17950     src1 = force_reg (mode, src1);
17951
17952   /* Source 1 cannot be a non-matching memory.  */
17953   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
17954     src1 = force_reg (mode, src1);
17955
17956   /* Improve address combine.  */
17957   if (code == PLUS
17958       && GET_MODE_CLASS (mode) == MODE_INT
17959       && MEM_P (src2))
17960     src2 = force_reg (mode, src2);
17961
17962   operands[1] = src1;
17963   operands[2] = src2;
17964   return dst;
17965 }
17966
17967 /* Similarly, but assume that the destination has already been
17968    set up properly.  */
17969
17970 void
17971 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
17972                                     machine_mode mode, rtx operands[])
17973 {
17974   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
17975   gcc_assert (dst == operands[0]);
17976 }
17977
17978 /* Attempt to expand a binary operator.  Make the expansion closer to the
17979    actual machine, then just general_operand, which will allow 3 separate
17980    memory references (one output, two input) in a single insn.  */
17981
17982 void
17983 ix86_expand_binary_operator (enum rtx_code code, machine_mode mode,
17984                              rtx operands[])
17985 {
17986   rtx src1, src2, dst, op, clob;
17987
17988   dst = ix86_fixup_binary_operands (code, mode, operands);
17989   src1 = operands[1];
17990   src2 = operands[2];
17991
17992  /* Emit the instruction.  */
17993
17994   op = gen_rtx_SET (dst, gen_rtx_fmt_ee (code, mode, src1, src2));
17995
17996   if (reload_completed
17997       && code == PLUS
17998       && !rtx_equal_p (dst, src1))
17999     {
18000       /* This is going to be an LEA; avoid splitting it later.  */
18001       emit_insn (op);
18002     }
18003   else
18004     {
18005       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18006       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18007     }
18008
18009   /* Fix up the destination if needed.  */
18010   if (dst != operands[0])
18011     emit_move_insn (operands[0], dst);
18012 }
18013
18014 /* Expand vector logical operation CODE (AND, IOR, XOR) in MODE with
18015    the given OPERANDS.  */
18016
18017 void
18018 ix86_expand_vector_logical_operator (enum rtx_code code, machine_mode mode,
18019                                      rtx operands[])
18020 {
18021   rtx op1 = NULL_RTX, op2 = NULL_RTX;
18022   if (GET_CODE (operands[1]) == SUBREG)
18023     {
18024       op1 = operands[1];
18025       op2 = operands[2];
18026     }
18027   else if (GET_CODE (operands[2]) == SUBREG)
18028     {
18029       op1 = operands[2];
18030       op2 = operands[1];
18031     }
18032   /* Optimize (__m128i) d | (__m128i) e and similar code
18033      when d and e are float vectors into float vector logical
18034      insn.  In C/C++ without using intrinsics there is no other way
18035      to express vector logical operation on float vectors than
18036      to cast them temporarily to integer vectors.  */
18037   if (op1
18038       && !TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
18039       && ((GET_CODE (op2) == SUBREG || GET_CODE (op2) == CONST_VECTOR))
18040       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op1))) == MODE_VECTOR_FLOAT
18041       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1))) == GET_MODE_SIZE (mode)
18042       && SUBREG_BYTE (op1) == 0
18043       && (GET_CODE (op2) == CONST_VECTOR
18044           || (GET_MODE (SUBREG_REG (op1)) == GET_MODE (SUBREG_REG (op2))
18045               && SUBREG_BYTE (op2) == 0))
18046       && can_create_pseudo_p ())
18047     {
18048       rtx dst;
18049       switch (GET_MODE (SUBREG_REG (op1)))
18050         {
18051         case V4SFmode:
18052         case V8SFmode:
18053         case V16SFmode:
18054         case V2DFmode:
18055         case V4DFmode:
18056         case V8DFmode:
18057           dst = gen_reg_rtx (GET_MODE (SUBREG_REG (op1)));
18058           if (GET_CODE (op2) == CONST_VECTOR)
18059             {
18060               op2 = gen_lowpart (GET_MODE (dst), op2);
18061               op2 = force_reg (GET_MODE (dst), op2);
18062             }
18063           else
18064             {
18065               op1 = operands[1];
18066               op2 = SUBREG_REG (operands[2]);
18067               if (!nonimmediate_operand (op2, GET_MODE (dst)))
18068                 op2 = force_reg (GET_MODE (dst), op2);
18069             }
18070           op1 = SUBREG_REG (op1);
18071           if (!nonimmediate_operand (op1, GET_MODE (dst)))
18072             op1 = force_reg (GET_MODE (dst), op1);
18073           emit_insn (gen_rtx_SET (dst,
18074                                   gen_rtx_fmt_ee (code, GET_MODE (dst),
18075                                                   op1, op2)));
18076           emit_move_insn (operands[0], gen_lowpart (mode, dst));
18077           return;
18078         default:
18079           break;
18080         }
18081     }
18082   if (!nonimmediate_operand (operands[1], mode))
18083     operands[1] = force_reg (mode, operands[1]);
18084   if (!nonimmediate_operand (operands[2], mode))
18085     operands[2] = force_reg (mode, operands[2]);
18086   ix86_fixup_binary_operands_no_copy (code, mode, operands);
18087   emit_insn (gen_rtx_SET (operands[0],
18088                           gen_rtx_fmt_ee (code, mode, operands[1],
18089                                           operands[2])));
18090 }
18091
18092 /* Return TRUE or FALSE depending on whether the binary operator meets the
18093    appropriate constraints.  */
18094
18095 bool
18096 ix86_binary_operator_ok (enum rtx_code code, machine_mode mode,
18097                          rtx operands[3])
18098 {
18099   rtx dst = operands[0];
18100   rtx src1 = operands[1];
18101   rtx src2 = operands[2];
18102
18103   /* Both source operands cannot be in memory.  */
18104   if (MEM_P (src1) && MEM_P (src2))
18105     return false;
18106
18107   /* Canonicalize operand order for commutative operators.  */
18108   if (ix86_swap_binary_operands_p (code, mode, operands))
18109     std::swap (src1, src2);
18110
18111   /* If the destination is memory, we must have a matching source operand.  */
18112   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
18113       return false;
18114
18115   /* Source 1 cannot be a constant.  */
18116   if (CONSTANT_P (src1))
18117     return false;
18118
18119   /* Source 1 cannot be a non-matching memory.  */
18120   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
18121     /* Support "andhi/andsi/anddi" as a zero-extending move.  */
18122     return (code == AND
18123             && (mode == HImode
18124                 || mode == SImode
18125                 || (TARGET_64BIT && mode == DImode))
18126             && satisfies_constraint_L (src2));
18127
18128   return true;
18129 }
18130
18131 /* Attempt to expand a unary operator.  Make the expansion closer to the
18132    actual machine, then just general_operand, which will allow 2 separate
18133    memory references (one output, one input) in a single insn.  */
18134
18135 void
18136 ix86_expand_unary_operator (enum rtx_code code, machine_mode mode,
18137                             rtx operands[])
18138 {
18139   bool matching_memory = false;
18140   rtx src, dst, op, clob;
18141
18142   dst = operands[0];
18143   src = operands[1];
18144
18145   /* If the destination is memory, and we do not have matching source
18146      operands, do things in registers.  */
18147   if (MEM_P (dst))
18148     {
18149       if (rtx_equal_p (dst, src))
18150         matching_memory = true;
18151       else
18152         dst = gen_reg_rtx (mode);
18153     }
18154
18155   /* When source operand is memory, destination must match.  */
18156   if (MEM_P (src) && !matching_memory)
18157     src = force_reg (mode, src);
18158
18159   /* Emit the instruction.  */
18160
18161   op = gen_rtx_SET (dst, gen_rtx_fmt_e (code, mode, src));
18162
18163   if (code == NOT)
18164     emit_insn (op);
18165   else
18166     {
18167       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18168       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18169     }
18170
18171   /* Fix up the destination if needed.  */
18172   if (dst != operands[0])
18173     emit_move_insn (operands[0], dst);
18174 }
18175
18176 /* Split 32bit/64bit divmod with 8bit unsigned divmod if dividend and
18177    divisor are within the range [0-255].  */
18178
18179 void
18180 ix86_split_idivmod (machine_mode mode, rtx operands[],
18181                     bool signed_p)
18182 {
18183   rtx_code_label *end_label, *qimode_label;
18184   rtx insn, div, mod;
18185   rtx scratch, tmp0, tmp1, tmp2;
18186   rtx (*gen_divmod4_1) (rtx, rtx, rtx, rtx);
18187   rtx (*gen_zero_extend) (rtx, rtx);
18188   rtx (*gen_test_ccno_1) (rtx, rtx);
18189
18190   switch (mode)
18191     {
18192     case SImode:
18193       gen_divmod4_1 = signed_p ? gen_divmodsi4_1 : gen_udivmodsi4_1;
18194       gen_test_ccno_1 = gen_testsi_ccno_1;
18195       gen_zero_extend = gen_zero_extendqisi2;
18196       break;
18197     case DImode:
18198       gen_divmod4_1 = signed_p ? gen_divmoddi4_1 : gen_udivmoddi4_1;
18199       gen_test_ccno_1 = gen_testdi_ccno_1;
18200       gen_zero_extend = gen_zero_extendqidi2;
18201       break;
18202     default:
18203       gcc_unreachable ();
18204     }
18205
18206   end_label = gen_label_rtx ();
18207   qimode_label = gen_label_rtx ();
18208
18209   scratch = gen_reg_rtx (mode);
18210
18211   /* Use 8bit unsigned divimod if dividend and divisor are within
18212      the range [0-255].  */
18213   emit_move_insn (scratch, operands[2]);
18214   scratch = expand_simple_binop (mode, IOR, scratch, operands[3],
18215                                  scratch, 1, OPTAB_DIRECT);
18216   emit_insn (gen_test_ccno_1 (scratch, GEN_INT (-0x100)));
18217   tmp0 = gen_rtx_REG (CCNOmode, FLAGS_REG);
18218   tmp0 = gen_rtx_EQ (VOIDmode, tmp0, const0_rtx);
18219   tmp0 = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp0,
18220                                gen_rtx_LABEL_REF (VOIDmode, qimode_label),
18221                                pc_rtx);
18222   insn = emit_jump_insn (gen_rtx_SET (pc_rtx, tmp0));
18223   predict_jump (REG_BR_PROB_BASE * 50 / 100);
18224   JUMP_LABEL (insn) = qimode_label;
18225
18226   /* Generate original signed/unsigned divimod.  */
18227   div = gen_divmod4_1 (operands[0], operands[1],
18228                        operands[2], operands[3]);
18229   emit_insn (div);
18230
18231   /* Branch to the end.  */
18232   emit_jump_insn (gen_jump (end_label));
18233   emit_barrier ();
18234
18235   /* Generate 8bit unsigned divide.  */
18236   emit_label (qimode_label);
18237   /* Don't use operands[0] for result of 8bit divide since not all
18238      registers support QImode ZERO_EXTRACT.  */
18239   tmp0 = simplify_gen_subreg (HImode, scratch, mode, 0);
18240   tmp1 = simplify_gen_subreg (HImode, operands[2], mode, 0);
18241   tmp2 = simplify_gen_subreg (QImode, operands[3], mode, 0);
18242   emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, tmp2));
18243
18244   if (signed_p)
18245     {
18246       div = gen_rtx_DIV (SImode, operands[2], operands[3]);
18247       mod = gen_rtx_MOD (SImode, operands[2], operands[3]);
18248     }
18249   else
18250     {
18251       div = gen_rtx_UDIV (SImode, operands[2], operands[3]);
18252       mod = gen_rtx_UMOD (SImode, operands[2], operands[3]);
18253     }
18254
18255   /* Extract remainder from AH.  */
18256   tmp1 = gen_rtx_ZERO_EXTRACT (mode, tmp0, GEN_INT (8), GEN_INT (8));
18257   if (REG_P (operands[1]))
18258     insn = emit_move_insn (operands[1], tmp1);
18259   else
18260     {
18261       /* Need a new scratch register since the old one has result
18262          of 8bit divide.  */
18263       scratch = gen_reg_rtx (mode);
18264       emit_move_insn (scratch, tmp1);
18265       insn = emit_move_insn (operands[1], scratch);
18266     }
18267   set_unique_reg_note (insn, REG_EQUAL, mod);
18268
18269   /* Zero extend quotient from AL.  */
18270   tmp1 = gen_lowpart (QImode, tmp0);
18271   insn = emit_insn (gen_zero_extend (operands[0], tmp1));
18272   set_unique_reg_note (insn, REG_EQUAL, div);
18273
18274   emit_label (end_label);
18275 }
18276
18277 #define LEA_MAX_STALL (3)
18278 #define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1)
18279
18280 /* Increase given DISTANCE in half-cycles according to
18281    dependencies between PREV and NEXT instructions.
18282    Add 1 half-cycle if there is no dependency and
18283    go to next cycle if there is some dependecy.  */
18284
18285 static unsigned int
18286 increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance)
18287 {
18288   df_ref def, use;
18289
18290   if (!prev || !next)
18291     return distance + (distance & 1) + 2;
18292
18293   if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev))
18294     return distance + 1;
18295
18296   FOR_EACH_INSN_USE (use, next)
18297     FOR_EACH_INSN_DEF (def, prev)
18298       if (!DF_REF_IS_ARTIFICIAL (def)
18299           && DF_REF_REGNO (use) == DF_REF_REGNO (def))
18300         return distance + (distance & 1) + 2;
18301
18302   return distance + 1;
18303 }
18304
18305 /* Function checks if instruction INSN defines register number
18306    REGNO1 or REGNO2.  */
18307
18308 static bool
18309 insn_defines_reg (unsigned int regno1, unsigned int regno2,
18310                   rtx_insn *insn)
18311 {
18312   df_ref def;
18313
18314   FOR_EACH_INSN_DEF (def, insn)
18315     if (DF_REF_REG_DEF_P (def)
18316         && !DF_REF_IS_ARTIFICIAL (def)
18317         && (regno1 == DF_REF_REGNO (def)
18318             || regno2 == DF_REF_REGNO (def)))
18319       return true;
18320
18321   return false;
18322 }
18323
18324 /* Function checks if instruction INSN uses register number
18325    REGNO as a part of address expression.  */
18326
18327 static bool
18328 insn_uses_reg_mem (unsigned int regno, rtx insn)
18329 {
18330   df_ref use;
18331
18332   FOR_EACH_INSN_USE (use, insn)
18333     if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use))
18334       return true;
18335
18336   return false;
18337 }
18338
18339 /* Search backward for non-agu definition of register number REGNO1
18340    or register number REGNO2 in basic block starting from instruction
18341    START up to head of basic block or instruction INSN.
18342
18343    Function puts true value into *FOUND var if definition was found
18344    and false otherwise.
18345
18346    Distance in half-cycles between START and found instruction or head
18347    of BB is added to DISTANCE and returned.  */
18348
18349 static int
18350 distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2,
18351                                rtx_insn *insn, int distance,
18352                                rtx_insn *start, bool *found)
18353 {
18354   basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL;
18355   rtx_insn *prev = start;
18356   rtx_insn *next = NULL;
18357
18358   *found = false;
18359
18360   while (prev
18361          && prev != insn
18362          && distance < LEA_SEARCH_THRESHOLD)
18363     {
18364       if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev))
18365         {
18366           distance = increase_distance (prev, next, distance);
18367           if (insn_defines_reg (regno1, regno2, prev))
18368             {
18369               if (recog_memoized (prev) < 0
18370                   || get_attr_type (prev) != TYPE_LEA)
18371                 {
18372                   *found = true;
18373                   return distance;
18374                 }
18375             }
18376
18377           next = prev;
18378         }
18379       if (prev == BB_HEAD (bb))
18380         break;
18381
18382       prev = PREV_INSN (prev);
18383     }
18384
18385   return distance;
18386 }
18387
18388 /* Search backward for non-agu definition of register number REGNO1
18389    or register number REGNO2 in INSN's basic block until
18390    1. Pass LEA_SEARCH_THRESHOLD instructions, or
18391    2. Reach neighbour BBs boundary, or
18392    3. Reach agu definition.
18393    Returns the distance between the non-agu definition point and INSN.
18394    If no definition point, returns -1.  */
18395
18396 static int
18397 distance_non_agu_define (unsigned int regno1, unsigned int regno2,
18398                          rtx_insn *insn)
18399 {
18400   basic_block bb = BLOCK_FOR_INSN (insn);
18401   int distance = 0;
18402   bool found = false;
18403
18404   if (insn != BB_HEAD (bb))
18405     distance = distance_non_agu_define_in_bb (regno1, regno2, insn,
18406                                               distance, PREV_INSN (insn),
18407                                               &found);
18408
18409   if (!found && distance < LEA_SEARCH_THRESHOLD)
18410     {
18411       edge e;
18412       edge_iterator ei;
18413       bool simple_loop = false;
18414
18415       FOR_EACH_EDGE (e, ei, bb->preds)
18416         if (e->src == bb)
18417           {
18418             simple_loop = true;
18419             break;
18420           }
18421
18422       if (simple_loop)
18423         distance = distance_non_agu_define_in_bb (regno1, regno2,
18424                                                   insn, distance,
18425                                                   BB_END (bb), &found);
18426       else
18427         {
18428           int shortest_dist = -1;
18429           bool found_in_bb = false;
18430
18431           FOR_EACH_EDGE (e, ei, bb->preds)
18432             {
18433               int bb_dist
18434                 = distance_non_agu_define_in_bb (regno1, regno2,
18435                                                  insn, distance,
18436                                                  BB_END (e->src),
18437                                                  &found_in_bb);
18438               if (found_in_bb)
18439                 {
18440                   if (shortest_dist < 0)
18441                     shortest_dist = bb_dist;
18442                   else if (bb_dist > 0)
18443                     shortest_dist = MIN (bb_dist, shortest_dist);
18444
18445                   found = true;
18446                 }
18447             }
18448
18449           distance = shortest_dist;
18450         }
18451     }
18452
18453   /* get_attr_type may modify recog data.  We want to make sure
18454      that recog data is valid for instruction INSN, on which
18455      distance_non_agu_define is called.  INSN is unchanged here.  */
18456   extract_insn_cached (insn);
18457
18458   if (!found)
18459     return -1;
18460
18461   return distance >> 1;
18462 }
18463
18464 /* Return the distance in half-cycles between INSN and the next
18465    insn that uses register number REGNO in memory address added
18466    to DISTANCE.  Return -1 if REGNO0 is set.
18467
18468    Put true value into *FOUND if register usage was found and
18469    false otherwise.
18470    Put true value into *REDEFINED if register redefinition was
18471    found and false otherwise.  */
18472
18473 static int
18474 distance_agu_use_in_bb (unsigned int regno,
18475                         rtx_insn *insn, int distance, rtx_insn *start,
18476                         bool *found, bool *redefined)
18477 {
18478   basic_block bb = NULL;
18479   rtx_insn *next = start;
18480   rtx_insn *prev = NULL;
18481
18482   *found = false;
18483   *redefined = false;
18484
18485   if (start != NULL_RTX)
18486     {
18487       bb = BLOCK_FOR_INSN (start);
18488       if (start != BB_HEAD (bb))
18489         /* If insn and start belong to the same bb, set prev to insn,
18490            so the call to increase_distance will increase the distance
18491            between insns by 1.  */
18492         prev = insn;
18493     }
18494
18495   while (next
18496          && next != insn
18497          && distance < LEA_SEARCH_THRESHOLD)
18498     {
18499       if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next))
18500         {
18501           distance = increase_distance(prev, next, distance);
18502           if (insn_uses_reg_mem (regno, next))
18503             {
18504               /* Return DISTANCE if OP0 is used in memory
18505                  address in NEXT.  */
18506               *found = true;
18507               return distance;
18508             }
18509
18510           if (insn_defines_reg (regno, INVALID_REGNUM, next))
18511             {
18512               /* Return -1 if OP0 is set in NEXT.  */
18513               *redefined = true;
18514               return -1;
18515             }
18516
18517           prev = next;
18518         }
18519
18520       if (next == BB_END (bb))
18521         break;
18522
18523       next = NEXT_INSN (next);
18524     }
18525
18526   return distance;
18527 }
18528
18529 /* Return the distance between INSN and the next insn that uses
18530    register number REGNO0 in memory address.  Return -1 if no such
18531    a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set.  */
18532
18533 static int
18534 distance_agu_use (unsigned int regno0, rtx_insn *insn)
18535 {
18536   basic_block bb = BLOCK_FOR_INSN (insn);
18537   int distance = 0;
18538   bool found = false;
18539   bool redefined = false;
18540
18541   if (insn != BB_END (bb))
18542     distance = distance_agu_use_in_bb (regno0, insn, distance,
18543                                        NEXT_INSN (insn),
18544                                        &found, &redefined);
18545
18546   if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD)
18547     {
18548       edge e;
18549       edge_iterator ei;
18550       bool simple_loop = false;
18551
18552       FOR_EACH_EDGE (e, ei, bb->succs)
18553         if (e->dest == bb)
18554           {
18555             simple_loop = true;
18556             break;
18557           }
18558
18559       if (simple_loop)
18560         distance = distance_agu_use_in_bb (regno0, insn,
18561                                            distance, BB_HEAD (bb),
18562                                            &found, &redefined);
18563       else
18564         {
18565           int shortest_dist = -1;
18566           bool found_in_bb = false;
18567           bool redefined_in_bb = false;
18568
18569           FOR_EACH_EDGE (e, ei, bb->succs)
18570             {
18571               int bb_dist
18572                 = distance_agu_use_in_bb (regno0, insn,
18573                                           distance, BB_HEAD (e->dest),
18574                                           &found_in_bb, &redefined_in_bb);
18575               if (found_in_bb)
18576                 {
18577                   if (shortest_dist < 0)
18578                     shortest_dist = bb_dist;
18579                   else if (bb_dist > 0)
18580                     shortest_dist = MIN (bb_dist, shortest_dist);
18581
18582                   found = true;
18583                 }
18584             }
18585
18586           distance = shortest_dist;
18587         }
18588     }
18589
18590   if (!found || redefined)
18591     return -1;
18592
18593   return distance >> 1;
18594 }
18595
18596 /* Define this macro to tune LEA priority vs ADD, it take effect when
18597    there is a dilemma of choicing LEA or ADD
18598    Negative value: ADD is more preferred than LEA
18599    Zero: Netrual
18600    Positive value: LEA is more preferred than ADD*/
18601 #define IX86_LEA_PRIORITY 0
18602
18603 /* Return true if usage of lea INSN has performance advantage
18604    over a sequence of instructions.  Instructions sequence has
18605    SPLIT_COST cycles higher latency than lea latency.  */
18606
18607 static bool
18608 ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
18609                       unsigned int regno2, int split_cost, bool has_scale)
18610 {
18611   int dist_define, dist_use;
18612
18613   /* For Silvermont if using a 2-source or 3-source LEA for
18614      non-destructive destination purposes, or due to wanting
18615      ability to use SCALE, the use of LEA is justified.  */
18616   if (TARGET_SILVERMONT || TARGET_INTEL)
18617     {
18618       if (has_scale)
18619         return true;
18620       if (split_cost < 1)
18621         return false;
18622       if (regno0 == regno1 || regno0 == regno2)
18623         return false;
18624       return true;
18625     }
18626
18627   dist_define = distance_non_agu_define (regno1, regno2, insn);
18628   dist_use = distance_agu_use (regno0, insn);
18629
18630   if (dist_define < 0 || dist_define >= LEA_MAX_STALL)
18631     {
18632       /* If there is no non AGU operand definition, no AGU
18633          operand usage and split cost is 0 then both lea
18634          and non lea variants have same priority.  Currently
18635          we prefer lea for 64 bit code and non lea on 32 bit
18636          code.  */
18637       if (dist_use < 0 && split_cost == 0)
18638         return TARGET_64BIT || IX86_LEA_PRIORITY;
18639       else
18640         return true;
18641     }
18642
18643   /* With longer definitions distance lea is more preferable.
18644      Here we change it to take into account splitting cost and
18645      lea priority.  */
18646   dist_define += split_cost + IX86_LEA_PRIORITY;
18647
18648   /* If there is no use in memory addess then we just check
18649      that split cost exceeds AGU stall.  */
18650   if (dist_use < 0)
18651     return dist_define > LEA_MAX_STALL;
18652
18653   /* If this insn has both backward non-agu dependence and forward
18654      agu dependence, the one with short distance takes effect.  */
18655   return dist_define >= dist_use;
18656 }
18657
18658 /* Return true if it is legal to clobber flags by INSN and
18659    false otherwise.  */
18660
18661 static bool
18662 ix86_ok_to_clobber_flags (rtx_insn *insn)
18663 {
18664   basic_block bb = BLOCK_FOR_INSN (insn);
18665   df_ref use;
18666   bitmap live;
18667
18668   while (insn)
18669     {
18670       if (NONDEBUG_INSN_P (insn))
18671         {
18672           FOR_EACH_INSN_USE (use, insn)
18673             if (DF_REF_REG_USE_P (use) && DF_REF_REGNO (use) == FLAGS_REG)
18674               return false;
18675
18676           if (insn_defines_reg (FLAGS_REG, INVALID_REGNUM, insn))
18677             return true;
18678         }
18679
18680       if (insn == BB_END (bb))
18681         break;
18682
18683       insn = NEXT_INSN (insn);
18684     }
18685
18686   live = df_get_live_out(bb);
18687   return !REGNO_REG_SET_P (live, FLAGS_REG);
18688 }
18689
18690 /* Return true if we need to split op0 = op1 + op2 into a sequence of
18691    move and add to avoid AGU stalls.  */
18692
18693 bool
18694 ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[])
18695 {
18696   unsigned int regno0, regno1, regno2;
18697
18698   /* Check if we need to optimize.  */
18699   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18700     return false;
18701
18702   /* Check it is correct to split here.  */
18703   if (!ix86_ok_to_clobber_flags(insn))
18704     return false;
18705
18706   regno0 = true_regnum (operands[0]);
18707   regno1 = true_regnum (operands[1]);
18708   regno2 = true_regnum (operands[2]);
18709
18710   /* We need to split only adds with non destructive
18711      destination operand.  */
18712   if (regno0 == regno1 || regno0 == regno2)
18713     return false;
18714   else
18715     return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false);
18716 }
18717
18718 /* Return true if we should emit lea instruction instead of mov
18719    instruction.  */
18720
18721 bool
18722 ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[])
18723 {
18724   unsigned int regno0, regno1;
18725
18726   /* Check if we need to optimize.  */
18727   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18728     return false;
18729
18730   /* Use lea for reg to reg moves only.  */
18731   if (!REG_P (operands[0]) || !REG_P (operands[1]))
18732     return false;
18733
18734   regno0 = true_regnum (operands[0]);
18735   regno1 = true_regnum (operands[1]);
18736
18737   return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false);
18738 }
18739
18740 /* Return true if we need to split lea into a sequence of
18741    instructions to avoid AGU stalls. */
18742
18743 bool
18744 ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
18745 {
18746   unsigned int regno0, regno1, regno2;
18747   int split_cost;
18748   struct ix86_address parts;
18749   int ok;
18750
18751   /* Check we need to optimize.  */
18752   if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
18753     return false;
18754
18755   /* The "at least two components" test below might not catch simple
18756      move or zero extension insns if parts.base is non-NULL and parts.disp
18757      is const0_rtx as the only components in the address, e.g. if the
18758      register is %rbp or %r13.  As this test is much cheaper and moves or
18759      zero extensions are the common case, do this check first.  */
18760   if (REG_P (operands[1])
18761       || (SImode_address_operand (operands[1], VOIDmode)
18762           && REG_P (XEXP (operands[1], 0))))
18763     return false;
18764
18765   /* Check if it is OK to split here.  */
18766   if (!ix86_ok_to_clobber_flags (insn))
18767     return false;
18768
18769   ok = ix86_decompose_address (operands[1], &parts);
18770   gcc_assert (ok);
18771
18772   /* There should be at least two components in the address.  */
18773   if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX)
18774       + (parts.disp != NULL_RTX) + (parts.scale > 1) < 2)
18775     return false;
18776
18777   /* We should not split into add if non legitimate pic
18778      operand is used as displacement. */
18779   if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp))
18780     return false;
18781
18782   regno0 = true_regnum (operands[0]) ;
18783   regno1 = INVALID_REGNUM;
18784   regno2 = INVALID_REGNUM;
18785
18786   if (parts.base)
18787     regno1 = true_regnum (parts.base);
18788   if (parts.index)
18789     regno2 = true_regnum (parts.index);
18790
18791   split_cost = 0;
18792
18793   /* Compute how many cycles we will add to execution time
18794      if split lea into a sequence of instructions.  */
18795   if (parts.base || parts.index)
18796     {
18797       /* Have to use mov instruction if non desctructive
18798          destination form is used.  */
18799       if (regno1 != regno0 && regno2 != regno0)
18800         split_cost += 1;
18801
18802       /* Have to add index to base if both exist.  */
18803       if (parts.base && parts.index)
18804         split_cost += 1;
18805
18806       /* Have to use shift and adds if scale is 2 or greater.  */
18807       if (parts.scale > 1)
18808         {
18809           if (regno0 != regno1)
18810             split_cost += 1;
18811           else if (regno2 == regno0)
18812             split_cost += 4;
18813           else
18814             split_cost += parts.scale;
18815         }
18816
18817       /* Have to use add instruction with immediate if
18818          disp is non zero.  */
18819       if (parts.disp && parts.disp != const0_rtx)
18820         split_cost += 1;
18821
18822       /* Subtract the price of lea.  */
18823       split_cost -= 1;
18824     }
18825
18826   return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost,
18827                                 parts.scale > 1);
18828 }
18829
18830 /* Emit x86 binary operand CODE in mode MODE, where the first operand
18831    matches destination.  RTX includes clobber of FLAGS_REG.  */
18832
18833 static void
18834 ix86_emit_binop (enum rtx_code code, machine_mode mode,
18835                  rtx dst, rtx src)
18836 {
18837   rtx op, clob;
18838
18839   op = gen_rtx_SET (dst, gen_rtx_fmt_ee (code, mode, dst, src));
18840   clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18841   
18842   emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18843 }
18844
18845 /* Return true if regno1 def is nearest to the insn.  */
18846
18847 static bool
18848 find_nearest_reg_def (rtx_insn *insn, int regno1, int regno2)
18849 {
18850   rtx_insn *prev = insn;
18851   rtx_insn *start = BB_HEAD (BLOCK_FOR_INSN (insn));
18852
18853   if (insn == start)
18854     return false;
18855   while (prev && prev != start)
18856     {
18857       if (!INSN_P (prev) || !NONDEBUG_INSN_P (prev))
18858         {
18859           prev = PREV_INSN (prev);
18860           continue;
18861         }
18862       if (insn_defines_reg (regno1, INVALID_REGNUM, prev))
18863         return true;
18864       else if (insn_defines_reg (regno2, INVALID_REGNUM, prev))
18865         return false;
18866       prev = PREV_INSN (prev);
18867     }
18868
18869   /* None of the regs is defined in the bb.  */
18870   return false;
18871 }
18872
18873 /* Split lea instructions into a sequence of instructions
18874    which are executed on ALU to avoid AGU stalls.
18875    It is assumed that it is allowed to clobber flags register
18876    at lea position.  */
18877
18878 void
18879 ix86_split_lea_for_addr (rtx_insn *insn, rtx operands[], machine_mode mode)
18880 {
18881   unsigned int regno0, regno1, regno2;
18882   struct ix86_address parts;
18883   rtx target, tmp;
18884   int ok, adds;
18885
18886   ok = ix86_decompose_address (operands[1], &parts);
18887   gcc_assert (ok);
18888
18889   target = gen_lowpart (mode, operands[0]);
18890
18891   regno0 = true_regnum (target);
18892   regno1 = INVALID_REGNUM;
18893   regno2 = INVALID_REGNUM;
18894
18895   if (parts.base)
18896     {
18897       parts.base = gen_lowpart (mode, parts.base);
18898       regno1 = true_regnum (parts.base);
18899     }
18900
18901   if (parts.index)
18902     {
18903       parts.index = gen_lowpart (mode, parts.index);
18904       regno2 = true_regnum (parts.index);
18905     }
18906
18907   if (parts.disp)
18908     parts.disp = gen_lowpart (mode, parts.disp);
18909
18910   if (parts.scale > 1)
18911     {
18912       /* Case r1 = r1 + ...  */
18913       if (regno1 == regno0)
18914         {
18915           /* If we have a case r1 = r1 + C * r2 then we
18916              should use multiplication which is very
18917              expensive.  Assume cost model is wrong if we
18918              have such case here.  */
18919           gcc_assert (regno2 != regno0);
18920
18921           for (adds = parts.scale; adds > 0; adds--)
18922             ix86_emit_binop (PLUS, mode, target, parts.index);
18923         }
18924       else
18925         {
18926           /* r1 = r2 + r3 * C case.  Need to move r3 into r1.  */
18927           if (regno0 != regno2)
18928             emit_insn (gen_rtx_SET (target, parts.index));
18929
18930           /* Use shift for scaling.  */
18931           ix86_emit_binop (ASHIFT, mode, target,
18932                            GEN_INT (exact_log2 (parts.scale)));
18933
18934           if (parts.base)
18935             ix86_emit_binop (PLUS, mode, target, parts.base);
18936
18937           if (parts.disp && parts.disp != const0_rtx)
18938             ix86_emit_binop (PLUS, mode, target, parts.disp);
18939         }
18940     }
18941   else if (!parts.base && !parts.index)
18942     {
18943       gcc_assert(parts.disp);
18944       emit_insn (gen_rtx_SET (target, parts.disp));
18945     }
18946   else
18947     {
18948       if (!parts.base)
18949         {
18950           if (regno0 != regno2)
18951             emit_insn (gen_rtx_SET (target, parts.index));
18952         }
18953       else if (!parts.index)
18954         {
18955           if (regno0 != regno1)
18956             emit_insn (gen_rtx_SET (target, parts.base));
18957         }
18958       else
18959         {
18960           if (regno0 == regno1)
18961             tmp = parts.index;
18962           else if (regno0 == regno2)
18963             tmp = parts.base;
18964           else
18965             {
18966               rtx tmp1;
18967
18968               /* Find better operand for SET instruction, depending
18969                  on which definition is farther from the insn.  */
18970               if (find_nearest_reg_def (insn, regno1, regno2))
18971                 tmp = parts.index, tmp1 = parts.base;
18972               else
18973                 tmp = parts.base, tmp1 = parts.index;
18974
18975               emit_insn (gen_rtx_SET (target, tmp));
18976
18977               if (parts.disp && parts.disp != const0_rtx)
18978                 ix86_emit_binop (PLUS, mode, target, parts.disp);
18979
18980               ix86_emit_binop (PLUS, mode, target, tmp1);
18981               return;
18982             }
18983
18984           ix86_emit_binop (PLUS, mode, target, tmp);
18985         }
18986
18987       if (parts.disp && parts.disp != const0_rtx)
18988         ix86_emit_binop (PLUS, mode, target, parts.disp);
18989     }
18990 }
18991
18992 /* Return true if it is ok to optimize an ADD operation to LEA
18993    operation to avoid flag register consumation.  For most processors,
18994    ADD is faster than LEA.  For the processors like BONNELL, if the
18995    destination register of LEA holds an actual address which will be
18996    used soon, LEA is better and otherwise ADD is better.  */
18997
18998 bool
18999 ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[])
19000 {
19001   unsigned int regno0 = true_regnum (operands[0]);
19002   unsigned int regno1 = true_regnum (operands[1]);
19003   unsigned int regno2 = true_regnum (operands[2]);
19004
19005   /* If a = b + c, (a!=b && a!=c), must use lea form. */
19006   if (regno0 != regno1 && regno0 != regno2)
19007     return true;
19008
19009   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
19010     return false;
19011
19012   return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false);
19013 }
19014
19015 /* Return true if destination reg of SET_BODY is shift count of
19016    USE_BODY.  */
19017
19018 static bool
19019 ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
19020 {
19021   rtx set_dest;
19022   rtx shift_rtx;
19023   int i;
19024
19025   /* Retrieve destination of SET_BODY.  */
19026   switch (GET_CODE (set_body))
19027     {
19028     case SET:
19029       set_dest = SET_DEST (set_body);
19030       if (!set_dest || !REG_P (set_dest))
19031         return false;
19032       break;
19033     case PARALLEL:
19034       for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
19035         if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
19036                                           use_body))
19037           return true;
19038     default:
19039       return false;
19040       break;
19041     }
19042
19043   /* Retrieve shift count of USE_BODY.  */
19044   switch (GET_CODE (use_body))
19045     {
19046     case SET:
19047       shift_rtx = XEXP (use_body, 1);
19048       break;
19049     case PARALLEL:
19050       for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
19051         if (ix86_dep_by_shift_count_body (set_body,
19052                                           XVECEXP (use_body, 0, i)))
19053           return true;
19054     default:
19055       return false;
19056       break;
19057     }
19058
19059   if (shift_rtx
19060       && (GET_CODE (shift_rtx) == ASHIFT
19061           || GET_CODE (shift_rtx) == LSHIFTRT
19062           || GET_CODE (shift_rtx) == ASHIFTRT
19063           || GET_CODE (shift_rtx) == ROTATE
19064           || GET_CODE (shift_rtx) == ROTATERT))
19065     {
19066       rtx shift_count = XEXP (shift_rtx, 1);
19067
19068       /* Return true if shift count is dest of SET_BODY.  */
19069       if (REG_P (shift_count))
19070         {
19071           /* Add check since it can be invoked before register
19072              allocation in pre-reload schedule.  */
19073           if (reload_completed
19074               && true_regnum (set_dest) == true_regnum (shift_count))
19075             return true;
19076           else if (REGNO(set_dest) == REGNO(shift_count))
19077             return true;
19078         }
19079     }
19080
19081   return false;
19082 }
19083
19084 /* Return true if destination reg of SET_INSN is shift count of
19085    USE_INSN.  */
19086
19087 bool
19088 ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
19089 {
19090   return ix86_dep_by_shift_count_body (PATTERN (set_insn),
19091                                        PATTERN (use_insn));
19092 }
19093
19094 /* Return TRUE or FALSE depending on whether the unary operator meets the
19095    appropriate constraints.  */
19096
19097 bool
19098 ix86_unary_operator_ok (enum rtx_code,
19099                         machine_mode,
19100                         rtx operands[2])
19101 {
19102   /* If one of operands is memory, source and destination must match.  */
19103   if ((MEM_P (operands[0])
19104        || MEM_P (operands[1]))
19105       && ! rtx_equal_p (operands[0], operands[1]))
19106     return false;
19107   return true;
19108 }
19109
19110 /* Return TRUE if the operands to a vec_interleave_{high,low}v2df
19111    are ok, keeping in mind the possible movddup alternative.  */
19112
19113 bool
19114 ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high)
19115 {
19116   if (MEM_P (operands[0]))
19117     return rtx_equal_p (operands[0], operands[1 + high]);
19118   if (MEM_P (operands[1]) && MEM_P (operands[2]))
19119     return TARGET_SSE3 && rtx_equal_p (operands[1], operands[2]);
19120   return true;
19121 }
19122
19123 /* Post-reload splitter for converting an SF or DFmode value in an
19124    SSE register into an unsigned SImode.  */
19125
19126 void
19127 ix86_split_convert_uns_si_sse (rtx operands[])
19128 {
19129   machine_mode vecmode;
19130   rtx value, large, zero_or_two31, input, two31, x;
19131
19132   large = operands[1];
19133   zero_or_two31 = operands[2];
19134   input = operands[3];
19135   two31 = operands[4];
19136   vecmode = GET_MODE (large);
19137   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
19138
19139   /* Load up the value into the low element.  We must ensure that the other
19140      elements are valid floats -- zero is the easiest such value.  */
19141   if (MEM_P (input))
19142     {
19143       if (vecmode == V4SFmode)
19144         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
19145       else
19146         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
19147     }
19148   else
19149     {
19150       input = gen_rtx_REG (vecmode, REGNO (input));
19151       emit_move_insn (value, CONST0_RTX (vecmode));
19152       if (vecmode == V4SFmode)
19153         emit_insn (gen_sse_movss (value, value, input));
19154       else
19155         emit_insn (gen_sse2_movsd (value, value, input));
19156     }
19157
19158   emit_move_insn (large, two31);
19159   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
19160
19161   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
19162   emit_insn (gen_rtx_SET (large, x));
19163
19164   x = gen_rtx_AND (vecmode, zero_or_two31, large);
19165   emit_insn (gen_rtx_SET (zero_or_two31, x));
19166
19167   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
19168   emit_insn (gen_rtx_SET (value, x));
19169
19170   large = gen_rtx_REG (V4SImode, REGNO (large));
19171   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
19172
19173   x = gen_rtx_REG (V4SImode, REGNO (value));
19174   if (vecmode == V4SFmode)
19175     emit_insn (gen_fix_truncv4sfv4si2 (x, value));
19176   else
19177     emit_insn (gen_sse2_cvttpd2dq (x, value));
19178   value = x;
19179
19180   emit_insn (gen_xorv4si3 (value, value, large));
19181 }
19182
19183 /* Convert an unsigned DImode value into a DFmode, using only SSE.
19184    Expects the 64-bit DImode to be supplied in a pair of integral
19185    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
19186    -mfpmath=sse, !optimize_size only.  */
19187
19188 void
19189 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
19190 {
19191   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
19192   rtx int_xmm, fp_xmm;
19193   rtx biases, exponents;
19194   rtx x;
19195
19196   int_xmm = gen_reg_rtx (V4SImode);
19197   if (TARGET_INTER_UNIT_MOVES_TO_VEC)
19198     emit_insn (gen_movdi_to_sse (int_xmm, input));
19199   else if (TARGET_SSE_SPLIT_REGS)
19200     {
19201       emit_clobber (int_xmm);
19202       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
19203     }
19204   else
19205     {
19206       x = gen_reg_rtx (V2DImode);
19207       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
19208       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
19209     }
19210
19211   x = gen_rtx_CONST_VECTOR (V4SImode,
19212                             gen_rtvec (4, GEN_INT (0x43300000UL),
19213                                        GEN_INT (0x45300000UL),
19214                                        const0_rtx, const0_rtx));
19215   exponents = validize_mem (force_const_mem (V4SImode, x));
19216
19217   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
19218   emit_insn (gen_vec_interleave_lowv4si (int_xmm, int_xmm, exponents));
19219
19220   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
19221      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
19222      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
19223      (0x1.0p84 + double(fp_value_hi_xmm)).
19224      Note these exponents differ by 32.  */
19225
19226   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
19227
19228   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
19229      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
19230   real_ldexp (&bias_lo_rvt, &dconst1, 52);
19231   real_ldexp (&bias_hi_rvt, &dconst1, 84);
19232   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
19233   x = const_double_from_real_value (bias_hi_rvt, DFmode);
19234   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
19235   biases = validize_mem (force_const_mem (V2DFmode, biases));
19236   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
19237
19238   /* Add the upper and lower DFmode values together.  */
19239   if (TARGET_SSE3)
19240     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
19241   else
19242     {
19243       x = copy_to_mode_reg (V2DFmode, fp_xmm);
19244       emit_insn (gen_vec_interleave_highv2df (fp_xmm, fp_xmm, fp_xmm));
19245       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
19246     }
19247
19248   ix86_expand_vector_extract (false, target, fp_xmm, 0);
19249 }
19250
19251 /* Not used, but eases macroization of patterns.  */
19252 void
19253 ix86_expand_convert_uns_sixf_sse (rtx, rtx)
19254 {
19255   gcc_unreachable ();
19256 }
19257
19258 /* Convert an unsigned SImode value into a DFmode.  Only currently used
19259    for SSE, but applicable anywhere.  */
19260
19261 void
19262 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
19263 {
19264   REAL_VALUE_TYPE TWO31r;
19265   rtx x, fp;
19266
19267   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
19268                            NULL, 1, OPTAB_DIRECT);
19269
19270   fp = gen_reg_rtx (DFmode);
19271   emit_insn (gen_floatsidf2 (fp, x));
19272
19273   real_ldexp (&TWO31r, &dconst1, 31);
19274   x = const_double_from_real_value (TWO31r, DFmode);
19275
19276   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
19277   if (x != target)
19278     emit_move_insn (target, x);
19279 }
19280
19281 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
19282    32-bit mode; otherwise we have a direct convert instruction.  */
19283
19284 void
19285 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
19286 {
19287   REAL_VALUE_TYPE TWO32r;
19288   rtx fp_lo, fp_hi, x;
19289
19290   fp_lo = gen_reg_rtx (DFmode);
19291   fp_hi = gen_reg_rtx (DFmode);
19292
19293   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
19294
19295   real_ldexp (&TWO32r, &dconst1, 32);
19296   x = const_double_from_real_value (TWO32r, DFmode);
19297   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
19298
19299   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
19300
19301   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
19302                            0, OPTAB_DIRECT);
19303   if (x != target)
19304     emit_move_insn (target, x);
19305 }
19306
19307 /* Convert an unsigned SImode value into a SFmode, using only SSE.
19308    For x86_32, -mfpmath=sse, !optimize_size only.  */
19309 void
19310 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
19311 {
19312   REAL_VALUE_TYPE ONE16r;
19313   rtx fp_hi, fp_lo, int_hi, int_lo, x;
19314
19315   real_ldexp (&ONE16r, &dconst1, 16);
19316   x = const_double_from_real_value (ONE16r, SFmode);
19317   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
19318                                       NULL, 0, OPTAB_DIRECT);
19319   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
19320                                       NULL, 0, OPTAB_DIRECT);
19321   fp_hi = gen_reg_rtx (SFmode);
19322   fp_lo = gen_reg_rtx (SFmode);
19323   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
19324   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
19325   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
19326                                0, OPTAB_DIRECT);
19327   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
19328                                0, OPTAB_DIRECT);
19329   if (!rtx_equal_p (target, fp_hi))
19330     emit_move_insn (target, fp_hi);
19331 }
19332
19333 /* floatunsv{4,8}siv{4,8}sf2 expander.  Expand code to convert
19334    a vector of unsigned ints VAL to vector of floats TARGET.  */
19335
19336 void
19337 ix86_expand_vector_convert_uns_vsivsf (rtx target, rtx val)
19338 {
19339   rtx tmp[8];
19340   REAL_VALUE_TYPE TWO16r;
19341   machine_mode intmode = GET_MODE (val);
19342   machine_mode fltmode = GET_MODE (target);
19343   rtx (*cvt) (rtx, rtx);
19344
19345   if (intmode == V4SImode)
19346     cvt = gen_floatv4siv4sf2;
19347   else
19348     cvt = gen_floatv8siv8sf2;
19349   tmp[0] = ix86_build_const_vector (intmode, 1, GEN_INT (0xffff));
19350   tmp[0] = force_reg (intmode, tmp[0]);
19351   tmp[1] = expand_simple_binop (intmode, AND, val, tmp[0], NULL_RTX, 1,
19352                                 OPTAB_DIRECT);
19353   tmp[2] = expand_simple_binop (intmode, LSHIFTRT, val, GEN_INT (16),
19354                                 NULL_RTX, 1, OPTAB_DIRECT);
19355   tmp[3] = gen_reg_rtx (fltmode);
19356   emit_insn (cvt (tmp[3], tmp[1]));
19357   tmp[4] = gen_reg_rtx (fltmode);
19358   emit_insn (cvt (tmp[4], tmp[2]));
19359   real_ldexp (&TWO16r, &dconst1, 16);
19360   tmp[5] = const_double_from_real_value (TWO16r, SFmode);
19361   tmp[5] = force_reg (fltmode, ix86_build_const_vector (fltmode, 1, tmp[5]));
19362   tmp[6] = expand_simple_binop (fltmode, MULT, tmp[4], tmp[5], NULL_RTX, 1,
19363                                 OPTAB_DIRECT);
19364   tmp[7] = expand_simple_binop (fltmode, PLUS, tmp[3], tmp[6], target, 1,
19365                                 OPTAB_DIRECT);
19366   if (tmp[7] != target)
19367     emit_move_insn (target, tmp[7]);
19368 }
19369
19370 /* Adjust a V*SFmode/V*DFmode value VAL so that *sfix_trunc* resp. fix_trunc*
19371    pattern can be used on it instead of *ufix_trunc* resp. fixuns_trunc*.
19372    This is done by doing just signed conversion if < 0x1p31, and otherwise by
19373    subtracting 0x1p31 first and xoring in 0x80000000 from *XORP afterwards.  */
19374
19375 rtx
19376 ix86_expand_adjust_ufix_to_sfix_si (rtx val, rtx *xorp)
19377 {
19378   REAL_VALUE_TYPE TWO31r;
19379   rtx two31r, tmp[4];
19380   machine_mode mode = GET_MODE (val);
19381   machine_mode scalarmode = GET_MODE_INNER (mode);
19382   machine_mode intmode = GET_MODE_SIZE (mode) == 32 ? V8SImode : V4SImode;
19383   rtx (*cmp) (rtx, rtx, rtx, rtx);
19384   int i;
19385
19386   for (i = 0; i < 3; i++)
19387     tmp[i] = gen_reg_rtx (mode);
19388   real_ldexp (&TWO31r, &dconst1, 31);
19389   two31r = const_double_from_real_value (TWO31r, scalarmode);
19390   two31r = ix86_build_const_vector (mode, 1, two31r);
19391   two31r = force_reg (mode, two31r);
19392   switch (mode)
19393     {
19394     case V8SFmode: cmp = gen_avx_maskcmpv8sf3; break;
19395     case V4SFmode: cmp = gen_sse_maskcmpv4sf3; break;
19396     case V4DFmode: cmp = gen_avx_maskcmpv4df3; break;
19397     case V2DFmode: cmp = gen_sse2_maskcmpv2df3; break;
19398     default: gcc_unreachable ();
19399     }
19400   tmp[3] = gen_rtx_LE (mode, two31r, val);
19401   emit_insn (cmp (tmp[0], two31r, val, tmp[3]));
19402   tmp[1] = expand_simple_binop (mode, AND, tmp[0], two31r, tmp[1],
19403                                 0, OPTAB_DIRECT);
19404   if (intmode == V4SImode || TARGET_AVX2)
19405     *xorp = expand_simple_binop (intmode, ASHIFT,
19406                                  gen_lowpart (intmode, tmp[0]),
19407                                  GEN_INT (31), NULL_RTX, 0,
19408                                  OPTAB_DIRECT);
19409   else
19410     {
19411       rtx two31 = GEN_INT (HOST_WIDE_INT_1U << 31);
19412       two31 = ix86_build_const_vector (intmode, 1, two31);
19413       *xorp = expand_simple_binop (intmode, AND,
19414                                    gen_lowpart (intmode, tmp[0]),
19415                                    two31, NULL_RTX, 0,
19416                                    OPTAB_DIRECT);
19417     }
19418   return expand_simple_binop (mode, MINUS, val, tmp[1], tmp[2],
19419                               0, OPTAB_DIRECT);
19420 }
19421
19422 /* A subroutine of ix86_build_signbit_mask.  If VECT is true,
19423    then replicate the value for all elements of the vector
19424    register.  */
19425
19426 rtx
19427 ix86_build_const_vector (machine_mode mode, bool vect, rtx value)
19428 {
19429   int i, n_elt;
19430   rtvec v;
19431   machine_mode scalar_mode;
19432
19433   switch (mode)
19434     {
19435     case V64QImode:
19436     case V32QImode:
19437     case V16QImode:
19438     case V32HImode:
19439     case V16HImode:
19440     case V8HImode:
19441     case V16SImode:
19442     case V8SImode:
19443     case V4SImode:
19444     case V8DImode:
19445     case V4DImode:
19446     case V2DImode:
19447       gcc_assert (vect);
19448     case V16SFmode:
19449     case V8SFmode:
19450     case V4SFmode:
19451     case V8DFmode:
19452     case V4DFmode:
19453     case V2DFmode:
19454       n_elt = GET_MODE_NUNITS (mode);
19455       v = rtvec_alloc (n_elt);
19456       scalar_mode = GET_MODE_INNER (mode);
19457
19458       RTVEC_ELT (v, 0) = value;
19459
19460       for (i = 1; i < n_elt; ++i)
19461         RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode);
19462
19463       return gen_rtx_CONST_VECTOR (mode, v);
19464
19465     default:
19466       gcc_unreachable ();
19467     }
19468 }
19469
19470 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
19471    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
19472    for an SSE register.  If VECT is true, then replicate the mask for
19473    all elements of the vector register.  If INVERT is true, then create
19474    a mask excluding the sign bit.  */
19475
19476 rtx
19477 ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert)
19478 {
19479   machine_mode vec_mode, imode;
19480   wide_int w;
19481   rtx mask, v;
19482
19483   switch (mode)
19484     {
19485     case V16SImode:
19486     case V16SFmode:
19487     case V8SImode:
19488     case V4SImode:
19489     case V8SFmode:
19490     case V4SFmode:
19491       vec_mode = mode;
19492       mode = GET_MODE_INNER (mode);
19493       imode = SImode;
19494       break;
19495
19496     case V8DImode:
19497     case V4DImode:
19498     case V2DImode:
19499     case V8DFmode:
19500     case V4DFmode:
19501     case V2DFmode:
19502       vec_mode = mode;
19503       mode = GET_MODE_INNER (mode);
19504       imode = DImode;
19505       break;
19506
19507     case TImode:
19508     case TFmode:
19509       vec_mode = VOIDmode;
19510       imode = TImode;
19511       break;
19512
19513     default:
19514       gcc_unreachable ();
19515     }
19516
19517   w = wi::set_bit_in_zero (GET_MODE_BITSIZE (mode) - 1,
19518                            GET_MODE_BITSIZE (mode));
19519   if (invert)
19520     w = wi::bit_not (w);
19521
19522   /* Force this value into the low part of a fp vector constant.  */
19523   mask = immed_wide_int_const (w, imode);
19524   mask = gen_lowpart (mode, mask);
19525
19526   if (vec_mode == VOIDmode)
19527     return force_reg (mode, mask);
19528
19529   v = ix86_build_const_vector (vec_mode, vect, mask);
19530   return force_reg (vec_mode, v);
19531 }
19532
19533 /* Generate code for floating point ABS or NEG.  */
19534
19535 void
19536 ix86_expand_fp_absneg_operator (enum rtx_code code, machine_mode mode,
19537                                 rtx operands[])
19538 {
19539   rtx mask, set, dst, src;
19540   bool use_sse = false;
19541   bool vector_mode = VECTOR_MODE_P (mode);
19542   machine_mode vmode = mode;
19543
19544   if (vector_mode)
19545     use_sse = true;
19546   else if (mode == TFmode)
19547     use_sse = true;
19548   else if (TARGET_SSE_MATH)
19549     {
19550       use_sse = SSE_FLOAT_MODE_P (mode);
19551       if (mode == SFmode)
19552         vmode = V4SFmode;
19553       else if (mode == DFmode)
19554         vmode = V2DFmode;
19555     }
19556
19557   /* NEG and ABS performed with SSE use bitwise mask operations.
19558      Create the appropriate mask now.  */
19559   if (use_sse)
19560     mask = ix86_build_signbit_mask (vmode, vector_mode, code == ABS);
19561   else
19562     mask = NULL_RTX;
19563
19564   dst = operands[0];
19565   src = operands[1];
19566
19567   set = gen_rtx_fmt_e (code, mode, src);
19568   set = gen_rtx_SET (dst, set);
19569
19570   if (mask)
19571     {
19572       rtx use, clob;
19573       rtvec par;
19574
19575       use = gen_rtx_USE (VOIDmode, mask);
19576       if (vector_mode)
19577         par = gen_rtvec (2, set, use);
19578       else
19579         {
19580           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
19581           par = gen_rtvec (3, set, use, clob);
19582         }
19583       emit_insn (gen_rtx_PARALLEL (VOIDmode, par));
19584     }
19585   else
19586     emit_insn (set);
19587 }
19588
19589 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
19590
19591 void
19592 ix86_expand_copysign (rtx operands[])
19593 {
19594   machine_mode mode, vmode;
19595   rtx dest, op0, op1, mask, nmask;
19596
19597   dest = operands[0];
19598   op0 = operands[1];
19599   op1 = operands[2];
19600
19601   mode = GET_MODE (dest);
19602
19603   if (mode == SFmode)
19604     vmode = V4SFmode;
19605   else if (mode == DFmode)
19606     vmode = V2DFmode;
19607   else
19608     vmode = mode;
19609
19610   if (CONST_DOUBLE_P (op0))
19611     {
19612       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
19613
19614       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
19615         op0 = simplify_unary_operation (ABS, mode, op0, mode);
19616
19617       if (mode == SFmode || mode == DFmode)
19618         {
19619           if (op0 == CONST0_RTX (mode))
19620             op0 = CONST0_RTX (vmode);
19621           else
19622             {
19623               rtx v = ix86_build_const_vector (vmode, false, op0);
19624
19625               op0 = force_reg (vmode, v);
19626             }
19627         }
19628       else if (op0 != CONST0_RTX (mode))
19629         op0 = force_reg (mode, op0);
19630
19631       mask = ix86_build_signbit_mask (vmode, 0, 0);
19632
19633       if (mode == SFmode)
19634         copysign_insn = gen_copysignsf3_const;
19635       else if (mode == DFmode)
19636         copysign_insn = gen_copysigndf3_const;
19637       else
19638         copysign_insn = gen_copysigntf3_const;
19639
19640       emit_insn (copysign_insn (dest, op0, op1, mask));
19641     }
19642   else
19643     {
19644       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
19645
19646       nmask = ix86_build_signbit_mask (vmode, 0, 1);
19647       mask = ix86_build_signbit_mask (vmode, 0, 0);
19648
19649       if (mode == SFmode)
19650         copysign_insn = gen_copysignsf3_var;
19651       else if (mode == DFmode)
19652         copysign_insn = gen_copysigndf3_var;
19653       else
19654         copysign_insn = gen_copysigntf3_var;
19655
19656       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
19657     }
19658 }
19659
19660 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
19661    be a constant, and so has already been expanded into a vector constant.  */
19662
19663 void
19664 ix86_split_copysign_const (rtx operands[])
19665 {
19666   machine_mode mode, vmode;
19667   rtx dest, op0, mask, x;
19668
19669   dest = operands[0];
19670   op0 = operands[1];
19671   mask = operands[3];
19672
19673   mode = GET_MODE (dest);
19674   vmode = GET_MODE (mask);
19675
19676   dest = simplify_gen_subreg (vmode, dest, mode, 0);
19677   x = gen_rtx_AND (vmode, dest, mask);
19678   emit_insn (gen_rtx_SET (dest, x));
19679
19680   if (op0 != CONST0_RTX (vmode))
19681     {
19682       x = gen_rtx_IOR (vmode, dest, op0);
19683       emit_insn (gen_rtx_SET (dest, x));
19684     }
19685 }
19686
19687 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
19688    so we have to do two masks.  */
19689
19690 void
19691 ix86_split_copysign_var (rtx operands[])
19692 {
19693   machine_mode mode, vmode;
19694   rtx dest, scratch, op0, op1, mask, nmask, x;
19695
19696   dest = operands[0];
19697   scratch = operands[1];
19698   op0 = operands[2];
19699   op1 = operands[3];
19700   nmask = operands[4];
19701   mask = operands[5];
19702
19703   mode = GET_MODE (dest);
19704   vmode = GET_MODE (mask);
19705
19706   if (rtx_equal_p (op0, op1))
19707     {
19708       /* Shouldn't happen often (it's useless, obviously), but when it does
19709          we'd generate incorrect code if we continue below.  */
19710       emit_move_insn (dest, op0);
19711       return;
19712     }
19713
19714   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
19715     {
19716       gcc_assert (REGNO (op1) == REGNO (scratch));
19717
19718       x = gen_rtx_AND (vmode, scratch, mask);
19719       emit_insn (gen_rtx_SET (scratch, x));
19720
19721       dest = mask;
19722       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
19723       x = gen_rtx_NOT (vmode, dest);
19724       x = gen_rtx_AND (vmode, x, op0);
19725       emit_insn (gen_rtx_SET (dest, x));
19726     }
19727   else
19728     {
19729       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
19730         {
19731           x = gen_rtx_AND (vmode, scratch, mask);
19732         }
19733       else                                              /* alternative 2,4 */
19734         {
19735           gcc_assert (REGNO (mask) == REGNO (scratch));
19736           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
19737           x = gen_rtx_AND (vmode, scratch, op1);
19738         }
19739       emit_insn (gen_rtx_SET (scratch, x));
19740
19741       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
19742         {
19743           dest = simplify_gen_subreg (vmode, op0, mode, 0);
19744           x = gen_rtx_AND (vmode, dest, nmask);
19745         }
19746       else                                              /* alternative 3,4 */
19747         {
19748           gcc_assert (REGNO (nmask) == REGNO (dest));
19749           dest = nmask;
19750           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
19751           x = gen_rtx_AND (vmode, dest, op0);
19752         }
19753       emit_insn (gen_rtx_SET (dest, x));
19754     }
19755
19756   x = gen_rtx_IOR (vmode, dest, scratch);
19757   emit_insn (gen_rtx_SET (dest, x));
19758 }
19759
19760 /* Return TRUE or FALSE depending on whether the first SET in INSN
19761    has source and destination with matching CC modes, and that the
19762    CC mode is at least as constrained as REQ_MODE.  */
19763
19764 bool
19765 ix86_match_ccmode (rtx insn, machine_mode req_mode)
19766 {
19767   rtx set;
19768   machine_mode set_mode;
19769
19770   set = PATTERN (insn);
19771   if (GET_CODE (set) == PARALLEL)
19772     set = XVECEXP (set, 0, 0);
19773   gcc_assert (GET_CODE (set) == SET);
19774   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
19775
19776   set_mode = GET_MODE (SET_DEST (set));
19777   switch (set_mode)
19778     {
19779     case CCNOmode:
19780       if (req_mode != CCNOmode
19781           && (req_mode != CCmode
19782               || XEXP (SET_SRC (set), 1) != const0_rtx))
19783         return false;
19784       break;
19785     case CCmode:
19786       if (req_mode == CCGCmode)
19787         return false;
19788       /* FALLTHRU */
19789     case CCGCmode:
19790       if (req_mode == CCGOCmode || req_mode == CCNOmode)
19791         return false;
19792       /* FALLTHRU */
19793     case CCGOCmode:
19794       if (req_mode == CCZmode)
19795         return false;
19796       /* FALLTHRU */
19797     case CCZmode:
19798       break;
19799
19800     case CCAmode:
19801     case CCCmode:
19802     case CCOmode:
19803     case CCPmode:
19804     case CCSmode:
19805       if (set_mode != req_mode)
19806         return false;
19807       break;
19808
19809     default:
19810       gcc_unreachable ();
19811     }
19812
19813   return GET_MODE (SET_SRC (set)) == set_mode;
19814 }
19815
19816 /* Generate insn patterns to do an integer compare of OPERANDS.  */
19817
19818 static rtx
19819 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
19820 {
19821   machine_mode cmpmode;
19822   rtx tmp, flags;
19823
19824   cmpmode = SELECT_CC_MODE (code, op0, op1);
19825   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
19826
19827   /* This is very simple, but making the interface the same as in the
19828      FP case makes the rest of the code easier.  */
19829   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
19830   emit_insn (gen_rtx_SET (flags, tmp));
19831
19832   /* Return the test that should be put into the flags user, i.e.
19833      the bcc, scc, or cmov instruction.  */
19834   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
19835 }
19836
19837 /* Figure out whether to use ordered or unordered fp comparisons.
19838    Return the appropriate mode to use.  */
19839
19840 machine_mode
19841 ix86_fp_compare_mode (enum rtx_code)
19842 {
19843   /* ??? In order to make all comparisons reversible, we do all comparisons
19844      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
19845      all forms trapping and nontrapping comparisons, we can make inequality
19846      comparisons trapping again, since it results in better code when using
19847      FCOM based compares.  */
19848   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
19849 }
19850
19851 machine_mode
19852 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
19853 {
19854   machine_mode mode = GET_MODE (op0);
19855
19856   if (SCALAR_FLOAT_MODE_P (mode))
19857     {
19858       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
19859       return ix86_fp_compare_mode (code);
19860     }
19861
19862   switch (code)
19863     {
19864       /* Only zero flag is needed.  */
19865     case EQ:                    /* ZF=0 */
19866     case NE:                    /* ZF!=0 */
19867       return CCZmode;
19868       /* Codes needing carry flag.  */
19869     case GEU:                   /* CF=0 */
19870     case LTU:                   /* CF=1 */
19871       /* Detect overflow checks.  They need just the carry flag.  */
19872       if (GET_CODE (op0) == PLUS
19873           && rtx_equal_p (op1, XEXP (op0, 0)))
19874         return CCCmode;
19875       else
19876         return CCmode;
19877     case GTU:                   /* CF=0 & ZF=0 */
19878     case LEU:                   /* CF=1 | ZF=1 */
19879       return CCmode;
19880       /* Codes possibly doable only with sign flag when
19881          comparing against zero.  */
19882     case GE:                    /* SF=OF   or   SF=0 */
19883     case LT:                    /* SF<>OF  or   SF=1 */
19884       if (op1 == const0_rtx)
19885         return CCGOCmode;
19886       else
19887         /* For other cases Carry flag is not required.  */
19888         return CCGCmode;
19889       /* Codes doable only with sign flag when comparing
19890          against zero, but we miss jump instruction for it
19891          so we need to use relational tests against overflow
19892          that thus needs to be zero.  */
19893     case GT:                    /* ZF=0 & SF=OF */
19894     case LE:                    /* ZF=1 | SF<>OF */
19895       if (op1 == const0_rtx)
19896         return CCNOmode;
19897       else
19898         return CCGCmode;
19899       /* strcmp pattern do (use flags) and combine may ask us for proper
19900          mode.  */
19901     case USE:
19902       return CCmode;
19903     default:
19904       gcc_unreachable ();
19905     }
19906 }
19907
19908 /* Return the fixed registers used for condition codes.  */
19909
19910 static bool
19911 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
19912 {
19913   *p1 = FLAGS_REG;
19914   *p2 = FPSR_REG;
19915   return true;
19916 }
19917
19918 /* If two condition code modes are compatible, return a condition code
19919    mode which is compatible with both.  Otherwise, return
19920    VOIDmode.  */
19921
19922 static machine_mode
19923 ix86_cc_modes_compatible (machine_mode m1, machine_mode m2)
19924 {
19925   if (m1 == m2)
19926     return m1;
19927
19928   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
19929     return VOIDmode;
19930
19931   if ((m1 == CCGCmode && m2 == CCGOCmode)
19932       || (m1 == CCGOCmode && m2 == CCGCmode))
19933     return CCGCmode;
19934
19935   if (m1 == CCZmode && (m2 == CCGCmode || m2 == CCGOCmode))
19936     return m2;
19937   else if (m2 == CCZmode && (m1 == CCGCmode || m1 == CCGOCmode))
19938     return m1;
19939
19940   switch (m1)
19941     {
19942     default:
19943       gcc_unreachable ();
19944
19945     case CCmode:
19946     case CCGCmode:
19947     case CCGOCmode:
19948     case CCNOmode:
19949     case CCAmode:
19950     case CCCmode:
19951     case CCOmode:
19952     case CCPmode:
19953     case CCSmode:
19954     case CCZmode:
19955       switch (m2)
19956         {
19957         default:
19958           return VOIDmode;
19959
19960         case CCmode:
19961         case CCGCmode:
19962         case CCGOCmode:
19963         case CCNOmode:
19964         case CCAmode:
19965         case CCCmode:
19966         case CCOmode:
19967         case CCPmode:
19968         case CCSmode:
19969         case CCZmode:
19970           return CCmode;
19971         }
19972
19973     case CCFPmode:
19974     case CCFPUmode:
19975       /* These are only compatible with themselves, which we already
19976          checked above.  */
19977       return VOIDmode;
19978     }
19979 }
19980
19981
19982 /* Return a comparison we can do and that it is equivalent to
19983    swap_condition (code) apart possibly from orderedness.
19984    But, never change orderedness if TARGET_IEEE_FP, returning
19985    UNKNOWN in that case if necessary.  */
19986
19987 static enum rtx_code
19988 ix86_fp_swap_condition (enum rtx_code code)
19989 {
19990   switch (code)
19991     {
19992     case GT:                   /* GTU - CF=0 & ZF=0 */
19993       return TARGET_IEEE_FP ? UNKNOWN : UNLT;
19994     case GE:                   /* GEU - CF=0 */
19995       return TARGET_IEEE_FP ? UNKNOWN : UNLE;
19996     case UNLT:                 /* LTU - CF=1 */
19997       return TARGET_IEEE_FP ? UNKNOWN : GT;
19998     case UNLE:                 /* LEU - CF=1 | ZF=1 */
19999       return TARGET_IEEE_FP ? UNKNOWN : GE;
20000     default:
20001       return swap_condition (code);
20002     }
20003 }
20004
20005 /* Return cost of comparison CODE using the best strategy for performance.
20006    All following functions do use number of instructions as a cost metrics.
20007    In future this should be tweaked to compute bytes for optimize_size and
20008    take into account performance of various instructions on various CPUs.  */
20009
20010 static int
20011 ix86_fp_comparison_cost (enum rtx_code code)
20012 {
20013   int arith_cost;
20014
20015   /* The cost of code using bit-twiddling on %ah.  */
20016   switch (code)
20017     {
20018     case UNLE:
20019     case UNLT:
20020     case LTGT:
20021     case GT:
20022     case GE:
20023     case UNORDERED:
20024     case ORDERED:
20025     case UNEQ:
20026       arith_cost = 4;
20027       break;
20028     case LT:
20029     case NE:
20030     case EQ:
20031     case UNGE:
20032       arith_cost = TARGET_IEEE_FP ? 5 : 4;
20033       break;
20034     case LE:
20035     case UNGT:
20036       arith_cost = TARGET_IEEE_FP ? 6 : 4;
20037       break;
20038     default:
20039       gcc_unreachable ();
20040     }
20041
20042   switch (ix86_fp_comparison_strategy (code))
20043     {
20044     case IX86_FPCMP_COMI:
20045       return arith_cost > 4 ? 3 : 2;
20046     case IX86_FPCMP_SAHF:
20047       return arith_cost > 4 ? 4 : 3;
20048     default:
20049       return arith_cost;
20050     }
20051 }
20052
20053 /* Return strategy to use for floating-point.  We assume that fcomi is always
20054    preferrable where available, since that is also true when looking at size
20055    (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test).  */
20056
20057 enum ix86_fpcmp_strategy
20058 ix86_fp_comparison_strategy (enum rtx_code)
20059 {
20060   /* Do fcomi/sahf based test when profitable.  */
20061
20062   if (TARGET_CMOVE)
20063     return IX86_FPCMP_COMI;
20064
20065   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
20066     return IX86_FPCMP_SAHF;
20067
20068   return IX86_FPCMP_ARITH;
20069 }
20070
20071 /* Swap, force into registers, or otherwise massage the two operands
20072    to a fp comparison.  The operands are updated in place; the new
20073    comparison code is returned.  */
20074
20075 static enum rtx_code
20076 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
20077 {
20078   machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
20079   rtx op0 = *pop0, op1 = *pop1;
20080   machine_mode op_mode = GET_MODE (op0);
20081   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
20082
20083   /* All of the unordered compare instructions only work on registers.
20084      The same is true of the fcomi compare instructions.  The XFmode
20085      compare instructions require registers except when comparing
20086      against zero or when converting operand 1 from fixed point to
20087      floating point.  */
20088
20089   if (!is_sse
20090       && (fpcmp_mode == CCFPUmode
20091           || (op_mode == XFmode
20092               && ! (standard_80387_constant_p (op0) == 1
20093                     || standard_80387_constant_p (op1) == 1)
20094               && GET_CODE (op1) != FLOAT)
20095           || ix86_fp_comparison_strategy (code) == IX86_FPCMP_COMI))
20096     {
20097       op0 = force_reg (op_mode, op0);
20098       op1 = force_reg (op_mode, op1);
20099     }
20100   else
20101     {
20102       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
20103          things around if they appear profitable, otherwise force op0
20104          into a register.  */
20105
20106       if (standard_80387_constant_p (op0) == 0
20107           || (MEM_P (op0)
20108               && ! (standard_80387_constant_p (op1) == 0
20109                     || MEM_P (op1))))
20110         {
20111           enum rtx_code new_code = ix86_fp_swap_condition (code);
20112           if (new_code != UNKNOWN)
20113             {
20114               std::swap (op0, op1);
20115               code = new_code;
20116             }
20117         }
20118
20119       if (!REG_P (op0))
20120         op0 = force_reg (op_mode, op0);
20121
20122       if (CONSTANT_P (op1))
20123         {
20124           int tmp = standard_80387_constant_p (op1);
20125           if (tmp == 0)
20126             op1 = validize_mem (force_const_mem (op_mode, op1));
20127           else if (tmp == 1)
20128             {
20129               if (TARGET_CMOVE)
20130                 op1 = force_reg (op_mode, op1);
20131             }
20132           else
20133             op1 = force_reg (op_mode, op1);
20134         }
20135     }
20136
20137   /* Try to rearrange the comparison to make it cheaper.  */
20138   if (ix86_fp_comparison_cost (code)
20139       > ix86_fp_comparison_cost (swap_condition (code))
20140       && (REG_P (op1) || can_create_pseudo_p ()))
20141     {
20142       std::swap (op0, op1);
20143       code = swap_condition (code);
20144       if (!REG_P (op0))
20145         op0 = force_reg (op_mode, op0);
20146     }
20147
20148   *pop0 = op0;
20149   *pop1 = op1;
20150   return code;
20151 }
20152
20153 /* Convert comparison codes we use to represent FP comparison to integer
20154    code that will result in proper branch.  Return UNKNOWN if no such code
20155    is available.  */
20156
20157 enum rtx_code
20158 ix86_fp_compare_code_to_integer (enum rtx_code code)
20159 {
20160   switch (code)
20161     {
20162     case GT:
20163       return GTU;
20164     case GE:
20165       return GEU;
20166     case ORDERED:
20167     case UNORDERED:
20168       return code;
20169       break;
20170     case UNEQ:
20171       return EQ;
20172       break;
20173     case UNLT:
20174       return LTU;
20175       break;
20176     case UNLE:
20177       return LEU;
20178       break;
20179     case LTGT:
20180       return NE;
20181       break;
20182     default:
20183       return UNKNOWN;
20184     }
20185 }
20186
20187 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
20188
20189 static rtx
20190 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch)
20191 {
20192   machine_mode fpcmp_mode, intcmp_mode;
20193   rtx tmp, tmp2;
20194
20195   fpcmp_mode = ix86_fp_compare_mode (code);
20196   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
20197
20198   /* Do fcomi/sahf based test when profitable.  */
20199   switch (ix86_fp_comparison_strategy (code))
20200     {
20201     case IX86_FPCMP_COMI:
20202       intcmp_mode = fpcmp_mode;
20203       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20204       tmp = gen_rtx_SET (gen_rtx_REG (fpcmp_mode, FLAGS_REG), tmp);
20205       emit_insn (tmp);
20206       break;
20207
20208     case IX86_FPCMP_SAHF:
20209       intcmp_mode = fpcmp_mode;
20210       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20211       tmp = gen_rtx_SET (gen_rtx_REG (fpcmp_mode, FLAGS_REG), tmp);
20212
20213       if (!scratch)
20214         scratch = gen_reg_rtx (HImode);
20215       tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
20216       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
20217       break;
20218
20219     case IX86_FPCMP_ARITH:
20220       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
20221       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20222       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
20223       if (!scratch)
20224         scratch = gen_reg_rtx (HImode);
20225       emit_insn (gen_rtx_SET (scratch, tmp2));
20226
20227       /* In the unordered case, we have to check C2 for NaN's, which
20228          doesn't happen to work out to anything nice combination-wise.
20229          So do some bit twiddling on the value we've got in AH to come
20230          up with an appropriate set of condition codes.  */
20231
20232       intcmp_mode = CCNOmode;
20233       switch (code)
20234         {
20235         case GT:
20236         case UNGT:
20237           if (code == GT || !TARGET_IEEE_FP)
20238             {
20239               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
20240               code = EQ;
20241             }
20242           else
20243             {
20244               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20245               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
20246               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
20247               intcmp_mode = CCmode;
20248               code = GEU;
20249             }
20250           break;
20251         case LT:
20252         case UNLT:
20253           if (code == LT && TARGET_IEEE_FP)
20254             {
20255               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20256               emit_insn (gen_cmpqi_ext_3 (scratch, const1_rtx));
20257               intcmp_mode = CCmode;
20258               code = EQ;
20259             }
20260           else
20261             {
20262               emit_insn (gen_testqi_ext_ccno_0 (scratch, const1_rtx));
20263               code = NE;
20264             }
20265           break;
20266         case GE:
20267         case UNGE:
20268           if (code == GE || !TARGET_IEEE_FP)
20269             {
20270               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
20271               code = EQ;
20272             }
20273           else
20274             {
20275               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20276               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch, const1_rtx));
20277               code = NE;
20278             }
20279           break;
20280         case LE:
20281         case UNLE:
20282           if (code == LE && TARGET_IEEE_FP)
20283             {
20284               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20285               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
20286               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
20287               intcmp_mode = CCmode;
20288               code = LTU;
20289             }
20290           else
20291             {
20292               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
20293               code = NE;
20294             }
20295           break;
20296         case EQ:
20297         case UNEQ:
20298           if (code == EQ && TARGET_IEEE_FP)
20299             {
20300               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20301               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
20302               intcmp_mode = CCmode;
20303               code = EQ;
20304             }
20305           else
20306             {
20307               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
20308               code = NE;
20309             }
20310           break;
20311         case NE:
20312         case LTGT:
20313           if (code == NE && TARGET_IEEE_FP)
20314             {
20315               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20316               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
20317                                              GEN_INT (0x40)));
20318               code = NE;
20319             }
20320           else
20321             {
20322               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
20323               code = EQ;
20324             }
20325           break;
20326
20327         case UNORDERED:
20328           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
20329           code = NE;
20330           break;
20331         case ORDERED:
20332           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
20333           code = EQ;
20334           break;
20335
20336         default:
20337           gcc_unreachable ();
20338         }
20339         break;
20340
20341     default:
20342       gcc_unreachable();
20343     }
20344
20345   /* Return the test that should be put into the flags user, i.e.
20346      the bcc, scc, or cmov instruction.  */
20347   return gen_rtx_fmt_ee (code, VOIDmode,
20348                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
20349                          const0_rtx);
20350 }
20351
20352 static rtx
20353 ix86_expand_compare (enum rtx_code code, rtx op0, rtx op1)
20354 {
20355   rtx ret;
20356
20357   if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
20358     ret = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
20359
20360   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
20361     {
20362       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
20363       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
20364     }
20365   else
20366     ret = ix86_expand_int_compare (code, op0, op1);
20367
20368   return ret;
20369 }
20370
20371 void
20372 ix86_expand_branch (enum rtx_code code, rtx op0, rtx op1, rtx label)
20373 {
20374   machine_mode mode = GET_MODE (op0);
20375   rtx tmp;
20376
20377   switch (mode)
20378     {
20379     case SFmode:
20380     case DFmode:
20381     case XFmode:
20382     case QImode:
20383     case HImode:
20384     case SImode:
20385       simple:
20386       tmp = ix86_expand_compare (code, op0, op1);
20387       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
20388                                   gen_rtx_LABEL_REF (VOIDmode, label),
20389                                   pc_rtx);
20390       emit_jump_insn (gen_rtx_SET (pc_rtx, tmp));
20391       return;
20392
20393     case DImode:
20394       if (TARGET_64BIT)
20395         goto simple;
20396     case TImode:
20397       /* Expand DImode branch into multiple compare+branch.  */
20398       {
20399         rtx lo[2], hi[2];
20400         rtx_code_label *label2;
20401         enum rtx_code code1, code2, code3;
20402         machine_mode submode;
20403
20404         if (CONSTANT_P (op0) && !CONSTANT_P (op1))
20405           {
20406             std::swap (op0, op1);
20407             code = swap_condition (code);
20408           }
20409
20410         split_double_mode (mode, &op0, 1, lo+0, hi+0);
20411         split_double_mode (mode, &op1, 1, lo+1, hi+1);
20412
20413         submode = mode == DImode ? SImode : DImode;
20414
20415         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
20416            avoid two branches.  This costs one extra insn, so disable when
20417            optimizing for size.  */
20418
20419         if ((code == EQ || code == NE)
20420             && (!optimize_insn_for_size_p ()
20421                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
20422           {
20423             rtx xor0, xor1;
20424
20425             xor1 = hi[0];
20426             if (hi[1] != const0_rtx)
20427               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
20428                                    NULL_RTX, 0, OPTAB_WIDEN);
20429
20430             xor0 = lo[0];
20431             if (lo[1] != const0_rtx)
20432               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
20433                                    NULL_RTX, 0, OPTAB_WIDEN);
20434
20435             tmp = expand_binop (submode, ior_optab, xor1, xor0,
20436                                 NULL_RTX, 0, OPTAB_WIDEN);
20437
20438             ix86_expand_branch (code, tmp, const0_rtx, label);
20439             return;
20440           }
20441
20442         /* Otherwise, if we are doing less-than or greater-or-equal-than,
20443            op1 is a constant and the low word is zero, then we can just
20444            examine the high word.  Similarly for low word -1 and
20445            less-or-equal-than or greater-than.  */
20446
20447         if (CONST_INT_P (hi[1]))
20448           switch (code)
20449             {
20450             case LT: case LTU: case GE: case GEU:
20451               if (lo[1] == const0_rtx)
20452                 {
20453                   ix86_expand_branch (code, hi[0], hi[1], label);
20454                   return;
20455                 }
20456               break;
20457             case LE: case LEU: case GT: case GTU:
20458               if (lo[1] == constm1_rtx)
20459                 {
20460                   ix86_expand_branch (code, hi[0], hi[1], label);
20461                   return;
20462                 }
20463               break;
20464             default:
20465               break;
20466             }
20467
20468         /* Otherwise, we need two or three jumps.  */
20469
20470         label2 = gen_label_rtx ();
20471
20472         code1 = code;
20473         code2 = swap_condition (code);
20474         code3 = unsigned_condition (code);
20475
20476         switch (code)
20477           {
20478           case LT: case GT: case LTU: case GTU:
20479             break;
20480
20481           case LE:   code1 = LT;  code2 = GT;  break;
20482           case GE:   code1 = GT;  code2 = LT;  break;
20483           case LEU:  code1 = LTU; code2 = GTU; break;
20484           case GEU:  code1 = GTU; code2 = LTU; break;
20485
20486           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
20487           case NE:   code2 = UNKNOWN; break;
20488
20489           default:
20490             gcc_unreachable ();
20491           }
20492
20493         /*
20494          * a < b =>
20495          *    if (hi(a) < hi(b)) goto true;
20496          *    if (hi(a) > hi(b)) goto false;
20497          *    if (lo(a) < lo(b)) goto true;
20498          *  false:
20499          */
20500
20501         if (code1 != UNKNOWN)
20502           ix86_expand_branch (code1, hi[0], hi[1], label);
20503         if (code2 != UNKNOWN)
20504           ix86_expand_branch (code2, hi[0], hi[1], label2);
20505
20506         ix86_expand_branch (code3, lo[0], lo[1], label);
20507
20508         if (code2 != UNKNOWN)
20509           emit_label (label2);
20510         return;
20511       }
20512
20513     default:
20514       gcc_assert (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC);
20515       goto simple;
20516     }
20517 }
20518
20519 /* Split branch based on floating point condition.  */
20520 void
20521 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
20522                       rtx target1, rtx target2, rtx tmp)
20523 {
20524   rtx condition;
20525   rtx i;
20526
20527   if (target2 != pc_rtx)
20528     {
20529       std::swap (target1, target2);
20530       code = reverse_condition_maybe_unordered (code);
20531     }
20532
20533   condition = ix86_expand_fp_compare (code, op1, op2,
20534                                       tmp);
20535
20536   i = emit_jump_insn (gen_rtx_SET
20537                       (pc_rtx,
20538                        gen_rtx_IF_THEN_ELSE (VOIDmode,
20539                                              condition, target1, target2)));
20540   if (split_branch_probability >= 0)
20541     add_int_reg_note (i, REG_BR_PROB, split_branch_probability);
20542 }
20543
20544 void
20545 ix86_expand_setcc (rtx dest, enum rtx_code code, rtx op0, rtx op1)
20546 {
20547   rtx ret;
20548
20549   gcc_assert (GET_MODE (dest) == QImode);
20550
20551   ret = ix86_expand_compare (code, op0, op1);
20552   PUT_MODE (ret, QImode);
20553   emit_insn (gen_rtx_SET (dest, ret));
20554 }
20555
20556 /* Expand comparison setting or clearing carry flag.  Return true when
20557    successful and set pop for the operation.  */
20558 static bool
20559 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
20560 {
20561   machine_mode mode =
20562     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
20563
20564   /* Do not handle double-mode compares that go through special path.  */
20565   if (mode == (TARGET_64BIT ? TImode : DImode))
20566     return false;
20567
20568   if (SCALAR_FLOAT_MODE_P (mode))
20569     {
20570       rtx compare_op;
20571       rtx_insn *compare_seq;
20572
20573       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
20574
20575       /* Shortcut:  following common codes never translate
20576          into carry flag compares.  */
20577       if (code == EQ || code == NE || code == UNEQ || code == LTGT
20578           || code == ORDERED || code == UNORDERED)
20579         return false;
20580
20581       /* These comparisons require zero flag; swap operands so they won't.  */
20582       if ((code == GT || code == UNLE || code == LE || code == UNGT)
20583           && !TARGET_IEEE_FP)
20584         {
20585           std::swap (op0, op1);
20586           code = swap_condition (code);
20587         }
20588
20589       /* Try to expand the comparison and verify that we end up with
20590          carry flag based comparison.  This fails to be true only when
20591          we decide to expand comparison using arithmetic that is not
20592          too common scenario.  */
20593       start_sequence ();
20594       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
20595       compare_seq = get_insns ();
20596       end_sequence ();
20597
20598       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
20599           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
20600         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
20601       else
20602         code = GET_CODE (compare_op);
20603
20604       if (code != LTU && code != GEU)
20605         return false;
20606
20607       emit_insn (compare_seq);
20608       *pop = compare_op;
20609       return true;
20610     }
20611
20612   if (!INTEGRAL_MODE_P (mode))
20613     return false;
20614
20615   switch (code)
20616     {
20617     case LTU:
20618     case GEU:
20619       break;
20620
20621     /* Convert a==0 into (unsigned)a<1.  */
20622     case EQ:
20623     case NE:
20624       if (op1 != const0_rtx)
20625         return false;
20626       op1 = const1_rtx;
20627       code = (code == EQ ? LTU : GEU);
20628       break;
20629
20630     /* Convert a>b into b<a or a>=b-1.  */
20631     case GTU:
20632     case LEU:
20633       if (CONST_INT_P (op1))
20634         {
20635           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
20636           /* Bail out on overflow.  We still can swap operands but that
20637              would force loading of the constant into register.  */
20638           if (op1 == const0_rtx
20639               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
20640             return false;
20641           code = (code == GTU ? GEU : LTU);
20642         }
20643       else
20644         {
20645           std::swap (op0, op1);
20646           code = (code == GTU ? LTU : GEU);
20647         }
20648       break;
20649
20650     /* Convert a>=0 into (unsigned)a<0x80000000.  */
20651     case LT:
20652     case GE:
20653       if (mode == DImode || op1 != const0_rtx)
20654         return false;
20655       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
20656       code = (code == LT ? GEU : LTU);
20657       break;
20658     case LE:
20659     case GT:
20660       if (mode == DImode || op1 != constm1_rtx)
20661         return false;
20662       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
20663       code = (code == LE ? GEU : LTU);
20664       break;
20665
20666     default:
20667       return false;
20668     }
20669   /* Swapping operands may cause constant to appear as first operand.  */
20670   if (!nonimmediate_operand (op0, VOIDmode))
20671     {
20672       if (!can_create_pseudo_p ())
20673         return false;
20674       op0 = force_reg (mode, op0);
20675     }
20676   *pop = ix86_expand_compare (code, op0, op1);
20677   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
20678   return true;
20679 }
20680
20681 bool
20682 ix86_expand_int_movcc (rtx operands[])
20683 {
20684   enum rtx_code code = GET_CODE (operands[1]), compare_code;
20685   rtx_insn *compare_seq;
20686   rtx compare_op;
20687   machine_mode mode = GET_MODE (operands[0]);
20688   bool sign_bit_compare_p = false;
20689   rtx op0 = XEXP (operands[1], 0);
20690   rtx op1 = XEXP (operands[1], 1);
20691
20692   if (GET_MODE (op0) == TImode
20693       || (GET_MODE (op0) == DImode
20694           && !TARGET_64BIT))
20695     return false;
20696
20697   start_sequence ();
20698   compare_op = ix86_expand_compare (code, op0, op1);
20699   compare_seq = get_insns ();
20700   end_sequence ();
20701
20702   compare_code = GET_CODE (compare_op);
20703
20704   if ((op1 == const0_rtx && (code == GE || code == LT))
20705       || (op1 == constm1_rtx && (code == GT || code == LE)))
20706     sign_bit_compare_p = true;
20707
20708   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
20709      HImode insns, we'd be swallowed in word prefix ops.  */
20710
20711   if ((mode != HImode || TARGET_FAST_PREFIX)
20712       && (mode != (TARGET_64BIT ? TImode : DImode))
20713       && CONST_INT_P (operands[2])
20714       && CONST_INT_P (operands[3]))
20715     {
20716       rtx out = operands[0];
20717       HOST_WIDE_INT ct = INTVAL (operands[2]);
20718       HOST_WIDE_INT cf = INTVAL (operands[3]);
20719       HOST_WIDE_INT diff;
20720
20721       diff = ct - cf;
20722       /*  Sign bit compares are better done using shifts than we do by using
20723           sbb.  */
20724       if (sign_bit_compare_p
20725           || ix86_expand_carry_flag_compare (code, op0, op1, &compare_op))
20726         {
20727           /* Detect overlap between destination and compare sources.  */
20728           rtx tmp = out;
20729
20730           if (!sign_bit_compare_p)
20731             {
20732               rtx flags;
20733               bool fpcmp = false;
20734
20735               compare_code = GET_CODE (compare_op);
20736
20737               flags = XEXP (compare_op, 0);
20738
20739               if (GET_MODE (flags) == CCFPmode
20740                   || GET_MODE (flags) == CCFPUmode)
20741                 {
20742                   fpcmp = true;
20743                   compare_code
20744                     = ix86_fp_compare_code_to_integer (compare_code);
20745                 }
20746
20747               /* To simplify rest of code, restrict to the GEU case.  */
20748               if (compare_code == LTU)
20749                 {
20750                   std::swap (ct, cf);
20751                   compare_code = reverse_condition (compare_code);
20752                   code = reverse_condition (code);
20753                 }
20754               else
20755                 {
20756                   if (fpcmp)
20757                     PUT_CODE (compare_op,
20758                               reverse_condition_maybe_unordered
20759                                 (GET_CODE (compare_op)));
20760                   else
20761                     PUT_CODE (compare_op,
20762                               reverse_condition (GET_CODE (compare_op)));
20763                 }
20764               diff = ct - cf;
20765
20766               if (reg_overlap_mentioned_p (out, op0)
20767                   || reg_overlap_mentioned_p (out, op1))
20768                 tmp = gen_reg_rtx (mode);
20769
20770               if (mode == DImode)
20771                 emit_insn (gen_x86_movdicc_0_m1 (tmp, flags, compare_op));
20772               else
20773                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp),
20774                                                  flags, compare_op));
20775             }
20776           else
20777             {
20778               if (code == GT || code == GE)
20779                 code = reverse_condition (code);
20780               else
20781                 {
20782                   std::swap (ct, cf);
20783                   diff = ct - cf;
20784                 }
20785               tmp = emit_store_flag (tmp, code, op0, op1, VOIDmode, 0, -1);
20786             }
20787
20788           if (diff == 1)
20789             {
20790               /*
20791                * cmpl op0,op1
20792                * sbbl dest,dest
20793                * [addl dest, ct]
20794                *
20795                * Size 5 - 8.
20796                */
20797               if (ct)
20798                 tmp = expand_simple_binop (mode, PLUS,
20799                                            tmp, GEN_INT (ct),
20800                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20801             }
20802           else if (cf == -1)
20803             {
20804               /*
20805                * cmpl op0,op1
20806                * sbbl dest,dest
20807                * orl $ct, dest
20808                *
20809                * Size 8.
20810                */
20811               tmp = expand_simple_binop (mode, IOR,
20812                                          tmp, GEN_INT (ct),
20813                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
20814             }
20815           else if (diff == -1 && ct)
20816             {
20817               /*
20818                * cmpl op0,op1
20819                * sbbl dest,dest
20820                * notl dest
20821                * [addl dest, cf]
20822                *
20823                * Size 8 - 11.
20824                */
20825               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
20826               if (cf)
20827                 tmp = expand_simple_binop (mode, PLUS,
20828                                            copy_rtx (tmp), GEN_INT (cf),
20829                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20830             }
20831           else
20832             {
20833               /*
20834                * cmpl op0,op1
20835                * sbbl dest,dest
20836                * [notl dest]
20837                * andl cf - ct, dest
20838                * [addl dest, ct]
20839                *
20840                * Size 8 - 11.
20841                */
20842
20843               if (cf == 0)
20844                 {
20845                   cf = ct;
20846                   ct = 0;
20847                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
20848                 }
20849
20850               tmp = expand_simple_binop (mode, AND,
20851                                          copy_rtx (tmp),
20852                                          gen_int_mode (cf - ct, mode),
20853                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
20854               if (ct)
20855                 tmp = expand_simple_binop (mode, PLUS,
20856                                            copy_rtx (tmp), GEN_INT (ct),
20857                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20858             }
20859
20860           if (!rtx_equal_p (tmp, out))
20861             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
20862
20863           return true;
20864         }
20865
20866       if (diff < 0)
20867         {
20868           machine_mode cmp_mode = GET_MODE (op0);
20869           enum rtx_code new_code;
20870
20871           if (SCALAR_FLOAT_MODE_P (cmp_mode))
20872             {
20873               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
20874
20875               /* We may be reversing unordered compare to normal compare, that
20876                  is not valid in general (we may convert non-trapping condition
20877                  to trapping one), however on i386 we currently emit all
20878                  comparisons unordered.  */
20879               new_code = reverse_condition_maybe_unordered (code);
20880             }
20881           else
20882             new_code = ix86_reverse_condition (code, cmp_mode);
20883           if (new_code != UNKNOWN)
20884             {
20885               std::swap (ct, cf);
20886               diff = -diff;
20887               code = new_code;
20888             }
20889         }
20890
20891       compare_code = UNKNOWN;
20892       if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
20893           && CONST_INT_P (op1))
20894         {
20895           if (op1 == const0_rtx
20896               && (code == LT || code == GE))
20897             compare_code = code;
20898           else if (op1 == constm1_rtx)
20899             {
20900               if (code == LE)
20901                 compare_code = LT;
20902               else if (code == GT)
20903                 compare_code = GE;
20904             }
20905         }
20906
20907       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
20908       if (compare_code != UNKNOWN
20909           && GET_MODE (op0) == GET_MODE (out)
20910           && (cf == -1 || ct == -1))
20911         {
20912           /* If lea code below could be used, only optimize
20913              if it results in a 2 insn sequence.  */
20914
20915           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
20916                  || diff == 3 || diff == 5 || diff == 9)
20917               || (compare_code == LT && ct == -1)
20918               || (compare_code == GE && cf == -1))
20919             {
20920               /*
20921                * notl op1       (if necessary)
20922                * sarl $31, op1
20923                * orl cf, op1
20924                */
20925               if (ct != -1)
20926                 {
20927                   cf = ct;
20928                   ct = -1;
20929                   code = reverse_condition (code);
20930                 }
20931
20932               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, -1);
20933
20934               out = expand_simple_binop (mode, IOR,
20935                                          out, GEN_INT (cf),
20936                                          out, 1, OPTAB_DIRECT);
20937               if (out != operands[0])
20938                 emit_move_insn (operands[0], out);
20939
20940               return true;
20941             }
20942         }
20943
20944
20945       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
20946            || diff == 3 || diff == 5 || diff == 9)
20947           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
20948           && (mode != DImode
20949               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
20950         {
20951           /*
20952            * xorl dest,dest
20953            * cmpl op1,op2
20954            * setcc dest
20955            * lea cf(dest*(ct-cf)),dest
20956            *
20957            * Size 14.
20958            *
20959            * This also catches the degenerate setcc-only case.
20960            */
20961
20962           rtx tmp;
20963           int nops;
20964
20965           out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, 1);
20966
20967           nops = 0;
20968           /* On x86_64 the lea instruction operates on Pmode, so we need
20969              to get arithmetics done in proper mode to match.  */
20970           if (diff == 1)
20971             tmp = copy_rtx (out);
20972           else
20973             {
20974               rtx out1;
20975               out1 = copy_rtx (out);
20976               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
20977               nops++;
20978               if (diff & 1)
20979                 {
20980                   tmp = gen_rtx_PLUS (mode, tmp, out1);
20981                   nops++;
20982                 }
20983             }
20984           if (cf != 0)
20985             {
20986               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
20987               nops++;
20988             }
20989           if (!rtx_equal_p (tmp, out))
20990             {
20991               if (nops == 1)
20992                 out = force_operand (tmp, copy_rtx (out));
20993               else
20994                 emit_insn (gen_rtx_SET (copy_rtx (out), copy_rtx (tmp)));
20995             }
20996           if (!rtx_equal_p (out, operands[0]))
20997             emit_move_insn (operands[0], copy_rtx (out));
20998
20999           return true;
21000         }
21001
21002       /*
21003        * General case:                  Jumpful:
21004        *   xorl dest,dest               cmpl op1, op2
21005        *   cmpl op1, op2                movl ct, dest
21006        *   setcc dest                   jcc 1f
21007        *   decl dest                    movl cf, dest
21008        *   andl (cf-ct),dest            1:
21009        *   addl ct,dest
21010        *
21011        * Size 20.                       Size 14.
21012        *
21013        * This is reasonably steep, but branch mispredict costs are
21014        * high on modern cpus, so consider failing only if optimizing
21015        * for space.
21016        */
21017
21018       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
21019           && BRANCH_COST (optimize_insn_for_speed_p (),
21020                           false) >= 2)
21021         {
21022           if (cf == 0)
21023             {
21024               machine_mode cmp_mode = GET_MODE (op0);
21025               enum rtx_code new_code;
21026
21027               if (SCALAR_FLOAT_MODE_P (cmp_mode))
21028                 {
21029                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
21030
21031                   /* We may be reversing unordered compare to normal compare,
21032                      that is not valid in general (we may convert non-trapping
21033                      condition to trapping one), however on i386 we currently
21034                      emit all comparisons unordered.  */
21035                   new_code = reverse_condition_maybe_unordered (code);
21036                 }
21037               else
21038                 {
21039                   new_code = ix86_reverse_condition (code, cmp_mode);
21040                   if (compare_code != UNKNOWN && new_code != UNKNOWN)
21041                     compare_code = reverse_condition (compare_code);
21042                 }
21043
21044               if (new_code != UNKNOWN)
21045                 {
21046                   cf = ct;
21047                   ct = 0;
21048                   code = new_code;
21049                 }
21050             }
21051
21052           if (compare_code != UNKNOWN)
21053             {
21054               /* notl op1       (if needed)
21055                  sarl $31, op1
21056                  andl (cf-ct), op1
21057                  addl ct, op1
21058
21059                  For x < 0 (resp. x <= -1) there will be no notl,
21060                  so if possible swap the constants to get rid of the
21061                  complement.
21062                  True/false will be -1/0 while code below (store flag
21063                  followed by decrement) is 0/-1, so the constants need
21064                  to be exchanged once more.  */
21065
21066               if (compare_code == GE || !cf)
21067                 {
21068                   code = reverse_condition (code);
21069                   compare_code = LT;
21070                 }
21071               else
21072                 std::swap (ct, cf);
21073
21074               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, -1);
21075             }
21076           else
21077             {
21078               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, 1);
21079
21080               out = expand_simple_binop (mode, PLUS, copy_rtx (out),
21081                                          constm1_rtx,
21082                                          copy_rtx (out), 1, OPTAB_DIRECT);
21083             }
21084
21085           out = expand_simple_binop (mode, AND, copy_rtx (out),
21086                                      gen_int_mode (cf - ct, mode),
21087                                      copy_rtx (out), 1, OPTAB_DIRECT);
21088           if (ct)
21089             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
21090                                        copy_rtx (out), 1, OPTAB_DIRECT);
21091           if (!rtx_equal_p (out, operands[0]))
21092             emit_move_insn (operands[0], copy_rtx (out));
21093
21094           return true;
21095         }
21096     }
21097
21098   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
21099     {
21100       /* Try a few things more with specific constants and a variable.  */
21101
21102       optab op;
21103       rtx var, orig_out, out, tmp;
21104
21105       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
21106         return false;
21107
21108       /* If one of the two operands is an interesting constant, load a
21109          constant with the above and mask it in with a logical operation.  */
21110
21111       if (CONST_INT_P (operands[2]))
21112         {
21113           var = operands[3];
21114           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
21115             operands[3] = constm1_rtx, op = and_optab;
21116           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
21117             operands[3] = const0_rtx, op = ior_optab;
21118           else
21119             return false;
21120         }
21121       else if (CONST_INT_P (operands[3]))
21122         {
21123           var = operands[2];
21124           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
21125             operands[2] = constm1_rtx, op = and_optab;
21126           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
21127             operands[2] = const0_rtx, op = ior_optab;
21128           else
21129             return false;
21130         }
21131       else
21132         return false;
21133
21134       orig_out = operands[0];
21135       tmp = gen_reg_rtx (mode);
21136       operands[0] = tmp;
21137
21138       /* Recurse to get the constant loaded.  */
21139       if (ix86_expand_int_movcc (operands) == 0)
21140         return false;
21141
21142       /* Mask in the interesting variable.  */
21143       out = expand_binop (mode, op, var, tmp, orig_out, 0,
21144                           OPTAB_WIDEN);
21145       if (!rtx_equal_p (out, orig_out))
21146         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
21147
21148       return true;
21149     }
21150
21151   /*
21152    * For comparison with above,
21153    *
21154    * movl cf,dest
21155    * movl ct,tmp
21156    * cmpl op1,op2
21157    * cmovcc tmp,dest
21158    *
21159    * Size 15.
21160    */
21161
21162   if (! nonimmediate_operand (operands[2], mode))
21163     operands[2] = force_reg (mode, operands[2]);
21164   if (! nonimmediate_operand (operands[3], mode))
21165     operands[3] = force_reg (mode, operands[3]);
21166
21167   if (! register_operand (operands[2], VOIDmode)
21168       && (mode == QImode
21169           || ! register_operand (operands[3], VOIDmode)))
21170     operands[2] = force_reg (mode, operands[2]);
21171
21172   if (mode == QImode
21173       && ! register_operand (operands[3], VOIDmode))
21174     operands[3] = force_reg (mode, operands[3]);
21175
21176   emit_insn (compare_seq);
21177   emit_insn (gen_rtx_SET (operands[0],
21178                           gen_rtx_IF_THEN_ELSE (mode,
21179                                                 compare_op, operands[2],
21180                                                 operands[3])));
21181   return true;
21182 }
21183
21184 /* Swap, force into registers, or otherwise massage the two operands
21185    to an sse comparison with a mask result.  Thus we differ a bit from
21186    ix86_prepare_fp_compare_args which expects to produce a flags result.
21187
21188    The DEST operand exists to help determine whether to commute commutative
21189    operators.  The POP0/POP1 operands are updated in place.  The new
21190    comparison code is returned, or UNKNOWN if not implementable.  */
21191
21192 static enum rtx_code
21193 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
21194                                   rtx *pop0, rtx *pop1)
21195 {
21196   switch (code)
21197     {
21198     case LTGT:
21199     case UNEQ:
21200       /* AVX supports all the needed comparisons.  */
21201       if (TARGET_AVX)
21202         break;
21203       /* We have no LTGT as an operator.  We could implement it with
21204          NE & ORDERED, but this requires an extra temporary.  It's
21205          not clear that it's worth it.  */
21206       return UNKNOWN;
21207
21208     case LT:
21209     case LE:
21210     case UNGT:
21211     case UNGE:
21212       /* These are supported directly.  */
21213       break;
21214
21215     case EQ:
21216     case NE:
21217     case UNORDERED:
21218     case ORDERED:
21219       /* AVX has 3 operand comparisons, no need to swap anything.  */
21220       if (TARGET_AVX)
21221         break;
21222       /* For commutative operators, try to canonicalize the destination
21223          operand to be first in the comparison - this helps reload to
21224          avoid extra moves.  */
21225       if (!dest || !rtx_equal_p (dest, *pop1))
21226         break;
21227       /* FALLTHRU */
21228
21229     case GE:
21230     case GT:
21231     case UNLE:
21232     case UNLT:
21233       /* These are not supported directly before AVX, and furthermore
21234          ix86_expand_sse_fp_minmax only optimizes LT/UNGE.  Swap the
21235          comparison operands to transform into something that is
21236          supported.  */
21237       std::swap (*pop0, *pop1);
21238       code = swap_condition (code);
21239       break;
21240
21241     default:
21242       gcc_unreachable ();
21243     }
21244
21245   return code;
21246 }
21247
21248 /* Detect conditional moves that exactly match min/max operational
21249    semantics.  Note that this is IEEE safe, as long as we don't
21250    interchange the operands.
21251
21252    Returns FALSE if this conditional move doesn't match a MIN/MAX,
21253    and TRUE if the operation is successful and instructions are emitted.  */
21254
21255 static bool
21256 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
21257                            rtx cmp_op1, rtx if_true, rtx if_false)
21258 {
21259   machine_mode mode;
21260   bool is_min;
21261   rtx tmp;
21262
21263   if (code == LT)
21264     ;
21265   else if (code == UNGE)
21266     std::swap (if_true, if_false);
21267   else
21268     return false;
21269
21270   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
21271     is_min = true;
21272   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
21273     is_min = false;
21274   else
21275     return false;
21276
21277   mode = GET_MODE (dest);
21278
21279   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
21280      but MODE may be a vector mode and thus not appropriate.  */
21281   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
21282     {
21283       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
21284       rtvec v;
21285
21286       if_true = force_reg (mode, if_true);
21287       v = gen_rtvec (2, if_true, if_false);
21288       tmp = gen_rtx_UNSPEC (mode, v, u);
21289     }
21290   else
21291     {
21292       code = is_min ? SMIN : SMAX;
21293       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
21294     }
21295
21296   emit_insn (gen_rtx_SET (dest, tmp));
21297   return true;
21298 }
21299
21300 /* Expand an sse vector comparison.  Return the register with the result.  */
21301
21302 static rtx
21303 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
21304                      rtx op_true, rtx op_false)
21305 {
21306   machine_mode mode = GET_MODE (dest);
21307   machine_mode cmp_ops_mode = GET_MODE (cmp_op0);
21308
21309   /* In general case result of comparison can differ from operands' type.  */
21310   machine_mode cmp_mode;
21311
21312   /* In AVX512F the result of comparison is an integer mask.  */
21313   bool maskcmp = false;
21314   rtx x;
21315
21316   if (GET_MODE_SIZE (cmp_ops_mode) == 64)
21317     {
21318       cmp_mode = mode_for_size (GET_MODE_NUNITS (cmp_ops_mode), MODE_INT, 0);
21319       gcc_assert (cmp_mode != BLKmode);
21320
21321       maskcmp = true;
21322     }
21323   else
21324     cmp_mode = cmp_ops_mode;
21325
21326
21327   cmp_op0 = force_reg (cmp_ops_mode, cmp_op0);
21328   if (!nonimmediate_operand (cmp_op1, cmp_ops_mode))
21329     cmp_op1 = force_reg (cmp_ops_mode, cmp_op1);
21330
21331   if (optimize
21332       || reg_overlap_mentioned_p (dest, op_true)
21333       || reg_overlap_mentioned_p (dest, op_false))
21334     dest = gen_reg_rtx (maskcmp ? cmp_mode : mode);
21335
21336   /* Compare patterns for int modes are unspec in AVX512F only.  */
21337   if (maskcmp && (code == GT || code == EQ))
21338     {
21339       rtx (*gen)(rtx, rtx, rtx);
21340
21341       switch (cmp_ops_mode)
21342         {
21343         case V64QImode:
21344           gcc_assert (TARGET_AVX512BW);
21345           gen = code == GT ? gen_avx512bw_gtv64qi3 : gen_avx512bw_eqv64qi3_1;
21346           break;
21347         case V32HImode:
21348           gcc_assert (TARGET_AVX512BW);
21349           gen = code == GT ? gen_avx512bw_gtv32hi3 : gen_avx512bw_eqv32hi3_1;
21350           break;
21351         case V16SImode:
21352           gen = code == GT ? gen_avx512f_gtv16si3 : gen_avx512f_eqv16si3_1;
21353           break;
21354         case V8DImode:
21355           gen = code == GT ? gen_avx512f_gtv8di3 : gen_avx512f_eqv8di3_1;
21356           break;
21357         default:
21358           gen = NULL;
21359         }
21360
21361       if (gen)
21362         {
21363           emit_insn (gen (dest, cmp_op0, cmp_op1));
21364           return dest;
21365         }
21366     }
21367   x = gen_rtx_fmt_ee (code, cmp_mode, cmp_op0, cmp_op1);
21368
21369   if (cmp_mode != mode && !maskcmp)
21370     {
21371       x = force_reg (cmp_ops_mode, x);
21372       convert_move (dest, x, false);
21373     }
21374   else
21375     emit_insn (gen_rtx_SET (dest, x));
21376
21377   return dest;
21378 }
21379
21380 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
21381    operations.  This is used for both scalar and vector conditional moves.  */
21382
21383 static void
21384 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
21385 {
21386   machine_mode mode = GET_MODE (dest);
21387   machine_mode cmpmode = GET_MODE (cmp);
21388
21389   /* In AVX512F the result of comparison is an integer mask.  */
21390   bool maskcmp = (mode != cmpmode && TARGET_AVX512F);
21391
21392   rtx t2, t3, x;
21393
21394   if (vector_all_ones_operand (op_true, mode)
21395       && rtx_equal_p (op_false, CONST0_RTX (mode))
21396       && !maskcmp)
21397     {
21398       emit_insn (gen_rtx_SET (dest, cmp));
21399     }
21400   else if (op_false == CONST0_RTX (mode)
21401       && !maskcmp)
21402     {
21403       op_true = force_reg (mode, op_true);
21404       x = gen_rtx_AND (mode, cmp, op_true);
21405       emit_insn (gen_rtx_SET (dest, x));
21406     }
21407   else if (op_true == CONST0_RTX (mode)
21408       && !maskcmp)
21409     {
21410       op_false = force_reg (mode, op_false);
21411       x = gen_rtx_NOT (mode, cmp);
21412       x = gen_rtx_AND (mode, x, op_false);
21413       emit_insn (gen_rtx_SET (dest, x));
21414     }
21415   else if (INTEGRAL_MODE_P (mode) && op_true == CONSTM1_RTX (mode)
21416       && !maskcmp)
21417     {
21418       op_false = force_reg (mode, op_false);
21419       x = gen_rtx_IOR (mode, cmp, op_false);
21420       emit_insn (gen_rtx_SET (dest, x));
21421     }
21422   else if (TARGET_XOP
21423       && !maskcmp)
21424     {
21425       op_true = force_reg (mode, op_true);
21426
21427       if (!nonimmediate_operand (op_false, mode))
21428         op_false = force_reg (mode, op_false);
21429
21430       emit_insn (gen_rtx_SET (dest, gen_rtx_IF_THEN_ELSE (mode, cmp,
21431                                                           op_true,
21432                                                           op_false)));
21433     }
21434   else
21435     {
21436       rtx (*gen) (rtx, rtx, rtx, rtx) = NULL;
21437       rtx d = dest;
21438
21439       if (!nonimmediate_operand (op_true, mode))
21440         op_true = force_reg (mode, op_true);
21441
21442       op_false = force_reg (mode, op_false);
21443
21444       switch (mode)
21445         {
21446         case V4SFmode:
21447           if (TARGET_SSE4_1)
21448             gen = gen_sse4_1_blendvps;
21449           break;
21450         case V2DFmode:
21451           if (TARGET_SSE4_1)
21452             gen = gen_sse4_1_blendvpd;
21453           break;
21454         case V16QImode:
21455         case V8HImode:
21456         case V4SImode:
21457         case V2DImode:
21458           if (TARGET_SSE4_1)
21459             {
21460               gen = gen_sse4_1_pblendvb;
21461               if (mode != V16QImode)
21462                 d = gen_reg_rtx (V16QImode);
21463               op_false = gen_lowpart (V16QImode, op_false);
21464               op_true = gen_lowpart (V16QImode, op_true);
21465               cmp = gen_lowpart (V16QImode, cmp);
21466             }
21467           break;
21468         case V8SFmode:
21469           if (TARGET_AVX)
21470             gen = gen_avx_blendvps256;
21471           break;
21472         case V4DFmode:
21473           if (TARGET_AVX)
21474             gen = gen_avx_blendvpd256;
21475           break;
21476         case V32QImode:
21477         case V16HImode:
21478         case V8SImode:
21479         case V4DImode:
21480           if (TARGET_AVX2)
21481             {
21482               gen = gen_avx2_pblendvb;
21483               if (mode != V32QImode)
21484                 d = gen_reg_rtx (V32QImode);
21485               op_false = gen_lowpart (V32QImode, op_false);
21486               op_true = gen_lowpart (V32QImode, op_true);
21487               cmp = gen_lowpart (V32QImode, cmp);
21488             }
21489           break;
21490
21491         case V64QImode:
21492           gen = gen_avx512bw_blendmv64qi;
21493           break;
21494         case V32HImode:
21495           gen = gen_avx512bw_blendmv32hi;
21496           break;
21497         case V16SImode:
21498           gen = gen_avx512f_blendmv16si;
21499           break;
21500         case V8DImode:
21501           gen = gen_avx512f_blendmv8di;
21502           break;
21503         case V8DFmode:
21504           gen = gen_avx512f_blendmv8df;
21505           break;
21506         case V16SFmode:
21507           gen = gen_avx512f_blendmv16sf;
21508           break;
21509
21510         default:
21511           break;
21512         }
21513
21514       if (gen != NULL)
21515         {
21516           emit_insn (gen (d, op_false, op_true, cmp));
21517           if (d != dest)
21518             emit_move_insn (dest, gen_lowpart (GET_MODE (dest), d));
21519         }
21520       else
21521         {
21522           op_true = force_reg (mode, op_true);
21523
21524           t2 = gen_reg_rtx (mode);
21525           if (optimize)
21526             t3 = gen_reg_rtx (mode);
21527           else
21528             t3 = dest;
21529
21530           x = gen_rtx_AND (mode, op_true, cmp);
21531           emit_insn (gen_rtx_SET (t2, x));
21532
21533           x = gen_rtx_NOT (mode, cmp);
21534           x = gen_rtx_AND (mode, x, op_false);
21535           emit_insn (gen_rtx_SET (t3, x));
21536
21537           x = gen_rtx_IOR (mode, t3, t2);
21538           emit_insn (gen_rtx_SET (dest, x));
21539         }
21540     }
21541 }
21542
21543 /* Expand a floating-point conditional move.  Return true if successful.  */
21544
21545 bool
21546 ix86_expand_fp_movcc (rtx operands[])
21547 {
21548   machine_mode mode = GET_MODE (operands[0]);
21549   enum rtx_code code = GET_CODE (operands[1]);
21550   rtx tmp, compare_op;
21551   rtx op0 = XEXP (operands[1], 0);
21552   rtx op1 = XEXP (operands[1], 1);
21553
21554   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
21555     {
21556       machine_mode cmode;
21557
21558       /* Since we've no cmove for sse registers, don't force bad register
21559          allocation just to gain access to it.  Deny movcc when the
21560          comparison mode doesn't match the move mode.  */
21561       cmode = GET_MODE (op0);
21562       if (cmode == VOIDmode)
21563         cmode = GET_MODE (op1);
21564       if (cmode != mode)
21565         return false;
21566
21567       code = ix86_prepare_sse_fp_compare_args (operands[0], code, &op0, &op1);
21568       if (code == UNKNOWN)
21569         return false;
21570
21571       if (ix86_expand_sse_fp_minmax (operands[0], code, op0, op1,
21572                                      operands[2], operands[3]))
21573         return true;
21574
21575       tmp = ix86_expand_sse_cmp (operands[0], code, op0, op1,
21576                                  operands[2], operands[3]);
21577       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
21578       return true;
21579     }
21580
21581   if (GET_MODE (op0) == TImode
21582       || (GET_MODE (op0) == DImode
21583           && !TARGET_64BIT))
21584     return false;
21585
21586   /* The floating point conditional move instructions don't directly
21587      support conditions resulting from a signed integer comparison.  */
21588
21589   compare_op = ix86_expand_compare (code, op0, op1);
21590   if (!fcmov_comparison_operator (compare_op, VOIDmode))
21591     {
21592       tmp = gen_reg_rtx (QImode);
21593       ix86_expand_setcc (tmp, code, op0, op1);
21594
21595       compare_op = ix86_expand_compare (NE, tmp, const0_rtx);
21596     }
21597
21598   emit_insn (gen_rtx_SET (operands[0],
21599                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
21600                                                 operands[2], operands[3])));
21601
21602   return true;
21603 }
21604
21605 /* Expand a floating-point vector conditional move; a vcond operation
21606    rather than a movcc operation.  */
21607
21608 bool
21609 ix86_expand_fp_vcond (rtx operands[])
21610 {
21611   enum rtx_code code = GET_CODE (operands[3]);
21612   rtx cmp;
21613
21614   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
21615                                            &operands[4], &operands[5]);
21616   if (code == UNKNOWN)
21617     {
21618       rtx temp;
21619       switch (GET_CODE (operands[3]))
21620         {
21621         case LTGT:
21622           temp = ix86_expand_sse_cmp (operands[0], ORDERED, operands[4],
21623                                       operands[5], operands[0], operands[0]);
21624           cmp = ix86_expand_sse_cmp (operands[0], NE, operands[4],
21625                                      operands[5], operands[1], operands[2]);
21626           code = AND;
21627           break;
21628         case UNEQ:
21629           temp = ix86_expand_sse_cmp (operands[0], UNORDERED, operands[4],
21630                                       operands[5], operands[0], operands[0]);
21631           cmp = ix86_expand_sse_cmp (operands[0], EQ, operands[4],
21632                                      operands[5], operands[1], operands[2]);
21633           code = IOR;
21634           break;
21635         default:
21636           gcc_unreachable ();
21637         }
21638       cmp = expand_simple_binop (GET_MODE (cmp), code, temp, cmp, cmp, 1,
21639                                  OPTAB_DIRECT);
21640       ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
21641       return true;
21642     }
21643
21644   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
21645                                  operands[5], operands[1], operands[2]))
21646     return true;
21647
21648   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
21649                              operands[1], operands[2]);
21650   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
21651   return true;
21652 }
21653
21654 /* Expand a signed/unsigned integral vector conditional move.  */
21655
21656 bool
21657 ix86_expand_int_vcond (rtx operands[])
21658 {
21659   machine_mode data_mode = GET_MODE (operands[0]);
21660   machine_mode mode = GET_MODE (operands[4]);
21661   enum rtx_code code = GET_CODE (operands[3]);
21662   bool negate = false;
21663   rtx x, cop0, cop1;
21664
21665   cop0 = operands[4];
21666   cop1 = operands[5];
21667
21668   /* Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
21669      and x < 0 ? 1 : 0 into (unsigned) x >> 31.  */
21670   if ((code == LT || code == GE)
21671       && data_mode == mode
21672       && cop1 == CONST0_RTX (mode)
21673       && operands[1 + (code == LT)] == CONST0_RTX (data_mode)
21674       && GET_MODE_SIZE (GET_MODE_INNER (data_mode)) > 1
21675       && GET_MODE_SIZE (GET_MODE_INNER (data_mode)) <= 8
21676       && (GET_MODE_SIZE (data_mode) == 16
21677           || (TARGET_AVX2 && GET_MODE_SIZE (data_mode) == 32)))
21678     {
21679       rtx negop = operands[2 - (code == LT)];
21680       int shift = GET_MODE_BITSIZE (GET_MODE_INNER (data_mode)) - 1;
21681       if (negop == CONST1_RTX (data_mode))
21682         {
21683           rtx res = expand_simple_binop (mode, LSHIFTRT, cop0, GEN_INT (shift),
21684                                          operands[0], 1, OPTAB_DIRECT);
21685           if (res != operands[0])
21686             emit_move_insn (operands[0], res);
21687           return true;
21688         }
21689       else if (GET_MODE_INNER (data_mode) != DImode
21690                && vector_all_ones_operand (negop, data_mode))
21691         {
21692           rtx res = expand_simple_binop (mode, ASHIFTRT, cop0, GEN_INT (shift),
21693                                          operands[0], 0, OPTAB_DIRECT);
21694           if (res != operands[0])
21695             emit_move_insn (operands[0], res);
21696           return true;
21697         }
21698     }
21699
21700   if (!nonimmediate_operand (cop1, mode))
21701     cop1 = force_reg (mode, cop1);
21702   if (!general_operand (operands[1], data_mode))
21703     operands[1] = force_reg (data_mode, operands[1]);
21704   if (!general_operand (operands[2], data_mode))
21705     operands[2] = force_reg (data_mode, operands[2]);
21706
21707   /* XOP supports all of the comparisons on all 128-bit vector int types.  */
21708   if (TARGET_XOP
21709       && (mode == V16QImode || mode == V8HImode
21710           || mode == V4SImode || mode == V2DImode))
21711     ;
21712   else
21713     {
21714       /* Canonicalize the comparison to EQ, GT, GTU.  */
21715       switch (code)
21716         {
21717         case EQ:
21718         case GT:
21719         case GTU:
21720           break;
21721
21722         case NE:
21723         case LE:
21724         case LEU:
21725           code = reverse_condition (code);
21726           negate = true;
21727           break;
21728
21729         case GE:
21730         case GEU:
21731           code = reverse_condition (code);
21732           negate = true;
21733           /* FALLTHRU */
21734
21735         case LT:
21736         case LTU:
21737           std::swap (cop0, cop1);
21738           code = swap_condition (code);
21739           break;
21740
21741         default:
21742           gcc_unreachable ();
21743         }
21744
21745       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
21746       if (mode == V2DImode)
21747         {
21748           switch (code)
21749             {
21750             case EQ:
21751               /* SSE4.1 supports EQ.  */
21752               if (!TARGET_SSE4_1)
21753                 return false;
21754               break;
21755
21756             case GT:
21757             case GTU:
21758               /* SSE4.2 supports GT/GTU.  */
21759               if (!TARGET_SSE4_2)
21760                 return false;
21761               break;
21762
21763             default:
21764               gcc_unreachable ();
21765             }
21766         }
21767
21768       /* Unsigned parallel compare is not supported by the hardware.
21769          Play some tricks to turn this into a signed comparison
21770          against 0.  */
21771       if (code == GTU)
21772         {
21773           cop0 = force_reg (mode, cop0);
21774
21775           switch (mode)
21776             {
21777             case V16SImode:
21778             case V8DImode:
21779             case V8SImode:
21780             case V4DImode:
21781             case V4SImode:
21782             case V2DImode:
21783                 {
21784                   rtx t1, t2, mask;
21785                   rtx (*gen_sub3) (rtx, rtx, rtx);
21786
21787                   switch (mode)
21788                     {
21789                     case V16SImode: gen_sub3 = gen_subv16si3; break;
21790                     case V8DImode: gen_sub3 = gen_subv8di3; break;
21791                     case V8SImode: gen_sub3 = gen_subv8si3; break;
21792                     case V4DImode: gen_sub3 = gen_subv4di3; break;
21793                     case V4SImode: gen_sub3 = gen_subv4si3; break;
21794                     case V2DImode: gen_sub3 = gen_subv2di3; break;
21795                     default:
21796                       gcc_unreachable ();
21797                     }
21798                   /* Subtract (-(INT MAX) - 1) from both operands to make
21799                      them signed.  */
21800                   mask = ix86_build_signbit_mask (mode, true, false);
21801                   t1 = gen_reg_rtx (mode);
21802                   emit_insn (gen_sub3 (t1, cop0, mask));
21803
21804                   t2 = gen_reg_rtx (mode);
21805                   emit_insn (gen_sub3 (t2, cop1, mask));
21806
21807                   cop0 = t1;
21808                   cop1 = t2;
21809                   code = GT;
21810                 }
21811               break;
21812
21813             case V64QImode:
21814             case V32HImode:
21815             case V32QImode:
21816             case V16HImode:
21817             case V16QImode:
21818             case V8HImode:
21819               /* Perform a parallel unsigned saturating subtraction.  */
21820               x = gen_reg_rtx (mode);
21821               emit_insn (gen_rtx_SET (x, gen_rtx_US_MINUS (mode, cop0, cop1)));
21822
21823               cop0 = x;
21824               cop1 = CONST0_RTX (mode);
21825               code = EQ;
21826               negate = !negate;
21827               break;
21828
21829             default:
21830               gcc_unreachable ();
21831             }
21832         }
21833     }
21834
21835   /* Allow the comparison to be done in one mode, but the movcc to
21836      happen in another mode.  */
21837   if (data_mode == mode)
21838     {
21839       x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
21840                                operands[1+negate], operands[2-negate]);
21841     }
21842   else
21843     {
21844       gcc_assert (GET_MODE_SIZE (data_mode) == GET_MODE_SIZE (mode));
21845       x = ix86_expand_sse_cmp (gen_reg_rtx (mode), code, cop0, cop1,
21846                                operands[1+negate], operands[2-negate]);
21847       if (GET_MODE (x) == mode)
21848         x = gen_lowpart (data_mode, x);
21849     }
21850
21851   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
21852                          operands[2-negate]);
21853   return true;
21854 }
21855
21856 /* AVX512F does support 64-byte integer vector operations,
21857    thus the longest vector we are faced with is V64QImode.  */
21858 #define MAX_VECT_LEN    64
21859
21860 struct expand_vec_perm_d
21861 {
21862   rtx target, op0, op1;
21863   unsigned char perm[MAX_VECT_LEN];
21864   machine_mode vmode;
21865   unsigned char nelt;
21866   bool one_operand_p;
21867   bool testing_p;
21868 };
21869
21870 static bool
21871 ix86_expand_vec_perm_vpermi2 (rtx target, rtx op0, rtx mask, rtx op1,
21872                               struct expand_vec_perm_d *d)
21873 {
21874   /* ix86_expand_vec_perm_vpermi2 is called from both const and non-const
21875      expander, so args are either in d, or in op0, op1 etc.  */
21876   machine_mode mode = GET_MODE (d ? d->op0 : op0);
21877   machine_mode maskmode = mode;
21878   rtx (*gen) (rtx, rtx, rtx, rtx) = NULL;
21879
21880   switch (mode)
21881     {
21882     case V8HImode:
21883       if (TARGET_AVX512VL && TARGET_AVX512BW)
21884         gen = gen_avx512vl_vpermi2varv8hi3;
21885       break;
21886     case V16HImode:
21887       if (TARGET_AVX512VL && TARGET_AVX512BW)
21888         gen = gen_avx512vl_vpermi2varv16hi3;
21889       break;
21890     case V64QImode:
21891       if (TARGET_AVX512VBMI)
21892         gen = gen_avx512bw_vpermi2varv64qi3;
21893       break;
21894     case V32HImode:
21895       if (TARGET_AVX512BW)
21896         gen = gen_avx512bw_vpermi2varv32hi3;
21897       break;
21898     case V4SImode:
21899       if (TARGET_AVX512VL)
21900         gen = gen_avx512vl_vpermi2varv4si3;
21901       break;
21902     case V8SImode:
21903       if (TARGET_AVX512VL)
21904         gen = gen_avx512vl_vpermi2varv8si3;
21905       break;
21906     case V16SImode:
21907       if (TARGET_AVX512F)
21908         gen = gen_avx512f_vpermi2varv16si3;
21909       break;
21910     case V4SFmode:
21911       if (TARGET_AVX512VL)
21912         {
21913           gen = gen_avx512vl_vpermi2varv4sf3;
21914           maskmode = V4SImode;
21915         }
21916       break;
21917     case V8SFmode:
21918       if (TARGET_AVX512VL)
21919         {
21920           gen = gen_avx512vl_vpermi2varv8sf3;
21921           maskmode = V8SImode;
21922         }
21923       break;
21924     case V16SFmode:
21925       if (TARGET_AVX512F)
21926         {
21927           gen = gen_avx512f_vpermi2varv16sf3;
21928           maskmode = V16SImode;
21929         }
21930       break;
21931     case V2DImode:
21932       if (TARGET_AVX512VL)
21933         gen = gen_avx512vl_vpermi2varv2di3;
21934       break;
21935     case V4DImode:
21936       if (TARGET_AVX512VL)
21937         gen = gen_avx512vl_vpermi2varv4di3;
21938       break;
21939     case V8DImode:
21940       if (TARGET_AVX512F)
21941         gen = gen_avx512f_vpermi2varv8di3;
21942       break;
21943     case V2DFmode:
21944       if (TARGET_AVX512VL)
21945         {
21946           gen = gen_avx512vl_vpermi2varv2df3;
21947           maskmode = V2DImode;
21948         }
21949       break;
21950     case V4DFmode:
21951       if (TARGET_AVX512VL)
21952         {
21953           gen = gen_avx512vl_vpermi2varv4df3;
21954           maskmode = V4DImode;
21955         }
21956       break;
21957     case V8DFmode:
21958       if (TARGET_AVX512F)
21959         {
21960           gen = gen_avx512f_vpermi2varv8df3;
21961           maskmode = V8DImode;
21962         }
21963       break;
21964     default:
21965       break;
21966     }
21967
21968   if (gen == NULL)
21969     return false;
21970
21971   /* ix86_expand_vec_perm_vpermi2 is called from both const and non-const
21972      expander, so args are either in d, or in op0, op1 etc.  */
21973   if (d)
21974     {
21975       rtx vec[64];
21976       target = d->target;
21977       op0 = d->op0;
21978       op1 = d->op1;
21979       for (int i = 0; i < d->nelt; ++i)
21980         vec[i] = GEN_INT (d->perm[i]);
21981       mask = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (d->nelt, vec));
21982     }
21983
21984   emit_insn (gen (target, op0, force_reg (maskmode, mask), op1));
21985   return true;
21986 }
21987
21988 /* Expand a variable vector permutation.  */
21989
21990 void
21991 ix86_expand_vec_perm (rtx operands[])
21992 {
21993   rtx target = operands[0];
21994   rtx op0 = operands[1];
21995   rtx op1 = operands[2];
21996   rtx mask = operands[3];
21997   rtx t1, t2, t3, t4, t5, t6, t7, t8, vt, vt2, vec[32];
21998   machine_mode mode = GET_MODE (op0);
21999   machine_mode maskmode = GET_MODE (mask);
22000   int w, e, i;
22001   bool one_operand_shuffle = rtx_equal_p (op0, op1);
22002
22003   /* Number of elements in the vector.  */
22004   w = GET_MODE_NUNITS (mode);
22005   e = GET_MODE_UNIT_SIZE (mode);
22006   gcc_assert (w <= 64);
22007
22008   if (ix86_expand_vec_perm_vpermi2 (target, op0, mask, op1, NULL))
22009     return;
22010
22011   if (TARGET_AVX2)
22012     {
22013       if (mode == V4DImode || mode == V4DFmode || mode == V16HImode)
22014         {
22015           /* Unfortunately, the VPERMQ and VPERMPD instructions only support
22016              an constant shuffle operand.  With a tiny bit of effort we can
22017              use VPERMD instead.  A re-interpretation stall for V4DFmode is
22018              unfortunate but there's no avoiding it.
22019              Similarly for V16HImode we don't have instructions for variable
22020              shuffling, while for V32QImode we can use after preparing suitable
22021              masks vpshufb; vpshufb; vpermq; vpor.  */
22022
22023           if (mode == V16HImode)
22024             {
22025               maskmode = mode = V32QImode;
22026               w = 32;
22027               e = 1;
22028             }
22029           else
22030             {
22031               maskmode = mode = V8SImode;
22032               w = 8;
22033               e = 4;
22034             }
22035           t1 = gen_reg_rtx (maskmode);
22036
22037           /* Replicate the low bits of the V4DImode mask into V8SImode:
22038                mask = { A B C D }
22039                t1 = { A A B B C C D D }.  */
22040           for (i = 0; i < w / 2; ++i)
22041             vec[i*2 + 1] = vec[i*2] = GEN_INT (i * 2);
22042           vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22043           vt = force_reg (maskmode, vt);
22044           mask = gen_lowpart (maskmode, mask);
22045           if (maskmode == V8SImode)
22046             emit_insn (gen_avx2_permvarv8si (t1, mask, vt));
22047           else
22048             emit_insn (gen_avx2_pshufbv32qi3 (t1, mask, vt));
22049
22050           /* Multiply the shuffle indicies by two.  */
22051           t1 = expand_simple_binop (maskmode, PLUS, t1, t1, t1, 1,
22052                                     OPTAB_DIRECT);
22053
22054           /* Add one to the odd shuffle indicies:
22055                 t1 = { A*2, A*2+1, B*2, B*2+1, ... }.  */
22056           for (i = 0; i < w / 2; ++i)
22057             {
22058               vec[i * 2] = const0_rtx;
22059               vec[i * 2 + 1] = const1_rtx;
22060             }
22061           vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22062           vt = validize_mem (force_const_mem (maskmode, vt));
22063           t1 = expand_simple_binop (maskmode, PLUS, t1, vt, t1, 1,
22064                                     OPTAB_DIRECT);
22065
22066           /* Continue as if V8SImode (resp. V32QImode) was used initially.  */
22067           operands[3] = mask = t1;
22068           target = gen_reg_rtx (mode);
22069           op0 = gen_lowpart (mode, op0);
22070           op1 = gen_lowpart (mode, op1);
22071         }
22072
22073       switch (mode)
22074         {
22075         case V8SImode:
22076           /* The VPERMD and VPERMPS instructions already properly ignore
22077              the high bits of the shuffle elements.  No need for us to
22078              perform an AND ourselves.  */
22079           if (one_operand_shuffle)
22080             {
22081               emit_insn (gen_avx2_permvarv8si (target, op0, mask));
22082               if (target != operands[0])
22083                 emit_move_insn (operands[0],
22084                                 gen_lowpart (GET_MODE (operands[0]), target));
22085             }
22086           else
22087             {
22088               t1 = gen_reg_rtx (V8SImode);
22089               t2 = gen_reg_rtx (V8SImode);
22090               emit_insn (gen_avx2_permvarv8si (t1, op0, mask));
22091               emit_insn (gen_avx2_permvarv8si (t2, op1, mask));
22092               goto merge_two;
22093             }
22094           return;
22095
22096         case V8SFmode:
22097           mask = gen_lowpart (V8SImode, mask);
22098           if (one_operand_shuffle)
22099             emit_insn (gen_avx2_permvarv8sf (target, op0, mask));
22100           else
22101             {
22102               t1 = gen_reg_rtx (V8SFmode);
22103               t2 = gen_reg_rtx (V8SFmode);
22104               emit_insn (gen_avx2_permvarv8sf (t1, op0, mask));
22105               emit_insn (gen_avx2_permvarv8sf (t2, op1, mask));
22106               goto merge_two;
22107             }
22108           return;
22109
22110         case V4SImode:
22111           /* By combining the two 128-bit input vectors into one 256-bit
22112              input vector, we can use VPERMD and VPERMPS for the full
22113              two-operand shuffle.  */
22114           t1 = gen_reg_rtx (V8SImode);
22115           t2 = gen_reg_rtx (V8SImode);
22116           emit_insn (gen_avx_vec_concatv8si (t1, op0, op1));
22117           emit_insn (gen_avx_vec_concatv8si (t2, mask, mask));
22118           emit_insn (gen_avx2_permvarv8si (t1, t1, t2));
22119           emit_insn (gen_avx_vextractf128v8si (target, t1, const0_rtx));
22120           return;
22121
22122         case V4SFmode:
22123           t1 = gen_reg_rtx (V8SFmode);
22124           t2 = gen_reg_rtx (V8SImode);
22125           mask = gen_lowpart (V4SImode, mask);
22126           emit_insn (gen_avx_vec_concatv8sf (t1, op0, op1));
22127           emit_insn (gen_avx_vec_concatv8si (t2, mask, mask));
22128           emit_insn (gen_avx2_permvarv8sf (t1, t1, t2));
22129           emit_insn (gen_avx_vextractf128v8sf (target, t1, const0_rtx));
22130           return;
22131
22132         case V32QImode:
22133           t1 = gen_reg_rtx (V32QImode);
22134           t2 = gen_reg_rtx (V32QImode);
22135           t3 = gen_reg_rtx (V32QImode);
22136           vt2 = GEN_INT (-128);
22137           for (i = 0; i < 32; i++)
22138             vec[i] = vt2;
22139           vt = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));
22140           vt = force_reg (V32QImode, vt);
22141           for (i = 0; i < 32; i++)
22142             vec[i] = i < 16 ? vt2 : const0_rtx;
22143           vt2 = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));
22144           vt2 = force_reg (V32QImode, vt2);
22145           /* From mask create two adjusted masks, which contain the same
22146              bits as mask in the low 7 bits of each vector element.
22147              The first mask will have the most significant bit clear
22148              if it requests element from the same 128-bit lane
22149              and MSB set if it requests element from the other 128-bit lane.
22150              The second mask will have the opposite values of the MSB,
22151              and additionally will have its 128-bit lanes swapped.
22152              E.g. { 07 12 1e 09 ... | 17 19 05 1f ... } mask vector will have
22153              t1   { 07 92 9e 09 ... | 17 19 85 1f ... } and
22154              t3   { 97 99 05 9f ... | 87 12 1e 89 ... } where each ...
22155              stands for other 12 bytes.  */
22156           /* The bit whether element is from the same lane or the other
22157              lane is bit 4, so shift it up by 3 to the MSB position.  */
22158           t5 = gen_reg_rtx (V4DImode);
22159           emit_insn (gen_ashlv4di3 (t5, gen_lowpart (V4DImode, mask),
22160                                     GEN_INT (3)));
22161           /* Clear MSB bits from the mask just in case it had them set.  */
22162           emit_insn (gen_avx2_andnotv32qi3 (t2, vt, mask));
22163           /* After this t1 will have MSB set for elements from other lane.  */
22164           emit_insn (gen_xorv32qi3 (t1, gen_lowpart (V32QImode, t5), vt2));
22165           /* Clear bits other than MSB.  */
22166           emit_insn (gen_andv32qi3 (t1, t1, vt));
22167           /* Or in the lower bits from mask into t3.  */
22168           emit_insn (gen_iorv32qi3 (t3, t1, t2));
22169           /* And invert MSB bits in t1, so MSB is set for elements from the same
22170              lane.  */
22171           emit_insn (gen_xorv32qi3 (t1, t1, vt));
22172           /* Swap 128-bit lanes in t3.  */
22173           t6 = gen_reg_rtx (V4DImode);
22174           emit_insn (gen_avx2_permv4di_1 (t6, gen_lowpart (V4DImode, t3),
22175                                           const2_rtx, GEN_INT (3),
22176                                           const0_rtx, const1_rtx));
22177           /* And or in the lower bits from mask into t1.  */
22178           emit_insn (gen_iorv32qi3 (t1, t1, t2));
22179           if (one_operand_shuffle)
22180             {
22181               /* Each of these shuffles will put 0s in places where
22182                  element from the other 128-bit lane is needed, otherwise
22183                  will shuffle in the requested value.  */
22184               emit_insn (gen_avx2_pshufbv32qi3 (t3, op0,
22185                                                 gen_lowpart (V32QImode, t6)));
22186               emit_insn (gen_avx2_pshufbv32qi3 (t1, op0, t1));
22187               /* For t3 the 128-bit lanes are swapped again.  */
22188               t7 = gen_reg_rtx (V4DImode);
22189               emit_insn (gen_avx2_permv4di_1 (t7, gen_lowpart (V4DImode, t3),
22190                                               const2_rtx, GEN_INT (3),
22191                                               const0_rtx, const1_rtx));
22192               /* And oring both together leads to the result.  */
22193               emit_insn (gen_iorv32qi3 (target, t1,
22194                                         gen_lowpart (V32QImode, t7)));
22195               if (target != operands[0])
22196                 emit_move_insn (operands[0],
22197                                 gen_lowpart (GET_MODE (operands[0]), target));
22198               return;
22199             }
22200
22201           t4 = gen_reg_rtx (V32QImode);
22202           /* Similarly to the above one_operand_shuffle code,
22203              just for repeated twice for each operand.  merge_two:
22204              code will merge the two results together.  */
22205           emit_insn (gen_avx2_pshufbv32qi3 (t4, op0,
22206                                             gen_lowpart (V32QImode, t6)));
22207           emit_insn (gen_avx2_pshufbv32qi3 (t3, op1,
22208                                             gen_lowpart (V32QImode, t6)));
22209           emit_insn (gen_avx2_pshufbv32qi3 (t2, op0, t1));
22210           emit_insn (gen_avx2_pshufbv32qi3 (t1, op1, t1));
22211           t7 = gen_reg_rtx (V4DImode);
22212           emit_insn (gen_avx2_permv4di_1 (t7, gen_lowpart (V4DImode, t4),
22213                                           const2_rtx, GEN_INT (3),
22214                                           const0_rtx, const1_rtx));
22215           t8 = gen_reg_rtx (V4DImode);
22216           emit_insn (gen_avx2_permv4di_1 (t8, gen_lowpart (V4DImode, t3),
22217                                           const2_rtx, GEN_INT (3),
22218                                           const0_rtx, const1_rtx));
22219           emit_insn (gen_iorv32qi3 (t4, t2, gen_lowpart (V32QImode, t7)));
22220           emit_insn (gen_iorv32qi3 (t3, t1, gen_lowpart (V32QImode, t8)));
22221           t1 = t4;
22222           t2 = t3;
22223           goto merge_two;
22224
22225         default:
22226           gcc_assert (GET_MODE_SIZE (mode) <= 16);
22227           break;
22228         }
22229     }
22230
22231   if (TARGET_XOP)
22232     {
22233       /* The XOP VPPERM insn supports three inputs.  By ignoring the 
22234          one_operand_shuffle special case, we avoid creating another
22235          set of constant vectors in memory.  */
22236       one_operand_shuffle = false;
22237
22238       /* mask = mask & {2*w-1, ...} */
22239       vt = GEN_INT (2*w - 1);
22240     }
22241   else
22242     {
22243       /* mask = mask & {w-1, ...} */
22244       vt = GEN_INT (w - 1);
22245     }
22246
22247   for (i = 0; i < w; i++)
22248     vec[i] = vt;
22249   vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22250   mask = expand_simple_binop (maskmode, AND, mask, vt,
22251                               NULL_RTX, 0, OPTAB_DIRECT);
22252
22253   /* For non-QImode operations, convert the word permutation control
22254      into a byte permutation control.  */
22255   if (mode != V16QImode)
22256     {
22257       mask = expand_simple_binop (maskmode, ASHIFT, mask,
22258                                   GEN_INT (exact_log2 (e)),
22259                                   NULL_RTX, 0, OPTAB_DIRECT);
22260
22261       /* Convert mask to vector of chars.  */
22262       mask = force_reg (V16QImode, gen_lowpart (V16QImode, mask));
22263
22264       /* Replicate each of the input bytes into byte positions:
22265          (v2di) --> {0,0,0,0,0,0,0,0, 8,8,8,8,8,8,8,8}
22266          (v4si) --> {0,0,0,0, 4,4,4,4, 8,8,8,8, 12,12,12,12}
22267          (v8hi) --> {0,0, 2,2, 4,4, 6,6, ...}.  */
22268       for (i = 0; i < 16; ++i)
22269         vec[i] = GEN_INT (i/e * e);
22270       vt = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, vec));
22271       vt = validize_mem (force_const_mem (V16QImode, vt));
22272       if (TARGET_XOP)
22273         emit_insn (gen_xop_pperm (mask, mask, mask, vt));
22274       else
22275         emit_insn (gen_ssse3_pshufbv16qi3 (mask, mask, vt));
22276
22277       /* Convert it into the byte positions by doing
22278          mask = mask + {0,1,..,16/w, 0,1,..,16/w, ...}  */
22279       for (i = 0; i < 16; ++i)
22280         vec[i] = GEN_INT (i % e);
22281       vt = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, vec));
22282       vt = validize_mem (force_const_mem (V16QImode, vt));
22283       emit_insn (gen_addv16qi3 (mask, mask, vt));
22284     }
22285
22286   /* The actual shuffle operations all operate on V16QImode.  */
22287   op0 = gen_lowpart (V16QImode, op0);
22288   op1 = gen_lowpart (V16QImode, op1);
22289
22290   if (TARGET_XOP)
22291     {
22292       if (GET_MODE (target) != V16QImode)
22293         target = gen_reg_rtx (V16QImode);
22294       emit_insn (gen_xop_pperm (target, op0, op1, mask));
22295       if (target != operands[0])
22296         emit_move_insn (operands[0],
22297                         gen_lowpart (GET_MODE (operands[0]), target));
22298     }
22299   else if (one_operand_shuffle)
22300     {
22301       if (GET_MODE (target) != V16QImode)
22302         target = gen_reg_rtx (V16QImode);
22303       emit_insn (gen_ssse3_pshufbv16qi3 (target, op0, mask));
22304       if (target != operands[0])
22305         emit_move_insn (operands[0],
22306                         gen_lowpart (GET_MODE (operands[0]), target));
22307     }
22308   else
22309     {
22310       rtx xops[6];
22311       bool ok;
22312
22313       /* Shuffle the two input vectors independently.  */
22314       t1 = gen_reg_rtx (V16QImode);
22315       t2 = gen_reg_rtx (V16QImode);
22316       emit_insn (gen_ssse3_pshufbv16qi3 (t1, op0, mask));
22317       emit_insn (gen_ssse3_pshufbv16qi3 (t2, op1, mask));
22318
22319  merge_two:
22320       /* Then merge them together.  The key is whether any given control
22321          element contained a bit set that indicates the second word.  */
22322       mask = operands[3];
22323       vt = GEN_INT (w);
22324       if (maskmode == V2DImode && !TARGET_SSE4_1)
22325         {
22326           /* Without SSE4.1, we don't have V2DImode EQ.  Perform one
22327              more shuffle to convert the V2DI input mask into a V4SI
22328              input mask.  At which point the masking that expand_int_vcond
22329              will work as desired.  */
22330           rtx t3 = gen_reg_rtx (V4SImode);
22331           emit_insn (gen_sse2_pshufd_1 (t3, gen_lowpart (V4SImode, mask),
22332                                         const0_rtx, const0_rtx,
22333                                         const2_rtx, const2_rtx));
22334           mask = t3;
22335           maskmode = V4SImode;
22336           e = w = 4;
22337         }
22338
22339       for (i = 0; i < w; i++)
22340         vec[i] = vt;
22341       vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22342       vt = force_reg (maskmode, vt);
22343       mask = expand_simple_binop (maskmode, AND, mask, vt,
22344                                   NULL_RTX, 0, OPTAB_DIRECT);
22345
22346       if (GET_MODE (target) != mode)
22347         target = gen_reg_rtx (mode);
22348       xops[0] = target;
22349       xops[1] = gen_lowpart (mode, t2);
22350       xops[2] = gen_lowpart (mode, t1);
22351       xops[3] = gen_rtx_EQ (maskmode, mask, vt);
22352       xops[4] = mask;
22353       xops[5] = vt;
22354       ok = ix86_expand_int_vcond (xops);
22355       gcc_assert (ok);
22356       if (target != operands[0])
22357         emit_move_insn (operands[0],
22358                         gen_lowpart (GET_MODE (operands[0]), target));
22359     }
22360 }
22361
22362 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
22363    true if we should do zero extension, else sign extension.  HIGH_P is
22364    true if we want the N/2 high elements, else the low elements.  */
22365
22366 void
22367 ix86_expand_sse_unpack (rtx dest, rtx src, bool unsigned_p, bool high_p)
22368 {
22369   machine_mode imode = GET_MODE (src);
22370   rtx tmp;
22371
22372   if (TARGET_SSE4_1)
22373     {
22374       rtx (*unpack)(rtx, rtx);
22375       rtx (*extract)(rtx, rtx) = NULL;
22376       machine_mode halfmode = BLKmode;
22377
22378       switch (imode)
22379         {
22380         case V64QImode:
22381           if (unsigned_p)
22382             unpack = gen_avx512bw_zero_extendv32qiv32hi2;
22383           else
22384             unpack = gen_avx512bw_sign_extendv32qiv32hi2;
22385           halfmode = V32QImode;
22386           extract
22387             = high_p ? gen_vec_extract_hi_v64qi : gen_vec_extract_lo_v64qi;
22388           break;
22389         case V32QImode:
22390           if (unsigned_p)
22391             unpack = gen_avx2_zero_extendv16qiv16hi2;
22392           else
22393             unpack = gen_avx2_sign_extendv16qiv16hi2;
22394           halfmode = V16QImode;
22395           extract
22396             = high_p ? gen_vec_extract_hi_v32qi : gen_vec_extract_lo_v32qi;
22397           break;
22398         case V32HImode:
22399           if (unsigned_p)
22400             unpack = gen_avx512f_zero_extendv16hiv16si2;
22401           else
22402             unpack = gen_avx512f_sign_extendv16hiv16si2;
22403           halfmode = V16HImode;
22404           extract
22405             = high_p ? gen_vec_extract_hi_v32hi : gen_vec_extract_lo_v32hi;
22406           break;
22407         case V16HImode:
22408           if (unsigned_p)
22409             unpack = gen_avx2_zero_extendv8hiv8si2;
22410           else
22411             unpack = gen_avx2_sign_extendv8hiv8si2;
22412           halfmode = V8HImode;
22413           extract
22414             = high_p ? gen_vec_extract_hi_v16hi : gen_vec_extract_lo_v16hi;
22415           break;
22416         case V16SImode:
22417           if (unsigned_p)
22418             unpack = gen_avx512f_zero_extendv8siv8di2;
22419           else
22420             unpack = gen_avx512f_sign_extendv8siv8di2;
22421           halfmode = V8SImode;
22422           extract
22423             = high_p ? gen_vec_extract_hi_v16si : gen_vec_extract_lo_v16si;
22424           break;
22425         case V8SImode:
22426           if (unsigned_p)
22427             unpack = gen_avx2_zero_extendv4siv4di2;
22428           else
22429             unpack = gen_avx2_sign_extendv4siv4di2;
22430           halfmode = V4SImode;
22431           extract
22432             = high_p ? gen_vec_extract_hi_v8si : gen_vec_extract_lo_v8si;
22433           break;
22434         case V16QImode:
22435           if (unsigned_p)
22436             unpack = gen_sse4_1_zero_extendv8qiv8hi2;
22437           else
22438             unpack = gen_sse4_1_sign_extendv8qiv8hi2;
22439           break;
22440         case V8HImode:
22441           if (unsigned_p)
22442             unpack = gen_sse4_1_zero_extendv4hiv4si2;
22443           else
22444             unpack = gen_sse4_1_sign_extendv4hiv4si2;
22445           break;
22446         case V4SImode:
22447           if (unsigned_p)
22448             unpack = gen_sse4_1_zero_extendv2siv2di2;
22449           else
22450             unpack = gen_sse4_1_sign_extendv2siv2di2;
22451           break;
22452         default:
22453           gcc_unreachable ();
22454         }
22455
22456       if (GET_MODE_SIZE (imode) >= 32)
22457         {
22458           tmp = gen_reg_rtx (halfmode);
22459           emit_insn (extract (tmp, src));
22460         }
22461       else if (high_p)
22462         {
22463           /* Shift higher 8 bytes to lower 8 bytes.  */
22464           tmp = gen_reg_rtx (V1TImode);
22465           emit_insn (gen_sse2_lshrv1ti3 (tmp, gen_lowpart (V1TImode, src),
22466                                          GEN_INT (64)));
22467           tmp = gen_lowpart (imode, tmp);
22468         }
22469       else
22470         tmp = src;
22471
22472       emit_insn (unpack (dest, tmp));
22473     }
22474   else
22475     {
22476       rtx (*unpack)(rtx, rtx, rtx);
22477
22478       switch (imode)
22479         {
22480         case V16QImode:
22481           if (high_p)
22482             unpack = gen_vec_interleave_highv16qi;
22483           else
22484             unpack = gen_vec_interleave_lowv16qi;
22485           break;
22486         case V8HImode:
22487           if (high_p)
22488             unpack = gen_vec_interleave_highv8hi;
22489           else
22490             unpack = gen_vec_interleave_lowv8hi;
22491           break;
22492         case V4SImode:
22493           if (high_p)
22494             unpack = gen_vec_interleave_highv4si;
22495           else
22496             unpack = gen_vec_interleave_lowv4si;
22497           break;
22498         default:
22499           gcc_unreachable ();
22500         }
22501
22502       if (unsigned_p)
22503         tmp = force_reg (imode, CONST0_RTX (imode));
22504       else
22505         tmp = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
22506                                    src, pc_rtx, pc_rtx);
22507
22508       rtx tmp2 = gen_reg_rtx (imode);
22509       emit_insn (unpack (tmp2, src, tmp));
22510       emit_move_insn (dest, gen_lowpart (GET_MODE (dest), tmp2));
22511     }
22512 }
22513
22514 /* Expand conditional increment or decrement using adb/sbb instructions.
22515    The default case using setcc followed by the conditional move can be
22516    done by generic code.  */
22517 bool
22518 ix86_expand_int_addcc (rtx operands[])
22519 {
22520   enum rtx_code code = GET_CODE (operands[1]);
22521   rtx flags;
22522   rtx (*insn)(rtx, rtx, rtx, rtx, rtx);
22523   rtx compare_op;
22524   rtx val = const0_rtx;
22525   bool fpcmp = false;
22526   machine_mode mode;
22527   rtx op0 = XEXP (operands[1], 0);
22528   rtx op1 = XEXP (operands[1], 1);
22529
22530   if (operands[3] != const1_rtx
22531       && operands[3] != constm1_rtx)
22532     return false;
22533   if (!ix86_expand_carry_flag_compare (code, op0, op1, &compare_op))
22534      return false;
22535   code = GET_CODE (compare_op);
22536
22537   flags = XEXP (compare_op, 0);
22538
22539   if (GET_MODE (flags) == CCFPmode
22540       || GET_MODE (flags) == CCFPUmode)
22541     {
22542       fpcmp = true;
22543       code = ix86_fp_compare_code_to_integer (code);
22544     }
22545
22546   if (code != LTU)
22547     {
22548       val = constm1_rtx;
22549       if (fpcmp)
22550         PUT_CODE (compare_op,
22551                   reverse_condition_maybe_unordered
22552                     (GET_CODE (compare_op)));
22553       else
22554         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
22555     }
22556
22557   mode = GET_MODE (operands[0]);
22558
22559   /* Construct either adc or sbb insn.  */
22560   if ((code == LTU) == (operands[3] == constm1_rtx))
22561     {
22562       switch (mode)
22563         {
22564           case QImode:
22565             insn = gen_subqi3_carry;
22566             break;
22567           case HImode:
22568             insn = gen_subhi3_carry;
22569             break;
22570           case SImode:
22571             insn = gen_subsi3_carry;
22572             break;
22573           case DImode:
22574             insn = gen_subdi3_carry;
22575             break;
22576           default:
22577             gcc_unreachable ();
22578         }
22579     }
22580   else
22581     {
22582       switch (mode)
22583         {
22584           case QImode:
22585             insn = gen_addqi3_carry;
22586             break;
22587           case HImode:
22588             insn = gen_addhi3_carry;
22589             break;
22590           case SImode:
22591             insn = gen_addsi3_carry;
22592             break;
22593           case DImode:
22594             insn = gen_adddi3_carry;
22595             break;
22596           default:
22597             gcc_unreachable ();
22598         }
22599     }
22600   emit_insn (insn (operands[0], operands[2], val, flags, compare_op));
22601
22602   return true;
22603 }
22604
22605
22606 /* Split operands 0 and 1 into half-mode parts.  Similar to split_double_mode,
22607    but works for floating pointer parameters and nonoffsetable memories.
22608    For pushes, it returns just stack offsets; the values will be saved
22609    in the right order.  Maximally three parts are generated.  */
22610
22611 static int
22612 ix86_split_to_parts (rtx operand, rtx *parts, machine_mode mode)
22613 {
22614   int size;
22615
22616   if (!TARGET_64BIT)
22617     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
22618   else
22619     size = (GET_MODE_SIZE (mode) + 4) / 8;
22620
22621   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
22622   gcc_assert (size >= 2 && size <= 4);
22623
22624   /* Optimize constant pool reference to immediates.  This is used by fp
22625      moves, that force all constants to memory to allow combining.  */
22626   if (MEM_P (operand) && MEM_READONLY_P (operand))
22627     {
22628       rtx tmp = maybe_get_pool_constant (operand);
22629       if (tmp)
22630         operand = tmp;
22631     }
22632
22633   if (MEM_P (operand) && !offsettable_memref_p (operand))
22634     {
22635       /* The only non-offsetable memories we handle are pushes.  */
22636       int ok = push_operand (operand, VOIDmode);
22637
22638       gcc_assert (ok);
22639
22640       operand = copy_rtx (operand);
22641       PUT_MODE (operand, word_mode);
22642       parts[0] = parts[1] = parts[2] = parts[3] = operand;
22643       return size;
22644     }
22645
22646   if (GET_CODE (operand) == CONST_VECTOR)
22647     {
22648       machine_mode imode = int_mode_for_mode (mode);
22649       /* Caution: if we looked through a constant pool memory above,
22650          the operand may actually have a different mode now.  That's
22651          ok, since we want to pun this all the way back to an integer.  */
22652       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
22653       gcc_assert (operand != NULL);
22654       mode = imode;
22655     }
22656
22657   if (!TARGET_64BIT)
22658     {
22659       if (mode == DImode)
22660         split_double_mode (mode, &operand, 1, &parts[0], &parts[1]);
22661       else
22662         {
22663           int i;
22664
22665           if (REG_P (operand))
22666             {
22667               gcc_assert (reload_completed);
22668               for (i = 0; i < size; i++)
22669                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
22670             }
22671           else if (offsettable_memref_p (operand))
22672             {
22673               operand = adjust_address (operand, SImode, 0);
22674               parts[0] = operand;
22675               for (i = 1; i < size; i++)
22676                 parts[i] = adjust_address (operand, SImode, 4 * i);
22677             }
22678           else if (CONST_DOUBLE_P (operand))
22679             {
22680               REAL_VALUE_TYPE r;
22681               long l[4];
22682
22683               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
22684               switch (mode)
22685                 {
22686                 case TFmode:
22687                   real_to_target (l, &r, mode);
22688                   parts[3] = gen_int_mode (l[3], SImode);
22689                   parts[2] = gen_int_mode (l[2], SImode);
22690                   break;
22691                 case XFmode:
22692                   /* We can't use REAL_VALUE_TO_TARGET_LONG_DOUBLE since
22693                      long double may not be 80-bit.  */
22694                   real_to_target (l, &r, mode);
22695                   parts[2] = gen_int_mode (l[2], SImode);
22696                   break;
22697                 case DFmode:
22698                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
22699                   break;
22700                 default:
22701                   gcc_unreachable ();
22702                 }
22703               parts[1] = gen_int_mode (l[1], SImode);
22704               parts[0] = gen_int_mode (l[0], SImode);
22705             }
22706           else
22707             gcc_unreachable ();
22708         }
22709     }
22710   else
22711     {
22712       if (mode == TImode)
22713         split_double_mode (mode, &operand, 1, &parts[0], &parts[1]);
22714       if (mode == XFmode || mode == TFmode)
22715         {
22716           machine_mode upper_mode = mode==XFmode ? SImode : DImode;
22717           if (REG_P (operand))
22718             {
22719               gcc_assert (reload_completed);
22720               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
22721               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
22722             }
22723           else if (offsettable_memref_p (operand))
22724             {
22725               operand = adjust_address (operand, DImode, 0);
22726               parts[0] = operand;
22727               parts[1] = adjust_address (operand, upper_mode, 8);
22728             }
22729           else if (CONST_DOUBLE_P (operand))
22730             {
22731               REAL_VALUE_TYPE r;
22732               long l[4];
22733
22734               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
22735               real_to_target (l, &r, mode);
22736
22737               /* real_to_target puts 32-bit pieces in each long.  */
22738               parts[0] =
22739                 gen_int_mode
22740                   ((l[0] & (HOST_WIDE_INT) 0xffffffff)
22741                    | ((l[1] & (HOST_WIDE_INT) 0xffffffff) << 32),
22742                    DImode);
22743
22744               if (upper_mode == SImode)
22745                 parts[1] = gen_int_mode (l[2], SImode);
22746               else
22747                 parts[1] =
22748                   gen_int_mode
22749                     ((l[2] & (HOST_WIDE_INT) 0xffffffff)
22750                      | ((l[3] & (HOST_WIDE_INT) 0xffffffff) << 32),
22751                      DImode);
22752             }
22753           else
22754             gcc_unreachable ();
22755         }
22756     }
22757
22758   return size;
22759 }
22760
22761 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
22762    Return false when normal moves are needed; true when all required
22763    insns have been emitted.  Operands 2-4 contain the input values
22764    int the correct order; operands 5-7 contain the output values.  */
22765
22766 void
22767 ix86_split_long_move (rtx operands[])
22768 {
22769   rtx part[2][4];
22770   int nparts, i, j;
22771   int push = 0;
22772   int collisions = 0;
22773   machine_mode mode = GET_MODE (operands[0]);
22774   bool collisionparts[4];
22775
22776   /* The DFmode expanders may ask us to move double.
22777      For 64bit target this is single move.  By hiding the fact
22778      here we simplify i386.md splitters.  */
22779   if (TARGET_64BIT && GET_MODE_SIZE (GET_MODE (operands[0])) == 8)
22780     {
22781       /* Optimize constant pool reference to immediates.  This is used by
22782          fp moves, that force all constants to memory to allow combining.  */
22783
22784       if (MEM_P (operands[1])
22785           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
22786           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
22787         operands[1] = get_pool_constant (XEXP (operands[1], 0));
22788       if (push_operand (operands[0], VOIDmode))
22789         {
22790           operands[0] = copy_rtx (operands[0]);
22791           PUT_MODE (operands[0], word_mode);
22792         }
22793       else
22794         operands[0] = gen_lowpart (DImode, operands[0]);
22795       operands[1] = gen_lowpart (DImode, operands[1]);
22796       emit_move_insn (operands[0], operands[1]);
22797       return;
22798     }
22799
22800   /* The only non-offsettable memory we handle is push.  */
22801   if (push_operand (operands[0], VOIDmode))
22802     push = 1;
22803   else
22804     gcc_assert (!MEM_P (operands[0])
22805                 || offsettable_memref_p (operands[0]));
22806
22807   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
22808   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
22809
22810   /* When emitting push, take care for source operands on the stack.  */
22811   if (push && MEM_P (operands[1])
22812       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
22813     {
22814       rtx src_base = XEXP (part[1][nparts - 1], 0);
22815
22816       /* Compensate for the stack decrement by 4.  */
22817       if (!TARGET_64BIT && nparts == 3
22818           && mode == XFmode && TARGET_128BIT_LONG_DOUBLE)
22819         src_base = plus_constant (Pmode, src_base, 4);
22820
22821       /* src_base refers to the stack pointer and is
22822          automatically decreased by emitted push.  */
22823       for (i = 0; i < nparts; i++)
22824         part[1][i] = change_address (part[1][i],
22825                                      GET_MODE (part[1][i]), src_base);
22826     }
22827
22828   /* We need to do copy in the right order in case an address register
22829      of the source overlaps the destination.  */
22830   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
22831     {
22832       rtx tmp;
22833
22834       for (i = 0; i < nparts; i++)
22835         {
22836           collisionparts[i]
22837             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
22838           if (collisionparts[i])
22839             collisions++;
22840         }
22841
22842       /* Collision in the middle part can be handled by reordering.  */
22843       if (collisions == 1 && nparts == 3 && collisionparts [1])
22844         {
22845           std::swap (part[0][1], part[0][2]);
22846           std::swap (part[1][1], part[1][2]);
22847         }
22848       else if (collisions == 1
22849                && nparts == 4
22850                && (collisionparts [1] || collisionparts [2]))
22851         {
22852           if (collisionparts [1])
22853             {
22854               std::swap (part[0][1], part[0][2]);
22855               std::swap (part[1][1], part[1][2]);
22856             }
22857           else
22858             {
22859               std::swap (part[0][2], part[0][3]);
22860               std::swap (part[1][2], part[1][3]);
22861             }
22862         }
22863
22864       /* If there are more collisions, we can't handle it by reordering.
22865          Do an lea to the last part and use only one colliding move.  */
22866       else if (collisions > 1)
22867         {
22868           rtx base, addr, tls_base = NULL_RTX;
22869
22870           collisions = 1;
22871
22872           base = part[0][nparts - 1];
22873
22874           /* Handle the case when the last part isn't valid for lea.
22875              Happens in 64-bit mode storing the 12-byte XFmode.  */
22876           if (GET_MODE (base) != Pmode)
22877             base = gen_rtx_REG (Pmode, REGNO (base));
22878
22879           addr = XEXP (part[1][0], 0);
22880           if (TARGET_TLS_DIRECT_SEG_REFS)
22881             {
22882               struct ix86_address parts;
22883               int ok = ix86_decompose_address (addr, &parts);
22884               gcc_assert (ok);
22885               if (parts.seg == DEFAULT_TLS_SEG_REG)
22886                 {
22887                   /* It is not valid to use %gs: or %fs: in
22888                      lea though, so we need to remove it from the
22889                      address used for lea and add it to each individual
22890                      memory loads instead.  */
22891                   addr = copy_rtx (addr);
22892                   rtx *x = &addr;
22893                   while (GET_CODE (*x) == PLUS)
22894                     {
22895                       for (i = 0; i < 2; i++)
22896                         {
22897                           rtx u = XEXP (*x, i);
22898                           if (GET_CODE (u) == ZERO_EXTEND)
22899                             u = XEXP (u, 0);
22900                           if (GET_CODE (u) == UNSPEC
22901                               && XINT (u, 1) == UNSPEC_TP)
22902                             {
22903                               tls_base = XEXP (*x, i);
22904                               *x = XEXP (*x, 1 - i);
22905                               break;
22906                             }
22907                         }
22908                       if (tls_base)
22909                         break;
22910                       x = &XEXP (*x, 0);
22911                     }
22912                   gcc_assert (tls_base);
22913                 }
22914             }
22915           emit_insn (gen_rtx_SET (base, addr));
22916           if (tls_base)
22917             base = gen_rtx_PLUS (GET_MODE (base), base, tls_base);
22918           part[1][0] = replace_equiv_address (part[1][0], base);
22919           for (i = 1; i < nparts; i++)
22920             {
22921               if (tls_base)
22922                 base = copy_rtx (base);
22923               tmp = plus_constant (Pmode, base, UNITS_PER_WORD * i);
22924               part[1][i] = replace_equiv_address (part[1][i], tmp);
22925             }
22926         }
22927     }
22928
22929   if (push)
22930     {
22931       if (!TARGET_64BIT)
22932         {
22933           if (nparts == 3)
22934             {
22935               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
22936                 emit_insn (ix86_gen_add3 (stack_pointer_rtx,
22937                                           stack_pointer_rtx, GEN_INT (-4)));
22938               emit_move_insn (part[0][2], part[1][2]);
22939             }
22940           else if (nparts == 4)
22941             {
22942               emit_move_insn (part[0][3], part[1][3]);
22943               emit_move_insn (part[0][2], part[1][2]);
22944             }
22945         }
22946       else
22947         {
22948           /* In 64bit mode we don't have 32bit push available.  In case this is
22949              register, it is OK - we will just use larger counterpart.  We also
22950              retype memory - these comes from attempt to avoid REX prefix on
22951              moving of second half of TFmode value.  */
22952           if (GET_MODE (part[1][1]) == SImode)
22953             {
22954               switch (GET_CODE (part[1][1]))
22955                 {
22956                 case MEM:
22957                   part[1][1] = adjust_address (part[1][1], DImode, 0);
22958                   break;
22959
22960                 case REG:
22961                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
22962                   break;
22963
22964                 default:
22965                   gcc_unreachable ();
22966                 }
22967
22968               if (GET_MODE (part[1][0]) == SImode)
22969                 part[1][0] = part[1][1];
22970             }
22971         }
22972       emit_move_insn (part[0][1], part[1][1]);
22973       emit_move_insn (part[0][0], part[1][0]);
22974       return;
22975     }
22976
22977   /* Choose correct order to not overwrite the source before it is copied.  */
22978   if ((REG_P (part[0][0])
22979        && REG_P (part[1][1])
22980        && (REGNO (part[0][0]) == REGNO (part[1][1])
22981            || (nparts == 3
22982                && REGNO (part[0][0]) == REGNO (part[1][2]))
22983            || (nparts == 4
22984                && REGNO (part[0][0]) == REGNO (part[1][3]))))
22985       || (collisions > 0
22986           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
22987     {
22988       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
22989         {
22990           operands[2 + i] = part[0][j];
22991           operands[6 + i] = part[1][j];
22992         }
22993     }
22994   else
22995     {
22996       for (i = 0; i < nparts; i++)
22997         {
22998           operands[2 + i] = part[0][i];
22999           operands[6 + i] = part[1][i];
23000         }
23001     }
23002
23003   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
23004   if (optimize_insn_for_size_p ())
23005     {
23006       for (j = 0; j < nparts - 1; j++)
23007         if (CONST_INT_P (operands[6 + j])
23008             && operands[6 + j] != const0_rtx
23009             && REG_P (operands[2 + j]))
23010           for (i = j; i < nparts - 1; i++)
23011             if (CONST_INT_P (operands[7 + i])
23012                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
23013               operands[7 + i] = operands[2 + j];
23014     }
23015
23016   for (i = 0; i < nparts; i++)
23017     emit_move_insn (operands[2 + i], operands[6 + i]);
23018
23019   return;
23020 }
23021
23022 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
23023    left shift by a constant, either using a single shift or
23024    a sequence of add instructions.  */
23025
23026 static void
23027 ix86_expand_ashl_const (rtx operand, int count, machine_mode mode)
23028 {
23029   rtx (*insn)(rtx, rtx, rtx);
23030
23031   if (count == 1
23032       || (count * ix86_cost->add <= ix86_cost->shift_const
23033           && !optimize_insn_for_size_p ()))
23034     {
23035       insn = mode == DImode ? gen_addsi3 : gen_adddi3;
23036       while (count-- > 0)
23037         emit_insn (insn (operand, operand, operand));
23038     }
23039   else
23040     {
23041       insn = mode == DImode ? gen_ashlsi3 : gen_ashldi3;
23042       emit_insn (insn (operand, operand, GEN_INT (count)));
23043     }
23044 }
23045
23046 void
23047 ix86_split_ashl (rtx *operands, rtx scratch, machine_mode mode)
23048 {
23049   rtx (*gen_ashl3)(rtx, rtx, rtx);
23050   rtx (*gen_shld)(rtx, rtx, rtx);
23051   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23052
23053   rtx low[2], high[2];
23054   int count;
23055
23056   if (CONST_INT_P (operands[2]))
23057     {
23058       split_double_mode (mode, operands, 2, low, high);
23059       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23060
23061       if (count >= half_width)
23062         {
23063           emit_move_insn (high[0], low[1]);
23064           emit_move_insn (low[0], const0_rtx);
23065
23066           if (count > half_width)
23067             ix86_expand_ashl_const (high[0], count - half_width, mode);
23068         }
23069       else
23070         {
23071           gen_shld = mode == DImode ? gen_x86_shld : gen_x86_64_shld;
23072
23073           if (!rtx_equal_p (operands[0], operands[1]))
23074             emit_move_insn (operands[0], operands[1]);
23075
23076           emit_insn (gen_shld (high[0], low[0], GEN_INT (count)));
23077           ix86_expand_ashl_const (low[0], count, mode);
23078         }
23079       return;
23080     }
23081
23082   split_double_mode (mode, operands, 1, low, high);
23083
23084   gen_ashl3 = mode == DImode ? gen_ashlsi3 : gen_ashldi3;
23085
23086   if (operands[1] == const1_rtx)
23087     {
23088       /* Assuming we've chosen a QImode capable registers, then 1 << N
23089          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
23090       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
23091         {
23092           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
23093
23094           ix86_expand_clear (low[0]);
23095           ix86_expand_clear (high[0]);
23096           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (half_width)));
23097
23098           d = gen_lowpart (QImode, low[0]);
23099           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
23100           s = gen_rtx_EQ (QImode, flags, const0_rtx);
23101           emit_insn (gen_rtx_SET (d, s));
23102
23103           d = gen_lowpart (QImode, high[0]);
23104           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
23105           s = gen_rtx_NE (QImode, flags, const0_rtx);
23106           emit_insn (gen_rtx_SET (d, s));
23107         }
23108
23109       /* Otherwise, we can get the same results by manually performing
23110          a bit extract operation on bit 5/6, and then performing the two
23111          shifts.  The two methods of getting 0/1 into low/high are exactly
23112          the same size.  Avoiding the shift in the bit extract case helps
23113          pentium4 a bit; no one else seems to care much either way.  */
23114       else
23115         {
23116           machine_mode half_mode;
23117           rtx (*gen_lshr3)(rtx, rtx, rtx);
23118           rtx (*gen_and3)(rtx, rtx, rtx);
23119           rtx (*gen_xor3)(rtx, rtx, rtx);
23120           HOST_WIDE_INT bits;
23121           rtx x;
23122
23123           if (mode == DImode)
23124             {
23125               half_mode = SImode;
23126               gen_lshr3 = gen_lshrsi3;
23127               gen_and3 = gen_andsi3;
23128               gen_xor3 = gen_xorsi3;
23129               bits = 5;
23130             }
23131           else
23132             {
23133               half_mode = DImode;
23134               gen_lshr3 = gen_lshrdi3;
23135               gen_and3 = gen_anddi3;
23136               gen_xor3 = gen_xordi3;
23137               bits = 6;
23138             }
23139
23140           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
23141             x = gen_rtx_ZERO_EXTEND (half_mode, operands[2]);
23142           else
23143             x = gen_lowpart (half_mode, operands[2]);
23144           emit_insn (gen_rtx_SET (high[0], x));
23145
23146           emit_insn (gen_lshr3 (high[0], high[0], GEN_INT (bits)));
23147           emit_insn (gen_and3 (high[0], high[0], const1_rtx));
23148           emit_move_insn (low[0], high[0]);
23149           emit_insn (gen_xor3 (low[0], low[0], const1_rtx));
23150         }
23151
23152       emit_insn (gen_ashl3 (low[0], low[0], operands[2]));
23153       emit_insn (gen_ashl3 (high[0], high[0], operands[2]));
23154       return;
23155     }
23156
23157   if (operands[1] == constm1_rtx)
23158     {
23159       /* For -1 << N, we can avoid the shld instruction, because we
23160          know that we're shifting 0...31/63 ones into a -1.  */
23161       emit_move_insn (low[0], constm1_rtx);
23162       if (optimize_insn_for_size_p ())
23163         emit_move_insn (high[0], low[0]);
23164       else
23165         emit_move_insn (high[0], constm1_rtx);
23166     }
23167   else
23168     {
23169       gen_shld = mode == DImode ? gen_x86_shld : gen_x86_64_shld;
23170
23171       if (!rtx_equal_p (operands[0], operands[1]))
23172         emit_move_insn (operands[0], operands[1]);
23173
23174       split_double_mode (mode, operands, 1, low, high);
23175       emit_insn (gen_shld (high[0], low[0], operands[2]));
23176     }
23177
23178   emit_insn (gen_ashl3 (low[0], low[0], operands[2]));
23179
23180   if (TARGET_CMOVE && scratch)
23181     {
23182       rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23183         = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23184
23185       ix86_expand_clear (scratch);
23186       emit_insn (gen_x86_shift_adj_1 (high[0], low[0], operands[2], scratch));
23187     }
23188   else
23189     {
23190       rtx (*gen_x86_shift_adj_2)(rtx, rtx, rtx)
23191         = mode == DImode ? gen_x86_shiftsi_adj_2 : gen_x86_shiftdi_adj_2;
23192
23193       emit_insn (gen_x86_shift_adj_2 (high[0], low[0], operands[2]));
23194     }
23195 }
23196
23197 void
23198 ix86_split_ashr (rtx *operands, rtx scratch, machine_mode mode)
23199 {
23200   rtx (*gen_ashr3)(rtx, rtx, rtx)
23201     = mode == DImode ? gen_ashrsi3 : gen_ashrdi3;
23202   rtx (*gen_shrd)(rtx, rtx, rtx);
23203   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23204
23205   rtx low[2], high[2];
23206   int count;
23207
23208   if (CONST_INT_P (operands[2]))
23209     {
23210       split_double_mode (mode, operands, 2, low, high);
23211       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23212
23213       if (count == GET_MODE_BITSIZE (mode) - 1)
23214         {
23215           emit_move_insn (high[0], high[1]);
23216           emit_insn (gen_ashr3 (high[0], high[0],
23217                                 GEN_INT (half_width - 1)));
23218           emit_move_insn (low[0], high[0]);
23219
23220         }
23221       else if (count >= half_width)
23222         {
23223           emit_move_insn (low[0], high[1]);
23224           emit_move_insn (high[0], low[0]);
23225           emit_insn (gen_ashr3 (high[0], high[0],
23226                                 GEN_INT (half_width - 1)));
23227
23228           if (count > half_width)
23229             emit_insn (gen_ashr3 (low[0], low[0],
23230                                   GEN_INT (count - half_width)));
23231         }
23232       else
23233         {
23234           gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23235
23236           if (!rtx_equal_p (operands[0], operands[1]))
23237             emit_move_insn (operands[0], operands[1]);
23238
23239           emit_insn (gen_shrd (low[0], high[0], GEN_INT (count)));
23240           emit_insn (gen_ashr3 (high[0], high[0], GEN_INT (count)));
23241         }
23242     }
23243   else
23244     {
23245       gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23246
23247      if (!rtx_equal_p (operands[0], operands[1]))
23248         emit_move_insn (operands[0], operands[1]);
23249
23250       split_double_mode (mode, operands, 1, low, high);
23251
23252       emit_insn (gen_shrd (low[0], high[0], operands[2]));
23253       emit_insn (gen_ashr3 (high[0], high[0], operands[2]));
23254
23255       if (TARGET_CMOVE && scratch)
23256         {
23257           rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23258             = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23259
23260           emit_move_insn (scratch, high[0]);
23261           emit_insn (gen_ashr3 (scratch, scratch,
23262                                 GEN_INT (half_width - 1)));
23263           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
23264                                           scratch));
23265         }
23266       else
23267         {
23268           rtx (*gen_x86_shift_adj_3)(rtx, rtx, rtx)
23269             = mode == DImode ? gen_x86_shiftsi_adj_3 : gen_x86_shiftdi_adj_3;
23270
23271           emit_insn (gen_x86_shift_adj_3 (low[0], high[0], operands[2]));
23272         }
23273     }
23274 }
23275
23276 void
23277 ix86_split_lshr (rtx *operands, rtx scratch, machine_mode mode)
23278 {
23279   rtx (*gen_lshr3)(rtx, rtx, rtx)
23280     = mode == DImode ? gen_lshrsi3 : gen_lshrdi3;
23281   rtx (*gen_shrd)(rtx, rtx, rtx);
23282   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23283
23284   rtx low[2], high[2];
23285   int count;
23286
23287   if (CONST_INT_P (operands[2]))
23288     {
23289       split_double_mode (mode, operands, 2, low, high);
23290       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23291
23292       if (count >= half_width)
23293         {
23294           emit_move_insn (low[0], high[1]);
23295           ix86_expand_clear (high[0]);
23296
23297           if (count > half_width)
23298             emit_insn (gen_lshr3 (low[0], low[0],
23299                                   GEN_INT (count - half_width)));
23300         }
23301       else
23302         {
23303           gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23304
23305           if (!rtx_equal_p (operands[0], operands[1]))
23306             emit_move_insn (operands[0], operands[1]);
23307
23308           emit_insn (gen_shrd (low[0], high[0], GEN_INT (count)));
23309           emit_insn (gen_lshr3 (high[0], high[0], GEN_INT (count)));
23310         }
23311     }
23312   else
23313     {
23314       gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23315
23316       if (!rtx_equal_p (operands[0], operands[1]))
23317         emit_move_insn (operands[0], operands[1]);
23318
23319       split_double_mode (mode, operands, 1, low, high);
23320
23321       emit_insn (gen_shrd (low[0], high[0], operands[2]));
23322       emit_insn (gen_lshr3 (high[0], high[0], operands[2]));
23323
23324       if (TARGET_CMOVE && scratch)
23325         {
23326           rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23327             = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23328
23329           ix86_expand_clear (scratch);
23330           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
23331                                           scratch));
23332         }
23333       else
23334         {
23335           rtx (*gen_x86_shift_adj_2)(rtx, rtx, rtx)
23336             = mode == DImode ? gen_x86_shiftsi_adj_2 : gen_x86_shiftdi_adj_2;
23337
23338           emit_insn (gen_x86_shift_adj_2 (low[0], high[0], operands[2]));
23339         }
23340     }
23341 }
23342
23343 /* Predict just emitted jump instruction to be taken with probability PROB.  */
23344 static void
23345 predict_jump (int prob)
23346 {
23347   rtx insn = get_last_insn ();
23348   gcc_assert (JUMP_P (insn));
23349   add_int_reg_note (insn, REG_BR_PROB, prob);
23350 }
23351
23352 /* Helper function for the string operations below.  Dest VARIABLE whether
23353    it is aligned to VALUE bytes.  If true, jump to the label.  */
23354 static rtx_code_label *
23355 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
23356 {
23357   rtx_code_label *label = gen_label_rtx ();
23358   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
23359   if (GET_MODE (variable) == DImode)
23360     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
23361   else
23362     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
23363   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
23364                            1, label);
23365   if (epilogue)
23366     predict_jump (REG_BR_PROB_BASE * 50 / 100);
23367   else
23368     predict_jump (REG_BR_PROB_BASE * 90 / 100);
23369   return label;
23370 }
23371
23372 /* Adjust COUNTER by the VALUE.  */
23373 static void
23374 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
23375 {
23376   rtx (*gen_add)(rtx, rtx, rtx)
23377     = GET_MODE (countreg) == DImode ? gen_adddi3 : gen_addsi3;
23378
23379   emit_insn (gen_add (countreg, countreg, GEN_INT (-value)));
23380 }
23381
23382 /* Zero extend possibly SImode EXP to Pmode register.  */
23383 rtx
23384 ix86_zero_extend_to_Pmode (rtx exp)
23385 {
23386   return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
23387 }
23388
23389 /* Divide COUNTREG by SCALE.  */
23390 static rtx
23391 scale_counter (rtx countreg, int scale)
23392 {
23393   rtx sc;
23394
23395   if (scale == 1)
23396     return countreg;
23397   if (CONST_INT_P (countreg))
23398     return GEN_INT (INTVAL (countreg) / scale);
23399   gcc_assert (REG_P (countreg));
23400
23401   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
23402                             GEN_INT (exact_log2 (scale)),
23403                             NULL, 1, OPTAB_DIRECT);
23404   return sc;
23405 }
23406
23407 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
23408    DImode for constant loop counts.  */
23409
23410 static machine_mode
23411 counter_mode (rtx count_exp)
23412 {
23413   if (GET_MODE (count_exp) != VOIDmode)
23414     return GET_MODE (count_exp);
23415   if (!CONST_INT_P (count_exp))
23416     return Pmode;
23417   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
23418     return DImode;
23419   return SImode;
23420 }
23421
23422 /* Copy the address to a Pmode register.  This is used for x32 to
23423    truncate DImode TLS address to a SImode register. */
23424
23425 static rtx
23426 ix86_copy_addr_to_reg (rtx addr)
23427 {
23428   rtx reg;
23429   if (GET_MODE (addr) == Pmode || GET_MODE (addr) == VOIDmode)
23430     {
23431       reg = copy_addr_to_reg (addr);
23432       REG_POINTER (reg) = 1;
23433       return reg;
23434     }
23435   else
23436     {
23437       gcc_assert (GET_MODE (addr) == DImode && Pmode == SImode);
23438       reg = copy_to_mode_reg (DImode, addr);
23439       REG_POINTER (reg) = 1;
23440       return gen_rtx_SUBREG (SImode, reg, 0);
23441     }
23442 }
23443
23444 /* When ISSETMEM is FALSE, output simple loop to move memory pointer to SRCPTR
23445    to DESTPTR via chunks of MODE unrolled UNROLL times, overall size is COUNT
23446    specified in bytes.  When ISSETMEM is TRUE, output the equivalent loop to set
23447    memory by VALUE (supposed to be in MODE).
23448
23449    The size is rounded down to whole number of chunk size moved at once.
23450    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
23451
23452
23453 static void
23454 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
23455                                rtx destptr, rtx srcptr, rtx value,
23456                                rtx count, machine_mode mode, int unroll,
23457                                int expected_size, bool issetmem)
23458 {
23459   rtx_code_label *out_label, *top_label;
23460   rtx iter, tmp;
23461   machine_mode iter_mode = counter_mode (count);
23462   int piece_size_n = GET_MODE_SIZE (mode) * unroll;
23463   rtx piece_size = GEN_INT (piece_size_n);
23464   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
23465   rtx size;
23466   int i;
23467
23468   top_label = gen_label_rtx ();
23469   out_label = gen_label_rtx ();
23470   iter = gen_reg_rtx (iter_mode);
23471
23472   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
23473                               NULL, 1, OPTAB_DIRECT);
23474   /* Those two should combine.  */
23475   if (piece_size == const1_rtx)
23476     {
23477       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
23478                                true, out_label);
23479       predict_jump (REG_BR_PROB_BASE * 10 / 100);
23480     }
23481   emit_move_insn (iter, const0_rtx);
23482
23483   emit_label (top_label);
23484
23485   tmp = convert_modes (Pmode, iter_mode, iter, true);
23486
23487   /* This assert could be relaxed - in this case we'll need to compute
23488      smallest power of two, containing in PIECE_SIZE_N and pass it to
23489      offset_address.  */
23490   gcc_assert ((piece_size_n & (piece_size_n - 1)) == 0);
23491   destmem = offset_address (destmem, tmp, piece_size_n);
23492   destmem = adjust_address (destmem, mode, 0);
23493
23494   if (!issetmem)
23495     {
23496       srcmem = offset_address (srcmem, copy_rtx (tmp), piece_size_n);
23497       srcmem = adjust_address (srcmem, mode, 0);
23498
23499       /* When unrolling for chips that reorder memory reads and writes,
23500          we can save registers by using single temporary.
23501          Also using 4 temporaries is overkill in 32bit mode.  */
23502       if (!TARGET_64BIT && 0)
23503         {
23504           for (i = 0; i < unroll; i++)
23505             {
23506               if (i)
23507                 {
23508                   destmem =
23509                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23510                   srcmem =
23511                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
23512                 }
23513               emit_move_insn (destmem, srcmem);
23514             }
23515         }
23516       else
23517         {
23518           rtx tmpreg[4];
23519           gcc_assert (unroll <= 4);
23520           for (i = 0; i < unroll; i++)
23521             {
23522               tmpreg[i] = gen_reg_rtx (mode);
23523               if (i)
23524                 {
23525                   srcmem =
23526                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
23527                 }
23528               emit_move_insn (tmpreg[i], srcmem);
23529             }
23530           for (i = 0; i < unroll; i++)
23531             {
23532               if (i)
23533                 {
23534                   destmem =
23535                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23536                 }
23537               emit_move_insn (destmem, tmpreg[i]);
23538             }
23539         }
23540     }
23541   else
23542     for (i = 0; i < unroll; i++)
23543       {
23544         if (i)
23545           destmem =
23546             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23547         emit_move_insn (destmem, value);
23548       }
23549
23550   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
23551                              true, OPTAB_LIB_WIDEN);
23552   if (tmp != iter)
23553     emit_move_insn (iter, tmp);
23554
23555   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
23556                            true, top_label);
23557   if (expected_size != -1)
23558     {
23559       expected_size /= GET_MODE_SIZE (mode) * unroll;
23560       if (expected_size == 0)
23561         predict_jump (0);
23562       else if (expected_size > REG_BR_PROB_BASE)
23563         predict_jump (REG_BR_PROB_BASE - 1);
23564       else
23565         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
23566     }
23567   else
23568     predict_jump (REG_BR_PROB_BASE * 80 / 100);
23569   iter = ix86_zero_extend_to_Pmode (iter);
23570   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
23571                              true, OPTAB_LIB_WIDEN);
23572   if (tmp != destptr)
23573     emit_move_insn (destptr, tmp);
23574   if (!issetmem)
23575     {
23576       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
23577                                  true, OPTAB_LIB_WIDEN);
23578       if (tmp != srcptr)
23579         emit_move_insn (srcptr, tmp);
23580     }
23581   emit_label (out_label);
23582 }
23583
23584 /* Output "rep; mov" or "rep; stos" instruction depending on ISSETMEM argument.
23585    When ISSETMEM is true, arguments SRCMEM and SRCPTR are ignored.
23586    When ISSETMEM is false, arguments VALUE and ORIG_VALUE are ignored.
23587    For setmem case, VALUE is a promoted to a wider size ORIG_VALUE.
23588    ORIG_VALUE is the original value passed to memset to fill the memory with.
23589    Other arguments have same meaning as for previous function.  */
23590
23591 static void
23592 expand_set_or_movmem_via_rep (rtx destmem, rtx srcmem,
23593                            rtx destptr, rtx srcptr, rtx value, rtx orig_value,
23594                            rtx count,
23595                            machine_mode mode, bool issetmem)
23596 {
23597   rtx destexp;
23598   rtx srcexp;
23599   rtx countreg;
23600   HOST_WIDE_INT rounded_count;
23601
23602   /* If possible, it is shorter to use rep movs.
23603      TODO: Maybe it is better to move this logic to decide_alg.  */
23604   if (mode == QImode && CONST_INT_P (count) && !(INTVAL (count) & 3)
23605       && (!issetmem || orig_value == const0_rtx))
23606     mode = SImode;
23607
23608   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
23609     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
23610
23611   countreg = ix86_zero_extend_to_Pmode (scale_counter (count,
23612                                                        GET_MODE_SIZE (mode)));
23613   if (mode != QImode)
23614     {
23615       destexp = gen_rtx_ASHIFT (Pmode, countreg,
23616                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
23617       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
23618     }
23619   else
23620     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
23621   if ((!issetmem || orig_value == const0_rtx) && CONST_INT_P (count))
23622     {
23623       rounded_count = (INTVAL (count)
23624                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
23625       destmem = shallow_copy_rtx (destmem);
23626       set_mem_size (destmem, rounded_count);
23627     }
23628   else if (MEM_SIZE_KNOWN_P (destmem))
23629     clear_mem_size (destmem);
23630
23631   if (issetmem)
23632     {
23633       value = force_reg (mode, gen_lowpart (mode, value));
23634       emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
23635     }
23636   else
23637     {
23638       if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
23639         srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
23640       if (mode != QImode)
23641         {
23642           srcexp = gen_rtx_ASHIFT (Pmode, countreg,
23643                                    GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
23644           srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
23645         }
23646       else
23647         srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
23648       if (CONST_INT_P (count))
23649         {
23650           rounded_count = (INTVAL (count)
23651                            & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
23652           srcmem = shallow_copy_rtx (srcmem);
23653           set_mem_size (srcmem, rounded_count);
23654         }
23655       else
23656         {
23657           if (MEM_SIZE_KNOWN_P (srcmem))
23658             clear_mem_size (srcmem);
23659         }
23660       emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
23661                               destexp, srcexp));
23662     }
23663 }
23664
23665 /* This function emits moves to copy SIZE_TO_MOVE bytes from SRCMEM to
23666    DESTMEM.
23667    SRC is passed by pointer to be updated on return.
23668    Return value is updated DST.  */
23669 static rtx
23670 emit_memmov (rtx destmem, rtx *srcmem, rtx destptr, rtx srcptr,
23671              HOST_WIDE_INT size_to_move)
23672 {
23673   rtx dst = destmem, src = *srcmem, adjust, tempreg;
23674   enum insn_code code;
23675   machine_mode move_mode;
23676   int piece_size, i;
23677
23678   /* Find the widest mode in which we could perform moves.
23679      Start with the biggest power of 2 less than SIZE_TO_MOVE and half
23680      it until move of such size is supported.  */
23681   piece_size = 1 << floor_log2 (size_to_move);
23682   move_mode = mode_for_size (piece_size * BITS_PER_UNIT, MODE_INT, 0);
23683   code = optab_handler (mov_optab, move_mode);
23684   while (code == CODE_FOR_nothing && piece_size > 1)
23685     {
23686       piece_size >>= 1;
23687       move_mode = mode_for_size (piece_size * BITS_PER_UNIT, MODE_INT, 0);
23688       code = optab_handler (mov_optab, move_mode);
23689     }
23690
23691   /* Find the corresponding vector mode with the same size as MOVE_MODE.
23692      MOVE_MODE is an integer mode at the moment (SI, DI, TI, etc.).  */
23693   if (GET_MODE_SIZE (move_mode) > GET_MODE_SIZE (word_mode))
23694     {
23695       int nunits = GET_MODE_SIZE (move_mode) / GET_MODE_SIZE (word_mode);
23696       move_mode = mode_for_vector (word_mode, nunits);
23697       code = optab_handler (mov_optab, move_mode);
23698       if (code == CODE_FOR_nothing)
23699         {
23700           move_mode = word_mode;
23701           piece_size = GET_MODE_SIZE (move_mode);
23702           code = optab_handler (mov_optab, move_mode);
23703         }
23704     }
23705   gcc_assert (code != CODE_FOR_nothing);
23706
23707   dst = adjust_automodify_address_nv (dst, move_mode, destptr, 0);
23708   src = adjust_automodify_address_nv (src, move_mode, srcptr, 0);
23709
23710   /* Emit moves.  We'll need SIZE_TO_MOVE/PIECE_SIZES moves.  */
23711   gcc_assert (size_to_move % piece_size == 0);
23712   adjust = GEN_INT (piece_size);
23713   for (i = 0; i < size_to_move; i += piece_size)
23714     {
23715       /* We move from memory to memory, so we'll need to do it via
23716          a temporary register.  */
23717       tempreg = gen_reg_rtx (move_mode);
23718       emit_insn (GEN_FCN (code) (tempreg, src));
23719       emit_insn (GEN_FCN (code) (dst, tempreg));
23720
23721       emit_move_insn (destptr,
23722                       gen_rtx_PLUS (Pmode, copy_rtx (destptr), adjust));
23723       emit_move_insn (srcptr,
23724                       gen_rtx_PLUS (Pmode, copy_rtx (srcptr), adjust));
23725
23726       dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23727                                           piece_size);
23728       src = adjust_automodify_address_nv (src, move_mode, srcptr,
23729                                           piece_size);
23730     }
23731
23732   /* Update DST and SRC rtx.  */
23733   *srcmem = src;
23734   return dst;
23735 }
23736
23737 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
23738 static void
23739 expand_movmem_epilogue (rtx destmem, rtx srcmem,
23740                         rtx destptr, rtx srcptr, rtx count, int max_size)
23741 {
23742   rtx src, dest;
23743   if (CONST_INT_P (count))
23744     {
23745       HOST_WIDE_INT countval = INTVAL (count);
23746       HOST_WIDE_INT epilogue_size = countval % max_size;
23747       int i;
23748
23749       /* For now MAX_SIZE should be a power of 2.  This assert could be
23750          relaxed, but it'll require a bit more complicated epilogue
23751          expanding.  */
23752       gcc_assert ((max_size & (max_size - 1)) == 0);
23753       for (i = max_size; i >= 1; i >>= 1)
23754         {
23755           if (epilogue_size & i)
23756             destmem = emit_memmov (destmem, &srcmem, destptr, srcptr, i);
23757         }
23758       return;
23759     }
23760   if (max_size > 8)
23761     {
23762       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
23763                                     count, 1, OPTAB_DIRECT);
23764       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
23765                                      count, QImode, 1, 4, false);
23766       return;
23767     }
23768
23769   /* When there are stringops, we can cheaply increase dest and src pointers.
23770      Otherwise we save code size by maintaining offset (zero is readily
23771      available from preceding rep operation) and using x86 addressing modes.
23772    */
23773   if (TARGET_SINGLE_STRINGOP)
23774     {
23775       if (max_size > 4)
23776         {
23777           rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23778           src = change_address (srcmem, SImode, srcptr);
23779           dest = change_address (destmem, SImode, destptr);
23780           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23781           emit_label (label);
23782           LABEL_NUSES (label) = 1;
23783         }
23784       if (max_size > 2)
23785         {
23786           rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23787           src = change_address (srcmem, HImode, srcptr);
23788           dest = change_address (destmem, HImode, destptr);
23789           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23790           emit_label (label);
23791           LABEL_NUSES (label) = 1;
23792         }
23793       if (max_size > 1)
23794         {
23795           rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23796           src = change_address (srcmem, QImode, srcptr);
23797           dest = change_address (destmem, QImode, destptr);
23798           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23799           emit_label (label);
23800           LABEL_NUSES (label) = 1;
23801         }
23802     }
23803   else
23804     {
23805       rtx offset = force_reg (Pmode, const0_rtx);
23806       rtx tmp;
23807
23808       if (max_size > 4)
23809         {
23810           rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23811           src = change_address (srcmem, SImode, srcptr);
23812           dest = change_address (destmem, SImode, destptr);
23813           emit_move_insn (dest, src);
23814           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
23815                                      true, OPTAB_LIB_WIDEN);
23816           if (tmp != offset)
23817             emit_move_insn (offset, tmp);
23818           emit_label (label);
23819           LABEL_NUSES (label) = 1;
23820         }
23821       if (max_size > 2)
23822         {
23823           rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23824           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
23825           src = change_address (srcmem, HImode, tmp);
23826           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
23827           dest = change_address (destmem, HImode, tmp);
23828           emit_move_insn (dest, src);
23829           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
23830                                      true, OPTAB_LIB_WIDEN);
23831           if (tmp != offset)
23832             emit_move_insn (offset, tmp);
23833           emit_label (label);
23834           LABEL_NUSES (label) = 1;
23835         }
23836       if (max_size > 1)
23837         {
23838           rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23839           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
23840           src = change_address (srcmem, QImode, tmp);
23841           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
23842           dest = change_address (destmem, QImode, tmp);
23843           emit_move_insn (dest, src);
23844           emit_label (label);
23845           LABEL_NUSES (label) = 1;
23846         }
23847     }
23848 }
23849
23850 /* This function emits moves to fill SIZE_TO_MOVE bytes starting from DESTMEM
23851    with value PROMOTED_VAL.
23852    SRC is passed by pointer to be updated on return.
23853    Return value is updated DST.  */
23854 static rtx
23855 emit_memset (rtx destmem, rtx destptr, rtx promoted_val,
23856              HOST_WIDE_INT size_to_move)
23857 {
23858   rtx dst = destmem, adjust;
23859   enum insn_code code;
23860   machine_mode move_mode;
23861   int piece_size, i;
23862
23863   /* Find the widest mode in which we could perform moves.
23864      Start with the biggest power of 2 less than SIZE_TO_MOVE and half
23865      it until move of such size is supported.  */
23866   move_mode = GET_MODE (promoted_val);
23867   if (move_mode == VOIDmode)
23868     move_mode = QImode;
23869   if (size_to_move < GET_MODE_SIZE (move_mode))
23870     {
23871       move_mode = mode_for_size (size_to_move * BITS_PER_UNIT, MODE_INT, 0);
23872       promoted_val = gen_lowpart (move_mode, promoted_val);
23873     }
23874   piece_size = GET_MODE_SIZE (move_mode);
23875   code = optab_handler (mov_optab, move_mode);
23876   gcc_assert (code != CODE_FOR_nothing && promoted_val != NULL_RTX);
23877
23878   dst = adjust_automodify_address_nv (dst, move_mode, destptr, 0);
23879
23880   /* Emit moves.  We'll need SIZE_TO_MOVE/PIECE_SIZES moves.  */
23881   gcc_assert (size_to_move % piece_size == 0);
23882   adjust = GEN_INT (piece_size);
23883   for (i = 0; i < size_to_move; i += piece_size)
23884     {
23885       if (piece_size <= GET_MODE_SIZE (word_mode))
23886         {
23887           emit_insn (gen_strset (destptr, dst, promoted_val));
23888           dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23889                                               piece_size);
23890           continue;
23891         }
23892
23893       emit_insn (GEN_FCN (code) (dst, promoted_val));
23894
23895       emit_move_insn (destptr,
23896                       gen_rtx_PLUS (Pmode, copy_rtx (destptr), adjust));
23897
23898       dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23899                                           piece_size);
23900     }
23901
23902   /* Update DST rtx.  */
23903   return dst;
23904 }
23905 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
23906 static void
23907 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
23908                                  rtx count, int max_size)
23909 {
23910   count =
23911     expand_simple_binop (counter_mode (count), AND, count,
23912                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
23913   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
23914                                  gen_lowpart (QImode, value), count, QImode,
23915                                  1, max_size / 2, true);
23916 }
23917
23918 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
23919 static void
23920 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx vec_value,
23921                         rtx count, int max_size)
23922 {
23923   rtx dest;
23924
23925   if (CONST_INT_P (count))
23926     {
23927       HOST_WIDE_INT countval = INTVAL (count);
23928       HOST_WIDE_INT epilogue_size = countval % max_size;
23929       int i;
23930
23931       /* For now MAX_SIZE should be a power of 2.  This assert could be
23932          relaxed, but it'll require a bit more complicated epilogue
23933          expanding.  */
23934       gcc_assert ((max_size & (max_size - 1)) == 0);
23935       for (i = max_size; i >= 1; i >>= 1)
23936         {
23937           if (epilogue_size & i)
23938             {
23939               if (vec_value && i > GET_MODE_SIZE (GET_MODE (value)))
23940                 destmem = emit_memset (destmem, destptr, vec_value, i);
23941               else
23942                 destmem = emit_memset (destmem, destptr, value, i);
23943             }
23944         }
23945       return;
23946     }
23947   if (max_size > 32)
23948     {
23949       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
23950       return;
23951     }
23952   if (max_size > 16)
23953     {
23954       rtx_code_label *label = ix86_expand_aligntest (count, 16, true);
23955       if (TARGET_64BIT)
23956         {
23957           dest = change_address (destmem, DImode, destptr);
23958           emit_insn (gen_strset (destptr, dest, value));
23959           dest = adjust_automodify_address_nv (dest, DImode, destptr, 8);
23960           emit_insn (gen_strset (destptr, dest, value));
23961         }
23962       else
23963         {
23964           dest = change_address (destmem, SImode, destptr);
23965           emit_insn (gen_strset (destptr, dest, value));
23966           dest = adjust_automodify_address_nv (dest, SImode, destptr, 4);
23967           emit_insn (gen_strset (destptr, dest, value));
23968           dest = adjust_automodify_address_nv (dest, SImode, destptr, 8);
23969           emit_insn (gen_strset (destptr, dest, value));
23970           dest = adjust_automodify_address_nv (dest, SImode, destptr, 12);
23971           emit_insn (gen_strset (destptr, dest, value));
23972         }
23973       emit_label (label);
23974       LABEL_NUSES (label) = 1;
23975     }
23976   if (max_size > 8)
23977     {
23978       rtx_code_label *label = ix86_expand_aligntest (count, 8, true);
23979       if (TARGET_64BIT)
23980         {
23981           dest = change_address (destmem, DImode, destptr);
23982           emit_insn (gen_strset (destptr, dest, value));
23983         }
23984       else
23985         {
23986           dest = change_address (destmem, SImode, destptr);
23987           emit_insn (gen_strset (destptr, dest, value));
23988           dest = adjust_automodify_address_nv (dest, SImode, destptr, 4);
23989           emit_insn (gen_strset (destptr, dest, value));
23990         }
23991       emit_label (label);
23992       LABEL_NUSES (label) = 1;
23993     }
23994   if (max_size > 4)
23995     {
23996       rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23997       dest = change_address (destmem, SImode, destptr);
23998       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
23999       emit_label (label);
24000       LABEL_NUSES (label) = 1;
24001     }
24002   if (max_size > 2)
24003     {
24004       rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
24005       dest = change_address (destmem, HImode, destptr);
24006       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
24007       emit_label (label);
24008       LABEL_NUSES (label) = 1;
24009     }
24010   if (max_size > 1)
24011     {
24012       rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
24013       dest = change_address (destmem, QImode, destptr);
24014       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
24015       emit_label (label);
24016       LABEL_NUSES (label) = 1;
24017     }
24018 }
24019
24020 /* Depending on ISSETMEM, copy enough from SRCMEM to DESTMEM or set enough to
24021    DESTMEM to align it to DESIRED_ALIGNMENT.  Original alignment is ALIGN.
24022    Depending on ISSETMEM, either arguments SRCMEM/SRCPTR or VALUE/VEC_VALUE are
24023    ignored.
24024    Return value is updated DESTMEM.  */
24025 static rtx
24026 expand_set_or_movmem_prologue (rtx destmem, rtx srcmem,
24027                                   rtx destptr, rtx srcptr, rtx value,
24028                                   rtx vec_value, rtx count, int align,
24029                                   int desired_alignment, bool issetmem)
24030 {
24031   int i;
24032   for (i = 1; i < desired_alignment; i <<= 1)
24033     {
24034       if (align <= i)
24035         {
24036           rtx_code_label *label = ix86_expand_aligntest (destptr, i, false);
24037           if (issetmem)
24038             {
24039               if (vec_value && i > GET_MODE_SIZE (GET_MODE (value)))
24040                 destmem = emit_memset (destmem, destptr, vec_value, i);
24041               else
24042                 destmem = emit_memset (destmem, destptr, value, i);
24043             }
24044           else
24045             destmem = emit_memmov (destmem, &srcmem, destptr, srcptr, i);
24046           ix86_adjust_counter (count, i);
24047           emit_label (label);
24048           LABEL_NUSES (label) = 1;
24049           set_mem_align (destmem, i * 2 * BITS_PER_UNIT);
24050         }
24051     }
24052   return destmem;
24053 }
24054
24055 /* Test if COUNT&SIZE is nonzero and if so, expand movme
24056    or setmem sequence that is valid for SIZE..2*SIZE-1 bytes
24057    and jump to DONE_LABEL.  */
24058 static void
24059 expand_small_movmem_or_setmem (rtx destmem, rtx srcmem,
24060                                rtx destptr, rtx srcptr,
24061                                rtx value, rtx vec_value,
24062                                rtx count, int size,
24063                                rtx done_label, bool issetmem)
24064 {
24065   rtx_code_label *label = ix86_expand_aligntest (count, size, false);
24066   machine_mode mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 1);
24067   rtx modesize;
24068   int n;
24069
24070   /* If we do not have vector value to copy, we must reduce size.  */
24071   if (issetmem)
24072     {
24073       if (!vec_value)
24074         {
24075           if (GET_MODE (value) == VOIDmode && size > 8)
24076             mode = Pmode;
24077           else if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (value)))
24078             mode = GET_MODE (value);
24079         }
24080       else
24081         mode = GET_MODE (vec_value), value = vec_value;
24082     }
24083   else
24084     {
24085       /* Choose appropriate vector mode.  */
24086       if (size >= 32)
24087         mode = TARGET_AVX ? V32QImode : TARGET_SSE ? V16QImode : DImode;
24088       else if (size >= 16)
24089         mode = TARGET_SSE ? V16QImode : DImode;
24090       srcmem = change_address (srcmem, mode, srcptr);
24091     }
24092   destmem = change_address (destmem, mode, destptr);
24093   modesize = GEN_INT (GET_MODE_SIZE (mode));
24094   gcc_assert (GET_MODE_SIZE (mode) <= size);
24095   for (n = 0; n * GET_MODE_SIZE (mode) < size; n++)
24096     {
24097       if (issetmem)
24098         emit_move_insn (destmem, gen_lowpart (mode, value));
24099       else
24100         {
24101           emit_move_insn (destmem, srcmem);
24102           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24103         }
24104       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24105     }
24106
24107   destmem = offset_address (destmem, count, 1);
24108   destmem = offset_address (destmem, GEN_INT (-2 * size),
24109                             GET_MODE_SIZE (mode));
24110   if (!issetmem)
24111     {
24112       srcmem = offset_address (srcmem, count, 1);
24113       srcmem = offset_address (srcmem, GEN_INT (-2 * size),
24114                                GET_MODE_SIZE (mode));
24115     }
24116   for (n = 0; n * GET_MODE_SIZE (mode) < size; n++)
24117     {
24118       if (issetmem)
24119         emit_move_insn (destmem, gen_lowpart (mode, value));
24120       else
24121         {
24122           emit_move_insn (destmem, srcmem);
24123           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24124         }
24125       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24126     }
24127   emit_jump_insn (gen_jump (done_label));
24128   emit_barrier ();
24129
24130   emit_label (label);
24131   LABEL_NUSES (label) = 1;
24132 }
24133
24134 /* Handle small memcpy (up to SIZE that is supposed to be small power of 2.
24135    and get ready for the main memcpy loop by copying iniital DESIRED_ALIGN-ALIGN
24136    bytes and last SIZE bytes adjusitng DESTPTR/SRCPTR/COUNT in a way we can
24137    proceed with an loop copying SIZE bytes at once. Do moves in MODE.
24138    DONE_LABEL is a label after the whole copying sequence. The label is created
24139    on demand if *DONE_LABEL is NULL.
24140    MIN_SIZE is minimal size of block copied.  This value gets adjusted for new
24141    bounds after the initial copies. 
24142
24143    DESTMEM/SRCMEM are memory expressions pointing to the copies block,
24144    DESTPTR/SRCPTR are pointers to the block. DYNAMIC_CHECK indicate whether
24145    we will dispatch to a library call for large blocks.
24146
24147    In pseudocode we do:
24148
24149    if (COUNT < SIZE)
24150      {
24151        Assume that SIZE is 4. Bigger sizes are handled analogously
24152        if (COUNT & 4)
24153          {
24154             copy 4 bytes from SRCPTR to DESTPTR
24155             copy 4 bytes from SRCPTR + COUNT - 4 to DESTPTR + COUNT - 4
24156             goto done_label
24157          }
24158        if (!COUNT)
24159          goto done_label;
24160        copy 1 byte from SRCPTR to DESTPTR
24161        if (COUNT & 2)
24162          {
24163             copy 2 bytes from SRCPTR to DESTPTR
24164             copy 2 bytes from SRCPTR + COUNT - 2 to DESTPTR + COUNT - 2
24165          }
24166      }
24167    else
24168      {
24169        copy at least DESIRED_ALIGN-ALIGN bytes from SRCPTR to DESTPTR
24170        copy SIZE bytes from SRCPTR + COUNT - SIZE to DESTPTR + COUNT -SIZE
24171
24172        OLD_DESPTR = DESTPTR;
24173        Align DESTPTR up to DESIRED_ALIGN
24174        SRCPTR += DESTPTR - OLD_DESTPTR
24175        COUNT -= DEST_PTR - OLD_DESTPTR
24176        if (DYNAMIC_CHECK)
24177          Round COUNT down to multiple of SIZE
24178        << optional caller supplied zero size guard is here >>
24179        << optional caller suppplied dynamic check is here >>
24180        << caller supplied main copy loop is here >>
24181      }
24182    done_label:
24183   */
24184 static void
24185 expand_set_or_movmem_prologue_epilogue_by_misaligned_moves (rtx destmem, rtx srcmem,
24186                                                             rtx *destptr, rtx *srcptr,
24187                                                             machine_mode mode,
24188                                                             rtx value, rtx vec_value,
24189                                                             rtx *count,
24190                                                             rtx_code_label **done_label,
24191                                                             int size,
24192                                                             int desired_align,
24193                                                             int align,
24194                                                             unsigned HOST_WIDE_INT *min_size,
24195                                                             bool dynamic_check,
24196                                                             bool issetmem)
24197 {
24198   rtx_code_label *loop_label = NULL, *label;
24199   int n;
24200   rtx modesize;
24201   int prolog_size = 0;
24202   rtx mode_value;
24203
24204   /* Chose proper value to copy.  */
24205   if (issetmem && VECTOR_MODE_P (mode))
24206     mode_value = vec_value;
24207   else
24208     mode_value = value;
24209   gcc_assert (GET_MODE_SIZE (mode) <= size);
24210
24211   /* See if block is big or small, handle small blocks.  */
24212   if (!CONST_INT_P (*count) && *min_size < (unsigned HOST_WIDE_INT)size)
24213     {
24214       int size2 = size;
24215       loop_label = gen_label_rtx ();
24216
24217       if (!*done_label)
24218         *done_label = gen_label_rtx ();
24219
24220       emit_cmp_and_jump_insns (*count, GEN_INT (size2), GE, 0, GET_MODE (*count),
24221                                1, loop_label);
24222       size2 >>= 1;
24223
24224       /* Handle sizes > 3.  */
24225       for (;size2 > 2; size2 >>= 1)
24226         expand_small_movmem_or_setmem (destmem, srcmem,
24227                                        *destptr, *srcptr,
24228                                        value, vec_value,
24229                                        *count,
24230                                        size2, *done_label, issetmem);
24231       /* Nothing to copy?  Jump to DONE_LABEL if so */
24232       emit_cmp_and_jump_insns (*count, const0_rtx, EQ, 0, GET_MODE (*count),
24233                                1, *done_label);
24234
24235       /* Do a byte copy.  */
24236       destmem = change_address (destmem, QImode, *destptr);
24237       if (issetmem)
24238         emit_move_insn (destmem, gen_lowpart (QImode, value));
24239       else
24240         {
24241           srcmem = change_address (srcmem, QImode, *srcptr);
24242           emit_move_insn (destmem, srcmem);
24243         }
24244
24245       /* Handle sizes 2 and 3.  */
24246       label = ix86_expand_aligntest (*count, 2, false);
24247       destmem = change_address (destmem, HImode, *destptr);
24248       destmem = offset_address (destmem, *count, 1);
24249       destmem = offset_address (destmem, GEN_INT (-2), 2);
24250       if (issetmem)
24251         emit_move_insn (destmem, gen_lowpart (HImode, value));
24252       else
24253         {
24254           srcmem = change_address (srcmem, HImode, *srcptr);
24255           srcmem = offset_address (srcmem, *count, 1);
24256           srcmem = offset_address (srcmem, GEN_INT (-2), 2);
24257           emit_move_insn (destmem, srcmem);
24258         }
24259
24260       emit_label (label);
24261       LABEL_NUSES (label) = 1;
24262       emit_jump_insn (gen_jump (*done_label));
24263       emit_barrier ();
24264     }
24265   else
24266     gcc_assert (*min_size >= (unsigned HOST_WIDE_INT)size
24267                 || UINTVAL (*count) >= (unsigned HOST_WIDE_INT)size);
24268
24269   /* Start memcpy for COUNT >= SIZE.  */
24270   if (loop_label)
24271     {
24272        emit_label (loop_label);
24273        LABEL_NUSES (loop_label) = 1;
24274     }
24275
24276   /* Copy first desired_align bytes.  */
24277   if (!issetmem)
24278     srcmem = change_address (srcmem, mode, *srcptr);
24279   destmem = change_address (destmem, mode, *destptr);
24280   modesize = GEN_INT (GET_MODE_SIZE (mode));
24281   for (n = 0; prolog_size < desired_align - align; n++)
24282     {
24283       if (issetmem)
24284         emit_move_insn (destmem, mode_value);
24285       else
24286         {
24287           emit_move_insn (destmem, srcmem);
24288           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24289         }
24290       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24291       prolog_size += GET_MODE_SIZE (mode);
24292     }
24293
24294
24295   /* Copy last SIZE bytes.  */
24296   destmem = offset_address (destmem, *count, 1);
24297   destmem = offset_address (destmem,
24298                             GEN_INT (-size - prolog_size),
24299                             1);
24300   if (issetmem)
24301     emit_move_insn (destmem, mode_value);
24302   else
24303     {
24304       srcmem = offset_address (srcmem, *count, 1);
24305       srcmem = offset_address (srcmem,
24306                                GEN_INT (-size - prolog_size),
24307                                1);
24308       emit_move_insn (destmem, srcmem);
24309     }
24310   for (n = 1; n * GET_MODE_SIZE (mode) < size; n++)
24311     {
24312       destmem = offset_address (destmem, modesize, 1);
24313       if (issetmem)
24314         emit_move_insn (destmem, mode_value);
24315       else
24316         {
24317           srcmem = offset_address (srcmem, modesize, 1);
24318           emit_move_insn (destmem, srcmem);
24319         }
24320     }
24321
24322   /* Align destination.  */
24323   if (desired_align > 1 && desired_align > align)
24324     {
24325       rtx saveddest = *destptr;
24326
24327       gcc_assert (desired_align <= size);
24328       /* Align destptr up, place it to new register.  */
24329       *destptr = expand_simple_binop (GET_MODE (*destptr), PLUS, *destptr,
24330                                       GEN_INT (prolog_size),
24331                                       NULL_RTX, 1, OPTAB_DIRECT);
24332       if (REG_P (*destptr) && REG_P (saveddest) && REG_POINTER (saveddest))
24333         REG_POINTER (*destptr) = 1;
24334       *destptr = expand_simple_binop (GET_MODE (*destptr), AND, *destptr,
24335                                       GEN_INT (-desired_align),
24336                                       *destptr, 1, OPTAB_DIRECT);
24337       /* See how many bytes we skipped.  */
24338       saveddest = expand_simple_binop (GET_MODE (*destptr), MINUS, saveddest,
24339                                        *destptr,
24340                                        saveddest, 1, OPTAB_DIRECT);
24341       /* Adjust srcptr and count.  */
24342       if (!issetmem)
24343         *srcptr = expand_simple_binop (GET_MODE (*srcptr), MINUS, *srcptr,
24344                                        saveddest, *srcptr, 1, OPTAB_DIRECT);
24345       *count = expand_simple_binop (GET_MODE (*count), PLUS, *count,
24346                                     saveddest, *count, 1, OPTAB_DIRECT);
24347       /* We copied at most size + prolog_size.  */
24348       if (*min_size > (unsigned HOST_WIDE_INT)(size + prolog_size))
24349         *min_size = (*min_size - size) & ~(unsigned HOST_WIDE_INT)(size - 1);
24350       else
24351         *min_size = 0;
24352
24353       /* Our loops always round down the bock size, but for dispatch to library
24354          we need precise value.  */
24355       if (dynamic_check)
24356         *count = expand_simple_binop (GET_MODE (*count), AND, *count,
24357                                       GEN_INT (-size), *count, 1, OPTAB_DIRECT);
24358     }
24359   else
24360     {
24361       gcc_assert (prolog_size == 0);
24362       /* Decrease count, so we won't end up copying last word twice.  */
24363       if (!CONST_INT_P (*count))
24364         *count = expand_simple_binop (GET_MODE (*count), PLUS, *count,
24365                                       constm1_rtx, *count, 1, OPTAB_DIRECT);
24366       else
24367         *count = GEN_INT ((UINTVAL (*count) - 1) & ~(unsigned HOST_WIDE_INT)(size - 1));
24368       if (*min_size)
24369         *min_size = (*min_size - 1) & ~(unsigned HOST_WIDE_INT)(size - 1);
24370     }
24371 }
24372
24373
24374 /* This function is like the previous one, except here we know how many bytes
24375    need to be copied.  That allows us to update alignment not only of DST, which
24376    is returned, but also of SRC, which is passed as a pointer for that
24377    reason.  */
24378 static rtx
24379 expand_set_or_movmem_constant_prologue (rtx dst, rtx *srcp, rtx destreg,
24380                                            rtx srcreg, rtx value, rtx vec_value,
24381                                            int desired_align, int align_bytes,
24382                                            bool issetmem)
24383 {
24384   rtx src = NULL;
24385   rtx orig_dst = dst;
24386   rtx orig_src = NULL;
24387   int piece_size = 1;
24388   int copied_bytes = 0;
24389
24390   if (!issetmem)
24391     {
24392       gcc_assert (srcp != NULL);
24393       src = *srcp;
24394       orig_src = src;
24395     }
24396
24397   for (piece_size = 1;
24398        piece_size <= desired_align && copied_bytes < align_bytes;
24399        piece_size <<= 1)
24400     {
24401       if (align_bytes & piece_size)
24402         {
24403           if (issetmem)
24404             {
24405               if (vec_value && piece_size > GET_MODE_SIZE (GET_MODE (value)))
24406                 dst = emit_memset (dst, destreg, vec_value, piece_size);
24407               else
24408                 dst = emit_memset (dst, destreg, value, piece_size);
24409             }
24410           else
24411             dst = emit_memmov (dst, &src, destreg, srcreg, piece_size);
24412           copied_bytes += piece_size;
24413         }
24414     }
24415   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
24416     set_mem_align (dst, desired_align * BITS_PER_UNIT);
24417   if (MEM_SIZE_KNOWN_P (orig_dst))
24418     set_mem_size (dst, MEM_SIZE (orig_dst) - align_bytes);
24419
24420   if (!issetmem)
24421     {
24422       int src_align_bytes = get_mem_align_offset (src, desired_align
24423                                                        * BITS_PER_UNIT);
24424       if (src_align_bytes >= 0)
24425         src_align_bytes = desired_align - src_align_bytes;
24426       if (src_align_bytes >= 0)
24427         {
24428           unsigned int src_align;
24429           for (src_align = desired_align; src_align >= 2; src_align >>= 1)
24430             {
24431               if ((src_align_bytes & (src_align - 1))
24432                    == (align_bytes & (src_align - 1)))
24433                 break;
24434             }
24435           if (src_align > (unsigned int) desired_align)
24436             src_align = desired_align;
24437           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
24438             set_mem_align (src, src_align * BITS_PER_UNIT);
24439         }
24440       if (MEM_SIZE_KNOWN_P (orig_src))
24441         set_mem_size (src, MEM_SIZE (orig_src) - align_bytes);
24442       *srcp = src;
24443     }
24444
24445   return dst;
24446 }
24447
24448 /* Return true if ALG can be used in current context.  
24449    Assume we expand memset if MEMSET is true.  */
24450 static bool
24451 alg_usable_p (enum stringop_alg alg, bool memset)
24452 {
24453   if (alg == no_stringop)
24454     return false;
24455   if (alg == vector_loop)
24456     return TARGET_SSE || TARGET_AVX;
24457   /* Algorithms using the rep prefix want at least edi and ecx;
24458      additionally, memset wants eax and memcpy wants esi.  Don't
24459      consider such algorithms if the user has appropriated those
24460      registers for their own purposes.  */
24461   if (alg == rep_prefix_1_byte
24462       || alg == rep_prefix_4_byte
24463       || alg == rep_prefix_8_byte)
24464     return !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
24465              || (memset ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
24466   return true;
24467 }
24468
24469 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
24470 static enum stringop_alg
24471 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size,
24472             unsigned HOST_WIDE_INT min_size, unsigned HOST_WIDE_INT max_size,
24473             bool memset, bool zero_memset, int *dynamic_check, bool *noalign)
24474 {
24475   const struct stringop_algs * algs;
24476   bool optimize_for_speed;
24477   int max = 0;
24478   const struct processor_costs *cost;
24479   int i;
24480   bool any_alg_usable_p = false;
24481
24482   *noalign = false;
24483   *dynamic_check = -1;
24484
24485   /* Even if the string operation call is cold, we still might spend a lot
24486      of time processing large blocks.  */
24487   if (optimize_function_for_size_p (cfun)
24488       || (optimize_insn_for_size_p ()
24489           && (max_size < 256
24490               || (expected_size != -1 && expected_size < 256))))
24491     optimize_for_speed = false;
24492   else
24493     optimize_for_speed = true;
24494
24495   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
24496   if (memset)
24497     algs = &cost->memset[TARGET_64BIT != 0];
24498   else
24499     algs = &cost->memcpy[TARGET_64BIT != 0];
24500
24501   /* See maximal size for user defined algorithm.  */
24502   for (i = 0; i < MAX_STRINGOP_ALGS; i++)
24503     {
24504       enum stringop_alg candidate = algs->size[i].alg;
24505       bool usable = alg_usable_p (candidate, memset);
24506       any_alg_usable_p |= usable;
24507
24508       if (candidate != libcall && candidate && usable)
24509           max = algs->size[i].max;
24510     }
24511
24512   /* If expected size is not known but max size is small enough
24513      so inline version is a win, set expected size into
24514      the range.  */
24515   if (((max > 1 && (unsigned HOST_WIDE_INT) max >= max_size) || max == -1)
24516       && expected_size == -1)
24517     expected_size = min_size / 2 + max_size / 2;
24518
24519   /* If user specified the algorithm, honnor it if possible.  */
24520   if (ix86_stringop_alg != no_stringop
24521       && alg_usable_p (ix86_stringop_alg, memset))
24522     return ix86_stringop_alg;
24523   /* rep; movq or rep; movl is the smallest variant.  */
24524   else if (!optimize_for_speed)
24525     {
24526       *noalign = true;
24527       if (!count || (count & 3) || (memset && !zero_memset))
24528         return alg_usable_p (rep_prefix_1_byte, memset)
24529                ? rep_prefix_1_byte : loop_1_byte;
24530       else
24531         return alg_usable_p (rep_prefix_4_byte, memset)
24532                ? rep_prefix_4_byte : loop;
24533     }
24534   /* Very tiny blocks are best handled via the loop, REP is expensive to
24535      setup.  */
24536   else if (expected_size != -1 && expected_size < 4)
24537     return loop_1_byte;
24538   else if (expected_size != -1)
24539     {
24540       enum stringop_alg alg = libcall;
24541       bool alg_noalign = false;
24542       for (i = 0; i < MAX_STRINGOP_ALGS; i++)
24543         {
24544           /* We get here if the algorithms that were not libcall-based
24545              were rep-prefix based and we are unable to use rep prefixes
24546              based on global register usage.  Break out of the loop and
24547              use the heuristic below.  */
24548           if (algs->size[i].max == 0)
24549             break;
24550           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
24551             {
24552               enum stringop_alg candidate = algs->size[i].alg;
24553
24554               if (candidate != libcall && alg_usable_p (candidate, memset))
24555                 {
24556                   alg = candidate;
24557                   alg_noalign = algs->size[i].noalign;
24558                 }
24559               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
24560                  last non-libcall inline algorithm.  */
24561               if (TARGET_INLINE_ALL_STRINGOPS)
24562                 {
24563                   /* When the current size is best to be copied by a libcall,
24564                      but we are still forced to inline, run the heuristic below
24565                      that will pick code for medium sized blocks.  */
24566                   if (alg != libcall)
24567                     {
24568                       *noalign = alg_noalign;
24569                       return alg;
24570                     }
24571                   else if (!any_alg_usable_p)
24572                     break;
24573                 }
24574               else if (alg_usable_p (candidate, memset))
24575                 {
24576                   *noalign = algs->size[i].noalign;
24577                   return candidate;
24578                 }
24579             }
24580         }
24581     }
24582   /* When asked to inline the call anyway, try to pick meaningful choice.
24583      We look for maximal size of block that is faster to copy by hand and
24584      take blocks of at most of that size guessing that average size will
24585      be roughly half of the block.
24586
24587      If this turns out to be bad, we might simply specify the preferred
24588      choice in ix86_costs.  */
24589   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24590       && (algs->unknown_size == libcall
24591           || !alg_usable_p (algs->unknown_size, memset)))
24592     {
24593       enum stringop_alg alg;
24594
24595       /* If there aren't any usable algorithms, then recursing on
24596          smaller sizes isn't going to find anything.  Just return the
24597          simple byte-at-a-time copy loop.  */
24598       if (!any_alg_usable_p)
24599         {
24600           /* Pick something reasonable.  */
24601           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24602             *dynamic_check = 128;
24603           return loop_1_byte;
24604         }
24605       if (max <= 0)
24606         max = 4096;
24607       alg = decide_alg (count, max / 2, min_size, max_size, memset,
24608                         zero_memset, dynamic_check, noalign);
24609       gcc_assert (*dynamic_check == -1);
24610       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24611         *dynamic_check = max;
24612       else
24613         gcc_assert (alg != libcall);
24614       return alg;
24615     }
24616   return (alg_usable_p (algs->unknown_size, memset)
24617           ? algs->unknown_size : libcall);
24618 }
24619
24620 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
24621    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
24622 static int
24623 decide_alignment (int align,
24624                   enum stringop_alg alg,
24625                   int expected_size,
24626                   machine_mode move_mode)
24627 {
24628   int desired_align = 0;
24629
24630   gcc_assert (alg != no_stringop);
24631
24632   if (alg == libcall)
24633     return 0;
24634   if (move_mode == VOIDmode)
24635     return 0;
24636
24637   desired_align = GET_MODE_SIZE (move_mode);
24638   /* PentiumPro has special logic triggering for 8 byte aligned blocks.
24639      copying whole cacheline at once.  */
24640   if (TARGET_PENTIUMPRO
24641       && (alg == rep_prefix_4_byte || alg == rep_prefix_1_byte))
24642     desired_align = 8;
24643
24644   if (optimize_size)
24645     desired_align = 1;
24646   if (desired_align < align)
24647     desired_align = align;
24648   if (expected_size != -1 && expected_size < 4)
24649     desired_align = align;
24650
24651   return desired_align;
24652 }
24653
24654
24655 /* Helper function for memcpy.  For QImode value 0xXY produce
24656    0xXYXYXYXY of wide specified by MODE.  This is essentially
24657    a * 0x10101010, but we can do slightly better than
24658    synth_mult by unwinding the sequence by hand on CPUs with
24659    slow multiply.  */
24660 static rtx
24661 promote_duplicated_reg (machine_mode mode, rtx val)
24662 {
24663   machine_mode valmode = GET_MODE (val);
24664   rtx tmp;
24665   int nops = mode == DImode ? 3 : 2;
24666
24667   gcc_assert (mode == SImode || mode == DImode || val == const0_rtx);
24668   if (val == const0_rtx)
24669     return copy_to_mode_reg (mode, CONST0_RTX (mode));
24670   if (CONST_INT_P (val))
24671     {
24672       HOST_WIDE_INT v = INTVAL (val) & 255;
24673
24674       v |= v << 8;
24675       v |= v << 16;
24676       if (mode == DImode)
24677         v |= (v << 16) << 16;
24678       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
24679     }
24680
24681   if (valmode == VOIDmode)
24682     valmode = QImode;
24683   if (valmode != QImode)
24684     val = gen_lowpart (QImode, val);
24685   if (mode == QImode)
24686     return val;
24687   if (!TARGET_PARTIAL_REG_STALL)
24688     nops--;
24689   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
24690       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
24691       <= (ix86_cost->shift_const + ix86_cost->add) * nops
24692           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
24693     {
24694       rtx reg = convert_modes (mode, QImode, val, true);
24695       tmp = promote_duplicated_reg (mode, const1_rtx);
24696       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
24697                                   OPTAB_DIRECT);
24698     }
24699   else
24700     {
24701       rtx reg = convert_modes (mode, QImode, val, true);
24702
24703       if (!TARGET_PARTIAL_REG_STALL)
24704         if (mode == SImode)
24705           emit_insn (gen_movsi_insv_1 (reg, reg));
24706         else
24707           emit_insn (gen_movdi_insv_1 (reg, reg));
24708       else
24709         {
24710           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
24711                                      NULL, 1, OPTAB_DIRECT);
24712           reg =
24713             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24714         }
24715       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
24716                                  NULL, 1, OPTAB_DIRECT);
24717       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24718       if (mode == SImode)
24719         return reg;
24720       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
24721                                  NULL, 1, OPTAB_DIRECT);
24722       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24723       return reg;
24724     }
24725 }
24726
24727 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
24728    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
24729    alignment from ALIGN to DESIRED_ALIGN.  */
24730 static rtx
24731 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align,
24732                                 int align)
24733 {
24734   rtx promoted_val;
24735
24736   if (TARGET_64BIT
24737       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
24738     promoted_val = promote_duplicated_reg (DImode, val);
24739   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
24740     promoted_val = promote_duplicated_reg (SImode, val);
24741   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
24742     promoted_val = promote_duplicated_reg (HImode, val);
24743   else
24744     promoted_val = val;
24745
24746   return promoted_val;
24747 }
24748
24749 /* Expand string move (memcpy) ot store (memset) operation.  Use i386 string
24750    operations when profitable.  The code depends upon architecture, block size
24751    and alignment, but always has one of the following overall structures:
24752
24753    Aligned move sequence:
24754
24755      1) Prologue guard: Conditional that jumps up to epilogues for small
24756         blocks that can be handled by epilogue alone.  This is faster
24757         but also needed for correctness, since prologue assume the block
24758         is larger than the desired alignment.
24759
24760         Optional dynamic check for size and libcall for large
24761         blocks is emitted here too, with -minline-stringops-dynamically.
24762
24763      2) Prologue: copy first few bytes in order to get destination
24764         aligned to DESIRED_ALIGN.  It is emitted only when ALIGN is less
24765         than DESIRED_ALIGN and up to DESIRED_ALIGN - ALIGN bytes can be
24766         copied.  We emit either a jump tree on power of two sized
24767         blocks, or a byte loop.
24768
24769      3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
24770         with specified algorithm.
24771
24772      4) Epilogue: code copying tail of the block that is too small to be
24773         handled by main body (or up to size guarded by prologue guard). 
24774
24775   Misaligned move sequence
24776
24777      1) missaligned move prologue/epilogue containing:
24778         a) Prologue handling small memory blocks and jumping to done_label
24779            (skipped if blocks are known to be large enough)
24780         b) Signle move copying first DESIRED_ALIGN-ALIGN bytes if alignment is
24781            needed by single possibly misaligned move
24782            (skipped if alignment is not needed)
24783         c) Copy of last SIZE_NEEDED bytes by possibly misaligned moves
24784
24785      2) Zero size guard dispatching to done_label, if needed
24786
24787      3) dispatch to library call, if needed,
24788
24789      3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
24790         with specified algorithm.  */
24791 bool
24792 ix86_expand_set_or_movmem (rtx dst, rtx src, rtx count_exp, rtx val_exp,
24793                            rtx align_exp, rtx expected_align_exp,
24794                            rtx expected_size_exp, rtx min_size_exp,
24795                            rtx max_size_exp, rtx probable_max_size_exp,
24796                            bool issetmem)
24797 {
24798   rtx destreg;
24799   rtx srcreg = NULL;
24800   rtx_code_label *label = NULL;
24801   rtx tmp;
24802   rtx_code_label *jump_around_label = NULL;
24803   HOST_WIDE_INT align = 1;
24804   unsigned HOST_WIDE_INT count = 0;
24805   HOST_WIDE_INT expected_size = -1;
24806   int size_needed = 0, epilogue_size_needed;
24807   int desired_align = 0, align_bytes = 0;
24808   enum stringop_alg alg;
24809   rtx promoted_val = NULL;
24810   rtx vec_promoted_val = NULL;
24811   bool force_loopy_epilogue = false;
24812   int dynamic_check;
24813   bool need_zero_guard = false;
24814   bool noalign;
24815   machine_mode move_mode = VOIDmode;
24816   int unroll_factor = 1;
24817   /* TODO: Once value ranges are available, fill in proper data.  */
24818   unsigned HOST_WIDE_INT min_size = 0;
24819   unsigned HOST_WIDE_INT max_size = -1;
24820   unsigned HOST_WIDE_INT probable_max_size = -1;
24821   bool misaligned_prologue_used = false;
24822
24823   if (CONST_INT_P (align_exp))
24824     align = INTVAL (align_exp);
24825   /* i386 can do misaligned access on reasonably increased cost.  */
24826   if (CONST_INT_P (expected_align_exp)
24827       && INTVAL (expected_align_exp) > align)
24828     align = INTVAL (expected_align_exp);
24829   /* ALIGN is the minimum of destination and source alignment, but we care here
24830      just about destination alignment.  */
24831   else if (!issetmem
24832            && MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
24833     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
24834
24835   if (CONST_INT_P (count_exp))
24836     {
24837       min_size = max_size = probable_max_size = count = expected_size
24838         = INTVAL (count_exp);
24839       /* When COUNT is 0, there is nothing to do.  */
24840       if (!count)
24841         return true;
24842     }
24843   else
24844     {
24845       if (min_size_exp)
24846         min_size = INTVAL (min_size_exp);
24847       if (max_size_exp)
24848         max_size = INTVAL (max_size_exp);
24849       if (probable_max_size_exp)
24850         probable_max_size = INTVAL (probable_max_size_exp);
24851       if (CONST_INT_P (expected_size_exp))
24852         expected_size = INTVAL (expected_size_exp);
24853      }
24854
24855   /* Make sure we don't need to care about overflow later on.  */
24856   if (count > (HOST_WIDE_INT_1U << 30))
24857     return false;
24858
24859   /* Step 0: Decide on preferred algorithm, desired alignment and
24860      size of chunks to be copied by main loop.  */
24861   alg = decide_alg (count, expected_size, min_size, probable_max_size,
24862                     issetmem,
24863                     issetmem && val_exp == const0_rtx,
24864                     &dynamic_check, &noalign);
24865   if (alg == libcall)
24866     return false;
24867   gcc_assert (alg != no_stringop);
24868
24869   /* For now vector-version of memset is generated only for memory zeroing, as
24870      creating of promoted vector value is very cheap in this case.  */
24871   if (issetmem && alg == vector_loop && val_exp != const0_rtx)
24872     alg = unrolled_loop;
24873
24874   if (!count)
24875     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
24876   destreg = ix86_copy_addr_to_reg (XEXP (dst, 0));
24877   if (!issetmem)
24878     srcreg = ix86_copy_addr_to_reg (XEXP (src, 0));
24879
24880   unroll_factor = 1;
24881   move_mode = word_mode;
24882   switch (alg)
24883     {
24884     case libcall:
24885     case no_stringop:
24886     case last_alg:
24887       gcc_unreachable ();
24888     case loop_1_byte:
24889       need_zero_guard = true;
24890       move_mode = QImode;
24891       break;
24892     case loop:
24893       need_zero_guard = true;
24894       break;
24895     case unrolled_loop:
24896       need_zero_guard = true;
24897       unroll_factor = (TARGET_64BIT ? 4 : 2);
24898       break;
24899     case vector_loop:
24900       need_zero_guard = true;
24901       unroll_factor = 4;
24902       /* Find the widest supported mode.  */
24903       move_mode = word_mode;
24904       while (optab_handler (mov_optab, GET_MODE_WIDER_MODE (move_mode))
24905              != CODE_FOR_nothing)
24906           move_mode = GET_MODE_WIDER_MODE (move_mode);
24907
24908       /* Find the corresponding vector mode with the same size as MOVE_MODE.
24909          MOVE_MODE is an integer mode at the moment (SI, DI, TI, etc.).  */
24910       if (GET_MODE_SIZE (move_mode) > GET_MODE_SIZE (word_mode))
24911         {
24912           int nunits = GET_MODE_SIZE (move_mode) / GET_MODE_SIZE (word_mode);
24913           move_mode = mode_for_vector (word_mode, nunits);
24914           if (optab_handler (mov_optab, move_mode) == CODE_FOR_nothing)
24915             move_mode = word_mode;
24916         }
24917       gcc_assert (optab_handler (mov_optab, move_mode) != CODE_FOR_nothing);
24918       break;
24919     case rep_prefix_8_byte:
24920       move_mode = DImode;
24921       break;
24922     case rep_prefix_4_byte:
24923       move_mode = SImode;
24924       break;
24925     case rep_prefix_1_byte:
24926       move_mode = QImode;
24927       break;
24928     }
24929   size_needed = GET_MODE_SIZE (move_mode) * unroll_factor;
24930   epilogue_size_needed = size_needed;
24931
24932   desired_align = decide_alignment (align, alg, expected_size, move_mode);
24933   if (!TARGET_ALIGN_STRINGOPS || noalign)
24934     align = desired_align;
24935
24936   /* Step 1: Prologue guard.  */
24937
24938   /* Alignment code needs count to be in register.  */
24939   if (CONST_INT_P (count_exp) && desired_align > align)
24940     {
24941       if (INTVAL (count_exp) > desired_align
24942           && INTVAL (count_exp) > size_needed)
24943         {
24944           align_bytes
24945             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
24946           if (align_bytes <= 0)
24947             align_bytes = 0;
24948           else
24949             align_bytes = desired_align - align_bytes;
24950         }
24951       if (align_bytes == 0)
24952         count_exp = force_reg (counter_mode (count_exp), count_exp);
24953     }
24954   gcc_assert (desired_align >= 1 && align >= 1);
24955
24956   /* Misaligned move sequences handle both prologue and epilogue at once.
24957      Default code generation results in a smaller code for large alignments
24958      and also avoids redundant job when sizes are known precisely.  */
24959   misaligned_prologue_used
24960     = (TARGET_MISALIGNED_MOVE_STRING_PRO_EPILOGUES
24961        && MAX (desired_align, epilogue_size_needed) <= 32
24962        && desired_align <= epilogue_size_needed
24963        && ((desired_align > align && !align_bytes)
24964            || (!count && epilogue_size_needed > 1)));
24965
24966   /* Do the cheap promotion to allow better CSE across the
24967      main loop and epilogue (ie one load of the big constant in the
24968      front of all code.  
24969      For now the misaligned move sequences do not have fast path
24970      without broadcasting.  */
24971   if (issetmem && ((CONST_INT_P (val_exp) || misaligned_prologue_used)))
24972     {
24973       if (alg == vector_loop)
24974         {
24975           gcc_assert (val_exp == const0_rtx);
24976           vec_promoted_val = promote_duplicated_reg (move_mode, val_exp);
24977           promoted_val = promote_duplicated_reg_to_size (val_exp,
24978                                                          GET_MODE_SIZE (word_mode),
24979                                                          desired_align, align);
24980         }
24981       else
24982         {
24983           promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
24984                                                          desired_align, align);
24985         }
24986     }
24987   /* Misaligned move sequences handles both prologues and epilogues at once.
24988      Default code generation results in smaller code for large alignments and
24989      also avoids redundant job when sizes are known precisely.  */
24990   if (misaligned_prologue_used)
24991     {
24992       /* Misaligned move prologue handled small blocks by itself.  */
24993       expand_set_or_movmem_prologue_epilogue_by_misaligned_moves
24994            (dst, src, &destreg, &srcreg,
24995             move_mode, promoted_val, vec_promoted_val,
24996             &count_exp,
24997             &jump_around_label,
24998             desired_align < align
24999             ? MAX (desired_align, epilogue_size_needed) : epilogue_size_needed,
25000             desired_align, align, &min_size, dynamic_check, issetmem);
25001       if (!issetmem)
25002         src = change_address (src, BLKmode, srcreg);
25003       dst = change_address (dst, BLKmode, destreg);
25004       set_mem_align (dst, desired_align * BITS_PER_UNIT);
25005       epilogue_size_needed = 0;
25006       if (need_zero_guard && !min_size)
25007         {
25008           /* It is possible that we copied enough so the main loop will not
25009              execute.  */
25010           gcc_assert (size_needed > 1);
25011           if (jump_around_label == NULL_RTX)
25012             jump_around_label = gen_label_rtx ();
25013           emit_cmp_and_jump_insns (count_exp,
25014                                    GEN_INT (size_needed),
25015                                    LTU, 0, counter_mode (count_exp), 1, jump_around_label);
25016           if (expected_size == -1
25017               || expected_size < (desired_align - align) / 2 + size_needed)
25018             predict_jump (REG_BR_PROB_BASE * 20 / 100);
25019           else
25020             predict_jump (REG_BR_PROB_BASE * 60 / 100);
25021         }
25022     }
25023   /* Ensure that alignment prologue won't copy past end of block.  */
25024   else if (size_needed > 1 || (desired_align > 1 && desired_align > align))
25025     {
25026       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
25027       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
25028          Make sure it is power of 2.  */
25029       epilogue_size_needed = 1 << (floor_log2 (epilogue_size_needed) + 1);
25030
25031       /* To improve performance of small blocks, we jump around the VAL
25032          promoting mode.  This mean that if the promoted VAL is not constant,
25033          we might not use it in the epilogue and have to use byte
25034          loop variant.  */
25035       if (issetmem && epilogue_size_needed > 2 && !promoted_val)
25036         force_loopy_epilogue = true;
25037       if ((count && count < (unsigned HOST_WIDE_INT) epilogue_size_needed)
25038           || max_size < (unsigned HOST_WIDE_INT) epilogue_size_needed)
25039         {
25040           /* If main algorithm works on QImode, no epilogue is needed.
25041              For small sizes just don't align anything.  */
25042           if (size_needed == 1)
25043             desired_align = align;
25044           else
25045             goto epilogue;
25046         }
25047       else if (!count
25048                && min_size < (unsigned HOST_WIDE_INT) epilogue_size_needed)
25049         {
25050           label = gen_label_rtx ();
25051           emit_cmp_and_jump_insns (count_exp,
25052                                    GEN_INT (epilogue_size_needed),
25053                                    LTU, 0, counter_mode (count_exp), 1, label);
25054           if (expected_size == -1 || expected_size < epilogue_size_needed)
25055             predict_jump (REG_BR_PROB_BASE * 60 / 100);
25056           else
25057             predict_jump (REG_BR_PROB_BASE * 20 / 100);
25058         }
25059     }
25060
25061   /* Emit code to decide on runtime whether library call or inline should be
25062      used.  */
25063   if (dynamic_check != -1)
25064     {
25065       if (!issetmem && CONST_INT_P (count_exp))
25066         {
25067           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
25068             {
25069               emit_block_move_via_libcall (dst, src, count_exp, false);
25070               count_exp = const0_rtx;
25071               goto epilogue;
25072             }
25073         }
25074       else
25075         {
25076           rtx_code_label *hot_label = gen_label_rtx ();
25077           if (jump_around_label == NULL_RTX)
25078             jump_around_label = gen_label_rtx ();
25079           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
25080                                    LEU, 0, counter_mode (count_exp),
25081                                    1, hot_label);
25082           predict_jump (REG_BR_PROB_BASE * 90 / 100);
25083           if (issetmem)
25084             set_storage_via_libcall (dst, count_exp, val_exp, false);
25085           else
25086             emit_block_move_via_libcall (dst, src, count_exp, false);
25087           emit_jump (jump_around_label);
25088           emit_label (hot_label);
25089         }
25090     }
25091
25092   /* Step 2: Alignment prologue.  */
25093   /* Do the expensive promotion once we branched off the small blocks.  */
25094   if (issetmem && !promoted_val)
25095     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
25096                                                    desired_align, align);
25097
25098   if (desired_align > align && !misaligned_prologue_used)
25099     {
25100       if (align_bytes == 0)
25101         {
25102           /* Except for the first move in prologue, we no longer know
25103              constant offset in aliasing info.  It don't seems to worth
25104              the pain to maintain it for the first move, so throw away
25105              the info early.  */
25106           dst = change_address (dst, BLKmode, destreg);
25107           if (!issetmem)
25108             src = change_address (src, BLKmode, srcreg);
25109           dst = expand_set_or_movmem_prologue (dst, src, destreg, srcreg,
25110                                             promoted_val, vec_promoted_val,
25111                                             count_exp, align, desired_align,
25112                                             issetmem);
25113           /* At most desired_align - align bytes are copied.  */
25114           if (min_size < (unsigned)(desired_align - align))
25115             min_size = 0;
25116           else
25117             min_size -= desired_align - align;
25118         }
25119       else
25120         {
25121           /* If we know how many bytes need to be stored before dst is
25122              sufficiently aligned, maintain aliasing info accurately.  */
25123           dst = expand_set_or_movmem_constant_prologue (dst, &src, destreg,
25124                                                            srcreg,
25125                                                            promoted_val,
25126                                                            vec_promoted_val,
25127                                                            desired_align,
25128                                                            align_bytes,
25129                                                            issetmem);
25130
25131           count_exp = plus_constant (counter_mode (count_exp),
25132                                      count_exp, -align_bytes);
25133           count -= align_bytes;
25134           min_size -= align_bytes;
25135           max_size -= align_bytes;
25136         }
25137       if (need_zero_guard
25138           && !min_size
25139           && (count < (unsigned HOST_WIDE_INT) size_needed
25140               || (align_bytes == 0
25141                   && count < ((unsigned HOST_WIDE_INT) size_needed
25142                               + desired_align - align))))
25143         {
25144           /* It is possible that we copied enough so the main loop will not
25145              execute.  */
25146           gcc_assert (size_needed > 1);
25147           if (label == NULL_RTX)
25148             label = gen_label_rtx ();
25149           emit_cmp_and_jump_insns (count_exp,
25150                                    GEN_INT (size_needed),
25151                                    LTU, 0, counter_mode (count_exp), 1, label);
25152           if (expected_size == -1
25153               || expected_size < (desired_align - align) / 2 + size_needed)
25154             predict_jump (REG_BR_PROB_BASE * 20 / 100);
25155           else
25156             predict_jump (REG_BR_PROB_BASE * 60 / 100);
25157         }
25158     }
25159   if (label && size_needed == 1)
25160     {
25161       emit_label (label);
25162       LABEL_NUSES (label) = 1;
25163       label = NULL;
25164       epilogue_size_needed = 1;
25165       if (issetmem)
25166         promoted_val = val_exp;
25167     }
25168   else if (label == NULL_RTX && !misaligned_prologue_used)
25169     epilogue_size_needed = size_needed;
25170
25171   /* Step 3: Main loop.  */
25172
25173   switch (alg)
25174     {
25175     case libcall:
25176     case no_stringop:
25177     case last_alg:
25178       gcc_unreachable ();
25179     case loop_1_byte:
25180     case loop:
25181     case unrolled_loop:
25182       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, promoted_val,
25183                                      count_exp, move_mode, unroll_factor,
25184                                      expected_size, issetmem);
25185       break;
25186     case vector_loop:
25187       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg,
25188                                      vec_promoted_val, count_exp, move_mode,
25189                                      unroll_factor, expected_size, issetmem);
25190       break;
25191     case rep_prefix_8_byte:
25192     case rep_prefix_4_byte:
25193     case rep_prefix_1_byte:
25194       expand_set_or_movmem_via_rep (dst, src, destreg, srcreg, promoted_val,
25195                                        val_exp, count_exp, move_mode, issetmem);
25196       break;
25197     }
25198   /* Adjust properly the offset of src and dest memory for aliasing.  */
25199   if (CONST_INT_P (count_exp))
25200     {
25201       if (!issetmem)
25202         src = adjust_automodify_address_nv (src, BLKmode, srcreg,
25203                                             (count / size_needed) * size_needed);
25204       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
25205                                           (count / size_needed) * size_needed);
25206     }
25207   else
25208     {
25209       if (!issetmem)
25210         src = change_address (src, BLKmode, srcreg);
25211       dst = change_address (dst, BLKmode, destreg);
25212     }
25213
25214   /* Step 4: Epilogue to copy the remaining bytes.  */
25215  epilogue:
25216   if (label)
25217     {
25218       /* When the main loop is done, COUNT_EXP might hold original count,
25219          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
25220          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
25221          bytes. Compensate if needed.  */
25222
25223       if (size_needed < epilogue_size_needed)
25224         {
25225           tmp =
25226             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
25227                                  GEN_INT (size_needed - 1), count_exp, 1,
25228                                  OPTAB_DIRECT);
25229           if (tmp != count_exp)
25230             emit_move_insn (count_exp, tmp);
25231         }
25232       emit_label (label);
25233       LABEL_NUSES (label) = 1;
25234     }
25235
25236   if (count_exp != const0_rtx && epilogue_size_needed > 1)
25237     {
25238       if (force_loopy_epilogue)
25239         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
25240                                          epilogue_size_needed);
25241       else
25242         {
25243           if (issetmem)
25244             expand_setmem_epilogue (dst, destreg, promoted_val,
25245                                     vec_promoted_val, count_exp,
25246                                     epilogue_size_needed);
25247           else
25248             expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
25249                                     epilogue_size_needed);
25250         }
25251     }
25252   if (jump_around_label)
25253     emit_label (jump_around_label);
25254   return true;
25255 }
25256
25257
25258 /* Expand the appropriate insns for doing strlen if not just doing
25259    repnz; scasb
25260
25261    out = result, initialized with the start address
25262    align_rtx = alignment of the address.
25263    scratch = scratch register, initialized with the startaddress when
25264         not aligned, otherwise undefined
25265
25266    This is just the body. It needs the initializations mentioned above and
25267    some address computing at the end.  These things are done in i386.md.  */
25268
25269 static void
25270 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
25271 {
25272   int align;
25273   rtx tmp;
25274   rtx_code_label *align_2_label = NULL;
25275   rtx_code_label *align_3_label = NULL;
25276   rtx_code_label *align_4_label = gen_label_rtx ();
25277   rtx_code_label *end_0_label = gen_label_rtx ();
25278   rtx mem;
25279   rtx tmpreg = gen_reg_rtx (SImode);
25280   rtx scratch = gen_reg_rtx (SImode);
25281   rtx cmp;
25282
25283   align = 0;
25284   if (CONST_INT_P (align_rtx))
25285     align = INTVAL (align_rtx);
25286
25287   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
25288
25289   /* Is there a known alignment and is it less than 4?  */
25290   if (align < 4)
25291     {
25292       rtx scratch1 = gen_reg_rtx (Pmode);
25293       emit_move_insn (scratch1, out);
25294       /* Is there a known alignment and is it not 2? */
25295       if (align != 2)
25296         {
25297           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
25298           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
25299
25300           /* Leave just the 3 lower bits.  */
25301           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
25302                                     NULL_RTX, 0, OPTAB_WIDEN);
25303
25304           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
25305                                    Pmode, 1, align_4_label);
25306           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
25307                                    Pmode, 1, align_2_label);
25308           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
25309                                    Pmode, 1, align_3_label);
25310         }
25311       else
25312         {
25313           /* Since the alignment is 2, we have to check 2 or 0 bytes;
25314              check if is aligned to 4 - byte.  */
25315
25316           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
25317                                     NULL_RTX, 0, OPTAB_WIDEN);
25318
25319           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
25320                                    Pmode, 1, align_4_label);
25321         }
25322
25323       mem = change_address (src, QImode, out);
25324
25325       /* Now compare the bytes.  */
25326
25327       /* Compare the first n unaligned byte on a byte per byte basis.  */
25328       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
25329                                QImode, 1, end_0_label);
25330
25331       /* Increment the address.  */
25332       emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25333
25334       /* Not needed with an alignment of 2 */
25335       if (align != 2)
25336         {
25337           emit_label (align_2_label);
25338
25339           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
25340                                    end_0_label);
25341
25342           emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25343
25344           emit_label (align_3_label);
25345         }
25346
25347       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
25348                                end_0_label);
25349
25350       emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25351     }
25352
25353   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
25354      align this loop.  It gives only huge programs, but does not help to
25355      speed up.  */
25356   emit_label (align_4_label);
25357
25358   mem = change_address (src, SImode, out);
25359   emit_move_insn (scratch, mem);
25360   emit_insn (ix86_gen_add3 (out, out, GEN_INT (4)));
25361
25362   /* This formula yields a nonzero result iff one of the bytes is zero.
25363      This saves three branches inside loop and many cycles.  */
25364
25365   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
25366   emit_insn (gen_one_cmplsi2 (scratch, scratch));
25367   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
25368   emit_insn (gen_andsi3 (tmpreg, tmpreg,
25369                          gen_int_mode (0x80808080, SImode)));
25370   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
25371                            align_4_label);
25372
25373   if (TARGET_CMOVE)
25374     {
25375        rtx reg = gen_reg_rtx (SImode);
25376        rtx reg2 = gen_reg_rtx (Pmode);
25377        emit_move_insn (reg, tmpreg);
25378        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
25379
25380        /* If zero is not in the first two bytes, move two bytes forward.  */
25381        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
25382        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25383        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
25384        emit_insn (gen_rtx_SET (tmpreg,
25385                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
25386                                                      reg,
25387                                                      tmpreg)));
25388        /* Emit lea manually to avoid clobbering of flags.  */
25389        emit_insn (gen_rtx_SET (reg2, gen_rtx_PLUS (Pmode, out, const2_rtx)));
25390
25391        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25392        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
25393        emit_insn (gen_rtx_SET (out,
25394                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
25395                                                      reg2,
25396                                                      out)));
25397     }
25398   else
25399     {
25400        rtx_code_label *end_2_label = gen_label_rtx ();
25401        /* Is zero in the first two bytes? */
25402
25403        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
25404        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25405        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
25406        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
25407                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
25408                             pc_rtx);
25409        tmp = emit_jump_insn (gen_rtx_SET (pc_rtx, tmp));
25410        JUMP_LABEL (tmp) = end_2_label;
25411
25412        /* Not in the first two.  Move two bytes forward.  */
25413        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
25414        emit_insn (ix86_gen_add3 (out, out, const2_rtx));
25415
25416        emit_label (end_2_label);
25417
25418     }
25419
25420   /* Avoid branch in fixing the byte.  */
25421   tmpreg = gen_lowpart (QImode, tmpreg);
25422   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
25423   tmp = gen_rtx_REG (CCmode, FLAGS_REG);
25424   cmp = gen_rtx_LTU (VOIDmode, tmp, const0_rtx);
25425   emit_insn (ix86_gen_sub3_carry (out, out, GEN_INT (3), tmp, cmp));
25426
25427   emit_label (end_0_label);
25428 }
25429
25430 /* Expand strlen.  */
25431
25432 bool
25433 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
25434 {
25435   rtx addr, scratch1, scratch2, scratch3, scratch4;
25436
25437   /* The generic case of strlen expander is long.  Avoid it's
25438      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
25439
25440   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
25441       && !TARGET_INLINE_ALL_STRINGOPS
25442       && !optimize_insn_for_size_p ()
25443       && (!CONST_INT_P (align) || INTVAL (align) < 4))
25444     return false;
25445
25446   addr = force_reg (Pmode, XEXP (src, 0));
25447   scratch1 = gen_reg_rtx (Pmode);
25448
25449   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
25450       && !optimize_insn_for_size_p ())
25451     {
25452       /* Well it seems that some optimizer does not combine a call like
25453          foo(strlen(bar), strlen(bar));
25454          when the move and the subtraction is done here.  It does calculate
25455          the length just once when these instructions are done inside of
25456          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
25457          often used and I use one fewer register for the lifetime of
25458          output_strlen_unroll() this is better.  */
25459
25460       emit_move_insn (out, addr);
25461
25462       ix86_expand_strlensi_unroll_1 (out, src, align);
25463
25464       /* strlensi_unroll_1 returns the address of the zero at the end of
25465          the string, like memchr(), so compute the length by subtracting
25466          the start address.  */
25467       emit_insn (ix86_gen_sub3 (out, out, addr));
25468     }
25469   else
25470     {
25471       rtx unspec;
25472
25473       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
25474       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
25475         return false;
25476
25477       scratch2 = gen_reg_rtx (Pmode);
25478       scratch3 = gen_reg_rtx (Pmode);
25479       scratch4 = force_reg (Pmode, constm1_rtx);
25480
25481       emit_move_insn (scratch3, addr);
25482       eoschar = force_reg (QImode, eoschar);
25483
25484       src = replace_equiv_address_nv (src, scratch3);
25485
25486       /* If .md starts supporting :P, this can be done in .md.  */
25487       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
25488                                                  scratch4), UNSPEC_SCAS);
25489       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
25490       emit_insn (ix86_gen_one_cmpl2 (scratch2, scratch1));
25491       emit_insn (ix86_gen_add3 (out, scratch2, constm1_rtx));
25492     }
25493   return true;
25494 }
25495
25496 /* For given symbol (function) construct code to compute address of it's PLT
25497    entry in large x86-64 PIC model.  */
25498 static rtx
25499 construct_plt_address (rtx symbol)
25500 {
25501   rtx tmp, unspec;
25502
25503   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
25504   gcc_assert (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF);
25505   gcc_assert (Pmode == DImode);
25506
25507   tmp = gen_reg_rtx (Pmode);
25508   unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
25509
25510   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
25511   emit_insn (ix86_gen_add3 (tmp, tmp, pic_offset_table_rtx));
25512   return tmp;
25513 }
25514
25515 rtx
25516 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
25517                   rtx callarg2,
25518                   rtx pop, bool sibcall)
25519 {
25520   rtx vec[3];
25521   rtx use = NULL, call;
25522   unsigned int vec_len = 0;
25523
25524   if (pop == const0_rtx)
25525     pop = NULL;
25526   gcc_assert (!TARGET_64BIT || !pop);
25527
25528   if (TARGET_MACHO && !TARGET_64BIT)
25529     {
25530 #if TARGET_MACHO
25531       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
25532         fnaddr = machopic_indirect_call_target (fnaddr);
25533 #endif
25534     }
25535   else
25536     {
25537       /* Static functions and indirect calls don't need the pic register.  Also,
25538          check if PLT was explicitly avoided via no-plt or "noplt" attribute, making
25539          it an indirect call.  */
25540       if (flag_pic
25541           && (!TARGET_64BIT
25542               || (ix86_cmodel == CM_LARGE_PIC
25543                   && DEFAULT_ABI != MS_ABI))
25544           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
25545           && !SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0))
25546           && flag_plt
25547           && (SYMBOL_REF_DECL ((XEXP (fnaddr, 0))) == NULL_TREE
25548               || !lookup_attribute ("noplt",
25549                      DECL_ATTRIBUTES (SYMBOL_REF_DECL (XEXP (fnaddr, 0))))))
25550         {
25551           use_reg (&use, gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM));
25552           if (ix86_use_pseudo_pic_reg ())
25553             emit_move_insn (gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM),
25554                             pic_offset_table_rtx);
25555         }
25556     }
25557
25558   /* Skip setting up RAX register for -mskip-rax-setup when there are no
25559      parameters passed in vector registers.  */
25560   if (TARGET_64BIT
25561       && (INTVAL (callarg2) > 0
25562           || (INTVAL (callarg2) == 0
25563               && (TARGET_SSE || !flag_skip_rax_setup))))
25564     {
25565       rtx al = gen_rtx_REG (QImode, AX_REG);
25566       emit_move_insn (al, callarg2);
25567       use_reg (&use, al);
25568     }
25569
25570   if (ix86_cmodel == CM_LARGE_PIC
25571       && !TARGET_PECOFF
25572       && MEM_P (fnaddr)
25573       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
25574       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
25575     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
25576   else if (sibcall
25577            ? !sibcall_insn_operand (XEXP (fnaddr, 0), word_mode)
25578            : !call_insn_operand (XEXP (fnaddr, 0), word_mode))
25579     {
25580       fnaddr = convert_to_mode (word_mode, XEXP (fnaddr, 0), 1);
25581       fnaddr = gen_rtx_MEM (QImode, copy_to_mode_reg (word_mode, fnaddr));
25582     }
25583
25584   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
25585
25586   if (retval)
25587     {
25588       /* We should add bounds as destination register in case
25589          pointer with bounds may be returned.  */
25590       if (TARGET_MPX && SCALAR_INT_MODE_P (GET_MODE (retval)))
25591         {
25592           rtx b0 = gen_rtx_REG (BND64mode, FIRST_BND_REG);
25593           rtx b1 = gen_rtx_REG (BND64mode, FIRST_BND_REG + 1);
25594           if (GET_CODE (retval) == PARALLEL)
25595             {
25596               b0 = gen_rtx_EXPR_LIST (VOIDmode, b0, const0_rtx);
25597               b1 = gen_rtx_EXPR_LIST (VOIDmode, b1, const0_rtx);
25598               rtx par = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, b0, b1));
25599               retval = chkp_join_splitted_slot (retval, par);
25600             }
25601           else
25602             {
25603               retval = gen_rtx_PARALLEL (VOIDmode,
25604                                          gen_rtvec (3, retval, b0, b1));
25605               chkp_put_regs_to_expr_list (retval);
25606             }
25607         }
25608
25609       call = gen_rtx_SET (retval, call);
25610     }
25611   vec[vec_len++] = call;
25612
25613   if (pop)
25614     {
25615       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
25616       pop = gen_rtx_SET (stack_pointer_rtx, pop);
25617       vec[vec_len++] = pop;
25618     }
25619
25620   if (TARGET_64BIT_MS_ABI
25621       && (!callarg2 || INTVAL (callarg2) != -2))
25622     {
25623       int const cregs_size
25624         = ARRAY_SIZE (x86_64_ms_sysv_extra_clobbered_registers);
25625       int i;
25626
25627       for (i = 0; i < cregs_size; i++)
25628         {
25629           int regno = x86_64_ms_sysv_extra_clobbered_registers[i];
25630           machine_mode mode = SSE_REGNO_P (regno) ? TImode : DImode;
25631
25632           clobber_reg (&use, gen_rtx_REG (mode, regno));
25633         }
25634     }
25635
25636   if (vec_len > 1)
25637     call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (vec_len, vec));
25638   call = emit_call_insn (call);
25639   if (use)
25640     CALL_INSN_FUNCTION_USAGE (call) = use;
25641
25642   return call;
25643 }
25644
25645 /* Return true if the function being called was marked with attribute "noplt"
25646    or using -fno-plt and we are compiling for non-PIC and x86_64.  We need to
25647    handle the non-PIC case in the backend because there is no easy interface
25648    for the front-end to force non-PLT calls to use the GOT.  This is currently
25649    used only with 64-bit ELF targets to call the function marked "noplt"
25650    indirectly.  */
25651
25652 static bool
25653 ix86_nopic_noplt_attribute_p (rtx call_op)
25654 {
25655   if (flag_pic || ix86_cmodel == CM_LARGE
25656       || !TARGET_64BIT || TARGET_MACHO || TARGET_SEH || TARGET_PECOFF
25657       || SYMBOL_REF_LOCAL_P (call_op))
25658     return false;
25659
25660   tree symbol_decl = SYMBOL_REF_DECL (call_op);
25661
25662   if (!flag_plt
25663       || (symbol_decl != NULL_TREE
25664           && lookup_attribute ("noplt", DECL_ATTRIBUTES (symbol_decl))))
25665     return true;
25666
25667   return false;
25668 }
25669
25670 /* Output the assembly for a call instruction.  */
25671
25672 const char *
25673 ix86_output_call_insn (rtx_insn *insn, rtx call_op)
25674 {
25675   bool direct_p = constant_call_address_operand (call_op, VOIDmode);
25676   bool seh_nop_p = false;
25677   const char *xasm;
25678
25679   if (SIBLING_CALL_P (insn))
25680     {
25681       if (direct_p && ix86_nopic_noplt_attribute_p (call_op))
25682         xasm = "%!jmp\t*%p0@GOTPCREL(%%rip)";
25683       else if (direct_p)
25684         xasm = "%!jmp\t%P0";
25685       /* SEH epilogue detection requires the indirect branch case
25686          to include REX.W.  */
25687       else if (TARGET_SEH)
25688         xasm = "%!rex.W jmp %A0";
25689       else
25690         xasm = "%!jmp\t%A0";
25691
25692       output_asm_insn (xasm, &call_op);
25693       return "";
25694     }
25695
25696   /* SEH unwinding can require an extra nop to be emitted in several
25697      circumstances.  Determine if we have one of those.  */
25698   if (TARGET_SEH)
25699     {
25700       rtx_insn *i;
25701
25702       for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
25703         {
25704           /* If we get to another real insn, we don't need the nop.  */
25705           if (INSN_P (i))
25706             break;
25707
25708           /* If we get to the epilogue note, prevent a catch region from
25709              being adjacent to the standard epilogue sequence.  If non-
25710              call-exceptions, we'll have done this during epilogue emission. */
25711           if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG
25712               && !flag_non_call_exceptions
25713               && !can_throw_internal (insn))
25714             {
25715               seh_nop_p = true;
25716               break;
25717             }
25718         }
25719
25720       /* If we didn't find a real insn following the call, prevent the
25721          unwinder from looking into the next function.  */
25722       if (i == NULL)
25723         seh_nop_p = true;
25724     }
25725
25726   if (direct_p && ix86_nopic_noplt_attribute_p (call_op))
25727     xasm = "%!call\t*%p0@GOTPCREL(%%rip)";
25728   else if (direct_p)
25729     xasm = "%!call\t%P0";
25730   else
25731     xasm = "%!call\t%A0";
25732
25733   output_asm_insn (xasm, &call_op);
25734
25735   if (seh_nop_p)
25736     return "nop";
25737
25738   return "";
25739 }
25740 \f
25741 /* Clear stack slot assignments remembered from previous functions.
25742    This is called from INIT_EXPANDERS once before RTL is emitted for each
25743    function.  */
25744
25745 static struct machine_function *
25746 ix86_init_machine_status (void)
25747 {
25748   struct machine_function *f;
25749
25750   f = ggc_cleared_alloc<machine_function> ();
25751   f->use_fast_prologue_epilogue_nregs = -1;
25752   f->call_abi = ix86_abi;
25753
25754   return f;
25755 }
25756
25757 /* Return a MEM corresponding to a stack slot with mode MODE.
25758    Allocate a new slot if necessary.
25759
25760    The RTL for a function can have several slots available: N is
25761    which slot to use.  */
25762
25763 rtx
25764 assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n)
25765 {
25766   struct stack_local_entry *s;
25767
25768   gcc_assert (n < MAX_386_STACK_LOCALS);
25769
25770   for (s = ix86_stack_locals; s; s = s->next)
25771     if (s->mode == mode && s->n == n)
25772       return validize_mem (copy_rtx (s->rtl));
25773
25774   s = ggc_alloc<stack_local_entry> ();
25775   s->n = n;
25776   s->mode = mode;
25777   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
25778
25779   s->next = ix86_stack_locals;
25780   ix86_stack_locals = s;
25781   return validize_mem (copy_rtx (s->rtl));
25782 }
25783
25784 static void
25785 ix86_instantiate_decls (void)
25786 {
25787   struct stack_local_entry *s;
25788
25789   for (s = ix86_stack_locals; s; s = s->next)
25790     if (s->rtl != NULL_RTX)
25791       instantiate_decl_rtl (s->rtl);
25792 }
25793 \f
25794 /* Check whether x86 address PARTS is a pc-relative address.  */
25795
25796 static bool
25797 rip_relative_addr_p (struct ix86_address *parts)
25798 {
25799   rtx base, index, disp;
25800
25801   base = parts->base;
25802   index = parts->index;
25803   disp = parts->disp;
25804
25805   if (disp && !base && !index)
25806     {
25807       if (TARGET_64BIT)
25808         {
25809           rtx symbol = disp;
25810
25811           if (GET_CODE (disp) == CONST)
25812             symbol = XEXP (disp, 0);
25813           if (GET_CODE (symbol) == PLUS
25814               && CONST_INT_P (XEXP (symbol, 1)))
25815             symbol = XEXP (symbol, 0);
25816
25817           if (GET_CODE (symbol) == LABEL_REF
25818               || (GET_CODE (symbol) == SYMBOL_REF
25819                   && SYMBOL_REF_TLS_MODEL (symbol) == 0)
25820               || (GET_CODE (symbol) == UNSPEC
25821                   && (XINT (symbol, 1) == UNSPEC_GOTPCREL
25822                       || XINT (symbol, 1) == UNSPEC_PCREL
25823                       || XINT (symbol, 1) == UNSPEC_GOTNTPOFF)))
25824             return true;
25825         }
25826     }
25827   return false;
25828 }
25829
25830 /* Calculate the length of the memory address in the instruction encoding.
25831    Includes addr32 prefix, does not include the one-byte modrm, opcode,
25832    or other prefixes.  We never generate addr32 prefix for LEA insn.  */
25833
25834 int
25835 memory_address_length (rtx addr, bool lea)
25836 {
25837   struct ix86_address parts;
25838   rtx base, index, disp;
25839   int len;
25840   int ok;
25841
25842   if (GET_CODE (addr) == PRE_DEC
25843       || GET_CODE (addr) == POST_INC
25844       || GET_CODE (addr) == PRE_MODIFY
25845       || GET_CODE (addr) == POST_MODIFY)
25846     return 0;
25847
25848   ok = ix86_decompose_address (addr, &parts);
25849   gcc_assert (ok);
25850
25851   len = (parts.seg == SEG_DEFAULT) ? 0 : 1;
25852
25853   /*  If this is not LEA instruction, add the length of addr32 prefix.  */
25854   if (TARGET_64BIT && !lea
25855       && (SImode_address_operand (addr, VOIDmode)
25856           || (parts.base && GET_MODE (parts.base) == SImode)
25857           || (parts.index && GET_MODE (parts.index) == SImode)))
25858     len++;
25859
25860   base = parts.base;
25861   index = parts.index;
25862   disp = parts.disp;
25863
25864   if (base && GET_CODE (base) == SUBREG)
25865     base = SUBREG_REG (base);
25866   if (index && GET_CODE (index) == SUBREG)
25867     index = SUBREG_REG (index);
25868
25869   gcc_assert (base == NULL_RTX || REG_P (base));
25870   gcc_assert (index == NULL_RTX || REG_P (index));
25871
25872   /* Rule of thumb:
25873        - esp as the base always wants an index,
25874        - ebp as the base always wants a displacement,
25875        - r12 as the base always wants an index,
25876        - r13 as the base always wants a displacement.  */
25877
25878   /* Register Indirect.  */
25879   if (base && !index && !disp)
25880     {
25881       /* esp (for its index) and ebp (for its displacement) need
25882          the two-byte modrm form.  Similarly for r12 and r13 in 64-bit
25883          code.  */
25884       if (base == arg_pointer_rtx
25885           || base == frame_pointer_rtx
25886           || REGNO (base) == SP_REG
25887           || REGNO (base) == BP_REG
25888           || REGNO (base) == R12_REG
25889           || REGNO (base) == R13_REG)
25890         len++;
25891     }
25892
25893   /* Direct Addressing.  In 64-bit mode mod 00 r/m 5
25894      is not disp32, but disp32(%rip), so for disp32
25895      SIB byte is needed, unless print_operand_address
25896      optimizes it into disp32(%rip) or (%rip) is implied
25897      by UNSPEC.  */
25898   else if (disp && !base && !index)
25899     {
25900       len += 4;
25901       if (rip_relative_addr_p (&parts))
25902         len++;
25903     }
25904   else
25905     {
25906       /* Find the length of the displacement constant.  */
25907       if (disp)
25908         {
25909           if (base && satisfies_constraint_K (disp))
25910             len += 1;
25911           else
25912             len += 4;
25913         }
25914       /* ebp always wants a displacement.  Similarly r13.  */
25915       else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
25916         len++;
25917
25918       /* An index requires the two-byte modrm form....  */
25919       if (index
25920           /* ...like esp (or r12), which always wants an index.  */
25921           || base == arg_pointer_rtx
25922           || base == frame_pointer_rtx
25923           || (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
25924         len++;
25925     }
25926
25927   return len;
25928 }
25929
25930 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
25931    is set, expect that insn have 8bit immediate alternative.  */
25932 int
25933 ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform)
25934 {
25935   int len = 0;
25936   int i;
25937   extract_insn_cached (insn);
25938   for (i = recog_data.n_operands - 1; i >= 0; --i)
25939     if (CONSTANT_P (recog_data.operand[i]))
25940       {
25941         enum attr_mode mode = get_attr_mode (insn);
25942
25943         gcc_assert (!len);
25944         if (shortform && CONST_INT_P (recog_data.operand[i]))
25945           {
25946             HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
25947             switch (mode)
25948               {
25949               case MODE_QI:
25950                 len = 1;
25951                 continue;
25952               case MODE_HI:
25953                 ival = trunc_int_for_mode (ival, HImode);
25954                 break;
25955               case MODE_SI:
25956                 ival = trunc_int_for_mode (ival, SImode);
25957                 break;
25958               default:
25959                 break;
25960               }
25961             if (IN_RANGE (ival, -128, 127))
25962               {
25963                 len = 1;
25964                 continue;
25965               }
25966           }
25967         switch (mode)
25968           {
25969           case MODE_QI:
25970             len = 1;
25971             break;
25972           case MODE_HI:
25973             len = 2;
25974             break;
25975           case MODE_SI:
25976             len = 4;
25977             break;
25978           /* Immediates for DImode instructions are encoded
25979              as 32bit sign extended values.  */
25980           case MODE_DI:
25981             len = 4;
25982             break;
25983           default:
25984             fatal_insn ("unknown insn mode", insn);
25985         }
25986       }
25987   return len;
25988 }
25989
25990 /* Compute default value for "length_address" attribute.  */
25991 int
25992 ix86_attr_length_address_default (rtx_insn *insn)
25993 {
25994   int i;
25995
25996   if (get_attr_type (insn) == TYPE_LEA)
25997     {
25998       rtx set = PATTERN (insn), addr;
25999
26000       if (GET_CODE (set) == PARALLEL)
26001         set = XVECEXP (set, 0, 0);
26002
26003       gcc_assert (GET_CODE (set) == SET);
26004
26005       addr = SET_SRC (set);
26006
26007       return memory_address_length (addr, true);
26008     }
26009
26010   extract_insn_cached (insn);
26011   for (i = recog_data.n_operands - 1; i >= 0; --i)
26012     if (MEM_P (recog_data.operand[i]))
26013       {
26014         constrain_operands_cached (insn, reload_completed);
26015         if (which_alternative != -1)
26016           {
26017             const char *constraints = recog_data.constraints[i];
26018             int alt = which_alternative;
26019
26020             while (*constraints == '=' || *constraints == '+')
26021               constraints++;
26022             while (alt-- > 0)
26023               while (*constraints++ != ',')
26024                 ;
26025             /* Skip ignored operands.  */
26026             if (*constraints == 'X')
26027               continue;
26028           }
26029         return memory_address_length (XEXP (recog_data.operand[i], 0), false);
26030       }
26031   return 0;
26032 }
26033
26034 /* Compute default value for "length_vex" attribute. It includes
26035    2 or 3 byte VEX prefix and 1 opcode byte.  */
26036
26037 int
26038 ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode,
26039                               bool has_vex_w)
26040 {
26041   int i;
26042
26043   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
26044      byte VEX prefix.  */
26045   if (!has_0f_opcode || has_vex_w)
26046     return 3 + 1;
26047
26048  /* We can always use 2 byte VEX prefix in 32bit.  */
26049   if (!TARGET_64BIT)
26050     return 2 + 1;
26051
26052   extract_insn_cached (insn);
26053
26054   for (i = recog_data.n_operands - 1; i >= 0; --i)
26055     if (REG_P (recog_data.operand[i]))
26056       {
26057         /* REX.W bit uses 3 byte VEX prefix.  */
26058         if (GET_MODE (recog_data.operand[i]) == DImode
26059             && GENERAL_REG_P (recog_data.operand[i]))
26060           return 3 + 1;
26061       }
26062     else
26063       {
26064         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
26065         if (MEM_P (recog_data.operand[i])
26066             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
26067           return 3 + 1;
26068       }
26069
26070   return 2 + 1;
26071 }
26072 \f
26073 /* Return the maximum number of instructions a cpu can issue.  */
26074
26075 static int
26076 ix86_issue_rate (void)
26077 {
26078   switch (ix86_tune)
26079     {
26080     case PROCESSOR_PENTIUM:
26081     case PROCESSOR_BONNELL:
26082     case PROCESSOR_SILVERMONT:
26083     case PROCESSOR_KNL:
26084     case PROCESSOR_INTEL:
26085     case PROCESSOR_K6:
26086     case PROCESSOR_BTVER2:
26087     case PROCESSOR_PENTIUM4:
26088     case PROCESSOR_NOCONA:
26089       return 2;
26090
26091     case PROCESSOR_PENTIUMPRO:
26092     case PROCESSOR_ATHLON:
26093     case PROCESSOR_K8:
26094     case PROCESSOR_AMDFAM10:
26095     case PROCESSOR_GENERIC:
26096     case PROCESSOR_BTVER1:
26097       return 3;
26098
26099     case PROCESSOR_BDVER1:
26100     case PROCESSOR_BDVER2:
26101     case PROCESSOR_BDVER3:
26102     case PROCESSOR_BDVER4:
26103     case PROCESSOR_CORE2:
26104     case PROCESSOR_NEHALEM:
26105     case PROCESSOR_SANDYBRIDGE:
26106     case PROCESSOR_HASWELL:
26107       return 4;
26108
26109     default:
26110       return 1;
26111     }
26112 }
26113
26114 /* A subroutine of ix86_adjust_cost -- return TRUE iff INSN reads flags set
26115    by DEP_INSN and nothing set by DEP_INSN.  */
26116
26117 static bool
26118 ix86_flags_dependent (rtx_insn *insn, rtx_insn *dep_insn, enum attr_type insn_type)
26119 {
26120   rtx set, set2;
26121
26122   /* Simplify the test for uninteresting insns.  */
26123   if (insn_type != TYPE_SETCC
26124       && insn_type != TYPE_ICMOV
26125       && insn_type != TYPE_FCMOV
26126       && insn_type != TYPE_IBR)
26127     return false;
26128
26129   if ((set = single_set (dep_insn)) != 0)
26130     {
26131       set = SET_DEST (set);
26132       set2 = NULL_RTX;
26133     }
26134   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
26135            && XVECLEN (PATTERN (dep_insn), 0) == 2
26136            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
26137            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
26138     {
26139       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
26140       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
26141     }
26142   else
26143     return false;
26144
26145   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
26146     return false;
26147
26148   /* This test is true if the dependent insn reads the flags but
26149      not any other potentially set register.  */
26150   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
26151     return false;
26152
26153   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
26154     return false;
26155
26156   return true;
26157 }
26158
26159 /* Return true iff USE_INSN has a memory address with operands set by
26160    SET_INSN.  */
26161
26162 bool
26163 ix86_agi_dependent (rtx_insn *set_insn, rtx_insn *use_insn)
26164 {
26165   int i;
26166   extract_insn_cached (use_insn);
26167   for (i = recog_data.n_operands - 1; i >= 0; --i)
26168     if (MEM_P (recog_data.operand[i]))
26169       {
26170         rtx addr = XEXP (recog_data.operand[i], 0);
26171         return modified_in_p (addr, set_insn) != 0;
26172       }
26173   return false;
26174 }
26175
26176 /* Helper function for exact_store_load_dependency.
26177    Return true if addr is found in insn.  */
26178 static bool
26179 exact_dependency_1 (rtx addr, rtx insn)
26180 {
26181   enum rtx_code code;
26182   const char *format_ptr;
26183   int i, j;
26184
26185   code = GET_CODE (insn);
26186   switch (code)
26187     {
26188     case MEM:
26189       if (rtx_equal_p (addr, insn))
26190         return true;
26191       break;
26192     case REG:
26193     CASE_CONST_ANY:
26194     case SYMBOL_REF:
26195     case CODE_LABEL:
26196     case PC:
26197     case CC0:
26198     case EXPR_LIST:
26199       return false;
26200     default:
26201       break;
26202     }
26203
26204   format_ptr = GET_RTX_FORMAT (code);
26205   for (i = 0; i < GET_RTX_LENGTH (code); i++)
26206     {
26207       switch (*format_ptr++)
26208         {
26209         case 'e':
26210           if (exact_dependency_1 (addr, XEXP (insn, i)))
26211             return true;
26212           break;
26213         case 'E':
26214           for (j = 0; j < XVECLEN (insn, i); j++)
26215             if (exact_dependency_1 (addr, XVECEXP (insn, i, j)))
26216               return true;
26217           break;
26218         }
26219     }
26220   return false;
26221 }
26222
26223 /* Return true if there exists exact dependency for store & load, i.e.
26224    the same memory address is used in them.  */
26225 static bool
26226 exact_store_load_dependency (rtx_insn *store, rtx_insn *load)
26227 {
26228   rtx set1, set2;
26229
26230   set1 = single_set (store);
26231   if (!set1)
26232     return false;
26233   if (!MEM_P (SET_DEST (set1)))
26234     return false;
26235   set2 = single_set (load);
26236   if (!set2)
26237     return false;
26238   if (exact_dependency_1 (SET_DEST (set1), SET_SRC (set2)))
26239     return true;
26240   return false;
26241 }
26242
26243 static int
26244 ix86_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
26245 {
26246   enum attr_type insn_type, dep_insn_type;
26247   enum attr_memory memory;
26248   rtx set, set2;
26249   int dep_insn_code_number;
26250
26251   /* Anti and output dependencies have zero cost on all CPUs.  */
26252   if (REG_NOTE_KIND (link) != 0)
26253     return 0;
26254
26255   dep_insn_code_number = recog_memoized (dep_insn);
26256
26257   /* If we can't recognize the insns, we can't really do anything.  */
26258   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
26259     return cost;
26260
26261   insn_type = get_attr_type (insn);
26262   dep_insn_type = get_attr_type (dep_insn);
26263
26264   switch (ix86_tune)
26265     {
26266     case PROCESSOR_PENTIUM:
26267       /* Address Generation Interlock adds a cycle of latency.  */
26268       if (insn_type == TYPE_LEA)
26269         {
26270           rtx addr = PATTERN (insn);
26271
26272           if (GET_CODE (addr) == PARALLEL)
26273             addr = XVECEXP (addr, 0, 0);
26274
26275           gcc_assert (GET_CODE (addr) == SET);
26276
26277           addr = SET_SRC (addr);
26278           if (modified_in_p (addr, dep_insn))
26279             cost += 1;
26280         }
26281       else if (ix86_agi_dependent (dep_insn, insn))
26282         cost += 1;
26283
26284       /* ??? Compares pair with jump/setcc.  */
26285       if (ix86_flags_dependent (insn, dep_insn, insn_type))
26286         cost = 0;
26287
26288       /* Floating point stores require value to be ready one cycle earlier.  */
26289       if (insn_type == TYPE_FMOV
26290           && get_attr_memory (insn) == MEMORY_STORE
26291           && !ix86_agi_dependent (dep_insn, insn))
26292         cost += 1;
26293       break;
26294
26295     case PROCESSOR_PENTIUMPRO:
26296       /* INT->FP conversion is expensive.  */
26297       if (get_attr_fp_int_src (dep_insn))
26298         cost += 5;
26299
26300       /* There is one cycle extra latency between an FP op and a store.  */
26301       if (insn_type == TYPE_FMOV
26302           && (set = single_set (dep_insn)) != NULL_RTX
26303           && (set2 = single_set (insn)) != NULL_RTX
26304           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
26305           && MEM_P (SET_DEST (set2)))
26306         cost += 1;
26307
26308       memory = get_attr_memory (insn);
26309
26310       /* Show ability of reorder buffer to hide latency of load by executing
26311          in parallel with previous instruction in case
26312          previous instruction is not needed to compute the address.  */
26313       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26314           && !ix86_agi_dependent (dep_insn, insn))
26315         {
26316           /* Claim moves to take one cycle, as core can issue one load
26317              at time and the next load can start cycle later.  */
26318           if (dep_insn_type == TYPE_IMOV
26319               || dep_insn_type == TYPE_FMOV)
26320             cost = 1;
26321           else if (cost > 1)
26322             cost--;
26323         }
26324       break;
26325
26326     case PROCESSOR_K6:
26327      /* The esp dependency is resolved before
26328         the instruction is really finished.  */
26329       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26330           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26331         return 1;
26332
26333       /* INT->FP conversion is expensive.  */
26334       if (get_attr_fp_int_src (dep_insn))
26335         cost += 5;
26336
26337       memory = get_attr_memory (insn);
26338
26339       /* Show ability of reorder buffer to hide latency of load by executing
26340          in parallel with previous instruction in case
26341          previous instruction is not needed to compute the address.  */
26342       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26343           && !ix86_agi_dependent (dep_insn, insn))
26344         {
26345           /* Claim moves to take one cycle, as core can issue one load
26346              at time and the next load can start cycle later.  */
26347           if (dep_insn_type == TYPE_IMOV
26348               || dep_insn_type == TYPE_FMOV)
26349             cost = 1;
26350           else if (cost > 2)
26351             cost -= 2;
26352           else
26353             cost = 1;
26354         }
26355       break;
26356
26357     case PROCESSOR_AMDFAM10:
26358     case PROCESSOR_BDVER1:
26359     case PROCESSOR_BDVER2:
26360     case PROCESSOR_BDVER3:
26361     case PROCESSOR_BDVER4:
26362     case PROCESSOR_BTVER1:
26363     case PROCESSOR_BTVER2:
26364     case PROCESSOR_GENERIC:
26365       /* Stack engine allows to execute push&pop instructions in parall.  */
26366       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26367           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26368         return 0;
26369       /* FALLTHRU */
26370
26371     case PROCESSOR_ATHLON:
26372     case PROCESSOR_K8:
26373       memory = get_attr_memory (insn);
26374
26375       /* Show ability of reorder buffer to hide latency of load by executing
26376          in parallel with previous instruction in case
26377          previous instruction is not needed to compute the address.  */
26378       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26379           && !ix86_agi_dependent (dep_insn, insn))
26380         {
26381           enum attr_unit unit = get_attr_unit (insn);
26382           int loadcost = 3;
26383
26384           /* Because of the difference between the length of integer and
26385              floating unit pipeline preparation stages, the memory operands
26386              for floating point are cheaper.
26387
26388              ??? For Athlon it the difference is most probably 2.  */
26389           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
26390             loadcost = 3;
26391           else
26392             loadcost = TARGET_ATHLON ? 2 : 0;
26393
26394           if (cost >= loadcost)
26395             cost -= loadcost;
26396           else
26397             cost = 0;
26398         }
26399       break;
26400
26401     case PROCESSOR_CORE2:
26402     case PROCESSOR_NEHALEM:
26403     case PROCESSOR_SANDYBRIDGE:
26404     case PROCESSOR_HASWELL:
26405       /* Stack engine allows to execute push&pop instructions in parall.  */
26406       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26407           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26408         return 0;
26409
26410       memory = get_attr_memory (insn);
26411
26412       /* Show ability of reorder buffer to hide latency of load by executing
26413          in parallel with previous instruction in case
26414          previous instruction is not needed to compute the address.  */
26415       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26416           && !ix86_agi_dependent (dep_insn, insn))
26417         {
26418           if (cost >= 4)
26419             cost -= 4;
26420           else
26421             cost = 0;
26422         }
26423       break;
26424
26425     case PROCESSOR_SILVERMONT:
26426     case PROCESSOR_KNL:
26427     case PROCESSOR_INTEL:
26428       if (!reload_completed)
26429         return cost;
26430
26431       /* Increase cost of integer loads.  */
26432       memory = get_attr_memory (dep_insn);
26433       if (memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26434         {
26435           enum attr_unit unit = get_attr_unit (dep_insn);
26436           if (unit == UNIT_INTEGER && cost == 1)
26437             {
26438               if (memory == MEMORY_LOAD)
26439                 cost = 3;
26440               else
26441                 {
26442                   /* Increase cost of ld/st for short int types only
26443                      because of store forwarding issue.  */
26444                   rtx set = single_set (dep_insn);
26445                   if (set && (GET_MODE (SET_DEST (set)) == QImode
26446                               || GET_MODE (SET_DEST (set)) == HImode))
26447                     {
26448                       /* Increase cost of store/load insn if exact
26449                          dependence exists and it is load insn.  */
26450                       enum attr_memory insn_memory = get_attr_memory (insn);
26451                       if (insn_memory == MEMORY_LOAD
26452                           && exact_store_load_dependency (dep_insn, insn))
26453                         cost = 3;
26454                     }
26455                 }
26456             }
26457         }
26458
26459     default:
26460       break;
26461     }
26462
26463   return cost;
26464 }
26465
26466 /* How many alternative schedules to try.  This should be as wide as the
26467    scheduling freedom in the DFA, but no wider.  Making this value too
26468    large results extra work for the scheduler.  */
26469
26470 static int
26471 ia32_multipass_dfa_lookahead (void)
26472 {
26473   switch (ix86_tune)
26474     {
26475     case PROCESSOR_PENTIUM:
26476       return 2;
26477
26478     case PROCESSOR_PENTIUMPRO:
26479     case PROCESSOR_K6:
26480       return 1;
26481
26482     case PROCESSOR_BDVER1:
26483     case PROCESSOR_BDVER2:
26484     case PROCESSOR_BDVER3:
26485     case PROCESSOR_BDVER4:
26486       /* We use lookahead value 4 for BD both before and after reload
26487          schedules. Plan is to have value 8 included for O3. */
26488         return 4;
26489
26490     case PROCESSOR_CORE2:
26491     case PROCESSOR_NEHALEM:
26492     case PROCESSOR_SANDYBRIDGE:
26493     case PROCESSOR_HASWELL:
26494     case PROCESSOR_BONNELL:
26495     case PROCESSOR_SILVERMONT:
26496     case PROCESSOR_KNL:
26497     case PROCESSOR_INTEL:
26498       /* Generally, we want haifa-sched:max_issue() to look ahead as far
26499          as many instructions can be executed on a cycle, i.e.,
26500          issue_rate.  I wonder why tuning for many CPUs does not do this.  */
26501       if (reload_completed)
26502         return ix86_issue_rate ();
26503       /* Don't use lookahead for pre-reload schedule to save compile time.  */
26504       return 0;
26505
26506     default:
26507       return 0;
26508     }
26509 }
26510
26511 /* Return true if target platform supports macro-fusion.  */
26512
26513 static bool
26514 ix86_macro_fusion_p ()
26515 {
26516   return TARGET_FUSE_CMP_AND_BRANCH;
26517 }
26518
26519 /* Check whether current microarchitecture support macro fusion
26520    for insn pair "CONDGEN + CONDJMP". Refer to
26521    "Intel Architectures Optimization Reference Manual". */
26522
26523 static bool
26524 ix86_macro_fusion_pair_p (rtx_insn *condgen, rtx_insn *condjmp)
26525 {
26526   rtx src, dest;
26527   enum rtx_code ccode;
26528   rtx compare_set = NULL_RTX, test_if, cond;
26529   rtx alu_set = NULL_RTX, addr = NULL_RTX;
26530
26531   if (!any_condjump_p (condjmp))
26532     return false;
26533
26534   if (get_attr_type (condgen) != TYPE_TEST
26535       && get_attr_type (condgen) != TYPE_ICMP
26536       && get_attr_type (condgen) != TYPE_INCDEC
26537       && get_attr_type (condgen) != TYPE_ALU)
26538     return false;
26539
26540   compare_set = single_set (condgen);
26541   if (compare_set == NULL_RTX
26542       && !TARGET_FUSE_ALU_AND_BRANCH)
26543     return false;
26544
26545   if (compare_set == NULL_RTX)
26546     {
26547       int i;
26548       rtx pat = PATTERN (condgen);
26549       for (i = 0; i < XVECLEN (pat, 0); i++)
26550         if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
26551           {
26552             rtx set_src = SET_SRC (XVECEXP (pat, 0, i));
26553             if (GET_CODE (set_src) == COMPARE)
26554               compare_set = XVECEXP (pat, 0, i);
26555             else
26556               alu_set = XVECEXP (pat, 0, i);
26557           }
26558     }
26559   if (compare_set == NULL_RTX)
26560     return false;
26561   src = SET_SRC (compare_set);
26562   if (GET_CODE (src) != COMPARE)
26563     return false;
26564
26565   /* Macro-fusion for cmp/test MEM-IMM + conditional jmp is not
26566      supported.  */
26567   if ((MEM_P (XEXP (src, 0))
26568        && CONST_INT_P (XEXP (src, 1)))
26569       || (MEM_P (XEXP (src, 1))
26570           && CONST_INT_P (XEXP (src, 0))))
26571     return false;
26572
26573   /* No fusion for RIP-relative address.  */
26574   if (MEM_P (XEXP (src, 0)))
26575     addr = XEXP (XEXP (src, 0), 0);
26576   else if (MEM_P (XEXP (src, 1)))
26577     addr = XEXP (XEXP (src, 1), 0);
26578
26579   if (addr) {
26580     ix86_address parts;
26581     int ok = ix86_decompose_address (addr, &parts);
26582     gcc_assert (ok);
26583
26584     if (rip_relative_addr_p (&parts))
26585       return false;
26586   }
26587
26588   test_if = SET_SRC (pc_set (condjmp));
26589   cond = XEXP (test_if, 0);
26590   ccode = GET_CODE (cond);
26591   /* Check whether conditional jump use Sign or Overflow Flags.  */
26592   if (!TARGET_FUSE_CMP_AND_BRANCH_SOFLAGS
26593       && (ccode == GE
26594           || ccode == GT
26595           || ccode == LE
26596           || ccode == LT))
26597     return false;
26598
26599   /* Return true for TYPE_TEST and TYPE_ICMP.  */
26600   if (get_attr_type (condgen) == TYPE_TEST
26601       || get_attr_type (condgen) == TYPE_ICMP)
26602     return true;
26603
26604   /* The following is the case that macro-fusion for alu + jmp.  */
26605   if (!TARGET_FUSE_ALU_AND_BRANCH || !alu_set)
26606     return false;
26607
26608   /* No fusion for alu op with memory destination operand.  */
26609   dest = SET_DEST (alu_set);
26610   if (MEM_P (dest))
26611     return false;
26612
26613   /* Macro-fusion for inc/dec + unsigned conditional jump is not
26614      supported.  */
26615   if (get_attr_type (condgen) == TYPE_INCDEC
26616       && (ccode == GEU
26617           || ccode == GTU
26618           || ccode == LEU
26619           || ccode == LTU))
26620     return false;
26621
26622   return true;
26623 }
26624
26625 /* Try to reorder ready list to take advantage of Atom pipelined IMUL
26626    execution. It is applied if
26627    (1) IMUL instruction is on the top of list;
26628    (2) There exists the only producer of independent IMUL instruction in
26629        ready list.
26630    Return index of IMUL producer if it was found and -1 otherwise.  */
26631 static int
26632 do_reorder_for_imul (rtx_insn **ready, int n_ready)
26633 {
26634   rtx_insn *insn;
26635   rtx set, insn1, insn2;
26636   sd_iterator_def sd_it;
26637   dep_t dep;
26638   int index = -1;
26639   int i;
26640
26641   if (!TARGET_BONNELL)
26642     return index;
26643
26644   /* Check that IMUL instruction is on the top of ready list.  */
26645   insn = ready[n_ready - 1];
26646   set = single_set (insn);
26647   if (!set)
26648     return index;
26649   if (!(GET_CODE (SET_SRC (set)) == MULT
26650       && GET_MODE (SET_SRC (set)) == SImode))
26651     return index;
26652
26653   /* Search for producer of independent IMUL instruction.  */
26654   for (i = n_ready - 2; i >= 0; i--)
26655     {
26656       insn = ready[i];
26657       if (!NONDEBUG_INSN_P (insn))
26658         continue;
26659       /* Skip IMUL instruction.  */
26660       insn2 = PATTERN (insn);
26661       if (GET_CODE (insn2) == PARALLEL)
26662         insn2 = XVECEXP (insn2, 0, 0);
26663       if (GET_CODE (insn2) == SET
26664           && GET_CODE (SET_SRC (insn2)) == MULT
26665           && GET_MODE (SET_SRC (insn2)) == SImode)
26666         continue;
26667
26668       FOR_EACH_DEP (insn, SD_LIST_FORW, sd_it, dep)
26669         {
26670           rtx con;
26671           con = DEP_CON (dep);
26672           if (!NONDEBUG_INSN_P (con))
26673             continue;
26674           insn1 = PATTERN (con);
26675           if (GET_CODE (insn1) == PARALLEL)
26676             insn1 = XVECEXP (insn1, 0, 0);
26677
26678           if (GET_CODE (insn1) == SET
26679               && GET_CODE (SET_SRC (insn1)) == MULT
26680               && GET_MODE (SET_SRC (insn1)) == SImode)
26681             {
26682               sd_iterator_def sd_it1;
26683               dep_t dep1;
26684               /* Check if there is no other dependee for IMUL.  */
26685               index = i;
26686               FOR_EACH_DEP (con, SD_LIST_BACK, sd_it1, dep1)
26687                 {
26688                   rtx pro;
26689                   pro = DEP_PRO (dep1);
26690                   if (!NONDEBUG_INSN_P (pro))
26691                     continue;
26692                   if (pro != insn)
26693                     index = -1;
26694                 }
26695               if (index >= 0)
26696                 break;
26697             }
26698         }
26699       if (index >= 0)
26700         break;
26701     }
26702   return index;
26703 }
26704
26705 /* Try to find the best candidate on the top of ready list if two insns
26706    have the same priority - candidate is best if its dependees were
26707    scheduled earlier. Applied for Silvermont only.
26708    Return true if top 2 insns must be interchanged.  */
26709 static bool
26710 swap_top_of_ready_list (rtx_insn **ready, int n_ready)
26711 {
26712   rtx_insn *top = ready[n_ready - 1];
26713   rtx_insn *next = ready[n_ready - 2];
26714   rtx set;
26715   sd_iterator_def sd_it;
26716   dep_t dep;
26717   int clock1 = -1;
26718   int clock2 = -1;
26719   #define INSN_TICK(INSN) (HID (INSN)->tick)
26720
26721   if (!TARGET_SILVERMONT && !TARGET_INTEL)
26722     return false;
26723
26724   if (!NONDEBUG_INSN_P (top))
26725     return false;
26726   if (!NONJUMP_INSN_P (top))
26727     return false;
26728   if (!NONDEBUG_INSN_P (next))
26729     return false;
26730   if (!NONJUMP_INSN_P (next))
26731     return false;
26732   set = single_set (top);
26733   if (!set)
26734     return false;
26735   set = single_set (next);
26736   if (!set)
26737     return false;
26738
26739   if (INSN_PRIORITY_KNOWN (top) && INSN_PRIORITY_KNOWN (next))
26740     {
26741       if (INSN_PRIORITY (top) != INSN_PRIORITY (next))
26742         return false;
26743       /* Determine winner more precise.  */
26744       FOR_EACH_DEP (top, SD_LIST_RES_BACK, sd_it, dep)
26745         {
26746           rtx pro;
26747           pro = DEP_PRO (dep);
26748           if (!NONDEBUG_INSN_P (pro))
26749             continue;
26750           if (INSN_TICK (pro) > clock1)
26751             clock1 = INSN_TICK (pro);
26752         }
26753       FOR_EACH_DEP (next, SD_LIST_RES_BACK, sd_it, dep)
26754         {
26755           rtx pro;
26756           pro = DEP_PRO (dep);
26757           if (!NONDEBUG_INSN_P (pro))
26758             continue;
26759           if (INSN_TICK (pro) > clock2)
26760             clock2 = INSN_TICK (pro);
26761         }
26762
26763       if (clock1 == clock2)
26764         {
26765           /* Determine winner - load must win. */
26766           enum attr_memory memory1, memory2;
26767           memory1 = get_attr_memory (top);
26768           memory2 = get_attr_memory (next);
26769           if (memory2 == MEMORY_LOAD && memory1 != MEMORY_LOAD)
26770             return true;
26771         }
26772         return (bool) (clock2 < clock1);
26773     }
26774   return false;
26775   #undef INSN_TICK
26776 }
26777
26778 /* Perform possible reodering of ready list for Atom/Silvermont only.
26779    Return issue rate.  */
26780 static int
26781 ix86_sched_reorder (FILE *dump, int sched_verbose, rtx_insn **ready,
26782                     int *pn_ready, int clock_var)
26783 {
26784   int issue_rate = -1;
26785   int n_ready = *pn_ready;
26786   int i;
26787   rtx_insn *insn;
26788   int index = -1;
26789
26790   /* Set up issue rate.  */
26791   issue_rate = ix86_issue_rate ();
26792
26793   /* Do reodering for BONNELL/SILVERMONT only.  */
26794   if (!TARGET_BONNELL && !TARGET_SILVERMONT && !TARGET_INTEL)
26795     return issue_rate;
26796
26797   /* Nothing to do if ready list contains only 1 instruction.  */
26798   if (n_ready <= 1)
26799     return issue_rate;
26800
26801   /* Do reodering for post-reload scheduler only.  */
26802   if (!reload_completed)
26803     return issue_rate;
26804
26805   if ((index = do_reorder_for_imul (ready, n_ready)) >= 0)
26806     {
26807       if (sched_verbose > 1)
26808         fprintf (dump, ";;\tatom sched_reorder: put %d insn on top\n",
26809                  INSN_UID (ready[index]));
26810
26811       /* Put IMUL producer (ready[index]) at the top of ready list.  */
26812       insn = ready[index];
26813       for (i = index; i < n_ready - 1; i++)
26814         ready[i] = ready[i + 1];
26815       ready[n_ready - 1] = insn;
26816       return issue_rate;
26817     }
26818
26819   /* Skip selective scheduling since HID is not populated in it.  */
26820   if (clock_var != 0
26821       && !sel_sched_p ()
26822       && swap_top_of_ready_list (ready, n_ready))
26823     {
26824       if (sched_verbose > 1)
26825         fprintf (dump, ";;\tslm sched_reorder: swap %d and %d insns\n",
26826                  INSN_UID (ready[n_ready - 1]), INSN_UID (ready[n_ready - 2]));
26827       /* Swap 2 top elements of ready list.  */
26828       insn = ready[n_ready - 1];
26829       ready[n_ready - 1] = ready[n_ready - 2];
26830       ready[n_ready - 2] = insn;
26831     }
26832   return issue_rate;
26833 }
26834
26835 static bool
26836 ix86_class_likely_spilled_p (reg_class_t);
26837
26838 /* Returns true if lhs of insn is HW function argument register and set up
26839    is_spilled to true if it is likely spilled HW register.  */
26840 static bool
26841 insn_is_function_arg (rtx insn, bool* is_spilled)
26842 {
26843   rtx dst;
26844
26845   if (!NONDEBUG_INSN_P (insn))
26846     return false;
26847   /* Call instructions are not movable, ignore it.  */
26848   if (CALL_P (insn))
26849     return false;
26850   insn = PATTERN (insn);
26851   if (GET_CODE (insn) == PARALLEL)
26852     insn = XVECEXP (insn, 0, 0);
26853   if (GET_CODE (insn) != SET)
26854     return false;
26855   dst = SET_DEST (insn);
26856   if (REG_P (dst) && HARD_REGISTER_P (dst)
26857       && ix86_function_arg_regno_p (REGNO (dst)))
26858     {
26859       /* Is it likely spilled HW register?  */
26860       if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst))
26861           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))))
26862         *is_spilled = true;
26863       return true;
26864     }
26865   return false;
26866 }
26867
26868 /* Add output dependencies for chain of function adjacent arguments if only
26869    there is a move to likely spilled HW register.  Return first argument
26870    if at least one dependence was added or NULL otherwise.  */
26871 static rtx_insn *
26872 add_parameter_dependencies (rtx_insn *call, rtx_insn *head)
26873 {
26874   rtx_insn *insn;
26875   rtx_insn *last = call;
26876   rtx_insn *first_arg = NULL;
26877   bool is_spilled = false;
26878
26879   head = PREV_INSN (head);
26880
26881   /* Find nearest to call argument passing instruction.  */
26882   while (true)
26883     {
26884       last = PREV_INSN (last);
26885       if (last == head)
26886         return NULL;
26887       if (!NONDEBUG_INSN_P (last))
26888         continue;
26889       if (insn_is_function_arg (last, &is_spilled))
26890         break;
26891       return NULL;
26892     }
26893
26894   first_arg = last;
26895   while (true)
26896     {
26897       insn = PREV_INSN (last);
26898       if (!INSN_P (insn))
26899         break;
26900       if (insn == head)
26901         break;
26902       if (!NONDEBUG_INSN_P (insn))
26903         {
26904           last = insn;
26905           continue;
26906         }
26907       if (insn_is_function_arg (insn, &is_spilled))
26908         {
26909           /* Add output depdendence between two function arguments if chain
26910              of output arguments contains likely spilled HW registers.  */
26911           if (is_spilled)
26912             add_dependence (first_arg, insn, REG_DEP_OUTPUT);
26913           first_arg = last = insn;
26914         }
26915       else
26916         break;
26917     }
26918   if (!is_spilled)
26919     return NULL;
26920   return first_arg;
26921 }
26922
26923 /* Add output or anti dependency from insn to first_arg to restrict its code
26924    motion.  */
26925 static void
26926 avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn)
26927 {
26928   rtx set;
26929   rtx tmp;
26930
26931   /* Add anti dependencies for bounds stores.  */
26932   if (INSN_P (insn)
26933       && GET_CODE (PATTERN (insn)) == PARALLEL
26934       && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == UNSPEC
26935       && XINT (XVECEXP (PATTERN (insn), 0, 0), 1) == UNSPEC_BNDSTX)
26936     {
26937       add_dependence (first_arg, insn, REG_DEP_ANTI);
26938       return;
26939     }
26940
26941   set = single_set (insn);
26942   if (!set)
26943     return;
26944   tmp = SET_DEST (set);
26945   if (REG_P (tmp))
26946     {
26947       /* Add output dependency to the first function argument.  */
26948       add_dependence (first_arg, insn, REG_DEP_OUTPUT);
26949       return;
26950     }
26951   /* Add anti dependency.  */
26952   add_dependence (first_arg, insn, REG_DEP_ANTI);
26953 }
26954
26955 /* Avoid cross block motion of function argument through adding dependency
26956    from the first non-jump instruction in bb.  */
26957 static void
26958 add_dependee_for_func_arg (rtx_insn *arg, basic_block bb)
26959 {
26960   rtx_insn *insn = BB_END (bb);
26961
26962   while (insn)
26963     {
26964       if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn))
26965         {
26966           rtx set = single_set (insn);
26967           if (set)
26968             {
26969               avoid_func_arg_motion (arg, insn);
26970               return;
26971             }
26972         }
26973       if (insn == BB_HEAD (bb))
26974         return;
26975       insn = PREV_INSN (insn);
26976     }
26977 }
26978
26979 /* Hook for pre-reload schedule - avoid motion of function arguments
26980    passed in likely spilled HW registers.  */
26981 static void
26982 ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail)
26983 {
26984   rtx_insn *insn;
26985   rtx_insn *first_arg = NULL;
26986   if (reload_completed)
26987     return;
26988   while (head != tail && DEBUG_INSN_P (head))
26989     head = NEXT_INSN (head);
26990   for (insn = tail; insn != head; insn = PREV_INSN (insn))
26991     if (INSN_P (insn) && CALL_P (insn))
26992       {
26993         first_arg = add_parameter_dependencies (insn, head);
26994         if (first_arg)
26995           {
26996             /* Add dependee for first argument to predecessors if only
26997                region contains more than one block.  */
26998             basic_block bb =  BLOCK_FOR_INSN (insn);
26999             int rgn = CONTAINING_RGN (bb->index);
27000             int nr_blks = RGN_NR_BLOCKS (rgn);
27001             /* Skip trivial regions and region head blocks that can have
27002                predecessors outside of region.  */
27003             if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0)
27004               {
27005                 edge e;
27006                 edge_iterator ei;
27007
27008                 /* Regions are SCCs with the exception of selective
27009                    scheduling with pipelining of outer blocks enabled.
27010                    So also check that immediate predecessors of a non-head
27011                    block are in the same region.  */
27012                 FOR_EACH_EDGE (e, ei, bb->preds)
27013                   {
27014                     /* Avoid creating of loop-carried dependencies through
27015                        using topological ordering in the region.  */
27016                     if (rgn == CONTAINING_RGN (e->src->index)
27017                         && BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index))
27018                       add_dependee_for_func_arg (first_arg, e->src); 
27019                   }
27020               }
27021             insn = first_arg;
27022             if (insn == head)
27023               break;
27024           }
27025       }
27026     else if (first_arg)
27027       avoid_func_arg_motion (first_arg, insn);
27028 }
27029
27030 /* Hook for pre-reload schedule - set priority of moves from likely spilled
27031    HW registers to maximum, to schedule them at soon as possible. These are
27032    moves from function argument registers at the top of the function entry
27033    and moves from function return value registers after call.  */
27034 static int
27035 ix86_adjust_priority (rtx_insn *insn, int priority)
27036 {
27037   rtx set;
27038
27039   if (reload_completed)
27040     return priority;
27041
27042   if (!NONDEBUG_INSN_P (insn))
27043     return priority;
27044
27045   set = single_set (insn);
27046   if (set)
27047     {
27048       rtx tmp = SET_SRC (set);
27049       if (REG_P (tmp)
27050           && HARD_REGISTER_P (tmp)
27051           && !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp))
27052           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp))))
27053         return current_sched_info->sched_max_insns_priority;
27054     }
27055
27056   return priority;
27057 }
27058
27059 /* Model decoder of Core 2/i7.
27060    Below hooks for multipass scheduling (see haifa-sched.c:max_issue)
27061    track the instruction fetch block boundaries and make sure that long
27062    (9+ bytes) instructions are assigned to D0.  */
27063
27064 /* Maximum length of an insn that can be handled by
27065    a secondary decoder unit.  '8' for Core 2/i7.  */
27066 static int core2i7_secondary_decoder_max_insn_size;
27067
27068 /* Ifetch block size, i.e., number of bytes decoder reads per cycle.
27069    '16' for Core 2/i7.  */
27070 static int core2i7_ifetch_block_size;
27071
27072 /* Maximum number of instructions decoder can handle per cycle.
27073    '6' for Core 2/i7.  */
27074 static int core2i7_ifetch_block_max_insns;
27075
27076 typedef struct ix86_first_cycle_multipass_data_ *
27077   ix86_first_cycle_multipass_data_t;
27078 typedef const struct ix86_first_cycle_multipass_data_ *
27079   const_ix86_first_cycle_multipass_data_t;
27080
27081 /* A variable to store target state across calls to max_issue within
27082    one cycle.  */
27083 static struct ix86_first_cycle_multipass_data_ _ix86_first_cycle_multipass_data,
27084   *ix86_first_cycle_multipass_data = &_ix86_first_cycle_multipass_data;
27085
27086 /* Initialize DATA.  */
27087 static void
27088 core2i7_first_cycle_multipass_init (void *_data)
27089 {
27090   ix86_first_cycle_multipass_data_t data
27091     = (ix86_first_cycle_multipass_data_t) _data;
27092
27093   data->ifetch_block_len = 0;
27094   data->ifetch_block_n_insns = 0;
27095   data->ready_try_change = NULL;
27096   data->ready_try_change_size = 0;
27097 }
27098
27099 /* Advancing the cycle; reset ifetch block counts.  */
27100 static void
27101 core2i7_dfa_post_advance_cycle (void)
27102 {
27103   ix86_first_cycle_multipass_data_t data = ix86_first_cycle_multipass_data;
27104
27105   gcc_assert (data->ifetch_block_n_insns <= core2i7_ifetch_block_max_insns);
27106
27107   data->ifetch_block_len = 0;
27108   data->ifetch_block_n_insns = 0;
27109 }
27110
27111 static int min_insn_size (rtx_insn *);
27112
27113 /* Filter out insns from ready_try that the core will not be able to issue
27114    on current cycle due to decoder.  */
27115 static void
27116 core2i7_first_cycle_multipass_filter_ready_try
27117 (const_ix86_first_cycle_multipass_data_t data,
27118  signed char *ready_try, int n_ready, bool first_cycle_insn_p)
27119 {
27120   while (n_ready--)
27121     {
27122       rtx_insn *insn;
27123       int insn_size;
27124
27125       if (ready_try[n_ready])
27126         continue;
27127
27128       insn = get_ready_element (n_ready);
27129       insn_size = min_insn_size (insn);
27130
27131       if (/* If this is a too long an insn for a secondary decoder ...  */
27132           (!first_cycle_insn_p
27133            && insn_size > core2i7_secondary_decoder_max_insn_size)
27134           /* ... or it would not fit into the ifetch block ...  */
27135           || data->ifetch_block_len + insn_size > core2i7_ifetch_block_size
27136           /* ... or the decoder is full already ...  */
27137           || data->ifetch_block_n_insns + 1 > core2i7_ifetch_block_max_insns)
27138         /* ... mask the insn out.  */
27139         {
27140           ready_try[n_ready] = 1;
27141
27142           if (data->ready_try_change)
27143             bitmap_set_bit (data->ready_try_change, n_ready);
27144         }
27145     }
27146 }
27147
27148 /* Prepare for a new round of multipass lookahead scheduling.  */
27149 static void
27150 core2i7_first_cycle_multipass_begin (void *_data,
27151                                      signed char *ready_try, int n_ready,
27152                                      bool first_cycle_insn_p)
27153 {
27154   ix86_first_cycle_multipass_data_t data
27155     = (ix86_first_cycle_multipass_data_t) _data;
27156   const_ix86_first_cycle_multipass_data_t prev_data
27157     = ix86_first_cycle_multipass_data;
27158
27159   /* Restore the state from the end of the previous round.  */
27160   data->ifetch_block_len = prev_data->ifetch_block_len;
27161   data->ifetch_block_n_insns = prev_data->ifetch_block_n_insns;
27162
27163   /* Filter instructions that cannot be issued on current cycle due to
27164      decoder restrictions.  */
27165   core2i7_first_cycle_multipass_filter_ready_try (data, ready_try, n_ready,
27166                                                   first_cycle_insn_p);
27167 }
27168
27169 /* INSN is being issued in current solution.  Account for its impact on
27170    the decoder model.  */
27171 static void
27172 core2i7_first_cycle_multipass_issue (void *_data,
27173                                      signed char *ready_try, int n_ready,
27174                                      rtx_insn *insn, const void *_prev_data)
27175 {
27176   ix86_first_cycle_multipass_data_t data
27177     = (ix86_first_cycle_multipass_data_t) _data;
27178   const_ix86_first_cycle_multipass_data_t prev_data
27179     = (const_ix86_first_cycle_multipass_data_t) _prev_data;
27180
27181   int insn_size = min_insn_size (insn);
27182
27183   data->ifetch_block_len = prev_data->ifetch_block_len + insn_size;
27184   data->ifetch_block_n_insns = prev_data->ifetch_block_n_insns + 1;
27185   gcc_assert (data->ifetch_block_len <= core2i7_ifetch_block_size
27186               && data->ifetch_block_n_insns <= core2i7_ifetch_block_max_insns);
27187
27188   /* Allocate or resize the bitmap for storing INSN's effect on ready_try.  */
27189   if (!data->ready_try_change)
27190     {
27191       data->ready_try_change = sbitmap_alloc (n_ready);
27192       data->ready_try_change_size = n_ready;
27193     }
27194   else if (data->ready_try_change_size < n_ready)
27195     {
27196       data->ready_try_change = sbitmap_resize (data->ready_try_change,
27197                                                n_ready, 0);
27198       data->ready_try_change_size = n_ready;
27199     }
27200   bitmap_clear (data->ready_try_change);
27201
27202   /* Filter out insns from ready_try that the core will not be able to issue
27203      on current cycle due to decoder.  */
27204   core2i7_first_cycle_multipass_filter_ready_try (data, ready_try, n_ready,
27205                                                   false);
27206 }
27207
27208 /* Revert the effect on ready_try.  */
27209 static void
27210 core2i7_first_cycle_multipass_backtrack (const void *_data,
27211                                          signed char *ready_try,
27212                                          int n_ready ATTRIBUTE_UNUSED)
27213 {
27214   const_ix86_first_cycle_multipass_data_t data
27215     = (const_ix86_first_cycle_multipass_data_t) _data;
27216   unsigned int i = 0;
27217   sbitmap_iterator sbi;
27218
27219   gcc_assert (bitmap_last_set_bit (data->ready_try_change) < n_ready);
27220   EXECUTE_IF_SET_IN_BITMAP (data->ready_try_change, 0, i, sbi)
27221     {
27222       ready_try[i] = 0;
27223     }
27224 }
27225
27226 /* Save the result of multipass lookahead scheduling for the next round.  */
27227 static void
27228 core2i7_first_cycle_multipass_end (const void *_data)
27229 {
27230   const_ix86_first_cycle_multipass_data_t data
27231     = (const_ix86_first_cycle_multipass_data_t) _data;
27232   ix86_first_cycle_multipass_data_t next_data
27233     = ix86_first_cycle_multipass_data;
27234
27235   if (data != NULL)
27236     {
27237       next_data->ifetch_block_len = data->ifetch_block_len;
27238       next_data->ifetch_block_n_insns = data->ifetch_block_n_insns;
27239     }
27240 }
27241
27242 /* Deallocate target data.  */
27243 static void
27244 core2i7_first_cycle_multipass_fini (void *_data)
27245 {
27246   ix86_first_cycle_multipass_data_t data
27247     = (ix86_first_cycle_multipass_data_t) _data;
27248
27249   if (data->ready_try_change)
27250     {
27251       sbitmap_free (data->ready_try_change);
27252       data->ready_try_change = NULL;
27253       data->ready_try_change_size = 0;
27254     }
27255 }
27256
27257 /* Prepare for scheduling pass.  */
27258 static void
27259 ix86_sched_init_global (FILE *, int, int)
27260 {
27261   /* Install scheduling hooks for current CPU.  Some of these hooks are used
27262      in time-critical parts of the scheduler, so we only set them up when
27263      they are actually used.  */
27264   switch (ix86_tune)
27265     {
27266     case PROCESSOR_CORE2:
27267     case PROCESSOR_NEHALEM:
27268     case PROCESSOR_SANDYBRIDGE:
27269     case PROCESSOR_HASWELL:
27270       /* Do not perform multipass scheduling for pre-reload schedule
27271          to save compile time.  */
27272       if (reload_completed)
27273         {
27274           targetm.sched.dfa_post_advance_cycle
27275             = core2i7_dfa_post_advance_cycle;
27276           targetm.sched.first_cycle_multipass_init
27277             = core2i7_first_cycle_multipass_init;
27278           targetm.sched.first_cycle_multipass_begin
27279             = core2i7_first_cycle_multipass_begin;
27280           targetm.sched.first_cycle_multipass_issue
27281             = core2i7_first_cycle_multipass_issue;
27282           targetm.sched.first_cycle_multipass_backtrack
27283             = core2i7_first_cycle_multipass_backtrack;
27284           targetm.sched.first_cycle_multipass_end
27285             = core2i7_first_cycle_multipass_end;
27286           targetm.sched.first_cycle_multipass_fini
27287             = core2i7_first_cycle_multipass_fini;
27288
27289           /* Set decoder parameters.  */
27290           core2i7_secondary_decoder_max_insn_size = 8;
27291           core2i7_ifetch_block_size = 16;
27292           core2i7_ifetch_block_max_insns = 6;
27293           break;
27294         }
27295       /* ... Fall through ...  */
27296     default:
27297       targetm.sched.dfa_post_advance_cycle = NULL;
27298       targetm.sched.first_cycle_multipass_init = NULL;
27299       targetm.sched.first_cycle_multipass_begin = NULL;
27300       targetm.sched.first_cycle_multipass_issue = NULL;
27301       targetm.sched.first_cycle_multipass_backtrack = NULL;
27302       targetm.sched.first_cycle_multipass_end = NULL;
27303       targetm.sched.first_cycle_multipass_fini = NULL;
27304       break;
27305     }
27306 }
27307
27308 \f
27309 /* Compute the alignment given to a constant that is being placed in memory.
27310    EXP is the constant and ALIGN is the alignment that the object would
27311    ordinarily have.
27312    The value of this function is used instead of that alignment to align
27313    the object.  */
27314
27315 int
27316 ix86_constant_alignment (tree exp, int align)
27317 {
27318   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
27319       || TREE_CODE (exp) == INTEGER_CST)
27320     {
27321       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
27322         return 64;
27323       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
27324         return 128;
27325     }
27326   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
27327            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
27328     return BITS_PER_WORD;
27329
27330   return align;
27331 }
27332
27333 /* Compute the alignment for a static variable.
27334    TYPE is the data type, and ALIGN is the alignment that
27335    the object would ordinarily have.  The value of this function is used
27336    instead of that alignment to align the object.  */
27337
27338 int
27339 ix86_data_alignment (tree type, int align, bool opt)
27340 {
27341   /* GCC 4.8 and earlier used to incorrectly assume this alignment even
27342      for symbols from other compilation units or symbols that don't need
27343      to bind locally.  In order to preserve some ABI compatibility with
27344      those compilers, ensure we don't decrease alignment from what we
27345      used to assume.  */
27346
27347   int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT);
27348
27349   /* A data structure, equal or greater than the size of a cache line
27350      (64 bytes in the Pentium 4 and other recent Intel processors, including
27351      processors based on Intel Core microarchitecture) should be aligned
27352      so that its base address is a multiple of a cache line size.  */
27353
27354   int max_align
27355     = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
27356
27357   if (max_align < BITS_PER_WORD)
27358     max_align = BITS_PER_WORD;
27359
27360   switch (ix86_align_data_type)
27361     {
27362     case ix86_align_data_type_abi: opt = false; break;
27363     case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break;
27364     case ix86_align_data_type_cacheline: break;
27365     }
27366
27367   if (opt
27368       && AGGREGATE_TYPE_P (type)
27369       && TYPE_SIZE (type)
27370       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
27371     {
27372       if (wi::geu_p (TYPE_SIZE (type), max_align_compat)
27373           && align < max_align_compat)
27374         align = max_align_compat;
27375        if (wi::geu_p (TYPE_SIZE (type), max_align)
27376            && align < max_align)
27377          align = max_align;
27378     }
27379
27380   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
27381      to 16byte boundary.  */
27382   if (TARGET_64BIT)
27383     {
27384       if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
27385           && TYPE_SIZE (type)
27386           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
27387           && wi::geu_p (TYPE_SIZE (type), 128)
27388           && align < 128)
27389         return 128;
27390     }
27391
27392   if (!opt)
27393     return align;
27394
27395   if (TREE_CODE (type) == ARRAY_TYPE)
27396     {
27397       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
27398         return 64;
27399       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
27400         return 128;
27401     }
27402   else if (TREE_CODE (type) == COMPLEX_TYPE)
27403     {
27404
27405       if (TYPE_MODE (type) == DCmode && align < 64)
27406         return 64;
27407       if ((TYPE_MODE (type) == XCmode
27408            || TYPE_MODE (type) == TCmode) && align < 128)
27409         return 128;
27410     }
27411   else if ((TREE_CODE (type) == RECORD_TYPE
27412             || TREE_CODE (type) == UNION_TYPE
27413             || TREE_CODE (type) == QUAL_UNION_TYPE)
27414            && TYPE_FIELDS (type))
27415     {
27416       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
27417         return 64;
27418       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
27419         return 128;
27420     }
27421   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
27422            || TREE_CODE (type) == INTEGER_TYPE)
27423     {
27424       if (TYPE_MODE (type) == DFmode && align < 64)
27425         return 64;
27426       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
27427         return 128;
27428     }
27429
27430   return align;
27431 }
27432
27433 /* Compute the alignment for a local variable or a stack slot.  EXP is
27434    the data type or decl itself, MODE is the widest mode available and
27435    ALIGN is the alignment that the object would ordinarily have.  The
27436    value of this macro is used instead of that alignment to align the
27437    object.  */
27438
27439 unsigned int
27440 ix86_local_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   /* Don't do dynamic stack realignment for long long objects with
27457      -mpreferred-stack-boundary=2.  */
27458   if (!TARGET_64BIT
27459       && align == 64
27460       && ix86_preferred_stack_boundary < 64
27461       && (mode == DImode || (type && TYPE_MODE (type) == DImode))
27462       && (!type || !TYPE_USER_ALIGN (type))
27463       && (!decl || !DECL_USER_ALIGN (decl)))
27464     align = 32;
27465
27466   /* If TYPE is NULL, we are allocating a stack slot for caller-save
27467      register in MODE.  We will return the largest alignment of XF
27468      and DF.  */
27469   if (!type)
27470     {
27471       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
27472         align = GET_MODE_ALIGNMENT (DFmode);
27473       return align;
27474     }
27475
27476   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
27477      to 16byte boundary.  Exact wording is:
27478
27479      An array uses the same alignment as its elements, except that a local or
27480      global array variable of length at least 16 bytes or
27481      a C99 variable-length array variable always has alignment of at least 16 bytes.
27482
27483      This was added to allow use of aligned SSE instructions at arrays.  This
27484      rule is meant for static storage (where compiler can not do the analysis
27485      by itself).  We follow it for automatic variables only when convenient.
27486      We fully control everything in the function compiled and functions from
27487      other unit can not rely on the alignment.
27488
27489      Exclude va_list type.  It is the common case of local array where
27490      we can not benefit from the alignment.  
27491
27492      TODO: Probably one should optimize for size only when var is not escaping.  */
27493   if (TARGET_64BIT && optimize_function_for_speed_p (cfun)
27494       && TARGET_SSE)
27495     {
27496       if (AGGREGATE_TYPE_P (type)
27497           && (va_list_type_node == NULL_TREE
27498               || (TYPE_MAIN_VARIANT (type)
27499                   != TYPE_MAIN_VARIANT (va_list_type_node)))
27500           && TYPE_SIZE (type)
27501           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
27502           && wi::geu_p (TYPE_SIZE (type), 16)
27503           && align < 128)
27504         return 128;
27505     }
27506   if (TREE_CODE (type) == ARRAY_TYPE)
27507     {
27508       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
27509         return 64;
27510       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
27511         return 128;
27512     }
27513   else if (TREE_CODE (type) == COMPLEX_TYPE)
27514     {
27515       if (TYPE_MODE (type) == DCmode && align < 64)
27516         return 64;
27517       if ((TYPE_MODE (type) == XCmode
27518            || TYPE_MODE (type) == TCmode) && align < 128)
27519         return 128;
27520     }
27521   else if ((TREE_CODE (type) == RECORD_TYPE
27522             || TREE_CODE (type) == UNION_TYPE
27523             || TREE_CODE (type) == QUAL_UNION_TYPE)
27524            && TYPE_FIELDS (type))
27525     {
27526       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
27527         return 64;
27528       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
27529         return 128;
27530     }
27531   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
27532            || TREE_CODE (type) == INTEGER_TYPE)
27533     {
27534
27535       if (TYPE_MODE (type) == DFmode && align < 64)
27536         return 64;
27537       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
27538         return 128;
27539     }
27540   return align;
27541 }
27542
27543 /* Compute the minimum required alignment for dynamic stack realignment
27544    purposes for a local variable, parameter or a stack slot.  EXP is
27545    the data type or decl itself, MODE is its mode and ALIGN is the
27546    alignment that the object would ordinarily have.  */
27547
27548 unsigned int
27549 ix86_minimum_alignment (tree exp, machine_mode mode,
27550                         unsigned int align)
27551 {
27552   tree type, decl;
27553
27554   if (exp && DECL_P (exp))
27555     {
27556       type = TREE_TYPE (exp);
27557       decl = exp;
27558     }
27559   else
27560     {
27561       type = exp;
27562       decl = NULL;
27563     }
27564
27565   if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
27566     return align;
27567
27568   /* Don't do dynamic stack realignment for long long objects with
27569      -mpreferred-stack-boundary=2.  */
27570   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
27571       && (!type || !TYPE_USER_ALIGN (type))
27572       && (!decl || !DECL_USER_ALIGN (decl)))
27573     return 32;
27574
27575   return align;
27576 }
27577 \f
27578 /* Find a location for the static chain incoming to a nested function.
27579    This is a register, unless all free registers are used by arguments.  */
27580
27581 static rtx
27582 ix86_static_chain (const_tree fndecl_or_type, bool incoming_p)
27583 {
27584   unsigned regno;
27585
27586   /* While this function won't be called by the middle-end when a static
27587      chain isn't needed, it's also used throughout the backend so it's
27588      easiest to keep this check centralized.  */
27589   if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type))
27590     return NULL;
27591
27592   if (TARGET_64BIT)
27593     {
27594       /* We always use R10 in 64-bit mode.  */
27595       regno = R10_REG;
27596     }
27597   else
27598     {
27599       const_tree fntype, fndecl;
27600       unsigned int ccvt;
27601
27602       /* By default in 32-bit mode we use ECX to pass the static chain.  */
27603       regno = CX_REG;
27604
27605       if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL)
27606         {
27607           fntype = TREE_TYPE (fndecl_or_type);
27608           fndecl = fndecl_or_type;
27609         }
27610       else
27611         {
27612           fntype = fndecl_or_type;
27613           fndecl = NULL;
27614         }
27615
27616       ccvt = ix86_get_callcvt (fntype);
27617       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
27618         {
27619           /* Fastcall functions use ecx/edx for arguments, which leaves
27620              us with EAX for the static chain.
27621              Thiscall functions use ecx for arguments, which also
27622              leaves us with EAX for the static chain.  */
27623           regno = AX_REG;
27624         }
27625       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
27626         {
27627           /* Thiscall functions use ecx for arguments, which leaves
27628              us with EAX and EDX for the static chain.
27629              We are using for abi-compatibility EAX.  */
27630           regno = AX_REG;
27631         }
27632       else if (ix86_function_regparm (fntype, fndecl) == 3)
27633         {
27634           /* For regparm 3, we have no free call-clobbered registers in
27635              which to store the static chain.  In order to implement this,
27636              we have the trampoline push the static chain to the stack.
27637              However, we can't push a value below the return address when
27638              we call the nested function directly, so we have to use an
27639              alternate entry point.  For this we use ESI, and have the
27640              alternate entry point push ESI, so that things appear the
27641              same once we're executing the nested function.  */
27642           if (incoming_p)
27643             {
27644               if (fndecl == current_function_decl)
27645                 ix86_static_chain_on_stack = true;
27646               return gen_frame_mem (SImode,
27647                                     plus_constant (Pmode,
27648                                                    arg_pointer_rtx, -8));
27649             }
27650           regno = SI_REG;
27651         }
27652     }
27653
27654   return gen_rtx_REG (Pmode, regno);
27655 }
27656
27657 /* Emit RTL insns to initialize the variable parts of a trampoline.
27658    FNDECL is the decl of the target address; M_TRAMP is a MEM for
27659    the trampoline, and CHAIN_VALUE is an RTX for the static chain
27660    to be passed to the target function.  */
27661
27662 static void
27663 ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
27664 {
27665   rtx mem, fnaddr;
27666   int opcode;
27667   int offset = 0;
27668
27669   fnaddr = XEXP (DECL_RTL (fndecl), 0);
27670
27671   if (TARGET_64BIT)
27672     {
27673       int size;
27674
27675       /* Load the function address to r11.  Try to load address using
27676          the shorter movl instead of movabs.  We may want to support
27677          movq for kernel mode, but kernel does not use trampolines at
27678          the moment.  FNADDR is a 32bit address and may not be in
27679          DImode when ptr_mode == SImode.  Always use movl in this
27680          case.  */
27681       if (ptr_mode == SImode
27682           || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
27683         {
27684           fnaddr = copy_addr_to_reg (fnaddr);
27685
27686           mem = adjust_address (m_tramp, HImode, offset);
27687           emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
27688
27689           mem = adjust_address (m_tramp, SImode, offset + 2);
27690           emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
27691           offset += 6;
27692         }
27693       else
27694         {
27695           mem = adjust_address (m_tramp, HImode, offset);
27696           emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
27697
27698           mem = adjust_address (m_tramp, DImode, offset + 2);
27699           emit_move_insn (mem, fnaddr);
27700           offset += 10;
27701         }
27702
27703       /* Load static chain using movabs to r10.  Use the shorter movl
27704          instead of movabs when ptr_mode == SImode.  */
27705       if (ptr_mode == SImode)
27706         {
27707           opcode = 0xba41;
27708           size = 6;
27709         }
27710       else
27711         {
27712           opcode = 0xba49;
27713           size = 10;
27714         }
27715
27716       mem = adjust_address (m_tramp, HImode, offset);
27717       emit_move_insn (mem, gen_int_mode (opcode, HImode));
27718
27719       mem = adjust_address (m_tramp, ptr_mode, offset + 2);
27720       emit_move_insn (mem, chain_value);
27721       offset += size;
27722
27723       /* Jump to r11; the last (unused) byte is a nop, only there to
27724          pad the write out to a single 32-bit store.  */
27725       mem = adjust_address (m_tramp, SImode, offset);
27726       emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
27727       offset += 4;
27728     }
27729   else
27730     {
27731       rtx disp, chain;
27732
27733       /* Depending on the static chain location, either load a register
27734          with a constant, or push the constant to the stack.  All of the
27735          instructions are the same size.  */
27736       chain = ix86_static_chain (fndecl, true);
27737       if (REG_P (chain))
27738         {
27739           switch (REGNO (chain))
27740             {
27741             case AX_REG:
27742               opcode = 0xb8; break;
27743             case CX_REG:
27744               opcode = 0xb9; break;
27745             default:
27746               gcc_unreachable ();
27747             }
27748         }
27749       else
27750         opcode = 0x68;
27751
27752       mem = adjust_address (m_tramp, QImode, offset);
27753       emit_move_insn (mem, gen_int_mode (opcode, QImode));
27754
27755       mem = adjust_address (m_tramp, SImode, offset + 1);
27756       emit_move_insn (mem, chain_value);
27757       offset += 5;
27758
27759       mem = adjust_address (m_tramp, QImode, offset);
27760       emit_move_insn (mem, gen_int_mode (0xe9, QImode));
27761
27762       mem = adjust_address (m_tramp, SImode, offset + 1);
27763
27764       /* Compute offset from the end of the jmp to the target function.
27765          In the case in which the trampoline stores the static chain on
27766          the stack, we need to skip the first insn which pushes the
27767          (call-saved) register static chain; this push is 1 byte.  */
27768       offset += 5;
27769       disp = expand_binop (SImode, sub_optab, fnaddr,
27770                            plus_constant (Pmode, XEXP (m_tramp, 0),
27771                                           offset - (MEM_P (chain) ? 1 : 0)),
27772                            NULL_RTX, 1, OPTAB_DIRECT);
27773       emit_move_insn (mem, disp);
27774     }
27775
27776   gcc_assert (offset <= TRAMPOLINE_SIZE);
27777
27778 #ifdef HAVE_ENABLE_EXECUTE_STACK
27779 #ifdef CHECK_EXECUTE_STACK_ENABLED
27780   if (CHECK_EXECUTE_STACK_ENABLED)
27781 #endif
27782   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
27783                      LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
27784 #endif
27785 }
27786 \f
27787 /* The following file contains several enumerations and data structures
27788    built from the definitions in i386-builtin-types.def.  */
27789
27790 #include "i386-builtin-types.inc"
27791
27792 /* Table for the ix86 builtin non-function types.  */
27793 static GTY(()) tree ix86_builtin_type_tab[(int) IX86_BT_LAST_CPTR + 1];
27794
27795 /* Retrieve an element from the above table, building some of
27796    the types lazily.  */
27797
27798 static tree
27799 ix86_get_builtin_type (enum ix86_builtin_type tcode)
27800 {
27801   unsigned int index;
27802   tree type, itype;
27803
27804   gcc_assert ((unsigned)tcode < ARRAY_SIZE(ix86_builtin_type_tab));
27805
27806   type = ix86_builtin_type_tab[(int) tcode];
27807   if (type != NULL)
27808     return type;
27809
27810   gcc_assert (tcode > IX86_BT_LAST_PRIM);
27811   if (tcode <= IX86_BT_LAST_VECT)
27812     {
27813       machine_mode mode;
27814
27815       index = tcode - IX86_BT_LAST_PRIM - 1;
27816       itype = ix86_get_builtin_type (ix86_builtin_type_vect_base[index]);
27817       mode = ix86_builtin_type_vect_mode[index];
27818
27819       type = build_vector_type_for_mode (itype, mode);
27820     }
27821   else
27822     {
27823       int quals;
27824
27825       index = tcode - IX86_BT_LAST_VECT - 1;
27826       if (tcode <= IX86_BT_LAST_PTR)
27827         quals = TYPE_UNQUALIFIED;
27828       else
27829         quals = TYPE_QUAL_CONST;
27830
27831       itype = ix86_get_builtin_type (ix86_builtin_type_ptr_base[index]);
27832       if (quals != TYPE_UNQUALIFIED)
27833         itype = build_qualified_type (itype, quals);
27834
27835       type = build_pointer_type (itype);
27836     }
27837
27838   ix86_builtin_type_tab[(int) tcode] = type;
27839   return type;
27840 }
27841
27842 /* Table for the ix86 builtin function types.  */
27843 static GTY(()) tree ix86_builtin_func_type_tab[(int) IX86_BT_LAST_ALIAS + 1];
27844
27845 /* Retrieve an element from the above table, building some of
27846    the types lazily.  */
27847
27848 static tree
27849 ix86_get_builtin_func_type (enum ix86_builtin_func_type tcode)
27850 {
27851   tree type;
27852
27853   gcc_assert ((unsigned)tcode < ARRAY_SIZE (ix86_builtin_func_type_tab));
27854
27855   type = ix86_builtin_func_type_tab[(int) tcode];
27856   if (type != NULL)
27857     return type;
27858
27859   if (tcode <= IX86_BT_LAST_FUNC)
27860     {
27861       unsigned start = ix86_builtin_func_start[(int) tcode];
27862       unsigned after = ix86_builtin_func_start[(int) tcode + 1];
27863       tree rtype, atype, args = void_list_node;
27864       unsigned i;
27865
27866       rtype = ix86_get_builtin_type (ix86_builtin_func_args[start]);
27867       for (i = after - 1; i > start; --i)
27868         {
27869           atype = ix86_get_builtin_type (ix86_builtin_func_args[i]);
27870           args = tree_cons (NULL, atype, args);
27871         }
27872
27873       type = build_function_type (rtype, args);
27874     }
27875   else
27876     {
27877       unsigned index = tcode - IX86_BT_LAST_FUNC - 1;
27878       enum ix86_builtin_func_type icode;
27879
27880       icode = ix86_builtin_func_alias_base[index];
27881       type = ix86_get_builtin_func_type (icode);
27882     }
27883
27884   ix86_builtin_func_type_tab[(int) tcode] = type;
27885   return type;
27886 }
27887
27888
27889 /* Codes for all the SSE/MMX builtins.  */
27890 enum ix86_builtins
27891 {
27892   IX86_BUILTIN_ADDPS,
27893   IX86_BUILTIN_ADDSS,
27894   IX86_BUILTIN_DIVPS,
27895   IX86_BUILTIN_DIVSS,
27896   IX86_BUILTIN_MULPS,
27897   IX86_BUILTIN_MULSS,
27898   IX86_BUILTIN_SUBPS,
27899   IX86_BUILTIN_SUBSS,
27900
27901   IX86_BUILTIN_CMPEQPS,
27902   IX86_BUILTIN_CMPLTPS,
27903   IX86_BUILTIN_CMPLEPS,
27904   IX86_BUILTIN_CMPGTPS,
27905   IX86_BUILTIN_CMPGEPS,
27906   IX86_BUILTIN_CMPNEQPS,
27907   IX86_BUILTIN_CMPNLTPS,
27908   IX86_BUILTIN_CMPNLEPS,
27909   IX86_BUILTIN_CMPNGTPS,
27910   IX86_BUILTIN_CMPNGEPS,
27911   IX86_BUILTIN_CMPORDPS,
27912   IX86_BUILTIN_CMPUNORDPS,
27913   IX86_BUILTIN_CMPEQSS,
27914   IX86_BUILTIN_CMPLTSS,
27915   IX86_BUILTIN_CMPLESS,
27916   IX86_BUILTIN_CMPNEQSS,
27917   IX86_BUILTIN_CMPNLTSS,
27918   IX86_BUILTIN_CMPNLESS,
27919   IX86_BUILTIN_CMPORDSS,
27920   IX86_BUILTIN_CMPUNORDSS,
27921
27922   IX86_BUILTIN_COMIEQSS,
27923   IX86_BUILTIN_COMILTSS,
27924   IX86_BUILTIN_COMILESS,
27925   IX86_BUILTIN_COMIGTSS,
27926   IX86_BUILTIN_COMIGESS,
27927   IX86_BUILTIN_COMINEQSS,
27928   IX86_BUILTIN_UCOMIEQSS,
27929   IX86_BUILTIN_UCOMILTSS,
27930   IX86_BUILTIN_UCOMILESS,
27931   IX86_BUILTIN_UCOMIGTSS,
27932   IX86_BUILTIN_UCOMIGESS,
27933   IX86_BUILTIN_UCOMINEQSS,
27934
27935   IX86_BUILTIN_CVTPI2PS,
27936   IX86_BUILTIN_CVTPS2PI,
27937   IX86_BUILTIN_CVTSI2SS,
27938   IX86_BUILTIN_CVTSI642SS,
27939   IX86_BUILTIN_CVTSS2SI,
27940   IX86_BUILTIN_CVTSS2SI64,
27941   IX86_BUILTIN_CVTTPS2PI,
27942   IX86_BUILTIN_CVTTSS2SI,
27943   IX86_BUILTIN_CVTTSS2SI64,
27944
27945   IX86_BUILTIN_MAXPS,
27946   IX86_BUILTIN_MAXSS,
27947   IX86_BUILTIN_MINPS,
27948   IX86_BUILTIN_MINSS,
27949
27950   IX86_BUILTIN_LOADUPS,
27951   IX86_BUILTIN_STOREUPS,
27952   IX86_BUILTIN_MOVSS,
27953
27954   IX86_BUILTIN_MOVHLPS,
27955   IX86_BUILTIN_MOVLHPS,
27956   IX86_BUILTIN_LOADHPS,
27957   IX86_BUILTIN_LOADLPS,
27958   IX86_BUILTIN_STOREHPS,
27959   IX86_BUILTIN_STORELPS,
27960
27961   IX86_BUILTIN_MASKMOVQ,
27962   IX86_BUILTIN_MOVMSKPS,
27963   IX86_BUILTIN_PMOVMSKB,
27964
27965   IX86_BUILTIN_MOVNTPS,
27966   IX86_BUILTIN_MOVNTQ,
27967
27968   IX86_BUILTIN_LOADDQU,
27969   IX86_BUILTIN_STOREDQU,
27970
27971   IX86_BUILTIN_PACKSSWB,
27972   IX86_BUILTIN_PACKSSDW,
27973   IX86_BUILTIN_PACKUSWB,
27974
27975   IX86_BUILTIN_PADDB,
27976   IX86_BUILTIN_PADDW,
27977   IX86_BUILTIN_PADDD,
27978   IX86_BUILTIN_PADDQ,
27979   IX86_BUILTIN_PADDSB,
27980   IX86_BUILTIN_PADDSW,
27981   IX86_BUILTIN_PADDUSB,
27982   IX86_BUILTIN_PADDUSW,
27983   IX86_BUILTIN_PSUBB,
27984   IX86_BUILTIN_PSUBW,
27985   IX86_BUILTIN_PSUBD,
27986   IX86_BUILTIN_PSUBQ,
27987   IX86_BUILTIN_PSUBSB,
27988   IX86_BUILTIN_PSUBSW,
27989   IX86_BUILTIN_PSUBUSB,
27990   IX86_BUILTIN_PSUBUSW,
27991
27992   IX86_BUILTIN_PAND,
27993   IX86_BUILTIN_PANDN,
27994   IX86_BUILTIN_POR,
27995   IX86_BUILTIN_PXOR,
27996
27997   IX86_BUILTIN_PAVGB,
27998   IX86_BUILTIN_PAVGW,
27999
28000   IX86_BUILTIN_PCMPEQB,
28001   IX86_BUILTIN_PCMPEQW,
28002   IX86_BUILTIN_PCMPEQD,
28003   IX86_BUILTIN_PCMPGTB,
28004   IX86_BUILTIN_PCMPGTW,
28005   IX86_BUILTIN_PCMPGTD,
28006
28007   IX86_BUILTIN_PMADDWD,
28008
28009   IX86_BUILTIN_PMAXSW,
28010   IX86_BUILTIN_PMAXUB,
28011   IX86_BUILTIN_PMINSW,
28012   IX86_BUILTIN_PMINUB,
28013
28014   IX86_BUILTIN_PMULHUW,
28015   IX86_BUILTIN_PMULHW,
28016   IX86_BUILTIN_PMULLW,
28017
28018   IX86_BUILTIN_PSADBW,
28019   IX86_BUILTIN_PSHUFW,
28020
28021   IX86_BUILTIN_PSLLW,
28022   IX86_BUILTIN_PSLLD,
28023   IX86_BUILTIN_PSLLQ,
28024   IX86_BUILTIN_PSRAW,
28025   IX86_BUILTIN_PSRAD,
28026   IX86_BUILTIN_PSRLW,
28027   IX86_BUILTIN_PSRLD,
28028   IX86_BUILTIN_PSRLQ,
28029   IX86_BUILTIN_PSLLWI,
28030   IX86_BUILTIN_PSLLDI,
28031   IX86_BUILTIN_PSLLQI,
28032   IX86_BUILTIN_PSRAWI,
28033   IX86_BUILTIN_PSRADI,
28034   IX86_BUILTIN_PSRLWI,
28035   IX86_BUILTIN_PSRLDI,
28036   IX86_BUILTIN_PSRLQI,
28037
28038   IX86_BUILTIN_PUNPCKHBW,
28039   IX86_BUILTIN_PUNPCKHWD,
28040   IX86_BUILTIN_PUNPCKHDQ,
28041   IX86_BUILTIN_PUNPCKLBW,
28042   IX86_BUILTIN_PUNPCKLWD,
28043   IX86_BUILTIN_PUNPCKLDQ,
28044
28045   IX86_BUILTIN_SHUFPS,
28046
28047   IX86_BUILTIN_RCPPS,
28048   IX86_BUILTIN_RCPSS,
28049   IX86_BUILTIN_RSQRTPS,
28050   IX86_BUILTIN_RSQRTPS_NR,
28051   IX86_BUILTIN_RSQRTSS,
28052   IX86_BUILTIN_RSQRTF,
28053   IX86_BUILTIN_SQRTPS,
28054   IX86_BUILTIN_SQRTPS_NR,
28055   IX86_BUILTIN_SQRTSS,
28056
28057   IX86_BUILTIN_UNPCKHPS,
28058   IX86_BUILTIN_UNPCKLPS,
28059
28060   IX86_BUILTIN_ANDPS,
28061   IX86_BUILTIN_ANDNPS,
28062   IX86_BUILTIN_ORPS,
28063   IX86_BUILTIN_XORPS,
28064
28065   IX86_BUILTIN_EMMS,
28066   IX86_BUILTIN_LDMXCSR,
28067   IX86_BUILTIN_STMXCSR,
28068   IX86_BUILTIN_SFENCE,
28069
28070   IX86_BUILTIN_FXSAVE,
28071   IX86_BUILTIN_FXRSTOR,
28072   IX86_BUILTIN_FXSAVE64,
28073   IX86_BUILTIN_FXRSTOR64,
28074
28075   IX86_BUILTIN_XSAVE,
28076   IX86_BUILTIN_XRSTOR,
28077   IX86_BUILTIN_XSAVE64,
28078   IX86_BUILTIN_XRSTOR64,
28079
28080   IX86_BUILTIN_XSAVEOPT,
28081   IX86_BUILTIN_XSAVEOPT64,
28082
28083   IX86_BUILTIN_XSAVEC,
28084   IX86_BUILTIN_XSAVEC64,
28085
28086   IX86_BUILTIN_XSAVES,
28087   IX86_BUILTIN_XRSTORS,
28088   IX86_BUILTIN_XSAVES64,
28089   IX86_BUILTIN_XRSTORS64,
28090
28091   /* 3DNow! Original */
28092   IX86_BUILTIN_FEMMS,
28093   IX86_BUILTIN_PAVGUSB,
28094   IX86_BUILTIN_PF2ID,
28095   IX86_BUILTIN_PFACC,
28096   IX86_BUILTIN_PFADD,
28097   IX86_BUILTIN_PFCMPEQ,
28098   IX86_BUILTIN_PFCMPGE,
28099   IX86_BUILTIN_PFCMPGT,
28100   IX86_BUILTIN_PFMAX,
28101   IX86_BUILTIN_PFMIN,
28102   IX86_BUILTIN_PFMUL,
28103   IX86_BUILTIN_PFRCP,
28104   IX86_BUILTIN_PFRCPIT1,
28105   IX86_BUILTIN_PFRCPIT2,
28106   IX86_BUILTIN_PFRSQIT1,
28107   IX86_BUILTIN_PFRSQRT,
28108   IX86_BUILTIN_PFSUB,
28109   IX86_BUILTIN_PFSUBR,
28110   IX86_BUILTIN_PI2FD,
28111   IX86_BUILTIN_PMULHRW,
28112
28113   /* 3DNow! Athlon Extensions */
28114   IX86_BUILTIN_PF2IW,
28115   IX86_BUILTIN_PFNACC,
28116   IX86_BUILTIN_PFPNACC,
28117   IX86_BUILTIN_PI2FW,
28118   IX86_BUILTIN_PSWAPDSI,
28119   IX86_BUILTIN_PSWAPDSF,
28120
28121   /* SSE2 */
28122   IX86_BUILTIN_ADDPD,
28123   IX86_BUILTIN_ADDSD,
28124   IX86_BUILTIN_DIVPD,
28125   IX86_BUILTIN_DIVSD,
28126   IX86_BUILTIN_MULPD,
28127   IX86_BUILTIN_MULSD,
28128   IX86_BUILTIN_SUBPD,
28129   IX86_BUILTIN_SUBSD,
28130
28131   IX86_BUILTIN_CMPEQPD,
28132   IX86_BUILTIN_CMPLTPD,
28133   IX86_BUILTIN_CMPLEPD,
28134   IX86_BUILTIN_CMPGTPD,
28135   IX86_BUILTIN_CMPGEPD,
28136   IX86_BUILTIN_CMPNEQPD,
28137   IX86_BUILTIN_CMPNLTPD,
28138   IX86_BUILTIN_CMPNLEPD,
28139   IX86_BUILTIN_CMPNGTPD,
28140   IX86_BUILTIN_CMPNGEPD,
28141   IX86_BUILTIN_CMPORDPD,
28142   IX86_BUILTIN_CMPUNORDPD,
28143   IX86_BUILTIN_CMPEQSD,
28144   IX86_BUILTIN_CMPLTSD,
28145   IX86_BUILTIN_CMPLESD,
28146   IX86_BUILTIN_CMPNEQSD,
28147   IX86_BUILTIN_CMPNLTSD,
28148   IX86_BUILTIN_CMPNLESD,
28149   IX86_BUILTIN_CMPORDSD,
28150   IX86_BUILTIN_CMPUNORDSD,
28151
28152   IX86_BUILTIN_COMIEQSD,
28153   IX86_BUILTIN_COMILTSD,
28154   IX86_BUILTIN_COMILESD,
28155   IX86_BUILTIN_COMIGTSD,
28156   IX86_BUILTIN_COMIGESD,
28157   IX86_BUILTIN_COMINEQSD,
28158   IX86_BUILTIN_UCOMIEQSD,
28159   IX86_BUILTIN_UCOMILTSD,
28160   IX86_BUILTIN_UCOMILESD,
28161   IX86_BUILTIN_UCOMIGTSD,
28162   IX86_BUILTIN_UCOMIGESD,
28163   IX86_BUILTIN_UCOMINEQSD,
28164
28165   IX86_BUILTIN_MAXPD,
28166   IX86_BUILTIN_MAXSD,
28167   IX86_BUILTIN_MINPD,
28168   IX86_BUILTIN_MINSD,
28169
28170   IX86_BUILTIN_ANDPD,
28171   IX86_BUILTIN_ANDNPD,
28172   IX86_BUILTIN_ORPD,
28173   IX86_BUILTIN_XORPD,
28174
28175   IX86_BUILTIN_SQRTPD,
28176   IX86_BUILTIN_SQRTSD,
28177
28178   IX86_BUILTIN_UNPCKHPD,
28179   IX86_BUILTIN_UNPCKLPD,
28180
28181   IX86_BUILTIN_SHUFPD,
28182
28183   IX86_BUILTIN_LOADUPD,
28184   IX86_BUILTIN_STOREUPD,
28185   IX86_BUILTIN_MOVSD,
28186
28187   IX86_BUILTIN_LOADHPD,
28188   IX86_BUILTIN_LOADLPD,
28189
28190   IX86_BUILTIN_CVTDQ2PD,
28191   IX86_BUILTIN_CVTDQ2PS,
28192
28193   IX86_BUILTIN_CVTPD2DQ,
28194   IX86_BUILTIN_CVTPD2PI,
28195   IX86_BUILTIN_CVTPD2PS,
28196   IX86_BUILTIN_CVTTPD2DQ,
28197   IX86_BUILTIN_CVTTPD2PI,
28198
28199   IX86_BUILTIN_CVTPI2PD,
28200   IX86_BUILTIN_CVTSI2SD,
28201   IX86_BUILTIN_CVTSI642SD,
28202
28203   IX86_BUILTIN_CVTSD2SI,
28204   IX86_BUILTIN_CVTSD2SI64,
28205   IX86_BUILTIN_CVTSD2SS,
28206   IX86_BUILTIN_CVTSS2SD,
28207   IX86_BUILTIN_CVTTSD2SI,
28208   IX86_BUILTIN_CVTTSD2SI64,
28209
28210   IX86_BUILTIN_CVTPS2DQ,
28211   IX86_BUILTIN_CVTPS2PD,
28212   IX86_BUILTIN_CVTTPS2DQ,
28213
28214   IX86_BUILTIN_MOVNTI,
28215   IX86_BUILTIN_MOVNTI64,
28216   IX86_BUILTIN_MOVNTPD,
28217   IX86_BUILTIN_MOVNTDQ,
28218
28219   IX86_BUILTIN_MOVQ128,
28220
28221   /* SSE2 MMX */
28222   IX86_BUILTIN_MASKMOVDQU,
28223   IX86_BUILTIN_MOVMSKPD,
28224   IX86_BUILTIN_PMOVMSKB128,
28225
28226   IX86_BUILTIN_PACKSSWB128,
28227   IX86_BUILTIN_PACKSSDW128,
28228   IX86_BUILTIN_PACKUSWB128,
28229
28230   IX86_BUILTIN_PADDB128,
28231   IX86_BUILTIN_PADDW128,
28232   IX86_BUILTIN_PADDD128,
28233   IX86_BUILTIN_PADDQ128,
28234   IX86_BUILTIN_PADDSB128,
28235   IX86_BUILTIN_PADDSW128,
28236   IX86_BUILTIN_PADDUSB128,
28237   IX86_BUILTIN_PADDUSW128,
28238   IX86_BUILTIN_PSUBB128,
28239   IX86_BUILTIN_PSUBW128,
28240   IX86_BUILTIN_PSUBD128,
28241   IX86_BUILTIN_PSUBQ128,
28242   IX86_BUILTIN_PSUBSB128,
28243   IX86_BUILTIN_PSUBSW128,
28244   IX86_BUILTIN_PSUBUSB128,
28245   IX86_BUILTIN_PSUBUSW128,
28246
28247   IX86_BUILTIN_PAND128,
28248   IX86_BUILTIN_PANDN128,
28249   IX86_BUILTIN_POR128,
28250   IX86_BUILTIN_PXOR128,
28251
28252   IX86_BUILTIN_PAVGB128,
28253   IX86_BUILTIN_PAVGW128,
28254
28255   IX86_BUILTIN_PCMPEQB128,
28256   IX86_BUILTIN_PCMPEQW128,
28257   IX86_BUILTIN_PCMPEQD128,
28258   IX86_BUILTIN_PCMPGTB128,
28259   IX86_BUILTIN_PCMPGTW128,
28260   IX86_BUILTIN_PCMPGTD128,
28261
28262   IX86_BUILTIN_PMADDWD128,
28263
28264   IX86_BUILTIN_PMAXSW128,
28265   IX86_BUILTIN_PMAXUB128,
28266   IX86_BUILTIN_PMINSW128,
28267   IX86_BUILTIN_PMINUB128,
28268
28269   IX86_BUILTIN_PMULUDQ,
28270   IX86_BUILTIN_PMULUDQ128,
28271   IX86_BUILTIN_PMULHUW128,
28272   IX86_BUILTIN_PMULHW128,
28273   IX86_BUILTIN_PMULLW128,
28274
28275   IX86_BUILTIN_PSADBW128,
28276   IX86_BUILTIN_PSHUFHW,
28277   IX86_BUILTIN_PSHUFLW,
28278   IX86_BUILTIN_PSHUFD,
28279
28280   IX86_BUILTIN_PSLLDQI128,
28281   IX86_BUILTIN_PSLLWI128,
28282   IX86_BUILTIN_PSLLDI128,
28283   IX86_BUILTIN_PSLLQI128,
28284   IX86_BUILTIN_PSRAWI128,
28285   IX86_BUILTIN_PSRADI128,
28286   IX86_BUILTIN_PSRLDQI128,
28287   IX86_BUILTIN_PSRLWI128,
28288   IX86_BUILTIN_PSRLDI128,
28289   IX86_BUILTIN_PSRLQI128,
28290
28291   IX86_BUILTIN_PSLLDQ128,
28292   IX86_BUILTIN_PSLLW128,
28293   IX86_BUILTIN_PSLLD128,
28294   IX86_BUILTIN_PSLLQ128,
28295   IX86_BUILTIN_PSRAW128,
28296   IX86_BUILTIN_PSRAD128,
28297   IX86_BUILTIN_PSRLW128,
28298   IX86_BUILTIN_PSRLD128,
28299   IX86_BUILTIN_PSRLQ128,
28300
28301   IX86_BUILTIN_PUNPCKHBW128,
28302   IX86_BUILTIN_PUNPCKHWD128,
28303   IX86_BUILTIN_PUNPCKHDQ128,
28304   IX86_BUILTIN_PUNPCKHQDQ128,
28305   IX86_BUILTIN_PUNPCKLBW128,
28306   IX86_BUILTIN_PUNPCKLWD128,
28307   IX86_BUILTIN_PUNPCKLDQ128,
28308   IX86_BUILTIN_PUNPCKLQDQ128,
28309
28310   IX86_BUILTIN_CLFLUSH,
28311   IX86_BUILTIN_MFENCE,
28312   IX86_BUILTIN_LFENCE,
28313   IX86_BUILTIN_PAUSE,
28314
28315   IX86_BUILTIN_FNSTENV,
28316   IX86_BUILTIN_FLDENV,
28317   IX86_BUILTIN_FNSTSW,
28318   IX86_BUILTIN_FNCLEX,
28319
28320   IX86_BUILTIN_BSRSI,
28321   IX86_BUILTIN_BSRDI,
28322   IX86_BUILTIN_RDPMC,
28323   IX86_BUILTIN_RDTSC,
28324   IX86_BUILTIN_RDTSCP,
28325   IX86_BUILTIN_ROLQI,
28326   IX86_BUILTIN_ROLHI,
28327   IX86_BUILTIN_RORQI,
28328   IX86_BUILTIN_RORHI,
28329
28330   /* SSE3.  */
28331   IX86_BUILTIN_ADDSUBPS,
28332   IX86_BUILTIN_HADDPS,
28333   IX86_BUILTIN_HSUBPS,
28334   IX86_BUILTIN_MOVSHDUP,
28335   IX86_BUILTIN_MOVSLDUP,
28336   IX86_BUILTIN_ADDSUBPD,
28337   IX86_BUILTIN_HADDPD,
28338   IX86_BUILTIN_HSUBPD,
28339   IX86_BUILTIN_LDDQU,
28340
28341   IX86_BUILTIN_MONITOR,
28342   IX86_BUILTIN_MWAIT,
28343
28344   /* SSSE3.  */
28345   IX86_BUILTIN_PHADDW,
28346   IX86_BUILTIN_PHADDD,
28347   IX86_BUILTIN_PHADDSW,
28348   IX86_BUILTIN_PHSUBW,
28349   IX86_BUILTIN_PHSUBD,
28350   IX86_BUILTIN_PHSUBSW,
28351   IX86_BUILTIN_PMADDUBSW,
28352   IX86_BUILTIN_PMULHRSW,
28353   IX86_BUILTIN_PSHUFB,
28354   IX86_BUILTIN_PSIGNB,
28355   IX86_BUILTIN_PSIGNW,
28356   IX86_BUILTIN_PSIGND,
28357   IX86_BUILTIN_PALIGNR,
28358   IX86_BUILTIN_PABSB,
28359   IX86_BUILTIN_PABSW,
28360   IX86_BUILTIN_PABSD,
28361
28362   IX86_BUILTIN_PHADDW128,
28363   IX86_BUILTIN_PHADDD128,
28364   IX86_BUILTIN_PHADDSW128,
28365   IX86_BUILTIN_PHSUBW128,
28366   IX86_BUILTIN_PHSUBD128,
28367   IX86_BUILTIN_PHSUBSW128,
28368   IX86_BUILTIN_PMADDUBSW128,
28369   IX86_BUILTIN_PMULHRSW128,
28370   IX86_BUILTIN_PSHUFB128,
28371   IX86_BUILTIN_PSIGNB128,
28372   IX86_BUILTIN_PSIGNW128,
28373   IX86_BUILTIN_PSIGND128,
28374   IX86_BUILTIN_PALIGNR128,
28375   IX86_BUILTIN_PABSB128,
28376   IX86_BUILTIN_PABSW128,
28377   IX86_BUILTIN_PABSD128,
28378
28379   /* AMDFAM10 - SSE4A New Instructions.  */
28380   IX86_BUILTIN_MOVNTSD,
28381   IX86_BUILTIN_MOVNTSS,
28382   IX86_BUILTIN_EXTRQI,
28383   IX86_BUILTIN_EXTRQ,
28384   IX86_BUILTIN_INSERTQI,
28385   IX86_BUILTIN_INSERTQ,
28386
28387   /* SSE4.1.  */
28388   IX86_BUILTIN_BLENDPD,
28389   IX86_BUILTIN_BLENDPS,
28390   IX86_BUILTIN_BLENDVPD,
28391   IX86_BUILTIN_BLENDVPS,
28392   IX86_BUILTIN_PBLENDVB128,
28393   IX86_BUILTIN_PBLENDW128,
28394
28395   IX86_BUILTIN_DPPD,
28396   IX86_BUILTIN_DPPS,
28397
28398   IX86_BUILTIN_INSERTPS128,
28399
28400   IX86_BUILTIN_MOVNTDQA,
28401   IX86_BUILTIN_MPSADBW128,
28402   IX86_BUILTIN_PACKUSDW128,
28403   IX86_BUILTIN_PCMPEQQ,
28404   IX86_BUILTIN_PHMINPOSUW128,
28405
28406   IX86_BUILTIN_PMAXSB128,
28407   IX86_BUILTIN_PMAXSD128,
28408   IX86_BUILTIN_PMAXUD128,
28409   IX86_BUILTIN_PMAXUW128,
28410
28411   IX86_BUILTIN_PMINSB128,
28412   IX86_BUILTIN_PMINSD128,
28413   IX86_BUILTIN_PMINUD128,
28414   IX86_BUILTIN_PMINUW128,
28415
28416   IX86_BUILTIN_PMOVSXBW128,
28417   IX86_BUILTIN_PMOVSXBD128,
28418   IX86_BUILTIN_PMOVSXBQ128,
28419   IX86_BUILTIN_PMOVSXWD128,
28420   IX86_BUILTIN_PMOVSXWQ128,
28421   IX86_BUILTIN_PMOVSXDQ128,
28422
28423   IX86_BUILTIN_PMOVZXBW128,
28424   IX86_BUILTIN_PMOVZXBD128,
28425   IX86_BUILTIN_PMOVZXBQ128,
28426   IX86_BUILTIN_PMOVZXWD128,
28427   IX86_BUILTIN_PMOVZXWQ128,
28428   IX86_BUILTIN_PMOVZXDQ128,
28429
28430   IX86_BUILTIN_PMULDQ128,
28431   IX86_BUILTIN_PMULLD128,
28432
28433   IX86_BUILTIN_ROUNDSD,
28434   IX86_BUILTIN_ROUNDSS,
28435
28436   IX86_BUILTIN_ROUNDPD,
28437   IX86_BUILTIN_ROUNDPS,
28438
28439   IX86_BUILTIN_FLOORPD,
28440   IX86_BUILTIN_CEILPD,
28441   IX86_BUILTIN_TRUNCPD,
28442   IX86_BUILTIN_RINTPD,
28443   IX86_BUILTIN_ROUNDPD_AZ,
28444
28445   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX,
28446   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX,
28447   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX,
28448
28449   IX86_BUILTIN_FLOORPS,
28450   IX86_BUILTIN_CEILPS,
28451   IX86_BUILTIN_TRUNCPS,
28452   IX86_BUILTIN_RINTPS,
28453   IX86_BUILTIN_ROUNDPS_AZ,
28454
28455   IX86_BUILTIN_FLOORPS_SFIX,
28456   IX86_BUILTIN_CEILPS_SFIX,
28457   IX86_BUILTIN_ROUNDPS_AZ_SFIX,
28458
28459   IX86_BUILTIN_PTESTZ,
28460   IX86_BUILTIN_PTESTC,
28461   IX86_BUILTIN_PTESTNZC,
28462
28463   IX86_BUILTIN_VEC_INIT_V2SI,
28464   IX86_BUILTIN_VEC_INIT_V4HI,
28465   IX86_BUILTIN_VEC_INIT_V8QI,
28466   IX86_BUILTIN_VEC_EXT_V2DF,
28467   IX86_BUILTIN_VEC_EXT_V2DI,
28468   IX86_BUILTIN_VEC_EXT_V4SF,
28469   IX86_BUILTIN_VEC_EXT_V4SI,
28470   IX86_BUILTIN_VEC_EXT_V8HI,
28471   IX86_BUILTIN_VEC_EXT_V2SI,
28472   IX86_BUILTIN_VEC_EXT_V4HI,
28473   IX86_BUILTIN_VEC_EXT_V16QI,
28474   IX86_BUILTIN_VEC_SET_V2DI,
28475   IX86_BUILTIN_VEC_SET_V4SF,
28476   IX86_BUILTIN_VEC_SET_V4SI,
28477   IX86_BUILTIN_VEC_SET_V8HI,
28478   IX86_BUILTIN_VEC_SET_V4HI,
28479   IX86_BUILTIN_VEC_SET_V16QI,
28480
28481   IX86_BUILTIN_VEC_PACK_SFIX,
28482   IX86_BUILTIN_VEC_PACK_SFIX256,
28483
28484   /* SSE4.2.  */
28485   IX86_BUILTIN_CRC32QI,
28486   IX86_BUILTIN_CRC32HI,
28487   IX86_BUILTIN_CRC32SI,
28488   IX86_BUILTIN_CRC32DI,
28489
28490   IX86_BUILTIN_PCMPESTRI128,
28491   IX86_BUILTIN_PCMPESTRM128,
28492   IX86_BUILTIN_PCMPESTRA128,
28493   IX86_BUILTIN_PCMPESTRC128,
28494   IX86_BUILTIN_PCMPESTRO128,
28495   IX86_BUILTIN_PCMPESTRS128,
28496   IX86_BUILTIN_PCMPESTRZ128,
28497   IX86_BUILTIN_PCMPISTRI128,
28498   IX86_BUILTIN_PCMPISTRM128,
28499   IX86_BUILTIN_PCMPISTRA128,
28500   IX86_BUILTIN_PCMPISTRC128,
28501   IX86_BUILTIN_PCMPISTRO128,
28502   IX86_BUILTIN_PCMPISTRS128,
28503   IX86_BUILTIN_PCMPISTRZ128,
28504
28505   IX86_BUILTIN_PCMPGTQ,
28506
28507   /* AES instructions */
28508   IX86_BUILTIN_AESENC128,
28509   IX86_BUILTIN_AESENCLAST128,
28510   IX86_BUILTIN_AESDEC128,
28511   IX86_BUILTIN_AESDECLAST128,
28512   IX86_BUILTIN_AESIMC128,
28513   IX86_BUILTIN_AESKEYGENASSIST128,
28514
28515   /* PCLMUL instruction */
28516   IX86_BUILTIN_PCLMULQDQ128,
28517
28518   /* AVX */
28519   IX86_BUILTIN_ADDPD256,
28520   IX86_BUILTIN_ADDPS256,
28521   IX86_BUILTIN_ADDSUBPD256,
28522   IX86_BUILTIN_ADDSUBPS256,
28523   IX86_BUILTIN_ANDPD256,
28524   IX86_BUILTIN_ANDPS256,
28525   IX86_BUILTIN_ANDNPD256,
28526   IX86_BUILTIN_ANDNPS256,
28527   IX86_BUILTIN_BLENDPD256,
28528   IX86_BUILTIN_BLENDPS256,
28529   IX86_BUILTIN_BLENDVPD256,
28530   IX86_BUILTIN_BLENDVPS256,
28531   IX86_BUILTIN_DIVPD256,
28532   IX86_BUILTIN_DIVPS256,
28533   IX86_BUILTIN_DPPS256,
28534   IX86_BUILTIN_HADDPD256,
28535   IX86_BUILTIN_HADDPS256,
28536   IX86_BUILTIN_HSUBPD256,
28537   IX86_BUILTIN_HSUBPS256,
28538   IX86_BUILTIN_MAXPD256,
28539   IX86_BUILTIN_MAXPS256,
28540   IX86_BUILTIN_MINPD256,
28541   IX86_BUILTIN_MINPS256,
28542   IX86_BUILTIN_MULPD256,
28543   IX86_BUILTIN_MULPS256,
28544   IX86_BUILTIN_ORPD256,
28545   IX86_BUILTIN_ORPS256,
28546   IX86_BUILTIN_SHUFPD256,
28547   IX86_BUILTIN_SHUFPS256,
28548   IX86_BUILTIN_SUBPD256,
28549   IX86_BUILTIN_SUBPS256,
28550   IX86_BUILTIN_XORPD256,
28551   IX86_BUILTIN_XORPS256,
28552   IX86_BUILTIN_CMPSD,
28553   IX86_BUILTIN_CMPSS,
28554   IX86_BUILTIN_CMPPD,
28555   IX86_BUILTIN_CMPPS,
28556   IX86_BUILTIN_CMPPD256,
28557   IX86_BUILTIN_CMPPS256,
28558   IX86_BUILTIN_CVTDQ2PD256,
28559   IX86_BUILTIN_CVTDQ2PS256,
28560   IX86_BUILTIN_CVTPD2PS256,
28561   IX86_BUILTIN_CVTPS2DQ256,
28562   IX86_BUILTIN_CVTPS2PD256,
28563   IX86_BUILTIN_CVTTPD2DQ256,
28564   IX86_BUILTIN_CVTPD2DQ256,
28565   IX86_BUILTIN_CVTTPS2DQ256,
28566   IX86_BUILTIN_EXTRACTF128PD256,
28567   IX86_BUILTIN_EXTRACTF128PS256,
28568   IX86_BUILTIN_EXTRACTF128SI256,
28569   IX86_BUILTIN_VZEROALL,
28570   IX86_BUILTIN_VZEROUPPER,
28571   IX86_BUILTIN_VPERMILVARPD,
28572   IX86_BUILTIN_VPERMILVARPS,
28573   IX86_BUILTIN_VPERMILVARPD256,
28574   IX86_BUILTIN_VPERMILVARPS256,
28575   IX86_BUILTIN_VPERMILPD,
28576   IX86_BUILTIN_VPERMILPS,
28577   IX86_BUILTIN_VPERMILPD256,
28578   IX86_BUILTIN_VPERMILPS256,
28579   IX86_BUILTIN_VPERMIL2PD,
28580   IX86_BUILTIN_VPERMIL2PS,
28581   IX86_BUILTIN_VPERMIL2PD256,
28582   IX86_BUILTIN_VPERMIL2PS256,
28583   IX86_BUILTIN_VPERM2F128PD256,
28584   IX86_BUILTIN_VPERM2F128PS256,
28585   IX86_BUILTIN_VPERM2F128SI256,
28586   IX86_BUILTIN_VBROADCASTSS,
28587   IX86_BUILTIN_VBROADCASTSD256,
28588   IX86_BUILTIN_VBROADCASTSS256,
28589   IX86_BUILTIN_VBROADCASTPD256,
28590   IX86_BUILTIN_VBROADCASTPS256,
28591   IX86_BUILTIN_VINSERTF128PD256,
28592   IX86_BUILTIN_VINSERTF128PS256,
28593   IX86_BUILTIN_VINSERTF128SI256,
28594   IX86_BUILTIN_LOADUPD256,
28595   IX86_BUILTIN_LOADUPS256,
28596   IX86_BUILTIN_STOREUPD256,
28597   IX86_BUILTIN_STOREUPS256,
28598   IX86_BUILTIN_LDDQU256,
28599   IX86_BUILTIN_MOVNTDQ256,
28600   IX86_BUILTIN_MOVNTPD256,
28601   IX86_BUILTIN_MOVNTPS256,
28602   IX86_BUILTIN_LOADDQU256,
28603   IX86_BUILTIN_STOREDQU256,
28604   IX86_BUILTIN_MASKLOADPD,
28605   IX86_BUILTIN_MASKLOADPS,
28606   IX86_BUILTIN_MASKSTOREPD,
28607   IX86_BUILTIN_MASKSTOREPS,
28608   IX86_BUILTIN_MASKLOADPD256,
28609   IX86_BUILTIN_MASKLOADPS256,
28610   IX86_BUILTIN_MASKSTOREPD256,
28611   IX86_BUILTIN_MASKSTOREPS256,
28612   IX86_BUILTIN_MOVSHDUP256,
28613   IX86_BUILTIN_MOVSLDUP256,
28614   IX86_BUILTIN_MOVDDUP256,
28615
28616   IX86_BUILTIN_SQRTPD256,
28617   IX86_BUILTIN_SQRTPS256,
28618   IX86_BUILTIN_SQRTPS_NR256,
28619   IX86_BUILTIN_RSQRTPS256,
28620   IX86_BUILTIN_RSQRTPS_NR256,
28621
28622   IX86_BUILTIN_RCPPS256,
28623
28624   IX86_BUILTIN_ROUNDPD256,
28625   IX86_BUILTIN_ROUNDPS256,
28626
28627   IX86_BUILTIN_FLOORPD256,
28628   IX86_BUILTIN_CEILPD256,
28629   IX86_BUILTIN_TRUNCPD256,
28630   IX86_BUILTIN_RINTPD256,
28631   IX86_BUILTIN_ROUNDPD_AZ256,
28632
28633   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256,
28634   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256,
28635   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256,
28636
28637   IX86_BUILTIN_FLOORPS256,
28638   IX86_BUILTIN_CEILPS256,
28639   IX86_BUILTIN_TRUNCPS256,
28640   IX86_BUILTIN_RINTPS256,
28641   IX86_BUILTIN_ROUNDPS_AZ256,
28642
28643   IX86_BUILTIN_FLOORPS_SFIX256,
28644   IX86_BUILTIN_CEILPS_SFIX256,
28645   IX86_BUILTIN_ROUNDPS_AZ_SFIX256,
28646
28647   IX86_BUILTIN_UNPCKHPD256,
28648   IX86_BUILTIN_UNPCKLPD256,
28649   IX86_BUILTIN_UNPCKHPS256,
28650   IX86_BUILTIN_UNPCKLPS256,
28651
28652   IX86_BUILTIN_SI256_SI,
28653   IX86_BUILTIN_PS256_PS,
28654   IX86_BUILTIN_PD256_PD,
28655   IX86_BUILTIN_SI_SI256,
28656   IX86_BUILTIN_PS_PS256,
28657   IX86_BUILTIN_PD_PD256,
28658
28659   IX86_BUILTIN_VTESTZPD,
28660   IX86_BUILTIN_VTESTCPD,
28661   IX86_BUILTIN_VTESTNZCPD,
28662   IX86_BUILTIN_VTESTZPS,
28663   IX86_BUILTIN_VTESTCPS,
28664   IX86_BUILTIN_VTESTNZCPS,
28665   IX86_BUILTIN_VTESTZPD256,
28666   IX86_BUILTIN_VTESTCPD256,
28667   IX86_BUILTIN_VTESTNZCPD256,
28668   IX86_BUILTIN_VTESTZPS256,
28669   IX86_BUILTIN_VTESTCPS256,
28670   IX86_BUILTIN_VTESTNZCPS256,
28671   IX86_BUILTIN_PTESTZ256,
28672   IX86_BUILTIN_PTESTC256,
28673   IX86_BUILTIN_PTESTNZC256,
28674
28675   IX86_BUILTIN_MOVMSKPD256,
28676   IX86_BUILTIN_MOVMSKPS256,
28677
28678   /* AVX2 */
28679   IX86_BUILTIN_MPSADBW256,
28680   IX86_BUILTIN_PABSB256,
28681   IX86_BUILTIN_PABSW256,
28682   IX86_BUILTIN_PABSD256,
28683   IX86_BUILTIN_PACKSSDW256,
28684   IX86_BUILTIN_PACKSSWB256,
28685   IX86_BUILTIN_PACKUSDW256,
28686   IX86_BUILTIN_PACKUSWB256,
28687   IX86_BUILTIN_PADDB256,
28688   IX86_BUILTIN_PADDW256,
28689   IX86_BUILTIN_PADDD256,
28690   IX86_BUILTIN_PADDQ256,
28691   IX86_BUILTIN_PADDSB256,
28692   IX86_BUILTIN_PADDSW256,
28693   IX86_BUILTIN_PADDUSB256,
28694   IX86_BUILTIN_PADDUSW256,
28695   IX86_BUILTIN_PALIGNR256,
28696   IX86_BUILTIN_AND256I,
28697   IX86_BUILTIN_ANDNOT256I,
28698   IX86_BUILTIN_PAVGB256,
28699   IX86_BUILTIN_PAVGW256,
28700   IX86_BUILTIN_PBLENDVB256,
28701   IX86_BUILTIN_PBLENDVW256,
28702   IX86_BUILTIN_PCMPEQB256,
28703   IX86_BUILTIN_PCMPEQW256,
28704   IX86_BUILTIN_PCMPEQD256,
28705   IX86_BUILTIN_PCMPEQQ256,
28706   IX86_BUILTIN_PCMPGTB256,
28707   IX86_BUILTIN_PCMPGTW256,
28708   IX86_BUILTIN_PCMPGTD256,
28709   IX86_BUILTIN_PCMPGTQ256,
28710   IX86_BUILTIN_PHADDW256,
28711   IX86_BUILTIN_PHADDD256,
28712   IX86_BUILTIN_PHADDSW256,
28713   IX86_BUILTIN_PHSUBW256,
28714   IX86_BUILTIN_PHSUBD256,
28715   IX86_BUILTIN_PHSUBSW256,
28716   IX86_BUILTIN_PMADDUBSW256,
28717   IX86_BUILTIN_PMADDWD256,
28718   IX86_BUILTIN_PMAXSB256,
28719   IX86_BUILTIN_PMAXSW256,
28720   IX86_BUILTIN_PMAXSD256,
28721   IX86_BUILTIN_PMAXUB256,
28722   IX86_BUILTIN_PMAXUW256,
28723   IX86_BUILTIN_PMAXUD256,
28724   IX86_BUILTIN_PMINSB256,
28725   IX86_BUILTIN_PMINSW256,
28726   IX86_BUILTIN_PMINSD256,
28727   IX86_BUILTIN_PMINUB256,
28728   IX86_BUILTIN_PMINUW256,
28729   IX86_BUILTIN_PMINUD256,
28730   IX86_BUILTIN_PMOVMSKB256,
28731   IX86_BUILTIN_PMOVSXBW256,
28732   IX86_BUILTIN_PMOVSXBD256,
28733   IX86_BUILTIN_PMOVSXBQ256,
28734   IX86_BUILTIN_PMOVSXWD256,
28735   IX86_BUILTIN_PMOVSXWQ256,
28736   IX86_BUILTIN_PMOVSXDQ256,
28737   IX86_BUILTIN_PMOVZXBW256,
28738   IX86_BUILTIN_PMOVZXBD256,
28739   IX86_BUILTIN_PMOVZXBQ256,
28740   IX86_BUILTIN_PMOVZXWD256,
28741   IX86_BUILTIN_PMOVZXWQ256,
28742   IX86_BUILTIN_PMOVZXDQ256,
28743   IX86_BUILTIN_PMULDQ256,
28744   IX86_BUILTIN_PMULHRSW256,
28745   IX86_BUILTIN_PMULHUW256,
28746   IX86_BUILTIN_PMULHW256,
28747   IX86_BUILTIN_PMULLW256,
28748   IX86_BUILTIN_PMULLD256,
28749   IX86_BUILTIN_PMULUDQ256,
28750   IX86_BUILTIN_POR256,
28751   IX86_BUILTIN_PSADBW256,
28752   IX86_BUILTIN_PSHUFB256,
28753   IX86_BUILTIN_PSHUFD256,
28754   IX86_BUILTIN_PSHUFHW256,
28755   IX86_BUILTIN_PSHUFLW256,
28756   IX86_BUILTIN_PSIGNB256,
28757   IX86_BUILTIN_PSIGNW256,
28758   IX86_BUILTIN_PSIGND256,
28759   IX86_BUILTIN_PSLLDQI256,
28760   IX86_BUILTIN_PSLLWI256,
28761   IX86_BUILTIN_PSLLW256,
28762   IX86_BUILTIN_PSLLDI256,
28763   IX86_BUILTIN_PSLLD256,
28764   IX86_BUILTIN_PSLLQI256,
28765   IX86_BUILTIN_PSLLQ256,
28766   IX86_BUILTIN_PSRAWI256,
28767   IX86_BUILTIN_PSRAW256,
28768   IX86_BUILTIN_PSRADI256,
28769   IX86_BUILTIN_PSRAD256,
28770   IX86_BUILTIN_PSRLDQI256,
28771   IX86_BUILTIN_PSRLWI256,
28772   IX86_BUILTIN_PSRLW256,
28773   IX86_BUILTIN_PSRLDI256,
28774   IX86_BUILTIN_PSRLD256,
28775   IX86_BUILTIN_PSRLQI256,
28776   IX86_BUILTIN_PSRLQ256,
28777   IX86_BUILTIN_PSUBB256,
28778   IX86_BUILTIN_PSUBW256,
28779   IX86_BUILTIN_PSUBD256,
28780   IX86_BUILTIN_PSUBQ256,
28781   IX86_BUILTIN_PSUBSB256,
28782   IX86_BUILTIN_PSUBSW256,
28783   IX86_BUILTIN_PSUBUSB256,
28784   IX86_BUILTIN_PSUBUSW256,
28785   IX86_BUILTIN_PUNPCKHBW256,
28786   IX86_BUILTIN_PUNPCKHWD256,
28787   IX86_BUILTIN_PUNPCKHDQ256,
28788   IX86_BUILTIN_PUNPCKHQDQ256,
28789   IX86_BUILTIN_PUNPCKLBW256,
28790   IX86_BUILTIN_PUNPCKLWD256,
28791   IX86_BUILTIN_PUNPCKLDQ256,
28792   IX86_BUILTIN_PUNPCKLQDQ256,
28793   IX86_BUILTIN_PXOR256,
28794   IX86_BUILTIN_MOVNTDQA256,
28795   IX86_BUILTIN_VBROADCASTSS_PS,
28796   IX86_BUILTIN_VBROADCASTSS_PS256,
28797   IX86_BUILTIN_VBROADCASTSD_PD256,
28798   IX86_BUILTIN_VBROADCASTSI256,
28799   IX86_BUILTIN_PBLENDD256,
28800   IX86_BUILTIN_PBLENDD128,
28801   IX86_BUILTIN_PBROADCASTB256,
28802   IX86_BUILTIN_PBROADCASTW256,
28803   IX86_BUILTIN_PBROADCASTD256,
28804   IX86_BUILTIN_PBROADCASTQ256,
28805   IX86_BUILTIN_PBROADCASTB128,
28806   IX86_BUILTIN_PBROADCASTW128,
28807   IX86_BUILTIN_PBROADCASTD128,
28808   IX86_BUILTIN_PBROADCASTQ128,
28809   IX86_BUILTIN_VPERMVARSI256,
28810   IX86_BUILTIN_VPERMDF256,
28811   IX86_BUILTIN_VPERMVARSF256,
28812   IX86_BUILTIN_VPERMDI256,
28813   IX86_BUILTIN_VPERMTI256,
28814   IX86_BUILTIN_VEXTRACT128I256,
28815   IX86_BUILTIN_VINSERT128I256,
28816   IX86_BUILTIN_MASKLOADD,
28817   IX86_BUILTIN_MASKLOADQ,
28818   IX86_BUILTIN_MASKLOADD256,
28819   IX86_BUILTIN_MASKLOADQ256,
28820   IX86_BUILTIN_MASKSTORED,
28821   IX86_BUILTIN_MASKSTOREQ,
28822   IX86_BUILTIN_MASKSTORED256,
28823   IX86_BUILTIN_MASKSTOREQ256,
28824   IX86_BUILTIN_PSLLVV4DI,
28825   IX86_BUILTIN_PSLLVV2DI,
28826   IX86_BUILTIN_PSLLVV8SI,
28827   IX86_BUILTIN_PSLLVV4SI,
28828   IX86_BUILTIN_PSRAVV8SI,
28829   IX86_BUILTIN_PSRAVV4SI,
28830   IX86_BUILTIN_PSRLVV4DI,
28831   IX86_BUILTIN_PSRLVV2DI,
28832   IX86_BUILTIN_PSRLVV8SI,
28833   IX86_BUILTIN_PSRLVV4SI,
28834
28835   IX86_BUILTIN_GATHERSIV2DF,
28836   IX86_BUILTIN_GATHERSIV4DF,
28837   IX86_BUILTIN_GATHERDIV2DF,
28838   IX86_BUILTIN_GATHERDIV4DF,
28839   IX86_BUILTIN_GATHERSIV4SF,
28840   IX86_BUILTIN_GATHERSIV8SF,
28841   IX86_BUILTIN_GATHERDIV4SF,
28842   IX86_BUILTIN_GATHERDIV8SF,
28843   IX86_BUILTIN_GATHERSIV2DI,
28844   IX86_BUILTIN_GATHERSIV4DI,
28845   IX86_BUILTIN_GATHERDIV2DI,
28846   IX86_BUILTIN_GATHERDIV4DI,
28847   IX86_BUILTIN_GATHERSIV4SI,
28848   IX86_BUILTIN_GATHERSIV8SI,
28849   IX86_BUILTIN_GATHERDIV4SI,
28850   IX86_BUILTIN_GATHERDIV8SI,
28851
28852   /* AVX512F */
28853   IX86_BUILTIN_SI512_SI256,
28854   IX86_BUILTIN_PD512_PD256,
28855   IX86_BUILTIN_PS512_PS256,
28856   IX86_BUILTIN_SI512_SI,
28857   IX86_BUILTIN_PD512_PD,
28858   IX86_BUILTIN_PS512_PS,
28859   IX86_BUILTIN_ADDPD512,
28860   IX86_BUILTIN_ADDPS512,
28861   IX86_BUILTIN_ADDSD_ROUND,
28862   IX86_BUILTIN_ADDSS_ROUND,
28863   IX86_BUILTIN_ALIGND512,
28864   IX86_BUILTIN_ALIGNQ512,
28865   IX86_BUILTIN_BLENDMD512,
28866   IX86_BUILTIN_BLENDMPD512,
28867   IX86_BUILTIN_BLENDMPS512,
28868   IX86_BUILTIN_BLENDMQ512,
28869   IX86_BUILTIN_BROADCASTF32X4_512,
28870   IX86_BUILTIN_BROADCASTF64X4_512,
28871   IX86_BUILTIN_BROADCASTI32X4_512,
28872   IX86_BUILTIN_BROADCASTI64X4_512,
28873   IX86_BUILTIN_BROADCASTSD512,
28874   IX86_BUILTIN_BROADCASTSS512,
28875   IX86_BUILTIN_CMPD512,
28876   IX86_BUILTIN_CMPPD512,
28877   IX86_BUILTIN_CMPPS512,
28878   IX86_BUILTIN_CMPQ512,
28879   IX86_BUILTIN_CMPSD_MASK,
28880   IX86_BUILTIN_CMPSS_MASK,
28881   IX86_BUILTIN_COMIDF,
28882   IX86_BUILTIN_COMISF,
28883   IX86_BUILTIN_COMPRESSPD512,
28884   IX86_BUILTIN_COMPRESSPDSTORE512,
28885   IX86_BUILTIN_COMPRESSPS512,
28886   IX86_BUILTIN_COMPRESSPSSTORE512,
28887   IX86_BUILTIN_CVTDQ2PD512,
28888   IX86_BUILTIN_CVTDQ2PS512,
28889   IX86_BUILTIN_CVTPD2DQ512,
28890   IX86_BUILTIN_CVTPD2PS512,
28891   IX86_BUILTIN_CVTPD2UDQ512,
28892   IX86_BUILTIN_CVTPH2PS512,
28893   IX86_BUILTIN_CVTPS2DQ512,
28894   IX86_BUILTIN_CVTPS2PD512,
28895   IX86_BUILTIN_CVTPS2PH512,
28896   IX86_BUILTIN_CVTPS2UDQ512,
28897   IX86_BUILTIN_CVTSD2SS_ROUND,
28898   IX86_BUILTIN_CVTSI2SD64,
28899   IX86_BUILTIN_CVTSI2SS32,
28900   IX86_BUILTIN_CVTSI2SS64,
28901   IX86_BUILTIN_CVTSS2SD_ROUND,
28902   IX86_BUILTIN_CVTTPD2DQ512,
28903   IX86_BUILTIN_CVTTPD2UDQ512,
28904   IX86_BUILTIN_CVTTPS2DQ512,
28905   IX86_BUILTIN_CVTTPS2UDQ512,
28906   IX86_BUILTIN_CVTUDQ2PD512,
28907   IX86_BUILTIN_CVTUDQ2PS512,
28908   IX86_BUILTIN_CVTUSI2SD32,
28909   IX86_BUILTIN_CVTUSI2SD64,
28910   IX86_BUILTIN_CVTUSI2SS32,
28911   IX86_BUILTIN_CVTUSI2SS64,
28912   IX86_BUILTIN_DIVPD512,
28913   IX86_BUILTIN_DIVPS512,
28914   IX86_BUILTIN_DIVSD_ROUND,
28915   IX86_BUILTIN_DIVSS_ROUND,
28916   IX86_BUILTIN_EXPANDPD512,
28917   IX86_BUILTIN_EXPANDPD512Z,
28918   IX86_BUILTIN_EXPANDPDLOAD512,
28919   IX86_BUILTIN_EXPANDPDLOAD512Z,
28920   IX86_BUILTIN_EXPANDPS512,
28921   IX86_BUILTIN_EXPANDPS512Z,
28922   IX86_BUILTIN_EXPANDPSLOAD512,
28923   IX86_BUILTIN_EXPANDPSLOAD512Z,
28924   IX86_BUILTIN_EXTRACTF32X4,
28925   IX86_BUILTIN_EXTRACTF64X4,
28926   IX86_BUILTIN_EXTRACTI32X4,
28927   IX86_BUILTIN_EXTRACTI64X4,
28928   IX86_BUILTIN_FIXUPIMMPD512_MASK,
28929   IX86_BUILTIN_FIXUPIMMPD512_MASKZ,
28930   IX86_BUILTIN_FIXUPIMMPS512_MASK,
28931   IX86_BUILTIN_FIXUPIMMPS512_MASKZ,
28932   IX86_BUILTIN_FIXUPIMMSD128_MASK,
28933   IX86_BUILTIN_FIXUPIMMSD128_MASKZ,
28934   IX86_BUILTIN_FIXUPIMMSS128_MASK,
28935   IX86_BUILTIN_FIXUPIMMSS128_MASKZ,
28936   IX86_BUILTIN_GETEXPPD512,
28937   IX86_BUILTIN_GETEXPPS512,
28938   IX86_BUILTIN_GETEXPSD128,
28939   IX86_BUILTIN_GETEXPSS128,
28940   IX86_BUILTIN_GETMANTPD512,
28941   IX86_BUILTIN_GETMANTPS512,
28942   IX86_BUILTIN_GETMANTSD128,
28943   IX86_BUILTIN_GETMANTSS128,
28944   IX86_BUILTIN_INSERTF32X4,
28945   IX86_BUILTIN_INSERTF64X4,
28946   IX86_BUILTIN_INSERTI32X4,
28947   IX86_BUILTIN_INSERTI64X4,
28948   IX86_BUILTIN_LOADAPD512,
28949   IX86_BUILTIN_LOADAPS512,
28950   IX86_BUILTIN_LOADDQUDI512,
28951   IX86_BUILTIN_LOADDQUSI512,
28952   IX86_BUILTIN_LOADUPD512,
28953   IX86_BUILTIN_LOADUPS512,
28954   IX86_BUILTIN_MAXPD512,
28955   IX86_BUILTIN_MAXPS512,
28956   IX86_BUILTIN_MAXSD_ROUND,
28957   IX86_BUILTIN_MAXSS_ROUND,
28958   IX86_BUILTIN_MINPD512,
28959   IX86_BUILTIN_MINPS512,
28960   IX86_BUILTIN_MINSD_ROUND,
28961   IX86_BUILTIN_MINSS_ROUND,
28962   IX86_BUILTIN_MOVAPD512,
28963   IX86_BUILTIN_MOVAPS512,
28964   IX86_BUILTIN_MOVDDUP512,
28965   IX86_BUILTIN_MOVDQA32LOAD512,
28966   IX86_BUILTIN_MOVDQA32STORE512,
28967   IX86_BUILTIN_MOVDQA32_512,
28968   IX86_BUILTIN_MOVDQA64LOAD512,
28969   IX86_BUILTIN_MOVDQA64STORE512,
28970   IX86_BUILTIN_MOVDQA64_512,
28971   IX86_BUILTIN_MOVNTDQ512,
28972   IX86_BUILTIN_MOVNTDQA512,
28973   IX86_BUILTIN_MOVNTPD512,
28974   IX86_BUILTIN_MOVNTPS512,
28975   IX86_BUILTIN_MOVSHDUP512,
28976   IX86_BUILTIN_MOVSLDUP512,
28977   IX86_BUILTIN_MULPD512,
28978   IX86_BUILTIN_MULPS512,
28979   IX86_BUILTIN_MULSD_ROUND,
28980   IX86_BUILTIN_MULSS_ROUND,
28981   IX86_BUILTIN_PABSD512,
28982   IX86_BUILTIN_PABSQ512,
28983   IX86_BUILTIN_PADDD512,
28984   IX86_BUILTIN_PADDQ512,
28985   IX86_BUILTIN_PANDD512,
28986   IX86_BUILTIN_PANDND512,
28987   IX86_BUILTIN_PANDNQ512,
28988   IX86_BUILTIN_PANDQ512,
28989   IX86_BUILTIN_PBROADCASTD512,
28990   IX86_BUILTIN_PBROADCASTD512_GPR,
28991   IX86_BUILTIN_PBROADCASTMB512,
28992   IX86_BUILTIN_PBROADCASTMW512,
28993   IX86_BUILTIN_PBROADCASTQ512,
28994   IX86_BUILTIN_PBROADCASTQ512_GPR,
28995   IX86_BUILTIN_PCMPEQD512_MASK,
28996   IX86_BUILTIN_PCMPEQQ512_MASK,
28997   IX86_BUILTIN_PCMPGTD512_MASK,
28998   IX86_BUILTIN_PCMPGTQ512_MASK,
28999   IX86_BUILTIN_PCOMPRESSD512,
29000   IX86_BUILTIN_PCOMPRESSDSTORE512,
29001   IX86_BUILTIN_PCOMPRESSQ512,
29002   IX86_BUILTIN_PCOMPRESSQSTORE512,
29003   IX86_BUILTIN_PEXPANDD512,
29004   IX86_BUILTIN_PEXPANDD512Z,
29005   IX86_BUILTIN_PEXPANDDLOAD512,
29006   IX86_BUILTIN_PEXPANDDLOAD512Z,
29007   IX86_BUILTIN_PEXPANDQ512,
29008   IX86_BUILTIN_PEXPANDQ512Z,
29009   IX86_BUILTIN_PEXPANDQLOAD512,
29010   IX86_BUILTIN_PEXPANDQLOAD512Z,
29011   IX86_BUILTIN_PMAXSD512,
29012   IX86_BUILTIN_PMAXSQ512,
29013   IX86_BUILTIN_PMAXUD512,
29014   IX86_BUILTIN_PMAXUQ512,
29015   IX86_BUILTIN_PMINSD512,
29016   IX86_BUILTIN_PMINSQ512,
29017   IX86_BUILTIN_PMINUD512,
29018   IX86_BUILTIN_PMINUQ512,
29019   IX86_BUILTIN_PMOVDB512,
29020   IX86_BUILTIN_PMOVDB512_MEM,
29021   IX86_BUILTIN_PMOVDW512,
29022   IX86_BUILTIN_PMOVDW512_MEM,
29023   IX86_BUILTIN_PMOVQB512,
29024   IX86_BUILTIN_PMOVQB512_MEM,
29025   IX86_BUILTIN_PMOVQD512,
29026   IX86_BUILTIN_PMOVQD512_MEM,
29027   IX86_BUILTIN_PMOVQW512,
29028   IX86_BUILTIN_PMOVQW512_MEM,
29029   IX86_BUILTIN_PMOVSDB512,
29030   IX86_BUILTIN_PMOVSDB512_MEM,
29031   IX86_BUILTIN_PMOVSDW512,
29032   IX86_BUILTIN_PMOVSDW512_MEM,
29033   IX86_BUILTIN_PMOVSQB512,
29034   IX86_BUILTIN_PMOVSQB512_MEM,
29035   IX86_BUILTIN_PMOVSQD512,
29036   IX86_BUILTIN_PMOVSQD512_MEM,
29037   IX86_BUILTIN_PMOVSQW512,
29038   IX86_BUILTIN_PMOVSQW512_MEM,
29039   IX86_BUILTIN_PMOVSXBD512,
29040   IX86_BUILTIN_PMOVSXBQ512,
29041   IX86_BUILTIN_PMOVSXDQ512,
29042   IX86_BUILTIN_PMOVSXWD512,
29043   IX86_BUILTIN_PMOVSXWQ512,
29044   IX86_BUILTIN_PMOVUSDB512,
29045   IX86_BUILTIN_PMOVUSDB512_MEM,
29046   IX86_BUILTIN_PMOVUSDW512,
29047   IX86_BUILTIN_PMOVUSDW512_MEM,
29048   IX86_BUILTIN_PMOVUSQB512,
29049   IX86_BUILTIN_PMOVUSQB512_MEM,
29050   IX86_BUILTIN_PMOVUSQD512,
29051   IX86_BUILTIN_PMOVUSQD512_MEM,
29052   IX86_BUILTIN_PMOVUSQW512,
29053   IX86_BUILTIN_PMOVUSQW512_MEM,
29054   IX86_BUILTIN_PMOVZXBD512,
29055   IX86_BUILTIN_PMOVZXBQ512,
29056   IX86_BUILTIN_PMOVZXDQ512,
29057   IX86_BUILTIN_PMOVZXWD512,
29058   IX86_BUILTIN_PMOVZXWQ512,
29059   IX86_BUILTIN_PMULDQ512,
29060   IX86_BUILTIN_PMULLD512,
29061   IX86_BUILTIN_PMULUDQ512,
29062   IX86_BUILTIN_PORD512,
29063   IX86_BUILTIN_PORQ512,
29064   IX86_BUILTIN_PROLD512,
29065   IX86_BUILTIN_PROLQ512,
29066   IX86_BUILTIN_PROLVD512,
29067   IX86_BUILTIN_PROLVQ512,
29068   IX86_BUILTIN_PRORD512,
29069   IX86_BUILTIN_PRORQ512,
29070   IX86_BUILTIN_PRORVD512,
29071   IX86_BUILTIN_PRORVQ512,
29072   IX86_BUILTIN_PSHUFD512,
29073   IX86_BUILTIN_PSLLD512,
29074   IX86_BUILTIN_PSLLDI512,
29075   IX86_BUILTIN_PSLLQ512,
29076   IX86_BUILTIN_PSLLQI512,
29077   IX86_BUILTIN_PSLLVV16SI,
29078   IX86_BUILTIN_PSLLVV8DI,
29079   IX86_BUILTIN_PSRAD512,
29080   IX86_BUILTIN_PSRADI512,
29081   IX86_BUILTIN_PSRAQ512,
29082   IX86_BUILTIN_PSRAQI512,
29083   IX86_BUILTIN_PSRAVV16SI,
29084   IX86_BUILTIN_PSRAVV8DI,
29085   IX86_BUILTIN_PSRLD512,
29086   IX86_BUILTIN_PSRLDI512,
29087   IX86_BUILTIN_PSRLQ512,
29088   IX86_BUILTIN_PSRLQI512,
29089   IX86_BUILTIN_PSRLVV16SI,
29090   IX86_BUILTIN_PSRLVV8DI,
29091   IX86_BUILTIN_PSUBD512,
29092   IX86_BUILTIN_PSUBQ512,
29093   IX86_BUILTIN_PTESTMD512,
29094   IX86_BUILTIN_PTESTMQ512,
29095   IX86_BUILTIN_PTESTNMD512,
29096   IX86_BUILTIN_PTESTNMQ512,
29097   IX86_BUILTIN_PUNPCKHDQ512,
29098   IX86_BUILTIN_PUNPCKHQDQ512,
29099   IX86_BUILTIN_PUNPCKLDQ512,
29100   IX86_BUILTIN_PUNPCKLQDQ512,
29101   IX86_BUILTIN_PXORD512,
29102   IX86_BUILTIN_PXORQ512,
29103   IX86_BUILTIN_RCP14PD512,
29104   IX86_BUILTIN_RCP14PS512,
29105   IX86_BUILTIN_RCP14SD,
29106   IX86_BUILTIN_RCP14SS,
29107   IX86_BUILTIN_RNDSCALEPD,
29108   IX86_BUILTIN_RNDSCALEPS,
29109   IX86_BUILTIN_RNDSCALESD,
29110   IX86_BUILTIN_RNDSCALESS,
29111   IX86_BUILTIN_RSQRT14PD512,
29112   IX86_BUILTIN_RSQRT14PS512,
29113   IX86_BUILTIN_RSQRT14SD,
29114   IX86_BUILTIN_RSQRT14SS,
29115   IX86_BUILTIN_SCALEFPD512,
29116   IX86_BUILTIN_SCALEFPS512,
29117   IX86_BUILTIN_SCALEFSD,
29118   IX86_BUILTIN_SCALEFSS,
29119   IX86_BUILTIN_SHUFPD512,
29120   IX86_BUILTIN_SHUFPS512,
29121   IX86_BUILTIN_SHUF_F32x4,
29122   IX86_BUILTIN_SHUF_F64x2,
29123   IX86_BUILTIN_SHUF_I32x4,
29124   IX86_BUILTIN_SHUF_I64x2,
29125   IX86_BUILTIN_SQRTPD512,
29126   IX86_BUILTIN_SQRTPD512_MASK,
29127   IX86_BUILTIN_SQRTPS512_MASK,
29128   IX86_BUILTIN_SQRTPS_NR512,
29129   IX86_BUILTIN_SQRTSD_ROUND,
29130   IX86_BUILTIN_SQRTSS_ROUND,
29131   IX86_BUILTIN_STOREAPD512,
29132   IX86_BUILTIN_STOREAPS512,
29133   IX86_BUILTIN_STOREDQUDI512,
29134   IX86_BUILTIN_STOREDQUSI512,
29135   IX86_BUILTIN_STOREUPD512,
29136   IX86_BUILTIN_STOREUPS512,
29137   IX86_BUILTIN_SUBPD512,
29138   IX86_BUILTIN_SUBPS512,
29139   IX86_BUILTIN_SUBSD_ROUND,
29140   IX86_BUILTIN_SUBSS_ROUND,
29141   IX86_BUILTIN_UCMPD512,
29142   IX86_BUILTIN_UCMPQ512,
29143   IX86_BUILTIN_UNPCKHPD512,
29144   IX86_BUILTIN_UNPCKHPS512,
29145   IX86_BUILTIN_UNPCKLPD512,
29146   IX86_BUILTIN_UNPCKLPS512,
29147   IX86_BUILTIN_VCVTSD2SI32,
29148   IX86_BUILTIN_VCVTSD2SI64,
29149   IX86_BUILTIN_VCVTSD2USI32,
29150   IX86_BUILTIN_VCVTSD2USI64,
29151   IX86_BUILTIN_VCVTSS2SI32,
29152   IX86_BUILTIN_VCVTSS2SI64,
29153   IX86_BUILTIN_VCVTSS2USI32,
29154   IX86_BUILTIN_VCVTSS2USI64,
29155   IX86_BUILTIN_VCVTTSD2SI32,
29156   IX86_BUILTIN_VCVTTSD2SI64,
29157   IX86_BUILTIN_VCVTTSD2USI32,
29158   IX86_BUILTIN_VCVTTSD2USI64,
29159   IX86_BUILTIN_VCVTTSS2SI32,
29160   IX86_BUILTIN_VCVTTSS2SI64,
29161   IX86_BUILTIN_VCVTTSS2USI32,
29162   IX86_BUILTIN_VCVTTSS2USI64,
29163   IX86_BUILTIN_VFMADDPD512_MASK,
29164   IX86_BUILTIN_VFMADDPD512_MASK3,
29165   IX86_BUILTIN_VFMADDPD512_MASKZ,
29166   IX86_BUILTIN_VFMADDPS512_MASK,
29167   IX86_BUILTIN_VFMADDPS512_MASK3,
29168   IX86_BUILTIN_VFMADDPS512_MASKZ,
29169   IX86_BUILTIN_VFMADDSD3_ROUND,
29170   IX86_BUILTIN_VFMADDSS3_ROUND,
29171   IX86_BUILTIN_VFMADDSUBPD512_MASK,
29172   IX86_BUILTIN_VFMADDSUBPD512_MASK3,
29173   IX86_BUILTIN_VFMADDSUBPD512_MASKZ,
29174   IX86_BUILTIN_VFMADDSUBPS512_MASK,
29175   IX86_BUILTIN_VFMADDSUBPS512_MASK3,
29176   IX86_BUILTIN_VFMADDSUBPS512_MASKZ,
29177   IX86_BUILTIN_VFMSUBADDPD512_MASK3,
29178   IX86_BUILTIN_VFMSUBADDPS512_MASK3,
29179   IX86_BUILTIN_VFMSUBPD512_MASK3,
29180   IX86_BUILTIN_VFMSUBPS512_MASK3,
29181   IX86_BUILTIN_VFMSUBSD3_MASK3,
29182   IX86_BUILTIN_VFMSUBSS3_MASK3,
29183   IX86_BUILTIN_VFNMADDPD512_MASK,
29184   IX86_BUILTIN_VFNMADDPS512_MASK,
29185   IX86_BUILTIN_VFNMSUBPD512_MASK,
29186   IX86_BUILTIN_VFNMSUBPD512_MASK3,
29187   IX86_BUILTIN_VFNMSUBPS512_MASK,
29188   IX86_BUILTIN_VFNMSUBPS512_MASK3,
29189   IX86_BUILTIN_VPCLZCNTD512,
29190   IX86_BUILTIN_VPCLZCNTQ512,
29191   IX86_BUILTIN_VPCONFLICTD512,
29192   IX86_BUILTIN_VPCONFLICTQ512,
29193   IX86_BUILTIN_VPERMDF512,
29194   IX86_BUILTIN_VPERMDI512,
29195   IX86_BUILTIN_VPERMI2VARD512,
29196   IX86_BUILTIN_VPERMI2VARPD512,
29197   IX86_BUILTIN_VPERMI2VARPS512,
29198   IX86_BUILTIN_VPERMI2VARQ512,
29199   IX86_BUILTIN_VPERMILPD512,
29200   IX86_BUILTIN_VPERMILPS512,
29201   IX86_BUILTIN_VPERMILVARPD512,
29202   IX86_BUILTIN_VPERMILVARPS512,
29203   IX86_BUILTIN_VPERMT2VARD512,
29204   IX86_BUILTIN_VPERMT2VARD512_MASKZ,
29205   IX86_BUILTIN_VPERMT2VARPD512,
29206   IX86_BUILTIN_VPERMT2VARPD512_MASKZ,
29207   IX86_BUILTIN_VPERMT2VARPS512,
29208   IX86_BUILTIN_VPERMT2VARPS512_MASKZ,
29209   IX86_BUILTIN_VPERMT2VARQ512,
29210   IX86_BUILTIN_VPERMT2VARQ512_MASKZ,
29211   IX86_BUILTIN_VPERMVARDF512,
29212   IX86_BUILTIN_VPERMVARDI512,
29213   IX86_BUILTIN_VPERMVARSF512,
29214   IX86_BUILTIN_VPERMVARSI512,
29215   IX86_BUILTIN_VTERNLOGD512_MASK,
29216   IX86_BUILTIN_VTERNLOGD512_MASKZ,
29217   IX86_BUILTIN_VTERNLOGQ512_MASK,
29218   IX86_BUILTIN_VTERNLOGQ512_MASKZ,
29219
29220   /* Mask arithmetic operations */
29221   IX86_BUILTIN_KAND16,
29222   IX86_BUILTIN_KANDN16,
29223   IX86_BUILTIN_KNOT16,
29224   IX86_BUILTIN_KOR16,
29225   IX86_BUILTIN_KORTESTC16,
29226   IX86_BUILTIN_KORTESTZ16,
29227   IX86_BUILTIN_KUNPCKBW,
29228   IX86_BUILTIN_KXNOR16,
29229   IX86_BUILTIN_KXOR16,
29230   IX86_BUILTIN_KMOV16,
29231
29232   /* AVX512VL.  */
29233   IX86_BUILTIN_PMOVUSQD256_MEM,
29234   IX86_BUILTIN_PMOVUSQD128_MEM,
29235   IX86_BUILTIN_PMOVSQD256_MEM,
29236   IX86_BUILTIN_PMOVSQD128_MEM,
29237   IX86_BUILTIN_PMOVQD256_MEM,
29238   IX86_BUILTIN_PMOVQD128_MEM,
29239   IX86_BUILTIN_PMOVUSQW256_MEM,
29240   IX86_BUILTIN_PMOVUSQW128_MEM,
29241   IX86_BUILTIN_PMOVSQW256_MEM,
29242   IX86_BUILTIN_PMOVSQW128_MEM,
29243   IX86_BUILTIN_PMOVQW256_MEM,
29244   IX86_BUILTIN_PMOVQW128_MEM,
29245   IX86_BUILTIN_PMOVUSQB256_MEM,
29246   IX86_BUILTIN_PMOVUSQB128_MEM,
29247   IX86_BUILTIN_PMOVSQB256_MEM,
29248   IX86_BUILTIN_PMOVSQB128_MEM,
29249   IX86_BUILTIN_PMOVQB256_MEM,
29250   IX86_BUILTIN_PMOVQB128_MEM,
29251   IX86_BUILTIN_PMOVUSDW256_MEM,
29252   IX86_BUILTIN_PMOVUSDW128_MEM,
29253   IX86_BUILTIN_PMOVSDW256_MEM,
29254   IX86_BUILTIN_PMOVSDW128_MEM,
29255   IX86_BUILTIN_PMOVDW256_MEM,
29256   IX86_BUILTIN_PMOVDW128_MEM,
29257   IX86_BUILTIN_PMOVUSDB256_MEM,
29258   IX86_BUILTIN_PMOVUSDB128_MEM,
29259   IX86_BUILTIN_PMOVSDB256_MEM,
29260   IX86_BUILTIN_PMOVSDB128_MEM,
29261   IX86_BUILTIN_PMOVDB256_MEM,
29262   IX86_BUILTIN_PMOVDB128_MEM,
29263   IX86_BUILTIN_MOVDQA64LOAD256_MASK,
29264   IX86_BUILTIN_MOVDQA64LOAD128_MASK,
29265   IX86_BUILTIN_MOVDQA32LOAD256_MASK,
29266   IX86_BUILTIN_MOVDQA32LOAD128_MASK,
29267   IX86_BUILTIN_MOVDQA64STORE256_MASK,
29268   IX86_BUILTIN_MOVDQA64STORE128_MASK,
29269   IX86_BUILTIN_MOVDQA32STORE256_MASK,
29270   IX86_BUILTIN_MOVDQA32STORE128_MASK,
29271   IX86_BUILTIN_LOADAPD256_MASK,
29272   IX86_BUILTIN_LOADAPD128_MASK,
29273   IX86_BUILTIN_LOADAPS256_MASK,
29274   IX86_BUILTIN_LOADAPS128_MASK,
29275   IX86_BUILTIN_STOREAPD256_MASK,
29276   IX86_BUILTIN_STOREAPD128_MASK,
29277   IX86_BUILTIN_STOREAPS256_MASK,
29278   IX86_BUILTIN_STOREAPS128_MASK,
29279   IX86_BUILTIN_LOADUPD256_MASK,
29280   IX86_BUILTIN_LOADUPD128_MASK,
29281   IX86_BUILTIN_LOADUPS256_MASK,
29282   IX86_BUILTIN_LOADUPS128_MASK,
29283   IX86_BUILTIN_STOREUPD256_MASK,
29284   IX86_BUILTIN_STOREUPD128_MASK,
29285   IX86_BUILTIN_STOREUPS256_MASK,
29286   IX86_BUILTIN_STOREUPS128_MASK,
29287   IX86_BUILTIN_LOADDQUDI256_MASK,
29288   IX86_BUILTIN_LOADDQUDI128_MASK,
29289   IX86_BUILTIN_LOADDQUSI256_MASK,
29290   IX86_BUILTIN_LOADDQUSI128_MASK,
29291   IX86_BUILTIN_LOADDQUHI256_MASK,
29292   IX86_BUILTIN_LOADDQUHI128_MASK,
29293   IX86_BUILTIN_LOADDQUQI256_MASK,
29294   IX86_BUILTIN_LOADDQUQI128_MASK,
29295   IX86_BUILTIN_STOREDQUDI256_MASK,
29296   IX86_BUILTIN_STOREDQUDI128_MASK,
29297   IX86_BUILTIN_STOREDQUSI256_MASK,
29298   IX86_BUILTIN_STOREDQUSI128_MASK,
29299   IX86_BUILTIN_STOREDQUHI256_MASK,
29300   IX86_BUILTIN_STOREDQUHI128_MASK,
29301   IX86_BUILTIN_STOREDQUQI256_MASK,
29302   IX86_BUILTIN_STOREDQUQI128_MASK,
29303   IX86_BUILTIN_COMPRESSPDSTORE256,
29304   IX86_BUILTIN_COMPRESSPDSTORE128,
29305   IX86_BUILTIN_COMPRESSPSSTORE256,
29306   IX86_BUILTIN_COMPRESSPSSTORE128,
29307   IX86_BUILTIN_PCOMPRESSQSTORE256,
29308   IX86_BUILTIN_PCOMPRESSQSTORE128,
29309   IX86_BUILTIN_PCOMPRESSDSTORE256,
29310   IX86_BUILTIN_PCOMPRESSDSTORE128,
29311   IX86_BUILTIN_EXPANDPDLOAD256,
29312   IX86_BUILTIN_EXPANDPDLOAD128,
29313   IX86_BUILTIN_EXPANDPSLOAD256,
29314   IX86_BUILTIN_EXPANDPSLOAD128,
29315   IX86_BUILTIN_PEXPANDQLOAD256,
29316   IX86_BUILTIN_PEXPANDQLOAD128,
29317   IX86_BUILTIN_PEXPANDDLOAD256,
29318   IX86_BUILTIN_PEXPANDDLOAD128,
29319   IX86_BUILTIN_EXPANDPDLOAD256Z,
29320   IX86_BUILTIN_EXPANDPDLOAD128Z,
29321   IX86_BUILTIN_EXPANDPSLOAD256Z,
29322   IX86_BUILTIN_EXPANDPSLOAD128Z,
29323   IX86_BUILTIN_PEXPANDQLOAD256Z,
29324   IX86_BUILTIN_PEXPANDQLOAD128Z,
29325   IX86_BUILTIN_PEXPANDDLOAD256Z,
29326   IX86_BUILTIN_PEXPANDDLOAD128Z,
29327   IX86_BUILTIN_PALIGNR256_MASK,
29328   IX86_BUILTIN_PALIGNR128_MASK,
29329   IX86_BUILTIN_MOVDQA64_256_MASK,
29330   IX86_BUILTIN_MOVDQA64_128_MASK,
29331   IX86_BUILTIN_MOVDQA32_256_MASK,
29332   IX86_BUILTIN_MOVDQA32_128_MASK,
29333   IX86_BUILTIN_MOVAPD256_MASK,
29334   IX86_BUILTIN_MOVAPD128_MASK,
29335   IX86_BUILTIN_MOVAPS256_MASK,
29336   IX86_BUILTIN_MOVAPS128_MASK,
29337   IX86_BUILTIN_MOVDQUHI256_MASK,
29338   IX86_BUILTIN_MOVDQUHI128_MASK,
29339   IX86_BUILTIN_MOVDQUQI256_MASK,
29340   IX86_BUILTIN_MOVDQUQI128_MASK,
29341   IX86_BUILTIN_MINPS128_MASK,
29342   IX86_BUILTIN_MAXPS128_MASK,
29343   IX86_BUILTIN_MINPD128_MASK,
29344   IX86_BUILTIN_MAXPD128_MASK,
29345   IX86_BUILTIN_MAXPD256_MASK,
29346   IX86_BUILTIN_MAXPS256_MASK,
29347   IX86_BUILTIN_MINPD256_MASK,
29348   IX86_BUILTIN_MINPS256_MASK,
29349   IX86_BUILTIN_MULPS128_MASK,
29350   IX86_BUILTIN_DIVPS128_MASK,
29351   IX86_BUILTIN_MULPD128_MASK,
29352   IX86_BUILTIN_DIVPD128_MASK,
29353   IX86_BUILTIN_DIVPD256_MASK,
29354   IX86_BUILTIN_DIVPS256_MASK,
29355   IX86_BUILTIN_MULPD256_MASK,
29356   IX86_BUILTIN_MULPS256_MASK,
29357   IX86_BUILTIN_ADDPD128_MASK,
29358   IX86_BUILTIN_ADDPD256_MASK,
29359   IX86_BUILTIN_ADDPS128_MASK,
29360   IX86_BUILTIN_ADDPS256_MASK,
29361   IX86_BUILTIN_SUBPD128_MASK,
29362   IX86_BUILTIN_SUBPD256_MASK,
29363   IX86_BUILTIN_SUBPS128_MASK,
29364   IX86_BUILTIN_SUBPS256_MASK,
29365   IX86_BUILTIN_XORPD256_MASK,
29366   IX86_BUILTIN_XORPD128_MASK,
29367   IX86_BUILTIN_XORPS256_MASK,
29368   IX86_BUILTIN_XORPS128_MASK,
29369   IX86_BUILTIN_ORPD256_MASK,
29370   IX86_BUILTIN_ORPD128_MASK,
29371   IX86_BUILTIN_ORPS256_MASK,
29372   IX86_BUILTIN_ORPS128_MASK,
29373   IX86_BUILTIN_BROADCASTF32x2_256,
29374   IX86_BUILTIN_BROADCASTI32x2_256,
29375   IX86_BUILTIN_BROADCASTI32x2_128,
29376   IX86_BUILTIN_BROADCASTF64X2_256,
29377   IX86_BUILTIN_BROADCASTI64X2_256,
29378   IX86_BUILTIN_BROADCASTF32X4_256,
29379   IX86_BUILTIN_BROADCASTI32X4_256,
29380   IX86_BUILTIN_EXTRACTF32X4_256,
29381   IX86_BUILTIN_EXTRACTI32X4_256,
29382   IX86_BUILTIN_DBPSADBW256,
29383   IX86_BUILTIN_DBPSADBW128,
29384   IX86_BUILTIN_CVTTPD2QQ256,
29385   IX86_BUILTIN_CVTTPD2QQ128,
29386   IX86_BUILTIN_CVTTPD2UQQ256,
29387   IX86_BUILTIN_CVTTPD2UQQ128,
29388   IX86_BUILTIN_CVTPD2QQ256,
29389   IX86_BUILTIN_CVTPD2QQ128,
29390   IX86_BUILTIN_CVTPD2UQQ256,
29391   IX86_BUILTIN_CVTPD2UQQ128,
29392   IX86_BUILTIN_CVTPD2UDQ256_MASK,
29393   IX86_BUILTIN_CVTPD2UDQ128_MASK,
29394   IX86_BUILTIN_CVTTPS2QQ256,
29395   IX86_BUILTIN_CVTTPS2QQ128,
29396   IX86_BUILTIN_CVTTPS2UQQ256,
29397   IX86_BUILTIN_CVTTPS2UQQ128,
29398   IX86_BUILTIN_CVTTPS2DQ256_MASK,
29399   IX86_BUILTIN_CVTTPS2DQ128_MASK,
29400   IX86_BUILTIN_CVTTPS2UDQ256,
29401   IX86_BUILTIN_CVTTPS2UDQ128,
29402   IX86_BUILTIN_CVTTPD2DQ256_MASK,
29403   IX86_BUILTIN_CVTTPD2DQ128_MASK,
29404   IX86_BUILTIN_CVTTPD2UDQ256_MASK,
29405   IX86_BUILTIN_CVTTPD2UDQ128_MASK,
29406   IX86_BUILTIN_CVTPD2DQ256_MASK,
29407   IX86_BUILTIN_CVTPD2DQ128_MASK,
29408   IX86_BUILTIN_CVTDQ2PD256_MASK,
29409   IX86_BUILTIN_CVTDQ2PD128_MASK,
29410   IX86_BUILTIN_CVTUDQ2PD256_MASK,
29411   IX86_BUILTIN_CVTUDQ2PD128_MASK,
29412   IX86_BUILTIN_CVTDQ2PS256_MASK,
29413   IX86_BUILTIN_CVTDQ2PS128_MASK,
29414   IX86_BUILTIN_CVTUDQ2PS256_MASK,
29415   IX86_BUILTIN_CVTUDQ2PS128_MASK,
29416   IX86_BUILTIN_CVTPS2PD256_MASK,
29417   IX86_BUILTIN_CVTPS2PD128_MASK,
29418   IX86_BUILTIN_PBROADCASTB256_MASK,
29419   IX86_BUILTIN_PBROADCASTB256_GPR_MASK,
29420   IX86_BUILTIN_PBROADCASTB128_MASK,
29421   IX86_BUILTIN_PBROADCASTB128_GPR_MASK,
29422   IX86_BUILTIN_PBROADCASTW256_MASK,
29423   IX86_BUILTIN_PBROADCASTW256_GPR_MASK,
29424   IX86_BUILTIN_PBROADCASTW128_MASK,
29425   IX86_BUILTIN_PBROADCASTW128_GPR_MASK,
29426   IX86_BUILTIN_PBROADCASTD256_MASK,
29427   IX86_BUILTIN_PBROADCASTD256_GPR_MASK,
29428   IX86_BUILTIN_PBROADCASTD128_MASK,
29429   IX86_BUILTIN_PBROADCASTD128_GPR_MASK,
29430   IX86_BUILTIN_PBROADCASTQ256_MASK,
29431   IX86_BUILTIN_PBROADCASTQ256_GPR_MASK,
29432   IX86_BUILTIN_PBROADCASTQ128_MASK,
29433   IX86_BUILTIN_PBROADCASTQ128_GPR_MASK,
29434   IX86_BUILTIN_BROADCASTSS256,
29435   IX86_BUILTIN_BROADCASTSS128,
29436   IX86_BUILTIN_BROADCASTSD256,
29437   IX86_BUILTIN_EXTRACTF64X2_256,
29438   IX86_BUILTIN_EXTRACTI64X2_256,
29439   IX86_BUILTIN_INSERTF32X4_256,
29440   IX86_BUILTIN_INSERTI32X4_256,
29441   IX86_BUILTIN_PMOVSXBW256_MASK,
29442   IX86_BUILTIN_PMOVSXBW128_MASK,
29443   IX86_BUILTIN_PMOVSXBD256_MASK,
29444   IX86_BUILTIN_PMOVSXBD128_MASK,
29445   IX86_BUILTIN_PMOVSXBQ256_MASK,
29446   IX86_BUILTIN_PMOVSXBQ128_MASK,
29447   IX86_BUILTIN_PMOVSXWD256_MASK,
29448   IX86_BUILTIN_PMOVSXWD128_MASK,
29449   IX86_BUILTIN_PMOVSXWQ256_MASK,
29450   IX86_BUILTIN_PMOVSXWQ128_MASK,
29451   IX86_BUILTIN_PMOVSXDQ256_MASK,
29452   IX86_BUILTIN_PMOVSXDQ128_MASK,
29453   IX86_BUILTIN_PMOVZXBW256_MASK,
29454   IX86_BUILTIN_PMOVZXBW128_MASK,
29455   IX86_BUILTIN_PMOVZXBD256_MASK,
29456   IX86_BUILTIN_PMOVZXBD128_MASK,
29457   IX86_BUILTIN_PMOVZXBQ256_MASK,
29458   IX86_BUILTIN_PMOVZXBQ128_MASK,
29459   IX86_BUILTIN_PMOVZXWD256_MASK,
29460   IX86_BUILTIN_PMOVZXWD128_MASK,
29461   IX86_BUILTIN_PMOVZXWQ256_MASK,
29462   IX86_BUILTIN_PMOVZXWQ128_MASK,
29463   IX86_BUILTIN_PMOVZXDQ256_MASK,
29464   IX86_BUILTIN_PMOVZXDQ128_MASK,
29465   IX86_BUILTIN_REDUCEPD256_MASK,
29466   IX86_BUILTIN_REDUCEPD128_MASK,
29467   IX86_BUILTIN_REDUCEPS256_MASK,
29468   IX86_BUILTIN_REDUCEPS128_MASK,
29469   IX86_BUILTIN_REDUCESD_MASK,
29470   IX86_BUILTIN_REDUCESS_MASK,
29471   IX86_BUILTIN_VPERMVARHI256_MASK,
29472   IX86_BUILTIN_VPERMVARHI128_MASK,
29473   IX86_BUILTIN_VPERMT2VARHI256,
29474   IX86_BUILTIN_VPERMT2VARHI256_MASKZ,
29475   IX86_BUILTIN_VPERMT2VARHI128,
29476   IX86_BUILTIN_VPERMT2VARHI128_MASKZ,
29477   IX86_BUILTIN_VPERMI2VARHI256,
29478   IX86_BUILTIN_VPERMI2VARHI128,
29479   IX86_BUILTIN_RCP14PD256,
29480   IX86_BUILTIN_RCP14PD128,
29481   IX86_BUILTIN_RCP14PS256,
29482   IX86_BUILTIN_RCP14PS128,
29483   IX86_BUILTIN_RSQRT14PD256_MASK,
29484   IX86_BUILTIN_RSQRT14PD128_MASK,
29485   IX86_BUILTIN_RSQRT14PS256_MASK,
29486   IX86_BUILTIN_RSQRT14PS128_MASK,
29487   IX86_BUILTIN_SQRTPD256_MASK,
29488   IX86_BUILTIN_SQRTPD128_MASK,
29489   IX86_BUILTIN_SQRTPS256_MASK,
29490   IX86_BUILTIN_SQRTPS128_MASK,
29491   IX86_BUILTIN_PADDB128_MASK,
29492   IX86_BUILTIN_PADDW128_MASK,
29493   IX86_BUILTIN_PADDD128_MASK,
29494   IX86_BUILTIN_PADDQ128_MASK,
29495   IX86_BUILTIN_PSUBB128_MASK,
29496   IX86_BUILTIN_PSUBW128_MASK,
29497   IX86_BUILTIN_PSUBD128_MASK,
29498   IX86_BUILTIN_PSUBQ128_MASK,
29499   IX86_BUILTIN_PADDSB128_MASK,
29500   IX86_BUILTIN_PADDSW128_MASK,
29501   IX86_BUILTIN_PSUBSB128_MASK,
29502   IX86_BUILTIN_PSUBSW128_MASK,
29503   IX86_BUILTIN_PADDUSB128_MASK,
29504   IX86_BUILTIN_PADDUSW128_MASK,
29505   IX86_BUILTIN_PSUBUSB128_MASK,
29506   IX86_BUILTIN_PSUBUSW128_MASK,
29507   IX86_BUILTIN_PADDB256_MASK,
29508   IX86_BUILTIN_PADDW256_MASK,
29509   IX86_BUILTIN_PADDD256_MASK,
29510   IX86_BUILTIN_PADDQ256_MASK,
29511   IX86_BUILTIN_PADDSB256_MASK,
29512   IX86_BUILTIN_PADDSW256_MASK,
29513   IX86_BUILTIN_PADDUSB256_MASK,
29514   IX86_BUILTIN_PADDUSW256_MASK,
29515   IX86_BUILTIN_PSUBB256_MASK,
29516   IX86_BUILTIN_PSUBW256_MASK,
29517   IX86_BUILTIN_PSUBD256_MASK,
29518   IX86_BUILTIN_PSUBQ256_MASK,
29519   IX86_BUILTIN_PSUBSB256_MASK,
29520   IX86_BUILTIN_PSUBSW256_MASK,
29521   IX86_BUILTIN_PSUBUSB256_MASK,
29522   IX86_BUILTIN_PSUBUSW256_MASK,
29523   IX86_BUILTIN_SHUF_F64x2_256,
29524   IX86_BUILTIN_SHUF_I64x2_256,
29525   IX86_BUILTIN_SHUF_I32x4_256,
29526   IX86_BUILTIN_SHUF_F32x4_256,
29527   IX86_BUILTIN_PMOVWB128,
29528   IX86_BUILTIN_PMOVWB256,
29529   IX86_BUILTIN_PMOVSWB128,
29530   IX86_BUILTIN_PMOVSWB256,
29531   IX86_BUILTIN_PMOVUSWB128,
29532   IX86_BUILTIN_PMOVUSWB256,
29533   IX86_BUILTIN_PMOVDB128,
29534   IX86_BUILTIN_PMOVDB256,
29535   IX86_BUILTIN_PMOVSDB128,
29536   IX86_BUILTIN_PMOVSDB256,
29537   IX86_BUILTIN_PMOVUSDB128,
29538   IX86_BUILTIN_PMOVUSDB256,
29539   IX86_BUILTIN_PMOVDW128,
29540   IX86_BUILTIN_PMOVDW256,
29541   IX86_BUILTIN_PMOVSDW128,
29542   IX86_BUILTIN_PMOVSDW256,
29543   IX86_BUILTIN_PMOVUSDW128,
29544   IX86_BUILTIN_PMOVUSDW256,
29545   IX86_BUILTIN_PMOVQB128,
29546   IX86_BUILTIN_PMOVQB256,
29547   IX86_BUILTIN_PMOVSQB128,
29548   IX86_BUILTIN_PMOVSQB256,
29549   IX86_BUILTIN_PMOVUSQB128,
29550   IX86_BUILTIN_PMOVUSQB256,
29551   IX86_BUILTIN_PMOVQW128,
29552   IX86_BUILTIN_PMOVQW256,
29553   IX86_BUILTIN_PMOVSQW128,
29554   IX86_BUILTIN_PMOVSQW256,
29555   IX86_BUILTIN_PMOVUSQW128,
29556   IX86_BUILTIN_PMOVUSQW256,
29557   IX86_BUILTIN_PMOVQD128,
29558   IX86_BUILTIN_PMOVQD256,
29559   IX86_BUILTIN_PMOVSQD128,
29560   IX86_BUILTIN_PMOVSQD256,
29561   IX86_BUILTIN_PMOVUSQD128,
29562   IX86_BUILTIN_PMOVUSQD256,
29563   IX86_BUILTIN_RANGEPD256,
29564   IX86_BUILTIN_RANGEPD128,
29565   IX86_BUILTIN_RANGEPS256,
29566   IX86_BUILTIN_RANGEPS128,
29567   IX86_BUILTIN_GETEXPPS256,
29568   IX86_BUILTIN_GETEXPPD256,
29569   IX86_BUILTIN_GETEXPPS128,
29570   IX86_BUILTIN_GETEXPPD128,
29571   IX86_BUILTIN_FIXUPIMMPD256_MASK,
29572   IX86_BUILTIN_FIXUPIMMPD256_MASKZ,
29573   IX86_BUILTIN_FIXUPIMMPS256_MASK,
29574   IX86_BUILTIN_FIXUPIMMPS256_MASKZ,
29575   IX86_BUILTIN_FIXUPIMMPD128_MASK,
29576   IX86_BUILTIN_FIXUPIMMPD128_MASKZ,
29577   IX86_BUILTIN_FIXUPIMMPS128_MASK,
29578   IX86_BUILTIN_FIXUPIMMPS128_MASKZ,
29579   IX86_BUILTIN_PABSQ256,
29580   IX86_BUILTIN_PABSQ128,
29581   IX86_BUILTIN_PABSD256_MASK,
29582   IX86_BUILTIN_PABSD128_MASK,
29583   IX86_BUILTIN_PMULHRSW256_MASK,
29584   IX86_BUILTIN_PMULHRSW128_MASK,
29585   IX86_BUILTIN_PMULHUW128_MASK,
29586   IX86_BUILTIN_PMULHUW256_MASK,
29587   IX86_BUILTIN_PMULHW256_MASK,
29588   IX86_BUILTIN_PMULHW128_MASK,
29589   IX86_BUILTIN_PMULLW256_MASK,
29590   IX86_BUILTIN_PMULLW128_MASK,
29591   IX86_BUILTIN_PMULLQ256,
29592   IX86_BUILTIN_PMULLQ128,
29593   IX86_BUILTIN_ANDPD256_MASK,
29594   IX86_BUILTIN_ANDPD128_MASK,
29595   IX86_BUILTIN_ANDPS256_MASK,
29596   IX86_BUILTIN_ANDPS128_MASK,
29597   IX86_BUILTIN_ANDNPD256_MASK,
29598   IX86_BUILTIN_ANDNPD128_MASK,
29599   IX86_BUILTIN_ANDNPS256_MASK,
29600   IX86_BUILTIN_ANDNPS128_MASK,
29601   IX86_BUILTIN_PSLLWI128_MASK,
29602   IX86_BUILTIN_PSLLDI128_MASK,
29603   IX86_BUILTIN_PSLLQI128_MASK,
29604   IX86_BUILTIN_PSLLW128_MASK,
29605   IX86_BUILTIN_PSLLD128_MASK,
29606   IX86_BUILTIN_PSLLQ128_MASK,
29607   IX86_BUILTIN_PSLLWI256_MASK ,
29608   IX86_BUILTIN_PSLLW256_MASK,
29609   IX86_BUILTIN_PSLLDI256_MASK,
29610   IX86_BUILTIN_PSLLD256_MASK,
29611   IX86_BUILTIN_PSLLQI256_MASK,
29612   IX86_BUILTIN_PSLLQ256_MASK,
29613   IX86_BUILTIN_PSRADI128_MASK,
29614   IX86_BUILTIN_PSRAD128_MASK,
29615   IX86_BUILTIN_PSRADI256_MASK,
29616   IX86_BUILTIN_PSRAD256_MASK,
29617   IX86_BUILTIN_PSRAQI128_MASK,
29618   IX86_BUILTIN_PSRAQ128_MASK,
29619   IX86_BUILTIN_PSRAQI256_MASK,
29620   IX86_BUILTIN_PSRAQ256_MASK,
29621   IX86_BUILTIN_PANDD256,
29622   IX86_BUILTIN_PANDD128,
29623   IX86_BUILTIN_PSRLDI128_MASK,
29624   IX86_BUILTIN_PSRLD128_MASK,
29625   IX86_BUILTIN_PSRLDI256_MASK,
29626   IX86_BUILTIN_PSRLD256_MASK,
29627   IX86_BUILTIN_PSRLQI128_MASK,
29628   IX86_BUILTIN_PSRLQ128_MASK,
29629   IX86_BUILTIN_PSRLQI256_MASK,
29630   IX86_BUILTIN_PSRLQ256_MASK,
29631   IX86_BUILTIN_PANDQ256,
29632   IX86_BUILTIN_PANDQ128,
29633   IX86_BUILTIN_PANDND256,
29634   IX86_BUILTIN_PANDND128,
29635   IX86_BUILTIN_PANDNQ256,
29636   IX86_BUILTIN_PANDNQ128,
29637   IX86_BUILTIN_PORD256,
29638   IX86_BUILTIN_PORD128,
29639   IX86_BUILTIN_PORQ256,
29640   IX86_BUILTIN_PORQ128,
29641   IX86_BUILTIN_PXORD256,
29642   IX86_BUILTIN_PXORD128,
29643   IX86_BUILTIN_PXORQ256,
29644   IX86_BUILTIN_PXORQ128,
29645   IX86_BUILTIN_PACKSSWB256_MASK,
29646   IX86_BUILTIN_PACKSSWB128_MASK,
29647   IX86_BUILTIN_PACKUSWB256_MASK,
29648   IX86_BUILTIN_PACKUSWB128_MASK,
29649   IX86_BUILTIN_RNDSCALEPS256,
29650   IX86_BUILTIN_RNDSCALEPD256,
29651   IX86_BUILTIN_RNDSCALEPS128,
29652   IX86_BUILTIN_RNDSCALEPD128,
29653   IX86_BUILTIN_VTERNLOGQ256_MASK,
29654   IX86_BUILTIN_VTERNLOGQ256_MASKZ,
29655   IX86_BUILTIN_VTERNLOGD256_MASK,
29656   IX86_BUILTIN_VTERNLOGD256_MASKZ,
29657   IX86_BUILTIN_VTERNLOGQ128_MASK,
29658   IX86_BUILTIN_VTERNLOGQ128_MASKZ,
29659   IX86_BUILTIN_VTERNLOGD128_MASK,
29660   IX86_BUILTIN_VTERNLOGD128_MASKZ,
29661   IX86_BUILTIN_SCALEFPD256,
29662   IX86_BUILTIN_SCALEFPS256,
29663   IX86_BUILTIN_SCALEFPD128,
29664   IX86_BUILTIN_SCALEFPS128,
29665   IX86_BUILTIN_VFMADDPD256_MASK,
29666   IX86_BUILTIN_VFMADDPD256_MASK3,
29667   IX86_BUILTIN_VFMADDPD256_MASKZ,
29668   IX86_BUILTIN_VFMADDPD128_MASK,
29669   IX86_BUILTIN_VFMADDPD128_MASK3,
29670   IX86_BUILTIN_VFMADDPD128_MASKZ,
29671   IX86_BUILTIN_VFMADDPS256_MASK,
29672   IX86_BUILTIN_VFMADDPS256_MASK3,
29673   IX86_BUILTIN_VFMADDPS256_MASKZ,
29674   IX86_BUILTIN_VFMADDPS128_MASK,
29675   IX86_BUILTIN_VFMADDPS128_MASK3,
29676   IX86_BUILTIN_VFMADDPS128_MASKZ,
29677   IX86_BUILTIN_VFMSUBPD256_MASK3,
29678   IX86_BUILTIN_VFMSUBPD128_MASK3,
29679   IX86_BUILTIN_VFMSUBPS256_MASK3,
29680   IX86_BUILTIN_VFMSUBPS128_MASK3,
29681   IX86_BUILTIN_VFNMADDPD256_MASK,
29682   IX86_BUILTIN_VFNMADDPD128_MASK,
29683   IX86_BUILTIN_VFNMADDPS256_MASK,
29684   IX86_BUILTIN_VFNMADDPS128_MASK,
29685   IX86_BUILTIN_VFNMSUBPD256_MASK,
29686   IX86_BUILTIN_VFNMSUBPD256_MASK3,
29687   IX86_BUILTIN_VFNMSUBPD128_MASK,
29688   IX86_BUILTIN_VFNMSUBPD128_MASK3,
29689   IX86_BUILTIN_VFNMSUBPS256_MASK,
29690   IX86_BUILTIN_VFNMSUBPS256_MASK3,
29691   IX86_BUILTIN_VFNMSUBPS128_MASK,
29692   IX86_BUILTIN_VFNMSUBPS128_MASK3,
29693   IX86_BUILTIN_VFMADDSUBPD256_MASK,
29694   IX86_BUILTIN_VFMADDSUBPD256_MASK3,
29695   IX86_BUILTIN_VFMADDSUBPD256_MASKZ,
29696   IX86_BUILTIN_VFMADDSUBPD128_MASK,
29697   IX86_BUILTIN_VFMADDSUBPD128_MASK3,
29698   IX86_BUILTIN_VFMADDSUBPD128_MASKZ,
29699   IX86_BUILTIN_VFMADDSUBPS256_MASK,
29700   IX86_BUILTIN_VFMADDSUBPS256_MASK3,
29701   IX86_BUILTIN_VFMADDSUBPS256_MASKZ,
29702   IX86_BUILTIN_VFMADDSUBPS128_MASK,
29703   IX86_BUILTIN_VFMADDSUBPS128_MASK3,
29704   IX86_BUILTIN_VFMADDSUBPS128_MASKZ,
29705   IX86_BUILTIN_VFMSUBADDPD256_MASK3,
29706   IX86_BUILTIN_VFMSUBADDPD128_MASK3,
29707   IX86_BUILTIN_VFMSUBADDPS256_MASK3,
29708   IX86_BUILTIN_VFMSUBADDPS128_MASK3,
29709   IX86_BUILTIN_INSERTF64X2_256,
29710   IX86_BUILTIN_INSERTI64X2_256,
29711   IX86_BUILTIN_PSRAVV16HI,
29712   IX86_BUILTIN_PSRAVV8HI,
29713   IX86_BUILTIN_PMADDUBSW256_MASK,
29714   IX86_BUILTIN_PMADDUBSW128_MASK,
29715   IX86_BUILTIN_PMADDWD256_MASK,
29716   IX86_BUILTIN_PMADDWD128_MASK,
29717   IX86_BUILTIN_PSRLVV16HI,
29718   IX86_BUILTIN_PSRLVV8HI,
29719   IX86_BUILTIN_CVTPS2DQ256_MASK,
29720   IX86_BUILTIN_CVTPS2DQ128_MASK,
29721   IX86_BUILTIN_CVTPS2UDQ256,
29722   IX86_BUILTIN_CVTPS2UDQ128,
29723   IX86_BUILTIN_CVTPS2QQ256,
29724   IX86_BUILTIN_CVTPS2QQ128,
29725   IX86_BUILTIN_CVTPS2UQQ256,
29726   IX86_BUILTIN_CVTPS2UQQ128,
29727   IX86_BUILTIN_GETMANTPS256,
29728   IX86_BUILTIN_GETMANTPS128,
29729   IX86_BUILTIN_GETMANTPD256,
29730   IX86_BUILTIN_GETMANTPD128,
29731   IX86_BUILTIN_MOVDDUP256_MASK,
29732   IX86_BUILTIN_MOVDDUP128_MASK,
29733   IX86_BUILTIN_MOVSHDUP256_MASK,
29734   IX86_BUILTIN_MOVSHDUP128_MASK,
29735   IX86_BUILTIN_MOVSLDUP256_MASK,
29736   IX86_BUILTIN_MOVSLDUP128_MASK,
29737   IX86_BUILTIN_CVTQQ2PS256,
29738   IX86_BUILTIN_CVTQQ2PS128,
29739   IX86_BUILTIN_CVTUQQ2PS256,
29740   IX86_BUILTIN_CVTUQQ2PS128,
29741   IX86_BUILTIN_CVTQQ2PD256,
29742   IX86_BUILTIN_CVTQQ2PD128,
29743   IX86_BUILTIN_CVTUQQ2PD256,
29744   IX86_BUILTIN_CVTUQQ2PD128,
29745   IX86_BUILTIN_VPERMT2VARQ256,
29746   IX86_BUILTIN_VPERMT2VARQ256_MASKZ,
29747   IX86_BUILTIN_VPERMT2VARD256,
29748   IX86_BUILTIN_VPERMT2VARD256_MASKZ,
29749   IX86_BUILTIN_VPERMI2VARQ256,
29750   IX86_BUILTIN_VPERMI2VARD256,
29751   IX86_BUILTIN_VPERMT2VARPD256,
29752   IX86_BUILTIN_VPERMT2VARPD256_MASKZ,
29753   IX86_BUILTIN_VPERMT2VARPS256,
29754   IX86_BUILTIN_VPERMT2VARPS256_MASKZ,
29755   IX86_BUILTIN_VPERMI2VARPD256,
29756   IX86_BUILTIN_VPERMI2VARPS256,
29757   IX86_BUILTIN_VPERMT2VARQ128,
29758   IX86_BUILTIN_VPERMT2VARQ128_MASKZ,
29759   IX86_BUILTIN_VPERMT2VARD128,
29760   IX86_BUILTIN_VPERMT2VARD128_MASKZ,
29761   IX86_BUILTIN_VPERMI2VARQ128,
29762   IX86_BUILTIN_VPERMI2VARD128,
29763   IX86_BUILTIN_VPERMT2VARPD128,
29764   IX86_BUILTIN_VPERMT2VARPD128_MASKZ,
29765   IX86_BUILTIN_VPERMT2VARPS128,
29766   IX86_BUILTIN_VPERMT2VARPS128_MASKZ,
29767   IX86_BUILTIN_VPERMI2VARPD128,
29768   IX86_BUILTIN_VPERMI2VARPS128,
29769   IX86_BUILTIN_PSHUFB256_MASK,
29770   IX86_BUILTIN_PSHUFB128_MASK,
29771   IX86_BUILTIN_PSHUFHW256_MASK,
29772   IX86_BUILTIN_PSHUFHW128_MASK,
29773   IX86_BUILTIN_PSHUFLW256_MASK,
29774   IX86_BUILTIN_PSHUFLW128_MASK,
29775   IX86_BUILTIN_PSHUFD256_MASK,
29776   IX86_BUILTIN_PSHUFD128_MASK,
29777   IX86_BUILTIN_SHUFPD256_MASK,
29778   IX86_BUILTIN_SHUFPD128_MASK,
29779   IX86_BUILTIN_SHUFPS256_MASK,
29780   IX86_BUILTIN_SHUFPS128_MASK,
29781   IX86_BUILTIN_PROLVQ256,
29782   IX86_BUILTIN_PROLVQ128,
29783   IX86_BUILTIN_PROLQ256,
29784   IX86_BUILTIN_PROLQ128,
29785   IX86_BUILTIN_PRORVQ256,
29786   IX86_BUILTIN_PRORVQ128,
29787   IX86_BUILTIN_PRORQ256,
29788   IX86_BUILTIN_PRORQ128,
29789   IX86_BUILTIN_PSRAVQ128,
29790   IX86_BUILTIN_PSRAVQ256,
29791   IX86_BUILTIN_PSLLVV4DI_MASK,
29792   IX86_BUILTIN_PSLLVV2DI_MASK,
29793   IX86_BUILTIN_PSLLVV8SI_MASK,
29794   IX86_BUILTIN_PSLLVV4SI_MASK,
29795   IX86_BUILTIN_PSRAVV8SI_MASK,
29796   IX86_BUILTIN_PSRAVV4SI_MASK,
29797   IX86_BUILTIN_PSRLVV4DI_MASK,
29798   IX86_BUILTIN_PSRLVV2DI_MASK,
29799   IX86_BUILTIN_PSRLVV8SI_MASK,
29800   IX86_BUILTIN_PSRLVV4SI_MASK,
29801   IX86_BUILTIN_PSRAWI256_MASK,
29802   IX86_BUILTIN_PSRAW256_MASK,
29803   IX86_BUILTIN_PSRAWI128_MASK,
29804   IX86_BUILTIN_PSRAW128_MASK,
29805   IX86_BUILTIN_PSRLWI256_MASK,
29806   IX86_BUILTIN_PSRLW256_MASK,
29807   IX86_BUILTIN_PSRLWI128_MASK,
29808   IX86_BUILTIN_PSRLW128_MASK,
29809   IX86_BUILTIN_PRORVD256,
29810   IX86_BUILTIN_PROLVD256,
29811   IX86_BUILTIN_PRORD256,
29812   IX86_BUILTIN_PROLD256,
29813   IX86_BUILTIN_PRORVD128,
29814   IX86_BUILTIN_PROLVD128,
29815   IX86_BUILTIN_PRORD128,
29816   IX86_BUILTIN_PROLD128,
29817   IX86_BUILTIN_FPCLASSPD256,
29818   IX86_BUILTIN_FPCLASSPD128,
29819   IX86_BUILTIN_FPCLASSSD,
29820   IX86_BUILTIN_FPCLASSPS256,
29821   IX86_BUILTIN_FPCLASSPS128,
29822   IX86_BUILTIN_FPCLASSSS,
29823   IX86_BUILTIN_CVTB2MASK128,
29824   IX86_BUILTIN_CVTB2MASK256,
29825   IX86_BUILTIN_CVTW2MASK128,
29826   IX86_BUILTIN_CVTW2MASK256,
29827   IX86_BUILTIN_CVTD2MASK128,
29828   IX86_BUILTIN_CVTD2MASK256,
29829   IX86_BUILTIN_CVTQ2MASK128,
29830   IX86_BUILTIN_CVTQ2MASK256,
29831   IX86_BUILTIN_CVTMASK2B128,
29832   IX86_BUILTIN_CVTMASK2B256,
29833   IX86_BUILTIN_CVTMASK2W128,
29834   IX86_BUILTIN_CVTMASK2W256,
29835   IX86_BUILTIN_CVTMASK2D128,
29836   IX86_BUILTIN_CVTMASK2D256,
29837   IX86_BUILTIN_CVTMASK2Q128,
29838   IX86_BUILTIN_CVTMASK2Q256,
29839   IX86_BUILTIN_PCMPEQB128_MASK,
29840   IX86_BUILTIN_PCMPEQB256_MASK,
29841   IX86_BUILTIN_PCMPEQW128_MASK,
29842   IX86_BUILTIN_PCMPEQW256_MASK,
29843   IX86_BUILTIN_PCMPEQD128_MASK,
29844   IX86_BUILTIN_PCMPEQD256_MASK,
29845   IX86_BUILTIN_PCMPEQQ128_MASK,
29846   IX86_BUILTIN_PCMPEQQ256_MASK,
29847   IX86_BUILTIN_PCMPGTB128_MASK,
29848   IX86_BUILTIN_PCMPGTB256_MASK,
29849   IX86_BUILTIN_PCMPGTW128_MASK,
29850   IX86_BUILTIN_PCMPGTW256_MASK,
29851   IX86_BUILTIN_PCMPGTD128_MASK,
29852   IX86_BUILTIN_PCMPGTD256_MASK,
29853   IX86_BUILTIN_PCMPGTQ128_MASK,
29854   IX86_BUILTIN_PCMPGTQ256_MASK,
29855   IX86_BUILTIN_PTESTMB128,
29856   IX86_BUILTIN_PTESTMB256,
29857   IX86_BUILTIN_PTESTMW128,
29858   IX86_BUILTIN_PTESTMW256,
29859   IX86_BUILTIN_PTESTMD128,
29860   IX86_BUILTIN_PTESTMD256,
29861   IX86_BUILTIN_PTESTMQ128,
29862   IX86_BUILTIN_PTESTMQ256,
29863   IX86_BUILTIN_PTESTNMB128,
29864   IX86_BUILTIN_PTESTNMB256,
29865   IX86_BUILTIN_PTESTNMW128,
29866   IX86_BUILTIN_PTESTNMW256,
29867   IX86_BUILTIN_PTESTNMD128,
29868   IX86_BUILTIN_PTESTNMD256,
29869   IX86_BUILTIN_PTESTNMQ128,
29870   IX86_BUILTIN_PTESTNMQ256,
29871   IX86_BUILTIN_PBROADCASTMB128,
29872   IX86_BUILTIN_PBROADCASTMB256,
29873   IX86_BUILTIN_PBROADCASTMW128,
29874   IX86_BUILTIN_PBROADCASTMW256,
29875   IX86_BUILTIN_COMPRESSPD256,
29876   IX86_BUILTIN_COMPRESSPD128,
29877   IX86_BUILTIN_COMPRESSPS256,
29878   IX86_BUILTIN_COMPRESSPS128,
29879   IX86_BUILTIN_PCOMPRESSQ256,
29880   IX86_BUILTIN_PCOMPRESSQ128,
29881   IX86_BUILTIN_PCOMPRESSD256,
29882   IX86_BUILTIN_PCOMPRESSD128,
29883   IX86_BUILTIN_EXPANDPD256,
29884   IX86_BUILTIN_EXPANDPD128,
29885   IX86_BUILTIN_EXPANDPS256,
29886   IX86_BUILTIN_EXPANDPS128,
29887   IX86_BUILTIN_PEXPANDQ256,
29888   IX86_BUILTIN_PEXPANDQ128,
29889   IX86_BUILTIN_PEXPANDD256,
29890   IX86_BUILTIN_PEXPANDD128,
29891   IX86_BUILTIN_EXPANDPD256Z,
29892   IX86_BUILTIN_EXPANDPD128Z,
29893   IX86_BUILTIN_EXPANDPS256Z,
29894   IX86_BUILTIN_EXPANDPS128Z,
29895   IX86_BUILTIN_PEXPANDQ256Z,
29896   IX86_BUILTIN_PEXPANDQ128Z,
29897   IX86_BUILTIN_PEXPANDD256Z,
29898   IX86_BUILTIN_PEXPANDD128Z,
29899   IX86_BUILTIN_PMAXSD256_MASK,
29900   IX86_BUILTIN_PMINSD256_MASK,
29901   IX86_BUILTIN_PMAXUD256_MASK,
29902   IX86_BUILTIN_PMINUD256_MASK,
29903   IX86_BUILTIN_PMAXSD128_MASK,
29904   IX86_BUILTIN_PMINSD128_MASK,
29905   IX86_BUILTIN_PMAXUD128_MASK,
29906   IX86_BUILTIN_PMINUD128_MASK,
29907   IX86_BUILTIN_PMAXSQ256_MASK,
29908   IX86_BUILTIN_PMINSQ256_MASK,
29909   IX86_BUILTIN_PMAXUQ256_MASK,
29910   IX86_BUILTIN_PMINUQ256_MASK,
29911   IX86_BUILTIN_PMAXSQ128_MASK,
29912   IX86_BUILTIN_PMINSQ128_MASK,
29913   IX86_BUILTIN_PMAXUQ128_MASK,
29914   IX86_BUILTIN_PMINUQ128_MASK,
29915   IX86_BUILTIN_PMINSB256_MASK,
29916   IX86_BUILTIN_PMINUB256_MASK,
29917   IX86_BUILTIN_PMAXSB256_MASK,
29918   IX86_BUILTIN_PMAXUB256_MASK,
29919   IX86_BUILTIN_PMINSB128_MASK,
29920   IX86_BUILTIN_PMINUB128_MASK,
29921   IX86_BUILTIN_PMAXSB128_MASK,
29922   IX86_BUILTIN_PMAXUB128_MASK,
29923   IX86_BUILTIN_PMINSW256_MASK,
29924   IX86_BUILTIN_PMINUW256_MASK,
29925   IX86_BUILTIN_PMAXSW256_MASK,
29926   IX86_BUILTIN_PMAXUW256_MASK,
29927   IX86_BUILTIN_PMINSW128_MASK,
29928   IX86_BUILTIN_PMINUW128_MASK,
29929   IX86_BUILTIN_PMAXSW128_MASK,
29930   IX86_BUILTIN_PMAXUW128_MASK,
29931   IX86_BUILTIN_VPCONFLICTQ256,
29932   IX86_BUILTIN_VPCONFLICTD256,
29933   IX86_BUILTIN_VPCLZCNTQ256,
29934   IX86_BUILTIN_VPCLZCNTD256,
29935   IX86_BUILTIN_UNPCKHPD256_MASK,
29936   IX86_BUILTIN_UNPCKHPD128_MASK,
29937   IX86_BUILTIN_UNPCKHPS256_MASK,
29938   IX86_BUILTIN_UNPCKHPS128_MASK,
29939   IX86_BUILTIN_UNPCKLPD256_MASK,
29940   IX86_BUILTIN_UNPCKLPD128_MASK,
29941   IX86_BUILTIN_UNPCKLPS256_MASK,
29942   IX86_BUILTIN_VPCONFLICTQ128,
29943   IX86_BUILTIN_VPCONFLICTD128,
29944   IX86_BUILTIN_VPCLZCNTQ128,
29945   IX86_BUILTIN_VPCLZCNTD128,
29946   IX86_BUILTIN_UNPCKLPS128_MASK,
29947   IX86_BUILTIN_ALIGND256,
29948   IX86_BUILTIN_ALIGNQ256,
29949   IX86_BUILTIN_ALIGND128,
29950   IX86_BUILTIN_ALIGNQ128,
29951   IX86_BUILTIN_CVTPS2PH256_MASK,
29952   IX86_BUILTIN_CVTPS2PH_MASK,
29953   IX86_BUILTIN_CVTPH2PS_MASK,
29954   IX86_BUILTIN_CVTPH2PS256_MASK,
29955   IX86_BUILTIN_PUNPCKHDQ128_MASK,
29956   IX86_BUILTIN_PUNPCKHDQ256_MASK,
29957   IX86_BUILTIN_PUNPCKHQDQ128_MASK,
29958   IX86_BUILTIN_PUNPCKHQDQ256_MASK,
29959   IX86_BUILTIN_PUNPCKLDQ128_MASK,
29960   IX86_BUILTIN_PUNPCKLDQ256_MASK,
29961   IX86_BUILTIN_PUNPCKLQDQ128_MASK,
29962   IX86_BUILTIN_PUNPCKLQDQ256_MASK,
29963   IX86_BUILTIN_PUNPCKHBW128_MASK,
29964   IX86_BUILTIN_PUNPCKHBW256_MASK,
29965   IX86_BUILTIN_PUNPCKHWD128_MASK,
29966   IX86_BUILTIN_PUNPCKHWD256_MASK,
29967   IX86_BUILTIN_PUNPCKLBW128_MASK,
29968   IX86_BUILTIN_PUNPCKLBW256_MASK,
29969   IX86_BUILTIN_PUNPCKLWD128_MASK,
29970   IX86_BUILTIN_PUNPCKLWD256_MASK,
29971   IX86_BUILTIN_PSLLVV16HI,
29972   IX86_BUILTIN_PSLLVV8HI,
29973   IX86_BUILTIN_PACKSSDW256_MASK,
29974   IX86_BUILTIN_PACKSSDW128_MASK,
29975   IX86_BUILTIN_PACKUSDW256_MASK,
29976   IX86_BUILTIN_PACKUSDW128_MASK,
29977   IX86_BUILTIN_PAVGB256_MASK,
29978   IX86_BUILTIN_PAVGW256_MASK,
29979   IX86_BUILTIN_PAVGB128_MASK,
29980   IX86_BUILTIN_PAVGW128_MASK,
29981   IX86_BUILTIN_VPERMVARSF256_MASK,
29982   IX86_BUILTIN_VPERMVARDF256_MASK,
29983   IX86_BUILTIN_VPERMDF256_MASK,
29984   IX86_BUILTIN_PABSB256_MASK,
29985   IX86_BUILTIN_PABSB128_MASK,
29986   IX86_BUILTIN_PABSW256_MASK,
29987   IX86_BUILTIN_PABSW128_MASK,
29988   IX86_BUILTIN_VPERMILVARPD_MASK,
29989   IX86_BUILTIN_VPERMILVARPS_MASK,
29990   IX86_BUILTIN_VPERMILVARPD256_MASK,
29991   IX86_BUILTIN_VPERMILVARPS256_MASK,
29992   IX86_BUILTIN_VPERMILPD_MASK,
29993   IX86_BUILTIN_VPERMILPS_MASK,
29994   IX86_BUILTIN_VPERMILPD256_MASK,
29995   IX86_BUILTIN_VPERMILPS256_MASK,
29996   IX86_BUILTIN_BLENDMQ256,
29997   IX86_BUILTIN_BLENDMD256,
29998   IX86_BUILTIN_BLENDMPD256,
29999   IX86_BUILTIN_BLENDMPS256,
30000   IX86_BUILTIN_BLENDMQ128,
30001   IX86_BUILTIN_BLENDMD128,
30002   IX86_BUILTIN_BLENDMPD128,
30003   IX86_BUILTIN_BLENDMPS128,
30004   IX86_BUILTIN_BLENDMW256,
30005   IX86_BUILTIN_BLENDMB256,
30006   IX86_BUILTIN_BLENDMW128,
30007   IX86_BUILTIN_BLENDMB128,
30008   IX86_BUILTIN_PMULLD256_MASK,
30009   IX86_BUILTIN_PMULLD128_MASK,
30010   IX86_BUILTIN_PMULUDQ256_MASK,
30011   IX86_BUILTIN_PMULDQ256_MASK,
30012   IX86_BUILTIN_PMULDQ128_MASK,
30013   IX86_BUILTIN_PMULUDQ128_MASK,
30014   IX86_BUILTIN_CVTPD2PS256_MASK,
30015   IX86_BUILTIN_CVTPD2PS_MASK,
30016   IX86_BUILTIN_VPERMVARSI256_MASK,
30017   IX86_BUILTIN_VPERMVARDI256_MASK,
30018   IX86_BUILTIN_VPERMDI256_MASK,
30019   IX86_BUILTIN_CMPQ256,
30020   IX86_BUILTIN_CMPD256,
30021   IX86_BUILTIN_UCMPQ256,
30022   IX86_BUILTIN_UCMPD256,
30023   IX86_BUILTIN_CMPB256,
30024   IX86_BUILTIN_CMPW256,
30025   IX86_BUILTIN_UCMPB256,
30026   IX86_BUILTIN_UCMPW256,
30027   IX86_BUILTIN_CMPPD256_MASK,
30028   IX86_BUILTIN_CMPPS256_MASK,
30029   IX86_BUILTIN_CMPQ128,
30030   IX86_BUILTIN_CMPD128,
30031   IX86_BUILTIN_UCMPQ128,
30032   IX86_BUILTIN_UCMPD128,
30033   IX86_BUILTIN_CMPB128,
30034   IX86_BUILTIN_CMPW128,
30035   IX86_BUILTIN_UCMPB128,
30036   IX86_BUILTIN_UCMPW128,
30037   IX86_BUILTIN_CMPPD128_MASK,
30038   IX86_BUILTIN_CMPPS128_MASK,
30039
30040   IX86_BUILTIN_GATHER3SIV8SF,
30041   IX86_BUILTIN_GATHER3SIV4SF,
30042   IX86_BUILTIN_GATHER3SIV4DF,
30043   IX86_BUILTIN_GATHER3SIV2DF,
30044   IX86_BUILTIN_GATHER3DIV8SF,
30045   IX86_BUILTIN_GATHER3DIV4SF,
30046   IX86_BUILTIN_GATHER3DIV4DF,
30047   IX86_BUILTIN_GATHER3DIV2DF,
30048   IX86_BUILTIN_GATHER3SIV8SI,
30049   IX86_BUILTIN_GATHER3SIV4SI,
30050   IX86_BUILTIN_GATHER3SIV4DI,
30051   IX86_BUILTIN_GATHER3SIV2DI,
30052   IX86_BUILTIN_GATHER3DIV8SI,
30053   IX86_BUILTIN_GATHER3DIV4SI,
30054   IX86_BUILTIN_GATHER3DIV4DI,
30055   IX86_BUILTIN_GATHER3DIV2DI,
30056   IX86_BUILTIN_SCATTERSIV8SF,
30057   IX86_BUILTIN_SCATTERSIV4SF,
30058   IX86_BUILTIN_SCATTERSIV4DF,
30059   IX86_BUILTIN_SCATTERSIV2DF,
30060   IX86_BUILTIN_SCATTERDIV8SF,
30061   IX86_BUILTIN_SCATTERDIV4SF,
30062   IX86_BUILTIN_SCATTERDIV4DF,
30063   IX86_BUILTIN_SCATTERDIV2DF,
30064   IX86_BUILTIN_SCATTERSIV8SI,
30065   IX86_BUILTIN_SCATTERSIV4SI,
30066   IX86_BUILTIN_SCATTERSIV4DI,
30067   IX86_BUILTIN_SCATTERSIV2DI,
30068   IX86_BUILTIN_SCATTERDIV8SI,
30069   IX86_BUILTIN_SCATTERDIV4SI,
30070   IX86_BUILTIN_SCATTERDIV4DI,
30071   IX86_BUILTIN_SCATTERDIV2DI,
30072
30073   /* AVX512DQ.  */
30074   IX86_BUILTIN_RANGESD128,
30075   IX86_BUILTIN_RANGESS128,
30076   IX86_BUILTIN_KUNPCKWD,
30077   IX86_BUILTIN_KUNPCKDQ,
30078   IX86_BUILTIN_BROADCASTF32x2_512,
30079   IX86_BUILTIN_BROADCASTI32x2_512,
30080   IX86_BUILTIN_BROADCASTF64X2_512,
30081   IX86_BUILTIN_BROADCASTI64X2_512,
30082   IX86_BUILTIN_BROADCASTF32X8_512,
30083   IX86_BUILTIN_BROADCASTI32X8_512,
30084   IX86_BUILTIN_EXTRACTF64X2_512,
30085   IX86_BUILTIN_EXTRACTF32X8,
30086   IX86_BUILTIN_EXTRACTI64X2_512,
30087   IX86_BUILTIN_EXTRACTI32X8,
30088   IX86_BUILTIN_REDUCEPD512_MASK,
30089   IX86_BUILTIN_REDUCEPS512_MASK,
30090   IX86_BUILTIN_PMULLQ512,
30091   IX86_BUILTIN_XORPD512,
30092   IX86_BUILTIN_XORPS512,
30093   IX86_BUILTIN_ORPD512,
30094   IX86_BUILTIN_ORPS512,
30095   IX86_BUILTIN_ANDPD512,
30096   IX86_BUILTIN_ANDPS512,
30097   IX86_BUILTIN_ANDNPD512,
30098   IX86_BUILTIN_ANDNPS512,
30099   IX86_BUILTIN_INSERTF32X8,
30100   IX86_BUILTIN_INSERTI32X8,
30101   IX86_BUILTIN_INSERTF64X2_512,
30102   IX86_BUILTIN_INSERTI64X2_512,
30103   IX86_BUILTIN_FPCLASSPD512,
30104   IX86_BUILTIN_FPCLASSPS512,
30105   IX86_BUILTIN_CVTD2MASK512,
30106   IX86_BUILTIN_CVTQ2MASK512,
30107   IX86_BUILTIN_CVTMASK2D512,
30108   IX86_BUILTIN_CVTMASK2Q512,
30109   IX86_BUILTIN_CVTPD2QQ512,
30110   IX86_BUILTIN_CVTPS2QQ512,
30111   IX86_BUILTIN_CVTPD2UQQ512,
30112   IX86_BUILTIN_CVTPS2UQQ512,
30113   IX86_BUILTIN_CVTQQ2PS512,
30114   IX86_BUILTIN_CVTUQQ2PS512,
30115   IX86_BUILTIN_CVTQQ2PD512,
30116   IX86_BUILTIN_CVTUQQ2PD512,
30117   IX86_BUILTIN_CVTTPS2QQ512,
30118   IX86_BUILTIN_CVTTPS2UQQ512,
30119   IX86_BUILTIN_CVTTPD2QQ512,
30120   IX86_BUILTIN_CVTTPD2UQQ512,
30121   IX86_BUILTIN_RANGEPS512,
30122   IX86_BUILTIN_RANGEPD512,
30123
30124   /* AVX512BW.  */
30125   IX86_BUILTIN_PACKUSDW512,
30126   IX86_BUILTIN_PACKSSDW512,
30127   IX86_BUILTIN_LOADDQUHI512_MASK,
30128   IX86_BUILTIN_LOADDQUQI512_MASK,
30129   IX86_BUILTIN_PSLLDQ512,
30130   IX86_BUILTIN_PSRLDQ512,
30131   IX86_BUILTIN_STOREDQUHI512_MASK,
30132   IX86_BUILTIN_STOREDQUQI512_MASK,
30133   IX86_BUILTIN_PALIGNR512,
30134   IX86_BUILTIN_PALIGNR512_MASK,
30135   IX86_BUILTIN_MOVDQUHI512_MASK,
30136   IX86_BUILTIN_MOVDQUQI512_MASK,
30137   IX86_BUILTIN_PSADBW512,
30138   IX86_BUILTIN_DBPSADBW512,
30139   IX86_BUILTIN_PBROADCASTB512,
30140   IX86_BUILTIN_PBROADCASTB512_GPR,
30141   IX86_BUILTIN_PBROADCASTW512,
30142   IX86_BUILTIN_PBROADCASTW512_GPR,
30143   IX86_BUILTIN_PMOVSXBW512_MASK,
30144   IX86_BUILTIN_PMOVZXBW512_MASK,
30145   IX86_BUILTIN_VPERMVARHI512_MASK,
30146   IX86_BUILTIN_VPERMT2VARHI512,
30147   IX86_BUILTIN_VPERMT2VARHI512_MASKZ,
30148   IX86_BUILTIN_VPERMI2VARHI512,
30149   IX86_BUILTIN_PAVGB512,
30150   IX86_BUILTIN_PAVGW512,
30151   IX86_BUILTIN_PADDB512,
30152   IX86_BUILTIN_PSUBB512,
30153   IX86_BUILTIN_PSUBSB512,
30154   IX86_BUILTIN_PADDSB512,
30155   IX86_BUILTIN_PSUBUSB512,
30156   IX86_BUILTIN_PADDUSB512,
30157   IX86_BUILTIN_PSUBW512,
30158   IX86_BUILTIN_PADDW512,
30159   IX86_BUILTIN_PSUBSW512,
30160   IX86_BUILTIN_PADDSW512,
30161   IX86_BUILTIN_PSUBUSW512,
30162   IX86_BUILTIN_PADDUSW512,
30163   IX86_BUILTIN_PMAXUW512,
30164   IX86_BUILTIN_PMAXSW512,
30165   IX86_BUILTIN_PMINUW512,
30166   IX86_BUILTIN_PMINSW512,
30167   IX86_BUILTIN_PMAXUB512,
30168   IX86_BUILTIN_PMAXSB512,
30169   IX86_BUILTIN_PMINUB512,
30170   IX86_BUILTIN_PMINSB512,
30171   IX86_BUILTIN_PMOVWB512,
30172   IX86_BUILTIN_PMOVSWB512,
30173   IX86_BUILTIN_PMOVUSWB512,
30174   IX86_BUILTIN_PMULHRSW512_MASK,
30175   IX86_BUILTIN_PMULHUW512_MASK,
30176   IX86_BUILTIN_PMULHW512_MASK,
30177   IX86_BUILTIN_PMULLW512_MASK,
30178   IX86_BUILTIN_PSLLWI512_MASK,
30179   IX86_BUILTIN_PSLLW512_MASK,
30180   IX86_BUILTIN_PACKSSWB512,
30181   IX86_BUILTIN_PACKUSWB512,
30182   IX86_BUILTIN_PSRAVV32HI,
30183   IX86_BUILTIN_PMADDUBSW512_MASK,
30184   IX86_BUILTIN_PMADDWD512_MASK,
30185   IX86_BUILTIN_PSRLVV32HI,
30186   IX86_BUILTIN_PUNPCKHBW512,
30187   IX86_BUILTIN_PUNPCKHWD512,
30188   IX86_BUILTIN_PUNPCKLBW512,
30189   IX86_BUILTIN_PUNPCKLWD512,
30190   IX86_BUILTIN_PSHUFB512,
30191   IX86_BUILTIN_PSHUFHW512,
30192   IX86_BUILTIN_PSHUFLW512,
30193   IX86_BUILTIN_PSRAWI512,
30194   IX86_BUILTIN_PSRAW512,
30195   IX86_BUILTIN_PSRLWI512,
30196   IX86_BUILTIN_PSRLW512,
30197   IX86_BUILTIN_CVTB2MASK512,
30198   IX86_BUILTIN_CVTW2MASK512,
30199   IX86_BUILTIN_CVTMASK2B512,
30200   IX86_BUILTIN_CVTMASK2W512,
30201   IX86_BUILTIN_PCMPEQB512_MASK,
30202   IX86_BUILTIN_PCMPEQW512_MASK,
30203   IX86_BUILTIN_PCMPGTB512_MASK,
30204   IX86_BUILTIN_PCMPGTW512_MASK,
30205   IX86_BUILTIN_PTESTMB512,
30206   IX86_BUILTIN_PTESTMW512,
30207   IX86_BUILTIN_PTESTNMB512,
30208   IX86_BUILTIN_PTESTNMW512,
30209   IX86_BUILTIN_PSLLVV32HI,
30210   IX86_BUILTIN_PABSB512,
30211   IX86_BUILTIN_PABSW512,
30212   IX86_BUILTIN_BLENDMW512,
30213   IX86_BUILTIN_BLENDMB512,
30214   IX86_BUILTIN_CMPB512,
30215   IX86_BUILTIN_CMPW512,
30216   IX86_BUILTIN_UCMPB512,
30217   IX86_BUILTIN_UCMPW512,
30218
30219   /* Alternate 4 and 8 element gather/scatter for the vectorizer
30220      where all operands are 32-byte or 64-byte wide respectively.  */
30221   IX86_BUILTIN_GATHERALTSIV4DF,
30222   IX86_BUILTIN_GATHERALTDIV8SF,
30223   IX86_BUILTIN_GATHERALTSIV4DI,
30224   IX86_BUILTIN_GATHERALTDIV8SI,
30225   IX86_BUILTIN_GATHER3ALTDIV16SF,
30226   IX86_BUILTIN_GATHER3ALTDIV16SI,
30227   IX86_BUILTIN_GATHER3ALTSIV4DF,
30228   IX86_BUILTIN_GATHER3ALTDIV8SF,
30229   IX86_BUILTIN_GATHER3ALTSIV4DI,
30230   IX86_BUILTIN_GATHER3ALTDIV8SI,
30231   IX86_BUILTIN_GATHER3ALTSIV8DF,
30232   IX86_BUILTIN_GATHER3ALTSIV8DI,
30233   IX86_BUILTIN_GATHER3DIV16SF,
30234   IX86_BUILTIN_GATHER3DIV16SI,
30235   IX86_BUILTIN_GATHER3DIV8DF,
30236   IX86_BUILTIN_GATHER3DIV8DI,
30237   IX86_BUILTIN_GATHER3SIV16SF,
30238   IX86_BUILTIN_GATHER3SIV16SI,
30239   IX86_BUILTIN_GATHER3SIV8DF,
30240   IX86_BUILTIN_GATHER3SIV8DI,
30241   IX86_BUILTIN_SCATTERDIV16SF,
30242   IX86_BUILTIN_SCATTERDIV16SI,
30243   IX86_BUILTIN_SCATTERDIV8DF,
30244   IX86_BUILTIN_SCATTERDIV8DI,
30245   IX86_BUILTIN_SCATTERSIV16SF,
30246   IX86_BUILTIN_SCATTERSIV16SI,
30247   IX86_BUILTIN_SCATTERSIV8DF,
30248   IX86_BUILTIN_SCATTERSIV8DI,
30249
30250   /* AVX512PF */
30251   IX86_BUILTIN_GATHERPFQPD,
30252   IX86_BUILTIN_GATHERPFDPS,
30253   IX86_BUILTIN_GATHERPFDPD,
30254   IX86_BUILTIN_GATHERPFQPS,
30255   IX86_BUILTIN_SCATTERPFDPD,
30256   IX86_BUILTIN_SCATTERPFDPS,
30257   IX86_BUILTIN_SCATTERPFQPD,
30258   IX86_BUILTIN_SCATTERPFQPS,
30259
30260   /* AVX-512ER */
30261   IX86_BUILTIN_EXP2PD_MASK,
30262   IX86_BUILTIN_EXP2PS_MASK,
30263   IX86_BUILTIN_EXP2PS,
30264   IX86_BUILTIN_RCP28PD,
30265   IX86_BUILTIN_RCP28PS,
30266   IX86_BUILTIN_RCP28SD,
30267   IX86_BUILTIN_RCP28SS,
30268   IX86_BUILTIN_RSQRT28PD,
30269   IX86_BUILTIN_RSQRT28PS,
30270   IX86_BUILTIN_RSQRT28SD,
30271   IX86_BUILTIN_RSQRT28SS,
30272
30273   /* AVX-512IFMA */
30274   IX86_BUILTIN_VPMADD52LUQ512,
30275   IX86_BUILTIN_VPMADD52HUQ512,
30276   IX86_BUILTIN_VPMADD52LUQ256,
30277   IX86_BUILTIN_VPMADD52HUQ256,
30278   IX86_BUILTIN_VPMADD52LUQ128,
30279   IX86_BUILTIN_VPMADD52HUQ128,
30280   IX86_BUILTIN_VPMADD52LUQ512_MASKZ,
30281   IX86_BUILTIN_VPMADD52HUQ512_MASKZ,
30282   IX86_BUILTIN_VPMADD52LUQ256_MASKZ,
30283   IX86_BUILTIN_VPMADD52HUQ256_MASKZ,
30284   IX86_BUILTIN_VPMADD52LUQ128_MASKZ,
30285   IX86_BUILTIN_VPMADD52HUQ128_MASKZ,
30286
30287   /* AVX-512VBMI */
30288   IX86_BUILTIN_VPMULTISHIFTQB512,
30289   IX86_BUILTIN_VPMULTISHIFTQB256,
30290   IX86_BUILTIN_VPMULTISHIFTQB128,
30291   IX86_BUILTIN_VPERMVARQI512_MASK,
30292   IX86_BUILTIN_VPERMT2VARQI512,
30293   IX86_BUILTIN_VPERMT2VARQI512_MASKZ,
30294   IX86_BUILTIN_VPERMI2VARQI512,
30295   IX86_BUILTIN_VPERMVARQI256_MASK,
30296   IX86_BUILTIN_VPERMVARQI128_MASK,
30297   IX86_BUILTIN_VPERMT2VARQI256,
30298   IX86_BUILTIN_VPERMT2VARQI256_MASKZ,
30299   IX86_BUILTIN_VPERMT2VARQI128,
30300   IX86_BUILTIN_VPERMT2VARQI128_MASKZ,
30301   IX86_BUILTIN_VPERMI2VARQI256,
30302   IX86_BUILTIN_VPERMI2VARQI128,
30303
30304   /* SHA builtins.  */
30305   IX86_BUILTIN_SHA1MSG1,
30306   IX86_BUILTIN_SHA1MSG2,
30307   IX86_BUILTIN_SHA1NEXTE,
30308   IX86_BUILTIN_SHA1RNDS4,
30309   IX86_BUILTIN_SHA256MSG1,
30310   IX86_BUILTIN_SHA256MSG2,
30311   IX86_BUILTIN_SHA256RNDS2,
30312
30313   /* CLWB instructions.  */
30314   IX86_BUILTIN_CLWB,
30315
30316   /* PCOMMIT instructions.  */
30317   IX86_BUILTIN_PCOMMIT,
30318
30319   /* CLFLUSHOPT instructions.  */
30320   IX86_BUILTIN_CLFLUSHOPT,
30321
30322   /* TFmode support builtins.  */
30323   IX86_BUILTIN_INFQ,
30324   IX86_BUILTIN_HUGE_VALQ,
30325   IX86_BUILTIN_FABSQ,
30326   IX86_BUILTIN_COPYSIGNQ,
30327
30328   /* Vectorizer support builtins.  */
30329   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512,
30330   IX86_BUILTIN_CPYSGNPS,
30331   IX86_BUILTIN_CPYSGNPD,
30332   IX86_BUILTIN_CPYSGNPS256,
30333   IX86_BUILTIN_CPYSGNPS512,
30334   IX86_BUILTIN_CPYSGNPD256,
30335   IX86_BUILTIN_CPYSGNPD512,
30336   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512,
30337   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512,
30338
30339
30340   /* FMA4 instructions.  */
30341   IX86_BUILTIN_VFMADDSS,
30342   IX86_BUILTIN_VFMADDSD,
30343   IX86_BUILTIN_VFMADDPS,
30344   IX86_BUILTIN_VFMADDPD,
30345   IX86_BUILTIN_VFMADDPS256,
30346   IX86_BUILTIN_VFMADDPD256,
30347   IX86_BUILTIN_VFMADDSUBPS,
30348   IX86_BUILTIN_VFMADDSUBPD,
30349   IX86_BUILTIN_VFMADDSUBPS256,
30350   IX86_BUILTIN_VFMADDSUBPD256,
30351
30352   /* FMA3 instructions.  */
30353   IX86_BUILTIN_VFMADDSS3,
30354   IX86_BUILTIN_VFMADDSD3,
30355
30356   /* XOP instructions.  */
30357   IX86_BUILTIN_VPCMOV,
30358   IX86_BUILTIN_VPCMOV_V2DI,
30359   IX86_BUILTIN_VPCMOV_V4SI,
30360   IX86_BUILTIN_VPCMOV_V8HI,
30361   IX86_BUILTIN_VPCMOV_V16QI,
30362   IX86_BUILTIN_VPCMOV_V4SF,
30363   IX86_BUILTIN_VPCMOV_V2DF,
30364   IX86_BUILTIN_VPCMOV256,
30365   IX86_BUILTIN_VPCMOV_V4DI256,
30366   IX86_BUILTIN_VPCMOV_V8SI256,
30367   IX86_BUILTIN_VPCMOV_V16HI256,
30368   IX86_BUILTIN_VPCMOV_V32QI256,
30369   IX86_BUILTIN_VPCMOV_V8SF256,
30370   IX86_BUILTIN_VPCMOV_V4DF256,
30371
30372   IX86_BUILTIN_VPPERM,
30373
30374   IX86_BUILTIN_VPMACSSWW,
30375   IX86_BUILTIN_VPMACSWW,
30376   IX86_BUILTIN_VPMACSSWD,
30377   IX86_BUILTIN_VPMACSWD,
30378   IX86_BUILTIN_VPMACSSDD,
30379   IX86_BUILTIN_VPMACSDD,
30380   IX86_BUILTIN_VPMACSSDQL,
30381   IX86_BUILTIN_VPMACSSDQH,
30382   IX86_BUILTIN_VPMACSDQL,
30383   IX86_BUILTIN_VPMACSDQH,
30384   IX86_BUILTIN_VPMADCSSWD,
30385   IX86_BUILTIN_VPMADCSWD,
30386
30387   IX86_BUILTIN_VPHADDBW,
30388   IX86_BUILTIN_VPHADDBD,
30389   IX86_BUILTIN_VPHADDBQ,
30390   IX86_BUILTIN_VPHADDWD,
30391   IX86_BUILTIN_VPHADDWQ,
30392   IX86_BUILTIN_VPHADDDQ,
30393   IX86_BUILTIN_VPHADDUBW,
30394   IX86_BUILTIN_VPHADDUBD,
30395   IX86_BUILTIN_VPHADDUBQ,
30396   IX86_BUILTIN_VPHADDUWD,
30397   IX86_BUILTIN_VPHADDUWQ,
30398   IX86_BUILTIN_VPHADDUDQ,
30399   IX86_BUILTIN_VPHSUBBW,
30400   IX86_BUILTIN_VPHSUBWD,
30401   IX86_BUILTIN_VPHSUBDQ,
30402
30403   IX86_BUILTIN_VPROTB,
30404   IX86_BUILTIN_VPROTW,
30405   IX86_BUILTIN_VPROTD,
30406   IX86_BUILTIN_VPROTQ,
30407   IX86_BUILTIN_VPROTB_IMM,
30408   IX86_BUILTIN_VPROTW_IMM,
30409   IX86_BUILTIN_VPROTD_IMM,
30410   IX86_BUILTIN_VPROTQ_IMM,
30411
30412   IX86_BUILTIN_VPSHLB,
30413   IX86_BUILTIN_VPSHLW,
30414   IX86_BUILTIN_VPSHLD,
30415   IX86_BUILTIN_VPSHLQ,
30416   IX86_BUILTIN_VPSHAB,
30417   IX86_BUILTIN_VPSHAW,
30418   IX86_BUILTIN_VPSHAD,
30419   IX86_BUILTIN_VPSHAQ,
30420
30421   IX86_BUILTIN_VFRCZSS,
30422   IX86_BUILTIN_VFRCZSD,
30423   IX86_BUILTIN_VFRCZPS,
30424   IX86_BUILTIN_VFRCZPD,
30425   IX86_BUILTIN_VFRCZPS256,
30426   IX86_BUILTIN_VFRCZPD256,
30427
30428   IX86_BUILTIN_VPCOMEQUB,
30429   IX86_BUILTIN_VPCOMNEUB,
30430   IX86_BUILTIN_VPCOMLTUB,
30431   IX86_BUILTIN_VPCOMLEUB,
30432   IX86_BUILTIN_VPCOMGTUB,
30433   IX86_BUILTIN_VPCOMGEUB,
30434   IX86_BUILTIN_VPCOMFALSEUB,
30435   IX86_BUILTIN_VPCOMTRUEUB,
30436
30437   IX86_BUILTIN_VPCOMEQUW,
30438   IX86_BUILTIN_VPCOMNEUW,
30439   IX86_BUILTIN_VPCOMLTUW,
30440   IX86_BUILTIN_VPCOMLEUW,
30441   IX86_BUILTIN_VPCOMGTUW,
30442   IX86_BUILTIN_VPCOMGEUW,
30443   IX86_BUILTIN_VPCOMFALSEUW,
30444   IX86_BUILTIN_VPCOMTRUEUW,
30445
30446   IX86_BUILTIN_VPCOMEQUD,
30447   IX86_BUILTIN_VPCOMNEUD,
30448   IX86_BUILTIN_VPCOMLTUD,
30449   IX86_BUILTIN_VPCOMLEUD,
30450   IX86_BUILTIN_VPCOMGTUD,
30451   IX86_BUILTIN_VPCOMGEUD,
30452   IX86_BUILTIN_VPCOMFALSEUD,
30453   IX86_BUILTIN_VPCOMTRUEUD,
30454
30455   IX86_BUILTIN_VPCOMEQUQ,
30456   IX86_BUILTIN_VPCOMNEUQ,
30457   IX86_BUILTIN_VPCOMLTUQ,
30458   IX86_BUILTIN_VPCOMLEUQ,
30459   IX86_BUILTIN_VPCOMGTUQ,
30460   IX86_BUILTIN_VPCOMGEUQ,
30461   IX86_BUILTIN_VPCOMFALSEUQ,
30462   IX86_BUILTIN_VPCOMTRUEUQ,
30463
30464   IX86_BUILTIN_VPCOMEQB,
30465   IX86_BUILTIN_VPCOMNEB,
30466   IX86_BUILTIN_VPCOMLTB,
30467   IX86_BUILTIN_VPCOMLEB,
30468   IX86_BUILTIN_VPCOMGTB,
30469   IX86_BUILTIN_VPCOMGEB,
30470   IX86_BUILTIN_VPCOMFALSEB,
30471   IX86_BUILTIN_VPCOMTRUEB,
30472
30473   IX86_BUILTIN_VPCOMEQW,
30474   IX86_BUILTIN_VPCOMNEW,
30475   IX86_BUILTIN_VPCOMLTW,
30476   IX86_BUILTIN_VPCOMLEW,
30477   IX86_BUILTIN_VPCOMGTW,
30478   IX86_BUILTIN_VPCOMGEW,
30479   IX86_BUILTIN_VPCOMFALSEW,
30480   IX86_BUILTIN_VPCOMTRUEW,
30481
30482   IX86_BUILTIN_VPCOMEQD,
30483   IX86_BUILTIN_VPCOMNED,
30484   IX86_BUILTIN_VPCOMLTD,
30485   IX86_BUILTIN_VPCOMLED,
30486   IX86_BUILTIN_VPCOMGTD,
30487   IX86_BUILTIN_VPCOMGED,
30488   IX86_BUILTIN_VPCOMFALSED,
30489   IX86_BUILTIN_VPCOMTRUED,
30490
30491   IX86_BUILTIN_VPCOMEQQ,
30492   IX86_BUILTIN_VPCOMNEQ,
30493   IX86_BUILTIN_VPCOMLTQ,
30494   IX86_BUILTIN_VPCOMLEQ,
30495   IX86_BUILTIN_VPCOMGTQ,
30496   IX86_BUILTIN_VPCOMGEQ,
30497   IX86_BUILTIN_VPCOMFALSEQ,
30498   IX86_BUILTIN_VPCOMTRUEQ,
30499
30500   /* LWP instructions.  */
30501   IX86_BUILTIN_LLWPCB,
30502   IX86_BUILTIN_SLWPCB,
30503   IX86_BUILTIN_LWPVAL32,
30504   IX86_BUILTIN_LWPVAL64,
30505   IX86_BUILTIN_LWPINS32,
30506   IX86_BUILTIN_LWPINS64,
30507
30508   IX86_BUILTIN_CLZS,
30509
30510   /* RTM */
30511   IX86_BUILTIN_XBEGIN,
30512   IX86_BUILTIN_XEND,
30513   IX86_BUILTIN_XABORT,
30514   IX86_BUILTIN_XTEST,
30515
30516   /* MPX */
30517   IX86_BUILTIN_BNDMK,
30518   IX86_BUILTIN_BNDSTX,
30519   IX86_BUILTIN_BNDLDX,
30520   IX86_BUILTIN_BNDCL,
30521   IX86_BUILTIN_BNDCU,
30522   IX86_BUILTIN_BNDRET,
30523   IX86_BUILTIN_BNDNARROW,
30524   IX86_BUILTIN_BNDINT,
30525   IX86_BUILTIN_SIZEOF,
30526   IX86_BUILTIN_BNDLOWER,
30527   IX86_BUILTIN_BNDUPPER,
30528
30529   /* BMI instructions.  */
30530   IX86_BUILTIN_BEXTR32,
30531   IX86_BUILTIN_BEXTR64,
30532   IX86_BUILTIN_CTZS,
30533
30534   /* TBM instructions.  */
30535   IX86_BUILTIN_BEXTRI32,
30536   IX86_BUILTIN_BEXTRI64,
30537
30538   /* BMI2 instructions. */
30539   IX86_BUILTIN_BZHI32,
30540   IX86_BUILTIN_BZHI64,
30541   IX86_BUILTIN_PDEP32,
30542   IX86_BUILTIN_PDEP64,
30543   IX86_BUILTIN_PEXT32,
30544   IX86_BUILTIN_PEXT64,
30545
30546   /* ADX instructions.  */
30547   IX86_BUILTIN_ADDCARRYX32,
30548   IX86_BUILTIN_ADDCARRYX64,
30549
30550   /* SBB instructions.  */
30551   IX86_BUILTIN_SBB32,
30552   IX86_BUILTIN_SBB64,
30553
30554   /* FSGSBASE instructions.  */
30555   IX86_BUILTIN_RDFSBASE32,
30556   IX86_BUILTIN_RDFSBASE64,
30557   IX86_BUILTIN_RDGSBASE32,
30558   IX86_BUILTIN_RDGSBASE64,
30559   IX86_BUILTIN_WRFSBASE32,
30560   IX86_BUILTIN_WRFSBASE64,
30561   IX86_BUILTIN_WRGSBASE32,
30562   IX86_BUILTIN_WRGSBASE64,
30563
30564   /* RDRND instructions.  */
30565   IX86_BUILTIN_RDRAND16_STEP,
30566   IX86_BUILTIN_RDRAND32_STEP,
30567   IX86_BUILTIN_RDRAND64_STEP,
30568
30569   /* RDSEED instructions.  */
30570   IX86_BUILTIN_RDSEED16_STEP,
30571   IX86_BUILTIN_RDSEED32_STEP,
30572   IX86_BUILTIN_RDSEED64_STEP,
30573
30574   /* F16C instructions.  */
30575   IX86_BUILTIN_CVTPH2PS,
30576   IX86_BUILTIN_CVTPH2PS256,
30577   IX86_BUILTIN_CVTPS2PH,
30578   IX86_BUILTIN_CVTPS2PH256,
30579
30580   /* MONITORX and MWAITX instrucions.   */
30581   IX86_BUILTIN_MONITORX,
30582   IX86_BUILTIN_MWAITX,
30583
30584   /* CFString built-in for darwin */
30585   IX86_BUILTIN_CFSTRING,
30586
30587   /* Builtins to get CPU type and supported features. */
30588   IX86_BUILTIN_CPU_INIT,
30589   IX86_BUILTIN_CPU_IS,
30590   IX86_BUILTIN_CPU_SUPPORTS,
30591
30592   /* Read/write FLAGS register built-ins.  */
30593   IX86_BUILTIN_READ_FLAGS,
30594   IX86_BUILTIN_WRITE_FLAGS,
30595
30596   IX86_BUILTIN_MAX
30597 };
30598
30599 /* Table for the ix86 builtin decls.  */
30600 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
30601
30602 /* Table of all of the builtin functions that are possible with different ISA's
30603    but are waiting to be built until a function is declared to use that
30604    ISA.  */
30605 struct builtin_isa {
30606   const char *name;             /* function name */
30607   enum ix86_builtin_func_type tcode; /* type to use in the declaration */
30608   HOST_WIDE_INT isa;            /* isa_flags this builtin is defined for */
30609   bool const_p;                 /* true if the declaration is constant */
30610   bool leaf_p;                  /* true if the declaration has leaf attribute */
30611   bool nothrow_p;               /* true if the declaration has nothrow attribute */
30612   bool set_and_not_built_p;
30613 };
30614
30615 static struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
30616
30617 /* Bits that can still enable any inclusion of a builtin.  */
30618 static HOST_WIDE_INT deferred_isa_values = 0;
30619
30620 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
30621    of which isa_flags to use in the ix86_builtins_isa array.  Stores the
30622    function decl in the ix86_builtins array.  Returns the function decl or
30623    NULL_TREE, if the builtin was not added.
30624
30625    If the front end has a special hook for builtin functions, delay adding
30626    builtin functions that aren't in the current ISA until the ISA is changed
30627    with function specific optimization.  Doing so, can save about 300K for the
30628    default compiler.  When the builtin is expanded, check at that time whether
30629    it is valid.
30630
30631    If the front end doesn't have a special hook, record all builtins, even if
30632    it isn't an instruction set in the current ISA in case the user uses
30633    function specific options for a different ISA, so that we don't get scope
30634    errors if a builtin is added in the middle of a function scope.  */
30635
30636 static inline tree
30637 def_builtin (HOST_WIDE_INT mask, const char *name,
30638              enum ix86_builtin_func_type tcode,
30639              enum ix86_builtins code)
30640 {
30641   tree decl = NULL_TREE;
30642
30643   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
30644     {
30645       ix86_builtins_isa[(int) code].isa = mask;
30646
30647       mask &= ~OPTION_MASK_ISA_64BIT;
30648       if (mask == 0
30649           || (mask & ix86_isa_flags) != 0
30650           || (lang_hooks.builtin_function
30651               == lang_hooks.builtin_function_ext_scope))
30652
30653         {
30654           tree type = ix86_get_builtin_func_type (tcode);
30655           decl = add_builtin_function (name, type, code, BUILT_IN_MD,
30656                                        NULL, NULL_TREE);
30657           ix86_builtins[(int) code] = decl;
30658           ix86_builtins_isa[(int) code].set_and_not_built_p = false;
30659         }
30660       else
30661         {
30662           /* Just a MASK where set_and_not_built_p == true can potentially
30663              include a builtin.  */
30664           deferred_isa_values |= mask;
30665           ix86_builtins[(int) code] = NULL_TREE;
30666           ix86_builtins_isa[(int) code].tcode = tcode;
30667           ix86_builtins_isa[(int) code].name = name;
30668           ix86_builtins_isa[(int) code].leaf_p = false;
30669           ix86_builtins_isa[(int) code].nothrow_p = false;
30670           ix86_builtins_isa[(int) code].const_p = false;
30671           ix86_builtins_isa[(int) code].set_and_not_built_p = true;
30672         }
30673     }
30674
30675   return decl;
30676 }
30677
30678 /* Like def_builtin, but also marks the function decl "const".  */
30679
30680 static inline tree
30681 def_builtin_const (HOST_WIDE_INT mask, const char *name,
30682                    enum ix86_builtin_func_type tcode, enum ix86_builtins code)
30683 {
30684   tree decl = def_builtin (mask, name, tcode, code);
30685   if (decl)
30686     TREE_READONLY (decl) = 1;
30687   else
30688     ix86_builtins_isa[(int) code].const_p = true;
30689
30690   return decl;
30691 }
30692
30693 /* Add any new builtin functions for a given ISA that may not have been
30694    declared.  This saves a bit of space compared to adding all of the
30695    declarations to the tree, even if we didn't use them.  */
30696
30697 static void
30698 ix86_add_new_builtins (HOST_WIDE_INT isa)
30699 {
30700   if ((isa & deferred_isa_values) == 0)
30701     return;
30702
30703   /* Bits in ISA value can be removed from potential isa values.  */
30704   deferred_isa_values &= ~isa;
30705
30706   int i;
30707   tree saved_current_target_pragma = current_target_pragma;
30708   current_target_pragma = NULL_TREE;
30709
30710   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
30711     {
30712       if ((ix86_builtins_isa[i].isa & isa) != 0
30713           && ix86_builtins_isa[i].set_and_not_built_p)
30714         {
30715           tree decl, type;
30716
30717           /* Don't define the builtin again.  */
30718           ix86_builtins_isa[i].set_and_not_built_p = false;
30719
30720           type = ix86_get_builtin_func_type (ix86_builtins_isa[i].tcode);
30721           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
30722                                                  type, i, BUILT_IN_MD, NULL,
30723                                                  NULL_TREE);
30724
30725           ix86_builtins[i] = decl;
30726           if (ix86_builtins_isa[i].const_p)
30727             TREE_READONLY (decl) = 1;
30728           if (ix86_builtins_isa[i].leaf_p)
30729             DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
30730                                                       NULL_TREE);
30731           if (ix86_builtins_isa[i].nothrow_p)
30732             TREE_NOTHROW (decl) = 1;
30733         }
30734     }
30735
30736   current_target_pragma = saved_current_target_pragma;
30737 }
30738
30739 /* Bits for builtin_description.flag.  */
30740
30741 /* Set when we don't support the comparison natively, and should
30742    swap_comparison in order to support it.  */
30743 #define BUILTIN_DESC_SWAP_OPERANDS      1
30744
30745 struct builtin_description
30746 {
30747   const HOST_WIDE_INT mask;
30748   const enum insn_code icode;
30749   const char *const name;
30750   const enum ix86_builtins code;
30751   const enum rtx_code comparison;
30752   const int flag;
30753 };
30754
30755 static const struct builtin_description bdesc_comi[] =
30756 {
30757   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
30758   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
30759   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
30760   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
30761   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
30762   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
30763   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
30764   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
30765   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
30766   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
30767   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
30768   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
30769   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
30770   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
30771   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
30772   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
30773   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
30774   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
30775   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
30776   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
30777   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
30778   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
30779   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
30780   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
30781 };
30782
30783 static const struct builtin_description bdesc_pcmpestr[] =
30784 {
30785   /* SSE4.2 */
30786   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
30787   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
30788   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
30789   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
30790   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
30791   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
30792   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
30793 };
30794
30795 static const struct builtin_description bdesc_pcmpistr[] =
30796 {
30797   /* SSE4.2 */
30798   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
30799   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
30800   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
30801   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
30802   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
30803   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
30804   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
30805 };
30806
30807 /* Special builtins with variable number of arguments.  */
30808 static const struct builtin_description bdesc_special_args[] =
30809 {
30810   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdtsc", IX86_BUILTIN_RDTSC, UNKNOWN, (int) UINT64_FTYPE_VOID },
30811   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdtscp", IX86_BUILTIN_RDTSCP, UNKNOWN, (int) UINT64_FTYPE_PUNSIGNED },
30812   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_pause, "__builtin_ia32_pause", IX86_BUILTIN_PAUSE, UNKNOWN, (int) VOID_FTYPE_VOID },
30813
30814   /* 80387 (for use internally for atomic compound assignment).  */
30815   { 0, CODE_FOR_fnstenv, "__builtin_ia32_fnstenv", IX86_BUILTIN_FNSTENV, UNKNOWN, (int) VOID_FTYPE_PVOID },
30816   { 0, CODE_FOR_fldenv, "__builtin_ia32_fldenv", IX86_BUILTIN_FLDENV, UNKNOWN, (int) VOID_FTYPE_PCVOID },
30817   { 0, CODE_FOR_fnstsw, "__builtin_ia32_fnstsw", IX86_BUILTIN_FNSTSW, UNKNOWN, (int) USHORT_FTYPE_VOID },
30818   { 0, CODE_FOR_fnclex, "__builtin_ia32_fnclex", IX86_BUILTIN_FNCLEX, UNKNOWN, (int) VOID_FTYPE_VOID },
30819
30820   /* MMX */
30821   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
30822
30823   /* 3DNow! */
30824   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
30825
30826   /* FXSR, XSAVE, XSAVEOPT, XSAVEC and XSAVES.  */
30827   { OPTION_MASK_ISA_FXSR, CODE_FOR_nothing, "__builtin_ia32_fxsave", IX86_BUILTIN_FXSAVE, UNKNOWN, (int) VOID_FTYPE_PVOID },
30828   { OPTION_MASK_ISA_FXSR, CODE_FOR_nothing, "__builtin_ia32_fxrstor", IX86_BUILTIN_FXRSTOR, UNKNOWN, (int) VOID_FTYPE_PVOID },
30829   { OPTION_MASK_ISA_XSAVE, CODE_FOR_nothing, "__builtin_ia32_xsave", IX86_BUILTIN_XSAVE, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30830   { OPTION_MASK_ISA_XSAVE, CODE_FOR_nothing, "__builtin_ia32_xrstor", IX86_BUILTIN_XRSTOR, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30831   { OPTION_MASK_ISA_XSAVEOPT, CODE_FOR_nothing, "__builtin_ia32_xsaveopt", IX86_BUILTIN_XSAVEOPT, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30832   { OPTION_MASK_ISA_XSAVES, CODE_FOR_nothing, "__builtin_ia32_xsaves", IX86_BUILTIN_XSAVES, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30833   { OPTION_MASK_ISA_XSAVES, CODE_FOR_nothing, "__builtin_ia32_xrstors", IX86_BUILTIN_XRSTORS, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30834   { OPTION_MASK_ISA_XSAVEC, CODE_FOR_nothing, "__builtin_ia32_xsavec", IX86_BUILTIN_XSAVEC, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30835
30836   { OPTION_MASK_ISA_FXSR | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_fxsave64", IX86_BUILTIN_FXSAVE64, UNKNOWN, (int) VOID_FTYPE_PVOID },
30837   { OPTION_MASK_ISA_FXSR | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_fxrstor64", IX86_BUILTIN_FXRSTOR64, UNKNOWN, (int) VOID_FTYPE_PVOID },
30838   { OPTION_MASK_ISA_XSAVE | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsave64", IX86_BUILTIN_XSAVE64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30839   { OPTION_MASK_ISA_XSAVE | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xrstor64", IX86_BUILTIN_XRSTOR64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30840   { OPTION_MASK_ISA_XSAVEOPT | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsaveopt64", IX86_BUILTIN_XSAVEOPT64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30841   { OPTION_MASK_ISA_XSAVES | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsaves64", IX86_BUILTIN_XSAVES64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30842   { OPTION_MASK_ISA_XSAVES | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xrstors64", IX86_BUILTIN_XRSTORS64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30843   { OPTION_MASK_ISA_XSAVEC | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsavec64", IX86_BUILTIN_XSAVEC64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30844
30845   /* SSE */
30846   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storeups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30847   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30848   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
30849
30850   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
30851   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
30852   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
30853   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
30854
30855   /* SSE or 3DNow!A  */
30856   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30857   { 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 },
30858
30859   /* SSE2 */
30860   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30861   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30862   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_storeupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30863   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_storedquv16qi, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
30864   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30865   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
30866   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntisi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
30867   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_movntidi, "__builtin_ia32_movnti64", IX86_BUILTIN_MOVNTI64, UNKNOWN, (int) VOID_FTYPE_PLONGLONG_LONGLONG },
30868   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
30869   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loaddquv16qi, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
30870
30871   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
30872   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
30873
30874   /* SSE3 */
30875   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
30876
30877   /* SSE4.1 */
30878   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
30879
30880   /* SSE4A */
30881   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30882   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30883
30884   /* AVX */
30885   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
30886   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, "__builtin_ia32_vzeroupper", IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
30887
30888   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv4sf, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
30889   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv4df, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
30890   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv8sf, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
30891   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_v4df, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
30892   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_v8sf, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
30893
30894   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loadupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
30895   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loadups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
30896   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storeupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
30897   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storeups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
30898   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loaddquv32qi, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
30899   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storedquv32qi, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
30900   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
30901
30902   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
30903   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
30904   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
30905
30906   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DI },
30907   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SI },
30908   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DI },
30909   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SI },
30910   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DI_V2DF },
30911   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SI_V4SF },
30912   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DI_V4DF },
30913   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SI_V8SF },
30914
30915   /* AVX2 */
30916   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_movntdqa, "__builtin_ia32_movntdqa256", IX86_BUILTIN_MOVNTDQA256, UNKNOWN, (int) V4DI_FTYPE_PV4DI },
30917   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadd, "__builtin_ia32_maskloadd", IX86_BUILTIN_MASKLOADD, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI },
30918   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadq, "__builtin_ia32_maskloadq", IX86_BUILTIN_MASKLOADQ, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI },
30919   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadd256, "__builtin_ia32_maskloadd256", IX86_BUILTIN_MASKLOADD256, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI },
30920   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadq256, "__builtin_ia32_maskloadq256", IX86_BUILTIN_MASKLOADQ256, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI },
30921   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstored, "__builtin_ia32_maskstored", IX86_BUILTIN_MASKSTORED, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_V4SI },
30922   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstoreq, "__builtin_ia32_maskstoreq", IX86_BUILTIN_MASKSTOREQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_V2DI },
30923   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstored256, "__builtin_ia32_maskstored256", IX86_BUILTIN_MASKSTORED256, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_V8SI },
30924   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstoreq256, "__builtin_ia32_maskstoreq256", IX86_BUILTIN_MASKSTOREQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_V4DI },
30925
30926   /* AVX512F */
30927   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev16sf_mask, "__builtin_ia32_compressstoresf512_mask", IX86_BUILTIN_COMPRESSPSSTORE512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30928   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev16si_mask, "__builtin_ia32_compressstoresi512_mask", IX86_BUILTIN_PCOMPRESSDSTORE512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30929   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev8df_mask, "__builtin_ia32_compressstoredf512_mask", IX86_BUILTIN_COMPRESSPDSTORE512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30930   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev8di_mask, "__builtin_ia32_compressstoredi512_mask", IX86_BUILTIN_PCOMPRESSQSTORE512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30931   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_mask, "__builtin_ia32_expandloadsf512_mask", IX86_BUILTIN_EXPANDPSLOAD512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30932   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_maskz, "__builtin_ia32_expandloadsf512_maskz", IX86_BUILTIN_EXPANDPSLOAD512Z, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30933   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_mask, "__builtin_ia32_expandloadsi512_mask", IX86_BUILTIN_PEXPANDDLOAD512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30934   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_maskz, "__builtin_ia32_expandloadsi512_maskz", IX86_BUILTIN_PEXPANDDLOAD512Z, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30935   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_mask, "__builtin_ia32_expandloaddf512_mask", IX86_BUILTIN_EXPANDPDLOAD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30936   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_maskz, "__builtin_ia32_expandloaddf512_maskz", IX86_BUILTIN_EXPANDPDLOAD512Z, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30937   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_mask, "__builtin_ia32_expandloaddi512_mask", IX86_BUILTIN_PEXPANDQLOAD512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30938   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_maskz, "__builtin_ia32_expandloaddi512_maskz", IX86_BUILTIN_PEXPANDQLOAD512Z, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30939   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loaddquv16si_mask, "__builtin_ia32_loaddqusi512_mask", IX86_BUILTIN_LOADDQUSI512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30940   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loaddquv8di_mask, "__builtin_ia32_loaddqudi512_mask", IX86_BUILTIN_LOADDQUDI512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30941   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadupd512_mask, "__builtin_ia32_loadupd512_mask", IX86_BUILTIN_LOADUPD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30942   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadups512_mask, "__builtin_ia32_loadups512_mask", IX86_BUILTIN_LOADUPS512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30943   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16sf_mask, "__builtin_ia32_loadaps512_mask", IX86_BUILTIN_LOADAPS512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30944   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16si_mask, "__builtin_ia32_movdqa32load512_mask", IX86_BUILTIN_MOVDQA32LOAD512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30945   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8df_mask, "__builtin_ia32_loadapd512_mask", IX86_BUILTIN_LOADAPD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30946   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8di_mask, "__builtin_ia32_movdqa64load512_mask", IX86_BUILTIN_MOVDQA64LOAD512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30947   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv16sf, "__builtin_ia32_movntps512", IX86_BUILTIN_MOVNTPS512, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V16SF },
30948   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv8df, "__builtin_ia32_movntpd512", IX86_BUILTIN_MOVNTPD512, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V8DF },
30949   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv8di, "__builtin_ia32_movntdq512", IX86_BUILTIN_MOVNTDQ512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI },
30950   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntdqa, "__builtin_ia32_movntdqa512", IX86_BUILTIN_MOVNTDQA512, UNKNOWN, (int) V8DI_FTYPE_PV8DI },
30951   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storedquv16si_mask, "__builtin_ia32_storedqusi512_mask", IX86_BUILTIN_STOREDQUSI512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30952   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storedquv8di_mask, "__builtin_ia32_storedqudi512_mask", IX86_BUILTIN_STOREDQUDI512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30953   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storeupd512_mask, "__builtin_ia32_storeupd512_mask", IX86_BUILTIN_STOREUPD512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30954   { 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 },
30955   { 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 },
30956   { 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 },
30957   { 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 },
30958   { 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 },
30959   { 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 },
30960   { 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 },
30961   { 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 },
30962   { 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 },
30963   { 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 },
30964   { 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 },
30965   { 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 },
30966   { 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 },
30967   { 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 },
30968   { 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 },
30969   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storeups512_mask, "__builtin_ia32_storeups512_mask", IX86_BUILTIN_STOREUPS512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30970   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev16sf_mask, "__builtin_ia32_storeaps512_mask", IX86_BUILTIN_STOREAPS512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30971   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev16si_mask, "__builtin_ia32_movdqa32store512_mask", IX86_BUILTIN_MOVDQA32STORE512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30972   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev8df_mask, "__builtin_ia32_storeapd512_mask", IX86_BUILTIN_STOREAPD512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30973   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev8di_mask, "__builtin_ia32_movdqa64store512_mask", IX86_BUILTIN_MOVDQA64STORE512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30974
30975   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_llwpcb, "__builtin_ia32_llwpcb", IX86_BUILTIN_LLWPCB, UNKNOWN, (int) VOID_FTYPE_PVOID },
30976   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_slwpcb, "__builtin_ia32_slwpcb", IX86_BUILTIN_SLWPCB, UNKNOWN, (int) PVOID_FTYPE_VOID },
30977   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpvalsi3, "__builtin_ia32_lwpval32", IX86_BUILTIN_LWPVAL32, UNKNOWN, (int) VOID_FTYPE_UINT_UINT_UINT },
30978   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpvaldi3, "__builtin_ia32_lwpval64", IX86_BUILTIN_LWPVAL64, UNKNOWN, (int) VOID_FTYPE_UINT64_UINT_UINT },
30979   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinssi3, "__builtin_ia32_lwpins32", IX86_BUILTIN_LWPINS32, UNKNOWN, (int) UCHAR_FTYPE_UINT_UINT_UINT },
30980   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinsdi3, "__builtin_ia32_lwpins64", IX86_BUILTIN_LWPINS64, UNKNOWN, (int) UCHAR_FTYPE_UINT64_UINT_UINT },
30981
30982   /* FSGSBASE */
30983   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdfsbasesi, "__builtin_ia32_rdfsbase32", IX86_BUILTIN_RDFSBASE32, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30984   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdfsbasedi, "__builtin_ia32_rdfsbase64", IX86_BUILTIN_RDFSBASE64, UNKNOWN, (int) UINT64_FTYPE_VOID },
30985   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdgsbasesi, "__builtin_ia32_rdgsbase32", IX86_BUILTIN_RDGSBASE32, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30986   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdgsbasedi, "__builtin_ia32_rdgsbase64", IX86_BUILTIN_RDGSBASE64, UNKNOWN, (int) UINT64_FTYPE_VOID },
30987   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrfsbasesi, "__builtin_ia32_wrfsbase32", IX86_BUILTIN_WRFSBASE32, UNKNOWN, (int) VOID_FTYPE_UNSIGNED },
30988   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrfsbasedi, "__builtin_ia32_wrfsbase64", IX86_BUILTIN_WRFSBASE64, UNKNOWN, (int) VOID_FTYPE_UINT64 },
30989   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrgsbasesi, "__builtin_ia32_wrgsbase32", IX86_BUILTIN_WRGSBASE32, UNKNOWN, (int) VOID_FTYPE_UNSIGNED },
30990   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrgsbasedi, "__builtin_ia32_wrgsbase64", IX86_BUILTIN_WRGSBASE64, UNKNOWN, (int) VOID_FTYPE_UINT64 },
30991
30992   /* RTM */
30993   { OPTION_MASK_ISA_RTM, CODE_FOR_xbegin, "__builtin_ia32_xbegin", IX86_BUILTIN_XBEGIN, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30994   { OPTION_MASK_ISA_RTM, CODE_FOR_xend, "__builtin_ia32_xend", IX86_BUILTIN_XEND, UNKNOWN, (int) VOID_FTYPE_VOID },
30995   { OPTION_MASK_ISA_RTM, CODE_FOR_xtest, "__builtin_ia32_xtest", IX86_BUILTIN_XTEST, UNKNOWN, (int) INT_FTYPE_VOID },
30996
30997   /* AVX512BW */
30998   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_loaddquv32hi_mask, "__builtin_ia32_loaddquhi512_mask", IX86_BUILTIN_LOADDQUHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_PCV32HI_V32HI_SI },
30999   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_loaddquv64qi_mask, "__builtin_ia32_loaddquqi512_mask", IX86_BUILTIN_LOADDQUQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_PCV64QI_V64QI_DI },
31000   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_storedquv32hi_mask, "__builtin_ia32_storedquhi512_mask", IX86_BUILTIN_STOREDQUHI512_MASK, UNKNOWN, (int) VOID_FTYPE_PV32HI_V32HI_SI },
31001   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_storedquv64qi_mask, "__builtin_ia32_storedquqi512_mask", IX86_BUILTIN_STOREDQUQI512_MASK, UNKNOWN, (int) VOID_FTYPE_PV64QI_V64QI_DI },
31002
31003   /* AVX512VL */
31004   { 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 },
31005   { 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 },
31006   { 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 },
31007   { 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 },
31008   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4di_mask, "__builtin_ia32_movdqa64load256_mask", IX86_BUILTIN_MOVDQA64LOAD256_MASK, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
31009   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2di_mask, "__builtin_ia32_movdqa64load128_mask", IX86_BUILTIN_MOVDQA64LOAD128_MASK, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
31010   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8si_mask, "__builtin_ia32_movdqa32load256_mask", IX86_BUILTIN_MOVDQA32LOAD256_MASK, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
31011   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4si_mask, "__builtin_ia32_movdqa32load128_mask", IX86_BUILTIN_MOVDQA32LOAD128_MASK, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
31012   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4di_mask, "__builtin_ia32_movdqa64store256_mask", IX86_BUILTIN_MOVDQA64STORE256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
31013   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev2di_mask, "__builtin_ia32_movdqa64store128_mask", IX86_BUILTIN_MOVDQA64STORE128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
31014   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev8si_mask, "__builtin_ia32_movdqa32store256_mask", IX86_BUILTIN_MOVDQA32STORE256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
31015   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4si_mask, "__builtin_ia32_movdqa32store128_mask", IX86_BUILTIN_MOVDQA32STORE128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
31016   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4df_mask, "__builtin_ia32_loadapd256_mask", IX86_BUILTIN_LOADAPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
31017   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2df_mask, "__builtin_ia32_loadapd128_mask", IX86_BUILTIN_LOADAPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
31018   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8sf_mask, "__builtin_ia32_loadaps256_mask", IX86_BUILTIN_LOADAPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
31019   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4sf_mask, "__builtin_ia32_loadaps128_mask", IX86_BUILTIN_LOADAPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
31020   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4df_mask, "__builtin_ia32_storeapd256_mask", IX86_BUILTIN_STOREAPD256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
31021   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev2df_mask, "__builtin_ia32_storeapd128_mask", IX86_BUILTIN_STOREAPD128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
31022   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev8sf_mask, "__builtin_ia32_storeaps256_mask", IX86_BUILTIN_STOREAPS256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
31023   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4sf_mask, "__builtin_ia32_storeaps128_mask", IX86_BUILTIN_STOREAPS128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
31024   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loadupd256_mask, "__builtin_ia32_loadupd256_mask", IX86_BUILTIN_LOADUPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
31025   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loadupd_mask, "__builtin_ia32_loadupd128_mask", IX86_BUILTIN_LOADUPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
31026   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loadups256_mask, "__builtin_ia32_loadups256_mask", IX86_BUILTIN_LOADUPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
31027   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_loadups_mask, "__builtin_ia32_loadups128_mask", IX86_BUILTIN_LOADUPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
31028   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeupd256_mask, "__builtin_ia32_storeupd256_mask", IX86_BUILTIN_STOREUPD256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
31029   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeupd_mask, "__builtin_ia32_storeupd128_mask", IX86_BUILTIN_STOREUPD128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
31030   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeups256_mask, "__builtin_ia32_storeups256_mask", IX86_BUILTIN_STOREUPS256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
31031   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeups_mask, "__builtin_ia32_storeups128_mask", IX86_BUILTIN_STOREUPS128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
31032   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv4di_mask, "__builtin_ia32_loaddqudi256_mask", IX86_BUILTIN_LOADDQUDI256_MASK, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
31033   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv2di_mask, "__builtin_ia32_loaddqudi128_mask", IX86_BUILTIN_LOADDQUDI128_MASK, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
31034   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loaddquv8si_mask, "__builtin_ia32_loaddqusi256_mask", IX86_BUILTIN_LOADDQUSI256_MASK, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
31035   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loaddquv4si_mask, "__builtin_ia32_loaddqusi128_mask", IX86_BUILTIN_LOADDQUSI128_MASK, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
31036   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv4di_mask, "__builtin_ia32_storedqudi256_mask", IX86_BUILTIN_STOREDQUDI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
31037   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv2di_mask, "__builtin_ia32_storedqudi128_mask", IX86_BUILTIN_STOREDQUDI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
31038   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv8si_mask, "__builtin_ia32_storedqusi256_mask", IX86_BUILTIN_STOREDQUSI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
31039   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv4si_mask, "__builtin_ia32_storedqusi128_mask", IX86_BUILTIN_STOREDQUSI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
31040   { 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 },
31041   { 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 },
31042   { 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 },
31043   { 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 },
31044   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4df_mask, "__builtin_ia32_compressstoredf256_mask", IX86_BUILTIN_COMPRESSPDSTORE256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
31045   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev2df_mask, "__builtin_ia32_compressstoredf128_mask", IX86_BUILTIN_COMPRESSPDSTORE128, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
31046   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev8sf_mask, "__builtin_ia32_compressstoresf256_mask", IX86_BUILTIN_COMPRESSPSSTORE256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
31047   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4sf_mask, "__builtin_ia32_compressstoresf128_mask", IX86_BUILTIN_COMPRESSPSSTORE128, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
31048   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4di_mask, "__builtin_ia32_compressstoredi256_mask", IX86_BUILTIN_PCOMPRESSQSTORE256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
31049   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev2di_mask, "__builtin_ia32_compressstoredi128_mask", IX86_BUILTIN_PCOMPRESSQSTORE128, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
31050   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev8si_mask, "__builtin_ia32_compressstoresi256_mask", IX86_BUILTIN_PCOMPRESSDSTORE256, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
31051   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4si_mask, "__builtin_ia32_compressstoresi128_mask", IX86_BUILTIN_PCOMPRESSDSTORE128, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
31052   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_mask, "__builtin_ia32_expandloaddf256_mask", IX86_BUILTIN_EXPANDPDLOAD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
31053   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_mask, "__builtin_ia32_expandloaddf128_mask", IX86_BUILTIN_EXPANDPDLOAD128, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
31054   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_mask, "__builtin_ia32_expandloadsf256_mask", IX86_BUILTIN_EXPANDPSLOAD256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
31055   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_mask, "__builtin_ia32_expandloadsf128_mask", IX86_BUILTIN_EXPANDPSLOAD128, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
31056   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_mask, "__builtin_ia32_expandloaddi256_mask", IX86_BUILTIN_PEXPANDQLOAD256, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
31057   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_mask, "__builtin_ia32_expandloaddi128_mask", IX86_BUILTIN_PEXPANDQLOAD128, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
31058   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_mask, "__builtin_ia32_expandloadsi256_mask", IX86_BUILTIN_PEXPANDDLOAD256, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
31059   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_mask, "__builtin_ia32_expandloadsi128_mask", IX86_BUILTIN_PEXPANDDLOAD128, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
31060   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_maskz, "__builtin_ia32_expandloaddf256_maskz", IX86_BUILTIN_EXPANDPDLOAD256Z, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
31061   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_maskz, "__builtin_ia32_expandloaddf128_maskz", IX86_BUILTIN_EXPANDPDLOAD128Z, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
31062   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_maskz, "__builtin_ia32_expandloadsf256_maskz", IX86_BUILTIN_EXPANDPSLOAD256Z, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
31063   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_maskz, "__builtin_ia32_expandloadsf128_maskz", IX86_BUILTIN_EXPANDPSLOAD128Z, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
31064   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_maskz, "__builtin_ia32_expandloaddi256_maskz", IX86_BUILTIN_PEXPANDQLOAD256Z, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
31065   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_maskz, "__builtin_ia32_expandloaddi128_maskz", IX86_BUILTIN_PEXPANDQLOAD128Z, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
31066   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_maskz, "__builtin_ia32_expandloadsi256_maskz", IX86_BUILTIN_PEXPANDDLOAD256Z, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
31067   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_maskz, "__builtin_ia32_expandloadsi128_maskz", IX86_BUILTIN_PEXPANDDLOAD128Z, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
31068   { 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 },
31069   { 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 },
31070   { 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 },
31071   { 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 },
31072   { 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 },
31073   { 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 },
31074   { 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 },
31075   { 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 },
31076   { 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 },
31077   { 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 },
31078   { 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 },
31079   { 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 },
31080   { 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 },
31081   { 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 },
31082   { 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 },
31083   { 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 },
31084   { 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 },
31085   { 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 },
31086   { 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 },
31087   { 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 },
31088   { 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 },
31089   { 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 },
31090   { 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 },
31091   { 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 },
31092   { 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 },
31093   { 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 },
31094   { 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 },
31095   { 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 },
31096   { 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 },
31097   { 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 },
31098
31099   /* PCOMMIT.  */
31100   { OPTION_MASK_ISA_PCOMMIT, CODE_FOR_pcommit, "__builtin_ia32_pcommit", IX86_BUILTIN_PCOMMIT, UNKNOWN, (int) VOID_FTYPE_VOID },
31101 };
31102
31103 /* Builtins with variable number of arguments.  */
31104 static const struct builtin_description bdesc_args[] =
31105 {
31106   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_bsr, "__builtin_ia32_bsrsi", IX86_BUILTIN_BSRSI, UNKNOWN, (int) INT_FTYPE_INT },
31107   { OPTION_MASK_ISA_64BIT, CODE_FOR_bsr_rex64, "__builtin_ia32_bsrdi", IX86_BUILTIN_BSRDI, UNKNOWN, (int) INT64_FTYPE_INT64 },
31108   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdpmc", IX86_BUILTIN_RDPMC, UNKNOWN, (int) UINT64_FTYPE_INT },
31109   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlqi3, "__builtin_ia32_rolqi", IX86_BUILTIN_ROLQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
31110   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlhi3, "__builtin_ia32_rolhi", IX86_BUILTIN_ROLHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
31111   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrqi3, "__builtin_ia32_rorqi", IX86_BUILTIN_RORQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
31112   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrhi3, "__builtin_ia32_rorhi", IX86_BUILTIN_RORHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
31113
31114   /* MMX */
31115   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31116   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31117   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31118   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31119   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31120   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31121
31122   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31123   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31124   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31125   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31126   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31127   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31128   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31129   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31130
31131   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31132   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31133
31134   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31135   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31136   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31137   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31138
31139   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31140   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31141   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31142   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31143   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31144   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31145
31146   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31147   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31148   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31149   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31150   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
31151   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
31152
31153   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
31154   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
31155   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
31156
31157   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
31158
31159   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31160   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31161   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
31162   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31163   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31164   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
31165
31166   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31167   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31168   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
31169   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31170   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31171   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
31172
31173   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31174   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31175   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31176   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31177
31178   /* 3DNow! */
31179   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
31180   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
31181   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31182   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31183
31184   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31185   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31186   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31187   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31188   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31189   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31190   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31191   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31192   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31193   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31194   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31195   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31196   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31197   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31198   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31199
31200   /* 3DNow!A */
31201   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
31202   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
31203   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
31204   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31205   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31206   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31207
31208   /* SSE */
31209   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
31210   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31211   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31212   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31213   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31214   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31215   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
31216   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
31217   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
31218   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
31219   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
31220   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
31221
31222   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31223
31224   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31225   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31226   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31227   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31228   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31229   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31230   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31231   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31232
31233   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
31234   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
31235   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
31236   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31237   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31238   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31239   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
31240   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
31241   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
31242   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31243   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
31244   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31245   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
31246   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
31247   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
31248   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31249   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
31250   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
31251   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
31252   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31253
31254   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31255   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31256   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31257   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31258
31259   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31260   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31261   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31262   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31263
31264   { OPTION_MASK_ISA_SSE, CODE_FOR_copysignv4sf3,  "__builtin_ia32_copysignps", IX86_BUILTIN_CPYSGNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31265
31266   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31267   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31268   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31269   { OPTION_MASK_ISA_SSE, CODE_FOR_vec_interleave_highv4sf, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31270   { OPTION_MASK_ISA_SSE, CODE_FOR_vec_interleave_lowv4sf, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31271
31272   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
31273   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
31274   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
31275
31276   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
31277
31278   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31279   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31280   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31281
31282   { OPTION_MASK_ISA_SSE, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
31283   { OPTION_MASK_ISA_SSE, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
31284
31285   /* SSE MMX or 3Dnow!A */
31286   { 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 },
31287   { 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 },
31288   { 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 },
31289
31290   { 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 },
31291   { 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 },
31292   { 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 },
31293   { 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 },
31294
31295   { 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 },
31296   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
31297
31298   { 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 },
31299
31300   /* SSE2 */
31301   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31302
31303   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
31304   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
31305   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
31306   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
31307   { OPTION_MASK_ISA_SSE2, CODE_FOR_floatv4siv4sf2, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
31308
31309   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
31310   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
31311   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
31312   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
31313   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
31314
31315   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
31316
31317   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
31318   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
31319   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
31320   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
31321
31322   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_fix_notruncv4sfv4si, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31323   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
31324   { OPTION_MASK_ISA_SSE2, CODE_FOR_fix_truncv4sfv4si2, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31325
31326   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31327   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31328   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31329   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31330   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31331   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31332   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31333   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31334
31335   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
31336   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
31337   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
31338   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31339   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
31340   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31341   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
31342   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
31343   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
31344   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31345   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31346   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31347   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
31348   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
31349   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
31350   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31351   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
31352   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
31353   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
31354   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31355
31356   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31357   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31358   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31359   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31360
31361   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31362   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31363   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31364   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31365
31366   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysignv2df3,  "__builtin_ia32_copysignpd", IX86_BUILTIN_CPYSGNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31367
31368   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31369   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv2df, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31370   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv2df, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31371
31372   { 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 },
31373
31374   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31375   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31376   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31377   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31378   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31379   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31380   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31381   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31382
31383   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31384   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31385   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31386   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31387   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31388   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31389   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31390   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31391
31392   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31393   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
31394
31395   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31396   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31397   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31398   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31399
31400   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31401   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31402
31403   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31404   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31405   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
31406   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31407   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31408   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
31409
31410   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31411   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31412   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31413   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31414
31415   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv16qi, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31416   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv8hi, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
31417   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv4si, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
31418   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv2di, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31419   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv16qi, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31420   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv8hi, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31421   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv4si, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31422   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv2di, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31423
31424   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
31425   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
31426   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
31427
31428   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31429   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
31430
31431   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
31432   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_widen_umult_even_v4si, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
31433
31434   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
31435
31436   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
31437   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
31438   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
31439   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
31440
31441   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlv1ti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_CONVERT },
31442   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31443   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31444   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
31445   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31446   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31447   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
31448
31449   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrv1ti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_CONVERT },
31450   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31451   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31452   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
31453   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31454   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31455   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
31456
31457   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31458   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31459   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31460   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31461
31462   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
31463   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
31464   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
31465
31466   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
31467
31468   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31469
31470   /* SSE2 MMX */
31471   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
31472   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
31473
31474   /* SSE3 */
31475   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
31476   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31477
31478   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31479   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31480   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31481   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31482   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31483   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31484
31485   /* SSSE3 */
31486   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
31487   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
31488   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31489   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
31490   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
31491   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
31492
31493   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31494   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31495   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31496   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31497   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31498   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31499   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31500   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31501   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31502   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31503   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31504   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31505   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
31506   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
31507   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31508   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31509   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31510   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31511   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31512   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31513   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31514   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31515   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31516   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31517
31518   /* SSSE3.  */
31519   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT_CONVERT },
31520   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_INT_CONVERT },
31521
31522   /* SSE4.1 */
31523   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31524   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31525   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
31526   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
31527   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31528   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31529   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31530   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
31531   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
31532   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
31533
31534   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
31535   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
31536   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
31537   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
31538   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
31539   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
31540   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
31541   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
31542   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
31543   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
31544   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
31545   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
31546   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31547
31548   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
31549   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31550   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31551   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31552   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31553   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31554   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31555   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31556   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31557   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31558   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
31559   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31560
31561   /* SSE4.1 */
31562   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
31563   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
31564   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31565   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31566
31567   { 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 },
31568   { 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 },
31569   { 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 },
31570   { 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 },
31571
31572   { 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 },
31573   { 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 },
31574
31575   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv2df2, "__builtin_ia32_roundpd_az", IX86_BUILTIN_ROUNDPD_AZ, UNKNOWN, (int) V2DF_FTYPE_V2DF },
31576   { 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 },
31577
31578   { 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 },
31579   { 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 },
31580   { 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 },
31581   { 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 },
31582
31583   { 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 },
31584   { 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 },
31585
31586   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv4sf2, "__builtin_ia32_roundps_az", IX86_BUILTIN_ROUNDPS_AZ, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31587   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv4sf2_sfix, "__builtin_ia32_roundps_az_sfix", IX86_BUILTIN_ROUNDPS_AZ_SFIX, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31588
31589   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31590   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31591   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31592
31593   /* SSE4.2 */
31594   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31595   { 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 },
31596   { 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 },
31597   { 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 },
31598   { 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 },
31599
31600   /* SSE4A */
31601   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
31602   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
31603   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
31604   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31605
31606   /* AES */
31607   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
31608   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31609
31610   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31611   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31612   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31613   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31614
31615   /* PCLMUL */
31616   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
31617
31618   /* AVX */
31619   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31620   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31621   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31622   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31623   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31624   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31625   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31626   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31627   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31628   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31629   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31630   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31631   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31632   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31633   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31634   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31635   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31636   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31637   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31638   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31639   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31640   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31641   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31642   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31643   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31644   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31645
31646   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
31647   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
31648   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
31649   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
31650
31651   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31652   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31653   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
31654   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
31655   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31656   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31657   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31658   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vmcmpv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31659   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vmcmpv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31660   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31661   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31662   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31663   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31664   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
31665   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
31666   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
31667   { OPTION_MASK_ISA_AVX, CODE_FOR_floatv4siv4df2, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
31668   { OPTION_MASK_ISA_AVX, CODE_FOR_floatv8siv8sf2, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
31669   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
31670   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_fix_notruncv8sfv8si, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31671   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
31672   { OPTION_MASK_ISA_AVX, CODE_FOR_fix_truncv4dfv4si2, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
31673   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
31674   { OPTION_MASK_ISA_AVX, CODE_FOR_fix_truncv8sfv8si2, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31675   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31676   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31677   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
31678   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
31679   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
31680   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31681   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
31682   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
31683   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
31684   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
31685
31686   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31687   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31688   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31689
31690   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31691   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31692   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31693   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31694   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31695
31696   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31697
31698   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31699   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
31700
31701   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_floorpd256", IX86_BUILTIN_FLOORPD256, (enum rtx_code) ROUND_FLOOR, (int) V4DF_FTYPE_V4DF_ROUND },
31702   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_ceilpd256", IX86_BUILTIN_CEILPD256, (enum rtx_code) ROUND_CEIL, (int) V4DF_FTYPE_V4DF_ROUND },
31703   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_truncpd256", IX86_BUILTIN_TRUNCPD256, (enum rtx_code) ROUND_TRUNC, (int) V4DF_FTYPE_V4DF_ROUND },
31704   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_rintpd256", IX86_BUILTIN_RINTPD256, (enum rtx_code) ROUND_MXCSR, (int) V4DF_FTYPE_V4DF_ROUND },
31705
31706   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv4df2, "__builtin_ia32_roundpd_az256", IX86_BUILTIN_ROUNDPD_AZ256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31707   { 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 },
31708
31709   { 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 },
31710   { 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 },
31711
31712   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_floorps256", IX86_BUILTIN_FLOORPS256, (enum rtx_code) ROUND_FLOOR, (int) V8SF_FTYPE_V8SF_ROUND },
31713   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_ceilps256", IX86_BUILTIN_CEILPS256, (enum rtx_code) ROUND_CEIL, (int) V8SF_FTYPE_V8SF_ROUND },
31714   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_truncps256", IX86_BUILTIN_TRUNCPS256, (enum rtx_code) ROUND_TRUNC, (int) V8SF_FTYPE_V8SF_ROUND },
31715   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_rintps256", IX86_BUILTIN_RINTPS256, (enum rtx_code) ROUND_MXCSR, (int) V8SF_FTYPE_V8SF_ROUND },
31716
31717   { 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 },
31718   { 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 },
31719
31720   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv8sf2, "__builtin_ia32_roundps_az256", IX86_BUILTIN_ROUNDPS_AZ256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31721   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv8sf2_sfix, "__builtin_ia32_roundps_az_sfix256", IX86_BUILTIN_ROUNDPS_AZ_SFIX256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31722
31723   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31724   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31725   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31726   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31727
31728   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
31729   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
31730   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
31731   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v8si, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
31732   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v8sf, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
31733   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v4df, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
31734
31735   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31736   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31737   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31738   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31739   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31740   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31741   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31742   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31743   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31744   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31745   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31746   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31747   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31748   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31749   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31750
31751   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
31752   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
31753
31754   { OPTION_MASK_ISA_AVX, CODE_FOR_copysignv8sf3,  "__builtin_ia32_copysignps256", IX86_BUILTIN_CPYSGNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31755   { OPTION_MASK_ISA_AVX, CODE_FOR_copysignv4df3,  "__builtin_ia32_copysignpd256", IX86_BUILTIN_CPYSGNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31756
31757   { 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 },
31758
31759   /* AVX2 */
31760   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_mpsadbw, "__builtin_ia32_mpsadbw256", IX86_BUILTIN_MPSADBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_INT },
31761   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv32qi2, "__builtin_ia32_pabsb256", IX86_BUILTIN_PABSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI },
31762   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv16hi2, "__builtin_ia32_pabsw256", IX86_BUILTIN_PABSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI },
31763   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv8si2, "__builtin_ia32_pabsd256", IX86_BUILTIN_PABSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI },
31764   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packssdw, "__builtin_ia32_packssdw256",  IX86_BUILTIN_PACKSSDW256, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI },
31765   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packsswb, "__builtin_ia32_packsswb256",  IX86_BUILTIN_PACKSSWB256, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI },
31766   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packusdw, "__builtin_ia32_packusdw256",  IX86_BUILTIN_PACKUSDW256, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI },
31767   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packuswb, "__builtin_ia32_packuswb256",  IX86_BUILTIN_PACKUSWB256, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI },
31768   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv32qi3, "__builtin_ia32_paddb256", IX86_BUILTIN_PADDB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31769   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv16hi3, "__builtin_ia32_paddw256", IX86_BUILTIN_PADDW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31770   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv8si3, "__builtin_ia32_paddd256", IX86_BUILTIN_PADDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31771   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv4di3, "__builtin_ia32_paddq256", IX86_BUILTIN_PADDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31772   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ssaddv32qi3, "__builtin_ia32_paddsb256", IX86_BUILTIN_PADDSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31773   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ssaddv16hi3, "__builtin_ia32_paddsw256", IX86_BUILTIN_PADDSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31774   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_usaddv32qi3, "__builtin_ia32_paddusb256", IX86_BUILTIN_PADDUSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31775   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_usaddv16hi3, "__builtin_ia32_paddusw256", IX86_BUILTIN_PADDUSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31776   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_palignrv2ti, "__builtin_ia32_palignr256", IX86_BUILTIN_PALIGNR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT_CONVERT },
31777   { OPTION_MASK_ISA_AVX2, CODE_FOR_andv4di3, "__builtin_ia32_andsi256", IX86_BUILTIN_AND256I, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31778   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_andnotv4di3, "__builtin_ia32_andnotsi256", IX86_BUILTIN_ANDNOT256I, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31779   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_uavgv32qi3, "__builtin_ia32_pavgb256",  IX86_BUILTIN_PAVGB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31780   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_uavgv16hi3, "__builtin_ia32_pavgw256",  IX86_BUILTIN_PAVGW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31781   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblendvb, "__builtin_ia32_pblendvb256", IX86_BUILTIN_PBLENDVB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI },
31782   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblendw, "__builtin_ia32_pblendw256", IX86_BUILTIN_PBLENDVW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_INT },
31783   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv32qi3, "__builtin_ia32_pcmpeqb256", IX86_BUILTIN_PCMPEQB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31784   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv16hi3, "__builtin_ia32_pcmpeqw256", IX86_BUILTIN_PCMPEQW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31785   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv8si3, "__builtin_ia32_pcmpeqd256", IX86_BUILTIN_PCMPEQD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI  },
31786   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv4di3, "__builtin_ia32_pcmpeqq256", IX86_BUILTIN_PCMPEQQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI  },
31787   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv32qi3, "__builtin_ia32_pcmpgtb256", IX86_BUILTIN_PCMPGTB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31788   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv16hi3, "__builtin_ia32_pcmpgtw256", IX86_BUILTIN_PCMPGTW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31789   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv8si3, "__builtin_ia32_pcmpgtd256", IX86_BUILTIN_PCMPGTD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI  },
31790   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv4di3, "__builtin_ia32_pcmpgtq256", IX86_BUILTIN_PCMPGTQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI  },
31791   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phaddwv16hi3, "__builtin_ia32_phaddw256", IX86_BUILTIN_PHADDW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31792   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phadddv8si3, "__builtin_ia32_phaddd256", IX86_BUILTIN_PHADDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31793   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phaddswv16hi3, "__builtin_ia32_phaddsw256", IX86_BUILTIN_PHADDSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31794   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubwv16hi3, "__builtin_ia32_phsubw256", IX86_BUILTIN_PHSUBW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31795   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubdv8si3, "__builtin_ia32_phsubd256", IX86_BUILTIN_PHSUBD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31796   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubswv16hi3, "__builtin_ia32_phsubsw256", IX86_BUILTIN_PHSUBSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31797   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmaddubsw256, "__builtin_ia32_pmaddubsw256", IX86_BUILTIN_PMADDUBSW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI },
31798   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmaddwd, "__builtin_ia32_pmaddwd256", IX86_BUILTIN_PMADDWD256, UNKNOWN, (int) V8SI_FTYPE_V16HI_V16HI },
31799   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv32qi3, "__builtin_ia32_pmaxsb256", IX86_BUILTIN_PMAXSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31800   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv16hi3, "__builtin_ia32_pmaxsw256", IX86_BUILTIN_PMAXSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31801   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv8si3 , "__builtin_ia32_pmaxsd256", IX86_BUILTIN_PMAXSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31802   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv32qi3, "__builtin_ia32_pmaxub256", IX86_BUILTIN_PMAXUB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31803   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv16hi3, "__builtin_ia32_pmaxuw256", IX86_BUILTIN_PMAXUW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31804   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv8si3 , "__builtin_ia32_pmaxud256", IX86_BUILTIN_PMAXUD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31805   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv32qi3, "__builtin_ia32_pminsb256", IX86_BUILTIN_PMINSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31806   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv16hi3, "__builtin_ia32_pminsw256", IX86_BUILTIN_PMINSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31807   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv8si3 , "__builtin_ia32_pminsd256", IX86_BUILTIN_PMINSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31808   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv32qi3, "__builtin_ia32_pminub256", IX86_BUILTIN_PMINUB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31809   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv16hi3, "__builtin_ia32_pminuw256", IX86_BUILTIN_PMINUW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31810   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv8si3 , "__builtin_ia32_pminud256", IX86_BUILTIN_PMINUD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31811   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmovmskb, "__builtin_ia32_pmovmskb256", IX86_BUILTIN_PMOVMSKB256, UNKNOWN, (int) INT_FTYPE_V32QI },
31812   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv16qiv16hi2, "__builtin_ia32_pmovsxbw256", IX86_BUILTIN_PMOVSXBW256, UNKNOWN, (int) V16HI_FTYPE_V16QI },
31813   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv8qiv8si2  , "__builtin_ia32_pmovsxbd256", IX86_BUILTIN_PMOVSXBD256, UNKNOWN, (int) V8SI_FTYPE_V16QI },
31814   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4qiv4di2  , "__builtin_ia32_pmovsxbq256", IX86_BUILTIN_PMOVSXBQ256, UNKNOWN, (int) V4DI_FTYPE_V16QI },
31815   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv8hiv8si2  , "__builtin_ia32_pmovsxwd256", IX86_BUILTIN_PMOVSXWD256, UNKNOWN, (int) V8SI_FTYPE_V8HI },
31816   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4hiv4di2  , "__builtin_ia32_pmovsxwq256", IX86_BUILTIN_PMOVSXWQ256, UNKNOWN, (int) V4DI_FTYPE_V8HI },
31817   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4siv4di2  , "__builtin_ia32_pmovsxdq256", IX86_BUILTIN_PMOVSXDQ256, UNKNOWN, (int) V4DI_FTYPE_V4SI },
31818   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv16qiv16hi2, "__builtin_ia32_pmovzxbw256", IX86_BUILTIN_PMOVZXBW256, UNKNOWN, (int) V16HI_FTYPE_V16QI },
31819   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv8qiv8si2  , "__builtin_ia32_pmovzxbd256", IX86_BUILTIN_PMOVZXBD256, UNKNOWN, (int) V8SI_FTYPE_V16QI },
31820   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4qiv4di2  , "__builtin_ia32_pmovzxbq256", IX86_BUILTIN_PMOVZXBQ256, UNKNOWN, (int) V4DI_FTYPE_V16QI },
31821   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv8hiv8si2  , "__builtin_ia32_pmovzxwd256", IX86_BUILTIN_PMOVZXWD256, UNKNOWN, (int) V8SI_FTYPE_V8HI },
31822   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4hiv4di2  , "__builtin_ia32_pmovzxwq256", IX86_BUILTIN_PMOVZXWQ256, UNKNOWN, (int) V4DI_FTYPE_V8HI },
31823   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4siv4di2  , "__builtin_ia32_pmovzxdq256", IX86_BUILTIN_PMOVZXDQ256, UNKNOWN, (int) V4DI_FTYPE_V4SI },
31824   { OPTION_MASK_ISA_AVX2, CODE_FOR_vec_widen_smult_even_v8si, "__builtin_ia32_pmuldq256", IX86_BUILTIN_PMULDQ256, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI },
31825   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmulhrswv16hi3 , "__builtin_ia32_pmulhrsw256", IX86_BUILTIN_PMULHRSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31826   { OPTION_MASK_ISA_AVX2, CODE_FOR_umulv16hi3_highpart, "__builtin_ia32_pmulhuw256" , IX86_BUILTIN_PMULHUW256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31827   { OPTION_MASK_ISA_AVX2, CODE_FOR_smulv16hi3_highpart, "__builtin_ia32_pmulhw256"  , IX86_BUILTIN_PMULHW256  , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31828   { OPTION_MASK_ISA_AVX2, CODE_FOR_mulv16hi3, "__builtin_ia32_pmullw256"  , IX86_BUILTIN_PMULLW256  , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31829   { OPTION_MASK_ISA_AVX2, CODE_FOR_mulv8si3, "__builtin_ia32_pmulld256"  , IX86_BUILTIN_PMULLD256  , UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31830   { OPTION_MASK_ISA_AVX2, CODE_FOR_vec_widen_umult_even_v8si, "__builtin_ia32_pmuludq256", IX86_BUILTIN_PMULUDQ256, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI },
31831   { OPTION_MASK_ISA_AVX2, CODE_FOR_iorv4di3, "__builtin_ia32_por256", IX86_BUILTIN_POR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31832   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psadbw, "__builtin_ia32_psadbw256", IX86_BUILTIN_PSADBW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI },
31833   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufbv32qi3, "__builtin_ia32_pshufb256", IX86_BUILTIN_PSHUFB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31834   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufdv3, "__builtin_ia32_pshufd256", IX86_BUILTIN_PSHUFD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT },
31835   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufhwv3, "__builtin_ia32_pshufhw256", IX86_BUILTIN_PSHUFHW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT },
31836   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshuflwv3, "__builtin_ia32_pshuflw256", IX86_BUILTIN_PSHUFLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT },
31837   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv32qi3, "__builtin_ia32_psignb256", IX86_BUILTIN_PSIGNB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31838   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv16hi3, "__builtin_ia32_psignw256", IX86_BUILTIN_PSIGNW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31839   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv8si3 , "__builtin_ia32_psignd256", IX86_BUILTIN_PSIGND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31840   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlv2ti3, "__builtin_ia32_pslldqi256", IX86_BUILTIN_PSLLDQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_CONVERT },
31841   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv16hi3, "__builtin_ia32_psllwi256", IX86_BUILTIN_PSLLWI256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31842   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv16hi3, "__builtin_ia32_psllw256", IX86_BUILTIN_PSLLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31843   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv8si3, "__builtin_ia32_pslldi256", IX86_BUILTIN_PSLLDI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31844   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv8si3, "__builtin_ia32_pslld256", IX86_BUILTIN_PSLLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31845   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv4di3, "__builtin_ia32_psllqi256", IX86_BUILTIN_PSLLQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_COUNT },
31846   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv4di3, "__builtin_ia32_psllq256", IX86_BUILTIN_PSLLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_COUNT },
31847   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv16hi3, "__builtin_ia32_psrawi256", IX86_BUILTIN_PSRAWI256, UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31848   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv16hi3, "__builtin_ia32_psraw256", IX86_BUILTIN_PSRAW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31849   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv8si3, "__builtin_ia32_psradi256", IX86_BUILTIN_PSRADI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31850   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv8si3, "__builtin_ia32_psrad256", IX86_BUILTIN_PSRAD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31851   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrv2ti3, "__builtin_ia32_psrldqi256", IX86_BUILTIN_PSRLDQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_CONVERT },
31852   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv16hi3, "__builtin_ia32_psrlwi256", IX86_BUILTIN_PSRLWI256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31853   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv16hi3, "__builtin_ia32_psrlw256", IX86_BUILTIN_PSRLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31854   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv8si3, "__builtin_ia32_psrldi256", IX86_BUILTIN_PSRLDI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31855   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv8si3, "__builtin_ia32_psrld256", IX86_BUILTIN_PSRLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31856   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv4di3, "__builtin_ia32_psrlqi256", IX86_BUILTIN_PSRLQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_COUNT },
31857   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv4di3, "__builtin_ia32_psrlq256", IX86_BUILTIN_PSRLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_COUNT },
31858   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv32qi3, "__builtin_ia32_psubb256", IX86_BUILTIN_PSUBB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31859   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv16hi3, "__builtin_ia32_psubw256", IX86_BUILTIN_PSUBW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31860   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv8si3, "__builtin_ia32_psubd256", IX86_BUILTIN_PSUBD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31861   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv4di3, "__builtin_ia32_psubq256", IX86_BUILTIN_PSUBQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31862   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sssubv32qi3, "__builtin_ia32_psubsb256", IX86_BUILTIN_PSUBSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31863   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sssubv16hi3, "__builtin_ia32_psubsw256", IX86_BUILTIN_PSUBSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31864   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ussubv32qi3, "__builtin_ia32_psubusb256", IX86_BUILTIN_PSUBUSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31865   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ussubv16hi3, "__builtin_ia32_psubusw256", IX86_BUILTIN_PSUBUSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31866   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv32qi, "__builtin_ia32_punpckhbw256", IX86_BUILTIN_PUNPCKHBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31867   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv16hi, "__builtin_ia32_punpckhwd256", IX86_BUILTIN_PUNPCKHWD256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI  },
31868   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv8si, "__builtin_ia32_punpckhdq256", IX86_BUILTIN_PUNPCKHDQ256, UNKNOWN,  (int) V8SI_FTYPE_V8SI_V8SI },
31869   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv4di, "__builtin_ia32_punpckhqdq256", IX86_BUILTIN_PUNPCKHQDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31870   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv32qi, "__builtin_ia32_punpcklbw256", IX86_BUILTIN_PUNPCKLBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31871   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv16hi, "__builtin_ia32_punpcklwd256", IX86_BUILTIN_PUNPCKLWD256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31872   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv8si, "__builtin_ia32_punpckldq256", IX86_BUILTIN_PUNPCKLDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31873   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv4di, "__builtin_ia32_punpcklqdq256", IX86_BUILTIN_PUNPCKLQDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31874   { OPTION_MASK_ISA_AVX2, CODE_FOR_xorv4di3, "__builtin_ia32_pxor256", IX86_BUILTIN_PXOR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31875   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv4sf, "__builtin_ia32_vbroadcastss_ps", IX86_BUILTIN_VBROADCASTSS_PS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31876   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv8sf, "__builtin_ia32_vbroadcastss_ps256", IX86_BUILTIN_VBROADCASTSS_PS256, UNKNOWN, (int) V8SF_FTYPE_V4SF },
31877   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv4df, "__builtin_ia32_vbroadcastsd_pd256", IX86_BUILTIN_VBROADCASTSD_PD256, UNKNOWN, (int) V4DF_FTYPE_V2DF },
31878   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vbroadcasti128_v4di, "__builtin_ia32_vbroadcastsi256", IX86_BUILTIN_VBROADCASTSI256, UNKNOWN, (int) V4DI_FTYPE_V2DI },
31879   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblenddv4si, "__builtin_ia32_pblendd128", IX86_BUILTIN_PBLENDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT },
31880   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblenddv8si, "__builtin_ia32_pblendd256", IX86_BUILTIN_PBLENDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
31881   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv32qi, "__builtin_ia32_pbroadcastb256", IX86_BUILTIN_PBROADCASTB256, UNKNOWN, (int) V32QI_FTYPE_V16QI },
31882   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv16hi, "__builtin_ia32_pbroadcastw256", IX86_BUILTIN_PBROADCASTW256, UNKNOWN, (int) V16HI_FTYPE_V8HI },
31883   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv8si, "__builtin_ia32_pbroadcastd256", IX86_BUILTIN_PBROADCASTD256, UNKNOWN, (int) V8SI_FTYPE_V4SI },
31884   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv4di, "__builtin_ia32_pbroadcastq256", IX86_BUILTIN_PBROADCASTQ256, UNKNOWN, (int) V4DI_FTYPE_V2DI },
31885   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv16qi, "__builtin_ia32_pbroadcastb128", IX86_BUILTIN_PBROADCASTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
31886   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv8hi, "__builtin_ia32_pbroadcastw128", IX86_BUILTIN_PBROADCASTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31887   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv4si, "__builtin_ia32_pbroadcastd128", IX86_BUILTIN_PBROADCASTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
31888   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv2di, "__builtin_ia32_pbroadcastq128", IX86_BUILTIN_PBROADCASTQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31889   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permvarv8si, "__builtin_ia32_permvarsi256", IX86_BUILTIN_VPERMVARSI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31890   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permvarv8sf, "__builtin_ia32_permvarsf256", IX86_BUILTIN_VPERMVARSF256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
31891   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv4df, "__builtin_ia32_permdf256", IX86_BUILTIN_VPERMDF256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31892   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv4di, "__builtin_ia32_permdi256", IX86_BUILTIN_VPERMDI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT },
31893   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv2ti, "__builtin_ia32_permti256", IX86_BUILTIN_VPERMTI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT },
31894   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx_vextractf128v4di, "__builtin_ia32_extract128i256", IX86_BUILTIN_VEXTRACT128I256, UNKNOWN, (int) V2DI_FTYPE_V4DI_INT },
31895   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx_vinsertf128v4di, "__builtin_ia32_insert128i256", IX86_BUILTIN_VINSERT128I256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_INT },
31896   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv4di, "__builtin_ia32_psllv4di", IX86_BUILTIN_PSLLVV4DI, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31897   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv2di, "__builtin_ia32_psllv2di", IX86_BUILTIN_PSLLVV2DI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31898   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv8si, "__builtin_ia32_psllv8si", IX86_BUILTIN_PSLLVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31899   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv4si, "__builtin_ia32_psllv4si", IX86_BUILTIN_PSLLVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31900   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashrvv8si, "__builtin_ia32_psrav8si", IX86_BUILTIN_PSRAVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31901   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashrvv4si, "__builtin_ia32_psrav4si", IX86_BUILTIN_PSRAVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31902   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv4di, "__builtin_ia32_psrlv4di", IX86_BUILTIN_PSRLVV4DI, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31903   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv2di, "__builtin_ia32_psrlv2di", IX86_BUILTIN_PSRLVV2DI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31904   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv8si, "__builtin_ia32_psrlv8si", IX86_BUILTIN_PSRLVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31905   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv4si, "__builtin_ia32_psrlv4si", IX86_BUILTIN_PSRLVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31906
31907   { OPTION_MASK_ISA_LZCNT, CODE_FOR_clzhi2_lzcnt,   "__builtin_clzs",   IX86_BUILTIN_CLZS,    UNKNOWN,     (int) UINT16_FTYPE_UINT16 },
31908
31909   /* BMI */
31910   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_bextr_si, "__builtin_ia32_bextr_u32", IX86_BUILTIN_BEXTR32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31911   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_bextr_di, "__builtin_ia32_bextr_u64", IX86_BUILTIN_BEXTR64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31912   { OPTION_MASK_ISA_BMI, CODE_FOR_ctzhi2,       "__builtin_ctzs",           IX86_BUILTIN_CTZS,    UNKNOWN, (int) UINT16_FTYPE_UINT16 },
31913
31914   /* TBM */
31915   { OPTION_MASK_ISA_TBM, CODE_FOR_tbm_bextri_si, "__builtin_ia32_bextri_u32", IX86_BUILTIN_BEXTRI32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31916   { OPTION_MASK_ISA_TBM, CODE_FOR_tbm_bextri_di, "__builtin_ia32_bextri_u64", IX86_BUILTIN_BEXTRI64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31917
31918   /* F16C */
31919   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtph2ps, "__builtin_ia32_vcvtph2ps", IX86_BUILTIN_CVTPH2PS, UNKNOWN, (int) V4SF_FTYPE_V8HI },
31920   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtph2ps256, "__builtin_ia32_vcvtph2ps256", IX86_BUILTIN_CVTPH2PS256, UNKNOWN, (int) V8SF_FTYPE_V8HI },
31921   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtps2ph, "__builtin_ia32_vcvtps2ph", IX86_BUILTIN_CVTPS2PH, UNKNOWN, (int) V8HI_FTYPE_V4SF_INT },
31922   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtps2ph256, "__builtin_ia32_vcvtps2ph256", IX86_BUILTIN_CVTPS2PH256, UNKNOWN, (int) V8HI_FTYPE_V8SF_INT },
31923
31924   /* BMI2 */
31925   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_bzhi_si3, "__builtin_ia32_bzhi_si", IX86_BUILTIN_BZHI32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31926   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_bzhi_di3, "__builtin_ia32_bzhi_di", IX86_BUILTIN_BZHI64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31927   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pdep_si3, "__builtin_ia32_pdep_si", IX86_BUILTIN_PDEP32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31928   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pdep_di3, "__builtin_ia32_pdep_di", IX86_BUILTIN_PDEP64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31929   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pext_si3, "__builtin_ia32_pext_si", IX86_BUILTIN_PEXT32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31930   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pext_di3, "__builtin_ia32_pext_di", IX86_BUILTIN_PEXT64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31931
31932   /* AVX512F */
31933   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_si512_256si, "__builtin_ia32_si512_256si", IX86_BUILTIN_SI512_SI256, UNKNOWN, (int) V16SI_FTYPE_V8SI },
31934   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ps512_256ps, "__builtin_ia32_ps512_256ps", IX86_BUILTIN_PS512_PS256, UNKNOWN, (int) V16SF_FTYPE_V8SF },
31935   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pd512_256pd, "__builtin_ia32_pd512_256pd", IX86_BUILTIN_PD512_PD256, UNKNOWN, (int) V8DF_FTYPE_V4DF },
31936   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_si512_si, "__builtin_ia32_si512_si", IX86_BUILTIN_SI512_SI, UNKNOWN, (int) V16SI_FTYPE_V4SI },
31937   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ps512_ps, "__builtin_ia32_ps512_ps", IX86_BUILTIN_PS512_PS, UNKNOWN, (int) V16SF_FTYPE_V4SF },
31938   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pd512_pd, "__builtin_ia32_pd512_pd", IX86_BUILTIN_PD512_PD, UNKNOWN, (int) V8DF_FTYPE_V2DF },
31939   { 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 },
31940   { 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 },
31941   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv16si, "__builtin_ia32_blendmd_512_mask", IX86_BUILTIN_BLENDMD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31942   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv8df, "__builtin_ia32_blendmpd_512_mask", IX86_BUILTIN_BLENDMPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31943   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv16sf, "__builtin_ia32_blendmps_512_mask", IX86_BUILTIN_BLENDMPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31944   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv8di, "__builtin_ia32_blendmq_512_mask", IX86_BUILTIN_BLENDMQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31945   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv16sf_mask, "__builtin_ia32_broadcastf32x4_512", IX86_BUILTIN_BROADCASTF32X4_512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
31946   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv8df_mask, "__builtin_ia32_broadcastf64x4_512", IX86_BUILTIN_BROADCASTF64X4_512, UNKNOWN, (int) V8DF_FTYPE_V4DF_V8DF_QI },
31947   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv16si_mask, "__builtin_ia32_broadcasti32x4_512", IX86_BUILTIN_BROADCASTI32X4_512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
31948   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv8di_mask, "__builtin_ia32_broadcasti64x4_512", IX86_BUILTIN_BROADCASTI64X4_512, UNKNOWN, (int) V8DI_FTYPE_V4DI_V8DI_QI },
31949   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv8df_mask, "__builtin_ia32_broadcastsd512", IX86_BUILTIN_BROADCASTSD512, UNKNOWN, (int) V8DF_FTYPE_V2DF_V8DF_QI },
31950   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv16sf_mask, "__builtin_ia32_broadcastss512", IX86_BUILTIN_BROADCASTSS512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
31951   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv16si3_mask, "__builtin_ia32_cmpd512_mask", IX86_BUILTIN_CMPD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_INT_HI },
31952   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv8di3_mask, "__builtin_ia32_cmpq512_mask", IX86_BUILTIN_CMPQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_INT_QI },
31953   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv8df_mask, "__builtin_ia32_compressdf512_mask", IX86_BUILTIN_COMPRESSPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31954   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv16sf_mask, "__builtin_ia32_compresssf512_mask", IX86_BUILTIN_COMPRESSPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31955   { OPTION_MASK_ISA_AVX512F, CODE_FOR_floatv8siv8df2_mask, "__builtin_ia32_cvtdq2pd512_mask", IX86_BUILTIN_CVTDQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SI_V8DF_QI },
31956   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtps2ph512_mask,  "__builtin_ia32_vcvtps2ph512_mask", IX86_BUILTIN_CVTPS2PH512, UNKNOWN, (int) V16HI_FTYPE_V16SF_INT_V16HI_HI },
31957   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufloatv8siv8df2_mask, "__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SI_V8DF_QI },
31958   { OPTION_MASK_ISA_AVX512F, CODE_FOR_cvtusi2sd32, "__builtin_ia32_cvtusi2sd32", IX86_BUILTIN_CVTUSI2SD32, UNKNOWN, (int) V2DF_FTYPE_V2DF_UINT },
31959   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_mask, "__builtin_ia32_expanddf512_mask", IX86_BUILTIN_EXPANDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31960   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_maskz, "__builtin_ia32_expanddf512_maskz", IX86_BUILTIN_EXPANDPD512Z, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31961   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_mask, "__builtin_ia32_expandsf512_mask", IX86_BUILTIN_EXPANDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31962   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_maskz, "__builtin_ia32_expandsf512_maskz", IX86_BUILTIN_EXPANDPS512Z, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31963   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextractf32x4_mask, "__builtin_ia32_extractf32x4_mask", IX86_BUILTIN_EXTRACTF32X4, UNKNOWN, (int) V4SF_FTYPE_V16SF_INT_V4SF_QI },
31964   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextractf64x4_mask, "__builtin_ia32_extractf64x4_mask", IX86_BUILTIN_EXTRACTF64X4, UNKNOWN, (int) V4DF_FTYPE_V8DF_INT_V4DF_QI },
31965   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextracti32x4_mask, "__builtin_ia32_extracti32x4_mask", IX86_BUILTIN_EXTRACTI32X4, UNKNOWN, (int) V4SI_FTYPE_V16SI_INT_V4SI_QI },
31966   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextracti64x4_mask, "__builtin_ia32_extracti64x4_mask", IX86_BUILTIN_EXTRACTI64X4, UNKNOWN, (int) V4DI_FTYPE_V8DI_INT_V4DI_QI },
31967   { 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 },
31968   { 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 },
31969   { 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 },
31970   { 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 },
31971   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8df_mask, "__builtin_ia32_movapd512_mask", IX86_BUILTIN_MOVAPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31972   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16sf_mask, "__builtin_ia32_movaps512_mask", IX86_BUILTIN_MOVAPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31973   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movddup512_mask, "__builtin_ia32_movddup512_mask", IX86_BUILTIN_MOVDDUP512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31974   { 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 },
31975   { 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 },
31976   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movshdup512_mask, "__builtin_ia32_movshdup512_mask", IX86_BUILTIN_MOVSHDUP512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31977   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movsldup512_mask, "__builtin_ia32_movsldup512_mask", IX86_BUILTIN_MOVSLDUP512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31978   { OPTION_MASK_ISA_AVX512F, CODE_FOR_absv16si2_mask, "__builtin_ia32_pabsd512_mask", IX86_BUILTIN_PABSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31979   { OPTION_MASK_ISA_AVX512F, CODE_FOR_absv8di2_mask, "__builtin_ia32_pabsq512_mask", IX86_BUILTIN_PABSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31980   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv16si3_mask, "__builtin_ia32_paddd512_mask", IX86_BUILTIN_PADDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31981   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv8di3_mask, "__builtin_ia32_paddq512_mask", IX86_BUILTIN_PADDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31982   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andv16si3_mask, "__builtin_ia32_pandd512_mask", IX86_BUILTIN_PANDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31983   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_andnotv16si3_mask, "__builtin_ia32_pandnd512_mask", IX86_BUILTIN_PANDND512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31984   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_andnotv8di3_mask, "__builtin_ia32_pandnq512_mask", IX86_BUILTIN_PANDNQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31985   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andv8di3_mask, "__builtin_ia32_pandq512_mask", IX86_BUILTIN_PANDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31986   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv16si_mask, "__builtin_ia32_pbroadcastd512", IX86_BUILTIN_PBROADCASTD512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
31987   { 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 },
31988   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskb_vec_dupv8di, "__builtin_ia32_broadcastmb512", IX86_BUILTIN_PBROADCASTMB512, UNKNOWN, (int) V8DI_FTYPE_QI },
31989   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskw_vec_dupv16si, "__builtin_ia32_broadcastmw512", IX86_BUILTIN_PBROADCASTMW512, UNKNOWN, (int) V16SI_FTYPE_HI },
31990   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv8di_mask, "__builtin_ia32_pbroadcastq512", IX86_BUILTIN_PBROADCASTQ512, UNKNOWN, (int) V8DI_FTYPE_V2DI_V8DI_QI },
31991   { 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 },
31992   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_eqv16si3_mask, "__builtin_ia32_pcmpeqd512_mask", IX86_BUILTIN_PCMPEQD512_MASK, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31993   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_eqv8di3_mask, "__builtin_ia32_pcmpeqq512_mask", IX86_BUILTIN_PCMPEQQ512_MASK, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31994   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_gtv16si3_mask, "__builtin_ia32_pcmpgtd512_mask", IX86_BUILTIN_PCMPGTD512_MASK, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31995   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_gtv8di3_mask, "__builtin_ia32_pcmpgtq512_mask", IX86_BUILTIN_PCMPGTQ512_MASK, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31996   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv16si_mask, "__builtin_ia32_compresssi512_mask", IX86_BUILTIN_PCOMPRESSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31997   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv8di_mask, "__builtin_ia32_compressdi512_mask", IX86_BUILTIN_PCOMPRESSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31998   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_mask, "__builtin_ia32_expandsi512_mask", IX86_BUILTIN_PEXPANDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31999   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_maskz, "__builtin_ia32_expandsi512_maskz", IX86_BUILTIN_PEXPANDD512Z, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
32000   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_mask, "__builtin_ia32_expanddi512_mask", IX86_BUILTIN_PEXPANDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
32001   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_maskz, "__builtin_ia32_expanddi512_maskz", IX86_BUILTIN_PEXPANDQ512Z, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
32002   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv16si3_mask, "__builtin_ia32_pmaxsd512_mask", IX86_BUILTIN_PMAXSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32003   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv8di3_mask, "__builtin_ia32_pmaxsq512_mask", IX86_BUILTIN_PMAXSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32004   { OPTION_MASK_ISA_AVX512F, CODE_FOR_umaxv16si3_mask, "__builtin_ia32_pmaxud512_mask", IX86_BUILTIN_PMAXUD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32005   { OPTION_MASK_ISA_AVX512F, CODE_FOR_umaxv8di3_mask, "__builtin_ia32_pmaxuq512_mask", IX86_BUILTIN_PMAXUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32006   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv16si3_mask, "__builtin_ia32_pminsd512_mask", IX86_BUILTIN_PMINSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32007   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv8di3_mask, "__builtin_ia32_pminsq512_mask", IX86_BUILTIN_PMINSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32008   { OPTION_MASK_ISA_AVX512F, CODE_FOR_uminv16si3_mask, "__builtin_ia32_pminud512_mask", IX86_BUILTIN_PMINUD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32009   { OPTION_MASK_ISA_AVX512F, CODE_FOR_uminv8di3_mask, "__builtin_ia32_pminuq512_mask", IX86_BUILTIN_PMINUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32010   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16qi2_mask, "__builtin_ia32_pmovdb512_mask", IX86_BUILTIN_PMOVDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
32011   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16hi2_mask, "__builtin_ia32_pmovdw512_mask", IX86_BUILTIN_PMOVDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
32012   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div16qi2_mask, "__builtin_ia32_pmovqb512_mask", IX86_BUILTIN_PMOVQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
32013   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8si2_mask, "__builtin_ia32_pmovqd512_mask", IX86_BUILTIN_PMOVQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
32014   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8hi2_mask, "__builtin_ia32_pmovqw512_mask", IX86_BUILTIN_PMOVQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
32015   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16qi2_mask, "__builtin_ia32_pmovsdb512_mask", IX86_BUILTIN_PMOVSDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
32016   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16hi2_mask, "__builtin_ia32_pmovsdw512_mask", IX86_BUILTIN_PMOVSDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
32017   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div16qi2_mask, "__builtin_ia32_pmovsqb512_mask", IX86_BUILTIN_PMOVSQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
32018   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8si2_mask, "__builtin_ia32_pmovsqd512_mask", IX86_BUILTIN_PMOVSQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
32019   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8hi2_mask, "__builtin_ia32_pmovsqw512_mask", IX86_BUILTIN_PMOVSQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
32020   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv16qiv16si2_mask, "__builtin_ia32_pmovsxbd512_mask", IX86_BUILTIN_PMOVSXBD512, UNKNOWN, (int) V16SI_FTYPE_V16QI_V16SI_HI },
32021   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8qiv8di2_mask, "__builtin_ia32_pmovsxbq512_mask", IX86_BUILTIN_PMOVSXBQ512, UNKNOWN, (int) V8DI_FTYPE_V16QI_V8DI_QI },
32022   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8siv8di2_mask, "__builtin_ia32_pmovsxdq512_mask", IX86_BUILTIN_PMOVSXDQ512, UNKNOWN, (int) V8DI_FTYPE_V8SI_V8DI_QI },
32023   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv16hiv16si2_mask, "__builtin_ia32_pmovsxwd512_mask", IX86_BUILTIN_PMOVSXWD512, UNKNOWN, (int) V16SI_FTYPE_V16HI_V16SI_HI },
32024   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8hiv8di2_mask, "__builtin_ia32_pmovsxwq512_mask", IX86_BUILTIN_PMOVSXWQ512, UNKNOWN, (int) V8DI_FTYPE_V8HI_V8DI_QI },
32025   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16qi2_mask, "__builtin_ia32_pmovusdb512_mask", IX86_BUILTIN_PMOVUSDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
32026   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16hi2_mask, "__builtin_ia32_pmovusdw512_mask", IX86_BUILTIN_PMOVUSDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
32027   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div16qi2_mask, "__builtin_ia32_pmovusqb512_mask", IX86_BUILTIN_PMOVUSQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
32028   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8si2_mask, "__builtin_ia32_pmovusqd512_mask", IX86_BUILTIN_PMOVUSQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
32029   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8hi2_mask, "__builtin_ia32_pmovusqw512_mask", IX86_BUILTIN_PMOVUSQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
32030   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv16qiv16si2_mask, "__builtin_ia32_pmovzxbd512_mask", IX86_BUILTIN_PMOVZXBD512, UNKNOWN, (int) V16SI_FTYPE_V16QI_V16SI_HI },
32031   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8qiv8di2_mask, "__builtin_ia32_pmovzxbq512_mask", IX86_BUILTIN_PMOVZXBQ512, UNKNOWN, (int) V8DI_FTYPE_V16QI_V8DI_QI },
32032   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8siv8di2_mask, "__builtin_ia32_pmovzxdq512_mask", IX86_BUILTIN_PMOVZXDQ512, UNKNOWN, (int) V8DI_FTYPE_V8SI_V8DI_QI },
32033   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv16hiv16si2_mask, "__builtin_ia32_pmovzxwd512_mask", IX86_BUILTIN_PMOVZXWD512, UNKNOWN, (int) V16SI_FTYPE_V16HI_V16SI_HI },
32034   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8hiv8di2_mask, "__builtin_ia32_pmovzxwq512_mask", IX86_BUILTIN_PMOVZXWQ512, UNKNOWN, (int) V8DI_FTYPE_V8HI_V8DI_QI },
32035   { 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 },
32036   { OPTION_MASK_ISA_AVX512F, CODE_FOR_mulv16si3_mask, "__builtin_ia32_pmulld512_mask"  , IX86_BUILTIN_PMULLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32037   { 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 },
32038   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorv16si3_mask, "__builtin_ia32_pord512_mask", IX86_BUILTIN_PORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32039   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorv8di3_mask, "__builtin_ia32_porq512_mask", IX86_BUILTIN_PORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32040   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolv16si_mask, "__builtin_ia32_prold512_mask", IX86_BUILTIN_PROLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
32041   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolv8di_mask, "__builtin_ia32_prolq512_mask", IX86_BUILTIN_PROLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
32042   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolvv16si_mask, "__builtin_ia32_prolvd512_mask", IX86_BUILTIN_PROLVD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32043   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolvv8di_mask, "__builtin_ia32_prolvq512_mask", IX86_BUILTIN_PROLVQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32044   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorv16si_mask, "__builtin_ia32_prord512_mask", IX86_BUILTIN_PRORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
32045   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorv8di_mask, "__builtin_ia32_prorq512_mask", IX86_BUILTIN_PRORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
32046   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorvv16si_mask, "__builtin_ia32_prorvd512_mask", IX86_BUILTIN_PRORVD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32047   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorvv8di_mask, "__builtin_ia32_prorvq512_mask", IX86_BUILTIN_PRORVQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32048   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pshufdv3_mask, "__builtin_ia32_pshufd512_mask", IX86_BUILTIN_PSHUFD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
32049   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv16si3_mask, "__builtin_ia32_pslld512_mask", IX86_BUILTIN_PSLLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
32050   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv16si3_mask, "__builtin_ia32_pslldi512_mask", IX86_BUILTIN_PSLLDI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
32051   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv8di3_mask, "__builtin_ia32_psllq512_mask", IX86_BUILTIN_PSLLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
32052   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv8di3_mask, "__builtin_ia32_psllqi512_mask", IX86_BUILTIN_PSLLQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
32053   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashlvv16si_mask, "__builtin_ia32_psllv16si_mask", IX86_BUILTIN_PSLLVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32054   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashlvv8di_mask, "__builtin_ia32_psllv8di_mask", IX86_BUILTIN_PSLLVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32055   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv16si3_mask, "__builtin_ia32_psrad512_mask", IX86_BUILTIN_PSRAD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
32056   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv16si3_mask, "__builtin_ia32_psradi512_mask", IX86_BUILTIN_PSRADI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
32057   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv8di3_mask, "__builtin_ia32_psraq512_mask", IX86_BUILTIN_PSRAQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
32058   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv8di3_mask, "__builtin_ia32_psraqi512_mask", IX86_BUILTIN_PSRAQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
32059   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashrvv16si_mask, "__builtin_ia32_psrav16si_mask", IX86_BUILTIN_PSRAVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32060   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashrvv8di_mask, "__builtin_ia32_psrav8di_mask", IX86_BUILTIN_PSRAVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32061   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv16si3_mask, "__builtin_ia32_psrld512_mask", IX86_BUILTIN_PSRLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
32062   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv16si3_mask, "__builtin_ia32_psrldi512_mask", IX86_BUILTIN_PSRLDI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
32063   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv8di3_mask, "__builtin_ia32_psrlq512_mask", IX86_BUILTIN_PSRLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
32064   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv8di3_mask, "__builtin_ia32_psrlqi512_mask", IX86_BUILTIN_PSRLQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
32065   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_lshrvv16si_mask, "__builtin_ia32_psrlv16si_mask", IX86_BUILTIN_PSRLVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32066   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_lshrvv8di_mask, "__builtin_ia32_psrlv8di_mask", IX86_BUILTIN_PSRLVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32067   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv16si3_mask, "__builtin_ia32_psubd512_mask", IX86_BUILTIN_PSUBD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32068   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv8di3_mask, "__builtin_ia32_psubq512_mask", IX86_BUILTIN_PSUBQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32069   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testmv16si3_mask, "__builtin_ia32_ptestmd512", IX86_BUILTIN_PTESTMD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
32070   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testmv8di3_mask, "__builtin_ia32_ptestmq512", IX86_BUILTIN_PTESTMQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
32071   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testnmv16si3_mask, "__builtin_ia32_ptestnmd512", IX86_BUILTIN_PTESTNMD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
32072   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testnmv8di3_mask, "__builtin_ia32_ptestnmq512", IX86_BUILTIN_PTESTNMQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
32073   { 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 },
32074   { 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 },
32075   { 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 },
32076   { 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 },
32077   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorv16si3_mask, "__builtin_ia32_pxord512_mask", IX86_BUILTIN_PXORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32078   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorv8di3_mask, "__builtin_ia32_pxorq512_mask", IX86_BUILTIN_PXORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32079   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rcp14v8df_mask, "__builtin_ia32_rcp14pd512_mask", IX86_BUILTIN_RCP14PD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
32080   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rcp14v16sf_mask, "__builtin_ia32_rcp14ps512_mask", IX86_BUILTIN_RCP14PS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
32081   { OPTION_MASK_ISA_AVX512F, CODE_FOR_srcp14v2df, "__builtin_ia32_rcp14sd", IX86_BUILTIN_RCP14SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
32082   { OPTION_MASK_ISA_AVX512F, CODE_FOR_srcp14v4sf, "__builtin_ia32_rcp14ss", IX86_BUILTIN_RCP14SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
32083   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v8df_mask, "__builtin_ia32_rsqrt14pd512_mask", IX86_BUILTIN_RSQRT14PD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
32084   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v16sf_mask, "__builtin_ia32_rsqrt14ps512_mask", IX86_BUILTIN_RSQRT14PS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
32085   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v2df, "__builtin_ia32_rsqrt14sd", IX86_BUILTIN_RSQRT14SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
32086   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v4sf, "__builtin_ia32_rsqrt14ss", IX86_BUILTIN_RSQRT14SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
32087   { 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 },
32088   { 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 },
32089   { 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 },
32090   { 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 },
32091   { 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 },
32092   { 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 },
32093   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ucmpv16si3_mask, "__builtin_ia32_ucmpd512_mask", IX86_BUILTIN_UCMPD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_INT_HI },
32094   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ucmpv8di3_mask, "__builtin_ia32_ucmpq512_mask", IX86_BUILTIN_UCMPQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_INT_QI },
32095   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpckhpd512_mask, "__builtin_ia32_unpckhpd512_mask", IX86_BUILTIN_UNPCKHPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32096   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpckhps512_mask, "__builtin_ia32_unpckhps512_mask", IX86_BUILTIN_UNPCKHPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32097   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpcklpd512_mask, "__builtin_ia32_unpcklpd512_mask", IX86_BUILTIN_UNPCKLPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32098   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpcklps512_mask,  "__builtin_ia32_unpcklps512_mask", IX86_BUILTIN_UNPCKLPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32099   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_clzv16si2_mask, "__builtin_ia32_vplzcntd_512_mask", IX86_BUILTIN_VPCLZCNTD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
32100   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_clzv8di2_mask, "__builtin_ia32_vplzcntq_512_mask", IX86_BUILTIN_VPCLZCNTQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
32101   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_conflictv16si_mask, "__builtin_ia32_vpconflictsi_512_mask", IX86_BUILTIN_VPCONFLICTD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
32102   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_conflictv8di_mask, "__builtin_ia32_vpconflictdi_512_mask", IX86_BUILTIN_VPCONFLICTQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
32103   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permv8df_mask, "__builtin_ia32_permdf512_mask", IX86_BUILTIN_VPERMDF512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
32104   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permv8di_mask, "__builtin_ia32_permdi512_mask", IX86_BUILTIN_VPERMDI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
32105   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv16si3_mask, "__builtin_ia32_vpermi2vard512_mask", IX86_BUILTIN_VPERMI2VARD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32106   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv8df3_mask, "__builtin_ia32_vpermi2varpd512_mask", IX86_BUILTIN_VPERMI2VARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
32107   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv16sf3_mask, "__builtin_ia32_vpermi2varps512_mask", IX86_BUILTIN_VPERMI2VARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
32108   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv8di3_mask, "__builtin_ia32_vpermi2varq512_mask", IX86_BUILTIN_VPERMI2VARQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32109   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilv8df_mask, "__builtin_ia32_vpermilpd512_mask", IX86_BUILTIN_VPERMILPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
32110   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilv16sf_mask, "__builtin_ia32_vpermilps512_mask", IX86_BUILTIN_VPERMILPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI },
32111   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilvarv8df3_mask, "__builtin_ia32_vpermilvarpd512_mask", IX86_BUILTIN_VPERMILVARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
32112   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilvarv16sf3_mask, "__builtin_ia32_vpermilvarps512_mask", IX86_BUILTIN_VPERMILVARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
32113   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16si3_mask, "__builtin_ia32_vpermt2vard512_mask", IX86_BUILTIN_VPERMT2VARD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32114   { 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 },
32115   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8df3_mask, "__builtin_ia32_vpermt2varpd512_mask", IX86_BUILTIN_VPERMT2VARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_V8DF_QI },
32116   { 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 },
32117   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16sf3_mask, "__builtin_ia32_vpermt2varps512_mask", IX86_BUILTIN_VPERMT2VARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_V16SF_HI },
32118   { 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 },
32119   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8di3_mask, "__builtin_ia32_vpermt2varq512_mask", IX86_BUILTIN_VPERMT2VARQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32120   { 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 },
32121   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv8df_mask, "__builtin_ia32_permvardf512_mask", IX86_BUILTIN_VPERMVARDF512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
32122   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv8di_mask, "__builtin_ia32_permvardi512_mask", IX86_BUILTIN_VPERMVARDI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32123   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv16sf_mask, "__builtin_ia32_permvarsf512_mask", IX86_BUILTIN_VPERMVARSF512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
32124   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv16si_mask, "__builtin_ia32_permvarsi512_mask", IX86_BUILTIN_VPERMVARSI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
32125   { 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 },
32126   { 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 },
32127   { 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 },
32128   { 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 },
32129
32130   { OPTION_MASK_ISA_AVX512F, CODE_FOR_copysignv16sf3,  "__builtin_ia32_copysignps512", IX86_BUILTIN_CPYSGNPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF },
32131   { OPTION_MASK_ISA_AVX512F, CODE_FOR_copysignv8df3,  "__builtin_ia32_copysignpd512", IX86_BUILTIN_CPYSGNPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF },
32132   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sqrtv8df2, "__builtin_ia32_sqrtpd512", IX86_BUILTIN_SQRTPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF },
32133   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sqrtv16sf2, "__builtin_ia32_sqrtps512", IX86_BUILTIN_SQRTPS_NR512, UNKNOWN, (int) V16SF_FTYPE_V16SF },
32134   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_exp2v16sf, "__builtin_ia32_exp2ps", IX86_BUILTIN_EXP2PS, UNKNOWN, (int) V16SF_FTYPE_V16SF },
32135   { 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 },
32136   { 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 },
32137   { 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 },
32138
32139   /* Mask arithmetic operations */
32140   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andhi3, "__builtin_ia32_kandhi", IX86_BUILTIN_KAND16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32141   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kandnhi, "__builtin_ia32_kandnhi", IX86_BUILTIN_KANDN16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32142   { OPTION_MASK_ISA_AVX512F, CODE_FOR_one_cmplhi2, "__builtin_ia32_knothi", IX86_BUILTIN_KNOT16, UNKNOWN, (int) HI_FTYPE_HI },
32143   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorhi3, "__builtin_ia32_korhi", IX86_BUILTIN_KOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32144   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kortestchi, "__builtin_ia32_kortestchi", IX86_BUILTIN_KORTESTC16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32145   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kortestzhi, "__builtin_ia32_kortestzhi", IX86_BUILTIN_KORTESTZ16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32146   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kunpckhi, "__builtin_ia32_kunpckhi", IX86_BUILTIN_KUNPCKBW, UNKNOWN, (int) HI_FTYPE_HI_HI },
32147   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kxnorhi, "__builtin_ia32_kxnorhi", IX86_BUILTIN_KXNOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32148   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorhi3, "__builtin_ia32_kxorhi", IX86_BUILTIN_KXOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32149   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kmovw, "__builtin_ia32_kmov16", IX86_BUILTIN_KMOV16, UNKNOWN, (int) HI_FTYPE_HI },
32150
32151   /* SHA */
32152   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1msg1, 0, IX86_BUILTIN_SHA1MSG1, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32153   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1msg2, 0, IX86_BUILTIN_SHA1MSG2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32154   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1nexte, 0, IX86_BUILTIN_SHA1NEXTE, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32155   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1rnds4, 0, IX86_BUILTIN_SHA1RNDS4, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT },
32156   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256msg1, 0, IX86_BUILTIN_SHA256MSG1, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32157   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256msg2, 0, IX86_BUILTIN_SHA256MSG2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32158   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256rnds2, 0, IX86_BUILTIN_SHA256RNDS2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI },
32159
32160   /* AVX512VL.  */
32161   { 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 },
32162   { 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 },
32163   { 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 },
32164   { 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 },
32165   { 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 },
32166   { 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 },
32167   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4df_mask, "__builtin_ia32_movapd256_mask", IX86_BUILTIN_MOVAPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32168   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2df_mask, "__builtin_ia32_movapd128_mask", IX86_BUILTIN_MOVAPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32169   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8sf_mask, "__builtin_ia32_movaps256_mask", IX86_BUILTIN_MOVAPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32170   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4sf_mask, "__builtin_ia32_movaps128_mask", IX86_BUILTIN_MOVAPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32171   { 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 },
32172   { 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 },
32173   { 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 },
32174   { 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 },
32175   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4sf3_mask, "__builtin_ia32_minps_mask", IX86_BUILTIN_MINPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32176   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4sf3_mask, "__builtin_ia32_maxps_mask", IX86_BUILTIN_MAXPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32177   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv2df3_mask, "__builtin_ia32_minpd_mask", IX86_BUILTIN_MINPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32178   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv2df3_mask, "__builtin_ia32_maxpd_mask", IX86_BUILTIN_MAXPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32179   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4df3_mask, "__builtin_ia32_maxpd256_mask", IX86_BUILTIN_MAXPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32180   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8sf3_mask, "__builtin_ia32_maxps256_mask", IX86_BUILTIN_MAXPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32181   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4df3_mask, "__builtin_ia32_minpd256_mask", IX86_BUILTIN_MINPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32182   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8sf3_mask, "__builtin_ia32_minps256_mask", IX86_BUILTIN_MINPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32183   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4sf3_mask, "__builtin_ia32_mulps_mask", IX86_BUILTIN_MULPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32184   { 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 },
32185   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv2df3_mask, "__builtin_ia32_mulpd_mask", IX86_BUILTIN_MULPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32186   { 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 },
32187   { 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 },
32188   { 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 },
32189   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4df3_mask, "__builtin_ia32_mulpd256_mask", IX86_BUILTIN_MULPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32190   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8sf3_mask, "__builtin_ia32_mulps256_mask", IX86_BUILTIN_MULPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32191   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv2df3_mask, "__builtin_ia32_addpd128_mask", IX86_BUILTIN_ADDPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32192   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4df3_mask, "__builtin_ia32_addpd256_mask", IX86_BUILTIN_ADDPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32193   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4sf3_mask, "__builtin_ia32_addps128_mask", IX86_BUILTIN_ADDPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32194   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8sf3_mask, "__builtin_ia32_addps256_mask", IX86_BUILTIN_ADDPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32195   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv2df3_mask, "__builtin_ia32_subpd128_mask", IX86_BUILTIN_SUBPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32196   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4df3_mask, "__builtin_ia32_subpd256_mask", IX86_BUILTIN_SUBPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32197   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4sf3_mask, "__builtin_ia32_subps128_mask", IX86_BUILTIN_SUBPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32198   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8sf3_mask, "__builtin_ia32_subps256_mask", IX86_BUILTIN_SUBPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32199   { 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 },
32200   { 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 },
32201   { 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 },
32202   { 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 },
32203   { 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 },
32204   { 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 },
32205   { 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 },
32206   { 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 },
32207   { 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 },
32208   { 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 },
32209   { 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 },
32210   { 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 },
32211   { 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 },
32212   { 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 },
32213   { 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 },
32214   { 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 },
32215   { 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 },
32216   { 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 },
32217   { 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 },
32218   { 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 },
32219   { 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 },
32220   { 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 },
32221   { 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 },
32222   { 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 },
32223   { 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 },
32224   { 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 },
32225   { 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 },
32226   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv4dfv4si2_mask, "__builtin_ia32_cvtpd2udq256_mask", IX86_BUILTIN_CVTPD2UDQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32227   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv2dfv2si2_mask, "__builtin_ia32_cvtpd2udq128_mask", IX86_BUILTIN_CVTPD2UDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32228   { 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 },
32229   { 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 },
32230   { 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 },
32231   { 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 },
32232   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv8sfv8si2_mask, "__builtin_ia32_cvttps2dq256_mask", IX86_BUILTIN_CVTTPS2DQ256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32233   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4sfv4si2_mask, "__builtin_ia32_cvttps2dq128_mask", IX86_BUILTIN_CVTTPS2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32234   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv8sfv8si2_mask, "__builtin_ia32_cvttps2udq256_mask", IX86_BUILTIN_CVTTPS2UDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32235   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4sfv4si2_mask, "__builtin_ia32_cvttps2udq128_mask", IX86_BUILTIN_CVTTPS2UDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32236   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4dfv4si2_mask, "__builtin_ia32_cvttpd2dq256_mask", IX86_BUILTIN_CVTTPD2DQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32237   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvttpd2dq_mask, "__builtin_ia32_cvttpd2dq128_mask", IX86_BUILTIN_CVTTPD2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32238   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4dfv4si2_mask, "__builtin_ia32_cvttpd2udq256_mask", IX86_BUILTIN_CVTTPD2UDQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32239   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv2dfv2si2_mask, "__builtin_ia32_cvttpd2udq128_mask", IX86_BUILTIN_CVTTPD2UDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32240   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtpd2dq256_mask, "__builtin_ia32_cvtpd2dq256_mask", IX86_BUILTIN_CVTPD2DQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32241   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtpd2dq_mask, "__builtin_ia32_cvtpd2dq128_mask", IX86_BUILTIN_CVTPD2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32242   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4siv4df2_mask, "__builtin_ia32_cvtdq2pd256_mask", IX86_BUILTIN_CVTDQ2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SI_V4DF_QI },
32243   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtdq2pd_mask, "__builtin_ia32_cvtdq2pd128_mask", IX86_BUILTIN_CVTDQ2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SI_V2DF_QI },
32244   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4siv4df2_mask, "__builtin_ia32_cvtudq2pd256_mask", IX86_BUILTIN_CVTUDQ2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SI_V4DF_QI },
32245   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv2siv2df2_mask, "__builtin_ia32_cvtudq2pd128_mask", IX86_BUILTIN_CVTUDQ2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SI_V2DF_QI },
32246   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv8siv8sf2_mask, "__builtin_ia32_cvtdq2ps256_mask", IX86_BUILTIN_CVTDQ2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_QI },
32247   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4siv4sf2_mask, "__builtin_ia32_cvtdq2ps128_mask", IX86_BUILTIN_CVTDQ2PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_QI },
32248   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv8siv8sf2_mask, "__builtin_ia32_cvtudq2ps256_mask", IX86_BUILTIN_CVTUDQ2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_QI },
32249   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4siv4sf2_mask, "__builtin_ia32_cvtudq2ps128_mask", IX86_BUILTIN_CVTUDQ2PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_QI },
32250   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtps2pd256_mask, "__builtin_ia32_cvtps2pd256_mask", IX86_BUILTIN_CVTPS2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SF_V4DF_QI },
32251   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtps2pd_mask, "__builtin_ia32_cvtps2pd128_mask", IX86_BUILTIN_CVTPS2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SF_V2DF_QI },
32252   { 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 },
32253   { 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 },
32254   { 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 },
32255   { 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 },
32256   { 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 },
32257   { 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 },
32258   { 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 },
32259   { 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 },
32260   { 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 },
32261   { 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 },
32262   { 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 },
32263   { 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 },
32264   { 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 },
32265   { 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 },
32266   { 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 },
32267   { 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 },
32268   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv8sf_mask, "__builtin_ia32_broadcastss256_mask", IX86_BUILTIN_BROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_V4SF_V8SF_QI },
32269   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4sf_mask, "__builtin_ia32_broadcastss128_mask", IX86_BUILTIN_BROADCASTSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32270   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4df_mask, "__builtin_ia32_broadcastsd256_mask", IX86_BUILTIN_BROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_V2DF_V4DF_QI },
32271   { 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 },
32272   { 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 },
32273   { 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 },
32274   { 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 },
32275   { 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 },
32276   { 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 },
32277   { 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 },
32278   { 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 },
32279   { 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 },
32280   { 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 },
32281   { 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 },
32282   { 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 },
32283   { 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 },
32284   { 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 },
32285   { 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 },
32286   { 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 },
32287   { 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 },
32288   { 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 },
32289   { 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 },
32290   { 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 },
32291   { 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 },
32292   { 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 },
32293   { 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 },
32294   { 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 },
32295   { 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 },
32296   { 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 },
32297   { 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 },
32298   { 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 },
32299   { 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 },
32300   { 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 },
32301   { 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 },
32302   { 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 },
32303   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducesv2df, "__builtin_ia32_reducesd", IX86_BUILTIN_REDUCESD_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32304   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducesv4sf, "__builtin_ia32_reducess", IX86_BUILTIN_REDUCESS_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32305   { 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 },
32306   { 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 },
32307   { 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 },
32308   { 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 },
32309   { 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 },
32310   { 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 },
32311   { 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 },
32312   { 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 },
32313   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v4df_mask, "__builtin_ia32_rcp14pd256_mask", IX86_BUILTIN_RCP14PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32314   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v2df_mask, "__builtin_ia32_rcp14pd128_mask", IX86_BUILTIN_RCP14PD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32315   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v8sf_mask, "__builtin_ia32_rcp14ps256_mask", IX86_BUILTIN_RCP14PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32316   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v4sf_mask, "__builtin_ia32_rcp14ps128_mask", IX86_BUILTIN_RCP14PS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32317   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v4df_mask, "__builtin_ia32_rsqrt14pd256_mask", IX86_BUILTIN_RSQRT14PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32318   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v2df_mask, "__builtin_ia32_rsqrt14pd128_mask", IX86_BUILTIN_RSQRT14PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32319   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v8sf_mask, "__builtin_ia32_rsqrt14ps256_mask", IX86_BUILTIN_RSQRT14PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32320   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v4sf_mask, "__builtin_ia32_rsqrt14ps128_mask", IX86_BUILTIN_RSQRT14PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32321   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_sqrtv4df2_mask, "__builtin_ia32_sqrtpd256_mask", IX86_BUILTIN_SQRTPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32322   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_sqrtv2df2_mask, "__builtin_ia32_sqrtpd128_mask", IX86_BUILTIN_SQRTPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32323   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_sqrtv8sf2_mask, "__builtin_ia32_sqrtps256_mask", IX86_BUILTIN_SQRTPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32324   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_sqrtv4sf2_mask, "__builtin_ia32_sqrtps128_mask", IX86_BUILTIN_SQRTPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32325   { 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 },
32326   { 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 },
32327   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4si3_mask, "__builtin_ia32_paddd128_mask", IX86_BUILTIN_PADDD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32328   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv2di3_mask, "__builtin_ia32_paddq128_mask", IX86_BUILTIN_PADDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32329   { 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 },
32330   { 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 },
32331   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4si3_mask, "__builtin_ia32_psubd128_mask", IX86_BUILTIN_PSUBD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32332   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv2di3_mask, "__builtin_ia32_psubq128_mask", IX86_BUILTIN_PSUBQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32333   { 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 },
32334   { 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 },
32335   { 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 },
32336   { 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 },
32337   { 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 },
32338   { 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 },
32339   { 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 },
32340   { 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 },
32341   { 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 },
32342   { 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 },
32343   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8si3_mask, "__builtin_ia32_paddd256_mask", IX86_BUILTIN_PADDD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32344   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4di3_mask, "__builtin_ia32_paddq256_mask", IX86_BUILTIN_PADDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32345   { 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 },
32346   { 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 },
32347   { 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 },
32348   { 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 },
32349   { 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 },
32350   { 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 },
32351   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8si3_mask, "__builtin_ia32_psubd256_mask", IX86_BUILTIN_PSUBD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32352   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4di3_mask, "__builtin_ia32_psubq256_mask", IX86_BUILTIN_PSUBQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32353   { 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 },
32354   { 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 },
32355   { 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 },
32356   { 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 },
32357   { 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 },
32358   { 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 },
32359   { 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 },
32360   { 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 },
32361   { 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 },
32362   { 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 },
32363   { 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 },
32364   { 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 },
32365   { 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 },
32366   { 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 },
32367   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4qi2_mask, "__builtin_ia32_pmovdb128_mask", IX86_BUILTIN_PMOVDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32368   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8qi2_mask, "__builtin_ia32_pmovdb256_mask", IX86_BUILTIN_PMOVDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32369   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4qi2_mask, "__builtin_ia32_pmovsdb128_mask", IX86_BUILTIN_PMOVSDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32370   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8qi2_mask, "__builtin_ia32_pmovsdb256_mask", IX86_BUILTIN_PMOVSDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32371   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4qi2_mask, "__builtin_ia32_pmovusdb128_mask", IX86_BUILTIN_PMOVUSDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32372   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8qi2_mask, "__builtin_ia32_pmovusdb256_mask", IX86_BUILTIN_PMOVUSDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32373   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4hi2_mask, "__builtin_ia32_pmovdw128_mask", IX86_BUILTIN_PMOVDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32374   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8hi2_mask, "__builtin_ia32_pmovdw256_mask", IX86_BUILTIN_PMOVDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32375   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4hi2_mask, "__builtin_ia32_pmovsdw128_mask", IX86_BUILTIN_PMOVSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32376   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8hi2_mask, "__builtin_ia32_pmovsdw256_mask", IX86_BUILTIN_PMOVSDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32377   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4hi2_mask, "__builtin_ia32_pmovusdw128_mask", IX86_BUILTIN_PMOVUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32378   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8hi2_mask, "__builtin_ia32_pmovusdw256_mask", IX86_BUILTIN_PMOVUSDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32379   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2qi2_mask, "__builtin_ia32_pmovqb128_mask", IX86_BUILTIN_PMOVQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32380   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4qi2_mask, "__builtin_ia32_pmovqb256_mask", IX86_BUILTIN_PMOVQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32381   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2qi2_mask, "__builtin_ia32_pmovsqb128_mask", IX86_BUILTIN_PMOVSQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32382   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4qi2_mask, "__builtin_ia32_pmovsqb256_mask", IX86_BUILTIN_PMOVSQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32383   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2qi2_mask, "__builtin_ia32_pmovusqb128_mask", IX86_BUILTIN_PMOVUSQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32384   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4qi2_mask, "__builtin_ia32_pmovusqb256_mask", IX86_BUILTIN_PMOVUSQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32385   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2hi2_mask, "__builtin_ia32_pmovqw128_mask", IX86_BUILTIN_PMOVQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32386   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4hi2_mask, "__builtin_ia32_pmovqw256_mask", IX86_BUILTIN_PMOVQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32387   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2hi2_mask, "__builtin_ia32_pmovsqw128_mask", IX86_BUILTIN_PMOVSQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32388   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4hi2_mask, "__builtin_ia32_pmovsqw256_mask", IX86_BUILTIN_PMOVSQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32389   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2hi2_mask, "__builtin_ia32_pmovusqw128_mask", IX86_BUILTIN_PMOVUSQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32390   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4hi2_mask, "__builtin_ia32_pmovusqw256_mask", IX86_BUILTIN_PMOVUSQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32391   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2si2_mask, "__builtin_ia32_pmovqd128_mask", IX86_BUILTIN_PMOVQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32392   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4si2_mask, "__builtin_ia32_pmovqd256_mask", IX86_BUILTIN_PMOVQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32393   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2si2_mask, "__builtin_ia32_pmovsqd128_mask", IX86_BUILTIN_PMOVSQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32394   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4si2_mask, "__builtin_ia32_pmovsqd256_mask", IX86_BUILTIN_PMOVSQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32395   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2si2_mask, "__builtin_ia32_pmovusqd128_mask", IX86_BUILTIN_PMOVUSQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32396   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4si2_mask, "__builtin_ia32_pmovusqd256_mask", IX86_BUILTIN_PMOVUSQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32397   { 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 },
32398   { 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 },
32399   { 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 },
32400   { 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 },
32401   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv8sf_mask, "__builtin_ia32_getexpps256_mask", IX86_BUILTIN_GETEXPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32402   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv4df_mask, "__builtin_ia32_getexppd256_mask", IX86_BUILTIN_GETEXPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32403   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv4sf_mask, "__builtin_ia32_getexpps128_mask", IX86_BUILTIN_GETEXPPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32404   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv2df_mask, "__builtin_ia32_getexppd128_mask", IX86_BUILTIN_GETEXPPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32405   { 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 },
32406   { 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 },
32407   { 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 },
32408   { 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 },
32409   { 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 },
32410   { 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 },
32411   { 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 },
32412   { 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 },
32413   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv4di2_mask, "__builtin_ia32_pabsq256_mask", IX86_BUILTIN_PABSQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32414   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv2di2_mask, "__builtin_ia32_pabsq128_mask", IX86_BUILTIN_PABSQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32415   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv8si2_mask, "__builtin_ia32_pabsd256_mask", IX86_BUILTIN_PABSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32416   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv4si2_mask, "__builtin_ia32_pabsd128_mask", IX86_BUILTIN_PABSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32417   { 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 },
32418   { 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 },
32419   { 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 },
32420   { 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 },
32421   { 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 },
32422   { 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 },
32423   { 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 },
32424   { 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 },
32425   { 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 },
32426   { 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 },
32427   { 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 },
32428   { 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 },
32429   { 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 },
32430   { 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 },
32431   { 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 },
32432   { 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 },
32433   { 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 },
32434   { 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 },
32435   { 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 },
32436   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4si3_mask, "__builtin_ia32_pslldi128_mask", IX86_BUILTIN_PSLLDI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32437   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv2di3_mask, "__builtin_ia32_psllqi128_mask", IX86_BUILTIN_PSLLQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32438   { 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 },
32439   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4si3_mask, "__builtin_ia32_pslld128_mask", IX86_BUILTIN_PSLLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32440   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv2di3_mask, "__builtin_ia32_psllq128_mask", IX86_BUILTIN_PSLLQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32441   { 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 },
32442   { 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 },
32443   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8si3_mask, "__builtin_ia32_pslldi256_mask", IX86_BUILTIN_PSLLDI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32444   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8si3_mask, "__builtin_ia32_pslld256_mask", IX86_BUILTIN_PSLLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32445   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4di3_mask, "__builtin_ia32_psllqi256_mask", IX86_BUILTIN_PSLLQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32446   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4di3_mask, "__builtin_ia32_psllq256_mask", IX86_BUILTIN_PSLLQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32447   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4si3_mask, "__builtin_ia32_psradi128_mask", IX86_BUILTIN_PSRADI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32448   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4si3_mask, "__builtin_ia32_psrad128_mask", IX86_BUILTIN_PSRAD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32449   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8si3_mask, "__builtin_ia32_psradi256_mask", IX86_BUILTIN_PSRADI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32450   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8si3_mask, "__builtin_ia32_psrad256_mask", IX86_BUILTIN_PSRAD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32451   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv2di3_mask, "__builtin_ia32_psraqi128_mask", IX86_BUILTIN_PSRAQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32452   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv2di3_mask, "__builtin_ia32_psraq128_mask", IX86_BUILTIN_PSRAQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32453   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4di3_mask, "__builtin_ia32_psraqi256_mask", IX86_BUILTIN_PSRAQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32454   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4di3_mask, "__builtin_ia32_psraq256_mask", IX86_BUILTIN_PSRAQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32455   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv8si3_mask, "__builtin_ia32_pandd256_mask", IX86_BUILTIN_PANDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32456   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4si3_mask, "__builtin_ia32_pandd128_mask", IX86_BUILTIN_PANDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32457   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4si3_mask, "__builtin_ia32_psrldi128_mask", IX86_BUILTIN_PSRLDI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32458   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4si3_mask, "__builtin_ia32_psrld128_mask", IX86_BUILTIN_PSRLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32459   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8si3_mask, "__builtin_ia32_psrldi256_mask", IX86_BUILTIN_PSRLDI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32460   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8si3_mask, "__builtin_ia32_psrld256_mask", IX86_BUILTIN_PSRLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32461   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv2di3_mask, "__builtin_ia32_psrlqi128_mask", IX86_BUILTIN_PSRLQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32462   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv2di3_mask, "__builtin_ia32_psrlq128_mask", IX86_BUILTIN_PSRLQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32463   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4di3_mask, "__builtin_ia32_psrlqi256_mask", IX86_BUILTIN_PSRLQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32464   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4di3_mask, "__builtin_ia32_psrlq256_mask", IX86_BUILTIN_PSRLQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32465   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4di3_mask, "__builtin_ia32_pandq256_mask", IX86_BUILTIN_PANDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32466   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv2di3_mask, "__builtin_ia32_pandq128_mask", IX86_BUILTIN_PANDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32467   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_andnotv8si3_mask, "__builtin_ia32_pandnd256_mask", IX86_BUILTIN_PANDND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32468   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv4si3_mask, "__builtin_ia32_pandnd128_mask", IX86_BUILTIN_PANDND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32469   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_andnotv4di3_mask, "__builtin_ia32_pandnq256_mask", IX86_BUILTIN_PANDNQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32470   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv2di3_mask, "__builtin_ia32_pandnq128_mask", IX86_BUILTIN_PANDNQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32471   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv8si3_mask, "__builtin_ia32_pord256_mask", IX86_BUILTIN_PORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32472   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4si3_mask, "__builtin_ia32_pord128_mask", IX86_BUILTIN_PORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32473   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4di3_mask, "__builtin_ia32_porq256_mask", IX86_BUILTIN_PORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32474   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv2di3_mask, "__builtin_ia32_porq128_mask", IX86_BUILTIN_PORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32475   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv8si3_mask, "__builtin_ia32_pxord256_mask", IX86_BUILTIN_PXORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32476   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4si3_mask, "__builtin_ia32_pxord128_mask", IX86_BUILTIN_PXORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32477   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4di3_mask, "__builtin_ia32_pxorq256_mask", IX86_BUILTIN_PXORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32478   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv2di3_mask, "__builtin_ia32_pxorq128_mask", IX86_BUILTIN_PXORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32479   { 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 },
32480   { 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 },
32481   { 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 },
32482   { 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 },
32483   { 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 },
32484   { 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 },
32485   { 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 },
32486   { 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 },
32487   { 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 },
32488   { 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 },
32489   { 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 },
32490   { 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 },
32491   { 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 },
32492   { 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 },
32493   { 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 },
32494   { 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 },
32495   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv4df_mask, "__builtin_ia32_scalefpd256_mask", IX86_BUILTIN_SCALEFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32496   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv8sf_mask, "__builtin_ia32_scalefps256_mask", IX86_BUILTIN_SCALEFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32497   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv2df_mask, "__builtin_ia32_scalefpd128_mask", IX86_BUILTIN_SCALEFPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32498   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv4sf_mask, "__builtin_ia32_scalefps128_mask", IX86_BUILTIN_SCALEFPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32499   { 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 },
32500   { 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 },
32501   { 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 },
32502   { 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 },
32503   { 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 },
32504   { 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 },
32505   { 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 },
32506   { 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 },
32507   { 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 },
32508   { 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 },
32509   { 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 },
32510   { 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 },
32511   { 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 },
32512   { 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 },
32513   { 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 },
32514   { 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 },
32515   { 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 },
32516   { 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 },
32517   { 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 },
32518   { 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 },
32519   { 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 },
32520   { 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 },
32521   { 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 },
32522   { 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 },
32523   { 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 },
32524   { 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 },
32525   { 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 },
32526   { 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 },
32527   { 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 },
32528   { 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 },
32529   { 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 },
32530   { 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 },
32531   { 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 },
32532   { 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 },
32533   { 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 },
32534   { 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 },
32535   { 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 },
32536   { 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 },
32537   { 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 },
32538   { 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 },
32539   { 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 },
32540   { 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 },
32541   { 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 },
32542   { 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 },
32543   { 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 },
32544   { 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 },
32545   { 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 },
32546   { 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 },
32547   { 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 },
32548   { 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 },
32549   { 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 },
32550   { 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 },
32551   { 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 },
32552   { 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 },
32553   { 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 },
32554   { 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 },
32555   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ufix_notruncv8sfv8si_mask, "__builtin_ia32_cvtps2udq256_mask", IX86_BUILTIN_CVTPS2UDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32556   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ufix_notruncv4sfv4si_mask, "__builtin_ia32_cvtps2udq128_mask", IX86_BUILTIN_CVTPS2UDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32557   { 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 },
32558   { 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 },
32559   { 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 },
32560   { 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 },
32561   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv8sf_mask, "__builtin_ia32_getmantps256_mask", IX86_BUILTIN_GETMANTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT_V8SF_QI },
32562   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv4sf_mask, "__builtin_ia32_getmantps128_mask", IX86_BUILTIN_GETMANTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_V4SF_QI },
32563   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv4df_mask, "__builtin_ia32_getmantpd256_mask", IX86_BUILTIN_GETMANTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32564   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv2df_mask, "__builtin_ia32_getmantpd128_mask", IX86_BUILTIN_GETMANTPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT_V2DF_QI },
32565   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movddup256_mask, "__builtin_ia32_movddup256_mask", IX86_BUILTIN_MOVDDUP256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32566   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_dupv2df_mask, "__builtin_ia32_movddup128_mask", IX86_BUILTIN_MOVDDUP128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32567   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movshdup256_mask, "__builtin_ia32_movshdup256_mask", IX86_BUILTIN_MOVSHDUP256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32568   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse3_movshdup_mask, "__builtin_ia32_movshdup128_mask", IX86_BUILTIN_MOVSHDUP128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32569   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movsldup256_mask, "__builtin_ia32_movsldup256_mask", IX86_BUILTIN_MOVSLDUP256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32570   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse3_movsldup_mask, "__builtin_ia32_movsldup128_mask", IX86_BUILTIN_MOVSLDUP128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32571   { 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 },
32572   { 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 },
32573   { 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 },
32574   { 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 },
32575   { 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 },
32576   { 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 },
32577   { 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 },
32578   { 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 },
32579   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4di3_mask, "__builtin_ia32_vpermt2varq256_mask", IX86_BUILTIN_VPERMT2VARQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32580   { 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 },
32581   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8si3_mask, "__builtin_ia32_vpermt2vard256_mask", IX86_BUILTIN_VPERMT2VARD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32582   { 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 },
32583   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4di3_mask, "__builtin_ia32_vpermi2varq256_mask", IX86_BUILTIN_VPERMI2VARQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32584   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8si3_mask, "__builtin_ia32_vpermi2vard256_mask", IX86_BUILTIN_VPERMI2VARD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32585   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4df3_mask, "__builtin_ia32_vpermt2varpd256_mask", IX86_BUILTIN_VPERMT2VARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DI_V4DF_V4DF_QI },
32586   { 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 },
32587   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8sf3_mask, "__builtin_ia32_vpermt2varps256_mask", IX86_BUILTIN_VPERMT2VARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_V8SF_QI },
32588   { 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 },
32589   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4df3_mask, "__builtin_ia32_vpermi2varpd256_mask", IX86_BUILTIN_VPERMI2VARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI_V4DF_QI },
32590   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8sf3_mask, "__builtin_ia32_vpermi2varps256_mask", IX86_BUILTIN_VPERMI2VARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI_V8SF_QI },
32591   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2di3_mask, "__builtin_ia32_vpermt2varq128_mask", IX86_BUILTIN_VPERMT2VARQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32592   { 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 },
32593   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4si3_mask, "__builtin_ia32_vpermt2vard128_mask", IX86_BUILTIN_VPERMT2VARD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32594   { 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 },
32595   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv2di3_mask, "__builtin_ia32_vpermi2varq128_mask", IX86_BUILTIN_VPERMI2VARQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32596   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4si3_mask, "__builtin_ia32_vpermi2vard128_mask", IX86_BUILTIN_VPERMI2VARD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32597   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2df3_mask, "__builtin_ia32_vpermt2varpd128_mask", IX86_BUILTIN_VPERMT2VARPD128, UNKNOWN, (int) V2DF_FTYPE_V2DI_V2DF_V2DF_QI },
32598   { 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 },
32599   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4sf3_mask, "__builtin_ia32_vpermt2varps128_mask", IX86_BUILTIN_VPERMT2VARPS128, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_V4SF_QI },
32600   { 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 },
32601   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv2df3_mask, "__builtin_ia32_vpermi2varpd128_mask", IX86_BUILTIN_VPERMI2VARPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI_V2DF_QI },
32602   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4sf3_mask, "__builtin_ia32_vpermi2varps128_mask", IX86_BUILTIN_VPERMI2VARPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI_V4SF_QI },
32603   { 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 },
32604   { 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 },
32605   { 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 },
32606   { 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 },
32607   { 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 },
32608   { 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 },
32609   { 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 },
32610   { 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 },
32611   { 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 },
32612   { 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 },
32613   { 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 },
32614   { 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 },
32615   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv4di_mask, "__builtin_ia32_prolvq256_mask", IX86_BUILTIN_PROLVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32616   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv2di_mask, "__builtin_ia32_prolvq128_mask", IX86_BUILTIN_PROLVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32617   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv4di_mask, "__builtin_ia32_prolq256_mask", IX86_BUILTIN_PROLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32618   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv2di_mask, "__builtin_ia32_prolq128_mask", IX86_BUILTIN_PROLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32619   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv4di_mask, "__builtin_ia32_prorvq256_mask", IX86_BUILTIN_PRORVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32620   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv2di_mask, "__builtin_ia32_prorvq128_mask", IX86_BUILTIN_PRORVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32621   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv4di_mask, "__builtin_ia32_prorq256_mask", IX86_BUILTIN_PRORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32622   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv2di_mask, "__builtin_ia32_prorq128_mask", IX86_BUILTIN_PRORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32623   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv2di_mask, "__builtin_ia32_psravq128_mask", IX86_BUILTIN_PSRAVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32624   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv4di_mask, "__builtin_ia32_psravq256_mask", IX86_BUILTIN_PSRAVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32625   { 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 },
32626   { 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 },
32627   { 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 },
32628   { 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 },
32629   { 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 },
32630   { 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 },
32631   { 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 },
32632   { 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 },
32633   { 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 },
32634   { 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 },
32635   { 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 },
32636   { 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 },
32637   { 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 },
32638   { 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 },
32639   { 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 },
32640   { 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 },
32641   { 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 },
32642   { 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 },
32643   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv8si_mask, "__builtin_ia32_prorvd256_mask", IX86_BUILTIN_PRORVD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32644   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv8si_mask, "__builtin_ia32_prolvd256_mask", IX86_BUILTIN_PROLVD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32645   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv8si_mask, "__builtin_ia32_prord256_mask", IX86_BUILTIN_PRORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32646   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv8si_mask, "__builtin_ia32_prold256_mask", IX86_BUILTIN_PROLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32647   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv4si_mask, "__builtin_ia32_prorvd128_mask", IX86_BUILTIN_PRORVD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32648   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv4si_mask, "__builtin_ia32_prolvd128_mask", IX86_BUILTIN_PROLVD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32649   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv4si_mask, "__builtin_ia32_prord128_mask", IX86_BUILTIN_PRORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32650   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv4si_mask, "__builtin_ia32_prold128_mask", IX86_BUILTIN_PROLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32651   { 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 },
32652   { 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 },
32653   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vmfpclassv2df, "__builtin_ia32_fpclasssd", IX86_BUILTIN_FPCLASSSD, UNKNOWN, (int) QI_FTYPE_V2DF_INT },
32654   { 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 },
32655   { 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 },
32656   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vmfpclassv4sf, "__builtin_ia32_fpclassss", IX86_BUILTIN_FPCLASSSS, UNKNOWN, (int) QI_FTYPE_V4SF_INT },
32657   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtb2maskv16qi, "__builtin_ia32_cvtb2mask128", IX86_BUILTIN_CVTB2MASK128, UNKNOWN, (int) HI_FTYPE_V16QI },
32658   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtb2maskv32qi, "__builtin_ia32_cvtb2mask256", IX86_BUILTIN_CVTB2MASK256, UNKNOWN, (int) SI_FTYPE_V32QI },
32659   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtw2maskv8hi, "__builtin_ia32_cvtw2mask128", IX86_BUILTIN_CVTW2MASK128, UNKNOWN, (int) QI_FTYPE_V8HI },
32660   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtw2maskv16hi, "__builtin_ia32_cvtw2mask256", IX86_BUILTIN_CVTW2MASK256, UNKNOWN, (int) HI_FTYPE_V16HI },
32661   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtd2maskv4si, "__builtin_ia32_cvtd2mask128", IX86_BUILTIN_CVTD2MASK128, UNKNOWN, (int) QI_FTYPE_V4SI },
32662   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtd2maskv8si, "__builtin_ia32_cvtd2mask256", IX86_BUILTIN_CVTD2MASK256, UNKNOWN, (int) QI_FTYPE_V8SI },
32663   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtq2maskv2di, "__builtin_ia32_cvtq2mask128", IX86_BUILTIN_CVTQ2MASK128, UNKNOWN, (int) QI_FTYPE_V2DI },
32664   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtq2maskv4di, "__builtin_ia32_cvtq2mask256", IX86_BUILTIN_CVTQ2MASK256, UNKNOWN, (int) QI_FTYPE_V4DI },
32665   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2bv16qi, "__builtin_ia32_cvtmask2b128", IX86_BUILTIN_CVTMASK2B128, UNKNOWN, (int) V16QI_FTYPE_HI },
32666   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2bv32qi, "__builtin_ia32_cvtmask2b256", IX86_BUILTIN_CVTMASK2B256, UNKNOWN, (int) V32QI_FTYPE_SI },
32667   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2wv8hi, "__builtin_ia32_cvtmask2w128", IX86_BUILTIN_CVTMASK2W128, UNKNOWN, (int) V8HI_FTYPE_QI },
32668   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2wv16hi, "__builtin_ia32_cvtmask2w256", IX86_BUILTIN_CVTMASK2W256, UNKNOWN, (int) V16HI_FTYPE_HI },
32669   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2dv4si, "__builtin_ia32_cvtmask2d128", IX86_BUILTIN_CVTMASK2D128, UNKNOWN, (int) V4SI_FTYPE_QI },
32670   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2dv8si, "__builtin_ia32_cvtmask2d256", IX86_BUILTIN_CVTMASK2D256, UNKNOWN, (int) V8SI_FTYPE_QI },
32671   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2qv2di, "__builtin_ia32_cvtmask2q128", IX86_BUILTIN_CVTMASK2Q128, UNKNOWN, (int) V2DI_FTYPE_QI },
32672   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2qv4di, "__builtin_ia32_cvtmask2q256", IX86_BUILTIN_CVTMASK2Q256, UNKNOWN, (int) V4DI_FTYPE_QI },
32673   { 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 },
32674   { 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 },
32675   { 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 },
32676   { 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 },
32677   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv4si3_mask, "__builtin_ia32_pcmpeqd128_mask", IX86_BUILTIN_PCMPEQD128_MASK, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32678   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv8si3_mask, "__builtin_ia32_pcmpeqd256_mask", IX86_BUILTIN_PCMPEQD256_MASK, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32679   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv2di3_mask, "__builtin_ia32_pcmpeqq128_mask", IX86_BUILTIN_PCMPEQQ128_MASK, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32680   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv4di3_mask, "__builtin_ia32_pcmpeqq256_mask", IX86_BUILTIN_PCMPEQQ256_MASK, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32681   { 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 },
32682   { 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 },
32683   { 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 },
32684   { 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 },
32685   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv4si3_mask, "__builtin_ia32_pcmpgtd128_mask", IX86_BUILTIN_PCMPGTD128_MASK, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32686   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv8si3_mask, "__builtin_ia32_pcmpgtd256_mask", IX86_BUILTIN_PCMPGTD256_MASK, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32687   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv2di3_mask, "__builtin_ia32_pcmpgtq128_mask", IX86_BUILTIN_PCMPGTQ128_MASK, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32688   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv4di3_mask, "__builtin_ia32_pcmpgtq256_mask", IX86_BUILTIN_PCMPGTQ256_MASK, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32689   { 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 },
32690   { 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 },
32691   { 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 },
32692   { 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 },
32693   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv4si3_mask, "__builtin_ia32_ptestmd128", IX86_BUILTIN_PTESTMD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32694   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv8si3_mask, "__builtin_ia32_ptestmd256", IX86_BUILTIN_PTESTMD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32695   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv2di3_mask, "__builtin_ia32_ptestmq128", IX86_BUILTIN_PTESTMQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32696   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv4di3_mask, "__builtin_ia32_ptestmq256", IX86_BUILTIN_PTESTMQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32697   { 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 },
32698   { 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 },
32699   { 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 },
32700   { 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 },
32701   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv4si3_mask, "__builtin_ia32_ptestnmd128", IX86_BUILTIN_PTESTNMD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32702   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv8si3_mask, "__builtin_ia32_ptestnmd256", IX86_BUILTIN_PTESTNMD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32703   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv2di3_mask, "__builtin_ia32_ptestnmq128", IX86_BUILTIN_PTESTNMQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32704   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv4di3_mask, "__builtin_ia32_ptestnmq256", IX86_BUILTIN_PTESTNMQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32705   { 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 },
32706   { 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 },
32707   { 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 },
32708   { 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 },
32709   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4df_mask, "__builtin_ia32_compressdf256_mask", IX86_BUILTIN_COMPRESSPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32710   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv2df_mask, "__builtin_ia32_compressdf128_mask", IX86_BUILTIN_COMPRESSPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32711   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv8sf_mask, "__builtin_ia32_compresssf256_mask", IX86_BUILTIN_COMPRESSPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32712   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4sf_mask, "__builtin_ia32_compresssf128_mask", IX86_BUILTIN_COMPRESSPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32713   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4di_mask, "__builtin_ia32_compressdi256_mask", IX86_BUILTIN_PCOMPRESSQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32714   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv2di_mask, "__builtin_ia32_compressdi128_mask", IX86_BUILTIN_PCOMPRESSQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32715   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv8si_mask, "__builtin_ia32_compresssi256_mask", IX86_BUILTIN_PCOMPRESSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32716   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4si_mask, "__builtin_ia32_compresssi128_mask", IX86_BUILTIN_PCOMPRESSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32717   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_mask, "__builtin_ia32_expanddf256_mask", IX86_BUILTIN_EXPANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32718   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_mask, "__builtin_ia32_expanddf128_mask", IX86_BUILTIN_EXPANDPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32719   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_mask, "__builtin_ia32_expandsf256_mask", IX86_BUILTIN_EXPANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32720   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_mask, "__builtin_ia32_expandsf128_mask", IX86_BUILTIN_EXPANDPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32721   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_mask, "__builtin_ia32_expanddi256_mask", IX86_BUILTIN_PEXPANDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32722   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_mask, "__builtin_ia32_expanddi128_mask", IX86_BUILTIN_PEXPANDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32723   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_mask, "__builtin_ia32_expandsi256_mask", IX86_BUILTIN_PEXPANDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32724   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_mask, "__builtin_ia32_expandsi128_mask", IX86_BUILTIN_PEXPANDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32725   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_maskz, "__builtin_ia32_expanddf256_maskz", IX86_BUILTIN_EXPANDPD256Z, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32726   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_maskz, "__builtin_ia32_expanddf128_maskz", IX86_BUILTIN_EXPANDPD128Z, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32727   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_maskz, "__builtin_ia32_expandsf256_maskz", IX86_BUILTIN_EXPANDPS256Z, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32728   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_maskz, "__builtin_ia32_expandsf128_maskz", IX86_BUILTIN_EXPANDPS128Z, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32729   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_maskz, "__builtin_ia32_expanddi256_maskz", IX86_BUILTIN_PEXPANDQ256Z, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32730   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_maskz, "__builtin_ia32_expanddi128_maskz", IX86_BUILTIN_PEXPANDQ128Z, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32731   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_maskz, "__builtin_ia32_expandsi256_maskz", IX86_BUILTIN_PEXPANDD256Z, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32732   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_maskz, "__builtin_ia32_expandsi128_maskz", IX86_BUILTIN_PEXPANDD128Z, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32733   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8si3_mask, "__builtin_ia32_pmaxsd256_mask", IX86_BUILTIN_PMAXSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32734   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8si3_mask, "__builtin_ia32_pminsd256_mask", IX86_BUILTIN_PMINSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32735   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv8si3_mask, "__builtin_ia32_pmaxud256_mask", IX86_BUILTIN_PMAXUD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32736   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv8si3_mask, "__builtin_ia32_pminud256_mask", IX86_BUILTIN_PMINUD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32737   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4si3_mask, "__builtin_ia32_pmaxsd128_mask", IX86_BUILTIN_PMAXSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32738   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4si3_mask, "__builtin_ia32_pminsd128_mask", IX86_BUILTIN_PMINSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32739   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv4si3_mask, "__builtin_ia32_pmaxud128_mask", IX86_BUILTIN_PMAXUD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32740   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv4si3_mask, "__builtin_ia32_pminud128_mask", IX86_BUILTIN_PMINUD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32741   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4di3_mask, "__builtin_ia32_pmaxsq256_mask", IX86_BUILTIN_PMAXSQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32742   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4di3_mask, "__builtin_ia32_pminsq256_mask", IX86_BUILTIN_PMINSQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32743   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv4di3_mask, "__builtin_ia32_pmaxuq256_mask", IX86_BUILTIN_PMAXUQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32744   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv4di3_mask, "__builtin_ia32_pminuq256_mask", IX86_BUILTIN_PMINUQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32745   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv2di3_mask, "__builtin_ia32_pmaxsq128_mask", IX86_BUILTIN_PMAXSQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32746   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv2di3_mask, "__builtin_ia32_pminsq128_mask", IX86_BUILTIN_PMINSQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32747   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv2di3_mask, "__builtin_ia32_pmaxuq128_mask", IX86_BUILTIN_PMAXUQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32748   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv2di3_mask, "__builtin_ia32_pminuq128_mask", IX86_BUILTIN_PMINUQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32749   { 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 },
32750   { 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 },
32751   { 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 },
32752   { 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 },
32753   { 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 },
32754   { 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 },
32755   { 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 },
32756   { 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 },
32757   { 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 },
32758   { 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 },
32759   { 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 },
32760   { 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 },
32761   { 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 },
32762   { 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 },
32763   { 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 },
32764   { 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 },
32765   { 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 },
32766   { 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 },
32767   { 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 },
32768   { 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 },
32769   { 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 },
32770   { 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 },
32771   { 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 },
32772   { 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 },
32773   { 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 },
32774   { 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 },
32775   { 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 },
32776   { 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 },
32777   { 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 },
32778   { 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 },
32779   { 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 },
32780   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_unpcklps128_mask,  "__builtin_ia32_unpcklps128_mask", IX86_BUILTIN_UNPCKLPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32781   { 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 },
32782   { 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 },
32783   { 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 },
32784   { 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 },
32785   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtps2ph256_mask,  "__builtin_ia32_vcvtps2ph256_mask", IX86_BUILTIN_CVTPS2PH256_MASK, UNKNOWN, (int) V8HI_FTYPE_V8SF_INT_V8HI_QI },
32786   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtps2ph_mask,  "__builtin_ia32_vcvtps2ph_mask", IX86_BUILTIN_CVTPS2PH_MASK, UNKNOWN, (int) V8HI_FTYPE_V4SF_INT_V8HI_QI },
32787   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtph2ps_mask, "__builtin_ia32_vcvtph2ps_mask", IX86_BUILTIN_CVTPH2PS_MASK, UNKNOWN, (int) V4SF_FTYPE_V8HI_V4SF_QI },
32788   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtph2ps256_mask, "__builtin_ia32_vcvtph2ps256_mask", IX86_BUILTIN_CVTPH2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8HI_V8SF_QI },
32789   { 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 },
32790   { 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 },
32791   { 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 },
32792   { 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 },
32793   { 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 },
32794   { 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 },
32795   { 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 },
32796   { 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 },
32797   { 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 },
32798   { 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 },
32799   { 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 },
32800   { 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 },
32801   { 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 },
32802   { 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 },
32803   { 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 },
32804   { 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 },
32805   { 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 },
32806   { 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 },
32807   { 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 },
32808   { 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 },
32809   { 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 },
32810   { 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 },
32811   { 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 },
32812   { 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 },
32813   { 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 },
32814   { 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 },
32815   { 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 },
32816   { 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 },
32817   { 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 },
32818   { 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 },
32819   { 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 },
32820   { 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 },
32821   { 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 },
32822   { 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 },
32823   { 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 },
32824   { 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 },
32825   { 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 },
32826   { 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 },
32827   { 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 },
32828   { 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 },
32829   { 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 },
32830   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4di, "__builtin_ia32_blendmq_256_mask", IX86_BUILTIN_BLENDMQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32831   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8si, "__builtin_ia32_blendmd_256_mask", IX86_BUILTIN_BLENDMD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32832   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4df, "__builtin_ia32_blendmpd_256_mask", IX86_BUILTIN_BLENDMPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32833   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8sf, "__builtin_ia32_blendmps_256_mask", IX86_BUILTIN_BLENDMPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32834   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv2di, "__builtin_ia32_blendmq_128_mask", IX86_BUILTIN_BLENDMQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32835   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4si, "__builtin_ia32_blendmd_128_mask", IX86_BUILTIN_BLENDMD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32836   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv2df, "__builtin_ia32_blendmpd_128_mask", IX86_BUILTIN_BLENDMPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32837   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4sf, "__builtin_ia32_blendmps_128_mask", IX86_BUILTIN_BLENDMPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32838   { 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 },
32839   { 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 },
32840   { 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 },
32841   { 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 },
32842   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8si3_mask, "__builtin_ia32_pmulld256_mask", IX86_BUILTIN_PMULLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32843   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4si3_mask, "__builtin_ia32_pmulld128_mask", IX86_BUILTIN_PMULLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32844   { 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 },
32845   { 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 },
32846   { 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 },
32847   { 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 },
32848   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtpd2ps256_mask, "__builtin_ia32_cvtpd2ps256_mask", IX86_BUILTIN_CVTPD2PS256_MASK, UNKNOWN, (int) V4SF_FTYPE_V4DF_V4SF_QI },
32849   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtpd2ps_mask, "__builtin_ia32_cvtpd2ps_mask", IX86_BUILTIN_CVTPD2PS_MASK, UNKNOWN, (int) V4SF_FTYPE_V2DF_V4SF_QI },
32850   { 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 },
32851   { 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 },
32852   { 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 },
32853   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4di3_mask, "__builtin_ia32_cmpq256_mask", IX86_BUILTIN_CMPQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_INT_QI },
32854   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv8si3_mask, "__builtin_ia32_cmpd256_mask", IX86_BUILTIN_CMPD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_INT_QI },
32855   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv4di3_mask, "__builtin_ia32_ucmpq256_mask", IX86_BUILTIN_UCMPQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_INT_QI },
32856   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv8si3_mask, "__builtin_ia32_ucmpd256_mask", IX86_BUILTIN_UCMPD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_INT_QI },
32857   { 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 },
32858   { 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 },
32859   { 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 },
32860   { 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 },
32861   { 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 },
32862   { 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 },
32863   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv2di3_mask, "__builtin_ia32_cmpq128_mask", IX86_BUILTIN_CMPQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_INT_QI },
32864   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4si3_mask, "__builtin_ia32_cmpd128_mask", IX86_BUILTIN_CMPD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_INT_QI },
32865   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv2di3_mask, "__builtin_ia32_ucmpq128_mask", IX86_BUILTIN_UCMPQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_INT_QI },
32866   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv4si3_mask, "__builtin_ia32_ucmpd128_mask", IX86_BUILTIN_UCMPD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_INT_QI },
32867   { 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 },
32868   { 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 },
32869   { 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 },
32870   { 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 },
32871   { 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 },
32872   { 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 },
32873
32874   /* AVX512DQ.  */
32875   { 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 },
32876   { 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 },
32877   { 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 },
32878   { 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 },
32879   { 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 },
32880   { 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 },
32881   { 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 },
32882   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextractf32x8_mask, "__builtin_ia32_extractf32x8_mask", IX86_BUILTIN_EXTRACTF32X8, UNKNOWN, (int) V8SF_FTYPE_V16SF_INT_V8SF_QI },
32883   { 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 },
32884   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextracti32x8_mask, "__builtin_ia32_extracti32x8_mask", IX86_BUILTIN_EXTRACTI32X8, UNKNOWN, (int) V8SI_FTYPE_V16SI_INT_V8SI_QI },
32885   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducepv8df_mask, "__builtin_ia32_reducepd512_mask", IX86_BUILTIN_REDUCEPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
32886   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducepv16sf_mask, "__builtin_ia32_reduceps512_mask", IX86_BUILTIN_REDUCEPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI },
32887   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_mulv8di3_mask, "__builtin_ia32_pmullq512_mask", IX86_BUILTIN_PMULLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32888   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_xorv8df3_mask, "__builtin_ia32_xorpd512_mask", IX86_BUILTIN_XORPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32889   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_xorv16sf3_mask, "__builtin_ia32_xorps512_mask", IX86_BUILTIN_XORPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32890   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_iorv8df3_mask, "__builtin_ia32_orpd512_mask", IX86_BUILTIN_ORPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32891   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_iorv16sf3_mask, "__builtin_ia32_orps512_mask", IX86_BUILTIN_ORPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32892   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_andv8df3_mask, "__builtin_ia32_andpd512_mask", IX86_BUILTIN_ANDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32893   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_andv16sf3_mask, "__builtin_ia32_andps512_mask", IX86_BUILTIN_ANDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32894   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_andnotv8df3_mask, "__builtin_ia32_andnpd512_mask", IX86_BUILTIN_ANDNPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI},
32895   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_andnotv16sf3_mask, "__builtin_ia32_andnps512_mask", IX86_BUILTIN_ANDNPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32896   { 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 },
32897   { 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 },
32898   { 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 },
32899   { 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 },
32900   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_fpclassv8df_mask, "__builtin_ia32_fpclasspd512_mask", IX86_BUILTIN_FPCLASSPD512, UNKNOWN, (int) QI_FTYPE_V8DF_INT_QI },
32901   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_fpclassv16sf_mask, "__builtin_ia32_fpclassps512_mask", IX86_BUILTIN_FPCLASSPS512, UNKNOWN, (int) HI_FTYPE_V16SF_INT_HI },
32902   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtd2maskv16si, "__builtin_ia32_cvtd2mask512", IX86_BUILTIN_CVTD2MASK512, UNKNOWN, (int) HI_FTYPE_V16SI },
32903   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtq2maskv8di, "__builtin_ia32_cvtq2mask512", IX86_BUILTIN_CVTQ2MASK512, UNKNOWN, (int) QI_FTYPE_V8DI },
32904   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtmask2dv16si, "__builtin_ia32_cvtmask2d512", IX86_BUILTIN_CVTMASK2D512, UNKNOWN, (int) V16SI_FTYPE_HI },
32905   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtmask2qv8di, "__builtin_ia32_cvtmask2q512", IX86_BUILTIN_CVTMASK2Q512, UNKNOWN, (int) V8DI_FTYPE_QI },
32906
32907   /* AVX512BW.  */
32908   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_kunpcksi, "__builtin_ia32_kunpcksi", IX86_BUILTIN_KUNPCKWD, UNKNOWN, (int) SI_FTYPE_SI_SI },
32909   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_kunpckdi, "__builtin_ia32_kunpckdi", IX86_BUILTIN_KUNPCKDQ, UNKNOWN, (int) DI_FTYPE_DI_DI },
32910   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packusdw_mask, "__builtin_ia32_packusdw512_mask",  IX86_BUILTIN_PACKUSDW512, UNKNOWN, (int) V32HI_FTYPE_V16SI_V16SI_V32HI_SI },
32911   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashlv4ti3, "__builtin_ia32_pslldq512", IX86_BUILTIN_PSLLDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_CONVERT },
32912   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_lshrv4ti3, "__builtin_ia32_psrldq512", IX86_BUILTIN_PSRLDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_CONVERT },
32913   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packssdw_mask, "__builtin_ia32_packssdw512_mask",  IX86_BUILTIN_PACKSSDW512, UNKNOWN, (int) V32HI_FTYPE_V16SI_V16SI_V32HI_SI },
32914   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_palignrv4ti, "__builtin_ia32_palignr512", IX86_BUILTIN_PALIGNR512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_INT_CONVERT },
32915   { 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 },
32916   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_loaddquv32hi_mask, "__builtin_ia32_movdquhi512_mask", IX86_BUILTIN_MOVDQUHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32917   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_loaddquv64qi_mask, "__builtin_ia32_movdquqi512_mask", IX86_BUILTIN_MOVDQUQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32918   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_psadbw, "__builtin_ia32_psadbw512", IX86_BUILTIN_PSADBW512, UNKNOWN, (int) V8DI_FTYPE_V64QI_V64QI },
32919   { 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 },
32920   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dupv64qi_mask, "__builtin_ia32_pbroadcastb512_mask", IX86_BUILTIN_PBROADCASTB512, UNKNOWN, (int) V64QI_FTYPE_V16QI_V64QI_DI },
32921   { 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 },
32922   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dupv32hi_mask, "__builtin_ia32_pbroadcastw512_mask", IX86_BUILTIN_PBROADCASTW512, UNKNOWN, (int) V32HI_FTYPE_V8HI_V32HI_SI },
32923   { 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 },
32924   { 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 },
32925   { 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 },
32926   { 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 },
32927   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermt2varv32hi3_mask, "__builtin_ia32_vpermt2varhi512_mask", IX86_BUILTIN_VPERMT2VARHI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32928   { 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 },
32929   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermi2varv32hi3_mask, "__builtin_ia32_vpermi2varhi512_mask", IX86_BUILTIN_VPERMI2VARHI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32930   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_uavgv64qi3_mask, "__builtin_ia32_pavgb512_mask", IX86_BUILTIN_PAVGB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32931   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_uavgv32hi3_mask, "__builtin_ia32_pavgw512_mask", IX86_BUILTIN_PAVGW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32932   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_addv64qi3_mask, "__builtin_ia32_paddb512_mask", IX86_BUILTIN_PADDB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32933   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_subv64qi3_mask, "__builtin_ia32_psubb512_mask", IX86_BUILTIN_PSUBB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32934   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sssubv64qi3_mask, "__builtin_ia32_psubsb512_mask", IX86_BUILTIN_PSUBSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32935   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ssaddv64qi3_mask, "__builtin_ia32_paddsb512_mask", IX86_BUILTIN_PADDSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32936   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ussubv64qi3_mask, "__builtin_ia32_psubusb512_mask", IX86_BUILTIN_PSUBUSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32937   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_usaddv64qi3_mask, "__builtin_ia32_paddusb512_mask", IX86_BUILTIN_PADDUSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32938   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_subv32hi3_mask, "__builtin_ia32_psubw512_mask", IX86_BUILTIN_PSUBW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32939   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_addv32hi3_mask, "__builtin_ia32_paddw512_mask", IX86_BUILTIN_PADDW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32940   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sssubv32hi3_mask, "__builtin_ia32_psubsw512_mask", IX86_BUILTIN_PSUBSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32941   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ssaddv32hi3_mask, "__builtin_ia32_paddsw512_mask", IX86_BUILTIN_PADDSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32942   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ussubv32hi3_mask, "__builtin_ia32_psubusw512_mask", IX86_BUILTIN_PSUBUSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32943   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_usaddv32hi3_mask, "__builtin_ia32_paddusw512_mask", IX86_BUILTIN_PADDUSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32944   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umaxv32hi3_mask, "__builtin_ia32_pmaxuw512_mask", IX86_BUILTIN_PMAXUW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32945   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smaxv32hi3_mask, "__builtin_ia32_pmaxsw512_mask", IX86_BUILTIN_PMAXSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32946   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_uminv32hi3_mask, "__builtin_ia32_pminuw512_mask", IX86_BUILTIN_PMINUW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32947   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_sminv32hi3_mask, "__builtin_ia32_pminsw512_mask", IX86_BUILTIN_PMINSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32948   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umaxv64qi3_mask, "__builtin_ia32_pmaxub512_mask", IX86_BUILTIN_PMAXUB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32949   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smaxv64qi3_mask, "__builtin_ia32_pmaxsb512_mask", IX86_BUILTIN_PMAXSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32950   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_uminv64qi3_mask, "__builtin_ia32_pminub512_mask", IX86_BUILTIN_PMINUB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32951   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_sminv64qi3_mask, "__builtin_ia32_pminsb512_mask", IX86_BUILTIN_PMINSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32952   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovwb512_mask", IX86_BUILTIN_PMOVWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32953   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ss_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovswb512_mask", IX86_BUILTIN_PMOVSWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32954   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_us_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovuswb512_mask", IX86_BUILTIN_PMOVUSWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32955   { 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 },
32956   { 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 },
32957   { 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 },
32958   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_mulv32hi3_mask, "__builtin_ia32_pmullw512_mask", IX86_BUILTIN_PMULLW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32959   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashlv32hi3_mask, "__builtin_ia32_psllwi512_mask", IX86_BUILTIN_PSLLWI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32960   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashlv32hi3_mask, "__builtin_ia32_psllw512_mask", IX86_BUILTIN_PSLLW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32961   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packsswb_mask, "__builtin_ia32_packsswb512_mask",  IX86_BUILTIN_PACKSSWB512, UNKNOWN, (int) V64QI_FTYPE_V32HI_V32HI_V64QI_DI },
32962   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packuswb_mask, "__builtin_ia32_packuswb512_mask",  IX86_BUILTIN_PACKUSWB512, UNKNOWN, (int) V64QI_FTYPE_V32HI_V32HI_V64QI_DI },
32963   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashrvv32hi_mask, "__builtin_ia32_psrav32hi_mask", IX86_BUILTIN_PSRAVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32964   { 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 },
32965   { 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 },
32966   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_lshrvv32hi_mask, "__builtin_ia32_psrlv32hi_mask", IX86_BUILTIN_PSRLVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32967   { 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 },
32968   { 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 },
32969   { 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 },
32970   { 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 },
32971   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshufbv64qi3_mask, "__builtin_ia32_pshufb512_mask", IX86_BUILTIN_PSHUFB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32972   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshufhwv32hi_mask, "__builtin_ia32_pshufhw512_mask", IX86_BUILTIN_PSHUFHW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32973   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshuflwv32hi_mask, "__builtin_ia32_pshuflw512_mask", IX86_BUILTIN_PSHUFLW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32974   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashrv32hi3_mask, "__builtin_ia32_psrawi512_mask", IX86_BUILTIN_PSRAWI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32975   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashrv32hi3_mask, "__builtin_ia32_psraw512_mask", IX86_BUILTIN_PSRAW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32976   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_lshrv32hi3_mask, "__builtin_ia32_psrlwi512_mask", IX86_BUILTIN_PSRLWI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32977   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_lshrv32hi3_mask, "__builtin_ia32_psrlw512_mask", IX86_BUILTIN_PSRLW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32978   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtb2maskv64qi, "__builtin_ia32_cvtb2mask512", IX86_BUILTIN_CVTB2MASK512, UNKNOWN, (int) DI_FTYPE_V64QI },
32979   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtw2maskv32hi, "__builtin_ia32_cvtw2mask512", IX86_BUILTIN_CVTW2MASK512, UNKNOWN, (int) SI_FTYPE_V32HI },
32980   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtmask2bv64qi, "__builtin_ia32_cvtmask2b512", IX86_BUILTIN_CVTMASK2B512, UNKNOWN, (int) V64QI_FTYPE_DI },
32981   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtmask2wv32hi, "__builtin_ia32_cvtmask2w512", IX86_BUILTIN_CVTMASK2W512, UNKNOWN, (int) V32HI_FTYPE_SI },
32982   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_eqv64qi3_mask, "__builtin_ia32_pcmpeqb512_mask", IX86_BUILTIN_PCMPEQB512_MASK, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32983   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_eqv32hi3_mask, "__builtin_ia32_pcmpeqw512_mask", IX86_BUILTIN_PCMPEQW512_MASK, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32984   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_gtv64qi3_mask, "__builtin_ia32_pcmpgtb512_mask", IX86_BUILTIN_PCMPGTB512_MASK, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32985   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_gtv32hi3_mask, "__builtin_ia32_pcmpgtw512_mask", IX86_BUILTIN_PCMPGTW512_MASK, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32986   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testmv64qi3_mask, "__builtin_ia32_ptestmb512", IX86_BUILTIN_PTESTMB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32987   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testmv32hi3_mask, "__builtin_ia32_ptestmw512", IX86_BUILTIN_PTESTMW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32988   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testnmv64qi3_mask, "__builtin_ia32_ptestnmb512", IX86_BUILTIN_PTESTNMB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32989   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testnmv32hi3_mask, "__builtin_ia32_ptestnmw512", IX86_BUILTIN_PTESTNMW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32990   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashlvv32hi_mask, "__builtin_ia32_psllv32hi_mask", IX86_BUILTIN_PSLLVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32991   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_absv64qi2_mask, "__builtin_ia32_pabsb512_mask", IX86_BUILTIN_PABSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32992   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_absv32hi2_mask, "__builtin_ia32_pabsw512_mask", IX86_BUILTIN_PABSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32993   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_blendmv32hi, "__builtin_ia32_blendmw_512_mask", IX86_BUILTIN_BLENDMW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32994   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_blendmv64qi, "__builtin_ia32_blendmb_512_mask", IX86_BUILTIN_BLENDMB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32995   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cmpv64qi3_mask, "__builtin_ia32_cmpb512_mask", IX86_BUILTIN_CMPB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_INT_DI },
32996   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cmpv32hi3_mask, "__builtin_ia32_cmpw512_mask", IX86_BUILTIN_CMPW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_INT_SI },
32997   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ucmpv64qi3_mask, "__builtin_ia32_ucmpb512_mask", IX86_BUILTIN_UCMPB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_INT_DI },
32998   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ucmpv32hi3_mask, "__builtin_ia32_ucmpw512_mask", IX86_BUILTIN_UCMPW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_INT_SI },
32999
33000   /* AVX512IFMA */
33001   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52luqv8di_mask, "__builtin_ia32_vpmadd52luq512_mask", IX86_BUILTIN_VPMADD52LUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
33002   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52luqv8di_maskz, "__builtin_ia32_vpmadd52luq512_maskz", IX86_BUILTIN_VPMADD52LUQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
33003   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52huqv8di_mask, "__builtin_ia32_vpmadd52huq512_mask", IX86_BUILTIN_VPMADD52HUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
33004   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52huqv8di_maskz, "__builtin_ia32_vpmadd52huq512_maskz", IX86_BUILTIN_VPMADD52HUQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
33005   { 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 },
33006   { 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 },
33007   { 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 },
33008   { 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 },
33009   { 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 },
33010   { 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 },
33011   { 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 },
33012   { 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 },
33013
33014   /* AVX512VBMI */
33015   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_vpmultishiftqbv64qi_mask, "__builtin_ia32_vpmultishiftqb512_mask", IX86_BUILTIN_VPMULTISHIFTQB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
33016   { 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 },
33017   { 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 },
33018   { 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 },
33019   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermt2varv64qi3_mask, "__builtin_ia32_vpermt2varqi512_mask", IX86_BUILTIN_VPERMT2VARQI512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
33020   { 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 },
33021   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermi2varv64qi3_mask, "__builtin_ia32_vpermi2varqi512_mask", IX86_BUILTIN_VPERMI2VARQI512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
33022   { 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 },
33023   { 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 },
33024   { 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 },
33025   { 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 },
33026   { 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 },
33027   { 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 },
33028   { 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 },
33029   { 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 },
33030 };
33031
33032 /* Builtins with rounding support.  */
33033 static const struct builtin_description bdesc_round_args[] =
33034 {
33035   /* AVX512F */
33036   { 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 },
33037   { 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 },
33038   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmaddv2df3_round, "__builtin_ia32_addsd_round", IX86_BUILTIN_ADDSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33039   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmaddv4sf3_round, "__builtin_ia32_addss_round", IX86_BUILTIN_ADDSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33040   { 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 },
33041   { 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 },
33042   { 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 },
33043   { 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 },
33044   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_comi_round, "__builtin_ia32_vcomisd", IX86_BUILTIN_COMIDF, UNKNOWN, (int) INT_FTYPE_V2DF_V2DF_INT_INT },
33045   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_comi_round, "__builtin_ia32_vcomiss", IX86_BUILTIN_COMISF, UNKNOWN, (int) INT_FTYPE_V4SF_V4SF_INT_INT },
33046   { OPTION_MASK_ISA_AVX512F, CODE_FOR_floatv16siv16sf2_mask_round, "__builtin_ia32_cvtdq2ps512_mask", IX86_BUILTIN_CVTDQ2PS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_HI_INT },
33047   { 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 },
33048   { 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 },
33049   { 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 },
33050   { 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 },
33051   { 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 },
33052   { 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 },
33053   { 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 },
33054   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtsd2ss_round, "__builtin_ia32_cvtsd2ss_round", IX86_BUILTIN_CVTSD2SS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF_INT },
33055   { 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 },
33056   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvtsi2ss_round, "__builtin_ia32_cvtsi2ss32", IX86_BUILTIN_CVTSI2SS32, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_INT },
33057   { 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 },
33058   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtss2sd_round, "__builtin_ia32_cvtss2sd_round", IX86_BUILTIN_CVTSS2SD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF_INT },
33059   { 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 },
33060   { 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 },
33061   { 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 },
33062   { 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 },
33063   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufloatv16siv16sf2_mask_round, "__builtin_ia32_cvtudq2ps512_mask", IX86_BUILTIN_CVTUDQ2PS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_HI_INT },
33064   { 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 },
33065   { OPTION_MASK_ISA_AVX512F, CODE_FOR_cvtusi2ss32_round, "__builtin_ia32_cvtusi2ss32", IX86_BUILTIN_CVTUSI2SS32, UNKNOWN, (int) V4SF_FTYPE_V4SF_UINT_INT },
33066   { 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 },
33067   { 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 },
33068   { 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 },
33069   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmdivv2df3_round, "__builtin_ia32_divsd_round", IX86_BUILTIN_DIVSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33070   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmdivv4sf3_round, "__builtin_ia32_divss_round", IX86_BUILTIN_DIVSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33071   { 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 },
33072   { 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 },
33073   { 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 },
33074   { 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 },
33075   { 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 },
33076   { 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 },
33077   { 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 },
33078   { 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 },
33079   { 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 },
33080   { 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 },
33081   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sgetexpv2df_round, "__builtin_ia32_getexpsd128_round", IX86_BUILTIN_GETEXPSD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33082   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sgetexpv4sf_round, "__builtin_ia32_getexpss128_round", IX86_BUILTIN_GETEXPSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33083   { 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 },
33084   { 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 },
33085   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vgetmantv2df_round, "__builtin_ia32_getmantsd_round", IX86_BUILTIN_GETMANTSD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
33086   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vgetmantv4sf_round, "__builtin_ia32_getmantss_round", IX86_BUILTIN_GETMANTSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
33087   { 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 },
33088   { 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 },
33089   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsmaxv2df3_round, "__builtin_ia32_maxsd_round", IX86_BUILTIN_MAXSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33090   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsmaxv4sf3_round, "__builtin_ia32_maxss_round", IX86_BUILTIN_MAXSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33091   { 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 },
33092   { 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 },
33093   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsminv2df3_round, "__builtin_ia32_minsd_round", IX86_BUILTIN_MINSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33094   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsminv4sf3_round, "__builtin_ia32_minss_round", IX86_BUILTIN_MINSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33095   { 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 },
33096   { 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 },
33097   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmmulv2df3_round, "__builtin_ia32_mulsd_round", IX86_BUILTIN_MULSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33098   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmmulv4sf3_round, "__builtin_ia32_mulss_round", IX86_BUILTIN_MULSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33099   { 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 },
33100   { 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 },
33101   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev2df_round, "__builtin_ia32_rndscalesd_round", IX86_BUILTIN_RNDSCALESD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
33102   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev4sf_round, "__builtin_ia32_rndscaless_round", IX86_BUILTIN_RNDSCALESS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
33103   { 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 },
33104   { 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 },
33105   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmscalefv2df_round, "__builtin_ia32_scalefsd_round", IX86_BUILTIN_SCALEFSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33106   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmscalefv4sf_round, "__builtin_ia32_scalefss_round", IX86_BUILTIN_SCALEFSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33107   { 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 },
33108   { 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 },
33109   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsqrtv2df2_round, "__builtin_ia32_sqrtsd_round", IX86_BUILTIN_SQRTSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33110   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsqrtv4sf2_round, "__builtin_ia32_sqrtss_round", IX86_BUILTIN_SQRTSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33111   { 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 },
33112   { 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 },
33113   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsubv2df3_round, "__builtin_ia32_subsd_round", IX86_BUILTIN_SUBSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33114   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsubv4sf3_round, "__builtin_ia32_subss_round", IX86_BUILTIN_SUBSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33115   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtsd2si_round, "__builtin_ia32_vcvtsd2si32", IX86_BUILTIN_VCVTSD2SI32, UNKNOWN, (int) INT_FTYPE_V2DF_INT },
33116   { 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 },
33117   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtsd2usi_round, "__builtin_ia32_vcvtsd2usi32", IX86_BUILTIN_VCVTSD2USI32, UNKNOWN, (int) UINT_FTYPE_V2DF_INT },
33118   { 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 },
33119   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvtss2si_round, "__builtin_ia32_vcvtss2si32", IX86_BUILTIN_VCVTSS2SI32, UNKNOWN, (int) INT_FTYPE_V4SF_INT },
33120   { 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 },
33121   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtss2usi_round, "__builtin_ia32_vcvtss2usi32", IX86_BUILTIN_VCVTSS2USI32, UNKNOWN, (int) UINT_FTYPE_V4SF_INT },
33122   { 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 },
33123   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvttsd2si_round, "__builtin_ia32_vcvttsd2si32", IX86_BUILTIN_VCVTTSD2SI32, UNKNOWN, (int) INT_FTYPE_V2DF_INT },
33124   { 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 },
33125   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvttsd2usi_round, "__builtin_ia32_vcvttsd2usi32", IX86_BUILTIN_VCVTTSD2USI32, UNKNOWN, (int) UINT_FTYPE_V2DF_INT },
33126   { 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 },
33127   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvttss2si_round, "__builtin_ia32_vcvttss2si32", IX86_BUILTIN_VCVTTSS2SI32, UNKNOWN, (int) INT_FTYPE_V4SF_INT },
33128   { 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 },
33129   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvttss2usi_round, "__builtin_ia32_vcvttss2usi32", IX86_BUILTIN_VCVTTSS2USI32, UNKNOWN, (int) UINT_FTYPE_V4SF_INT },
33130   { 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 },
33131   { 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 },
33132   { 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 },
33133   { 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 },
33134   { 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 },
33135   { 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 },
33136   { 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 },
33137   { 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 },
33138   { 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 },
33139   { 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 },
33140   { 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 },
33141   { 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 },
33142   { 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 },
33143   { 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 },
33144   { 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 },
33145   { 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 },
33146   { 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 },
33147   { 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 },
33148   { 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 },
33149   { 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 },
33150   { 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 },
33151   { 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 },
33152   { 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 },
33153   { 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 },
33154   { 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 },
33155
33156   /* AVX512ER */
33157   { 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 },
33158   { 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 },
33159   { 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 },
33160   { 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 },
33161   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrcp28v2df_round, "__builtin_ia32_rcp28sd_round", IX86_BUILTIN_RCP28SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33162   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrcp28v4sf_round, "__builtin_ia32_rcp28ss_round", IX86_BUILTIN_RCP28SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33163   { 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 },
33164   { 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 },
33165   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrsqrt28v2df_round, "__builtin_ia32_rsqrt28sd_round", IX86_BUILTIN_RSQRT28SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33166   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrsqrt28v4sf_round, "__builtin_ia32_rsqrt28ss_round", IX86_BUILTIN_RSQRT28SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33167
33168   /* AVX512DQ.  */
33169   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangesv2df_round, "__builtin_ia32_rangesd128_round", IX86_BUILTIN_RANGESD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
33170   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangesv4sf_round, "__builtin_ia32_rangess128_round", IX86_BUILTIN_RANGESS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
33171   { 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 },
33172   { 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 },
33173   { 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 },
33174   { 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 },
33175   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_floatv8div8sf2_mask_round, "__builtin_ia32_cvtqq2ps512_mask", IX86_BUILTIN_CVTQQ2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DI_V8SF_QI_INT },
33176   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufloatv8div8sf2_mask_round, "__builtin_ia32_cvtuqq2ps512_mask", IX86_BUILTIN_CVTUQQ2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DI_V8SF_QI_INT },
33177   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_floatv8div8df2_mask_round, "__builtin_ia32_cvtqq2pd512_mask", IX86_BUILTIN_CVTQQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_QI_INT },
33178   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufloatv8div8df2_mask_round, "__builtin_ia32_cvtuqq2pd512_mask", IX86_BUILTIN_CVTUQQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_QI_INT },
33179   { 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 },
33180   { 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 },
33181   { 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 },
33182   { 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 },
33183   { 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 },
33184   { 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 },
33185 };
33186
33187 /* Bultins for MPX.  */
33188 static const struct builtin_description bdesc_mpx[] =
33189 {
33190   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndstx", IX86_BUILTIN_BNDSTX, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND_PCVOID },
33191   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndcl", IX86_BUILTIN_BNDCL, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND },
33192   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndcu", IX86_BUILTIN_BNDCU, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND },
33193 };
33194
33195 /* Const builtins for MPX.  */
33196 static const struct builtin_description bdesc_mpx_const[] =
33197 {
33198   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndmk", IX86_BUILTIN_BNDMK, UNKNOWN, (int) BND_FTYPE_PCVOID_ULONG },
33199   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndldx", IX86_BUILTIN_BNDLDX, UNKNOWN, (int) BND_FTYPE_PCVOID_PCVOID },
33200   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_narrow_bounds", IX86_BUILTIN_BNDNARROW, UNKNOWN, (int) PVOID_FTYPE_PCVOID_BND_ULONG },
33201   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndint", IX86_BUILTIN_BNDINT, UNKNOWN, (int) BND_FTYPE_BND_BND },
33202   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_sizeof", IX86_BUILTIN_SIZEOF, UNKNOWN, (int) ULONG_FTYPE_VOID },
33203   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndlower", IX86_BUILTIN_BNDLOWER, UNKNOWN, (int) PVOID_FTYPE_BND },
33204   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndupper", IX86_BUILTIN_BNDUPPER, UNKNOWN, (int) PVOID_FTYPE_BND },
33205   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndret", IX86_BUILTIN_BNDRET, UNKNOWN, (int) BND_FTYPE_PCVOID },
33206 };
33207
33208 /* FMA4 and XOP.  */
33209 #define MULTI_ARG_4_DF2_DI_I    V2DF_FTYPE_V2DF_V2DF_V2DI_INT
33210 #define MULTI_ARG_4_DF2_DI_I1   V4DF_FTYPE_V4DF_V4DF_V4DI_INT
33211 #define MULTI_ARG_4_SF2_SI_I    V4SF_FTYPE_V4SF_V4SF_V4SI_INT
33212 #define MULTI_ARG_4_SF2_SI_I1   V8SF_FTYPE_V8SF_V8SF_V8SI_INT
33213 #define MULTI_ARG_3_SF          V4SF_FTYPE_V4SF_V4SF_V4SF
33214 #define MULTI_ARG_3_DF          V2DF_FTYPE_V2DF_V2DF_V2DF
33215 #define MULTI_ARG_3_SF2         V8SF_FTYPE_V8SF_V8SF_V8SF
33216 #define MULTI_ARG_3_DF2         V4DF_FTYPE_V4DF_V4DF_V4DF
33217 #define MULTI_ARG_3_DI          V2DI_FTYPE_V2DI_V2DI_V2DI
33218 #define MULTI_ARG_3_SI          V4SI_FTYPE_V4SI_V4SI_V4SI
33219 #define MULTI_ARG_3_SI_DI       V4SI_FTYPE_V4SI_V4SI_V2DI
33220 #define MULTI_ARG_3_HI          V8HI_FTYPE_V8HI_V8HI_V8HI
33221 #define MULTI_ARG_3_HI_SI       V8HI_FTYPE_V8HI_V8HI_V4SI
33222 #define MULTI_ARG_3_QI          V16QI_FTYPE_V16QI_V16QI_V16QI
33223 #define MULTI_ARG_3_DI2         V4DI_FTYPE_V4DI_V4DI_V4DI
33224 #define MULTI_ARG_3_SI2         V8SI_FTYPE_V8SI_V8SI_V8SI
33225 #define MULTI_ARG_3_HI2         V16HI_FTYPE_V16HI_V16HI_V16HI
33226 #define MULTI_ARG_3_QI2         V32QI_FTYPE_V32QI_V32QI_V32QI
33227 #define MULTI_ARG_2_SF          V4SF_FTYPE_V4SF_V4SF
33228 #define MULTI_ARG_2_DF          V2DF_FTYPE_V2DF_V2DF
33229 #define MULTI_ARG_2_DI          V2DI_FTYPE_V2DI_V2DI
33230 #define MULTI_ARG_2_SI          V4SI_FTYPE_V4SI_V4SI
33231 #define MULTI_ARG_2_HI          V8HI_FTYPE_V8HI_V8HI
33232 #define MULTI_ARG_2_QI          V16QI_FTYPE_V16QI_V16QI
33233 #define MULTI_ARG_2_DI_IMM      V2DI_FTYPE_V2DI_SI
33234 #define MULTI_ARG_2_SI_IMM      V4SI_FTYPE_V4SI_SI
33235 #define MULTI_ARG_2_HI_IMM      V8HI_FTYPE_V8HI_SI
33236 #define MULTI_ARG_2_QI_IMM      V16QI_FTYPE_V16QI_SI
33237 #define MULTI_ARG_2_DI_CMP      V2DI_FTYPE_V2DI_V2DI_CMP
33238 #define MULTI_ARG_2_SI_CMP      V4SI_FTYPE_V4SI_V4SI_CMP
33239 #define MULTI_ARG_2_HI_CMP      V8HI_FTYPE_V8HI_V8HI_CMP
33240 #define MULTI_ARG_2_QI_CMP      V16QI_FTYPE_V16QI_V16QI_CMP
33241 #define MULTI_ARG_2_SF_TF       V4SF_FTYPE_V4SF_V4SF_TF
33242 #define MULTI_ARG_2_DF_TF       V2DF_FTYPE_V2DF_V2DF_TF
33243 #define MULTI_ARG_2_DI_TF       V2DI_FTYPE_V2DI_V2DI_TF
33244 #define MULTI_ARG_2_SI_TF       V4SI_FTYPE_V4SI_V4SI_TF
33245 #define MULTI_ARG_2_HI_TF       V8HI_FTYPE_V8HI_V8HI_TF
33246 #define MULTI_ARG_2_QI_TF       V16QI_FTYPE_V16QI_V16QI_TF
33247 #define MULTI_ARG_1_SF          V4SF_FTYPE_V4SF
33248 #define MULTI_ARG_1_DF          V2DF_FTYPE_V2DF
33249 #define MULTI_ARG_1_SF2         V8SF_FTYPE_V8SF
33250 #define MULTI_ARG_1_DF2         V4DF_FTYPE_V4DF
33251 #define MULTI_ARG_1_DI          V2DI_FTYPE_V2DI
33252 #define MULTI_ARG_1_SI          V4SI_FTYPE_V4SI
33253 #define MULTI_ARG_1_HI          V8HI_FTYPE_V8HI
33254 #define MULTI_ARG_1_QI          V16QI_FTYPE_V16QI
33255 #define MULTI_ARG_1_SI_DI       V2DI_FTYPE_V4SI
33256 #define MULTI_ARG_1_HI_DI       V2DI_FTYPE_V8HI
33257 #define MULTI_ARG_1_HI_SI       V4SI_FTYPE_V8HI
33258 #define MULTI_ARG_1_QI_DI       V2DI_FTYPE_V16QI
33259 #define MULTI_ARG_1_QI_SI       V4SI_FTYPE_V16QI
33260 #define MULTI_ARG_1_QI_HI       V8HI_FTYPE_V16QI
33261
33262 static const struct builtin_description bdesc_multi_arg[] =
33263 {
33264   { OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_vmfmadd_v4sf,
33265     "__builtin_ia32_vfmaddss", IX86_BUILTIN_VFMADDSS,
33266     UNKNOWN, (int)MULTI_ARG_3_SF },
33267   { OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_vmfmadd_v2df,
33268     "__builtin_ia32_vfmaddsd", IX86_BUILTIN_VFMADDSD,
33269     UNKNOWN, (int)MULTI_ARG_3_DF },
33270
33271   { OPTION_MASK_ISA_FMA, CODE_FOR_fmai_vmfmadd_v4sf,
33272     "__builtin_ia32_vfmaddss3", IX86_BUILTIN_VFMADDSS3,
33273     UNKNOWN, (int)MULTI_ARG_3_SF },
33274   { OPTION_MASK_ISA_FMA, CODE_FOR_fmai_vmfmadd_v2df,
33275     "__builtin_ia32_vfmaddsd3", IX86_BUILTIN_VFMADDSD3,
33276     UNKNOWN, (int)MULTI_ARG_3_DF },
33277
33278   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v4sf,
33279     "__builtin_ia32_vfmaddps", IX86_BUILTIN_VFMADDPS,
33280     UNKNOWN, (int)MULTI_ARG_3_SF },
33281   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v2df,
33282     "__builtin_ia32_vfmaddpd", IX86_BUILTIN_VFMADDPD,
33283     UNKNOWN, (int)MULTI_ARG_3_DF },
33284   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v8sf,
33285     "__builtin_ia32_vfmaddps256", IX86_BUILTIN_VFMADDPS256,
33286     UNKNOWN, (int)MULTI_ARG_3_SF2 },
33287   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v4df,
33288     "__builtin_ia32_vfmaddpd256", IX86_BUILTIN_VFMADDPD256,
33289     UNKNOWN, (int)MULTI_ARG_3_DF2 },
33290
33291   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v4sf,
33292     "__builtin_ia32_vfmaddsubps", IX86_BUILTIN_VFMADDSUBPS,
33293     UNKNOWN, (int)MULTI_ARG_3_SF },
33294   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v2df,
33295     "__builtin_ia32_vfmaddsubpd", IX86_BUILTIN_VFMADDSUBPD,
33296     UNKNOWN, (int)MULTI_ARG_3_DF },
33297   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v8sf,
33298     "__builtin_ia32_vfmaddsubps256", IX86_BUILTIN_VFMADDSUBPS256,
33299     UNKNOWN, (int)MULTI_ARG_3_SF2 },
33300   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v4df,
33301     "__builtin_ia32_vfmaddsubpd256", IX86_BUILTIN_VFMADDSUBPD256,
33302     UNKNOWN, (int)MULTI_ARG_3_DF2 },
33303
33304   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2di,        "__builtin_ia32_vpcmov",      IX86_BUILTIN_VPCMOV,      UNKNOWN,      (int)MULTI_ARG_3_DI },
33305   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2di,        "__builtin_ia32_vpcmov_v2di", IX86_BUILTIN_VPCMOV_V2DI, UNKNOWN,      (int)MULTI_ARG_3_DI },
33306   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4si,        "__builtin_ia32_vpcmov_v4si", IX86_BUILTIN_VPCMOV_V4SI, UNKNOWN,      (int)MULTI_ARG_3_SI },
33307   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8hi,        "__builtin_ia32_vpcmov_v8hi", IX86_BUILTIN_VPCMOV_V8HI, UNKNOWN,      (int)MULTI_ARG_3_HI },
33308   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v16qi,       "__builtin_ia32_vpcmov_v16qi",IX86_BUILTIN_VPCMOV_V16QI,UNKNOWN,      (int)MULTI_ARG_3_QI },
33309   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2df,        "__builtin_ia32_vpcmov_v2df", IX86_BUILTIN_VPCMOV_V2DF, UNKNOWN,      (int)MULTI_ARG_3_DF },
33310   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4sf,        "__builtin_ia32_vpcmov_v4sf", IX86_BUILTIN_VPCMOV_V4SF, UNKNOWN,      (int)MULTI_ARG_3_SF },
33311
33312   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4di256,        "__builtin_ia32_vpcmov256",       IX86_BUILTIN_VPCMOV256,       UNKNOWN,      (int)MULTI_ARG_3_DI2 },
33313   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4di256,        "__builtin_ia32_vpcmov_v4di256",  IX86_BUILTIN_VPCMOV_V4DI256,  UNKNOWN,      (int)MULTI_ARG_3_DI2 },
33314   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8si256,        "__builtin_ia32_vpcmov_v8si256",  IX86_BUILTIN_VPCMOV_V8SI256,  UNKNOWN,      (int)MULTI_ARG_3_SI2 },
33315   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v16hi256,       "__builtin_ia32_vpcmov_v16hi256", IX86_BUILTIN_VPCMOV_V16HI256, UNKNOWN,      (int)MULTI_ARG_3_HI2 },
33316   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v32qi256,       "__builtin_ia32_vpcmov_v32qi256", IX86_BUILTIN_VPCMOV_V32QI256, UNKNOWN,      (int)MULTI_ARG_3_QI2 },
33317   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4df256,        "__builtin_ia32_vpcmov_v4df256",  IX86_BUILTIN_VPCMOV_V4DF256,  UNKNOWN,      (int)MULTI_ARG_3_DF2 },
33318   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8sf256,        "__builtin_ia32_vpcmov_v8sf256",  IX86_BUILTIN_VPCMOV_V8SF256,  UNKNOWN,      (int)MULTI_ARG_3_SF2 },
33319
33320   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pperm,             "__builtin_ia32_vpperm",      IX86_BUILTIN_VPPERM,      UNKNOWN,      (int)MULTI_ARG_3_QI },
33321
33322   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssww,          "__builtin_ia32_vpmacssww",   IX86_BUILTIN_VPMACSSWW,   UNKNOWN,      (int)MULTI_ARG_3_HI },
33323   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsww,           "__builtin_ia32_vpmacsww",    IX86_BUILTIN_VPMACSWW,    UNKNOWN,      (int)MULTI_ARG_3_HI },
33324   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsswd,          "__builtin_ia32_vpmacsswd",   IX86_BUILTIN_VPMACSSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33325   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacswd,           "__builtin_ia32_vpmacswd",    IX86_BUILTIN_VPMACSWD,    UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33326   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdd,          "__builtin_ia32_vpmacssdd",   IX86_BUILTIN_VPMACSSDD,   UNKNOWN,      (int)MULTI_ARG_3_SI },
33327   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdd,           "__builtin_ia32_vpmacsdd",    IX86_BUILTIN_VPMACSDD,    UNKNOWN,      (int)MULTI_ARG_3_SI },
33328   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdql,         "__builtin_ia32_vpmacssdql",  IX86_BUILTIN_VPMACSSDQL,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33329   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdqh,         "__builtin_ia32_vpmacssdqh",  IX86_BUILTIN_VPMACSSDQH,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33330   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdql,          "__builtin_ia32_vpmacsdql",   IX86_BUILTIN_VPMACSDQL,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33331   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdqh,          "__builtin_ia32_vpmacsdqh",   IX86_BUILTIN_VPMACSDQH,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33332   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmadcsswd,         "__builtin_ia32_vpmadcsswd",  IX86_BUILTIN_VPMADCSSWD,  UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33333   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmadcswd,          "__builtin_ia32_vpmadcswd",   IX86_BUILTIN_VPMADCSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33334
33335   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv2di3,        "__builtin_ia32_vprotq",      IX86_BUILTIN_VPROTQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33336   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv4si3,        "__builtin_ia32_vprotd",      IX86_BUILTIN_VPROTD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33337   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv8hi3,        "__builtin_ia32_vprotw",      IX86_BUILTIN_VPROTW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33338   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv16qi3,       "__builtin_ia32_vprotb",      IX86_BUILTIN_VPROTB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33339   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv2di3,         "__builtin_ia32_vprotqi",     IX86_BUILTIN_VPROTQ_IMM,  UNKNOWN,      (int)MULTI_ARG_2_DI_IMM },
33340   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv4si3,         "__builtin_ia32_vprotdi",     IX86_BUILTIN_VPROTD_IMM,  UNKNOWN,      (int)MULTI_ARG_2_SI_IMM },
33341   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv8hi3,         "__builtin_ia32_vprotwi",     IX86_BUILTIN_VPROTW_IMM,  UNKNOWN,      (int)MULTI_ARG_2_HI_IMM },
33342   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv16qi3,        "__builtin_ia32_vprotbi",     IX86_BUILTIN_VPROTB_IMM,  UNKNOWN,      (int)MULTI_ARG_2_QI_IMM },
33343   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav2di3,         "__builtin_ia32_vpshaq",      IX86_BUILTIN_VPSHAQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33344   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav4si3,         "__builtin_ia32_vpshad",      IX86_BUILTIN_VPSHAD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33345   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav8hi3,         "__builtin_ia32_vpshaw",      IX86_BUILTIN_VPSHAW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33346   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav16qi3,        "__builtin_ia32_vpshab",      IX86_BUILTIN_VPSHAB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33347   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv2di3,         "__builtin_ia32_vpshlq",      IX86_BUILTIN_VPSHLQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33348   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv4si3,         "__builtin_ia32_vpshld",      IX86_BUILTIN_VPSHLD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33349   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv8hi3,         "__builtin_ia32_vpshlw",      IX86_BUILTIN_VPSHLW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33350   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv16qi3,        "__builtin_ia32_vpshlb",      IX86_BUILTIN_VPSHLB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33351
33352   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vmfrczv4sf2,       "__builtin_ia32_vfrczss",     IX86_BUILTIN_VFRCZSS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
33353   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vmfrczv2df2,       "__builtin_ia32_vfrczsd",     IX86_BUILTIN_VFRCZSD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
33354   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv4sf2,         "__builtin_ia32_vfrczps",     IX86_BUILTIN_VFRCZPS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
33355   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv2df2,         "__builtin_ia32_vfrczpd",     IX86_BUILTIN_VFRCZPD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
33356   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv8sf2,         "__builtin_ia32_vfrczps256",  IX86_BUILTIN_VFRCZPS256,  UNKNOWN,      (int)MULTI_ARG_1_SF2 },
33357   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv4df2,         "__builtin_ia32_vfrczpd256",  IX86_BUILTIN_VFRCZPD256,  UNKNOWN,      (int)MULTI_ARG_1_DF2 },
33358
33359   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbw,           "__builtin_ia32_vphaddbw",    IX86_BUILTIN_VPHADDBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33360   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbd,           "__builtin_ia32_vphaddbd",    IX86_BUILTIN_VPHADDBD,    UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
33361   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbq,           "__builtin_ia32_vphaddbq",    IX86_BUILTIN_VPHADDBQ,    UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
33362   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddwd,           "__builtin_ia32_vphaddwd",    IX86_BUILTIN_VPHADDWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33363   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddwq,           "__builtin_ia32_vphaddwq",    IX86_BUILTIN_VPHADDWQ,    UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
33364   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadddq,           "__builtin_ia32_vphadddq",    IX86_BUILTIN_VPHADDDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33365   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubw,          "__builtin_ia32_vphaddubw",   IX86_BUILTIN_VPHADDUBW,   UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33366   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubd,          "__builtin_ia32_vphaddubd",   IX86_BUILTIN_VPHADDUBD,   UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
33367   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubq,          "__builtin_ia32_vphaddubq",   IX86_BUILTIN_VPHADDUBQ,   UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
33368   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadduwd,          "__builtin_ia32_vphadduwd",   IX86_BUILTIN_VPHADDUWD,   UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33369   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadduwq,          "__builtin_ia32_vphadduwq",   IX86_BUILTIN_VPHADDUWQ,   UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
33370   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddudq,          "__builtin_ia32_vphaddudq",   IX86_BUILTIN_VPHADDUDQ,   UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33371   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubbw,           "__builtin_ia32_vphsubbw",    IX86_BUILTIN_VPHSUBBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33372   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubwd,           "__builtin_ia32_vphsubwd",    IX86_BUILTIN_VPHSUBWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33373   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubdq,           "__builtin_ia32_vphsubdq",    IX86_BUILTIN_VPHSUBDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33374
33375   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomeqb",    IX86_BUILTIN_VPCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
33376   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomneb",    IX86_BUILTIN_VPCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
33377   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomneqb",   IX86_BUILTIN_VPCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
33378   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomltb",    IX86_BUILTIN_VPCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
33379   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomleb",    IX86_BUILTIN_VPCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
33380   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomgtb",    IX86_BUILTIN_VPCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
33381   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomgeb",    IX86_BUILTIN_VPCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
33382
33383   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomeqw",    IX86_BUILTIN_VPCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
33384   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomnew",    IX86_BUILTIN_VPCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
33385   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomneqw",   IX86_BUILTIN_VPCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
33386   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomltw",    IX86_BUILTIN_VPCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
33387   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomlew",    IX86_BUILTIN_VPCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
33388   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomgtw",    IX86_BUILTIN_VPCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
33389   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomgew",    IX86_BUILTIN_VPCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
33390
33391   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomeqd",    IX86_BUILTIN_VPCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
33392   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomned",    IX86_BUILTIN_VPCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
33393   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomneqd",   IX86_BUILTIN_VPCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
33394   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomltd",    IX86_BUILTIN_VPCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
33395   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomled",    IX86_BUILTIN_VPCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
33396   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomgtd",    IX86_BUILTIN_VPCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
33397   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomged",    IX86_BUILTIN_VPCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
33398
33399   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomeqq",    IX86_BUILTIN_VPCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
33400   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomneq",    IX86_BUILTIN_VPCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
33401   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomneqq",   IX86_BUILTIN_VPCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
33402   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomltq",    IX86_BUILTIN_VPCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
33403   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomleq",    IX86_BUILTIN_VPCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
33404   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomgtq",    IX86_BUILTIN_VPCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
33405   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomgeq",    IX86_BUILTIN_VPCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
33406
33407   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomequb",   IX86_BUILTIN_VPCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
33408   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomneub",   IX86_BUILTIN_VPCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
33409   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomnequb",  IX86_BUILTIN_VPCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
33410   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomltub",   IX86_BUILTIN_VPCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
33411   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomleub",   IX86_BUILTIN_VPCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
33412   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomgtub",   IX86_BUILTIN_VPCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
33413   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomgeub",   IX86_BUILTIN_VPCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
33414
33415   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomequw",   IX86_BUILTIN_VPCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
33416   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomneuw",   IX86_BUILTIN_VPCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
33417   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomnequw",  IX86_BUILTIN_VPCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
33418   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomltuw",   IX86_BUILTIN_VPCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
33419   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomleuw",   IX86_BUILTIN_VPCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
33420   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomgtuw",   IX86_BUILTIN_VPCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
33421   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomgeuw",   IX86_BUILTIN_VPCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
33422
33423   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomequd",   IX86_BUILTIN_VPCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
33424   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomneud",   IX86_BUILTIN_VPCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
33425   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomnequd",  IX86_BUILTIN_VPCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
33426   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomltud",   IX86_BUILTIN_VPCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
33427   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomleud",   IX86_BUILTIN_VPCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
33428   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomgtud",   IX86_BUILTIN_VPCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
33429   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomgeud",   IX86_BUILTIN_VPCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
33430
33431   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomequq",   IX86_BUILTIN_VPCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
33432   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomneuq",   IX86_BUILTIN_VPCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
33433   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomnequq",  IX86_BUILTIN_VPCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
33434   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomltuq",   IX86_BUILTIN_VPCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
33435   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomleuq",   IX86_BUILTIN_VPCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
33436   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomgtuq",   IX86_BUILTIN_VPCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
33437   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomgeuq",   IX86_BUILTIN_VPCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
33438
33439   { 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 },
33440   { 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 },
33441   { 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 },
33442   { 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 },
33443   { 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 },
33444   { 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 },
33445   { 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 },
33446   { 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 },
33447
33448   { 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 },
33449   { 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 },
33450   { 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 },
33451   { 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 },
33452   { 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 },
33453   { 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 },
33454   { 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 },
33455   { 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 },
33456
33457   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v2df3,     "__builtin_ia32_vpermil2pd",  IX86_BUILTIN_VPERMIL2PD, UNKNOWN, (int)MULTI_ARG_4_DF2_DI_I },
33458   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v4sf3,     "__builtin_ia32_vpermil2ps",  IX86_BUILTIN_VPERMIL2PS, UNKNOWN, (int)MULTI_ARG_4_SF2_SI_I },
33459   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v4df3,     "__builtin_ia32_vpermil2pd256", IX86_BUILTIN_VPERMIL2PD256, UNKNOWN, (int)MULTI_ARG_4_DF2_DI_I1 },
33460   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v8sf3,     "__builtin_ia32_vpermil2ps256", IX86_BUILTIN_VPERMIL2PS256, UNKNOWN, (int)MULTI_ARG_4_SF2_SI_I1 },
33461
33462 };
33463 \f
33464 /* TM vector builtins.  */
33465
33466 /* Reuse the existing x86-specific `struct builtin_description' cause
33467    we're lazy.  Add casts to make them fit.  */
33468 static const struct builtin_description bdesc_tm[] =
33469 {
33470   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WM64", (enum ix86_builtins) BUILT_IN_TM_STORE_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33471   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WaRM64", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33472   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WaWM64", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33473   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33474   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RaRM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33475   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RaWM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33476   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RfWM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33477
33478   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WM128", (enum ix86_builtins) BUILT_IN_TM_STORE_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33479   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WaRM128", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33480   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WaWM128", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33481   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33482   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RaRM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33483   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RaWM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33484   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RfWM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33485
33486   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WM256", (enum ix86_builtins) BUILT_IN_TM_STORE_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33487   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WaRM256", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33488   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WaWM256", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33489   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33490   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RaRM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33491   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RaWM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33492   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RfWM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33493
33494   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_LM64", (enum ix86_builtins) BUILT_IN_TM_LOG_M64, UNKNOWN, VOID_FTYPE_PCVOID },
33495   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_LM128", (enum ix86_builtins) BUILT_IN_TM_LOG_M128, UNKNOWN, VOID_FTYPE_PCVOID },
33496   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_LM256", (enum ix86_builtins) BUILT_IN_TM_LOG_M256, UNKNOWN, VOID_FTYPE_PCVOID },
33497 };
33498
33499 /* TM callbacks.  */
33500
33501 /* Return the builtin decl needed to load a vector of TYPE.  */
33502
33503 static tree
33504 ix86_builtin_tm_load (tree type)
33505 {
33506   if (TREE_CODE (type) == VECTOR_TYPE)
33507     {
33508       switch (tree_to_uhwi (TYPE_SIZE (type)))
33509         {
33510         case 64:
33511           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M64);
33512         case 128:
33513           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M128);
33514         case 256:
33515           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M256);
33516         }
33517     }
33518   return NULL_TREE;
33519 }
33520
33521 /* Return the builtin decl needed to store a vector of TYPE.  */
33522
33523 static tree
33524 ix86_builtin_tm_store (tree type)
33525 {
33526   if (TREE_CODE (type) == VECTOR_TYPE)
33527     {
33528       switch (tree_to_uhwi (TYPE_SIZE (type)))
33529         {
33530         case 64:
33531           return builtin_decl_explicit (BUILT_IN_TM_STORE_M64);
33532         case 128:
33533           return builtin_decl_explicit (BUILT_IN_TM_STORE_M128);
33534         case 256:
33535           return builtin_decl_explicit (BUILT_IN_TM_STORE_M256);
33536         }
33537     }
33538   return NULL_TREE;
33539 }
33540 \f
33541 /* Initialize the transactional memory vector load/store builtins.  */
33542
33543 static void
33544 ix86_init_tm_builtins (void)
33545 {
33546   enum ix86_builtin_func_type ftype;
33547   const struct builtin_description *d;
33548   size_t i;
33549   tree decl;
33550   tree attrs_load, attrs_type_load, attrs_store, attrs_type_store;
33551   tree attrs_log, attrs_type_log;
33552
33553   if (!flag_tm)
33554     return;
33555
33556   /* If there are no builtins defined, we must be compiling in a
33557      language without trans-mem support.  */
33558   if (!builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
33559     return;
33560
33561   /* Use whatever attributes a normal TM load has.  */
33562   decl = builtin_decl_explicit (BUILT_IN_TM_LOAD_1);
33563   attrs_load = DECL_ATTRIBUTES (decl);
33564   attrs_type_load = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33565   /* Use whatever attributes a normal TM store has.  */
33566   decl = builtin_decl_explicit (BUILT_IN_TM_STORE_1);
33567   attrs_store = DECL_ATTRIBUTES (decl);
33568   attrs_type_store = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33569   /* Use whatever attributes a normal TM log has.  */
33570   decl = builtin_decl_explicit (BUILT_IN_TM_LOG);
33571   attrs_log = DECL_ATTRIBUTES (decl);
33572   attrs_type_log = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33573
33574   for (i = 0, d = bdesc_tm;
33575        i < ARRAY_SIZE (bdesc_tm);
33576        i++, d++)
33577     {
33578       if ((d->mask & ix86_isa_flags) != 0
33579           || (lang_hooks.builtin_function
33580               == lang_hooks.builtin_function_ext_scope))
33581         {
33582           tree type, attrs, attrs_type;
33583           enum built_in_function code = (enum built_in_function) d->code;
33584
33585           ftype = (enum ix86_builtin_func_type) d->flag;
33586           type = ix86_get_builtin_func_type (ftype);
33587
33588           if (BUILTIN_TM_LOAD_P (code))
33589             {
33590               attrs = attrs_load;
33591               attrs_type = attrs_type_load;
33592             }
33593           else if (BUILTIN_TM_STORE_P (code))
33594             {
33595               attrs = attrs_store;
33596               attrs_type = attrs_type_store;
33597             }
33598           else
33599             {
33600               attrs = attrs_log;
33601               attrs_type = attrs_type_log;
33602             }
33603           decl = add_builtin_function (d->name, type, code, BUILT_IN_NORMAL,
33604                                        /* The builtin without the prefix for
33605                                           calling it directly.  */
33606                                        d->name + strlen ("__builtin_"),
33607                                        attrs);
33608           /* add_builtin_function() will set the DECL_ATTRIBUTES, now
33609              set the TYPE_ATTRIBUTES.  */
33610           decl_attributes (&TREE_TYPE (decl), attrs_type, ATTR_FLAG_BUILT_IN);
33611
33612           set_builtin_decl (code, decl, false);
33613         }
33614     }
33615 }
33616
33617 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
33618    in the current target ISA to allow the user to compile particular modules
33619    with different target specific options that differ from the command line
33620    options.  */
33621 static void
33622 ix86_init_mmx_sse_builtins (void)
33623 {
33624   const struct builtin_description * d;
33625   enum ix86_builtin_func_type ftype;
33626   size_t i;
33627
33628   /* Add all special builtins with variable number of operands.  */
33629   for (i = 0, d = bdesc_special_args;
33630        i < ARRAY_SIZE (bdesc_special_args);
33631        i++, d++)
33632     {
33633       if (d->name == 0)
33634         continue;
33635
33636       ftype = (enum ix86_builtin_func_type) d->flag;
33637       def_builtin (d->mask, d->name, ftype, d->code);
33638     }
33639
33640   /* Add all builtins with variable number of operands.  */
33641   for (i = 0, d = bdesc_args;
33642        i < ARRAY_SIZE (bdesc_args);
33643        i++, d++)
33644     {
33645       if (d->name == 0)
33646         continue;
33647
33648       ftype = (enum ix86_builtin_func_type) d->flag;
33649       def_builtin_const (d->mask, d->name, ftype, d->code);
33650     }
33651
33652   /* Add all builtins with rounding.  */
33653   for (i = 0, d = bdesc_round_args;
33654        i < ARRAY_SIZE (bdesc_round_args);
33655        i++, d++)
33656     {
33657       if (d->name == 0)
33658         continue;
33659
33660       ftype = (enum ix86_builtin_func_type) d->flag;
33661       def_builtin_const (d->mask, d->name, ftype, d->code);
33662     }
33663
33664   /* pcmpestr[im] insns.  */
33665   for (i = 0, d = bdesc_pcmpestr;
33666        i < ARRAY_SIZE (bdesc_pcmpestr);
33667        i++, d++)
33668     {
33669       if (d->code == IX86_BUILTIN_PCMPESTRM128)
33670         ftype = V16QI_FTYPE_V16QI_INT_V16QI_INT_INT;
33671       else
33672         ftype = INT_FTYPE_V16QI_INT_V16QI_INT_INT;
33673       def_builtin_const (d->mask, d->name, ftype, d->code);
33674     }
33675
33676   /* pcmpistr[im] insns.  */
33677   for (i = 0, d = bdesc_pcmpistr;
33678        i < ARRAY_SIZE (bdesc_pcmpistr);
33679        i++, d++)
33680     {
33681       if (d->code == IX86_BUILTIN_PCMPISTRM128)
33682         ftype = V16QI_FTYPE_V16QI_V16QI_INT;
33683       else
33684         ftype = INT_FTYPE_V16QI_V16QI_INT;
33685       def_builtin_const (d->mask, d->name, ftype, d->code);
33686     }
33687
33688   /* comi/ucomi insns.  */
33689   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
33690     {
33691       if (d->mask == OPTION_MASK_ISA_SSE2)
33692         ftype = INT_FTYPE_V2DF_V2DF;
33693       else
33694         ftype = INT_FTYPE_V4SF_V4SF;
33695       def_builtin_const (d->mask, d->name, ftype, d->code);
33696     }
33697
33698   /* SSE */
33699   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr",
33700                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_LDMXCSR);
33701   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr",
33702                UNSIGNED_FTYPE_VOID, IX86_BUILTIN_STMXCSR);
33703
33704   /* SSE or 3DNow!A */
33705   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
33706                "__builtin_ia32_maskmovq", VOID_FTYPE_V8QI_V8QI_PCHAR,
33707                IX86_BUILTIN_MASKMOVQ);
33708
33709   /* SSE2 */
33710   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu",
33711                VOID_FTYPE_V16QI_V16QI_PCHAR, IX86_BUILTIN_MASKMOVDQU);
33712
33713   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush",
33714                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLFLUSH);
33715   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence",
33716                             VOID_FTYPE_VOID, IX86_BUILTIN_MFENCE);
33717
33718   /* SSE3.  */
33719   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor",
33720                VOID_FTYPE_PCVOID_UNSIGNED_UNSIGNED, IX86_BUILTIN_MONITOR);
33721   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait",
33722                VOID_FTYPE_UNSIGNED_UNSIGNED, IX86_BUILTIN_MWAIT);
33723
33724   /* AES */
33725   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128",
33726                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENC128);
33727   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128",
33728                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENCLAST128);
33729   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128",
33730                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDEC128);
33731   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128",
33732                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDECLAST128);
33733   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128",
33734                      V2DI_FTYPE_V2DI, IX86_BUILTIN_AESIMC128);
33735   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128",
33736                      V2DI_FTYPE_V2DI_INT, IX86_BUILTIN_AESKEYGENASSIST128);
33737
33738   /* PCLMUL */
33739   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128",
33740                      V2DI_FTYPE_V2DI_V2DI_INT, IX86_BUILTIN_PCLMULQDQ128);
33741
33742   /* RDRND */
33743   def_builtin (OPTION_MASK_ISA_RDRND, "__builtin_ia32_rdrand16_step",
33744                INT_FTYPE_PUSHORT, IX86_BUILTIN_RDRAND16_STEP);
33745   def_builtin (OPTION_MASK_ISA_RDRND, "__builtin_ia32_rdrand32_step",
33746                INT_FTYPE_PUNSIGNED, IX86_BUILTIN_RDRAND32_STEP);
33747   def_builtin (OPTION_MASK_ISA_RDRND | OPTION_MASK_ISA_64BIT,
33748                "__builtin_ia32_rdrand64_step", INT_FTYPE_PULONGLONG,
33749                IX86_BUILTIN_RDRAND64_STEP);
33750
33751   /* AVX2 */
33752   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv2df",
33753                V2DF_FTYPE_V2DF_PCDOUBLE_V4SI_V2DF_INT,
33754                IX86_BUILTIN_GATHERSIV2DF);
33755
33756   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4df",
33757                V4DF_FTYPE_V4DF_PCDOUBLE_V4SI_V4DF_INT,
33758                IX86_BUILTIN_GATHERSIV4DF);
33759
33760   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv2df",
33761                V2DF_FTYPE_V2DF_PCDOUBLE_V2DI_V2DF_INT,
33762                IX86_BUILTIN_GATHERDIV2DF);
33763
33764   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4df",
33765                V4DF_FTYPE_V4DF_PCDOUBLE_V4DI_V4DF_INT,
33766                IX86_BUILTIN_GATHERDIV4DF);
33767
33768   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4sf",
33769                V4SF_FTYPE_V4SF_PCFLOAT_V4SI_V4SF_INT,
33770                IX86_BUILTIN_GATHERSIV4SF);
33771
33772   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv8sf",
33773                V8SF_FTYPE_V8SF_PCFLOAT_V8SI_V8SF_INT,
33774                IX86_BUILTIN_GATHERSIV8SF);
33775
33776   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4sf",
33777                V4SF_FTYPE_V4SF_PCFLOAT_V2DI_V4SF_INT,
33778                IX86_BUILTIN_GATHERDIV4SF);
33779
33780   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4sf256",
33781                V4SF_FTYPE_V4SF_PCFLOAT_V4DI_V4SF_INT,
33782                IX86_BUILTIN_GATHERDIV8SF);
33783
33784   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv2di",
33785                V2DI_FTYPE_V2DI_PCINT64_V4SI_V2DI_INT,
33786                IX86_BUILTIN_GATHERSIV2DI);
33787
33788   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4di",
33789                V4DI_FTYPE_V4DI_PCINT64_V4SI_V4DI_INT,
33790                IX86_BUILTIN_GATHERSIV4DI);
33791
33792   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv2di",
33793                V2DI_FTYPE_V2DI_PCINT64_V2DI_V2DI_INT,
33794                IX86_BUILTIN_GATHERDIV2DI);
33795
33796   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4di",
33797                V4DI_FTYPE_V4DI_PCINT64_V4DI_V4DI_INT,
33798                IX86_BUILTIN_GATHERDIV4DI);
33799
33800   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4si",
33801                V4SI_FTYPE_V4SI_PCINT_V4SI_V4SI_INT,
33802                IX86_BUILTIN_GATHERSIV4SI);
33803
33804   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv8si",
33805                V8SI_FTYPE_V8SI_PCINT_V8SI_V8SI_INT,
33806                IX86_BUILTIN_GATHERSIV8SI);
33807
33808   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4si",
33809                V4SI_FTYPE_V4SI_PCINT_V2DI_V4SI_INT,
33810                IX86_BUILTIN_GATHERDIV4SI);
33811
33812   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4si256",
33813                V4SI_FTYPE_V4SI_PCINT_V4DI_V4SI_INT,
33814                IX86_BUILTIN_GATHERDIV8SI);
33815
33816   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df ",
33817                V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_V4DF_INT,
33818                IX86_BUILTIN_GATHERALTSIV4DF);
33819
33820   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256 ",
33821                V8SF_FTYPE_V8SF_PCFLOAT_V4DI_V8SF_INT,
33822                IX86_BUILTIN_GATHERALTDIV8SF);
33823
33824   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di ",
33825                V4DI_FTYPE_V4DI_PCINT64_V8SI_V4DI_INT,
33826                IX86_BUILTIN_GATHERALTSIV4DI);
33827
33828   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",
33829                V8SI_FTYPE_V8SI_PCINT_V4DI_V8SI_INT,
33830                IX86_BUILTIN_GATHERALTDIV8SI);
33831
33832   /* AVX512F */
33833   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv16sf",
33834                V16SF_FTYPE_V16SF_PCFLOAT_V16SI_HI_INT,
33835                IX86_BUILTIN_GATHER3SIV16SF);
33836
33837   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv8df",
33838                V8DF_FTYPE_V8DF_PCDOUBLE_V8SI_QI_INT,
33839                IX86_BUILTIN_GATHER3SIV8DF);
33840
33841   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv16sf",
33842                V8SF_FTYPE_V8SF_PCFLOAT_V8DI_QI_INT,
33843                IX86_BUILTIN_GATHER3DIV16SF);
33844
33845   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv8df",
33846                V8DF_FTYPE_V8DF_PCDOUBLE_V8DI_QI_INT,
33847                IX86_BUILTIN_GATHER3DIV8DF);
33848
33849   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv16si",
33850                V16SI_FTYPE_V16SI_PCINT_V16SI_HI_INT,
33851                IX86_BUILTIN_GATHER3SIV16SI);
33852
33853   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv8di",
33854                V8DI_FTYPE_V8DI_PCINT64_V8SI_QI_INT,
33855                IX86_BUILTIN_GATHER3SIV8DI);
33856
33857   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv16si",
33858                V8SI_FTYPE_V8SI_PCINT_V8DI_QI_INT,
33859                IX86_BUILTIN_GATHER3DIV16SI);
33860
33861   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv8di",
33862                V8DI_FTYPE_V8DI_PCINT64_V8DI_QI_INT,
33863                IX86_BUILTIN_GATHER3DIV8DI);
33864
33865   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df ",
33866                V8DF_FTYPE_V8DF_PCDOUBLE_V16SI_QI_INT,
33867                IX86_BUILTIN_GATHER3ALTSIV8DF);
33868
33869   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf ",
33870                V16SF_FTYPE_V16SF_PCFLOAT_V8DI_HI_INT,
33871                IX86_BUILTIN_GATHER3ALTDIV16SF);
33872
33873   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di ",
33874                V8DI_FTYPE_V8DI_PCINT64_V16SI_QI_INT,
33875                IX86_BUILTIN_GATHER3ALTSIV8DI);
33876
33877   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si ",
33878                V16SI_FTYPE_V16SI_PCINT_V8DI_HI_INT,
33879                IX86_BUILTIN_GATHER3ALTDIV16SI);
33880
33881   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv16sf",
33882                VOID_FTYPE_PFLOAT_HI_V16SI_V16SF_INT,
33883                IX86_BUILTIN_SCATTERSIV16SF);
33884
33885   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv8df",
33886                VOID_FTYPE_PDOUBLE_QI_V8SI_V8DF_INT,
33887                IX86_BUILTIN_SCATTERSIV8DF);
33888
33889   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv16sf",
33890                VOID_FTYPE_PFLOAT_QI_V8DI_V8SF_INT,
33891                IX86_BUILTIN_SCATTERDIV16SF);
33892
33893   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv8df",
33894                VOID_FTYPE_PDOUBLE_QI_V8DI_V8DF_INT,
33895                IX86_BUILTIN_SCATTERDIV8DF);
33896
33897   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv16si",
33898                VOID_FTYPE_PINT_HI_V16SI_V16SI_INT,
33899                IX86_BUILTIN_SCATTERSIV16SI);
33900
33901   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv8di",
33902                VOID_FTYPE_PLONGLONG_QI_V8SI_V8DI_INT,
33903                IX86_BUILTIN_SCATTERSIV8DI);
33904
33905   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv16si",
33906                VOID_FTYPE_PINT_QI_V8DI_V8SI_INT,
33907                IX86_BUILTIN_SCATTERDIV16SI);
33908
33909   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv8di",
33910                VOID_FTYPE_PLONGLONG_QI_V8DI_V8DI_INT,
33911                IX86_BUILTIN_SCATTERDIV8DI);
33912
33913   /* AVX512VL */
33914   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv2df",
33915                V2DF_FTYPE_V2DF_PCDOUBLE_V4SI_QI_INT,
33916                IX86_BUILTIN_GATHER3SIV2DF);
33917
33918   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4df",
33919                V4DF_FTYPE_V4DF_PCDOUBLE_V4SI_QI_INT,
33920                IX86_BUILTIN_GATHER3SIV4DF);
33921
33922   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div2df",
33923                V2DF_FTYPE_V2DF_PCDOUBLE_V2DI_QI_INT,
33924                IX86_BUILTIN_GATHER3DIV2DF);
33925
33926   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4df",
33927                V4DF_FTYPE_V4DF_PCDOUBLE_V4DI_QI_INT,
33928                IX86_BUILTIN_GATHER3DIV4DF);
33929
33930   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4sf",
33931                V4SF_FTYPE_V4SF_PCFLOAT_V4SI_QI_INT,
33932                IX86_BUILTIN_GATHER3SIV4SF);
33933
33934   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv8sf",
33935                V8SF_FTYPE_V8SF_PCFLOAT_V8SI_QI_INT,
33936                IX86_BUILTIN_GATHER3SIV8SF);
33937
33938   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4sf",
33939                V4SF_FTYPE_V4SF_PCFLOAT_V2DI_QI_INT,
33940                IX86_BUILTIN_GATHER3DIV4SF);
33941
33942   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div8sf",
33943                V4SF_FTYPE_V4SF_PCFLOAT_V4DI_QI_INT,
33944                IX86_BUILTIN_GATHER3DIV8SF);
33945
33946   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv2di",
33947                V2DI_FTYPE_V2DI_PCINT64_V4SI_QI_INT,
33948                IX86_BUILTIN_GATHER3SIV2DI);
33949
33950   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4di",
33951                V4DI_FTYPE_V4DI_PCINT64_V4SI_QI_INT,
33952                IX86_BUILTIN_GATHER3SIV4DI);
33953
33954   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div2di",
33955                V2DI_FTYPE_V2DI_PCINT64_V2DI_QI_INT,
33956                IX86_BUILTIN_GATHER3DIV2DI);
33957
33958   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4di",
33959                V4DI_FTYPE_V4DI_PCINT64_V4DI_QI_INT,
33960                IX86_BUILTIN_GATHER3DIV4DI);
33961
33962   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4si",
33963                V4SI_FTYPE_V4SI_PCINT_V4SI_QI_INT,
33964                IX86_BUILTIN_GATHER3SIV4SI);
33965
33966   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv8si",
33967                V8SI_FTYPE_V8SI_PCINT_V8SI_QI_INT,
33968                IX86_BUILTIN_GATHER3SIV8SI);
33969
33970   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4si",
33971                V4SI_FTYPE_V4SI_PCINT_V2DI_QI_INT,
33972                IX86_BUILTIN_GATHER3DIV4SI);
33973
33974   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div8si",
33975                V4SI_FTYPE_V4SI_PCINT_V4DI_QI_INT,
33976                IX86_BUILTIN_GATHER3DIV8SI);
33977
33978   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df ",
33979                V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_QI_INT,
33980                IX86_BUILTIN_GATHER3ALTSIV4DF);
33981
33982   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf ",
33983                V8SF_FTYPE_V8SF_PCFLOAT_V4DI_QI_INT,
33984                IX86_BUILTIN_GATHER3ALTDIV8SF);
33985
33986   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di ",
33987                V4DI_FTYPE_V4DI_PCINT64_V8SI_QI_INT,
33988                IX86_BUILTIN_GATHER3ALTSIV4DI);
33989
33990   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si ",
33991                V8SI_FTYPE_V8SI_PCINT_V4DI_QI_INT,
33992                IX86_BUILTIN_GATHER3ALTDIV8SI);
33993
33994   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv8sf",
33995                VOID_FTYPE_PFLOAT_QI_V8SI_V8SF_INT,
33996                IX86_BUILTIN_SCATTERSIV8SF);
33997
33998   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4sf",
33999                VOID_FTYPE_PFLOAT_QI_V4SI_V4SF_INT,
34000                IX86_BUILTIN_SCATTERSIV4SF);
34001
34002   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4df",
34003                VOID_FTYPE_PDOUBLE_QI_V4SI_V4DF_INT,
34004                IX86_BUILTIN_SCATTERSIV4DF);
34005
34006   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv2df",
34007                VOID_FTYPE_PDOUBLE_QI_V4SI_V2DF_INT,
34008                IX86_BUILTIN_SCATTERSIV2DF);
34009
34010   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv8sf",
34011                VOID_FTYPE_PFLOAT_QI_V4DI_V4SF_INT,
34012                IX86_BUILTIN_SCATTERDIV8SF);
34013
34014   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4sf",
34015                VOID_FTYPE_PFLOAT_QI_V2DI_V4SF_INT,
34016                IX86_BUILTIN_SCATTERDIV4SF);
34017
34018   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4df",
34019                VOID_FTYPE_PDOUBLE_QI_V4DI_V4DF_INT,
34020                IX86_BUILTIN_SCATTERDIV4DF);
34021
34022   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2df",
34023                VOID_FTYPE_PDOUBLE_QI_V2DI_V2DF_INT,
34024                IX86_BUILTIN_SCATTERDIV2DF);
34025
34026   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv8si",
34027                VOID_FTYPE_PINT_QI_V8SI_V8SI_INT,
34028                IX86_BUILTIN_SCATTERSIV8SI);
34029
34030   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4si",
34031                VOID_FTYPE_PINT_QI_V4SI_V4SI_INT,
34032                IX86_BUILTIN_SCATTERSIV4SI);
34033
34034   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4di",
34035                VOID_FTYPE_PLONGLONG_QI_V4SI_V4DI_INT,
34036                IX86_BUILTIN_SCATTERSIV4DI);
34037
34038   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv2di",
34039                VOID_FTYPE_PLONGLONG_QI_V4SI_V2DI_INT,
34040                IX86_BUILTIN_SCATTERSIV2DI);
34041
34042   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv8si",
34043                VOID_FTYPE_PINT_QI_V4DI_V4SI_INT,
34044                IX86_BUILTIN_SCATTERDIV8SI);
34045
34046   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4si",
34047                VOID_FTYPE_PINT_QI_V2DI_V4SI_INT,
34048                IX86_BUILTIN_SCATTERDIV4SI);
34049
34050   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4di",
34051                VOID_FTYPE_PLONGLONG_QI_V4DI_V4DI_INT,
34052                IX86_BUILTIN_SCATTERDIV4DI);
34053
34054   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2di",
34055                VOID_FTYPE_PLONGLONG_QI_V2DI_V2DI_INT,
34056                IX86_BUILTIN_SCATTERDIV2DI);
34057
34058   /* AVX512PF */
34059   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfdpd",
34060                VOID_FTYPE_QI_V8SI_PCINT64_INT_INT,
34061                IX86_BUILTIN_GATHERPFDPD);
34062   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfdps",
34063                VOID_FTYPE_HI_V16SI_PCINT_INT_INT,
34064                IX86_BUILTIN_GATHERPFDPS);
34065   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfqpd",
34066                VOID_FTYPE_QI_V8DI_PCINT64_INT_INT,
34067                IX86_BUILTIN_GATHERPFQPD);
34068   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfqps",
34069                VOID_FTYPE_QI_V8DI_PCINT_INT_INT,
34070                IX86_BUILTIN_GATHERPFQPS);
34071   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfdpd",
34072                VOID_FTYPE_QI_V8SI_PCINT64_INT_INT,
34073                IX86_BUILTIN_SCATTERPFDPD);
34074   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfdps",
34075                VOID_FTYPE_HI_V16SI_PCINT_INT_INT,
34076                IX86_BUILTIN_SCATTERPFDPS);
34077   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfqpd",
34078                VOID_FTYPE_QI_V8DI_PCINT64_INT_INT,
34079                IX86_BUILTIN_SCATTERPFQPD);
34080   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfqps",
34081                VOID_FTYPE_QI_V8DI_PCINT_INT_INT,
34082                IX86_BUILTIN_SCATTERPFQPS);
34083
34084   /* SHA */
34085   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1msg1",
34086                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1MSG1);
34087   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1msg2",
34088                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1MSG2);
34089   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1nexte",
34090                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1NEXTE);
34091   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1rnds4",
34092                      V4SI_FTYPE_V4SI_V4SI_INT, IX86_BUILTIN_SHA1RNDS4);
34093   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256msg1",
34094                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA256MSG1);
34095   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256msg2",
34096                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA256MSG2);
34097   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256rnds2",
34098                      V4SI_FTYPE_V4SI_V4SI_V4SI, IX86_BUILTIN_SHA256RNDS2);
34099
34100   /* RTM.  */
34101   def_builtin (OPTION_MASK_ISA_RTM, "__builtin_ia32_xabort",
34102                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_XABORT);
34103
34104   /* MMX access to the vec_init patterns.  */
34105   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si",
34106                      V2SI_FTYPE_INT_INT, IX86_BUILTIN_VEC_INIT_V2SI);
34107
34108   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi",
34109                      V4HI_FTYPE_HI_HI_HI_HI,
34110                      IX86_BUILTIN_VEC_INIT_V4HI);
34111
34112   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi",
34113                      V8QI_FTYPE_QI_QI_QI_QI_QI_QI_QI_QI,
34114                      IX86_BUILTIN_VEC_INIT_V8QI);
34115
34116   /* Access to the vec_extract patterns.  */
34117   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df",
34118                      DOUBLE_FTYPE_V2DF_INT, IX86_BUILTIN_VEC_EXT_V2DF);
34119   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di",
34120                      DI_FTYPE_V2DI_INT, IX86_BUILTIN_VEC_EXT_V2DI);
34121   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf",
34122                      FLOAT_FTYPE_V4SF_INT, IX86_BUILTIN_VEC_EXT_V4SF);
34123   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si",
34124                      SI_FTYPE_V4SI_INT, IX86_BUILTIN_VEC_EXT_V4SI);
34125   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi",
34126                      HI_FTYPE_V8HI_INT, IX86_BUILTIN_VEC_EXT_V8HI);
34127
34128   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
34129                      "__builtin_ia32_vec_ext_v4hi",
34130                      HI_FTYPE_V4HI_INT, IX86_BUILTIN_VEC_EXT_V4HI);
34131
34132   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si",
34133                      SI_FTYPE_V2SI_INT, IX86_BUILTIN_VEC_EXT_V2SI);
34134
34135   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi",
34136                      QI_FTYPE_V16QI_INT, IX86_BUILTIN_VEC_EXT_V16QI);
34137
34138   /* Access to the vec_set patterns.  */
34139   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT,
34140                      "__builtin_ia32_vec_set_v2di",
34141                      V2DI_FTYPE_V2DI_DI_INT, IX86_BUILTIN_VEC_SET_V2DI);
34142
34143   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf",
34144                      V4SF_FTYPE_V4SF_FLOAT_INT, IX86_BUILTIN_VEC_SET_V4SF);
34145
34146   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si",
34147                      V4SI_FTYPE_V4SI_SI_INT, IX86_BUILTIN_VEC_SET_V4SI);
34148
34149   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi",
34150                      V8HI_FTYPE_V8HI_HI_INT, IX86_BUILTIN_VEC_SET_V8HI);
34151
34152   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
34153                      "__builtin_ia32_vec_set_v4hi",
34154                      V4HI_FTYPE_V4HI_HI_INT, IX86_BUILTIN_VEC_SET_V4HI);
34155
34156   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi",
34157                      V16QI_FTYPE_V16QI_QI_INT, IX86_BUILTIN_VEC_SET_V16QI);
34158
34159   /* RDSEED */
34160   def_builtin (OPTION_MASK_ISA_RDSEED, "__builtin_ia32_rdseed_hi_step",
34161                INT_FTYPE_PUSHORT, IX86_BUILTIN_RDSEED16_STEP);
34162   def_builtin (OPTION_MASK_ISA_RDSEED, "__builtin_ia32_rdseed_si_step",
34163                INT_FTYPE_PUNSIGNED, IX86_BUILTIN_RDSEED32_STEP);
34164   def_builtin (OPTION_MASK_ISA_RDSEED | OPTION_MASK_ISA_64BIT,
34165                "__builtin_ia32_rdseed_di_step",
34166                INT_FTYPE_PULONGLONG, IX86_BUILTIN_RDSEED64_STEP);
34167
34168   /* ADCX */
34169   def_builtin (0, "__builtin_ia32_addcarryx_u32",
34170                UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED, IX86_BUILTIN_ADDCARRYX32);
34171   def_builtin (OPTION_MASK_ISA_64BIT,
34172                "__builtin_ia32_addcarryx_u64",
34173                UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG,
34174                IX86_BUILTIN_ADDCARRYX64);
34175
34176   /* SBB */
34177   def_builtin (0, "__builtin_ia32_sbb_u32",
34178                UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED, IX86_BUILTIN_SBB32);
34179   def_builtin (OPTION_MASK_ISA_64BIT,
34180                "__builtin_ia32_sbb_u64",
34181                UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG,
34182                IX86_BUILTIN_SBB64);
34183
34184   /* Read/write FLAGS.  */
34185   def_builtin (~OPTION_MASK_ISA_64BIT, "__builtin_ia32_readeflags_u32",
34186                UNSIGNED_FTYPE_VOID, IX86_BUILTIN_READ_FLAGS);
34187   def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_ia32_readeflags_u64",
34188                UINT64_FTYPE_VOID, IX86_BUILTIN_READ_FLAGS);
34189   def_builtin (~OPTION_MASK_ISA_64BIT, "__builtin_ia32_writeeflags_u32",
34190                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_WRITE_FLAGS);
34191   def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_ia32_writeeflags_u64",
34192                VOID_FTYPE_UINT64, IX86_BUILTIN_WRITE_FLAGS);
34193
34194   /* CLFLUSHOPT.  */
34195   def_builtin (OPTION_MASK_ISA_CLFLUSHOPT, "__builtin_ia32_clflushopt",
34196                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLFLUSHOPT);
34197
34198   /* CLWB.  */
34199   def_builtin (OPTION_MASK_ISA_CLWB, "__builtin_ia32_clwb",
34200                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLWB);
34201
34202   /* MONITORX and MWAITX.  */
34203   def_builtin (OPTION_MASK_ISA_MWAITX, "__builtin_ia32_monitorx",
34204                VOID_FTYPE_PCVOID_UNSIGNED_UNSIGNED, IX86_BUILTIN_MONITORX);
34205   def_builtin (OPTION_MASK_ISA_MWAITX, "__builtin_ia32_mwaitx",
34206                VOID_FTYPE_UNSIGNED_UNSIGNED_UNSIGNED, IX86_BUILTIN_MWAITX);
34207
34208   /* Add FMA4 multi-arg argument instructions */
34209   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
34210     {
34211       if (d->name == 0)
34212         continue;
34213
34214       ftype = (enum ix86_builtin_func_type) d->flag;
34215       def_builtin_const (d->mask, d->name, ftype, d->code);
34216     }
34217 }
34218
34219 static void
34220 ix86_init_mpx_builtins ()
34221 {
34222   const struct builtin_description * d;
34223   enum ix86_builtin_func_type ftype;
34224   tree decl;
34225   size_t i;
34226
34227   for (i = 0, d = bdesc_mpx;
34228        i < ARRAY_SIZE (bdesc_mpx);
34229        i++, d++)
34230     {
34231       if (d->name == 0)
34232         continue;
34233
34234       ftype = (enum ix86_builtin_func_type) d->flag;
34235       decl = def_builtin (d->mask, d->name, ftype, d->code);
34236
34237       /* With no leaf and nothrow flags for MPX builtins
34238          abnormal edges may follow its call when setjmp
34239          presents in the function.  Since we may have a lot
34240          of MPX builtins calls it causes lots of useless
34241          edges and enormous PHI nodes.  To avoid this we mark
34242          MPX builtins as leaf and nothrow.  */
34243       if (decl)
34244         {
34245           DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
34246                                                     NULL_TREE);
34247           TREE_NOTHROW (decl) = 1;
34248         }
34249       else
34250         {
34251           ix86_builtins_isa[(int)d->code].leaf_p = true;
34252           ix86_builtins_isa[(int)d->code].nothrow_p = true;
34253         }
34254     }
34255
34256   for (i = 0, d = bdesc_mpx_const;
34257        i < ARRAY_SIZE (bdesc_mpx_const);
34258        i++, d++)
34259     {
34260       if (d->name == 0)
34261         continue;
34262
34263       ftype = (enum ix86_builtin_func_type) d->flag;
34264       decl = def_builtin_const (d->mask, d->name, ftype, d->code);
34265
34266       if (decl)
34267         {
34268           DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
34269                                                     NULL_TREE);
34270           TREE_NOTHROW (decl) = 1;
34271         }
34272       else
34273         {
34274           ix86_builtins_isa[(int)d->code].leaf_p = true;
34275           ix86_builtins_isa[(int)d->code].nothrow_p = true;
34276         }
34277     }
34278 }
34279
34280 /* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL
34281    to return a pointer to VERSION_DECL if the outcome of the expression
34282    formed by PREDICATE_CHAIN is true.  This function will be called during
34283    version dispatch to decide which function version to execute.  It returns
34284    the basic block at the end, to which more conditions can be added.  */
34285
34286 static basic_block
34287 add_condition_to_bb (tree function_decl, tree version_decl,
34288                      tree predicate_chain, basic_block new_bb)
34289 {
34290   gimple return_stmt;
34291   tree convert_expr, result_var;
34292   gimple convert_stmt;
34293   gimple call_cond_stmt;
34294   gimple if_else_stmt;
34295
34296   basic_block bb1, bb2, bb3;
34297   edge e12, e23;
34298
34299   tree cond_var, and_expr_var = NULL_TREE;
34300   gimple_seq gseq;
34301
34302   tree predicate_decl, predicate_arg;
34303
34304   push_cfun (DECL_STRUCT_FUNCTION (function_decl));
34305
34306   gcc_assert (new_bb != NULL);
34307   gseq = bb_seq (new_bb);
34308
34309
34310   convert_expr = build1 (CONVERT_EXPR, ptr_type_node,
34311                          build_fold_addr_expr (version_decl));
34312   result_var = create_tmp_var (ptr_type_node);
34313   convert_stmt = gimple_build_assign (result_var, convert_expr); 
34314   return_stmt = gimple_build_return (result_var);
34315
34316   if (predicate_chain == NULL_TREE)
34317     {
34318       gimple_seq_add_stmt (&gseq, convert_stmt);
34319       gimple_seq_add_stmt (&gseq, return_stmt);
34320       set_bb_seq (new_bb, gseq);
34321       gimple_set_bb (convert_stmt, new_bb);
34322       gimple_set_bb (return_stmt, new_bb);
34323       pop_cfun ();
34324       return new_bb;
34325     }
34326
34327   while (predicate_chain != NULL)
34328     {
34329       cond_var = create_tmp_var (integer_type_node);
34330       predicate_decl = TREE_PURPOSE (predicate_chain);
34331       predicate_arg = TREE_VALUE (predicate_chain);
34332       call_cond_stmt = gimple_build_call (predicate_decl, 1, predicate_arg);
34333       gimple_call_set_lhs (call_cond_stmt, cond_var);
34334
34335       gimple_set_block (call_cond_stmt, DECL_INITIAL (function_decl));
34336       gimple_set_bb (call_cond_stmt, new_bb);
34337       gimple_seq_add_stmt (&gseq, call_cond_stmt);
34338
34339       predicate_chain = TREE_CHAIN (predicate_chain);
34340       
34341       if (and_expr_var == NULL)
34342         and_expr_var = cond_var;
34343       else
34344         {
34345           gimple assign_stmt;
34346           /* Use MIN_EXPR to check if any integer is zero?.
34347              and_expr_var = min_expr <cond_var, and_expr_var>  */
34348           assign_stmt = gimple_build_assign (and_expr_var,
34349                           build2 (MIN_EXPR, integer_type_node,
34350                                   cond_var, and_expr_var));
34351
34352           gimple_set_block (assign_stmt, DECL_INITIAL (function_decl));
34353           gimple_set_bb (assign_stmt, new_bb);
34354           gimple_seq_add_stmt (&gseq, assign_stmt);
34355         }
34356     }
34357
34358   if_else_stmt = gimple_build_cond (GT_EXPR, and_expr_var,
34359                                     integer_zero_node,
34360                                     NULL_TREE, NULL_TREE);
34361   gimple_set_block (if_else_stmt, DECL_INITIAL (function_decl));
34362   gimple_set_bb (if_else_stmt, new_bb);
34363   gimple_seq_add_stmt (&gseq, if_else_stmt);
34364
34365   gimple_seq_add_stmt (&gseq, convert_stmt);
34366   gimple_seq_add_stmt (&gseq, return_stmt);
34367   set_bb_seq (new_bb, gseq);
34368
34369   bb1 = new_bb;
34370   e12 = split_block (bb1, if_else_stmt);
34371   bb2 = e12->dest;
34372   e12->flags &= ~EDGE_FALLTHRU;
34373   e12->flags |= EDGE_TRUE_VALUE;
34374
34375   e23 = split_block (bb2, return_stmt);
34376
34377   gimple_set_bb (convert_stmt, bb2);
34378   gimple_set_bb (return_stmt, bb2);
34379
34380   bb3 = e23->dest;
34381   make_edge (bb1, bb3, EDGE_FALSE_VALUE); 
34382
34383   remove_edge (e23);
34384   make_edge (bb2, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
34385
34386   pop_cfun ();
34387
34388   return bb3;
34389 }
34390
34391 /* This parses the attribute arguments to target in DECL and determines
34392    the right builtin to use to match the platform specification.
34393    It returns the priority value for this version decl.  If PREDICATE_LIST
34394    is not NULL, it stores the list of cpu features that need to be checked
34395    before dispatching this function.  */
34396
34397 static unsigned int
34398 get_builtin_code_for_version (tree decl, tree *predicate_list)
34399 {
34400   tree attrs;
34401   struct cl_target_option cur_target;
34402   tree target_node;
34403   struct cl_target_option *new_target;
34404   const char *arg_str = NULL;
34405   const char *attrs_str = NULL;
34406   char *tok_str = NULL;
34407   char *token;
34408
34409   /* Priority of i386 features, greater value is higher priority.   This is
34410      used to decide the order in which function dispatch must happen.  For
34411      instance, a version specialized for SSE4.2 should be checked for dispatch
34412      before a version for SSE3, as SSE4.2 implies SSE3.  */
34413   enum feature_priority
34414   {
34415     P_ZERO = 0,
34416     P_MMX,
34417     P_SSE,
34418     P_SSE2,
34419     P_SSE3,
34420     P_SSSE3,
34421     P_PROC_SSSE3,
34422     P_SSE4_A,
34423     P_PROC_SSE4_A,
34424     P_SSE4_1,
34425     P_SSE4_2,
34426     P_PROC_SSE4_2,
34427     P_POPCNT,
34428     P_AVX,
34429     P_PROC_AVX,
34430     P_BMI,
34431     P_PROC_BMI,
34432     P_FMA4,
34433     P_XOP,
34434     P_PROC_XOP,
34435     P_FMA,    
34436     P_PROC_FMA,
34437     P_BMI2,
34438     P_AVX2,
34439     P_PROC_AVX2,
34440     P_AVX512F,
34441     P_PROC_AVX512F
34442   };
34443
34444  enum feature_priority priority = P_ZERO;
34445
34446   /* These are the target attribute strings for which a dispatcher is
34447      available, from fold_builtin_cpu.  */
34448
34449   static struct _feature_list
34450     {
34451       const char *const name;
34452       const enum feature_priority priority;
34453     }
34454   const feature_list[] =
34455     {
34456       {"mmx", P_MMX},
34457       {"sse", P_SSE},
34458       {"sse2", P_SSE2},
34459       {"sse3", P_SSE3},
34460       {"sse4a", P_SSE4_A},
34461       {"ssse3", P_SSSE3},
34462       {"sse4.1", P_SSE4_1},
34463       {"sse4.2", P_SSE4_2},
34464       {"popcnt", P_POPCNT},
34465       {"avx", P_AVX},
34466       {"bmi", P_BMI},
34467       {"fma4", P_FMA4},
34468       {"xop", P_XOP},
34469       {"fma", P_FMA},
34470       {"bmi2", P_BMI2},
34471       {"avx2", P_AVX2},
34472       {"avx512f", P_AVX512F}
34473     };
34474
34475
34476   static unsigned int NUM_FEATURES
34477     = sizeof (feature_list) / sizeof (struct _feature_list);
34478
34479   unsigned int i;
34480
34481   tree predicate_chain = NULL_TREE;
34482   tree predicate_decl, predicate_arg;
34483
34484   attrs = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34485   gcc_assert (attrs != NULL);
34486
34487   attrs = TREE_VALUE (TREE_VALUE (attrs));
34488
34489   gcc_assert (TREE_CODE (attrs) == STRING_CST);
34490   attrs_str = TREE_STRING_POINTER (attrs);
34491
34492   /* Return priority zero for default function.  */
34493   if (strcmp (attrs_str, "default") == 0)
34494     return 0;
34495
34496   /* Handle arch= if specified.  For priority, set it to be 1 more than
34497      the best instruction set the processor can handle.  For instance, if
34498      there is a version for atom and a version for ssse3 (the highest ISA
34499      priority for atom), the atom version must be checked for dispatch
34500      before the ssse3 version. */
34501   if (strstr (attrs_str, "arch=") != NULL)
34502     {
34503       cl_target_option_save (&cur_target, &global_options);
34504       target_node = ix86_valid_target_attribute_tree (attrs, &global_options,
34505                                                       &global_options_set);
34506     
34507       gcc_assert (target_node);
34508       new_target = TREE_TARGET_OPTION (target_node);
34509       gcc_assert (new_target);
34510       
34511       if (new_target->arch_specified && new_target->arch > 0)
34512         {
34513           switch (new_target->arch)
34514             {
34515             case PROCESSOR_CORE2:
34516               arg_str = "core2";
34517               priority = P_PROC_SSSE3;
34518               break;
34519             case PROCESSOR_NEHALEM:
34520               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_AES)
34521                 arg_str = "westmere";
34522               else
34523                 /* We translate "arch=corei7" and "arch=nehalem" to
34524                    "corei7" so that it will be mapped to M_INTEL_COREI7
34525                    as cpu type to cover all M_INTEL_COREI7_XXXs.  */
34526                 arg_str = "corei7";
34527               priority = P_PROC_SSE4_2;
34528               break;
34529             case PROCESSOR_SANDYBRIDGE:
34530               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_F16C)
34531                 arg_str = "ivybridge";
34532               else
34533                 arg_str = "sandybridge";
34534               priority = P_PROC_AVX;
34535               break;
34536             case PROCESSOR_HASWELL:
34537               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_ADX)
34538                 arg_str = "broadwell";
34539               else
34540                 arg_str = "haswell";
34541               priority = P_PROC_AVX2;
34542               break;
34543             case PROCESSOR_BONNELL:
34544               arg_str = "bonnell";
34545               priority = P_PROC_SSSE3;
34546               break;
34547             case PROCESSOR_KNL:
34548               arg_str = "knl";
34549               priority = P_PROC_AVX512F;
34550               break;
34551             case PROCESSOR_SILVERMONT:
34552               arg_str = "silvermont";
34553               priority = P_PROC_SSE4_2;
34554               break;
34555             case PROCESSOR_AMDFAM10:
34556               arg_str = "amdfam10h";
34557               priority = P_PROC_SSE4_A;
34558               break;
34559             case PROCESSOR_BTVER1:
34560               arg_str = "btver1";
34561               priority = P_PROC_SSE4_A;
34562               break;
34563             case PROCESSOR_BTVER2:
34564               arg_str = "btver2";
34565               priority = P_PROC_BMI;
34566               break;
34567             case PROCESSOR_BDVER1:
34568               arg_str = "bdver1";
34569               priority = P_PROC_XOP;
34570               break;
34571             case PROCESSOR_BDVER2:
34572               arg_str = "bdver2";
34573               priority = P_PROC_FMA;
34574               break;
34575             case PROCESSOR_BDVER3:
34576               arg_str = "bdver3";
34577               priority = P_PROC_FMA;
34578               break;
34579             case PROCESSOR_BDVER4:
34580               arg_str = "bdver4";
34581               priority = P_PROC_AVX2;
34582               break;
34583             }  
34584         }    
34585     
34586       cl_target_option_restore (&global_options, &cur_target);
34587         
34588       if (predicate_list && arg_str == NULL)
34589         {
34590           error_at (DECL_SOURCE_LOCATION (decl),
34591                 "No dispatcher found for the versioning attributes");
34592           return 0;
34593         }
34594     
34595       if (predicate_list)
34596         {
34597           predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_IS];
34598           /* For a C string literal the length includes the trailing NULL.  */
34599           predicate_arg = build_string_literal (strlen (arg_str) + 1, arg_str);
34600           predicate_chain = tree_cons (predicate_decl, predicate_arg,
34601                                        predicate_chain);
34602         }
34603     }
34604
34605   /* Process feature name.  */
34606   tok_str =  (char *) xmalloc (strlen (attrs_str) + 1);
34607   strcpy (tok_str, attrs_str);
34608   token = strtok (tok_str, ",");
34609   predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_SUPPORTS];
34610
34611   while (token != NULL)
34612     {
34613       /* Do not process "arch="  */
34614       if (strncmp (token, "arch=", 5) == 0)
34615         {
34616           token = strtok (NULL, ",");
34617           continue;
34618         }
34619       for (i = 0; i < NUM_FEATURES; ++i)
34620         {
34621           if (strcmp (token, feature_list[i].name) == 0)
34622             {
34623               if (predicate_list)
34624                 {
34625                   predicate_arg = build_string_literal (
34626                                   strlen (feature_list[i].name) + 1,
34627                                   feature_list[i].name);
34628                   predicate_chain = tree_cons (predicate_decl, predicate_arg,
34629                                                predicate_chain);
34630                 }
34631               /* Find the maximum priority feature.  */
34632               if (feature_list[i].priority > priority)
34633                 priority = feature_list[i].priority;
34634
34635               break;
34636             }
34637         }
34638       if (predicate_list && i == NUM_FEATURES)
34639         {
34640           error_at (DECL_SOURCE_LOCATION (decl),
34641                     "No dispatcher found for %s", token);
34642           return 0;
34643         }
34644       token = strtok (NULL, ",");
34645     }
34646   free (tok_str);
34647
34648   if (predicate_list && predicate_chain == NULL_TREE)
34649     {
34650       error_at (DECL_SOURCE_LOCATION (decl),
34651                 "No dispatcher found for the versioning attributes : %s",
34652                 attrs_str);
34653       return 0;
34654     }
34655   else if (predicate_list)
34656     {
34657       predicate_chain = nreverse (predicate_chain);
34658       *predicate_list = predicate_chain;
34659     }
34660
34661   return priority; 
34662 }
34663
34664 /* This compares the priority of target features in function DECL1
34665    and DECL2.  It returns positive value if DECL1 is higher priority,
34666    negative value if DECL2 is higher priority and 0 if they are the
34667    same.  */
34668
34669 static int
34670 ix86_compare_version_priority (tree decl1, tree decl2)
34671 {
34672   unsigned int priority1 = get_builtin_code_for_version (decl1, NULL);
34673   unsigned int priority2 = get_builtin_code_for_version (decl2, NULL);
34674
34675   return (int)priority1 - (int)priority2;
34676 }
34677
34678 /* V1 and V2 point to function versions with different priorities
34679    based on the target ISA.  This function compares their priorities.  */
34680  
34681 static int
34682 feature_compare (const void *v1, const void *v2)
34683 {
34684   typedef struct _function_version_info
34685     {
34686       tree version_decl;
34687       tree predicate_chain;
34688       unsigned int dispatch_priority;
34689     } function_version_info;
34690
34691   const function_version_info c1 = *(const function_version_info *)v1;
34692   const function_version_info c2 = *(const function_version_info *)v2;
34693   return (c2.dispatch_priority - c1.dispatch_priority);
34694 }
34695
34696 /* This function generates the dispatch function for
34697    multi-versioned functions.  DISPATCH_DECL is the function which will
34698    contain the dispatch logic.  FNDECLS are the function choices for
34699    dispatch, and is a tree chain.  EMPTY_BB is the basic block pointer
34700    in DISPATCH_DECL in which the dispatch code is generated.  */
34701
34702 static int
34703 dispatch_function_versions (tree dispatch_decl,
34704                             void *fndecls_p,
34705                             basic_block *empty_bb)
34706 {
34707   tree default_decl;
34708   gimple ifunc_cpu_init_stmt;
34709   gimple_seq gseq;
34710   int ix;
34711   tree ele;
34712   vec<tree> *fndecls;
34713   unsigned int num_versions = 0;
34714   unsigned int actual_versions = 0;
34715   unsigned int i;
34716
34717   struct _function_version_info
34718     {
34719       tree version_decl;
34720       tree predicate_chain;
34721       unsigned int dispatch_priority;
34722     }*function_version_info;
34723
34724   gcc_assert (dispatch_decl != NULL
34725               && fndecls_p != NULL
34726               && empty_bb != NULL);
34727
34728   /*fndecls_p is actually a vector.  */
34729   fndecls = static_cast<vec<tree> *> (fndecls_p);
34730
34731   /* At least one more version other than the default.  */
34732   num_versions = fndecls->length ();
34733   gcc_assert (num_versions >= 2);
34734
34735   function_version_info = (struct _function_version_info *)
34736     XNEWVEC (struct _function_version_info, (num_versions - 1));
34737
34738   /* The first version in the vector is the default decl.  */
34739   default_decl = (*fndecls)[0];
34740
34741   push_cfun (DECL_STRUCT_FUNCTION (dispatch_decl));
34742
34743   gseq = bb_seq (*empty_bb);
34744   /* Function version dispatch is via IFUNC.  IFUNC resolvers fire before
34745      constructors, so explicity call __builtin_cpu_init here.  */
34746   ifunc_cpu_init_stmt = gimple_build_call_vec (
34747                      ix86_builtins [(int) IX86_BUILTIN_CPU_INIT], vNULL);
34748   gimple_seq_add_stmt (&gseq, ifunc_cpu_init_stmt);
34749   gimple_set_bb (ifunc_cpu_init_stmt, *empty_bb);
34750   set_bb_seq (*empty_bb, gseq);
34751
34752   pop_cfun ();
34753
34754
34755   for (ix = 1; fndecls->iterate (ix, &ele); ++ix)
34756     {
34757       tree version_decl = ele;
34758       tree predicate_chain = NULL_TREE;
34759       unsigned int priority;
34760       /* Get attribute string, parse it and find the right predicate decl.
34761          The predicate function could be a lengthy combination of many
34762          features, like arch-type and various isa-variants.  */
34763       priority = get_builtin_code_for_version (version_decl,
34764                                                &predicate_chain);
34765
34766       if (predicate_chain == NULL_TREE)
34767         continue;
34768
34769       function_version_info [actual_versions].version_decl = version_decl;
34770       function_version_info [actual_versions].predicate_chain
34771          = predicate_chain;
34772       function_version_info [actual_versions].dispatch_priority = priority;
34773       actual_versions++;
34774     }
34775
34776   /* Sort the versions according to descending order of dispatch priority.  The
34777      priority is based on the ISA.  This is not a perfect solution.  There
34778      could still be ambiguity.  If more than one function version is suitable
34779      to execute,  which one should be dispatched?  In future, allow the user
34780      to specify a dispatch  priority next to the version.  */
34781   qsort (function_version_info, actual_versions,
34782          sizeof (struct _function_version_info), feature_compare);
34783
34784   for  (i = 0; i < actual_versions; ++i)
34785     *empty_bb = add_condition_to_bb (dispatch_decl,
34786                                      function_version_info[i].version_decl,
34787                                      function_version_info[i].predicate_chain,
34788                                      *empty_bb);
34789
34790   /* dispatch default version at the end.  */
34791   *empty_bb = add_condition_to_bb (dispatch_decl, default_decl,
34792                                    NULL, *empty_bb);
34793
34794   free (function_version_info);
34795   return 0;
34796 }
34797
34798 /* Comparator function to be used in qsort routine to sort attribute
34799    specification strings to "target".  */
34800
34801 static int
34802 attr_strcmp (const void *v1, const void *v2)
34803 {
34804   const char *c1 = *(char *const*)v1;
34805   const char *c2 = *(char *const*)v2;
34806   return strcmp (c1, c2);
34807 }
34808
34809 /* ARGLIST is the argument to target attribute.  This function tokenizes
34810    the comma separated arguments, sorts them and returns a string which
34811    is a unique identifier for the comma separated arguments.   It also
34812    replaces non-identifier characters "=,-" with "_".  */
34813
34814 static char *
34815 sorted_attr_string (tree arglist)
34816 {
34817   tree arg;
34818   size_t str_len_sum = 0;
34819   char **args = NULL;
34820   char *attr_str, *ret_str;
34821   char *attr = NULL;
34822   unsigned int argnum = 1;
34823   unsigned int i;
34824
34825   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
34826     {
34827       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
34828       size_t len = strlen (str);
34829       str_len_sum += len + 1;
34830       if (arg != arglist)
34831         argnum++;
34832       for (i = 0; i < strlen (str); i++)
34833         if (str[i] == ',')
34834           argnum++;
34835     }
34836
34837   attr_str = XNEWVEC (char, str_len_sum);
34838   str_len_sum = 0;
34839   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
34840     {
34841       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
34842       size_t len = strlen (str);
34843       memcpy (attr_str + str_len_sum, str, len);
34844       attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0';
34845       str_len_sum += len + 1;
34846     }
34847
34848   /* Replace "=,-" with "_".  */
34849   for (i = 0; i < strlen (attr_str); i++)
34850     if (attr_str[i] == '=' || attr_str[i]== '-')
34851       attr_str[i] = '_';
34852
34853   if (argnum == 1)
34854     return attr_str;
34855
34856   args = XNEWVEC (char *, argnum);
34857
34858   i = 0;
34859   attr = strtok (attr_str, ",");
34860   while (attr != NULL)
34861     {
34862       args[i] = attr;
34863       i++;
34864       attr = strtok (NULL, ",");
34865     }
34866
34867   qsort (args, argnum, sizeof (char *), attr_strcmp);
34868
34869   ret_str = XNEWVEC (char, str_len_sum);
34870   str_len_sum = 0;
34871   for (i = 0; i < argnum; i++)
34872     {
34873       size_t len = strlen (args[i]);
34874       memcpy (ret_str + str_len_sum, args[i], len);
34875       ret_str[str_len_sum + len] = i < argnum - 1 ? '_' : '\0';
34876       str_len_sum += len + 1;
34877     }
34878
34879   XDELETEVEC (args);
34880   XDELETEVEC (attr_str);
34881   return ret_str;
34882 }
34883
34884 /* This function changes the assembler name for functions that are
34885    versions.  If DECL is a function version and has a "target"
34886    attribute, it appends the attribute string to its assembler name.  */
34887
34888 static tree
34889 ix86_mangle_function_version_assembler_name (tree decl, tree id)
34890 {
34891   tree version_attr;
34892   const char *orig_name, *version_string;
34893   char *attr_str, *assembler_name;
34894
34895   if (DECL_DECLARED_INLINE_P (decl)
34896       && lookup_attribute ("gnu_inline",
34897                            DECL_ATTRIBUTES (decl)))
34898     error_at (DECL_SOURCE_LOCATION (decl),
34899               "Function versions cannot be marked as gnu_inline,"
34900               " bodies have to be generated");
34901
34902   if (DECL_VIRTUAL_P (decl)
34903       || DECL_VINDEX (decl))
34904     sorry ("Virtual function multiversioning not supported");
34905
34906   version_attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34907
34908   /* target attribute string cannot be NULL.  */
34909   gcc_assert (version_attr != NULL_TREE);
34910
34911   orig_name = IDENTIFIER_POINTER (id);
34912   version_string
34913     = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (version_attr)));
34914
34915   if (strcmp (version_string, "default") == 0)
34916     return id;
34917
34918   attr_str = sorted_attr_string (TREE_VALUE (version_attr));
34919   assembler_name = XNEWVEC (char, strlen (orig_name) + strlen (attr_str) + 2);
34920
34921   sprintf (assembler_name, "%s.%s", orig_name, attr_str);
34922
34923   /* Allow assembler name to be modified if already set.  */
34924   if (DECL_ASSEMBLER_NAME_SET_P (decl))
34925     SET_DECL_RTL (decl, NULL);
34926
34927   tree ret = get_identifier (assembler_name);
34928   XDELETEVEC (attr_str);
34929   XDELETEVEC (assembler_name);
34930   return ret;
34931 }
34932
34933 /* This function returns true if FN1 and FN2 are versions of the same function,
34934    that is, the target strings of the function decls are different.  This assumes
34935    that FN1 and FN2 have the same signature.  */
34936
34937 static bool
34938 ix86_function_versions (tree fn1, tree fn2)
34939 {
34940   tree attr1, attr2;
34941   char *target1, *target2;
34942   bool result;
34943
34944   if (TREE_CODE (fn1) != FUNCTION_DECL
34945       || TREE_CODE (fn2) != FUNCTION_DECL)
34946     return false;
34947
34948   attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
34949   attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
34950
34951   /* At least one function decl should have the target attribute specified.  */
34952   if (attr1 == NULL_TREE && attr2 == NULL_TREE)
34953     return false;
34954
34955   /* Diagnose missing target attribute if one of the decls is already
34956      multi-versioned.  */
34957   if (attr1 == NULL_TREE || attr2 == NULL_TREE)
34958     {
34959       if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
34960         {
34961           if (attr2 != NULL_TREE)
34962             {
34963               tree tem = fn1;
34964               fn1 = fn2;
34965               fn2 = tem;
34966               attr1 = attr2;
34967             }
34968           error_at (DECL_SOURCE_LOCATION (fn2),
34969                     "missing %<target%> attribute for multi-versioned %D",
34970                     fn2);
34971           inform (DECL_SOURCE_LOCATION (fn1),
34972                   "previous declaration of %D", fn1);
34973           /* Prevent diagnosing of the same error multiple times.  */
34974           DECL_ATTRIBUTES (fn2)
34975             = tree_cons (get_identifier ("target"),
34976                          copy_node (TREE_VALUE (attr1)),
34977                          DECL_ATTRIBUTES (fn2));
34978         }
34979       return false;
34980     }
34981
34982   target1 = sorted_attr_string (TREE_VALUE (attr1));
34983   target2 = sorted_attr_string (TREE_VALUE (attr2));
34984
34985   /* The sorted target strings must be different for fn1 and fn2
34986      to be versions.  */
34987   if (strcmp (target1, target2) == 0)
34988     result = false;
34989   else
34990     result = true;
34991
34992   XDELETEVEC (target1);
34993   XDELETEVEC (target2); 
34994   
34995   return result;
34996 }
34997
34998 static tree 
34999 ix86_mangle_decl_assembler_name (tree decl, tree id)
35000 {
35001   /* For function version, add the target suffix to the assembler name.  */
35002   if (TREE_CODE (decl) == FUNCTION_DECL
35003       && DECL_FUNCTION_VERSIONED (decl))
35004     id = ix86_mangle_function_version_assembler_name (decl, id);
35005 #ifdef SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME
35006   id = SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME (decl, id);
35007 #endif
35008
35009   return id;
35010 }
35011
35012 /* Return a new name by appending SUFFIX to the DECL name.  If make_unique
35013    is true, append the full path name of the source file.  */
35014
35015 static char *
35016 make_name (tree decl, const char *suffix, bool make_unique)
35017 {
35018   char *global_var_name;
35019   int name_len;
35020   const char *name;
35021   const char *unique_name = NULL;
35022
35023   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
35024
35025   /* Get a unique name that can be used globally without any chances
35026      of collision at link time.  */
35027   if (make_unique)
35028     unique_name = IDENTIFIER_POINTER (get_file_function_name ("\0"));
35029
35030   name_len = strlen (name) + strlen (suffix) + 2;
35031
35032   if (make_unique)
35033     name_len += strlen (unique_name) + 1;
35034   global_var_name = XNEWVEC (char, name_len);
35035
35036   /* Use '.' to concatenate names as it is demangler friendly.  */
35037   if (make_unique)
35038     snprintf (global_var_name, name_len, "%s.%s.%s", name, unique_name,
35039               suffix);
35040   else
35041     snprintf (global_var_name, name_len, "%s.%s", name, suffix);
35042
35043   return global_var_name;
35044 }
35045
35046 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
35047
35048 /* Make a dispatcher declaration for the multi-versioned function DECL.
35049    Calls to DECL function will be replaced with calls to the dispatcher
35050    by the front-end.  Return the decl created.  */
35051
35052 static tree
35053 make_dispatcher_decl (const tree decl)
35054 {
35055   tree func_decl;
35056   char *func_name;
35057   tree fn_type, func_type;
35058   bool is_uniq = false;
35059
35060   if (TREE_PUBLIC (decl) == 0)
35061     is_uniq = true;
35062
35063   func_name = make_name (decl, "ifunc", is_uniq);
35064
35065   fn_type = TREE_TYPE (decl);
35066   func_type = build_function_type (TREE_TYPE (fn_type),
35067                                    TYPE_ARG_TYPES (fn_type));
35068   
35069   func_decl = build_fn_decl (func_name, func_type);
35070   XDELETEVEC (func_name);
35071   TREE_USED (func_decl) = 1;
35072   DECL_CONTEXT (func_decl) = NULL_TREE;
35073   DECL_INITIAL (func_decl) = error_mark_node;
35074   DECL_ARTIFICIAL (func_decl) = 1;
35075   /* Mark this func as external, the resolver will flip it again if
35076      it gets generated.  */
35077   DECL_EXTERNAL (func_decl) = 1;
35078   /* This will be of type IFUNCs have to be externally visible.  */
35079   TREE_PUBLIC (func_decl) = 1;
35080
35081   return func_decl;  
35082 }
35083
35084 #endif
35085
35086 /* Returns true if decl is multi-versioned and DECL is the default function,
35087    that is it is not tagged with target specific optimization.  */
35088
35089 static bool
35090 is_function_default_version (const tree decl)
35091 {
35092   if (TREE_CODE (decl) != FUNCTION_DECL
35093       || !DECL_FUNCTION_VERSIONED (decl))
35094     return false;
35095   tree attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
35096   gcc_assert (attr);
35097   attr = TREE_VALUE (TREE_VALUE (attr));
35098   return (TREE_CODE (attr) == STRING_CST
35099           && strcmp (TREE_STRING_POINTER (attr), "default") == 0);
35100 }
35101
35102 /* Make a dispatcher declaration for the multi-versioned function DECL.
35103    Calls to DECL function will be replaced with calls to the dispatcher
35104    by the front-end.  Returns the decl of the dispatcher function.  */
35105
35106 static tree
35107 ix86_get_function_versions_dispatcher (void *decl)
35108 {
35109   tree fn = (tree) decl;
35110   struct cgraph_node *node = NULL;
35111   struct cgraph_node *default_node = NULL;
35112   struct cgraph_function_version_info *node_v = NULL;
35113   struct cgraph_function_version_info *first_v = NULL;
35114
35115   tree dispatch_decl = NULL;
35116
35117   struct cgraph_function_version_info *default_version_info = NULL;
35118  
35119   gcc_assert (fn != NULL && DECL_FUNCTION_VERSIONED (fn));
35120
35121   node = cgraph_node::get (fn);
35122   gcc_assert (node != NULL);
35123
35124   node_v = node->function_version ();
35125   gcc_assert (node_v != NULL);
35126  
35127   if (node_v->dispatcher_resolver != NULL)
35128     return node_v->dispatcher_resolver;
35129
35130   /* Find the default version and make it the first node.  */
35131   first_v = node_v;
35132   /* Go to the beginning of the chain.  */
35133   while (first_v->prev != NULL)
35134     first_v = first_v->prev;
35135   default_version_info = first_v;
35136   while (default_version_info != NULL)
35137     {
35138       if (is_function_default_version
35139             (default_version_info->this_node->decl))
35140         break;
35141       default_version_info = default_version_info->next;
35142     }
35143
35144   /* If there is no default node, just return NULL.  */
35145   if (default_version_info == NULL)
35146     return NULL;
35147
35148   /* Make default info the first node.  */
35149   if (first_v != default_version_info)
35150     {
35151       default_version_info->prev->next = default_version_info->next;
35152       if (default_version_info->next)
35153         default_version_info->next->prev = default_version_info->prev;
35154       first_v->prev = default_version_info;
35155       default_version_info->next = first_v;
35156       default_version_info->prev = NULL;
35157     }
35158
35159   default_node = default_version_info->this_node;
35160
35161 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
35162   if (targetm.has_ifunc_p ())
35163     {
35164       struct cgraph_function_version_info *it_v = NULL;
35165       struct cgraph_node *dispatcher_node = NULL;
35166       struct cgraph_function_version_info *dispatcher_version_info = NULL;
35167
35168       /* Right now, the dispatching is done via ifunc.  */
35169       dispatch_decl = make_dispatcher_decl (default_node->decl);
35170
35171       dispatcher_node = cgraph_node::get_create (dispatch_decl);
35172       gcc_assert (dispatcher_node != NULL);
35173       dispatcher_node->dispatcher_function = 1;
35174       dispatcher_version_info
35175         = dispatcher_node->insert_new_function_version ();
35176       dispatcher_version_info->next = default_version_info;
35177       dispatcher_node->definition = 1;
35178
35179       /* Set the dispatcher for all the versions.  */
35180       it_v = default_version_info;
35181       while (it_v != NULL)
35182         {
35183           it_v->dispatcher_resolver = dispatch_decl;
35184           it_v = it_v->next;
35185         }
35186     }
35187   else
35188 #endif
35189     {
35190       error_at (DECL_SOURCE_LOCATION (default_node->decl),
35191                 "multiversioning needs ifunc which is not supported "
35192                 "on this target");
35193     }
35194
35195   return dispatch_decl;
35196 }
35197
35198 /* Makes a function attribute of the form NAME(ARG_NAME) and chains
35199    it to CHAIN.  */
35200
35201 static tree
35202 make_attribute (const char *name, const char *arg_name, tree chain)
35203 {
35204   tree attr_name;
35205   tree attr_arg_name;
35206   tree attr_args;
35207   tree attr;
35208
35209   attr_name = get_identifier (name);
35210   attr_arg_name = build_string (strlen (arg_name), arg_name);
35211   attr_args = tree_cons (NULL_TREE, attr_arg_name, NULL_TREE);
35212   attr = tree_cons (attr_name, attr_args, chain);
35213   return attr;
35214 }
35215
35216 /* Make the resolver function decl to dispatch the versions of
35217    a multi-versioned function,  DEFAULT_DECL.  Create an
35218    empty basic block in the resolver and store the pointer in
35219    EMPTY_BB.  Return the decl of the resolver function.  */
35220
35221 static tree
35222 make_resolver_func (const tree default_decl,
35223                     const tree dispatch_decl,
35224                     basic_block *empty_bb)
35225 {
35226   char *resolver_name;
35227   tree decl, type, decl_name, t;
35228   bool is_uniq = false;
35229
35230   /* IFUNC's have to be globally visible.  So, if the default_decl is
35231      not, then the name of the IFUNC should be made unique.  */
35232   if (TREE_PUBLIC (default_decl) == 0)
35233     is_uniq = true;
35234
35235   /* Append the filename to the resolver function if the versions are
35236      not externally visible.  This is because the resolver function has
35237      to be externally visible for the loader to find it.  So, appending
35238      the filename will prevent conflicts with a resolver function from
35239      another module which is based on the same version name.  */
35240   resolver_name = make_name (default_decl, "resolver", is_uniq);
35241
35242   /* The resolver function should return a (void *). */
35243   type = build_function_type_list (ptr_type_node, NULL_TREE);
35244
35245   decl = build_fn_decl (resolver_name, type);
35246   decl_name = get_identifier (resolver_name);
35247   SET_DECL_ASSEMBLER_NAME (decl, decl_name);
35248
35249   DECL_NAME (decl) = decl_name;
35250   TREE_USED (decl) = 1;
35251   DECL_ARTIFICIAL (decl) = 1;
35252   DECL_IGNORED_P (decl) = 0;
35253   /* IFUNC resolvers have to be externally visible.  */
35254   TREE_PUBLIC (decl) = 1;
35255   DECL_UNINLINABLE (decl) = 1;
35256
35257   /* Resolver is not external, body is generated.  */
35258   DECL_EXTERNAL (decl) = 0;
35259   DECL_EXTERNAL (dispatch_decl) = 0;
35260
35261   DECL_CONTEXT (decl) = NULL_TREE;
35262   DECL_INITIAL (decl) = make_node (BLOCK);
35263   DECL_STATIC_CONSTRUCTOR (decl) = 0;
35264
35265   if (DECL_COMDAT_GROUP (default_decl)
35266       || TREE_PUBLIC (default_decl))
35267     {
35268       /* In this case, each translation unit with a call to this
35269          versioned function will put out a resolver.  Ensure it
35270          is comdat to keep just one copy.  */
35271       DECL_COMDAT (decl) = 1;
35272       make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
35273     }
35274   /* Build result decl and add to function_decl. */
35275   t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node);
35276   DECL_ARTIFICIAL (t) = 1;
35277   DECL_IGNORED_P (t) = 1;
35278   DECL_RESULT (decl) = t;
35279
35280   gimplify_function_tree (decl);
35281   push_cfun (DECL_STRUCT_FUNCTION (decl));
35282   *empty_bb = init_lowered_empty_function (decl, false, 0);
35283
35284   cgraph_node::add_new_function (decl, true);
35285   symtab->call_cgraph_insertion_hooks (cgraph_node::get_create (decl));
35286
35287   pop_cfun ();
35288
35289   gcc_assert (dispatch_decl != NULL);
35290   /* Mark dispatch_decl as "ifunc" with resolver as resolver_name.  */
35291   DECL_ATTRIBUTES (dispatch_decl) 
35292     = make_attribute ("ifunc", resolver_name, DECL_ATTRIBUTES (dispatch_decl));
35293
35294   /* Create the alias for dispatch to resolver here.  */
35295   /*cgraph_create_function_alias (dispatch_decl, decl);*/
35296   cgraph_node::create_same_body_alias (dispatch_decl, decl);
35297   XDELETEVEC (resolver_name);
35298   return decl;
35299 }
35300
35301 /* Generate the dispatching code body to dispatch multi-versioned function
35302    DECL.  The target hook is called to process the "target" attributes and
35303    provide the code to dispatch the right function at run-time.  NODE points
35304    to the dispatcher decl whose body will be created.  */
35305
35306 static tree 
35307 ix86_generate_version_dispatcher_body (void *node_p)
35308 {
35309   tree resolver_decl;
35310   basic_block empty_bb;
35311   tree default_ver_decl;
35312   struct cgraph_node *versn;
35313   struct cgraph_node *node;
35314
35315   struct cgraph_function_version_info *node_version_info = NULL;
35316   struct cgraph_function_version_info *versn_info = NULL;
35317
35318   node = (cgraph_node *)node_p;
35319
35320   node_version_info = node->function_version ();
35321   gcc_assert (node->dispatcher_function
35322               && node_version_info != NULL);
35323
35324   if (node_version_info->dispatcher_resolver)
35325     return node_version_info->dispatcher_resolver;
35326
35327   /* The first version in the chain corresponds to the default version.  */
35328   default_ver_decl = node_version_info->next->this_node->decl;
35329
35330   /* node is going to be an alias, so remove the finalized bit.  */
35331   node->definition = false;
35332
35333   resolver_decl = make_resolver_func (default_ver_decl,
35334                                       node->decl, &empty_bb);
35335
35336   node_version_info->dispatcher_resolver = resolver_decl;
35337
35338   push_cfun (DECL_STRUCT_FUNCTION (resolver_decl));
35339
35340   auto_vec<tree, 2> fn_ver_vec;
35341
35342   for (versn_info = node_version_info->next; versn_info;
35343        versn_info = versn_info->next)
35344     {
35345       versn = versn_info->this_node;
35346       /* Check for virtual functions here again, as by this time it should
35347          have been determined if this function needs a vtable index or
35348          not.  This happens for methods in derived classes that override
35349          virtual methods in base classes but are not explicitly marked as
35350          virtual.  */
35351       if (DECL_VINDEX (versn->decl))
35352         sorry ("Virtual function multiversioning not supported");
35353
35354       fn_ver_vec.safe_push (versn->decl);
35355     }
35356
35357   dispatch_function_versions (resolver_decl, &fn_ver_vec, &empty_bb);
35358   cgraph_edge::rebuild_edges ();
35359   pop_cfun ();
35360   return resolver_decl;
35361 }
35362 /* This builds the processor_model struct type defined in
35363    libgcc/config/i386/cpuinfo.c  */
35364
35365 static tree
35366 build_processor_model_struct (void)
35367 {
35368   const char *field_name[] = {"__cpu_vendor", "__cpu_type", "__cpu_subtype",
35369                               "__cpu_features"};
35370   tree field = NULL_TREE, field_chain = NULL_TREE;
35371   int i;
35372   tree type = make_node (RECORD_TYPE);
35373
35374   /* The first 3 fields are unsigned int.  */
35375   for (i = 0; i < 3; ++i)
35376     {
35377       field = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
35378                           get_identifier (field_name[i]), unsigned_type_node);
35379       if (field_chain != NULL_TREE)
35380         DECL_CHAIN (field) = field_chain;
35381       field_chain = field;
35382     }
35383
35384   /* The last field is an array of unsigned integers of size one.  */
35385   field = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
35386                       get_identifier (field_name[3]),
35387                       build_array_type (unsigned_type_node,
35388                                         build_index_type (size_one_node)));
35389   if (field_chain != NULL_TREE)
35390     DECL_CHAIN (field) = field_chain;
35391   field_chain = field;
35392
35393   finish_builtin_struct (type, "__processor_model", field_chain, NULL_TREE);
35394   return type;
35395 }
35396
35397 /* Returns a extern, comdat VAR_DECL of type TYPE and name NAME. */
35398
35399 static tree
35400 make_var_decl (tree type, const char *name)
35401 {
35402   tree new_decl;
35403
35404   new_decl = build_decl (UNKNOWN_LOCATION,
35405                          VAR_DECL,
35406                          get_identifier(name),
35407                          type);
35408
35409   DECL_EXTERNAL (new_decl) = 1;
35410   TREE_STATIC (new_decl) = 1;
35411   TREE_PUBLIC (new_decl) = 1;
35412   DECL_INITIAL (new_decl) = 0;
35413   DECL_ARTIFICIAL (new_decl) = 0;
35414   DECL_PRESERVE_P (new_decl) = 1;
35415
35416   make_decl_one_only (new_decl, DECL_ASSEMBLER_NAME (new_decl));
35417   assemble_variable (new_decl, 0, 0, 0);
35418
35419   return new_decl;
35420 }
35421
35422 /* FNDECL is a __builtin_cpu_is or a __builtin_cpu_supports call that is folded
35423    into an integer defined in libgcc/config/i386/cpuinfo.c */
35424
35425 static tree
35426 fold_builtin_cpu (tree fndecl, tree *args)
35427 {
35428   unsigned int i;
35429   enum ix86_builtins fn_code = (enum ix86_builtins)
35430                                 DECL_FUNCTION_CODE (fndecl);
35431   tree param_string_cst = NULL;
35432
35433   /* This is the order of bit-fields in __processor_features in cpuinfo.c */
35434   enum processor_features
35435   {
35436     F_CMOV = 0,
35437     F_MMX,
35438     F_POPCNT,
35439     F_SSE,
35440     F_SSE2,
35441     F_SSE3,
35442     F_SSSE3,
35443     F_SSE4_1,
35444     F_SSE4_2,
35445     F_AVX,
35446     F_AVX2,
35447     F_SSE4_A,
35448     F_FMA4,
35449     F_XOP,
35450     F_FMA,
35451     F_AVX512F,
35452     F_BMI,
35453     F_BMI2,
35454     F_MAX
35455   };
35456
35457   /* These are the values for vendor types and cpu types  and subtypes
35458      in cpuinfo.c.  Cpu types and subtypes should be subtracted by
35459      the corresponding start value.  */
35460   enum processor_model
35461   {
35462     M_INTEL = 1,
35463     M_AMD,
35464     M_CPU_TYPE_START,
35465     M_INTEL_BONNELL,
35466     M_INTEL_CORE2,
35467     M_INTEL_COREI7,
35468     M_AMDFAM10H,
35469     M_AMDFAM15H,
35470     M_INTEL_SILVERMONT,
35471     M_INTEL_KNL,
35472     M_AMD_BTVER1,
35473     M_AMD_BTVER2,    
35474     M_CPU_SUBTYPE_START,
35475     M_INTEL_COREI7_NEHALEM,
35476     M_INTEL_COREI7_WESTMERE,
35477     M_INTEL_COREI7_SANDYBRIDGE,
35478     M_AMDFAM10H_BARCELONA,
35479     M_AMDFAM10H_SHANGHAI,
35480     M_AMDFAM10H_ISTANBUL,
35481     M_AMDFAM15H_BDVER1,
35482     M_AMDFAM15H_BDVER2,
35483     M_AMDFAM15H_BDVER3,
35484     M_AMDFAM15H_BDVER4,
35485     M_INTEL_COREI7_IVYBRIDGE,
35486     M_INTEL_COREI7_HASWELL,
35487     M_INTEL_COREI7_BROADWELL
35488   };
35489
35490   static struct _arch_names_table
35491     {
35492       const char *const name;
35493       const enum processor_model model;
35494     }
35495   const arch_names_table[] =
35496     {
35497       {"amd", M_AMD},
35498       {"intel", M_INTEL},
35499       {"atom", M_INTEL_BONNELL},
35500       {"slm", M_INTEL_SILVERMONT},
35501       {"core2", M_INTEL_CORE2},
35502       {"corei7", M_INTEL_COREI7},
35503       {"nehalem", M_INTEL_COREI7_NEHALEM},
35504       {"westmere", M_INTEL_COREI7_WESTMERE},
35505       {"sandybridge", M_INTEL_COREI7_SANDYBRIDGE},
35506       {"ivybridge", M_INTEL_COREI7_IVYBRIDGE},
35507       {"haswell", M_INTEL_COREI7_HASWELL},
35508       {"broadwell", M_INTEL_COREI7_BROADWELL},
35509       {"bonnell", M_INTEL_BONNELL},
35510       {"silvermont", M_INTEL_SILVERMONT},
35511       {"knl", M_INTEL_KNL},
35512       {"amdfam10h", M_AMDFAM10H},
35513       {"barcelona", M_AMDFAM10H_BARCELONA},
35514       {"shanghai", M_AMDFAM10H_SHANGHAI},
35515       {"istanbul", M_AMDFAM10H_ISTANBUL},
35516       {"btver1", M_AMD_BTVER1},      
35517       {"amdfam15h", M_AMDFAM15H},
35518       {"bdver1", M_AMDFAM15H_BDVER1},
35519       {"bdver2", M_AMDFAM15H_BDVER2},
35520       {"bdver3", M_AMDFAM15H_BDVER3},
35521       {"bdver4", M_AMDFAM15H_BDVER4},
35522       {"btver2", M_AMD_BTVER2},      
35523     };
35524
35525   static struct _isa_names_table
35526     {
35527       const char *const name;
35528       const enum processor_features feature;
35529     }
35530   const isa_names_table[] =
35531     {
35532       {"cmov",   F_CMOV},
35533       {"mmx",    F_MMX},
35534       {"popcnt", F_POPCNT},
35535       {"sse",    F_SSE},
35536       {"sse2",   F_SSE2},
35537       {"sse3",   F_SSE3},
35538       {"ssse3",  F_SSSE3},
35539       {"sse4a",  F_SSE4_A},
35540       {"sse4.1", F_SSE4_1},
35541       {"sse4.2", F_SSE4_2},
35542       {"avx",    F_AVX},
35543       {"fma4",   F_FMA4},
35544       {"xop",    F_XOP},
35545       {"fma",    F_FMA},
35546       {"avx2",   F_AVX2},
35547       {"avx512f",F_AVX512F},
35548       {"bmi",    F_BMI},
35549       {"bmi2",   F_BMI2}
35550     };
35551
35552   tree __processor_model_type = build_processor_model_struct ();
35553   tree __cpu_model_var = make_var_decl (__processor_model_type,
35554                                         "__cpu_model");
35555
35556
35557   varpool_node::add (__cpu_model_var);
35558
35559   gcc_assert ((args != NULL) && (*args != NULL));
35560
35561   param_string_cst = *args;
35562   while (param_string_cst
35563          && TREE_CODE (param_string_cst) !=  STRING_CST)
35564     {
35565       /* *args must be a expr that can contain other EXPRS leading to a
35566          STRING_CST.   */
35567       if (!EXPR_P (param_string_cst))
35568         {
35569           error ("Parameter to builtin must be a string constant or literal");
35570           return integer_zero_node;
35571         }
35572       param_string_cst = TREE_OPERAND (EXPR_CHECK (param_string_cst), 0);
35573     }
35574
35575   gcc_assert (param_string_cst);
35576
35577   if (fn_code == IX86_BUILTIN_CPU_IS)
35578     {
35579       tree ref;
35580       tree field;
35581       tree final;
35582
35583       unsigned int field_val = 0;
35584       unsigned int NUM_ARCH_NAMES
35585         = sizeof (arch_names_table) / sizeof (struct _arch_names_table);
35586
35587       for (i = 0; i < NUM_ARCH_NAMES; i++)
35588         if (strcmp (arch_names_table[i].name,
35589             TREE_STRING_POINTER (param_string_cst)) == 0)
35590           break;
35591
35592       if (i == NUM_ARCH_NAMES)
35593         {
35594           error ("Parameter to builtin not valid: %s",
35595                  TREE_STRING_POINTER (param_string_cst));
35596           return integer_zero_node;
35597         }
35598
35599       field = TYPE_FIELDS (__processor_model_type);
35600       field_val = arch_names_table[i].model;
35601
35602       /* CPU types are stored in the next field.  */
35603       if (field_val > M_CPU_TYPE_START
35604           && field_val < M_CPU_SUBTYPE_START)
35605         {
35606           field = DECL_CHAIN (field);
35607           field_val -= M_CPU_TYPE_START;
35608         }
35609
35610       /* CPU subtypes are stored in the next field.  */
35611       if (field_val > M_CPU_SUBTYPE_START)
35612         {
35613           field = DECL_CHAIN ( DECL_CHAIN (field));
35614           field_val -= M_CPU_SUBTYPE_START;
35615         }
35616
35617       /* Get the appropriate field in __cpu_model.  */
35618       ref =  build3 (COMPONENT_REF, TREE_TYPE (field), __cpu_model_var,
35619                      field, NULL_TREE);
35620
35621       /* Check the value.  */
35622       final = build2 (EQ_EXPR, unsigned_type_node, ref,
35623                       build_int_cstu (unsigned_type_node, field_val));
35624       return build1 (CONVERT_EXPR, integer_type_node, final);
35625     }
35626   else if (fn_code == IX86_BUILTIN_CPU_SUPPORTS)
35627     {
35628       tree ref;
35629       tree array_elt;
35630       tree field;
35631       tree final;
35632
35633       unsigned int field_val = 0;
35634       unsigned int NUM_ISA_NAMES
35635         = sizeof (isa_names_table) / sizeof (struct _isa_names_table);
35636
35637       for (i = 0; i < NUM_ISA_NAMES; i++)
35638         if (strcmp (isa_names_table[i].name,
35639             TREE_STRING_POINTER (param_string_cst)) == 0)
35640           break;
35641
35642       if (i == NUM_ISA_NAMES)
35643         {
35644           error ("Parameter to builtin not valid: %s",
35645                  TREE_STRING_POINTER (param_string_cst));
35646           return integer_zero_node;
35647         }
35648
35649       field = TYPE_FIELDS (__processor_model_type);
35650       /* Get the last field, which is __cpu_features.  */
35651       while (DECL_CHAIN (field))
35652         field = DECL_CHAIN (field);
35653
35654       /* Get the appropriate field: __cpu_model.__cpu_features  */
35655       ref =  build3 (COMPONENT_REF, TREE_TYPE (field), __cpu_model_var,
35656                      field, NULL_TREE);
35657
35658       /* Access the 0th element of __cpu_features array.  */
35659       array_elt = build4 (ARRAY_REF, unsigned_type_node, ref,
35660                           integer_zero_node, NULL_TREE, NULL_TREE);
35661
35662       field_val = (1 << isa_names_table[i].feature);
35663       /* Return __cpu_model.__cpu_features[0] & field_val  */
35664       final = build2 (BIT_AND_EXPR, unsigned_type_node, array_elt,
35665                       build_int_cstu (unsigned_type_node, field_val));
35666       return build1 (CONVERT_EXPR, integer_type_node, final);
35667     }
35668   gcc_unreachable ();
35669 }
35670
35671 static tree
35672 ix86_fold_builtin (tree fndecl, int n_args,
35673                    tree *args, bool ignore ATTRIBUTE_UNUSED)
35674 {
35675   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
35676     {
35677       enum ix86_builtins fn_code = (enum ix86_builtins)
35678                                    DECL_FUNCTION_CODE (fndecl);
35679       if (fn_code ==  IX86_BUILTIN_CPU_IS
35680           || fn_code == IX86_BUILTIN_CPU_SUPPORTS)
35681         {
35682           gcc_assert (n_args == 1);
35683           return fold_builtin_cpu (fndecl, args);
35684         }
35685     }
35686
35687 #ifdef SUBTARGET_FOLD_BUILTIN
35688   return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore);
35689 #endif
35690
35691   return NULL_TREE;
35692 }
35693
35694 /* Make builtins to detect cpu type and features supported.  NAME is
35695    the builtin name, CODE is the builtin code, and FTYPE is the function
35696    type of the builtin.  */
35697
35698 static void
35699 make_cpu_type_builtin (const char* name, int code,
35700                        enum ix86_builtin_func_type ftype, bool is_const)
35701 {
35702   tree decl;
35703   tree type;
35704
35705   type = ix86_get_builtin_func_type (ftype);
35706   decl = add_builtin_function (name, type, code, BUILT_IN_MD,
35707                                NULL, NULL_TREE);
35708   gcc_assert (decl != NULL_TREE);
35709   ix86_builtins[(int) code] = decl;
35710   TREE_READONLY (decl) = is_const;
35711 }
35712
35713 /* Make builtins to get CPU type and features supported.  The created
35714    builtins are :
35715
35716    __builtin_cpu_init (), to detect cpu type and features,
35717    __builtin_cpu_is ("<CPUNAME>"), to check if cpu is of type <CPUNAME>,
35718    __builtin_cpu_supports ("<FEATURE>"), to check if cpu supports <FEATURE>
35719    */
35720
35721 static void
35722 ix86_init_platform_type_builtins (void)
35723 {
35724   make_cpu_type_builtin ("__builtin_cpu_init", IX86_BUILTIN_CPU_INIT,
35725                          INT_FTYPE_VOID, false);
35726   make_cpu_type_builtin ("__builtin_cpu_is", IX86_BUILTIN_CPU_IS,
35727                          INT_FTYPE_PCCHAR, true);
35728   make_cpu_type_builtin ("__builtin_cpu_supports", IX86_BUILTIN_CPU_SUPPORTS,
35729                          INT_FTYPE_PCCHAR, true);
35730 }
35731
35732 /* Internal method for ix86_init_builtins.  */
35733
35734 static void
35735 ix86_init_builtins_va_builtins_abi (void)
35736 {
35737   tree ms_va_ref, sysv_va_ref;
35738   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
35739   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
35740   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
35741   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
35742
35743   if (!TARGET_64BIT)
35744     return;
35745   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
35746   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
35747   ms_va_ref = build_reference_type (ms_va_list_type_node);
35748   sysv_va_ref =
35749     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
35750
35751   fnvoid_va_end_ms =
35752     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
35753   fnvoid_va_start_ms =
35754     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
35755   fnvoid_va_end_sysv =
35756     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
35757   fnvoid_va_start_sysv =
35758     build_varargs_function_type_list (void_type_node, sysv_va_ref,
35759                                        NULL_TREE);
35760   fnvoid_va_copy_ms =
35761     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
35762                               NULL_TREE);
35763   fnvoid_va_copy_sysv =
35764     build_function_type_list (void_type_node, sysv_va_ref,
35765                               sysv_va_ref, NULL_TREE);
35766
35767   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
35768                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
35769   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
35770                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
35771   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
35772                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
35773   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
35774                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35775   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
35776                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35777   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
35778                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35779 }
35780
35781 static void
35782 ix86_init_builtin_types (void)
35783 {
35784   tree float128_type_node, float80_type_node;
35785
35786   /* The __float80 type.  */
35787   float80_type_node = long_double_type_node;
35788   if (TYPE_MODE (float80_type_node) != XFmode)
35789     {
35790       /* The __float80 type.  */
35791       float80_type_node = make_node (REAL_TYPE);
35792
35793       TYPE_PRECISION (float80_type_node) = 80;
35794       layout_type (float80_type_node);
35795     }
35796   lang_hooks.types.register_builtin_type (float80_type_node, "__float80");
35797
35798   /* The __float128 type.  */
35799   float128_type_node = make_node (REAL_TYPE);
35800   TYPE_PRECISION (float128_type_node) = 128;
35801   layout_type (float128_type_node);
35802   lang_hooks.types.register_builtin_type (float128_type_node, "__float128");
35803
35804   /* This macro is built by i386-builtin-types.awk.  */
35805   DEFINE_BUILTIN_PRIMITIVE_TYPES;
35806 }
35807
35808 static void
35809 ix86_init_builtins (void)
35810 {
35811   tree t;
35812
35813   ix86_init_builtin_types ();
35814
35815   /* Builtins to get CPU type and features. */
35816   ix86_init_platform_type_builtins ();
35817
35818   /* TFmode support builtins.  */
35819   def_builtin_const (0, "__builtin_infq",
35820                      FLOAT128_FTYPE_VOID, IX86_BUILTIN_INFQ);
35821   def_builtin_const (0, "__builtin_huge_valq",
35822                      FLOAT128_FTYPE_VOID, IX86_BUILTIN_HUGE_VALQ);
35823
35824   /* We will expand them to normal call if SSE isn't available since
35825      they are used by libgcc. */
35826   t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128);
35827   t = add_builtin_function ("__builtin_fabsq", t, IX86_BUILTIN_FABSQ,
35828                             BUILT_IN_MD, "__fabstf2", NULL_TREE);
35829   TREE_READONLY (t) = 1;
35830   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = t;
35831
35832   t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128_FLOAT128);
35833   t = add_builtin_function ("__builtin_copysignq", t, IX86_BUILTIN_COPYSIGNQ,
35834                             BUILT_IN_MD, "__copysigntf3", NULL_TREE);
35835   TREE_READONLY (t) = 1;
35836   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = t;
35837
35838   ix86_init_tm_builtins ();
35839   ix86_init_mmx_sse_builtins ();
35840   ix86_init_mpx_builtins ();
35841
35842   if (TARGET_LP64)
35843     ix86_init_builtins_va_builtins_abi ();
35844
35845 #ifdef SUBTARGET_INIT_BUILTINS
35846   SUBTARGET_INIT_BUILTINS;
35847 #endif
35848 }
35849
35850 /* Return the ix86 builtin for CODE.  */
35851
35852 static tree
35853 ix86_builtin_decl (unsigned code, bool)
35854 {
35855   if (code >= IX86_BUILTIN_MAX)
35856     return error_mark_node;
35857
35858   return ix86_builtins[code];
35859 }
35860
35861 /* Errors in the source file can cause expand_expr to return const0_rtx
35862    where we expect a vector.  To avoid crashing, use one of the vector
35863    clear instructions.  */
35864 static rtx
35865 safe_vector_operand (rtx x, machine_mode mode)
35866 {
35867   if (x == const0_rtx)
35868     x = CONST0_RTX (mode);
35869   return x;
35870 }
35871
35872 /* Fixup modeless constants to fit required mode.  */
35873 static rtx
35874 fixup_modeless_constant (rtx x, machine_mode mode)
35875 {
35876   if (GET_MODE (x) == VOIDmode)
35877     x = convert_to_mode (mode, x, 1);
35878   return x;
35879 }
35880
35881 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
35882
35883 static rtx
35884 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
35885 {
35886   rtx pat;
35887   tree arg0 = CALL_EXPR_ARG (exp, 0);
35888   tree arg1 = CALL_EXPR_ARG (exp, 1);
35889   rtx op0 = expand_normal (arg0);
35890   rtx op1 = expand_normal (arg1);
35891   machine_mode tmode = insn_data[icode].operand[0].mode;
35892   machine_mode mode0 = insn_data[icode].operand[1].mode;
35893   machine_mode mode1 = insn_data[icode].operand[2].mode;
35894
35895   if (VECTOR_MODE_P (mode0))
35896     op0 = safe_vector_operand (op0, mode0);
35897   if (VECTOR_MODE_P (mode1))
35898     op1 = safe_vector_operand (op1, mode1);
35899
35900   if (optimize || !target
35901       || GET_MODE (target) != tmode
35902       || !insn_data[icode].operand[0].predicate (target, tmode))
35903     target = gen_reg_rtx (tmode);
35904
35905   if (GET_MODE (op1) == SImode && mode1 == TImode)
35906     {
35907       rtx x = gen_reg_rtx (V4SImode);
35908       emit_insn (gen_sse2_loadd (x, op1));
35909       op1 = gen_lowpart (TImode, x);
35910     }
35911
35912   if (!insn_data[icode].operand[1].predicate (op0, mode0))
35913     op0 = copy_to_mode_reg (mode0, op0);
35914   if (!insn_data[icode].operand[2].predicate (op1, mode1))
35915     op1 = copy_to_mode_reg (mode1, op1);
35916
35917   pat = GEN_FCN (icode) (target, op0, op1);
35918   if (! pat)
35919     return 0;
35920
35921   emit_insn (pat);
35922
35923   return target;
35924 }
35925
35926 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
35927
35928 static rtx
35929 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
35930                                enum ix86_builtin_func_type m_type,
35931                                enum rtx_code sub_code)
35932 {
35933   rtx pat;
35934   int i;
35935   int nargs;
35936   bool comparison_p = false;
35937   bool tf_p = false;
35938   bool last_arg_constant = false;
35939   int num_memory = 0;
35940   struct {
35941     rtx op;
35942     machine_mode mode;
35943   } args[4];
35944
35945   machine_mode tmode = insn_data[icode].operand[0].mode;
35946
35947   switch (m_type)
35948     {
35949     case MULTI_ARG_4_DF2_DI_I:
35950     case MULTI_ARG_4_DF2_DI_I1:
35951     case MULTI_ARG_4_SF2_SI_I:
35952     case MULTI_ARG_4_SF2_SI_I1:
35953       nargs = 4;
35954       last_arg_constant = true;
35955       break;
35956
35957     case MULTI_ARG_3_SF:
35958     case MULTI_ARG_3_DF:
35959     case MULTI_ARG_3_SF2:
35960     case MULTI_ARG_3_DF2:
35961     case MULTI_ARG_3_DI:
35962     case MULTI_ARG_3_SI:
35963     case MULTI_ARG_3_SI_DI:
35964     case MULTI_ARG_3_HI:
35965     case MULTI_ARG_3_HI_SI:
35966     case MULTI_ARG_3_QI:
35967     case MULTI_ARG_3_DI2:
35968     case MULTI_ARG_3_SI2:
35969     case MULTI_ARG_3_HI2:
35970     case MULTI_ARG_3_QI2:
35971       nargs = 3;
35972       break;
35973
35974     case MULTI_ARG_2_SF:
35975     case MULTI_ARG_2_DF:
35976     case MULTI_ARG_2_DI:
35977     case MULTI_ARG_2_SI:
35978     case MULTI_ARG_2_HI:
35979     case MULTI_ARG_2_QI:
35980       nargs = 2;
35981       break;
35982
35983     case MULTI_ARG_2_DI_IMM:
35984     case MULTI_ARG_2_SI_IMM:
35985     case MULTI_ARG_2_HI_IMM:
35986     case MULTI_ARG_2_QI_IMM:
35987       nargs = 2;
35988       last_arg_constant = true;
35989       break;
35990
35991     case MULTI_ARG_1_SF:
35992     case MULTI_ARG_1_DF:
35993     case MULTI_ARG_1_SF2:
35994     case MULTI_ARG_1_DF2:
35995     case MULTI_ARG_1_DI:
35996     case MULTI_ARG_1_SI:
35997     case MULTI_ARG_1_HI:
35998     case MULTI_ARG_1_QI:
35999     case MULTI_ARG_1_SI_DI:
36000     case MULTI_ARG_1_HI_DI:
36001     case MULTI_ARG_1_HI_SI:
36002     case MULTI_ARG_1_QI_DI:
36003     case MULTI_ARG_1_QI_SI:
36004     case MULTI_ARG_1_QI_HI:
36005       nargs = 1;
36006       break;
36007
36008     case MULTI_ARG_2_DI_CMP:
36009     case MULTI_ARG_2_SI_CMP:
36010     case MULTI_ARG_2_HI_CMP:
36011     case MULTI_ARG_2_QI_CMP:
36012       nargs = 2;
36013       comparison_p = true;
36014       break;
36015
36016     case MULTI_ARG_2_SF_TF:
36017     case MULTI_ARG_2_DF_TF:
36018     case MULTI_ARG_2_DI_TF:
36019     case MULTI_ARG_2_SI_TF:
36020     case MULTI_ARG_2_HI_TF:
36021     case MULTI_ARG_2_QI_TF:
36022       nargs = 2;
36023       tf_p = true;
36024       break;
36025
36026     default:
36027       gcc_unreachable ();
36028     }
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   gcc_assert (nargs <= 4);
36036
36037   for (i = 0; i < nargs; i++)
36038     {
36039       tree arg = CALL_EXPR_ARG (exp, i);
36040       rtx op = expand_normal (arg);
36041       int adjust = (comparison_p) ? 1 : 0;
36042       machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
36043
36044       if (last_arg_constant && i == nargs - 1)
36045         {
36046           if (!insn_data[icode].operand[i + 1].predicate (op, mode))
36047             {
36048               enum insn_code new_icode = icode;
36049               switch (icode)
36050                 {
36051                 case CODE_FOR_xop_vpermil2v2df3:
36052                 case CODE_FOR_xop_vpermil2v4sf3:
36053                 case CODE_FOR_xop_vpermil2v4df3:
36054                 case CODE_FOR_xop_vpermil2v8sf3:
36055                   error ("the last argument must be a 2-bit immediate");
36056                   return gen_reg_rtx (tmode);
36057                 case CODE_FOR_xop_rotlv2di3:
36058                   new_icode = CODE_FOR_rotlv2di3;
36059                   goto xop_rotl;
36060                 case CODE_FOR_xop_rotlv4si3:
36061                   new_icode = CODE_FOR_rotlv4si3;
36062                   goto xop_rotl;
36063                 case CODE_FOR_xop_rotlv8hi3:
36064                   new_icode = CODE_FOR_rotlv8hi3;
36065                   goto xop_rotl;
36066                 case CODE_FOR_xop_rotlv16qi3:
36067                   new_icode = CODE_FOR_rotlv16qi3;
36068                 xop_rotl:
36069                   if (CONST_INT_P (op))
36070                     {
36071                       int mask = GET_MODE_BITSIZE (GET_MODE_INNER (tmode)) - 1;
36072                       op = GEN_INT (INTVAL (op) & mask);
36073                       gcc_checking_assert
36074                         (insn_data[icode].operand[i + 1].predicate (op, mode));
36075                     }
36076                   else
36077                     {
36078                       gcc_checking_assert
36079                         (nargs == 2
36080                          && insn_data[new_icode].operand[0].mode == tmode
36081                          && insn_data[new_icode].operand[1].mode == tmode
36082                          && insn_data[new_icode].operand[2].mode == mode
36083                          && insn_data[new_icode].operand[0].predicate
36084                             == insn_data[icode].operand[0].predicate
36085                          && insn_data[new_icode].operand[1].predicate
36086                             == insn_data[icode].operand[1].predicate);
36087                       icode = new_icode;
36088                       goto non_constant;
36089                     }
36090                   break;
36091                 default:
36092                   gcc_unreachable ();
36093                 }
36094             }
36095         }
36096       else
36097         {
36098         non_constant:
36099           if (VECTOR_MODE_P (mode))
36100             op = safe_vector_operand (op, mode);
36101
36102           /* If we aren't optimizing, only allow one memory operand to be
36103              generated.  */
36104           if (memory_operand (op, mode))
36105             num_memory++;
36106
36107           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
36108
36109           if (optimize
36110               || !insn_data[icode].operand[i+adjust+1].predicate (op, mode)
36111               || num_memory > 1)
36112             op = force_reg (mode, op);
36113         }
36114
36115       args[i].op = op;
36116       args[i].mode = mode;
36117     }
36118
36119   switch (nargs)
36120     {
36121     case 1:
36122       pat = GEN_FCN (icode) (target, args[0].op);
36123       break;
36124
36125     case 2:
36126       if (tf_p)
36127         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
36128                                GEN_INT ((int)sub_code));
36129       else if (! comparison_p)
36130         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
36131       else
36132         {
36133           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
36134                                        args[0].op,
36135                                        args[1].op);
36136
36137           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
36138         }
36139       break;
36140
36141     case 3:
36142       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
36143       break;
36144
36145     case 4:
36146       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op, args[3].op);
36147       break;
36148
36149     default:
36150       gcc_unreachable ();
36151     }
36152
36153   if (! pat)
36154     return 0;
36155
36156   emit_insn (pat);
36157   return target;
36158 }
36159
36160 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
36161    insns with vec_merge.  */
36162
36163 static rtx
36164 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
36165                                     rtx target)
36166 {
36167   rtx pat;
36168   tree arg0 = CALL_EXPR_ARG (exp, 0);
36169   rtx op1, op0 = expand_normal (arg0);
36170   machine_mode tmode = insn_data[icode].operand[0].mode;
36171   machine_mode mode0 = insn_data[icode].operand[1].mode;
36172
36173   if (optimize || !target
36174       || GET_MODE (target) != tmode
36175       || !insn_data[icode].operand[0].predicate (target, tmode))
36176     target = gen_reg_rtx (tmode);
36177
36178   if (VECTOR_MODE_P (mode0))
36179     op0 = safe_vector_operand (op0, mode0);
36180
36181   if ((optimize && !register_operand (op0, mode0))
36182       || !insn_data[icode].operand[1].predicate (op0, mode0))
36183     op0 = copy_to_mode_reg (mode0, op0);
36184
36185   op1 = op0;
36186   if (!insn_data[icode].operand[2].predicate (op1, mode0))
36187     op1 = copy_to_mode_reg (mode0, op1);
36188
36189   pat = GEN_FCN (icode) (target, op0, op1);
36190   if (! pat)
36191     return 0;
36192   emit_insn (pat);
36193   return target;
36194 }
36195
36196 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
36197
36198 static rtx
36199 ix86_expand_sse_compare (const struct builtin_description *d,
36200                          tree exp, rtx target, bool swap)
36201 {
36202   rtx pat;
36203   tree arg0 = CALL_EXPR_ARG (exp, 0);
36204   tree arg1 = CALL_EXPR_ARG (exp, 1);
36205   rtx op0 = expand_normal (arg0);
36206   rtx op1 = expand_normal (arg1);
36207   rtx op2;
36208   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36209   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36210   machine_mode mode1 = insn_data[d->icode].operand[2].mode;
36211   enum rtx_code comparison = d->comparison;
36212
36213   if (VECTOR_MODE_P (mode0))
36214     op0 = safe_vector_operand (op0, mode0);
36215   if (VECTOR_MODE_P (mode1))
36216     op1 = safe_vector_operand (op1, mode1);
36217
36218   /* Swap operands if we have a comparison that isn't available in
36219      hardware.  */
36220   if (swap)
36221     std::swap (op0, op1);
36222
36223   if (optimize || !target
36224       || GET_MODE (target) != tmode
36225       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36226     target = gen_reg_rtx (tmode);
36227
36228   if ((optimize && !register_operand (op0, mode0))
36229       || !insn_data[d->icode].operand[1].predicate (op0, mode0))
36230     op0 = copy_to_mode_reg (mode0, op0);
36231   if ((optimize && !register_operand (op1, mode1))
36232       || !insn_data[d->icode].operand[2].predicate (op1, mode1))
36233     op1 = copy_to_mode_reg (mode1, op1);
36234
36235   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
36236   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
36237   if (! pat)
36238     return 0;
36239   emit_insn (pat);
36240   return target;
36241 }
36242
36243 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
36244
36245 static rtx
36246 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
36247                       rtx target)
36248 {
36249   rtx pat;
36250   tree arg0 = CALL_EXPR_ARG (exp, 0);
36251   tree arg1 = CALL_EXPR_ARG (exp, 1);
36252   rtx op0 = expand_normal (arg0);
36253   rtx op1 = expand_normal (arg1);
36254   machine_mode mode0 = insn_data[d->icode].operand[0].mode;
36255   machine_mode mode1 = insn_data[d->icode].operand[1].mode;
36256   enum rtx_code comparison = d->comparison;
36257
36258   if (VECTOR_MODE_P (mode0))
36259     op0 = safe_vector_operand (op0, mode0);
36260   if (VECTOR_MODE_P (mode1))
36261     op1 = safe_vector_operand (op1, mode1);
36262
36263   /* Swap operands if we have a comparison that isn't available in
36264      hardware.  */
36265   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
36266     std::swap (op0, op1);
36267
36268   target = gen_reg_rtx (SImode);
36269   emit_move_insn (target, const0_rtx);
36270   target = gen_rtx_SUBREG (QImode, target, 0);
36271
36272   if ((optimize && !register_operand (op0, mode0))
36273       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36274     op0 = copy_to_mode_reg (mode0, op0);
36275   if ((optimize && !register_operand (op1, mode1))
36276       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36277     op1 = copy_to_mode_reg (mode1, op1);
36278
36279   pat = GEN_FCN (d->icode) (op0, op1);
36280   if (! pat)
36281     return 0;
36282   emit_insn (pat);
36283   emit_insn (gen_rtx_SET (gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36284                           gen_rtx_fmt_ee (comparison, QImode,
36285                                           SET_DEST (pat),
36286                                           const0_rtx)));
36287
36288   return SUBREG_REG (target);
36289 }
36290
36291 /* Subroutines of ix86_expand_args_builtin to take care of round insns.  */
36292
36293 static rtx
36294 ix86_expand_sse_round (const struct builtin_description *d, tree exp,
36295                        rtx target)
36296 {
36297   rtx pat;
36298   tree arg0 = CALL_EXPR_ARG (exp, 0);
36299   rtx op1, op0 = expand_normal (arg0);
36300   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36301   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36302
36303   if (optimize || target == 0
36304       || GET_MODE (target) != tmode
36305       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36306     target = gen_reg_rtx (tmode);
36307
36308   if (VECTOR_MODE_P (mode0))
36309     op0 = safe_vector_operand (op0, mode0);
36310
36311   if ((optimize && !register_operand (op0, mode0))
36312       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36313     op0 = copy_to_mode_reg (mode0, op0);
36314
36315   op1 = GEN_INT (d->comparison);
36316
36317   pat = GEN_FCN (d->icode) (target, op0, op1);
36318   if (! pat)
36319     return 0;
36320   emit_insn (pat);
36321   return target;
36322 }
36323
36324 static rtx
36325 ix86_expand_sse_round_vec_pack_sfix (const struct builtin_description *d,
36326                                      tree exp, rtx target)
36327 {
36328   rtx pat;
36329   tree arg0 = CALL_EXPR_ARG (exp, 0);
36330   tree arg1 = CALL_EXPR_ARG (exp, 1);
36331   rtx op0 = expand_normal (arg0);
36332   rtx op1 = expand_normal (arg1);
36333   rtx op2;
36334   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36335   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36336   machine_mode mode1 = insn_data[d->icode].operand[2].mode;
36337
36338   if (optimize || target == 0
36339       || GET_MODE (target) != tmode
36340       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36341     target = gen_reg_rtx (tmode);
36342
36343   op0 = safe_vector_operand (op0, mode0);
36344   op1 = safe_vector_operand (op1, mode1);
36345
36346   if ((optimize && !register_operand (op0, mode0))
36347       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36348     op0 = copy_to_mode_reg (mode0, op0);
36349   if ((optimize && !register_operand (op1, mode1))
36350       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36351     op1 = copy_to_mode_reg (mode1, op1);
36352
36353   op2 = GEN_INT (d->comparison);
36354
36355   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
36356   if (! pat)
36357     return 0;
36358   emit_insn (pat);
36359   return target;
36360 }
36361
36362 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
36363
36364 static rtx
36365 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
36366                        rtx target)
36367 {
36368   rtx pat;
36369   tree arg0 = CALL_EXPR_ARG (exp, 0);
36370   tree arg1 = CALL_EXPR_ARG (exp, 1);
36371   rtx op0 = expand_normal (arg0);
36372   rtx op1 = expand_normal (arg1);
36373   machine_mode mode0 = insn_data[d->icode].operand[0].mode;
36374   machine_mode mode1 = insn_data[d->icode].operand[1].mode;
36375   enum rtx_code comparison = d->comparison;
36376
36377   if (VECTOR_MODE_P (mode0))
36378     op0 = safe_vector_operand (op0, mode0);
36379   if (VECTOR_MODE_P (mode1))
36380     op1 = safe_vector_operand (op1, mode1);
36381
36382   target = gen_reg_rtx (SImode);
36383   emit_move_insn (target, const0_rtx);
36384   target = gen_rtx_SUBREG (QImode, target, 0);
36385
36386   if ((optimize && !register_operand (op0, mode0))
36387       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36388     op0 = copy_to_mode_reg (mode0, op0);
36389   if ((optimize && !register_operand (op1, mode1))
36390       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36391     op1 = copy_to_mode_reg (mode1, op1);
36392
36393   pat = GEN_FCN (d->icode) (op0, op1);
36394   if (! pat)
36395     return 0;
36396   emit_insn (pat);
36397   emit_insn (gen_rtx_SET (gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36398                           gen_rtx_fmt_ee (comparison, QImode,
36399                                           SET_DEST (pat),
36400                                           const0_rtx)));
36401
36402   return SUBREG_REG (target);
36403 }
36404
36405 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
36406
36407 static rtx
36408 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
36409                           tree exp, rtx target)
36410 {
36411   rtx pat;
36412   tree arg0 = CALL_EXPR_ARG (exp, 0);
36413   tree arg1 = CALL_EXPR_ARG (exp, 1);
36414   tree arg2 = CALL_EXPR_ARG (exp, 2);
36415   tree arg3 = CALL_EXPR_ARG (exp, 3);
36416   tree arg4 = CALL_EXPR_ARG (exp, 4);
36417   rtx scratch0, scratch1;
36418   rtx op0 = expand_normal (arg0);
36419   rtx op1 = expand_normal (arg1);
36420   rtx op2 = expand_normal (arg2);
36421   rtx op3 = expand_normal (arg3);
36422   rtx op4 = expand_normal (arg4);
36423   machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
36424
36425   tmode0 = insn_data[d->icode].operand[0].mode;
36426   tmode1 = insn_data[d->icode].operand[1].mode;
36427   modev2 = insn_data[d->icode].operand[2].mode;
36428   modei3 = insn_data[d->icode].operand[3].mode;
36429   modev4 = insn_data[d->icode].operand[4].mode;
36430   modei5 = insn_data[d->icode].operand[5].mode;
36431   modeimm = insn_data[d->icode].operand[6].mode;
36432
36433   if (VECTOR_MODE_P (modev2))
36434     op0 = safe_vector_operand (op0, modev2);
36435   if (VECTOR_MODE_P (modev4))
36436     op2 = safe_vector_operand (op2, modev4);
36437
36438   if (!insn_data[d->icode].operand[2].predicate (op0, modev2))
36439     op0 = copy_to_mode_reg (modev2, op0);
36440   if (!insn_data[d->icode].operand[3].predicate (op1, modei3))
36441     op1 = copy_to_mode_reg (modei3, op1);
36442   if ((optimize && !register_operand (op2, modev4))
36443       || !insn_data[d->icode].operand[4].predicate (op2, modev4))
36444     op2 = copy_to_mode_reg (modev4, op2);
36445   if (!insn_data[d->icode].operand[5].predicate (op3, modei5))
36446     op3 = copy_to_mode_reg (modei5, op3);
36447
36448   if (!insn_data[d->icode].operand[6].predicate (op4, modeimm))
36449     {
36450       error ("the fifth argument must be an 8-bit immediate");
36451       return const0_rtx;
36452     }
36453
36454   if (d->code == IX86_BUILTIN_PCMPESTRI128)
36455     {
36456       if (optimize || !target
36457           || GET_MODE (target) != tmode0
36458           || !insn_data[d->icode].operand[0].predicate (target, tmode0))
36459         target = gen_reg_rtx (tmode0);
36460
36461       scratch1 = gen_reg_rtx (tmode1);
36462
36463       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
36464     }
36465   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
36466     {
36467       if (optimize || !target
36468           || GET_MODE (target) != tmode1
36469           || !insn_data[d->icode].operand[1].predicate (target, tmode1))
36470         target = gen_reg_rtx (tmode1);
36471
36472       scratch0 = gen_reg_rtx (tmode0);
36473
36474       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
36475     }
36476   else
36477     {
36478       gcc_assert (d->flag);
36479
36480       scratch0 = gen_reg_rtx (tmode0);
36481       scratch1 = gen_reg_rtx (tmode1);
36482
36483       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
36484     }
36485
36486   if (! pat)
36487     return 0;
36488
36489   emit_insn (pat);
36490
36491   if (d->flag)
36492     {
36493       target = gen_reg_rtx (SImode);
36494       emit_move_insn (target, const0_rtx);
36495       target = gen_rtx_SUBREG (QImode, target, 0);
36496
36497       emit_insn
36498         (gen_rtx_SET (gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36499                       gen_rtx_fmt_ee (EQ, QImode,
36500                                       gen_rtx_REG ((machine_mode) d->flag,
36501                                                    FLAGS_REG),
36502                                       const0_rtx)));
36503       return SUBREG_REG (target);
36504     }
36505   else
36506     return target;
36507 }
36508
36509
36510 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
36511
36512 static rtx
36513 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
36514                           tree exp, rtx target)
36515 {
36516   rtx pat;
36517   tree arg0 = CALL_EXPR_ARG (exp, 0);
36518   tree arg1 = CALL_EXPR_ARG (exp, 1);
36519   tree arg2 = CALL_EXPR_ARG (exp, 2);
36520   rtx scratch0, scratch1;
36521   rtx op0 = expand_normal (arg0);
36522   rtx op1 = expand_normal (arg1);
36523   rtx op2 = expand_normal (arg2);
36524   machine_mode tmode0, tmode1, modev2, modev3, modeimm;
36525
36526   tmode0 = insn_data[d->icode].operand[0].mode;
36527   tmode1 = insn_data[d->icode].operand[1].mode;
36528   modev2 = insn_data[d->icode].operand[2].mode;
36529   modev3 = insn_data[d->icode].operand[3].mode;
36530   modeimm = insn_data[d->icode].operand[4].mode;
36531
36532   if (VECTOR_MODE_P (modev2))
36533     op0 = safe_vector_operand (op0, modev2);
36534   if (VECTOR_MODE_P (modev3))
36535     op1 = safe_vector_operand (op1, modev3);
36536
36537   if (!insn_data[d->icode].operand[2].predicate (op0, modev2))
36538     op0 = copy_to_mode_reg (modev2, op0);
36539   if ((optimize && !register_operand (op1, modev3))
36540       || !insn_data[d->icode].operand[3].predicate (op1, modev3))
36541     op1 = copy_to_mode_reg (modev3, op1);
36542
36543   if (!insn_data[d->icode].operand[4].predicate (op2, modeimm))
36544     {
36545       error ("the third argument must be an 8-bit immediate");
36546       return const0_rtx;
36547     }
36548
36549   if (d->code == IX86_BUILTIN_PCMPISTRI128)
36550     {
36551       if (optimize || !target
36552           || GET_MODE (target) != tmode0
36553           || !insn_data[d->icode].operand[0].predicate (target, tmode0))
36554         target = gen_reg_rtx (tmode0);
36555
36556       scratch1 = gen_reg_rtx (tmode1);
36557
36558       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
36559     }
36560   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
36561     {
36562       if (optimize || !target
36563           || GET_MODE (target) != tmode1
36564           || !insn_data[d->icode].operand[1].predicate (target, tmode1))
36565         target = gen_reg_rtx (tmode1);
36566
36567       scratch0 = gen_reg_rtx (tmode0);
36568
36569       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
36570     }
36571   else
36572     {
36573       gcc_assert (d->flag);
36574
36575       scratch0 = gen_reg_rtx (tmode0);
36576       scratch1 = gen_reg_rtx (tmode1);
36577
36578       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
36579     }
36580
36581   if (! pat)
36582     return 0;
36583
36584   emit_insn (pat);
36585
36586   if (d->flag)
36587     {
36588       target = gen_reg_rtx (SImode);
36589       emit_move_insn (target, const0_rtx);
36590       target = gen_rtx_SUBREG (QImode, target, 0);
36591
36592       emit_insn
36593         (gen_rtx_SET (gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36594                       gen_rtx_fmt_ee (EQ, QImode,
36595                                       gen_rtx_REG ((machine_mode) d->flag,
36596                                                    FLAGS_REG),
36597                                       const0_rtx)));
36598       return SUBREG_REG (target);
36599     }
36600   else
36601     return target;
36602 }
36603
36604 /* Subroutine of ix86_expand_builtin to take care of insns with
36605    variable number of operands.  */
36606
36607 static rtx
36608 ix86_expand_args_builtin (const struct builtin_description *d,
36609                           tree exp, rtx target)
36610 {
36611   rtx pat, real_target;
36612   unsigned int i, nargs;
36613   unsigned int nargs_constant = 0;
36614   unsigned int mask_pos = 0;
36615   int num_memory = 0;
36616   struct
36617     {
36618       rtx op;
36619       machine_mode mode;
36620     } args[6];
36621   bool last_arg_count = false;
36622   enum insn_code icode = d->icode;
36623   const struct insn_data_d *insn_p = &insn_data[icode];
36624   machine_mode tmode = insn_p->operand[0].mode;
36625   machine_mode rmode = VOIDmode;
36626   bool swap = false;
36627   enum rtx_code comparison = d->comparison;
36628
36629   switch ((enum ix86_builtin_func_type) d->flag)
36630     {
36631     case V2DF_FTYPE_V2DF_ROUND:
36632     case V4DF_FTYPE_V4DF_ROUND:
36633     case V4SF_FTYPE_V4SF_ROUND:
36634     case V8SF_FTYPE_V8SF_ROUND:
36635     case V4SI_FTYPE_V4SF_ROUND:
36636     case V8SI_FTYPE_V8SF_ROUND:
36637       return ix86_expand_sse_round (d, exp, target);
36638     case V4SI_FTYPE_V2DF_V2DF_ROUND:
36639     case V8SI_FTYPE_V4DF_V4DF_ROUND:
36640     case V16SI_FTYPE_V8DF_V8DF_ROUND:
36641       return ix86_expand_sse_round_vec_pack_sfix (d, exp, target);
36642     case INT_FTYPE_V8SF_V8SF_PTEST:
36643     case INT_FTYPE_V4DI_V4DI_PTEST:
36644     case INT_FTYPE_V4DF_V4DF_PTEST:
36645     case INT_FTYPE_V4SF_V4SF_PTEST:
36646     case INT_FTYPE_V2DI_V2DI_PTEST:
36647     case INT_FTYPE_V2DF_V2DF_PTEST:
36648       return ix86_expand_sse_ptest (d, exp, target);
36649     case FLOAT128_FTYPE_FLOAT128:
36650     case FLOAT_FTYPE_FLOAT:
36651     case INT_FTYPE_INT:
36652     case UINT64_FTYPE_INT:
36653     case UINT16_FTYPE_UINT16:
36654     case INT64_FTYPE_INT64:
36655     case INT64_FTYPE_V4SF:
36656     case INT64_FTYPE_V2DF:
36657     case INT_FTYPE_V16QI:
36658     case INT_FTYPE_V8QI:
36659     case INT_FTYPE_V8SF:
36660     case INT_FTYPE_V4DF:
36661     case INT_FTYPE_V4SF:
36662     case INT_FTYPE_V2DF:
36663     case INT_FTYPE_V32QI:
36664     case V16QI_FTYPE_V16QI:
36665     case V8SI_FTYPE_V8SF:
36666     case V8SI_FTYPE_V4SI:
36667     case V8HI_FTYPE_V8HI:
36668     case V8HI_FTYPE_V16QI:
36669     case V8QI_FTYPE_V8QI:
36670     case V8SF_FTYPE_V8SF:
36671     case V8SF_FTYPE_V8SI:
36672     case V8SF_FTYPE_V4SF:
36673     case V8SF_FTYPE_V8HI:
36674     case V4SI_FTYPE_V4SI:
36675     case V4SI_FTYPE_V16QI:
36676     case V4SI_FTYPE_V4SF:
36677     case V4SI_FTYPE_V8SI:
36678     case V4SI_FTYPE_V8HI:
36679     case V4SI_FTYPE_V4DF:
36680     case V4SI_FTYPE_V2DF:
36681     case V4HI_FTYPE_V4HI:
36682     case V4DF_FTYPE_V4DF:
36683     case V4DF_FTYPE_V4SI:
36684     case V4DF_FTYPE_V4SF:
36685     case V4DF_FTYPE_V2DF:
36686     case V4SF_FTYPE_V4SF:
36687     case V4SF_FTYPE_V4SI:
36688     case V4SF_FTYPE_V8SF:
36689     case V4SF_FTYPE_V4DF:
36690     case V4SF_FTYPE_V8HI:
36691     case V4SF_FTYPE_V2DF:
36692     case V2DI_FTYPE_V2DI:
36693     case V2DI_FTYPE_V16QI:
36694     case V2DI_FTYPE_V8HI:
36695     case V2DI_FTYPE_V4SI:
36696     case V2DF_FTYPE_V2DF:
36697     case V2DF_FTYPE_V4SI:
36698     case V2DF_FTYPE_V4DF:
36699     case V2DF_FTYPE_V4SF:
36700     case V2DF_FTYPE_V2SI:
36701     case V2SI_FTYPE_V2SI:
36702     case V2SI_FTYPE_V4SF:
36703     case V2SI_FTYPE_V2SF:
36704     case V2SI_FTYPE_V2DF:
36705     case V2SF_FTYPE_V2SF:
36706     case V2SF_FTYPE_V2SI:
36707     case V32QI_FTYPE_V32QI:
36708     case V32QI_FTYPE_V16QI:
36709     case V16HI_FTYPE_V16HI:
36710     case V16HI_FTYPE_V8HI:
36711     case V8SI_FTYPE_V8SI:
36712     case V16HI_FTYPE_V16QI:
36713     case V8SI_FTYPE_V16QI:
36714     case V4DI_FTYPE_V16QI:
36715     case V8SI_FTYPE_V8HI:
36716     case V4DI_FTYPE_V8HI:
36717     case V4DI_FTYPE_V4SI:
36718     case V4DI_FTYPE_V2DI:
36719     case HI_FTYPE_HI:
36720     case HI_FTYPE_V16QI:
36721     case SI_FTYPE_V32QI:
36722     case DI_FTYPE_V64QI:
36723     case V16QI_FTYPE_HI:
36724     case V32QI_FTYPE_SI:
36725     case V64QI_FTYPE_DI:
36726     case V8HI_FTYPE_QI:
36727     case V16HI_FTYPE_HI:
36728     case V32HI_FTYPE_SI:
36729     case V4SI_FTYPE_QI:
36730     case V8SI_FTYPE_QI:
36731     case V4SI_FTYPE_HI:
36732     case V8SI_FTYPE_HI:
36733     case QI_FTYPE_V8HI:
36734     case HI_FTYPE_V16HI:
36735     case SI_FTYPE_V32HI:
36736     case QI_FTYPE_V4SI:
36737     case QI_FTYPE_V8SI:
36738     case HI_FTYPE_V16SI:
36739     case QI_FTYPE_V2DI:
36740     case QI_FTYPE_V4DI:
36741     case QI_FTYPE_V8DI:
36742     case UINT_FTYPE_V2DF:
36743     case UINT_FTYPE_V4SF:
36744     case UINT64_FTYPE_V2DF:
36745     case UINT64_FTYPE_V4SF:
36746     case V16QI_FTYPE_V8DI:
36747     case V16HI_FTYPE_V16SI:
36748     case V16SI_FTYPE_HI:
36749     case V2DI_FTYPE_QI:
36750     case V4DI_FTYPE_QI:
36751     case V16SI_FTYPE_V16SI:
36752     case V16SI_FTYPE_INT:
36753     case V16SF_FTYPE_FLOAT:
36754     case V16SF_FTYPE_V8SF:
36755     case V16SI_FTYPE_V8SI:
36756     case V16SF_FTYPE_V4SF:
36757     case V16SI_FTYPE_V4SI:
36758     case V16SF_FTYPE_V16SF:
36759     case V8HI_FTYPE_V8DI:
36760     case V8UHI_FTYPE_V8UHI:
36761     case V8SI_FTYPE_V8DI:
36762     case V8SF_FTYPE_V8DF:
36763     case V8DI_FTYPE_QI:
36764     case V8DI_FTYPE_INT64:
36765     case V8DI_FTYPE_V4DI:
36766     case V8DI_FTYPE_V8DI:
36767     case V8DF_FTYPE_DOUBLE:
36768     case V8DF_FTYPE_V4DF:
36769     case V8DF_FTYPE_V2DF:
36770     case V8DF_FTYPE_V8DF:
36771     case V8DF_FTYPE_V8SI:
36772       nargs = 1;
36773       break;
36774     case V4SF_FTYPE_V4SF_VEC_MERGE:
36775     case V2DF_FTYPE_V2DF_VEC_MERGE:
36776       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
36777     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
36778     case V16QI_FTYPE_V16QI_V16QI:
36779     case V16QI_FTYPE_V8HI_V8HI:
36780     case V16SI_FTYPE_V16SI_V16SI:
36781     case V16SF_FTYPE_V16SF_V16SF:
36782     case V16SF_FTYPE_V16SF_V16SI:
36783     case V8QI_FTYPE_V8QI_V8QI:
36784     case V8QI_FTYPE_V4HI_V4HI:
36785     case V8HI_FTYPE_V8HI_V8HI:
36786     case V8HI_FTYPE_V16QI_V16QI:
36787     case V8HI_FTYPE_V4SI_V4SI:
36788     case V8SF_FTYPE_V8SF_V8SF:
36789     case V8SF_FTYPE_V8SF_V8SI:
36790     case V8DI_FTYPE_V8DI_V8DI:
36791     case V8DF_FTYPE_V8DF_V8DF:
36792     case V8DF_FTYPE_V8DF_V8DI:
36793     case V4SI_FTYPE_V4SI_V4SI:
36794     case V4SI_FTYPE_V8HI_V8HI:
36795     case V4SI_FTYPE_V4SF_V4SF:
36796     case V4SI_FTYPE_V2DF_V2DF:
36797     case V4HI_FTYPE_V4HI_V4HI:
36798     case V4HI_FTYPE_V8QI_V8QI:
36799     case V4HI_FTYPE_V2SI_V2SI:
36800     case V4DF_FTYPE_V4DF_V4DF:
36801     case V4DF_FTYPE_V4DF_V4DI:
36802     case V4SF_FTYPE_V4SF_V4SF:
36803     case V4SF_FTYPE_V4SF_V4SI:
36804     case V4SF_FTYPE_V4SF_V2SI:
36805     case V4SF_FTYPE_V4SF_V2DF:
36806     case V4SF_FTYPE_V4SF_UINT:
36807     case V4SF_FTYPE_V4SF_UINT64:
36808     case V4SF_FTYPE_V4SF_DI:
36809     case V4SF_FTYPE_V4SF_SI:
36810     case V2DI_FTYPE_V2DI_V2DI:
36811     case V2DI_FTYPE_V16QI_V16QI:
36812     case V2DI_FTYPE_V4SI_V4SI:
36813     case V2UDI_FTYPE_V4USI_V4USI:
36814     case V2DI_FTYPE_V2DI_V16QI:
36815     case V2DI_FTYPE_V2DF_V2DF:
36816     case V2SI_FTYPE_V2SI_V2SI:
36817     case V2SI_FTYPE_V4HI_V4HI:
36818     case V2SI_FTYPE_V2SF_V2SF:
36819     case V2DF_FTYPE_V2DF_V2DF:
36820     case V2DF_FTYPE_V2DF_V4SF:
36821     case V2DF_FTYPE_V2DF_V2DI:
36822     case V2DF_FTYPE_V2DF_DI:
36823     case V2DF_FTYPE_V2DF_SI:
36824     case V2DF_FTYPE_V2DF_UINT:
36825     case V2DF_FTYPE_V2DF_UINT64:
36826     case V2SF_FTYPE_V2SF_V2SF:
36827     case V1DI_FTYPE_V1DI_V1DI:
36828     case V1DI_FTYPE_V8QI_V8QI:
36829     case V1DI_FTYPE_V2SI_V2SI:
36830     case V32QI_FTYPE_V16HI_V16HI:
36831     case V16HI_FTYPE_V8SI_V8SI:
36832     case V32QI_FTYPE_V32QI_V32QI:
36833     case V16HI_FTYPE_V32QI_V32QI:
36834     case V16HI_FTYPE_V16HI_V16HI:
36835     case V8SI_FTYPE_V4DF_V4DF:
36836     case V8SI_FTYPE_V8SI_V8SI:
36837     case V8SI_FTYPE_V16HI_V16HI:
36838     case V4DI_FTYPE_V4DI_V4DI:
36839     case V4DI_FTYPE_V8SI_V8SI:
36840     case V4UDI_FTYPE_V8USI_V8USI:
36841     case QI_FTYPE_V8DI_V8DI:
36842     case V8DI_FTYPE_V64QI_V64QI:
36843     case HI_FTYPE_V16SI_V16SI:
36844       if (comparison == UNKNOWN)
36845         return ix86_expand_binop_builtin (icode, exp, target);
36846       nargs = 2;
36847       break;
36848     case V4SF_FTYPE_V4SF_V4SF_SWAP:
36849     case V2DF_FTYPE_V2DF_V2DF_SWAP:
36850       gcc_assert (comparison != UNKNOWN);
36851       nargs = 2;
36852       swap = true;
36853       break;
36854     case V16HI_FTYPE_V16HI_V8HI_COUNT:
36855     case V16HI_FTYPE_V16HI_SI_COUNT:
36856     case V8SI_FTYPE_V8SI_V4SI_COUNT:
36857     case V8SI_FTYPE_V8SI_SI_COUNT:
36858     case V4DI_FTYPE_V4DI_V2DI_COUNT:
36859     case V4DI_FTYPE_V4DI_INT_COUNT:
36860     case V8HI_FTYPE_V8HI_V8HI_COUNT:
36861     case V8HI_FTYPE_V8HI_SI_COUNT:
36862     case V4SI_FTYPE_V4SI_V4SI_COUNT:
36863     case V4SI_FTYPE_V4SI_SI_COUNT:
36864     case V4HI_FTYPE_V4HI_V4HI_COUNT:
36865     case V4HI_FTYPE_V4HI_SI_COUNT:
36866     case V2DI_FTYPE_V2DI_V2DI_COUNT:
36867     case V2DI_FTYPE_V2DI_SI_COUNT:
36868     case V2SI_FTYPE_V2SI_V2SI_COUNT:
36869     case V2SI_FTYPE_V2SI_SI_COUNT:
36870     case V1DI_FTYPE_V1DI_V1DI_COUNT:
36871     case V1DI_FTYPE_V1DI_SI_COUNT:
36872       nargs = 2;
36873       last_arg_count = true;
36874       break;
36875     case UINT64_FTYPE_UINT64_UINT64:
36876     case UINT_FTYPE_UINT_UINT:
36877     case UINT_FTYPE_UINT_USHORT:
36878     case UINT_FTYPE_UINT_UCHAR:
36879     case UINT16_FTYPE_UINT16_INT:
36880     case UINT8_FTYPE_UINT8_INT:
36881     case HI_FTYPE_HI_HI:
36882     case SI_FTYPE_SI_SI:
36883     case DI_FTYPE_DI_DI:
36884     case V16SI_FTYPE_V8DF_V8DF:
36885       nargs = 2;
36886       break;
36887     case V2DI_FTYPE_V2DI_INT_CONVERT:
36888       nargs = 2;
36889       rmode = V1TImode;
36890       nargs_constant = 1;
36891       break;
36892     case V4DI_FTYPE_V4DI_INT_CONVERT:
36893       nargs = 2;
36894       rmode = V2TImode;
36895       nargs_constant = 1;
36896       break;
36897     case V8DI_FTYPE_V8DI_INT_CONVERT:
36898       nargs = 2;
36899       rmode = V4TImode;
36900       nargs_constant = 1;
36901       break;
36902     case V8HI_FTYPE_V8HI_INT:
36903     case V8HI_FTYPE_V8SF_INT:
36904     case V16HI_FTYPE_V16SF_INT:
36905     case V8HI_FTYPE_V4SF_INT:
36906     case V8SF_FTYPE_V8SF_INT:
36907     case V4SF_FTYPE_V16SF_INT:
36908     case V16SF_FTYPE_V16SF_INT:
36909     case V4SI_FTYPE_V4SI_INT:
36910     case V4SI_FTYPE_V8SI_INT:
36911     case V4HI_FTYPE_V4HI_INT:
36912     case V4DF_FTYPE_V4DF_INT:
36913     case V4DF_FTYPE_V8DF_INT:
36914     case V4SF_FTYPE_V4SF_INT:
36915     case V4SF_FTYPE_V8SF_INT:
36916     case V2DI_FTYPE_V2DI_INT:
36917     case V2DF_FTYPE_V2DF_INT:
36918     case V2DF_FTYPE_V4DF_INT:
36919     case V16HI_FTYPE_V16HI_INT:
36920     case V8SI_FTYPE_V8SI_INT:
36921     case V16SI_FTYPE_V16SI_INT:
36922     case V4SI_FTYPE_V16SI_INT:
36923     case V4DI_FTYPE_V4DI_INT:
36924     case V2DI_FTYPE_V4DI_INT:
36925     case V4DI_FTYPE_V8DI_INT:
36926     case HI_FTYPE_HI_INT:
36927     case QI_FTYPE_V4SF_INT:
36928     case QI_FTYPE_V2DF_INT:
36929       nargs = 2;
36930       nargs_constant = 1;
36931       break;
36932     case V16QI_FTYPE_V16QI_V16QI_V16QI:
36933     case V8SF_FTYPE_V8SF_V8SF_V8SF:
36934     case V4DF_FTYPE_V4DF_V4DF_V4DF:
36935     case V4SF_FTYPE_V4SF_V4SF_V4SF:
36936     case V2DF_FTYPE_V2DF_V2DF_V2DF:
36937     case V32QI_FTYPE_V32QI_V32QI_V32QI:
36938     case HI_FTYPE_V16SI_V16SI_HI:
36939     case QI_FTYPE_V8DI_V8DI_QI:
36940     case V16HI_FTYPE_V16SI_V16HI_HI:
36941     case V16QI_FTYPE_V16SI_V16QI_HI:
36942     case V16QI_FTYPE_V8DI_V16QI_QI:
36943     case V16SF_FTYPE_V16SF_V16SF_HI:
36944     case V16SF_FTYPE_V16SF_V16SF_V16SF:
36945     case V16SF_FTYPE_V16SF_V16SI_V16SF:
36946     case V16SF_FTYPE_V16SI_V16SF_HI:
36947     case V16SF_FTYPE_V16SI_V16SF_V16SF:
36948     case V16SF_FTYPE_V4SF_V16SF_HI:
36949     case V16SI_FTYPE_SI_V16SI_HI:
36950     case V16SI_FTYPE_V16HI_V16SI_HI:
36951     case V16SI_FTYPE_V16QI_V16SI_HI:
36952     case V16SI_FTYPE_V16SF_V16SI_HI:
36953     case V8SF_FTYPE_V4SF_V8SF_QI:
36954     case V4DF_FTYPE_V2DF_V4DF_QI:
36955     case V8SI_FTYPE_V4SI_V8SI_QI:
36956     case V8SI_FTYPE_SI_V8SI_QI:
36957     case V4SI_FTYPE_V4SI_V4SI_QI:
36958     case V4SI_FTYPE_SI_V4SI_QI:
36959     case V4DI_FTYPE_V2DI_V4DI_QI:
36960     case V4DI_FTYPE_DI_V4DI_QI:
36961     case V2DI_FTYPE_V2DI_V2DI_QI:
36962     case V2DI_FTYPE_DI_V2DI_QI:
36963     case V64QI_FTYPE_V64QI_V64QI_DI:
36964     case V64QI_FTYPE_V16QI_V64QI_DI:
36965     case V64QI_FTYPE_QI_V64QI_DI:
36966     case V32QI_FTYPE_V32QI_V32QI_SI:
36967     case V32QI_FTYPE_V16QI_V32QI_SI:
36968     case V32QI_FTYPE_QI_V32QI_SI:
36969     case V16QI_FTYPE_V16QI_V16QI_HI:
36970     case V16QI_FTYPE_QI_V16QI_HI:
36971     case V32HI_FTYPE_V8HI_V32HI_SI:
36972     case V32HI_FTYPE_HI_V32HI_SI:
36973     case V16HI_FTYPE_V8HI_V16HI_HI:
36974     case V16HI_FTYPE_HI_V16HI_HI:
36975     case V8HI_FTYPE_V8HI_V8HI_QI:
36976     case V8HI_FTYPE_HI_V8HI_QI:
36977     case V8SF_FTYPE_V8HI_V8SF_QI:
36978     case V4SF_FTYPE_V8HI_V4SF_QI:
36979     case V8SI_FTYPE_V8SF_V8SI_QI:
36980     case V4SI_FTYPE_V4SF_V4SI_QI:
36981     case V8DI_FTYPE_V8SF_V8DI_QI:
36982     case V4DI_FTYPE_V4SF_V4DI_QI:
36983     case V2DI_FTYPE_V4SF_V2DI_QI:
36984     case V8SF_FTYPE_V8DI_V8SF_QI:
36985     case V4SF_FTYPE_V4DI_V4SF_QI:
36986     case V4SF_FTYPE_V2DI_V4SF_QI:
36987     case V8DF_FTYPE_V8DI_V8DF_QI:
36988     case V4DF_FTYPE_V4DI_V4DF_QI:
36989     case V2DF_FTYPE_V2DI_V2DF_QI:
36990     case V16QI_FTYPE_V8HI_V16QI_QI:
36991     case V16QI_FTYPE_V16HI_V16QI_HI:
36992     case V16QI_FTYPE_V4SI_V16QI_QI:
36993     case V16QI_FTYPE_V8SI_V16QI_QI:
36994     case V8HI_FTYPE_V4SI_V8HI_QI:
36995     case V8HI_FTYPE_V8SI_V8HI_QI:
36996     case V16QI_FTYPE_V2DI_V16QI_QI:
36997     case V16QI_FTYPE_V4DI_V16QI_QI:
36998     case V8HI_FTYPE_V2DI_V8HI_QI:
36999     case V8HI_FTYPE_V4DI_V8HI_QI:
37000     case V4SI_FTYPE_V2DI_V4SI_QI:
37001     case V4SI_FTYPE_V4DI_V4SI_QI:
37002     case V32QI_FTYPE_V32HI_V32QI_SI:
37003     case HI_FTYPE_V16QI_V16QI_HI:
37004     case SI_FTYPE_V32QI_V32QI_SI:
37005     case DI_FTYPE_V64QI_V64QI_DI:
37006     case QI_FTYPE_V8HI_V8HI_QI:
37007     case HI_FTYPE_V16HI_V16HI_HI:
37008     case SI_FTYPE_V32HI_V32HI_SI:
37009     case QI_FTYPE_V4SI_V4SI_QI:
37010     case QI_FTYPE_V8SI_V8SI_QI:
37011     case QI_FTYPE_V2DI_V2DI_QI:
37012     case QI_FTYPE_V4DI_V4DI_QI:
37013     case V4SF_FTYPE_V2DF_V4SF_QI:
37014     case V4SF_FTYPE_V4DF_V4SF_QI:
37015     case V16SI_FTYPE_V16SI_V16SI_HI:
37016     case V16SI_FTYPE_V16SI_V16SI_V16SI:
37017     case V16SI_FTYPE_V4SI_V16SI_HI:
37018     case V2DI_FTYPE_V2DI_V2DI_V2DI:
37019     case V2DI_FTYPE_V4SI_V2DI_QI:
37020     case V2DI_FTYPE_V8HI_V2DI_QI:
37021     case V2DI_FTYPE_V16QI_V2DI_QI:
37022     case V4DI_FTYPE_V4DI_V4DI_QI:
37023     case V4DI_FTYPE_V4SI_V4DI_QI:
37024     case V4DI_FTYPE_V8HI_V4DI_QI:
37025     case V4DI_FTYPE_V16QI_V4DI_QI:
37026     case V8DI_FTYPE_V8DF_V8DI_QI:
37027     case V4DI_FTYPE_V4DF_V4DI_QI:
37028     case V2DI_FTYPE_V2DF_V2DI_QI:
37029     case V4SI_FTYPE_V4DF_V4SI_QI:
37030     case V4SI_FTYPE_V2DF_V4SI_QI:
37031     case V4SI_FTYPE_V8HI_V4SI_QI:
37032     case V4SI_FTYPE_V16QI_V4SI_QI:
37033     case V8SI_FTYPE_V8SI_V8SI_V8SI:
37034     case V4DI_FTYPE_V4DI_V4DI_V4DI:
37035     case V8DF_FTYPE_V2DF_V8DF_QI:
37036     case V8DF_FTYPE_V4DF_V8DF_QI:
37037     case V8DF_FTYPE_V8DF_V8DF_QI:
37038     case V8DF_FTYPE_V8DF_V8DF_V8DF:
37039     case V8SF_FTYPE_V8SF_V8SF_QI:
37040     case V8SF_FTYPE_V8SI_V8SF_QI:
37041     case V4DF_FTYPE_V4DF_V4DF_QI:
37042     case V4SF_FTYPE_V4SF_V4SF_QI:
37043     case V2DF_FTYPE_V2DF_V2DF_QI:
37044     case V2DF_FTYPE_V4SF_V2DF_QI:
37045     case V2DF_FTYPE_V4SI_V2DF_QI:
37046     case V4SF_FTYPE_V4SI_V4SF_QI:
37047     case V4DF_FTYPE_V4SF_V4DF_QI:
37048     case V4DF_FTYPE_V4SI_V4DF_QI:
37049     case V8SI_FTYPE_V8SI_V8SI_QI:
37050     case V8SI_FTYPE_V8HI_V8SI_QI:
37051     case V8SI_FTYPE_V16QI_V8SI_QI:
37052     case V8DF_FTYPE_V8DF_V8DI_V8DF:
37053     case V8DF_FTYPE_V8DI_V8DF_V8DF:
37054     case V8DF_FTYPE_V8SF_V8DF_QI:
37055     case V8DF_FTYPE_V8SI_V8DF_QI:
37056     case V8DI_FTYPE_DI_V8DI_QI:
37057     case V16SF_FTYPE_V8SF_V16SF_HI:
37058     case V16SI_FTYPE_V8SI_V16SI_HI:
37059     case V16HI_FTYPE_V16HI_V16HI_HI:
37060     case V8HI_FTYPE_V16QI_V8HI_QI:
37061     case V16HI_FTYPE_V16QI_V16HI_HI:
37062     case V32HI_FTYPE_V32HI_V32HI_SI:
37063     case V32HI_FTYPE_V32QI_V32HI_SI:
37064     case V8DI_FTYPE_V16QI_V8DI_QI:
37065     case V8DI_FTYPE_V2DI_V8DI_QI:
37066     case V8DI_FTYPE_V4DI_V8DI_QI:
37067     case V8DI_FTYPE_V8DI_V8DI_QI:
37068     case V8DI_FTYPE_V8DI_V8DI_V8DI:
37069     case V8DI_FTYPE_V8HI_V8DI_QI:
37070     case V8DI_FTYPE_V8SI_V8DI_QI:
37071     case V8HI_FTYPE_V8DI_V8HI_QI:
37072     case V8SF_FTYPE_V8DF_V8SF_QI:
37073     case V8SI_FTYPE_V8DF_V8SI_QI:
37074     case V8SI_FTYPE_V8DI_V8SI_QI:
37075     case V4SI_FTYPE_V4SI_V4SI_V4SI:
37076       nargs = 3;
37077       break;
37078     case V32QI_FTYPE_V32QI_V32QI_INT:
37079     case V16HI_FTYPE_V16HI_V16HI_INT:
37080     case V16QI_FTYPE_V16QI_V16QI_INT:
37081     case V4DI_FTYPE_V4DI_V4DI_INT:
37082     case V8HI_FTYPE_V8HI_V8HI_INT:
37083     case V8SI_FTYPE_V8SI_V8SI_INT:
37084     case V8SI_FTYPE_V8SI_V4SI_INT:
37085     case V8SF_FTYPE_V8SF_V8SF_INT:
37086     case V8SF_FTYPE_V8SF_V4SF_INT:
37087     case V4SI_FTYPE_V4SI_V4SI_INT:
37088     case V4DF_FTYPE_V4DF_V4DF_INT:
37089     case V16SF_FTYPE_V16SF_V16SF_INT:
37090     case V16SF_FTYPE_V16SF_V4SF_INT:
37091     case V16SI_FTYPE_V16SI_V4SI_INT:
37092     case V4DF_FTYPE_V4DF_V2DF_INT:
37093     case V4SF_FTYPE_V4SF_V4SF_INT:
37094     case V2DI_FTYPE_V2DI_V2DI_INT:
37095     case V4DI_FTYPE_V4DI_V2DI_INT:
37096     case V2DF_FTYPE_V2DF_V2DF_INT:
37097     case QI_FTYPE_V8DI_V8DI_INT:
37098     case QI_FTYPE_V8DF_V8DF_INT:
37099     case QI_FTYPE_V2DF_V2DF_INT:
37100     case QI_FTYPE_V4SF_V4SF_INT:
37101     case HI_FTYPE_V16SI_V16SI_INT:
37102     case HI_FTYPE_V16SF_V16SF_INT:
37103       nargs = 3;
37104       nargs_constant = 1;
37105       break;
37106     case V4DI_FTYPE_V4DI_V4DI_INT_CONVERT:
37107       nargs = 3;
37108       rmode = V4DImode;
37109       nargs_constant = 1;
37110       break;
37111     case V2DI_FTYPE_V2DI_V2DI_INT_CONVERT:
37112       nargs = 3;
37113       rmode = V2DImode;
37114       nargs_constant = 1;
37115       break;
37116     case V1DI_FTYPE_V1DI_V1DI_INT_CONVERT:
37117       nargs = 3;
37118       rmode = DImode;
37119       nargs_constant = 1;
37120       break;
37121     case V2DI_FTYPE_V2DI_UINT_UINT:
37122       nargs = 3;
37123       nargs_constant = 2;
37124       break;
37125     case V8DI_FTYPE_V8DI_V8DI_INT_CONVERT:
37126       nargs = 3;
37127       rmode = V8DImode;
37128       nargs_constant = 1;
37129       break;
37130     case V8DI_FTYPE_V8DI_V8DI_INT_V8DI_DI_CONVERT:
37131       nargs = 5;
37132       rmode = V8DImode;
37133       mask_pos = 2;
37134       nargs_constant = 1;
37135       break;
37136     case QI_FTYPE_V8DF_INT_QI:
37137     case QI_FTYPE_V4DF_INT_QI:
37138     case QI_FTYPE_V2DF_INT_QI:
37139     case HI_FTYPE_V16SF_INT_HI:
37140     case QI_FTYPE_V8SF_INT_QI:
37141     case QI_FTYPE_V4SF_INT_QI:
37142       nargs = 3;
37143       mask_pos = 1;
37144       nargs_constant = 1;
37145       break;
37146     case V4DI_FTYPE_V4DI_V4DI_INT_V4DI_SI_CONVERT:
37147       nargs = 5;
37148       rmode = V4DImode;
37149       mask_pos = 2;
37150       nargs_constant = 1;
37151       break;
37152     case V2DI_FTYPE_V2DI_V2DI_INT_V2DI_HI_CONVERT:
37153       nargs = 5;
37154       rmode = V2DImode;
37155       mask_pos = 2;
37156       nargs_constant = 1;
37157       break;
37158     case V32QI_FTYPE_V32QI_V32QI_V32QI_SI:
37159     case V32HI_FTYPE_V32HI_V32HI_V32HI_SI:
37160     case V32HI_FTYPE_V64QI_V64QI_V32HI_SI:
37161     case V16SI_FTYPE_V32HI_V32HI_V16SI_HI:
37162     case V64QI_FTYPE_V64QI_V64QI_V64QI_DI:
37163     case V32HI_FTYPE_V32HI_V8HI_V32HI_SI:
37164     case V16HI_FTYPE_V16HI_V8HI_V16HI_HI:
37165     case V8SI_FTYPE_V8SI_V4SI_V8SI_QI:
37166     case V4DI_FTYPE_V4DI_V2DI_V4DI_QI:
37167     case V64QI_FTYPE_V32HI_V32HI_V64QI_DI:
37168     case V32QI_FTYPE_V16HI_V16HI_V32QI_SI:
37169     case V16QI_FTYPE_V8HI_V8HI_V16QI_HI:
37170     case V32HI_FTYPE_V16SI_V16SI_V32HI_SI:
37171     case V16HI_FTYPE_V8SI_V8SI_V16HI_HI:
37172     case V8HI_FTYPE_V4SI_V4SI_V8HI_QI:
37173     case V4DF_FTYPE_V4DF_V4DI_V4DF_QI:
37174     case V8SF_FTYPE_V8SF_V8SI_V8SF_QI:
37175     case V4SF_FTYPE_V4SF_V4SI_V4SF_QI:
37176     case V2DF_FTYPE_V2DF_V2DI_V2DF_QI:
37177     case V2DI_FTYPE_V4SI_V4SI_V2DI_QI:
37178     case V4DI_FTYPE_V8SI_V8SI_V4DI_QI:
37179     case V4DF_FTYPE_V4DI_V4DF_V4DF_QI:
37180     case V8SF_FTYPE_V8SI_V8SF_V8SF_QI:
37181     case V2DF_FTYPE_V2DI_V2DF_V2DF_QI:
37182     case V4SF_FTYPE_V4SI_V4SF_V4SF_QI:
37183     case V16SF_FTYPE_V16SF_V16SF_V16SF_HI:
37184     case V16SF_FTYPE_V16SF_V16SI_V16SF_HI:
37185     case V16SF_FTYPE_V16SI_V16SF_V16SF_HI:
37186     case V16SI_FTYPE_V16SI_V16SI_V16SI_HI:
37187     case V16SI_FTYPE_V16SI_V4SI_V16SI_HI:
37188     case V8HI_FTYPE_V8HI_V8HI_V8HI_QI:
37189     case V8SI_FTYPE_V8SI_V8SI_V8SI_QI:
37190     case V4SI_FTYPE_V4SI_V4SI_V4SI_QI:
37191     case V8SF_FTYPE_V8SF_V8SF_V8SF_QI:
37192     case V16QI_FTYPE_V16QI_V16QI_V16QI_HI:
37193     case V16HI_FTYPE_V16HI_V16HI_V16HI_HI:
37194     case V2DI_FTYPE_V2DI_V2DI_V2DI_QI:
37195     case V2DF_FTYPE_V2DF_V2DF_V2DF_QI:
37196     case V2DF_FTYPE_V2DF_V4SF_V2DF_QI:
37197     case V4DI_FTYPE_V4DI_V4DI_V4DI_QI:
37198     case V4DF_FTYPE_V4DF_V4DF_V4DF_QI:
37199     case V4SF_FTYPE_V4SF_V2DF_V4SF_QI:
37200     case V4SF_FTYPE_V4SF_V4SF_V4SF_QI:
37201     case V8DF_FTYPE_V8DF_V8DF_V8DF_QI:
37202     case V8DF_FTYPE_V8DF_V8DI_V8DF_QI:
37203     case V8DF_FTYPE_V8DI_V8DF_V8DF_QI:
37204     case V8DI_FTYPE_V16SI_V16SI_V8DI_QI:
37205     case V8DI_FTYPE_V8DI_SI_V8DI_V8DI:
37206     case V8DI_FTYPE_V8DI_V2DI_V8DI_QI:
37207     case V8DI_FTYPE_V8DI_V8DI_V8DI_QI:
37208     case V8HI_FTYPE_V16QI_V16QI_V8HI_QI:
37209     case V16HI_FTYPE_V32QI_V32QI_V16HI_HI:
37210     case V8SI_FTYPE_V16HI_V16HI_V8SI_QI:
37211     case V4SI_FTYPE_V8HI_V8HI_V4SI_QI:
37212       nargs = 4;
37213       break;
37214     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
37215     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
37216     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
37217     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
37218     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT:
37219       nargs = 4;
37220       nargs_constant = 1;
37221       break;
37222     case QI_FTYPE_V4DI_V4DI_INT_QI:
37223     case QI_FTYPE_V8SI_V8SI_INT_QI:
37224     case QI_FTYPE_V4DF_V4DF_INT_QI:
37225     case QI_FTYPE_V8SF_V8SF_INT_QI:
37226     case QI_FTYPE_V2DI_V2DI_INT_QI:
37227     case QI_FTYPE_V4SI_V4SI_INT_QI:
37228     case QI_FTYPE_V2DF_V2DF_INT_QI:
37229     case QI_FTYPE_V4SF_V4SF_INT_QI:
37230     case DI_FTYPE_V64QI_V64QI_INT_DI:
37231     case SI_FTYPE_V32QI_V32QI_INT_SI:
37232     case HI_FTYPE_V16QI_V16QI_INT_HI:
37233     case SI_FTYPE_V32HI_V32HI_INT_SI:
37234     case HI_FTYPE_V16HI_V16HI_INT_HI:
37235     case QI_FTYPE_V8HI_V8HI_INT_QI:
37236       nargs = 4;
37237       mask_pos = 1;
37238       nargs_constant = 1;
37239       break;
37240     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
37241       nargs = 4;
37242       nargs_constant = 2;
37243       break;
37244     case UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED:
37245     case UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG:
37246       nargs = 4;
37247       break;
37248     case QI_FTYPE_V8DI_V8DI_INT_QI:
37249     case HI_FTYPE_V16SI_V16SI_INT_HI:
37250     case QI_FTYPE_V8DF_V8DF_INT_QI:
37251     case HI_FTYPE_V16SF_V16SF_INT_HI:
37252       mask_pos = 1;
37253       nargs = 4;
37254       nargs_constant = 1;
37255       break;
37256     case V8SF_FTYPE_V8SF_INT_V8SF_QI:
37257     case V4SF_FTYPE_V4SF_INT_V4SF_QI:
37258     case V2DF_FTYPE_V4DF_INT_V2DF_QI:
37259     case V2DI_FTYPE_V4DI_INT_V2DI_QI:
37260     case V8SF_FTYPE_V16SF_INT_V8SF_QI:
37261     case V8SI_FTYPE_V16SI_INT_V8SI_QI:
37262     case V2DF_FTYPE_V8DF_INT_V2DF_QI:
37263     case V2DI_FTYPE_V8DI_INT_V2DI_QI:
37264     case V4SF_FTYPE_V8SF_INT_V4SF_QI:
37265     case V4SI_FTYPE_V8SI_INT_V4SI_QI:
37266     case V8HI_FTYPE_V8SF_INT_V8HI_QI:
37267     case V8HI_FTYPE_V4SF_INT_V8HI_QI:
37268     case V32HI_FTYPE_V32HI_INT_V32HI_SI:
37269     case V16HI_FTYPE_V16HI_INT_V16HI_HI:
37270     case V8HI_FTYPE_V8HI_INT_V8HI_QI:
37271     case V4DI_FTYPE_V4DI_INT_V4DI_QI:
37272     case V2DI_FTYPE_V2DI_INT_V2DI_QI:
37273     case V8SI_FTYPE_V8SI_INT_V8SI_QI:
37274     case V4SI_FTYPE_V4SI_INT_V4SI_QI:
37275     case V4DF_FTYPE_V4DF_INT_V4DF_QI:
37276     case V2DF_FTYPE_V2DF_INT_V2DF_QI:
37277     case V8DF_FTYPE_V8DF_INT_V8DF_QI:
37278     case V16SF_FTYPE_V16SF_INT_V16SF_HI:
37279     case V16HI_FTYPE_V16SF_INT_V16HI_HI:
37280     case V16SI_FTYPE_V16SI_INT_V16SI_HI:
37281     case V4SI_FTYPE_V16SI_INT_V4SI_QI:
37282     case V4DI_FTYPE_V8DI_INT_V4DI_QI:
37283     case V4DF_FTYPE_V8DF_INT_V4DF_QI:
37284     case V4SF_FTYPE_V16SF_INT_V4SF_QI:
37285     case V8DI_FTYPE_V8DI_INT_V8DI_QI:
37286       nargs = 4;
37287       mask_pos = 2;
37288       nargs_constant = 1;
37289       break;
37290     case V16SF_FTYPE_V16SF_V4SF_INT_V16SF_HI:
37291     case V16SI_FTYPE_V16SI_V4SI_INT_V16SI_HI:
37292     case V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI:
37293     case V8DI_FTYPE_V8DI_V8DI_INT_V8DI_QI:
37294     case V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI:
37295     case V16SI_FTYPE_V16SI_V16SI_INT_V16SI_HI:
37296     case V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI:
37297     case V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI:
37298     case V8DF_FTYPE_V8DF_V4DF_INT_V8DF_QI:
37299     case V8DI_FTYPE_V8DI_V4DI_INT_V8DI_QI:
37300     case V4DF_FTYPE_V4DF_V4DF_INT_V4DF_QI:
37301     case V8SF_FTYPE_V8SF_V8SF_INT_V8SF_QI:
37302     case V8DF_FTYPE_V8DF_V2DF_INT_V8DF_QI:
37303     case V8DI_FTYPE_V8DI_V2DI_INT_V8DI_QI:
37304     case V8SI_FTYPE_V8SI_V8SI_INT_V8SI_QI:
37305     case V4DI_FTYPE_V4DI_V4DI_INT_V4DI_QI:
37306     case V4SI_FTYPE_V4SI_V4SI_INT_V4SI_QI:
37307     case V2DI_FTYPE_V2DI_V2DI_INT_V2DI_QI:
37308     case V32HI_FTYPE_V64QI_V64QI_INT_V32HI_SI:
37309     case V16HI_FTYPE_V32QI_V32QI_INT_V16HI_HI:
37310     case V8HI_FTYPE_V16QI_V16QI_INT_V8HI_QI:
37311     case V16SF_FTYPE_V16SF_V8SF_INT_V16SF_HI:
37312     case V16SI_FTYPE_V16SI_V8SI_INT_V16SI_HI:
37313     case V8SF_FTYPE_V8SF_V4SF_INT_V8SF_QI:
37314     case V8SI_FTYPE_V8SI_V4SI_INT_V8SI_QI:
37315     case V4DI_FTYPE_V4DI_V2DI_INT_V4DI_QI:
37316     case V4DF_FTYPE_V4DF_V2DF_INT_V4DF_QI:
37317       nargs = 5;
37318       mask_pos = 2;
37319       nargs_constant = 1;
37320       break;
37321     case V8DI_FTYPE_V8DI_V8DI_V8DI_INT_QI:
37322     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI:
37323     case V16SI_FTYPE_V16SI_V16SI_V16SI_INT_HI:
37324     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI:
37325     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI:
37326     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT_QI:
37327     case V8SI_FTYPE_V8SI_V8SI_V8SI_INT_QI:
37328     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT_QI:
37329     case V4DI_FTYPE_V4DI_V4DI_V4DI_INT_QI:
37330     case V4SI_FTYPE_V4SI_V4SI_V4SI_INT_QI:
37331     case V2DI_FTYPE_V2DI_V2DI_V2DI_INT_QI:
37332        nargs = 5;
37333       nargs = 5;
37334       mask_pos = 1;
37335       nargs_constant = 1;
37336       break;
37337
37338     default:
37339       gcc_unreachable ();
37340     }
37341
37342   gcc_assert (nargs <= ARRAY_SIZE (args));
37343
37344   if (comparison != UNKNOWN)
37345     {
37346       gcc_assert (nargs == 2);
37347       return ix86_expand_sse_compare (d, exp, target, swap);
37348     }
37349
37350   if (rmode == VOIDmode || rmode == tmode)
37351     {
37352       if (optimize
37353           || target == 0
37354           || GET_MODE (target) != tmode
37355           || !insn_p->operand[0].predicate (target, tmode))
37356         target = gen_reg_rtx (tmode);
37357       real_target = target;
37358     }
37359   else
37360     {
37361       real_target = gen_reg_rtx (tmode);
37362       target = simplify_gen_subreg (rmode, real_target, tmode, 0);
37363     }
37364
37365   for (i = 0; i < nargs; i++)
37366     {
37367       tree arg = CALL_EXPR_ARG (exp, i);
37368       rtx op = expand_normal (arg);
37369       machine_mode mode = insn_p->operand[i + 1].mode;
37370       bool match = insn_p->operand[i + 1].predicate (op, mode);
37371
37372       if (last_arg_count && (i + 1) == nargs)
37373         {
37374           /* SIMD shift insns take either an 8-bit immediate or
37375              register as count.  But builtin functions take int as
37376              count.  If count doesn't match, we put it in register.  */
37377           if (!match)
37378             {
37379               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
37380               if (!insn_p->operand[i + 1].predicate (op, mode))
37381                 op = copy_to_reg (op);
37382             }
37383         }
37384       else if ((mask_pos && (nargs - i - mask_pos) == nargs_constant) ||
37385                (!mask_pos && (nargs - i) <= nargs_constant))
37386         {
37387           if (!match)
37388             switch (icode)
37389               {
37390               case CODE_FOR_avx_vinsertf128v4di:
37391               case CODE_FOR_avx_vextractf128v4di:
37392                 error ("the last argument must be an 1-bit immediate");
37393                 return const0_rtx;
37394
37395               case CODE_FOR_avx512f_cmpv8di3_mask:
37396               case CODE_FOR_avx512f_cmpv16si3_mask:
37397               case CODE_FOR_avx512f_ucmpv8di3_mask:
37398               case CODE_FOR_avx512f_ucmpv16si3_mask:
37399               case CODE_FOR_avx512vl_cmpv4di3_mask:
37400               case CODE_FOR_avx512vl_cmpv8si3_mask:
37401               case CODE_FOR_avx512vl_ucmpv4di3_mask:
37402               case CODE_FOR_avx512vl_ucmpv8si3_mask:
37403               case CODE_FOR_avx512vl_cmpv2di3_mask:
37404               case CODE_FOR_avx512vl_cmpv4si3_mask:
37405               case CODE_FOR_avx512vl_ucmpv2di3_mask:
37406               case CODE_FOR_avx512vl_ucmpv4si3_mask:
37407                 error ("the last argument must be a 3-bit immediate");
37408                 return const0_rtx;
37409
37410               case CODE_FOR_sse4_1_roundsd:
37411               case CODE_FOR_sse4_1_roundss:
37412
37413               case CODE_FOR_sse4_1_roundpd:
37414               case CODE_FOR_sse4_1_roundps:
37415               case CODE_FOR_avx_roundpd256:
37416               case CODE_FOR_avx_roundps256:
37417
37418               case CODE_FOR_sse4_1_roundpd_vec_pack_sfix:
37419               case CODE_FOR_sse4_1_roundps_sfix:
37420               case CODE_FOR_avx_roundpd_vec_pack_sfix256:
37421               case CODE_FOR_avx_roundps_sfix256:
37422
37423               case CODE_FOR_sse4_1_blendps:
37424               case CODE_FOR_avx_blendpd256:
37425               case CODE_FOR_avx_vpermilv4df:
37426               case CODE_FOR_avx_vpermilv4df_mask:
37427               case CODE_FOR_avx512f_getmantv8df_mask:
37428               case CODE_FOR_avx512f_getmantv16sf_mask:
37429               case CODE_FOR_avx512vl_getmantv8sf_mask:
37430               case CODE_FOR_avx512vl_getmantv4df_mask:
37431               case CODE_FOR_avx512vl_getmantv4sf_mask:
37432               case CODE_FOR_avx512vl_getmantv2df_mask:
37433               case CODE_FOR_avx512dq_rangepv8df_mask_round:
37434               case CODE_FOR_avx512dq_rangepv16sf_mask_round:
37435               case CODE_FOR_avx512dq_rangepv4df_mask:
37436               case CODE_FOR_avx512dq_rangepv8sf_mask:
37437               case CODE_FOR_avx512dq_rangepv2df_mask:
37438               case CODE_FOR_avx512dq_rangepv4sf_mask:
37439               case CODE_FOR_avx_shufpd256_mask:
37440                 error ("the last argument must be a 4-bit immediate");
37441                 return const0_rtx;
37442
37443               case CODE_FOR_sha1rnds4:
37444               case CODE_FOR_sse4_1_blendpd:
37445               case CODE_FOR_avx_vpermilv2df:
37446               case CODE_FOR_avx_vpermilv2df_mask:
37447               case CODE_FOR_xop_vpermil2v2df3:
37448               case CODE_FOR_xop_vpermil2v4sf3:
37449               case CODE_FOR_xop_vpermil2v4df3:
37450               case CODE_FOR_xop_vpermil2v8sf3:
37451               case CODE_FOR_avx512f_vinsertf32x4_mask:
37452               case CODE_FOR_avx512f_vinserti32x4_mask:
37453               case CODE_FOR_avx512f_vextractf32x4_mask:
37454               case CODE_FOR_avx512f_vextracti32x4_mask:
37455               case CODE_FOR_sse2_shufpd:
37456               case CODE_FOR_sse2_shufpd_mask:
37457               case CODE_FOR_avx512dq_shuf_f64x2_mask:
37458               case CODE_FOR_avx512dq_shuf_i64x2_mask:
37459               case CODE_FOR_avx512vl_shuf_i32x4_mask:
37460               case CODE_FOR_avx512vl_shuf_f32x4_mask:
37461                 error ("the last argument must be a 2-bit immediate");
37462                 return const0_rtx;
37463
37464               case CODE_FOR_avx_vextractf128v4df:
37465               case CODE_FOR_avx_vextractf128v8sf:
37466               case CODE_FOR_avx_vextractf128v8si:
37467               case CODE_FOR_avx_vinsertf128v4df:
37468               case CODE_FOR_avx_vinsertf128v8sf:
37469               case CODE_FOR_avx_vinsertf128v8si:
37470               case CODE_FOR_avx512f_vinsertf64x4_mask:
37471               case CODE_FOR_avx512f_vinserti64x4_mask:
37472               case CODE_FOR_avx512f_vextractf64x4_mask:
37473               case CODE_FOR_avx512f_vextracti64x4_mask:
37474               case CODE_FOR_avx512dq_vinsertf32x8_mask:
37475               case CODE_FOR_avx512dq_vinserti32x8_mask:
37476               case CODE_FOR_avx512vl_vinsertv4df:
37477               case CODE_FOR_avx512vl_vinsertv4di:
37478               case CODE_FOR_avx512vl_vinsertv8sf:
37479               case CODE_FOR_avx512vl_vinsertv8si:
37480                 error ("the last argument must be a 1-bit immediate");
37481                 return const0_rtx;
37482
37483               case CODE_FOR_avx_vmcmpv2df3:
37484               case CODE_FOR_avx_vmcmpv4sf3:
37485               case CODE_FOR_avx_cmpv2df3:
37486               case CODE_FOR_avx_cmpv4sf3:
37487               case CODE_FOR_avx_cmpv4df3:
37488               case CODE_FOR_avx_cmpv8sf3:
37489               case CODE_FOR_avx512f_cmpv8df3_mask:
37490               case CODE_FOR_avx512f_cmpv16sf3_mask:
37491               case CODE_FOR_avx512f_vmcmpv2df3_mask:
37492               case CODE_FOR_avx512f_vmcmpv4sf3_mask:
37493                 error ("the last argument must be a 5-bit immediate");
37494                 return const0_rtx;
37495
37496               default:
37497                 switch (nargs_constant)
37498                   {
37499                   case 2:
37500                     if ((mask_pos && (nargs - i - mask_pos) == nargs_constant) ||
37501                         (!mask_pos && (nargs - i) == nargs_constant))
37502                       {
37503                         error ("the next to last argument must be an 8-bit immediate");
37504                         break;
37505                       }
37506                   case 1:
37507                     error ("the last argument must be an 8-bit immediate");
37508                     break;
37509                   default:
37510                     gcc_unreachable ();
37511                   }
37512                 return const0_rtx;
37513               }
37514         }
37515       else
37516         {
37517           if (VECTOR_MODE_P (mode))
37518             op = safe_vector_operand (op, mode);
37519
37520           /* If we aren't optimizing, only allow one memory operand to
37521              be generated.  */
37522           if (memory_operand (op, mode))
37523             num_memory++;
37524
37525           op = fixup_modeless_constant (op, mode);
37526
37527           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
37528             {
37529               if (optimize || !match || num_memory > 1)
37530                 op = copy_to_mode_reg (mode, op);
37531             }
37532           else
37533             {
37534               op = copy_to_reg (op);
37535               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
37536             }
37537         }
37538
37539       args[i].op = op;
37540       args[i].mode = mode;
37541     }
37542
37543   switch (nargs)
37544     {
37545     case 1:
37546       pat = GEN_FCN (icode) (real_target, args[0].op);
37547       break;
37548     case 2:
37549       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
37550       break;
37551     case 3:
37552       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37553                              args[2].op);
37554       break;
37555     case 4:
37556       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37557                              args[2].op, args[3].op);
37558       break;
37559     case 5:
37560       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37561                              args[2].op, args[3].op, args[4].op);
37562     case 6:
37563       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37564                              args[2].op, args[3].op, args[4].op,
37565                              args[5].op);
37566       break;
37567     default:
37568       gcc_unreachable ();
37569     }
37570
37571   if (! pat)
37572     return 0;
37573
37574   emit_insn (pat);
37575   return target;
37576 }
37577
37578 /* Transform pattern of following layout:
37579      (parallel [
37580        set (A B)
37581        (unspec [C] UNSPEC_EMBEDDED_ROUNDING)])
37582      ])
37583    into:
37584      (set (A B))
37585
37586    Or:
37587      (parallel [ A B
37588      ...
37589      (unspec [C] UNSPEC_EMBEDDED_ROUNDING)
37590      ...
37591      ])
37592    into:
37593      (parallel [ A B ... ])  */
37594
37595 static rtx
37596 ix86_erase_embedded_rounding (rtx pat)
37597 {
37598   if (GET_CODE (pat) == INSN)
37599     pat = PATTERN (pat);
37600
37601   gcc_assert (GET_CODE (pat) == PARALLEL);
37602
37603   if (XVECLEN (pat, 0) == 2)
37604     {
37605       rtx p0 = XVECEXP (pat, 0, 0);
37606       rtx p1 = XVECEXP (pat, 0, 1);
37607
37608       gcc_assert (GET_CODE (p0) == SET
37609                   && GET_CODE (p1) == UNSPEC
37610                   && XINT (p1, 1) == UNSPEC_EMBEDDED_ROUNDING);
37611
37612       return p0;
37613     }
37614   else
37615     {
37616       rtx *res = XALLOCAVEC (rtx, XVECLEN (pat, 0));
37617       int i = 0;
37618       int j = 0;
37619
37620       for (; i < XVECLEN (pat, 0); ++i)
37621         {
37622           rtx elem = XVECEXP (pat, 0, i);
37623           if (GET_CODE (elem) != UNSPEC
37624               || XINT (elem, 1) != UNSPEC_EMBEDDED_ROUNDING)
37625             res [j++] = elem;
37626         }
37627
37628       /*  No more than 1 occurence was removed.  */
37629       gcc_assert (j >= XVECLEN (pat, 0) - 1);
37630
37631       return gen_rtx_PARALLEL (GET_MODE (pat), gen_rtvec_v (j, res));
37632     }
37633 }
37634
37635 /* Subroutine of ix86_expand_round_builtin to take care of comi insns
37636    with rounding.  */
37637 static rtx
37638 ix86_expand_sse_comi_round (const struct builtin_description *d,
37639                             tree exp, rtx target)
37640 {
37641   rtx pat, set_dst;
37642   tree arg0 = CALL_EXPR_ARG (exp, 0);
37643   tree arg1 = CALL_EXPR_ARG (exp, 1);
37644   tree arg2 = CALL_EXPR_ARG (exp, 2);
37645   tree arg3 = CALL_EXPR_ARG (exp, 3);
37646   rtx op0 = expand_normal (arg0);
37647   rtx op1 = expand_normal (arg1);
37648   rtx op2 = expand_normal (arg2);
37649   rtx op3 = expand_normal (arg3);
37650   enum insn_code icode = d->icode;
37651   const struct insn_data_d *insn_p = &insn_data[icode];
37652   machine_mode mode0 = insn_p->operand[0].mode;
37653   machine_mode mode1 = insn_p->operand[1].mode;
37654   enum rtx_code comparison = UNEQ;
37655   bool need_ucomi = false;
37656
37657   /* See avxintrin.h for values.  */
37658   enum rtx_code comi_comparisons[32] =
37659     {
37660       UNEQ, GT, GE, UNORDERED, LTGT, UNLE, UNLT, ORDERED, UNEQ, UNLT,
37661       UNLE, LT, LTGT, GE, GT, LT, UNEQ, GT, GE, UNORDERED, LTGT, UNLE,
37662       UNLT, ORDERED, UNEQ, UNLT, UNLE, LT, LTGT, GE, GT, LT
37663     };
37664   bool need_ucomi_values[32] =
37665     {
37666       true,  false, false, true,  true,  false, false, true,
37667       true,  false, false, true,  true,  false, false, true,
37668       false, true,  true,  false, false, true,  true,  false,
37669       false, true,  true,  false, false, true,  true,  false
37670     };
37671
37672   if (!CONST_INT_P (op2))
37673     {
37674       error ("the third argument must be comparison constant");
37675       return const0_rtx;
37676     }
37677   if (INTVAL (op2) < 0 || INTVAL (op2) >= 32)
37678     {
37679       error ("incorrect comparison mode");
37680       return const0_rtx;
37681     }
37682
37683   if (!insn_p->operand[2].predicate (op3, SImode))
37684     {
37685       error ("incorrect rounding operand");
37686       return const0_rtx;
37687     }
37688
37689   comparison = comi_comparisons[INTVAL (op2)];
37690   need_ucomi = need_ucomi_values[INTVAL (op2)];
37691
37692   if (VECTOR_MODE_P (mode0))
37693     op0 = safe_vector_operand (op0, mode0);
37694   if (VECTOR_MODE_P (mode1))
37695     op1 = safe_vector_operand (op1, mode1);
37696
37697   target = gen_reg_rtx (SImode);
37698   emit_move_insn (target, const0_rtx);
37699   target = gen_rtx_SUBREG (QImode, target, 0);
37700
37701   if ((optimize && !register_operand (op0, mode0))
37702       || !insn_p->operand[0].predicate (op0, mode0))
37703     op0 = copy_to_mode_reg (mode0, op0);
37704   if ((optimize && !register_operand (op1, mode1))
37705       || !insn_p->operand[1].predicate (op1, mode1))
37706     op1 = copy_to_mode_reg (mode1, op1);
37707
37708   if (need_ucomi)
37709     icode = icode == CODE_FOR_sse_comi_round
37710                      ? CODE_FOR_sse_ucomi_round
37711                      : CODE_FOR_sse2_ucomi_round;
37712
37713   pat = GEN_FCN (icode) (op0, op1, op3);
37714   if (! pat)
37715     return 0;
37716
37717   /* Rounding operand can be either NO_ROUND or ROUND_SAE at this point.  */
37718   if (INTVAL (op3) == NO_ROUND)
37719     {
37720       pat = ix86_erase_embedded_rounding (pat);
37721       if (! pat)
37722         return 0;
37723
37724       set_dst = SET_DEST (pat);
37725     }
37726   else
37727     {
37728       gcc_assert (GET_CODE (XVECEXP (pat, 0, 0)) == SET);
37729       set_dst = SET_DEST (XVECEXP (pat, 0, 0));
37730     }
37731
37732   emit_insn (pat);
37733   emit_insn (gen_rtx_SET (gen_rtx_STRICT_LOW_PART (VOIDmode, target),
37734                           gen_rtx_fmt_ee (comparison, QImode,
37735                                           set_dst,
37736                                           const0_rtx)));
37737
37738   return SUBREG_REG (target);
37739 }
37740
37741 static rtx
37742 ix86_expand_round_builtin (const struct builtin_description *d,
37743                            tree exp, rtx target)
37744 {
37745   rtx pat;
37746   unsigned int i, nargs;
37747   struct
37748     {
37749       rtx op;
37750       machine_mode mode;
37751     } args[6];
37752   enum insn_code icode = d->icode;
37753   const struct insn_data_d *insn_p = &insn_data[icode];
37754   machine_mode tmode = insn_p->operand[0].mode;
37755   unsigned int nargs_constant = 0;
37756   unsigned int redundant_embed_rnd = 0;
37757
37758   switch ((enum ix86_builtin_func_type) d->flag)
37759     {
37760     case UINT64_FTYPE_V2DF_INT:
37761     case UINT64_FTYPE_V4SF_INT:
37762     case UINT_FTYPE_V2DF_INT:
37763     case UINT_FTYPE_V4SF_INT:
37764     case INT64_FTYPE_V2DF_INT:
37765     case INT64_FTYPE_V4SF_INT:
37766     case INT_FTYPE_V2DF_INT:
37767     case INT_FTYPE_V4SF_INT:
37768       nargs = 2;
37769       break;
37770     case V4SF_FTYPE_V4SF_UINT_INT:
37771     case V4SF_FTYPE_V4SF_UINT64_INT:
37772     case V2DF_FTYPE_V2DF_UINT64_INT:
37773     case V4SF_FTYPE_V4SF_INT_INT:
37774     case V4SF_FTYPE_V4SF_INT64_INT:
37775     case V2DF_FTYPE_V2DF_INT64_INT:
37776     case V4SF_FTYPE_V4SF_V4SF_INT:
37777     case V2DF_FTYPE_V2DF_V2DF_INT:
37778     case V4SF_FTYPE_V4SF_V2DF_INT:
37779     case V2DF_FTYPE_V2DF_V4SF_INT:
37780       nargs = 3;
37781       break;
37782     case V8SF_FTYPE_V8DF_V8SF_QI_INT:
37783     case V8DF_FTYPE_V8DF_V8DF_QI_INT:
37784     case V8SI_FTYPE_V8DF_V8SI_QI_INT:
37785     case V8DI_FTYPE_V8DF_V8DI_QI_INT:
37786     case V8SF_FTYPE_V8DI_V8SF_QI_INT:
37787     case V8DF_FTYPE_V8DI_V8DF_QI_INT:
37788     case V16SF_FTYPE_V16SF_V16SF_HI_INT:
37789     case V8DI_FTYPE_V8SF_V8DI_QI_INT:
37790     case V16SF_FTYPE_V16SI_V16SF_HI_INT:
37791     case V16SI_FTYPE_V16SF_V16SI_HI_INT:
37792     case V8DF_FTYPE_V8SF_V8DF_QI_INT:
37793     case V16SF_FTYPE_V16HI_V16SF_HI_INT:
37794     case V2DF_FTYPE_V2DF_V2DF_V2DF_INT:
37795     case V4SF_FTYPE_V4SF_V4SF_V4SF_INT:
37796       nargs = 4;
37797       break;
37798     case V4SF_FTYPE_V4SF_V4SF_INT_INT:
37799     case V2DF_FTYPE_V2DF_V2DF_INT_INT:
37800       nargs_constant = 2;
37801       nargs = 4;
37802       break;
37803     case INT_FTYPE_V4SF_V4SF_INT_INT:
37804     case INT_FTYPE_V2DF_V2DF_INT_INT:
37805       return ix86_expand_sse_comi_round (d, exp, target);
37806     case V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT:
37807     case V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT:
37808     case V2DF_FTYPE_V2DF_V2DF_V2DF_QI_INT:
37809     case V2DF_FTYPE_V2DF_V4SF_V2DF_QI_INT:
37810     case V4SF_FTYPE_V4SF_V4SF_V4SF_QI_INT:
37811     case V4SF_FTYPE_V4SF_V2DF_V4SF_QI_INT:
37812       nargs = 5;
37813       break;
37814     case V16SF_FTYPE_V16SF_INT_V16SF_HI_INT:
37815     case V8DF_FTYPE_V8DF_INT_V8DF_QI_INT:
37816       nargs_constant = 4;
37817       nargs = 5;
37818       break;
37819     case QI_FTYPE_V8DF_V8DF_INT_QI_INT:
37820     case QI_FTYPE_V2DF_V2DF_INT_QI_INT:
37821     case HI_FTYPE_V16SF_V16SF_INT_HI_INT:
37822     case QI_FTYPE_V4SF_V4SF_INT_QI_INT:
37823       nargs_constant = 3;
37824       nargs = 5;
37825       break;
37826     case V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI_INT:
37827     case V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI_INT:
37828     case V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI_INT:
37829     case V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI_INT:
37830       nargs = 6;
37831       nargs_constant = 4;
37832       break;
37833     case V8DF_FTYPE_V8DF_V8DF_V8DI_INT_QI_INT:
37834     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI_INT:
37835     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI_INT:
37836     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI_INT:
37837       nargs = 6;
37838       nargs_constant = 3;
37839       break;
37840     default:
37841       gcc_unreachable ();
37842     }
37843   gcc_assert (nargs <= ARRAY_SIZE (args));
37844
37845   if (optimize
37846       || target == 0
37847       || GET_MODE (target) != tmode
37848       || !insn_p->operand[0].predicate (target, tmode))
37849     target = gen_reg_rtx (tmode);
37850
37851   for (i = 0; i < nargs; i++)
37852     {
37853       tree arg = CALL_EXPR_ARG (exp, i);
37854       rtx op = expand_normal (arg);
37855       machine_mode mode = insn_p->operand[i + 1].mode;
37856       bool match = insn_p->operand[i + 1].predicate (op, mode);
37857
37858       if (i == nargs - nargs_constant)
37859         {
37860           if (!match)
37861             {
37862               switch (icode)
37863                 {
37864                 case CODE_FOR_avx512f_getmantv8df_mask_round:
37865                 case CODE_FOR_avx512f_getmantv16sf_mask_round:
37866                 case CODE_FOR_avx512f_vgetmantv2df_round:
37867                 case CODE_FOR_avx512f_vgetmantv4sf_round:
37868                   error ("the immediate argument must be a 4-bit immediate");
37869                   return const0_rtx;
37870                 case CODE_FOR_avx512f_cmpv8df3_mask_round:
37871                 case CODE_FOR_avx512f_cmpv16sf3_mask_round:
37872                 case CODE_FOR_avx512f_vmcmpv2df3_mask_round:
37873                 case CODE_FOR_avx512f_vmcmpv4sf3_mask_round:
37874                   error ("the immediate argument must be a 5-bit immediate");
37875                   return const0_rtx;
37876                 default:
37877                   error ("the immediate argument must be an 8-bit immediate");
37878                   return const0_rtx;
37879                 }
37880             }
37881         }
37882       else if (i == nargs-1)
37883         {
37884           if (!insn_p->operand[nargs].predicate (op, SImode))
37885             {
37886               error ("incorrect rounding operand");
37887               return const0_rtx;
37888             }
37889
37890           /* If there is no rounding use normal version of the pattern.  */
37891           if (INTVAL (op) == NO_ROUND)
37892             redundant_embed_rnd = 1;
37893         }
37894       else
37895         {
37896           if (VECTOR_MODE_P (mode))
37897             op = safe_vector_operand (op, mode);
37898
37899           op = fixup_modeless_constant (op, mode);
37900
37901           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
37902             {
37903               if (optimize || !match)
37904                 op = copy_to_mode_reg (mode, op);
37905             }
37906           else
37907             {
37908               op = copy_to_reg (op);
37909               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
37910             }
37911         }
37912
37913       args[i].op = op;
37914       args[i].mode = mode;
37915     }
37916
37917   switch (nargs)
37918     {
37919     case 1:
37920       pat = GEN_FCN (icode) (target, args[0].op);
37921       break;
37922     case 2:
37923       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
37924       break;
37925     case 3:
37926       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37927                              args[2].op);
37928       break;
37929     case 4:
37930       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37931                              args[2].op, args[3].op);
37932       break;
37933     case 5:
37934       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37935                              args[2].op, args[3].op, args[4].op);
37936     case 6:
37937       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37938                              args[2].op, args[3].op, args[4].op,
37939                              args[5].op);
37940       break;
37941     default:
37942       gcc_unreachable ();
37943     }
37944
37945   if (!pat)
37946     return 0;
37947
37948   if (redundant_embed_rnd)
37949     pat = ix86_erase_embedded_rounding (pat);
37950
37951   emit_insn (pat);
37952   return target;
37953 }
37954
37955 /* Subroutine of ix86_expand_builtin to take care of special insns
37956    with variable number of operands.  */
37957
37958 static rtx
37959 ix86_expand_special_args_builtin (const struct builtin_description *d,
37960                                   tree exp, rtx target)
37961 {
37962   tree arg;
37963   rtx pat, op;
37964   unsigned int i, nargs, arg_adjust, memory;
37965   bool aligned_mem = false;
37966   struct
37967     {
37968       rtx op;
37969       machine_mode mode;
37970     } args[3];
37971   enum insn_code icode = d->icode;
37972   bool last_arg_constant = false;
37973   const struct insn_data_d *insn_p = &insn_data[icode];
37974   machine_mode tmode = insn_p->operand[0].mode;
37975   enum { load, store } klass;
37976
37977   switch ((enum ix86_builtin_func_type) d->flag)
37978     {
37979     case VOID_FTYPE_VOID:
37980       emit_insn (GEN_FCN (icode) (target));
37981       return 0;
37982     case VOID_FTYPE_UINT64:
37983     case VOID_FTYPE_UNSIGNED:
37984       nargs = 0;
37985       klass = store;
37986       memory = 0;
37987       break;
37988
37989     case INT_FTYPE_VOID:
37990     case USHORT_FTYPE_VOID:
37991     case UINT64_FTYPE_VOID:
37992     case UNSIGNED_FTYPE_VOID:
37993       nargs = 0;
37994       klass = load;
37995       memory = 0;
37996       break;
37997     case UINT64_FTYPE_PUNSIGNED:
37998     case V2DI_FTYPE_PV2DI:
37999     case V4DI_FTYPE_PV4DI:
38000     case V32QI_FTYPE_PCCHAR:
38001     case V16QI_FTYPE_PCCHAR:
38002     case V8SF_FTYPE_PCV4SF:
38003     case V8SF_FTYPE_PCFLOAT:
38004     case V4SF_FTYPE_PCFLOAT:
38005     case V4DF_FTYPE_PCV2DF:
38006     case V4DF_FTYPE_PCDOUBLE:
38007     case V2DF_FTYPE_PCDOUBLE:
38008     case VOID_FTYPE_PVOID:
38009     case V16SI_FTYPE_PV4SI:
38010     case V16SF_FTYPE_PV4SF:
38011     case V8DI_FTYPE_PV4DI:
38012     case V8DI_FTYPE_PV8DI:
38013     case V8DF_FTYPE_PV4DF:
38014       nargs = 1;
38015       klass = load;
38016       memory = 0;
38017       switch (icode)
38018         {
38019         case CODE_FOR_sse4_1_movntdqa:
38020         case CODE_FOR_avx2_movntdqa:
38021         case CODE_FOR_avx512f_movntdqa:
38022           aligned_mem = true;
38023           break;
38024         default:
38025           break;
38026         }
38027       break;
38028     case VOID_FTYPE_PV2SF_V4SF:
38029     case VOID_FTYPE_PV8DI_V8DI:
38030     case VOID_FTYPE_PV4DI_V4DI:
38031     case VOID_FTYPE_PV2DI_V2DI:
38032     case VOID_FTYPE_PCHAR_V32QI:
38033     case VOID_FTYPE_PCHAR_V16QI:
38034     case VOID_FTYPE_PFLOAT_V16SF:
38035     case VOID_FTYPE_PFLOAT_V8SF:
38036     case VOID_FTYPE_PFLOAT_V4SF:
38037     case VOID_FTYPE_PDOUBLE_V8DF:
38038     case VOID_FTYPE_PDOUBLE_V4DF:
38039     case VOID_FTYPE_PDOUBLE_V2DF:
38040     case VOID_FTYPE_PLONGLONG_LONGLONG:
38041     case VOID_FTYPE_PULONGLONG_ULONGLONG:
38042     case VOID_FTYPE_PINT_INT:
38043       nargs = 1;
38044       klass = store;
38045       /* Reserve memory operand for target.  */
38046       memory = ARRAY_SIZE (args);
38047       switch (icode)
38048         {
38049         /* These builtins and instructions require the memory
38050            to be properly aligned.  */
38051         case CODE_FOR_avx_movntv4di:
38052         case CODE_FOR_sse2_movntv2di:
38053         case CODE_FOR_avx_movntv8sf:
38054         case CODE_FOR_sse_movntv4sf:
38055         case CODE_FOR_sse4a_vmmovntv4sf:
38056         case CODE_FOR_avx_movntv4df:
38057         case CODE_FOR_sse2_movntv2df:
38058         case CODE_FOR_sse4a_vmmovntv2df:
38059         case CODE_FOR_sse2_movntidi:
38060         case CODE_FOR_sse_movntq:
38061         case CODE_FOR_sse2_movntisi:
38062         case CODE_FOR_avx512f_movntv16sf:
38063         case CODE_FOR_avx512f_movntv8df:
38064         case CODE_FOR_avx512f_movntv8di:
38065           aligned_mem = true;
38066           break;
38067         default:
38068           break;
38069         }
38070       break;
38071     case V4SF_FTYPE_V4SF_PCV2SF:
38072     case V2DF_FTYPE_V2DF_PCDOUBLE:
38073       nargs = 2;
38074       klass = load;
38075       memory = 1;
38076       break;
38077     case V8SF_FTYPE_PCV8SF_V8SI:
38078     case V4DF_FTYPE_PCV4DF_V4DI:
38079     case V4SF_FTYPE_PCV4SF_V4SI:
38080     case V2DF_FTYPE_PCV2DF_V2DI:
38081     case V8SI_FTYPE_PCV8SI_V8SI:
38082     case V4DI_FTYPE_PCV4DI_V4DI:
38083     case V4SI_FTYPE_PCV4SI_V4SI:
38084     case V2DI_FTYPE_PCV2DI_V2DI:
38085       nargs = 2;
38086       klass = load;
38087       memory = 0;
38088       break;
38089     case VOID_FTYPE_PV8DF_V8DF_QI:
38090     case VOID_FTYPE_PV16SF_V16SF_HI:
38091     case VOID_FTYPE_PV8DI_V8DI_QI:
38092     case VOID_FTYPE_PV4DI_V4DI_QI:
38093     case VOID_FTYPE_PV2DI_V2DI_QI:
38094     case VOID_FTYPE_PV16SI_V16SI_HI:
38095     case VOID_FTYPE_PV8SI_V8SI_QI:
38096     case VOID_FTYPE_PV4SI_V4SI_QI:
38097       switch (icode)
38098         {
38099         /* These builtins and instructions require the memory
38100            to be properly aligned.  */
38101         case CODE_FOR_avx512f_storev16sf_mask:
38102         case CODE_FOR_avx512f_storev16si_mask:
38103         case CODE_FOR_avx512f_storev8df_mask:
38104         case CODE_FOR_avx512f_storev8di_mask:
38105         case CODE_FOR_avx512vl_storev8sf_mask:
38106         case CODE_FOR_avx512vl_storev8si_mask:
38107         case CODE_FOR_avx512vl_storev4df_mask:
38108         case CODE_FOR_avx512vl_storev4di_mask:
38109         case CODE_FOR_avx512vl_storev4sf_mask:
38110         case CODE_FOR_avx512vl_storev4si_mask:
38111         case CODE_FOR_avx512vl_storev2df_mask:
38112         case CODE_FOR_avx512vl_storev2di_mask:
38113           aligned_mem = true;
38114           break;
38115         default:
38116           break;
38117         }
38118       /* FALLTHRU */
38119     case VOID_FTYPE_PV8SF_V8SI_V8SF:
38120     case VOID_FTYPE_PV4DF_V4DI_V4DF:
38121     case VOID_FTYPE_PV4SF_V4SI_V4SF:
38122     case VOID_FTYPE_PV2DF_V2DI_V2DF:
38123     case VOID_FTYPE_PV8SI_V8SI_V8SI:
38124     case VOID_FTYPE_PV4DI_V4DI_V4DI:
38125     case VOID_FTYPE_PV4SI_V4SI_V4SI:
38126     case VOID_FTYPE_PV2DI_V2DI_V2DI:
38127     case VOID_FTYPE_PDOUBLE_V2DF_QI:
38128     case VOID_FTYPE_PFLOAT_V4SF_QI:
38129     case VOID_FTYPE_PV8SI_V8DI_QI:
38130     case VOID_FTYPE_PV8HI_V8DI_QI:
38131     case VOID_FTYPE_PV16HI_V16SI_HI:
38132     case VOID_FTYPE_PV16QI_V8DI_QI:
38133     case VOID_FTYPE_PV16QI_V16SI_HI:
38134     case VOID_FTYPE_PV4SI_V4DI_QI:
38135     case VOID_FTYPE_PV4SI_V2DI_QI:
38136     case VOID_FTYPE_PV8HI_V4DI_QI:
38137     case VOID_FTYPE_PV8HI_V2DI_QI:
38138     case VOID_FTYPE_PV8HI_V8SI_QI:
38139     case VOID_FTYPE_PV8HI_V4SI_QI:
38140     case VOID_FTYPE_PV16QI_V4DI_QI:
38141     case VOID_FTYPE_PV16QI_V2DI_QI:
38142     case VOID_FTYPE_PV16QI_V8SI_QI:
38143     case VOID_FTYPE_PV16QI_V4SI_QI:
38144     case VOID_FTYPE_PV8HI_V8HI_QI:
38145     case VOID_FTYPE_PV16HI_V16HI_HI:
38146     case VOID_FTYPE_PV32HI_V32HI_SI:
38147     case VOID_FTYPE_PV16QI_V16QI_HI:
38148     case VOID_FTYPE_PV32QI_V32QI_SI:
38149     case VOID_FTYPE_PV64QI_V64QI_DI:
38150     case VOID_FTYPE_PV4DF_V4DF_QI:
38151     case VOID_FTYPE_PV2DF_V2DF_QI:
38152     case VOID_FTYPE_PV8SF_V8SF_QI:
38153     case VOID_FTYPE_PV4SF_V4SF_QI:
38154       nargs = 2;
38155       klass = store;
38156       /* Reserve memory operand for target.  */
38157       memory = ARRAY_SIZE (args);
38158       break;
38159     case V4SF_FTYPE_PCV4SF_V4SF_QI:
38160     case V8SF_FTYPE_PCV8SF_V8SF_QI:
38161     case V16SF_FTYPE_PCV16SF_V16SF_HI:
38162     case V4SI_FTYPE_PCV4SI_V4SI_QI:
38163     case V8SI_FTYPE_PCV8SI_V8SI_QI:
38164     case V16SI_FTYPE_PCV16SI_V16SI_HI:
38165     case V2DF_FTYPE_PCV2DF_V2DF_QI:
38166     case V4DF_FTYPE_PCV4DF_V4DF_QI:
38167     case V8DF_FTYPE_PCV8DF_V8DF_QI:
38168     case V2DI_FTYPE_PCV2DI_V2DI_QI:
38169     case V4DI_FTYPE_PCV4DI_V4DI_QI:
38170     case V8DI_FTYPE_PCV8DI_V8DI_QI:
38171     case V2DF_FTYPE_PCDOUBLE_V2DF_QI:
38172     case V4SF_FTYPE_PCFLOAT_V4SF_QI:
38173     case V8HI_FTYPE_PCV8HI_V8HI_QI:
38174     case V16HI_FTYPE_PCV16HI_V16HI_HI:
38175     case V32HI_FTYPE_PCV32HI_V32HI_SI:
38176     case V16QI_FTYPE_PCV16QI_V16QI_HI:
38177     case V32QI_FTYPE_PCV32QI_V32QI_SI:
38178     case V64QI_FTYPE_PCV64QI_V64QI_DI:
38179       nargs = 3;
38180       klass = load;
38181       memory = 0;
38182       switch (icode)
38183         {
38184         /* These builtins and instructions require the memory
38185            to be properly aligned.  */
38186         case CODE_FOR_avx512f_loadv16sf_mask:
38187         case CODE_FOR_avx512f_loadv16si_mask:
38188         case CODE_FOR_avx512f_loadv8df_mask:
38189         case CODE_FOR_avx512f_loadv8di_mask:
38190         case CODE_FOR_avx512vl_loadv8sf_mask:
38191         case CODE_FOR_avx512vl_loadv8si_mask:
38192         case CODE_FOR_avx512vl_loadv4df_mask:
38193         case CODE_FOR_avx512vl_loadv4di_mask:
38194         case CODE_FOR_avx512vl_loadv4sf_mask:
38195         case CODE_FOR_avx512vl_loadv4si_mask:
38196         case CODE_FOR_avx512vl_loadv2df_mask:
38197         case CODE_FOR_avx512vl_loadv2di_mask:
38198         case CODE_FOR_avx512bw_loadv64qi_mask:
38199         case CODE_FOR_avx512vl_loadv32qi_mask:
38200         case CODE_FOR_avx512vl_loadv16qi_mask:
38201         case CODE_FOR_avx512bw_loadv32hi_mask:
38202         case CODE_FOR_avx512vl_loadv16hi_mask:
38203         case CODE_FOR_avx512vl_loadv8hi_mask:
38204           aligned_mem = true;
38205           break;
38206         default:
38207           break;
38208         }
38209       break;
38210     case VOID_FTYPE_UINT_UINT_UINT:
38211     case VOID_FTYPE_UINT64_UINT_UINT:
38212     case UCHAR_FTYPE_UINT_UINT_UINT:
38213     case UCHAR_FTYPE_UINT64_UINT_UINT:
38214       nargs = 3;
38215       klass = load;
38216       memory = ARRAY_SIZE (args);
38217       last_arg_constant = true;
38218       break;
38219     default:
38220       gcc_unreachable ();
38221     }
38222
38223   gcc_assert (nargs <= ARRAY_SIZE (args));
38224
38225   if (klass == store)
38226     {
38227       arg = CALL_EXPR_ARG (exp, 0);
38228       op = expand_normal (arg);
38229       gcc_assert (target == 0);
38230       if (memory)
38231         {
38232           op = ix86_zero_extend_to_Pmode (op);
38233           target = gen_rtx_MEM (tmode, op);
38234           /* target at this point has just BITS_PER_UNIT MEM_ALIGN
38235              on it.  Try to improve it using get_pointer_alignment,
38236              and if the special builtin is one that requires strict
38237              mode alignment, also from it's GET_MODE_ALIGNMENT.
38238              Failure to do so could lead to ix86_legitimate_combined_insn
38239              rejecting all changes to such insns.  */
38240           unsigned int align = get_pointer_alignment (arg);
38241           if (aligned_mem && align < GET_MODE_ALIGNMENT (tmode))
38242             align = GET_MODE_ALIGNMENT (tmode);
38243           if (MEM_ALIGN (target) < align)
38244             set_mem_align (target, align);
38245         }
38246       else
38247         target = force_reg (tmode, op);
38248       arg_adjust = 1;
38249     }
38250   else
38251     {
38252       arg_adjust = 0;
38253       if (optimize
38254           || target == 0
38255           || !register_operand (target, tmode)
38256           || GET_MODE (target) != tmode)
38257         target = gen_reg_rtx (tmode);
38258     }
38259
38260   for (i = 0; i < nargs; i++)
38261     {
38262       machine_mode mode = insn_p->operand[i + 1].mode;
38263       bool match;
38264
38265       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
38266       op = expand_normal (arg);
38267       match = insn_p->operand[i + 1].predicate (op, mode);
38268
38269       if (last_arg_constant && (i + 1) == nargs)
38270         {
38271           if (!match)
38272             {
38273               if (icode == CODE_FOR_lwp_lwpvalsi3
38274                   || icode == CODE_FOR_lwp_lwpinssi3
38275                   || icode == CODE_FOR_lwp_lwpvaldi3
38276                   || icode == CODE_FOR_lwp_lwpinsdi3)
38277                 error ("the last argument must be a 32-bit immediate");
38278               else
38279                 error ("the last argument must be an 8-bit immediate");
38280               return const0_rtx;
38281             }
38282         }
38283       else
38284         {
38285           if (i == memory)
38286             {
38287               /* This must be the memory operand.  */
38288               op = ix86_zero_extend_to_Pmode (op);
38289               op = gen_rtx_MEM (mode, op);
38290               /* op at this point has just BITS_PER_UNIT MEM_ALIGN
38291                  on it.  Try to improve it using get_pointer_alignment,
38292                  and if the special builtin is one that requires strict
38293                  mode alignment, also from it's GET_MODE_ALIGNMENT.
38294                  Failure to do so could lead to ix86_legitimate_combined_insn
38295                  rejecting all changes to such insns.  */
38296               unsigned int align = get_pointer_alignment (arg);
38297               if (aligned_mem && align < GET_MODE_ALIGNMENT (mode))
38298                 align = GET_MODE_ALIGNMENT (mode);
38299               if (MEM_ALIGN (op) < align)
38300                 set_mem_align (op, align);
38301             }
38302           else
38303             {
38304               /* This must be register.  */
38305               if (VECTOR_MODE_P (mode))
38306                 op = safe_vector_operand (op, mode);
38307
38308               op = fixup_modeless_constant (op, mode);
38309
38310               if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
38311                 op = copy_to_mode_reg (mode, op);
38312               else
38313                 {
38314                   op = copy_to_reg (op);
38315                   op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
38316                 }
38317             }
38318         }
38319
38320       args[i].op = op;
38321       args[i].mode = mode;
38322     }
38323
38324   switch (nargs)
38325     {
38326     case 0:
38327       pat = GEN_FCN (icode) (target);
38328       break;
38329     case 1:
38330       pat = GEN_FCN (icode) (target, args[0].op);
38331       break;
38332     case 2:
38333       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
38334       break;
38335     case 3:
38336       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
38337       break;
38338     default:
38339       gcc_unreachable ();
38340     }
38341
38342   if (! pat)
38343     return 0;
38344   emit_insn (pat);
38345   return klass == store ? 0 : target;
38346 }
38347
38348 /* Return the integer constant in ARG.  Constrain it to be in the range
38349    of the subparts of VEC_TYPE; issue an error if not.  */
38350
38351 static int
38352 get_element_number (tree vec_type, tree arg)
38353 {
38354   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
38355
38356   if (!tree_fits_uhwi_p (arg)
38357       || (elt = tree_to_uhwi (arg), elt > max))
38358     {
38359       error ("selector must be an integer constant in the range 0..%wi", max);
38360       return 0;
38361     }
38362
38363   return elt;
38364 }
38365
38366 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38367    ix86_expand_vector_init.  We DO have language-level syntax for this, in
38368    the form of  (type){ init-list }.  Except that since we can't place emms
38369    instructions from inside the compiler, we can't allow the use of MMX
38370    registers unless the user explicitly asks for it.  So we do *not* define
38371    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
38372    we have builtins invoked by mmintrin.h that gives us license to emit
38373    these sorts of instructions.  */
38374
38375 static rtx
38376 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
38377 {
38378   machine_mode tmode = TYPE_MODE (type);
38379   machine_mode inner_mode = GET_MODE_INNER (tmode);
38380   int i, n_elt = GET_MODE_NUNITS (tmode);
38381   rtvec v = rtvec_alloc (n_elt);
38382
38383   gcc_assert (VECTOR_MODE_P (tmode));
38384   gcc_assert (call_expr_nargs (exp) == n_elt);
38385
38386   for (i = 0; i < n_elt; ++i)
38387     {
38388       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
38389       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
38390     }
38391
38392   if (!target || !register_operand (target, tmode))
38393     target = gen_reg_rtx (tmode);
38394
38395   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
38396   return target;
38397 }
38398
38399 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38400    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
38401    had a language-level syntax for referencing vector elements.  */
38402
38403 static rtx
38404 ix86_expand_vec_ext_builtin (tree exp, rtx target)
38405 {
38406   machine_mode tmode, mode0;
38407   tree arg0, arg1;
38408   int elt;
38409   rtx op0;
38410
38411   arg0 = CALL_EXPR_ARG (exp, 0);
38412   arg1 = CALL_EXPR_ARG (exp, 1);
38413
38414   op0 = expand_normal (arg0);
38415   elt = get_element_number (TREE_TYPE (arg0), arg1);
38416
38417   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
38418   mode0 = TYPE_MODE (TREE_TYPE (arg0));
38419   gcc_assert (VECTOR_MODE_P (mode0));
38420
38421   op0 = force_reg (mode0, op0);
38422
38423   if (optimize || !target || !register_operand (target, tmode))
38424     target = gen_reg_rtx (tmode);
38425
38426   ix86_expand_vector_extract (true, target, op0, elt);
38427
38428   return target;
38429 }
38430
38431 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38432    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
38433    a language-level syntax for referencing vector elements.  */
38434
38435 static rtx
38436 ix86_expand_vec_set_builtin (tree exp)
38437 {
38438   machine_mode tmode, mode1;
38439   tree arg0, arg1, arg2;
38440   int elt;
38441   rtx op0, op1, target;
38442
38443   arg0 = CALL_EXPR_ARG (exp, 0);
38444   arg1 = CALL_EXPR_ARG (exp, 1);
38445   arg2 = CALL_EXPR_ARG (exp, 2);
38446
38447   tmode = TYPE_MODE (TREE_TYPE (arg0));
38448   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
38449   gcc_assert (VECTOR_MODE_P (tmode));
38450
38451   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
38452   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
38453   elt = get_element_number (TREE_TYPE (arg0), arg2);
38454
38455   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
38456     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
38457
38458   op0 = force_reg (tmode, op0);
38459   op1 = force_reg (mode1, op1);
38460
38461   /* OP0 is the source of these builtin functions and shouldn't be
38462      modified.  Create a copy, use it and return it as target.  */
38463   target = gen_reg_rtx (tmode);
38464   emit_move_insn (target, op0);
38465   ix86_expand_vector_set (true, target, op1, elt);
38466
38467   return target;
38468 }
38469
38470 /* Emit conditional move of SRC to DST with condition
38471    OP1 CODE OP2.  */
38472 static void
38473 ix86_emit_cmove (rtx dst, rtx src, enum rtx_code code, rtx op1, rtx op2)
38474 {
38475   rtx t;
38476
38477   if (TARGET_CMOVE)
38478     {
38479       t = ix86_expand_compare (code, op1, op2);
38480       emit_insn (gen_rtx_SET (dst, gen_rtx_IF_THEN_ELSE (GET_MODE (dst), t,
38481                                                          src, dst)));
38482     }
38483   else
38484     {
38485       rtx_code_label *nomove = gen_label_rtx ();
38486       emit_cmp_and_jump_insns (op1, op2, reverse_condition (code),
38487                                const0_rtx, GET_MODE (op1), 1, nomove);
38488       emit_move_insn (dst, src);
38489       emit_label (nomove);
38490     }
38491 }
38492
38493 /* Choose max of DST and SRC and put it to DST.  */
38494 static void
38495 ix86_emit_move_max (rtx dst, rtx src)
38496 {
38497   ix86_emit_cmove (dst, src, LTU, dst, src);
38498 }
38499
38500 /* Expand an expression EXP that calls a built-in function,
38501    with result going to TARGET if that's convenient
38502    (and in mode MODE if that's convenient).
38503    SUBTARGET may be used as the target for computing one of EXP's operands.
38504    IGNORE is nonzero if the value is to be ignored.  */
38505
38506 static rtx
38507 ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
38508                      machine_mode mode, int ignore)
38509 {
38510   const struct builtin_description *d;
38511   size_t i;
38512   enum insn_code icode;
38513   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
38514   tree arg0, arg1, arg2, arg3, arg4;
38515   rtx op0, op1, op2, op3, op4, pat, insn;
38516   machine_mode mode0, mode1, mode2, mode3, mode4;
38517   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
38518
38519   /* For CPU builtins that can be folded, fold first and expand the fold.  */
38520   switch (fcode)
38521     {
38522     case IX86_BUILTIN_CPU_INIT:
38523       {
38524         /* Make it call __cpu_indicator_init in libgcc. */
38525         tree call_expr, fndecl, type;
38526         type = build_function_type_list (integer_type_node, NULL_TREE); 
38527         fndecl = build_fn_decl ("__cpu_indicator_init", type);
38528         call_expr = build_call_expr (fndecl, 0); 
38529         return expand_expr (call_expr, target, mode, EXPAND_NORMAL);
38530       }
38531     case IX86_BUILTIN_CPU_IS:
38532     case IX86_BUILTIN_CPU_SUPPORTS:
38533       {
38534         tree arg0 = CALL_EXPR_ARG (exp, 0);
38535         tree fold_expr = fold_builtin_cpu (fndecl, &arg0);
38536         gcc_assert (fold_expr != NULL_TREE);
38537         return expand_expr (fold_expr, target, mode, EXPAND_NORMAL);
38538       }
38539     }
38540
38541   /* Determine whether the builtin function is available under the current ISA.
38542      Originally the builtin was not created if it wasn't applicable to the
38543      current ISA based on the command line switches.  With function specific
38544      options, we need to check in the context of the function making the call
38545      whether it is supported.  */
38546   if (ix86_builtins_isa[fcode].isa
38547       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
38548     {
38549       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
38550                                        NULL, (enum fpmath_unit) 0, false);
38551
38552       if (!opts)
38553         error ("%qE needs unknown isa option", fndecl);
38554       else
38555         {
38556           gcc_assert (opts != NULL);
38557           error ("%qE needs isa option %s", fndecl, opts);
38558           free (opts);
38559         }
38560       return const0_rtx;
38561     }
38562
38563   switch (fcode)
38564     {
38565     case IX86_BUILTIN_BNDMK:
38566       if (!target
38567           || GET_MODE (target) != BNDmode
38568           || !register_operand (target, BNDmode))
38569         target = gen_reg_rtx (BNDmode);
38570
38571       arg0 = CALL_EXPR_ARG (exp, 0);
38572       arg1 = CALL_EXPR_ARG (exp, 1);
38573
38574       op0 = expand_normal (arg0);
38575       op1 = expand_normal (arg1);
38576
38577       if (!register_operand (op0, Pmode))
38578         op0 = ix86_zero_extend_to_Pmode (op0);
38579       if (!register_operand (op1, Pmode))
38580         op1 = ix86_zero_extend_to_Pmode (op1);
38581
38582       /* Builtin arg1 is size of block but instruction op1 should
38583          be (size - 1).  */
38584       op1 = expand_simple_binop (Pmode, PLUS, op1, constm1_rtx,
38585                                  NULL_RTX, 1, OPTAB_DIRECT);
38586
38587       emit_insn (BNDmode == BND64mode
38588                  ? gen_bnd64_mk (target, op0, op1)
38589                  : gen_bnd32_mk (target, op0, op1));
38590       return target;
38591
38592     case IX86_BUILTIN_BNDSTX:
38593       arg0 = CALL_EXPR_ARG (exp, 0);
38594       arg1 = CALL_EXPR_ARG (exp, 1);
38595       arg2 = CALL_EXPR_ARG (exp, 2);
38596
38597       op0 = expand_normal (arg0);
38598       op1 = expand_normal (arg1);
38599       op2 = expand_normal (arg2);
38600
38601       if (!register_operand (op0, Pmode))
38602         op0 = ix86_zero_extend_to_Pmode (op0);
38603       if (!register_operand (op1, BNDmode))
38604         op1 = copy_to_mode_reg (BNDmode, op1);
38605       if (!register_operand (op2, Pmode))
38606         op2 = ix86_zero_extend_to_Pmode (op2);
38607
38608       emit_insn (BNDmode == BND64mode
38609                  ? gen_bnd64_stx (op2, op0, op1)
38610                  : gen_bnd32_stx (op2, op0, op1));
38611       return 0;
38612
38613     case IX86_BUILTIN_BNDLDX:
38614       if (!target
38615           || GET_MODE (target) != BNDmode
38616           || !register_operand (target, BNDmode))
38617         target = gen_reg_rtx (BNDmode);
38618
38619       arg0 = CALL_EXPR_ARG (exp, 0);
38620       arg1 = CALL_EXPR_ARG (exp, 1);
38621
38622       op0 = expand_normal (arg0);
38623       op1 = expand_normal (arg1);
38624
38625       if (!register_operand (op0, Pmode))
38626         op0 = ix86_zero_extend_to_Pmode (op0);
38627       if (!register_operand (op1, Pmode))
38628         op1 = ix86_zero_extend_to_Pmode (op1);
38629
38630       emit_insn (BNDmode == BND64mode
38631                  ? gen_bnd64_ldx (target, op0, op1)
38632                  : gen_bnd32_ldx (target, op0, op1));
38633       return target;
38634
38635     case IX86_BUILTIN_BNDCL:
38636       arg0 = CALL_EXPR_ARG (exp, 0);
38637       arg1 = CALL_EXPR_ARG (exp, 1);
38638
38639       op0 = expand_normal (arg0);
38640       op1 = expand_normal (arg1);
38641
38642       if (!register_operand (op0, Pmode))
38643         op0 = ix86_zero_extend_to_Pmode (op0);
38644       if (!register_operand (op1, BNDmode))
38645         op1 = copy_to_mode_reg (BNDmode, op1);
38646
38647       emit_insn (BNDmode == BND64mode
38648                  ? gen_bnd64_cl (op1, op0)
38649                  : gen_bnd32_cl (op1, op0));
38650       return 0;
38651
38652     case IX86_BUILTIN_BNDCU:
38653       arg0 = CALL_EXPR_ARG (exp, 0);
38654       arg1 = CALL_EXPR_ARG (exp, 1);
38655
38656       op0 = expand_normal (arg0);
38657       op1 = expand_normal (arg1);
38658
38659       if (!register_operand (op0, Pmode))
38660         op0 = ix86_zero_extend_to_Pmode (op0);
38661       if (!register_operand (op1, BNDmode))
38662         op1 = copy_to_mode_reg (BNDmode, op1);
38663
38664       emit_insn (BNDmode == BND64mode
38665                  ? gen_bnd64_cu (op1, op0)
38666                  : gen_bnd32_cu (op1, op0));
38667       return 0;
38668
38669     case IX86_BUILTIN_BNDRET:
38670       arg0 = CALL_EXPR_ARG (exp, 0);
38671       gcc_assert (TREE_CODE (arg0) == SSA_NAME);
38672       target = chkp_get_rtl_bounds (arg0);
38673
38674       /* If no bounds were specified for returned value,
38675          then use INIT bounds.  It usually happens when
38676          some built-in function is expanded.  */
38677       if (!target)
38678         {
38679           rtx t1 = gen_reg_rtx (Pmode);
38680           rtx t2 = gen_reg_rtx (Pmode);
38681           target = gen_reg_rtx (BNDmode);
38682           emit_move_insn (t1, const0_rtx);
38683           emit_move_insn (t2, constm1_rtx);
38684           emit_insn (BNDmode == BND64mode
38685                      ? gen_bnd64_mk (target, t1, t2)
38686                      : gen_bnd32_mk (target, t1, t2));
38687         }
38688
38689       gcc_assert (target && REG_P (target));
38690       return target;
38691
38692     case IX86_BUILTIN_BNDNARROW:
38693       {
38694         rtx m1, m1h1, m1h2, lb, ub, t1;
38695
38696         /* Return value and lb.  */
38697         arg0 = CALL_EXPR_ARG (exp, 0);
38698         /* Bounds.  */
38699         arg1 = CALL_EXPR_ARG (exp, 1);
38700         /* Size.  */
38701         arg2 = CALL_EXPR_ARG (exp, 2);
38702
38703         lb = expand_normal (arg0);
38704         op1 = expand_normal (arg1);
38705         op2 = expand_normal (arg2);
38706
38707         /* Size was passed but we need to use (size - 1) as for bndmk.  */
38708         op2 = expand_simple_binop (Pmode, PLUS, op2, constm1_rtx,
38709                                    NULL_RTX, 1, OPTAB_DIRECT);
38710
38711         /* Add LB to size and inverse to get UB.  */
38712         op2 = expand_simple_binop (Pmode, PLUS, op2, lb,
38713                                    op2, 1, OPTAB_DIRECT);
38714         ub = expand_simple_unop (Pmode, NOT, op2, op2, 1);
38715
38716         if (!register_operand (lb, Pmode))
38717           lb = ix86_zero_extend_to_Pmode (lb);
38718         if (!register_operand (ub, Pmode))
38719           ub = ix86_zero_extend_to_Pmode (ub);
38720
38721         /* We need to move bounds to memory before any computations.  */
38722         if (MEM_P (op1))
38723           m1 = op1;
38724         else
38725           {
38726             m1 = assign_386_stack_local (BNDmode, SLOT_TEMP);
38727             emit_move_insn (m1, op1);
38728           }
38729
38730         /* Generate mem expression to be used for access to LB and UB.  */
38731         m1h1 = adjust_address (m1, Pmode, 0);
38732         m1h2 = adjust_address (m1, Pmode, GET_MODE_SIZE (Pmode));
38733
38734         t1 = gen_reg_rtx (Pmode);
38735
38736         /* Compute LB.  */
38737         emit_move_insn (t1, m1h1);
38738         ix86_emit_move_max (t1, lb);
38739         emit_move_insn (m1h1, t1);
38740
38741         /* Compute UB.  UB is stored in 1's complement form.  Therefore
38742            we also use max here.  */
38743         emit_move_insn (t1, m1h2);
38744         ix86_emit_move_max (t1, ub);
38745         emit_move_insn (m1h2, t1);
38746
38747         op2 = gen_reg_rtx (BNDmode);
38748         emit_move_insn (op2, m1);
38749
38750         return chkp_join_splitted_slot (lb, op2);
38751       }
38752
38753     case IX86_BUILTIN_BNDINT:
38754       {
38755         rtx res, rh1, rh2, lb1, lb2, ub1, ub2;
38756
38757         if (!target
38758             || GET_MODE (target) != BNDmode
38759             || !register_operand (target, BNDmode))
38760           target = gen_reg_rtx (BNDmode);
38761
38762         arg0 = CALL_EXPR_ARG (exp, 0);
38763         arg1 = CALL_EXPR_ARG (exp, 1);
38764
38765         op0 = expand_normal (arg0);
38766         op1 = expand_normal (arg1);
38767
38768         res = assign_386_stack_local (BNDmode, SLOT_TEMP);
38769         rh1 = adjust_address (res, Pmode, 0);
38770         rh2 = adjust_address (res, Pmode, GET_MODE_SIZE (Pmode));
38771
38772         /* Put first bounds to temporaries.  */
38773         lb1 = gen_reg_rtx (Pmode);
38774         ub1 = gen_reg_rtx (Pmode);
38775         if (MEM_P (op0))
38776           {
38777             emit_move_insn (lb1, adjust_address (op0, Pmode, 0));
38778             emit_move_insn (ub1, adjust_address (op0, Pmode,
38779                                                  GET_MODE_SIZE (Pmode)));
38780           }
38781         else
38782           {
38783             emit_move_insn (res, op0);
38784             emit_move_insn (lb1, rh1);
38785             emit_move_insn (ub1, rh2);
38786           }
38787
38788         /* Put second bounds to temporaries.  */
38789         lb2 = gen_reg_rtx (Pmode);
38790         ub2 = gen_reg_rtx (Pmode);
38791         if (MEM_P (op1))
38792           {
38793             emit_move_insn (lb2, adjust_address (op1, Pmode, 0));
38794             emit_move_insn (ub2, adjust_address (op1, Pmode,
38795                                                  GET_MODE_SIZE (Pmode)));
38796           }
38797         else
38798           {
38799             emit_move_insn (res, op1);
38800             emit_move_insn (lb2, rh1);
38801             emit_move_insn (ub2, rh2);
38802           }
38803
38804         /* Compute LB.  */
38805         ix86_emit_move_max (lb1, lb2);
38806         emit_move_insn (rh1, lb1);
38807
38808         /* Compute UB.  UB is stored in 1's complement form.  Therefore
38809            we also use max here.  */
38810         ix86_emit_move_max (ub1, ub2);
38811         emit_move_insn (rh2, ub1);
38812
38813         emit_move_insn (target, res);
38814
38815         return target;
38816       }
38817
38818     case IX86_BUILTIN_SIZEOF:
38819       {
38820         tree name;
38821         rtx symbol;
38822
38823         if (!target
38824             || GET_MODE (target) != Pmode
38825             || !register_operand (target, Pmode))
38826           target = gen_reg_rtx (Pmode);
38827
38828         arg0 = CALL_EXPR_ARG (exp, 0);
38829         gcc_assert (TREE_CODE (arg0) == VAR_DECL);
38830
38831         name = DECL_ASSEMBLER_NAME (arg0);
38832         symbol = gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (name));
38833
38834         emit_insn (Pmode == SImode
38835                    ? gen_move_size_reloc_si (target, symbol)
38836                    : gen_move_size_reloc_di (target, symbol));
38837
38838         return target;
38839       }
38840
38841     case IX86_BUILTIN_BNDLOWER:
38842       {
38843         rtx mem, hmem;
38844
38845         if (!target
38846             || GET_MODE (target) != Pmode
38847             || !register_operand (target, Pmode))
38848           target = gen_reg_rtx (Pmode);
38849
38850         arg0 = CALL_EXPR_ARG (exp, 0);
38851         op0 = expand_normal (arg0);
38852
38853         /* We need to move bounds to memory first.  */
38854         if (MEM_P (op0))
38855           mem = op0;
38856         else
38857           {
38858             mem = assign_386_stack_local (BNDmode, SLOT_TEMP);
38859             emit_move_insn (mem, op0);
38860           }
38861
38862         /* Generate mem expression to access LB and load it.  */
38863         hmem = adjust_address (mem, Pmode, 0);
38864         emit_move_insn (target, hmem);
38865
38866         return target;
38867       }
38868
38869     case IX86_BUILTIN_BNDUPPER:
38870       {
38871         rtx mem, hmem, res;
38872
38873         if (!target
38874             || GET_MODE (target) != Pmode
38875             || !register_operand (target, Pmode))
38876           target = gen_reg_rtx (Pmode);
38877
38878         arg0 = CALL_EXPR_ARG (exp, 0);
38879         op0 = expand_normal (arg0);
38880
38881         /* We need to move bounds to memory first.  */
38882         if (MEM_P (op0))
38883           mem = op0;
38884         else
38885           {
38886             mem = assign_386_stack_local (BNDmode, SLOT_TEMP);
38887             emit_move_insn (mem, op0);
38888           }
38889
38890         /* Generate mem expression to access UB.  */
38891         hmem = adjust_address (mem, Pmode, GET_MODE_SIZE (Pmode));
38892
38893         /* We need to inverse all bits of UB.  */
38894         res = expand_simple_unop (Pmode, NOT, hmem, target, 1);
38895
38896         if (res != target)
38897           emit_move_insn (target, res);
38898
38899         return target;
38900       }
38901
38902     case IX86_BUILTIN_MASKMOVQ:
38903     case IX86_BUILTIN_MASKMOVDQU:
38904       icode = (fcode == IX86_BUILTIN_MASKMOVQ
38905                ? CODE_FOR_mmx_maskmovq
38906                : CODE_FOR_sse2_maskmovdqu);
38907       /* Note the arg order is different from the operand order.  */
38908       arg1 = CALL_EXPR_ARG (exp, 0);
38909       arg2 = CALL_EXPR_ARG (exp, 1);
38910       arg0 = CALL_EXPR_ARG (exp, 2);
38911       op0 = expand_normal (arg0);
38912       op1 = expand_normal (arg1);
38913       op2 = expand_normal (arg2);
38914       mode0 = insn_data[icode].operand[0].mode;
38915       mode1 = insn_data[icode].operand[1].mode;
38916       mode2 = insn_data[icode].operand[2].mode;
38917
38918       op0 = ix86_zero_extend_to_Pmode (op0);
38919       op0 = gen_rtx_MEM (mode1, op0);
38920
38921       if (!insn_data[icode].operand[0].predicate (op0, mode0))
38922         op0 = copy_to_mode_reg (mode0, op0);
38923       if (!insn_data[icode].operand[1].predicate (op1, mode1))
38924         op1 = copy_to_mode_reg (mode1, op1);
38925       if (!insn_data[icode].operand[2].predicate (op2, mode2))
38926         op2 = copy_to_mode_reg (mode2, op2);
38927       pat = GEN_FCN (icode) (op0, op1, op2);
38928       if (! pat)
38929         return 0;
38930       emit_insn (pat);
38931       return 0;
38932
38933     case IX86_BUILTIN_LDMXCSR:
38934       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
38935       target = assign_386_stack_local (SImode, SLOT_TEMP);
38936       emit_move_insn (target, op0);
38937       emit_insn (gen_sse_ldmxcsr (target));
38938       return 0;
38939
38940     case IX86_BUILTIN_STMXCSR:
38941       target = assign_386_stack_local (SImode, SLOT_TEMP);
38942       emit_insn (gen_sse_stmxcsr (target));
38943       return copy_to_mode_reg (SImode, target);
38944
38945     case IX86_BUILTIN_CLFLUSH:
38946         arg0 = CALL_EXPR_ARG (exp, 0);
38947         op0 = expand_normal (arg0);
38948         icode = CODE_FOR_sse2_clflush;
38949         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38950           op0 = ix86_zero_extend_to_Pmode (op0);
38951
38952         emit_insn (gen_sse2_clflush (op0));
38953         return 0;
38954
38955     case IX86_BUILTIN_CLWB:
38956         arg0 = CALL_EXPR_ARG (exp, 0);
38957         op0 = expand_normal (arg0);
38958         icode = CODE_FOR_clwb;
38959         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38960           op0 = ix86_zero_extend_to_Pmode (op0);
38961
38962         emit_insn (gen_clwb (op0));
38963         return 0;
38964
38965     case IX86_BUILTIN_CLFLUSHOPT:
38966         arg0 = CALL_EXPR_ARG (exp, 0);
38967         op0 = expand_normal (arg0);
38968         icode = CODE_FOR_clflushopt;
38969         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38970           op0 = ix86_zero_extend_to_Pmode (op0);
38971
38972         emit_insn (gen_clflushopt (op0));
38973         return 0;
38974
38975     case IX86_BUILTIN_MONITOR:
38976     case IX86_BUILTIN_MONITORX:
38977       arg0 = CALL_EXPR_ARG (exp, 0);
38978       arg1 = CALL_EXPR_ARG (exp, 1);
38979       arg2 = CALL_EXPR_ARG (exp, 2);
38980       op0 = expand_normal (arg0);
38981       op1 = expand_normal (arg1);
38982       op2 = expand_normal (arg2);
38983       if (!REG_P (op0))
38984         op0 = ix86_zero_extend_to_Pmode (op0);
38985       if (!REG_P (op1))
38986         op1 = copy_to_mode_reg (SImode, op1);
38987       if (!REG_P (op2))
38988         op2 = copy_to_mode_reg (SImode, op2);
38989
38990       emit_insn (fcode == IX86_BUILTIN_MONITOR 
38991                  ? ix86_gen_monitor (op0, op1, op2)
38992                  : ix86_gen_monitorx (op0, op1, op2));
38993       return 0;
38994
38995     case IX86_BUILTIN_MWAIT:
38996       arg0 = CALL_EXPR_ARG (exp, 0);
38997       arg1 = CALL_EXPR_ARG (exp, 1);
38998       op0 = expand_normal (arg0);
38999       op1 = expand_normal (arg1);
39000       if (!REG_P (op0))
39001         op0 = copy_to_mode_reg (SImode, op0);
39002       if (!REG_P (op1))
39003         op1 = copy_to_mode_reg (SImode, op1);
39004       emit_insn (gen_sse3_mwait (op0, op1));
39005       return 0;
39006
39007     case IX86_BUILTIN_MWAITX:
39008       arg0 = CALL_EXPR_ARG (exp, 0);
39009       arg1 = CALL_EXPR_ARG (exp, 1);
39010       arg2 = CALL_EXPR_ARG (exp, 2);
39011       op0 = expand_normal (arg0);
39012       op1 = expand_normal (arg1);
39013       op2 = expand_normal (arg2);
39014       if (!REG_P (op0))
39015         op0 = copy_to_mode_reg (SImode, op0);
39016       if (!REG_P (op1))
39017         op1 = copy_to_mode_reg (SImode, op1);
39018       if (!REG_P (op2))
39019         op2 = copy_to_mode_reg (SImode, op2);
39020       emit_insn (gen_mwaitx (op0, op1, op2));
39021       return 0;
39022
39023     case IX86_BUILTIN_VEC_INIT_V2SI:
39024     case IX86_BUILTIN_VEC_INIT_V4HI:
39025     case IX86_BUILTIN_VEC_INIT_V8QI:
39026       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
39027
39028     case IX86_BUILTIN_VEC_EXT_V2DF:
39029     case IX86_BUILTIN_VEC_EXT_V2DI:
39030     case IX86_BUILTIN_VEC_EXT_V4SF:
39031     case IX86_BUILTIN_VEC_EXT_V4SI:
39032     case IX86_BUILTIN_VEC_EXT_V8HI:
39033     case IX86_BUILTIN_VEC_EXT_V2SI:
39034     case IX86_BUILTIN_VEC_EXT_V4HI:
39035     case IX86_BUILTIN_VEC_EXT_V16QI:
39036       return ix86_expand_vec_ext_builtin (exp, target);
39037
39038     case IX86_BUILTIN_VEC_SET_V2DI:
39039     case IX86_BUILTIN_VEC_SET_V4SF:
39040     case IX86_BUILTIN_VEC_SET_V4SI:
39041     case IX86_BUILTIN_VEC_SET_V8HI:
39042     case IX86_BUILTIN_VEC_SET_V4HI:
39043     case IX86_BUILTIN_VEC_SET_V16QI:
39044       return ix86_expand_vec_set_builtin (exp);
39045
39046     case IX86_BUILTIN_INFQ:
39047     case IX86_BUILTIN_HUGE_VALQ:
39048       {
39049         REAL_VALUE_TYPE inf;
39050         rtx tmp;
39051
39052         real_inf (&inf);
39053         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
39054
39055         tmp = validize_mem (force_const_mem (mode, tmp));
39056
39057         if (target == 0)
39058           target = gen_reg_rtx (mode);
39059
39060         emit_move_insn (target, tmp);
39061         return target;
39062       }
39063
39064     case IX86_BUILTIN_RDPMC:
39065     case IX86_BUILTIN_RDTSC:
39066     case IX86_BUILTIN_RDTSCP:
39067
39068       op0 = gen_reg_rtx (DImode);
39069       op1 = gen_reg_rtx (DImode);
39070
39071       if (fcode == IX86_BUILTIN_RDPMC)
39072         {
39073           arg0 = CALL_EXPR_ARG (exp, 0);
39074           op2 = expand_normal (arg0);
39075           if (!register_operand (op2, SImode))
39076             op2 = copy_to_mode_reg (SImode, op2);
39077
39078           insn = (TARGET_64BIT
39079                   ? gen_rdpmc_rex64 (op0, op1, op2)
39080                   : gen_rdpmc (op0, op2));
39081           emit_insn (insn);
39082         }
39083       else if (fcode == IX86_BUILTIN_RDTSC)
39084         {
39085           insn = (TARGET_64BIT
39086                   ? gen_rdtsc_rex64 (op0, op1)
39087                   : gen_rdtsc (op0));
39088           emit_insn (insn);
39089         }
39090       else
39091         {
39092           op2 = gen_reg_rtx (SImode);
39093
39094           insn = (TARGET_64BIT
39095                   ? gen_rdtscp_rex64 (op0, op1, op2)
39096                   : gen_rdtscp (op0, op2));
39097           emit_insn (insn);
39098
39099           arg0 = CALL_EXPR_ARG (exp, 0);
39100           op4 = expand_normal (arg0);
39101           if (!address_operand (op4, VOIDmode))
39102             {
39103               op4 = convert_memory_address (Pmode, op4);
39104               op4 = copy_addr_to_reg (op4);
39105             }
39106           emit_move_insn (gen_rtx_MEM (SImode, op4), op2);
39107         }
39108
39109       if (target == 0)
39110         {
39111           /* mode is VOIDmode if __builtin_rd* has been called
39112              without lhs.  */
39113           if (mode == VOIDmode)
39114             return target;
39115           target = gen_reg_rtx (mode);
39116         }
39117
39118       if (TARGET_64BIT)
39119         {
39120           op1 = expand_simple_binop (DImode, ASHIFT, op1, GEN_INT (32),
39121                                      op1, 1, OPTAB_DIRECT);
39122           op0 = expand_simple_binop (DImode, IOR, op0, op1,
39123                                      op0, 1, OPTAB_DIRECT);
39124         }
39125
39126       emit_move_insn (target, op0);
39127       return target;
39128
39129     case IX86_BUILTIN_FXSAVE:
39130     case IX86_BUILTIN_FXRSTOR:
39131     case IX86_BUILTIN_FXSAVE64:
39132     case IX86_BUILTIN_FXRSTOR64:
39133     case IX86_BUILTIN_FNSTENV:
39134     case IX86_BUILTIN_FLDENV:
39135       mode0 = BLKmode;
39136       switch (fcode)
39137         {
39138         case IX86_BUILTIN_FXSAVE:
39139           icode = CODE_FOR_fxsave;
39140           break;
39141         case IX86_BUILTIN_FXRSTOR:
39142           icode = CODE_FOR_fxrstor;
39143           break;
39144         case IX86_BUILTIN_FXSAVE64:
39145           icode = CODE_FOR_fxsave64;
39146           break;
39147         case IX86_BUILTIN_FXRSTOR64:
39148           icode = CODE_FOR_fxrstor64;
39149           break;
39150         case IX86_BUILTIN_FNSTENV:
39151           icode = CODE_FOR_fnstenv;
39152           break;
39153         case IX86_BUILTIN_FLDENV:
39154           icode = CODE_FOR_fldenv;
39155           break;
39156         default:
39157           gcc_unreachable ();
39158         }
39159
39160       arg0 = CALL_EXPR_ARG (exp, 0);
39161       op0 = expand_normal (arg0);
39162
39163       if (!address_operand (op0, VOIDmode))
39164         {
39165           op0 = convert_memory_address (Pmode, op0);
39166           op0 = copy_addr_to_reg (op0);
39167         }
39168       op0 = gen_rtx_MEM (mode0, op0);
39169
39170       pat = GEN_FCN (icode) (op0);
39171       if (pat)
39172         emit_insn (pat);
39173       return 0;
39174
39175     case IX86_BUILTIN_XSAVE:
39176     case IX86_BUILTIN_XRSTOR:
39177     case IX86_BUILTIN_XSAVE64:
39178     case IX86_BUILTIN_XRSTOR64:
39179     case IX86_BUILTIN_XSAVEOPT:
39180     case IX86_BUILTIN_XSAVEOPT64:
39181     case IX86_BUILTIN_XSAVES:
39182     case IX86_BUILTIN_XRSTORS:
39183     case IX86_BUILTIN_XSAVES64:
39184     case IX86_BUILTIN_XRSTORS64:
39185     case IX86_BUILTIN_XSAVEC:
39186     case IX86_BUILTIN_XSAVEC64:
39187       arg0 = CALL_EXPR_ARG (exp, 0);
39188       arg1 = CALL_EXPR_ARG (exp, 1);
39189       op0 = expand_normal (arg0);
39190       op1 = expand_normal (arg1);
39191
39192       if (!address_operand (op0, VOIDmode))
39193         {
39194           op0 = convert_memory_address (Pmode, op0);
39195           op0 = copy_addr_to_reg (op0);
39196         }
39197       op0 = gen_rtx_MEM (BLKmode, op0);
39198
39199       op1 = force_reg (DImode, op1);
39200
39201       if (TARGET_64BIT)
39202         {
39203           op2 = expand_simple_binop (DImode, LSHIFTRT, op1, GEN_INT (32),
39204                                      NULL, 1, OPTAB_DIRECT);
39205           switch (fcode)
39206             {
39207             case IX86_BUILTIN_XSAVE:
39208               icode = CODE_FOR_xsave_rex64;
39209               break;
39210             case IX86_BUILTIN_XRSTOR:
39211               icode = CODE_FOR_xrstor_rex64;
39212               break;
39213             case IX86_BUILTIN_XSAVE64:
39214               icode = CODE_FOR_xsave64;
39215               break;
39216             case IX86_BUILTIN_XRSTOR64:
39217               icode = CODE_FOR_xrstor64;
39218               break;
39219             case IX86_BUILTIN_XSAVEOPT:
39220               icode = CODE_FOR_xsaveopt_rex64;
39221               break;
39222             case IX86_BUILTIN_XSAVEOPT64:
39223               icode = CODE_FOR_xsaveopt64;
39224               break;
39225             case IX86_BUILTIN_XSAVES:
39226               icode = CODE_FOR_xsaves_rex64;
39227               break;
39228             case IX86_BUILTIN_XRSTORS:
39229               icode = CODE_FOR_xrstors_rex64;
39230               break;
39231             case IX86_BUILTIN_XSAVES64:
39232               icode = CODE_FOR_xsaves64;
39233               break;
39234             case IX86_BUILTIN_XRSTORS64:
39235               icode = CODE_FOR_xrstors64;
39236               break;
39237             case IX86_BUILTIN_XSAVEC:
39238               icode = CODE_FOR_xsavec_rex64;
39239               break;
39240             case IX86_BUILTIN_XSAVEC64:
39241               icode = CODE_FOR_xsavec64;
39242               break;
39243             default:
39244               gcc_unreachable ();
39245             }
39246
39247           op2 = gen_lowpart (SImode, op2);
39248           op1 = gen_lowpart (SImode, op1);
39249           pat = GEN_FCN (icode) (op0, op1, op2);
39250         }
39251       else
39252         {
39253           switch (fcode)
39254             {
39255             case IX86_BUILTIN_XSAVE:
39256               icode = CODE_FOR_xsave;
39257               break;
39258             case IX86_BUILTIN_XRSTOR:
39259               icode = CODE_FOR_xrstor;
39260               break;
39261             case IX86_BUILTIN_XSAVEOPT:
39262               icode = CODE_FOR_xsaveopt;
39263               break;
39264             case IX86_BUILTIN_XSAVES:
39265               icode = CODE_FOR_xsaves;
39266               break;
39267             case IX86_BUILTIN_XRSTORS:
39268               icode = CODE_FOR_xrstors;
39269               break;
39270             case IX86_BUILTIN_XSAVEC:
39271               icode = CODE_FOR_xsavec;
39272               break;
39273             default:
39274               gcc_unreachable ();
39275             }
39276           pat = GEN_FCN (icode) (op0, op1);
39277         }
39278
39279       if (pat)
39280         emit_insn (pat);
39281       return 0;
39282
39283     case IX86_BUILTIN_LLWPCB:
39284       arg0 = CALL_EXPR_ARG (exp, 0);
39285       op0 = expand_normal (arg0);
39286       icode = CODE_FOR_lwp_llwpcb;
39287       if (!insn_data[icode].operand[0].predicate (op0, Pmode))
39288         op0 = ix86_zero_extend_to_Pmode (op0);
39289       emit_insn (gen_lwp_llwpcb (op0));
39290       return 0;
39291
39292     case IX86_BUILTIN_SLWPCB:
39293       icode = CODE_FOR_lwp_slwpcb;
39294       if (!target
39295           || !insn_data[icode].operand[0].predicate (target, Pmode))
39296         target = gen_reg_rtx (Pmode);
39297       emit_insn (gen_lwp_slwpcb (target));
39298       return target;
39299
39300     case IX86_BUILTIN_BEXTRI32:
39301     case IX86_BUILTIN_BEXTRI64:
39302       arg0 = CALL_EXPR_ARG (exp, 0);
39303       arg1 = CALL_EXPR_ARG (exp, 1);
39304       op0 = expand_normal (arg0);
39305       op1 = expand_normal (arg1);
39306       icode = (fcode == IX86_BUILTIN_BEXTRI32
39307           ? CODE_FOR_tbm_bextri_si
39308           : CODE_FOR_tbm_bextri_di);
39309       if (!CONST_INT_P (op1))
39310         {
39311           error ("last argument must be an immediate");
39312           return const0_rtx;
39313         }
39314       else
39315         {
39316           unsigned char length = (INTVAL (op1) >> 8) & 0xFF;
39317           unsigned char lsb_index = INTVAL (op1) & 0xFF;
39318           op1 = GEN_INT (length);
39319           op2 = GEN_INT (lsb_index);
39320           pat = GEN_FCN (icode) (target, op0, op1, op2);
39321           if (pat)
39322             emit_insn (pat);
39323           return target;
39324         }
39325
39326     case IX86_BUILTIN_RDRAND16_STEP:
39327       icode = CODE_FOR_rdrandhi_1;
39328       mode0 = HImode;
39329       goto rdrand_step;
39330
39331     case IX86_BUILTIN_RDRAND32_STEP:
39332       icode = CODE_FOR_rdrandsi_1;
39333       mode0 = SImode;
39334       goto rdrand_step;
39335
39336     case IX86_BUILTIN_RDRAND64_STEP:
39337       icode = CODE_FOR_rdranddi_1;
39338       mode0 = DImode;
39339
39340 rdrand_step:
39341       op0 = gen_reg_rtx (mode0);
39342       emit_insn (GEN_FCN (icode) (op0));
39343
39344       arg0 = CALL_EXPR_ARG (exp, 0);
39345       op1 = expand_normal (arg0);
39346       if (!address_operand (op1, VOIDmode))
39347         {
39348           op1 = convert_memory_address (Pmode, op1);
39349           op1 = copy_addr_to_reg (op1);
39350         }
39351       emit_move_insn (gen_rtx_MEM (mode0, op1), op0);
39352
39353       op1 = gen_reg_rtx (SImode);
39354       emit_move_insn (op1, CONST1_RTX (SImode));
39355
39356       /* Emit SImode conditional move.  */
39357       if (mode0 == HImode)
39358         {
39359           op2 = gen_reg_rtx (SImode);
39360           emit_insn (gen_zero_extendhisi2 (op2, op0));
39361         }
39362       else if (mode0 == SImode)
39363         op2 = op0;
39364       else
39365         op2 = gen_rtx_SUBREG (SImode, op0, 0);
39366
39367       if (target == 0
39368           || !register_operand (target, SImode))
39369         target = gen_reg_rtx (SImode);
39370
39371       pat = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG),
39372                          const0_rtx);
39373       emit_insn (gen_rtx_SET (target,
39374                               gen_rtx_IF_THEN_ELSE (SImode, pat, op2, op1)));
39375       return target;
39376
39377     case IX86_BUILTIN_RDSEED16_STEP:
39378       icode = CODE_FOR_rdseedhi_1;
39379       mode0 = HImode;
39380       goto rdseed_step;
39381
39382     case IX86_BUILTIN_RDSEED32_STEP:
39383       icode = CODE_FOR_rdseedsi_1;
39384       mode0 = SImode;
39385       goto rdseed_step;
39386
39387     case IX86_BUILTIN_RDSEED64_STEP:
39388       icode = CODE_FOR_rdseeddi_1;
39389       mode0 = DImode;
39390
39391 rdseed_step:
39392       op0 = gen_reg_rtx (mode0);
39393       emit_insn (GEN_FCN (icode) (op0));
39394
39395       arg0 = CALL_EXPR_ARG (exp, 0);
39396       op1 = expand_normal (arg0);
39397       if (!address_operand (op1, VOIDmode))
39398         {
39399           op1 = convert_memory_address (Pmode, op1);
39400           op1 = copy_addr_to_reg (op1);
39401         }
39402       emit_move_insn (gen_rtx_MEM (mode0, op1), op0);
39403
39404       op2 = gen_reg_rtx (QImode);
39405
39406       pat = gen_rtx_LTU (QImode, gen_rtx_REG (CCCmode, FLAGS_REG),
39407                          const0_rtx);
39408       emit_insn (gen_rtx_SET (op2, pat));
39409
39410       if (target == 0
39411           || !register_operand (target, SImode))
39412         target = gen_reg_rtx (SImode);
39413
39414       emit_insn (gen_zero_extendqisi2 (target, op2));
39415       return target;
39416
39417     case IX86_BUILTIN_SBB32:
39418       icode = CODE_FOR_subsi3_carry;
39419       mode0 = SImode;
39420       goto addcarryx;
39421
39422     case IX86_BUILTIN_SBB64:
39423       icode = CODE_FOR_subdi3_carry;
39424       mode0 = DImode;
39425       goto addcarryx;
39426
39427     case IX86_BUILTIN_ADDCARRYX32:
39428       icode = TARGET_ADX ? CODE_FOR_adcxsi3 : CODE_FOR_addsi3_carry;
39429       mode0 = SImode;
39430       goto addcarryx;
39431
39432     case IX86_BUILTIN_ADDCARRYX64:
39433       icode = TARGET_ADX ? CODE_FOR_adcxdi3 : CODE_FOR_adddi3_carry;
39434       mode0 = DImode;
39435
39436 addcarryx:
39437       arg0 = CALL_EXPR_ARG (exp, 0); /* unsigned char c_in.  */
39438       arg1 = CALL_EXPR_ARG (exp, 1); /* unsigned int src1.  */
39439       arg2 = CALL_EXPR_ARG (exp, 2); /* unsigned int src2.  */
39440       arg3 = CALL_EXPR_ARG (exp, 3); /* unsigned int *sum_out.  */
39441
39442       op0 = gen_reg_rtx (QImode);
39443
39444       /* Generate CF from input operand.  */
39445       op1 = expand_normal (arg0);
39446       op1 = copy_to_mode_reg (QImode, convert_to_mode (QImode, op1, 1));
39447       emit_insn (gen_addqi3_cc (op0, op1, constm1_rtx));
39448
39449       /* Gen ADCX instruction to compute X+Y+CF.  */
39450       op2 = expand_normal (arg1);
39451       op3 = expand_normal (arg2);
39452
39453       if (!REG_P (op2))
39454         op2 = copy_to_mode_reg (mode0, op2);
39455       if (!REG_P (op3))
39456         op3 = copy_to_mode_reg (mode0, op3);
39457
39458       op0 = gen_reg_rtx (mode0);
39459
39460       op4 = gen_rtx_REG (CCCmode, FLAGS_REG);
39461       pat = gen_rtx_LTU (VOIDmode, op4, const0_rtx);
39462       emit_insn (GEN_FCN (icode) (op0, op2, op3, op4, pat));
39463
39464       /* Store the result.  */
39465       op4 = expand_normal (arg3);
39466       if (!address_operand (op4, VOIDmode))
39467         {
39468           op4 = convert_memory_address (Pmode, op4);
39469           op4 = copy_addr_to_reg (op4);
39470         }
39471       emit_move_insn (gen_rtx_MEM (mode0, op4), op0);
39472
39473       /* Return current CF value.  */
39474       if (target == 0)
39475         target = gen_reg_rtx (QImode);
39476
39477       PUT_MODE (pat, QImode);
39478       emit_insn (gen_rtx_SET (target, pat));
39479       return target;
39480
39481     case IX86_BUILTIN_READ_FLAGS:
39482       emit_insn (gen_push (gen_rtx_REG (word_mode, FLAGS_REG)));
39483
39484       if (optimize
39485           || target == NULL_RTX
39486           || !nonimmediate_operand (target, word_mode)
39487           || GET_MODE (target) != word_mode)
39488         target = gen_reg_rtx (word_mode);
39489
39490       emit_insn (gen_pop (target));
39491       return target;
39492
39493     case IX86_BUILTIN_WRITE_FLAGS:
39494
39495       arg0 = CALL_EXPR_ARG (exp, 0);
39496       op0 = expand_normal (arg0);
39497       if (!general_no_elim_operand (op0, word_mode))
39498         op0 = copy_to_mode_reg (word_mode, op0);
39499
39500       emit_insn (gen_push (op0));
39501       emit_insn (gen_pop (gen_rtx_REG (word_mode, FLAGS_REG)));
39502       return 0;
39503
39504     case IX86_BUILTIN_KORTESTC16:
39505       icode = CODE_FOR_kortestchi;
39506       mode0 = HImode;
39507       mode1 = CCCmode;
39508       goto kortest;
39509
39510     case IX86_BUILTIN_KORTESTZ16:
39511       icode = CODE_FOR_kortestzhi;
39512       mode0 = HImode;
39513       mode1 = CCZmode;
39514
39515     kortest:
39516       arg0 = CALL_EXPR_ARG (exp, 0); /* Mask reg src1.  */
39517       arg1 = CALL_EXPR_ARG (exp, 1); /* Mask reg src2.  */
39518       op0 = expand_normal (arg0);
39519       op1 = expand_normal (arg1);
39520
39521       op0 = copy_to_reg (op0);
39522       op0 = simplify_gen_subreg (mode0, op0, GET_MODE (op0), 0);
39523       op1 = copy_to_reg (op1);
39524       op1 = simplify_gen_subreg (mode0, op1, GET_MODE (op1), 0);
39525
39526       target = gen_reg_rtx (QImode);
39527       emit_insn (gen_rtx_SET (target, const0_rtx));
39528
39529       /* Emit kortest.  */
39530       emit_insn (GEN_FCN (icode) (op0, op1));
39531       /* And use setcc to return result from flags.  */
39532       ix86_expand_setcc (target, EQ,
39533                          gen_rtx_REG (mode1, FLAGS_REG), const0_rtx);
39534       return target;
39535
39536     case IX86_BUILTIN_GATHERSIV2DF:
39537       icode = CODE_FOR_avx2_gathersiv2df;
39538       goto gather_gen;
39539     case IX86_BUILTIN_GATHERSIV4DF:
39540       icode = CODE_FOR_avx2_gathersiv4df;
39541       goto gather_gen;
39542     case IX86_BUILTIN_GATHERDIV2DF:
39543       icode = CODE_FOR_avx2_gatherdiv2df;
39544       goto gather_gen;
39545     case IX86_BUILTIN_GATHERDIV4DF:
39546       icode = CODE_FOR_avx2_gatherdiv4df;
39547       goto gather_gen;
39548     case IX86_BUILTIN_GATHERSIV4SF:
39549       icode = CODE_FOR_avx2_gathersiv4sf;
39550       goto gather_gen;
39551     case IX86_BUILTIN_GATHERSIV8SF:
39552       icode = CODE_FOR_avx2_gathersiv8sf;
39553       goto gather_gen;
39554     case IX86_BUILTIN_GATHERDIV4SF:
39555       icode = CODE_FOR_avx2_gatherdiv4sf;
39556       goto gather_gen;
39557     case IX86_BUILTIN_GATHERDIV8SF:
39558       icode = CODE_FOR_avx2_gatherdiv8sf;
39559       goto gather_gen;
39560     case IX86_BUILTIN_GATHERSIV2DI:
39561       icode = CODE_FOR_avx2_gathersiv2di;
39562       goto gather_gen;
39563     case IX86_BUILTIN_GATHERSIV4DI:
39564       icode = CODE_FOR_avx2_gathersiv4di;
39565       goto gather_gen;
39566     case IX86_BUILTIN_GATHERDIV2DI:
39567       icode = CODE_FOR_avx2_gatherdiv2di;
39568       goto gather_gen;
39569     case IX86_BUILTIN_GATHERDIV4DI:
39570       icode = CODE_FOR_avx2_gatherdiv4di;
39571       goto gather_gen;
39572     case IX86_BUILTIN_GATHERSIV4SI:
39573       icode = CODE_FOR_avx2_gathersiv4si;
39574       goto gather_gen;
39575     case IX86_BUILTIN_GATHERSIV8SI:
39576       icode = CODE_FOR_avx2_gathersiv8si;
39577       goto gather_gen;
39578     case IX86_BUILTIN_GATHERDIV4SI:
39579       icode = CODE_FOR_avx2_gatherdiv4si;
39580       goto gather_gen;
39581     case IX86_BUILTIN_GATHERDIV8SI:
39582       icode = CODE_FOR_avx2_gatherdiv8si;
39583       goto gather_gen;
39584     case IX86_BUILTIN_GATHERALTSIV4DF:
39585       icode = CODE_FOR_avx2_gathersiv4df;
39586       goto gather_gen;
39587     case IX86_BUILTIN_GATHERALTDIV8SF:
39588       icode = CODE_FOR_avx2_gatherdiv8sf;
39589       goto gather_gen;
39590     case IX86_BUILTIN_GATHERALTSIV4DI:
39591       icode = CODE_FOR_avx2_gathersiv4di;
39592       goto gather_gen;
39593     case IX86_BUILTIN_GATHERALTDIV8SI:
39594       icode = CODE_FOR_avx2_gatherdiv8si;
39595       goto gather_gen;
39596     case IX86_BUILTIN_GATHER3SIV16SF:
39597       icode = CODE_FOR_avx512f_gathersiv16sf;
39598       goto gather_gen;
39599     case IX86_BUILTIN_GATHER3SIV8DF:
39600       icode = CODE_FOR_avx512f_gathersiv8df;
39601       goto gather_gen;
39602     case IX86_BUILTIN_GATHER3DIV16SF:
39603       icode = CODE_FOR_avx512f_gatherdiv16sf;
39604       goto gather_gen;
39605     case IX86_BUILTIN_GATHER3DIV8DF:
39606       icode = CODE_FOR_avx512f_gatherdiv8df;
39607       goto gather_gen;
39608     case IX86_BUILTIN_GATHER3SIV16SI:
39609       icode = CODE_FOR_avx512f_gathersiv16si;
39610       goto gather_gen;
39611     case IX86_BUILTIN_GATHER3SIV8DI:
39612       icode = CODE_FOR_avx512f_gathersiv8di;
39613       goto gather_gen;
39614     case IX86_BUILTIN_GATHER3DIV16SI:
39615       icode = CODE_FOR_avx512f_gatherdiv16si;
39616       goto gather_gen;
39617     case IX86_BUILTIN_GATHER3DIV8DI:
39618       icode = CODE_FOR_avx512f_gatherdiv8di;
39619       goto gather_gen;
39620     case IX86_BUILTIN_GATHER3ALTSIV8DF:
39621       icode = CODE_FOR_avx512f_gathersiv8df;
39622       goto gather_gen;
39623     case IX86_BUILTIN_GATHER3ALTDIV16SF:
39624       icode = CODE_FOR_avx512f_gatherdiv16sf;
39625       goto gather_gen;
39626     case IX86_BUILTIN_GATHER3ALTSIV8DI:
39627       icode = CODE_FOR_avx512f_gathersiv8di;
39628       goto gather_gen;
39629     case IX86_BUILTIN_GATHER3ALTDIV16SI:
39630       icode = CODE_FOR_avx512f_gatherdiv16si;
39631       goto gather_gen;
39632     case IX86_BUILTIN_GATHER3SIV2DF:
39633       icode = CODE_FOR_avx512vl_gathersiv2df;
39634       goto gather_gen;
39635     case IX86_BUILTIN_GATHER3SIV4DF:
39636       icode = CODE_FOR_avx512vl_gathersiv4df;
39637       goto gather_gen;
39638     case IX86_BUILTIN_GATHER3DIV2DF:
39639       icode = CODE_FOR_avx512vl_gatherdiv2df;
39640       goto gather_gen;
39641     case IX86_BUILTIN_GATHER3DIV4DF:
39642       icode = CODE_FOR_avx512vl_gatherdiv4df;
39643       goto gather_gen;
39644     case IX86_BUILTIN_GATHER3SIV4SF:
39645       icode = CODE_FOR_avx512vl_gathersiv4sf;
39646       goto gather_gen;
39647     case IX86_BUILTIN_GATHER3SIV8SF:
39648       icode = CODE_FOR_avx512vl_gathersiv8sf;
39649       goto gather_gen;
39650     case IX86_BUILTIN_GATHER3DIV4SF:
39651       icode = CODE_FOR_avx512vl_gatherdiv4sf;
39652       goto gather_gen;
39653     case IX86_BUILTIN_GATHER3DIV8SF:
39654       icode = CODE_FOR_avx512vl_gatherdiv8sf;
39655       goto gather_gen;
39656     case IX86_BUILTIN_GATHER3SIV2DI:
39657       icode = CODE_FOR_avx512vl_gathersiv2di;
39658       goto gather_gen;
39659     case IX86_BUILTIN_GATHER3SIV4DI:
39660       icode = CODE_FOR_avx512vl_gathersiv4di;
39661       goto gather_gen;
39662     case IX86_BUILTIN_GATHER3DIV2DI:
39663       icode = CODE_FOR_avx512vl_gatherdiv2di;
39664       goto gather_gen;
39665     case IX86_BUILTIN_GATHER3DIV4DI:
39666       icode = CODE_FOR_avx512vl_gatherdiv4di;
39667       goto gather_gen;
39668     case IX86_BUILTIN_GATHER3SIV4SI:
39669       icode = CODE_FOR_avx512vl_gathersiv4si;
39670       goto gather_gen;
39671     case IX86_BUILTIN_GATHER3SIV8SI:
39672       icode = CODE_FOR_avx512vl_gathersiv8si;
39673       goto gather_gen;
39674     case IX86_BUILTIN_GATHER3DIV4SI:
39675       icode = CODE_FOR_avx512vl_gatherdiv4si;
39676       goto gather_gen;
39677     case IX86_BUILTIN_GATHER3DIV8SI:
39678       icode = CODE_FOR_avx512vl_gatherdiv8si;
39679       goto gather_gen;
39680     case IX86_BUILTIN_GATHER3ALTSIV4DF:
39681       icode = CODE_FOR_avx512vl_gathersiv4df;
39682       goto gather_gen;
39683     case IX86_BUILTIN_GATHER3ALTDIV8SF:
39684       icode = CODE_FOR_avx512vl_gatherdiv8sf;
39685       goto gather_gen;
39686     case IX86_BUILTIN_GATHER3ALTSIV4DI:
39687       icode = CODE_FOR_avx512vl_gathersiv4di;
39688       goto gather_gen;
39689     case IX86_BUILTIN_GATHER3ALTDIV8SI:
39690       icode = CODE_FOR_avx512vl_gatherdiv8si;
39691       goto gather_gen;
39692     case IX86_BUILTIN_SCATTERSIV16SF:
39693       icode = CODE_FOR_avx512f_scattersiv16sf;
39694       goto scatter_gen;
39695     case IX86_BUILTIN_SCATTERSIV8DF:
39696       icode = CODE_FOR_avx512f_scattersiv8df;
39697       goto scatter_gen;
39698     case IX86_BUILTIN_SCATTERDIV16SF:
39699       icode = CODE_FOR_avx512f_scatterdiv16sf;
39700       goto scatter_gen;
39701     case IX86_BUILTIN_SCATTERDIV8DF:
39702       icode = CODE_FOR_avx512f_scatterdiv8df;
39703       goto scatter_gen;
39704     case IX86_BUILTIN_SCATTERSIV16SI:
39705       icode = CODE_FOR_avx512f_scattersiv16si;
39706       goto scatter_gen;
39707     case IX86_BUILTIN_SCATTERSIV8DI:
39708       icode = CODE_FOR_avx512f_scattersiv8di;
39709       goto scatter_gen;
39710     case IX86_BUILTIN_SCATTERDIV16SI:
39711       icode = CODE_FOR_avx512f_scatterdiv16si;
39712       goto scatter_gen;
39713     case IX86_BUILTIN_SCATTERDIV8DI:
39714       icode = CODE_FOR_avx512f_scatterdiv8di;
39715       goto scatter_gen;
39716     case IX86_BUILTIN_SCATTERSIV8SF:
39717       icode = CODE_FOR_avx512vl_scattersiv8sf;
39718       goto scatter_gen;
39719     case IX86_BUILTIN_SCATTERSIV4SF:
39720       icode = CODE_FOR_avx512vl_scattersiv4sf;
39721       goto scatter_gen;
39722     case IX86_BUILTIN_SCATTERSIV4DF:
39723       icode = CODE_FOR_avx512vl_scattersiv4df;
39724       goto scatter_gen;
39725     case IX86_BUILTIN_SCATTERSIV2DF:
39726       icode = CODE_FOR_avx512vl_scattersiv2df;
39727       goto scatter_gen;
39728     case IX86_BUILTIN_SCATTERDIV8SF:
39729       icode = CODE_FOR_avx512vl_scatterdiv8sf;
39730       goto scatter_gen;
39731     case IX86_BUILTIN_SCATTERDIV4SF:
39732       icode = CODE_FOR_avx512vl_scatterdiv4sf;
39733       goto scatter_gen;
39734     case IX86_BUILTIN_SCATTERDIV4DF:
39735       icode = CODE_FOR_avx512vl_scatterdiv4df;
39736       goto scatter_gen;
39737     case IX86_BUILTIN_SCATTERDIV2DF:
39738       icode = CODE_FOR_avx512vl_scatterdiv2df;
39739       goto scatter_gen;
39740     case IX86_BUILTIN_SCATTERSIV8SI:
39741       icode = CODE_FOR_avx512vl_scattersiv8si;
39742       goto scatter_gen;
39743     case IX86_BUILTIN_SCATTERSIV4SI:
39744       icode = CODE_FOR_avx512vl_scattersiv4si;
39745       goto scatter_gen;
39746     case IX86_BUILTIN_SCATTERSIV4DI:
39747       icode = CODE_FOR_avx512vl_scattersiv4di;
39748       goto scatter_gen;
39749     case IX86_BUILTIN_SCATTERSIV2DI:
39750       icode = CODE_FOR_avx512vl_scattersiv2di;
39751       goto scatter_gen;
39752     case IX86_BUILTIN_SCATTERDIV8SI:
39753       icode = CODE_FOR_avx512vl_scatterdiv8si;
39754       goto scatter_gen;
39755     case IX86_BUILTIN_SCATTERDIV4SI:
39756       icode = CODE_FOR_avx512vl_scatterdiv4si;
39757       goto scatter_gen;
39758     case IX86_BUILTIN_SCATTERDIV4DI:
39759       icode = CODE_FOR_avx512vl_scatterdiv4di;
39760       goto scatter_gen;
39761     case IX86_BUILTIN_SCATTERDIV2DI:
39762       icode = CODE_FOR_avx512vl_scatterdiv2di;
39763       goto scatter_gen;
39764     case IX86_BUILTIN_GATHERPFDPD:
39765       icode = CODE_FOR_avx512pf_gatherpfv8sidf;
39766       goto vec_prefetch_gen;
39767     case IX86_BUILTIN_GATHERPFDPS:
39768       icode = CODE_FOR_avx512pf_gatherpfv16sisf;
39769       goto vec_prefetch_gen;
39770     case IX86_BUILTIN_GATHERPFQPD:
39771       icode = CODE_FOR_avx512pf_gatherpfv8didf;
39772       goto vec_prefetch_gen;
39773     case IX86_BUILTIN_GATHERPFQPS:
39774       icode = CODE_FOR_avx512pf_gatherpfv8disf;
39775       goto vec_prefetch_gen;
39776     case IX86_BUILTIN_SCATTERPFDPD:
39777       icode = CODE_FOR_avx512pf_scatterpfv8sidf;
39778       goto vec_prefetch_gen;
39779     case IX86_BUILTIN_SCATTERPFDPS:
39780       icode = CODE_FOR_avx512pf_scatterpfv16sisf;
39781       goto vec_prefetch_gen;
39782     case IX86_BUILTIN_SCATTERPFQPD:
39783       icode = CODE_FOR_avx512pf_scatterpfv8didf;
39784       goto vec_prefetch_gen;
39785     case IX86_BUILTIN_SCATTERPFQPS:
39786       icode = CODE_FOR_avx512pf_scatterpfv8disf;
39787       goto vec_prefetch_gen;
39788
39789     gather_gen:
39790       rtx half;
39791       rtx (*gen) (rtx, rtx);
39792
39793       arg0 = CALL_EXPR_ARG (exp, 0);
39794       arg1 = CALL_EXPR_ARG (exp, 1);
39795       arg2 = CALL_EXPR_ARG (exp, 2);
39796       arg3 = CALL_EXPR_ARG (exp, 3);
39797       arg4 = CALL_EXPR_ARG (exp, 4);
39798       op0 = expand_normal (arg0);
39799       op1 = expand_normal (arg1);
39800       op2 = expand_normal (arg2);
39801       op3 = expand_normal (arg3);
39802       op4 = expand_normal (arg4);
39803       /* Note the arg order is different from the operand order.  */
39804       mode0 = insn_data[icode].operand[1].mode;
39805       mode2 = insn_data[icode].operand[3].mode;
39806       mode3 = insn_data[icode].operand[4].mode;
39807       mode4 = insn_data[icode].operand[5].mode;
39808
39809       if (target == NULL_RTX
39810           || GET_MODE (target) != insn_data[icode].operand[0].mode
39811           || !insn_data[icode].operand[0].predicate (target,
39812                                                      GET_MODE (target)))
39813         subtarget = gen_reg_rtx (insn_data[icode].operand[0].mode);
39814       else
39815         subtarget = target;
39816
39817       switch (fcode)
39818         {
39819         case IX86_BUILTIN_GATHER3ALTSIV8DF:
39820         case IX86_BUILTIN_GATHER3ALTSIV8DI:
39821           half = gen_reg_rtx (V8SImode);
39822           if (!nonimmediate_operand (op2, V16SImode))
39823             op2 = copy_to_mode_reg (V16SImode, op2);
39824           emit_insn (gen_vec_extract_lo_v16si (half, op2));
39825           op2 = half;
39826           break;
39827         case IX86_BUILTIN_GATHER3ALTSIV4DF:
39828         case IX86_BUILTIN_GATHER3ALTSIV4DI:
39829         case IX86_BUILTIN_GATHERALTSIV4DF:
39830         case IX86_BUILTIN_GATHERALTSIV4DI:
39831           half = gen_reg_rtx (V4SImode);
39832           if (!nonimmediate_operand (op2, V8SImode))
39833             op2 = copy_to_mode_reg (V8SImode, op2);
39834           emit_insn (gen_vec_extract_lo_v8si (half, op2));
39835           op2 = half;
39836           break;
39837         case IX86_BUILTIN_GATHER3ALTDIV16SF:
39838         case IX86_BUILTIN_GATHER3ALTDIV16SI:
39839           half = gen_reg_rtx (mode0);
39840           if (mode0 == V8SFmode)
39841             gen = gen_vec_extract_lo_v16sf;
39842           else
39843             gen = gen_vec_extract_lo_v16si;
39844           if (!nonimmediate_operand (op0, GET_MODE (op0)))
39845             op0 = copy_to_mode_reg (GET_MODE (op0), op0);
39846           emit_insn (gen (half, op0));
39847           op0 = half;
39848           if (GET_MODE (op3) != VOIDmode)
39849             {
39850               if (!nonimmediate_operand (op3, GET_MODE (op3)))
39851                 op3 = copy_to_mode_reg (GET_MODE (op3), op3);
39852               emit_insn (gen (half, op3));
39853               op3 = half;
39854             }
39855           break;
39856         case IX86_BUILTIN_GATHER3ALTDIV8SF:
39857         case IX86_BUILTIN_GATHER3ALTDIV8SI:
39858         case IX86_BUILTIN_GATHERALTDIV8SF:
39859         case IX86_BUILTIN_GATHERALTDIV8SI:
39860           half = gen_reg_rtx (mode0);
39861           if (mode0 == V4SFmode)
39862             gen = gen_vec_extract_lo_v8sf;
39863           else
39864             gen = gen_vec_extract_lo_v8si;
39865           if (!nonimmediate_operand (op0, GET_MODE (op0)))
39866             op0 = copy_to_mode_reg (GET_MODE (op0), op0);
39867           emit_insn (gen (half, op0));
39868           op0 = half;
39869           if (GET_MODE (op3) != VOIDmode)
39870             {
39871               if (!nonimmediate_operand (op3, GET_MODE (op3)))
39872                 op3 = copy_to_mode_reg (GET_MODE (op3), op3);
39873               emit_insn (gen (half, op3));
39874               op3 = half;
39875             }
39876           break;
39877         default:
39878           break;
39879         }
39880
39881       /* Force memory operand only with base register here.  But we
39882          don't want to do it on memory operand for other builtin
39883          functions.  */
39884       op1 = ix86_zero_extend_to_Pmode (op1);
39885
39886       if (!insn_data[icode].operand[1].predicate (op0, mode0))
39887         op0 = copy_to_mode_reg (mode0, op0);
39888       if (!insn_data[icode].operand[2].predicate (op1, Pmode))
39889         op1 = copy_to_mode_reg (Pmode, op1);
39890       if (!insn_data[icode].operand[3].predicate (op2, mode2))
39891         op2 = copy_to_mode_reg (mode2, op2);
39892
39893       op3 = fixup_modeless_constant (op3, mode3);
39894
39895       if (GET_MODE (op3) == mode3 || GET_MODE (op3) == VOIDmode)
39896         {
39897           if (!insn_data[icode].operand[4].predicate (op3, mode3))
39898             op3 = copy_to_mode_reg (mode3, op3);
39899         }
39900       else
39901         {
39902           op3 = copy_to_reg (op3);
39903           op3 = simplify_gen_subreg (mode3, op3, GET_MODE (op3), 0);
39904         }
39905       if (!insn_data[icode].operand[5].predicate (op4, mode4))
39906         {
39907           error ("the last argument must be scale 1, 2, 4, 8");
39908           return const0_rtx;
39909         }
39910
39911       /* Optimize.  If mask is known to have all high bits set,
39912          replace op0 with pc_rtx to signal that the instruction
39913          overwrites the whole destination and doesn't use its
39914          previous contents.  */
39915       if (optimize)
39916         {
39917           if (TREE_CODE (arg3) == INTEGER_CST)
39918             {
39919               if (integer_all_onesp (arg3))
39920                 op0 = pc_rtx;
39921             }
39922           else if (TREE_CODE (arg3) == VECTOR_CST)
39923             {
39924               unsigned int negative = 0;
39925               for (i = 0; i < VECTOR_CST_NELTS (arg3); ++i)
39926                 {
39927                   tree cst = VECTOR_CST_ELT (arg3, i);
39928                   if (TREE_CODE (cst) == INTEGER_CST
39929                       && tree_int_cst_sign_bit (cst))
39930                     negative++;
39931                   else if (TREE_CODE (cst) == REAL_CST
39932                            && REAL_VALUE_NEGATIVE (TREE_REAL_CST (cst)))
39933                     negative++;
39934                 }
39935               if (negative == TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg3)))
39936                 op0 = pc_rtx;
39937             }
39938           else if (TREE_CODE (arg3) == SSA_NAME
39939                    && TREE_CODE (TREE_TYPE (arg3)) == VECTOR_TYPE)
39940             {
39941               /* Recognize also when mask is like:
39942                  __v2df src = _mm_setzero_pd ();
39943                  __v2df mask = _mm_cmpeq_pd (src, src);
39944                  or
39945                  __v8sf src = _mm256_setzero_ps ();
39946                  __v8sf mask = _mm256_cmp_ps (src, src, _CMP_EQ_OQ);
39947                  as that is a cheaper way to load all ones into
39948                  a register than having to load a constant from
39949                  memory.  */
39950               gimple def_stmt = SSA_NAME_DEF_STMT (arg3);
39951               if (is_gimple_call (def_stmt))
39952                 {
39953                   tree fndecl = gimple_call_fndecl (def_stmt);
39954                   if (fndecl
39955                       && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
39956                     switch ((unsigned int) DECL_FUNCTION_CODE (fndecl))
39957                       {
39958                       case IX86_BUILTIN_CMPPD:
39959                       case IX86_BUILTIN_CMPPS:
39960                       case IX86_BUILTIN_CMPPD256:
39961                       case IX86_BUILTIN_CMPPS256:
39962                         if (!integer_zerop (gimple_call_arg (def_stmt, 2)))
39963                           break;
39964                         /* FALLTHRU */
39965                       case IX86_BUILTIN_CMPEQPD:
39966                       case IX86_BUILTIN_CMPEQPS:
39967                         if (initializer_zerop (gimple_call_arg (def_stmt, 0))
39968                             && initializer_zerop (gimple_call_arg (def_stmt,
39969                                                                    1)))
39970                           op0 = pc_rtx;
39971                         break;
39972                       default:
39973                         break;
39974                       }
39975                 }
39976             }
39977         }
39978
39979       pat = GEN_FCN (icode) (subtarget, op0, op1, op2, op3, op4);
39980       if (! pat)
39981         return const0_rtx;
39982       emit_insn (pat);
39983
39984       switch (fcode)
39985         {
39986         case IX86_BUILTIN_GATHER3DIV16SF:
39987           if (target == NULL_RTX)
39988             target = gen_reg_rtx (V8SFmode);
39989           emit_insn (gen_vec_extract_lo_v16sf (target, subtarget));
39990           break;
39991         case IX86_BUILTIN_GATHER3DIV16SI:
39992           if (target == NULL_RTX)
39993             target = gen_reg_rtx (V8SImode);
39994           emit_insn (gen_vec_extract_lo_v16si (target, subtarget));
39995           break;
39996         case IX86_BUILTIN_GATHER3DIV8SF:
39997         case IX86_BUILTIN_GATHERDIV8SF:
39998           if (target == NULL_RTX)
39999             target = gen_reg_rtx (V4SFmode);
40000           emit_insn (gen_vec_extract_lo_v8sf (target, subtarget));
40001           break;
40002         case IX86_BUILTIN_GATHER3DIV8SI:
40003         case IX86_BUILTIN_GATHERDIV8SI:
40004           if (target == NULL_RTX)
40005             target = gen_reg_rtx (V4SImode);
40006           emit_insn (gen_vec_extract_lo_v8si (target, subtarget));
40007           break;
40008         default:
40009           target = subtarget;
40010           break;
40011         }
40012       return target;
40013
40014     scatter_gen:
40015       arg0 = CALL_EXPR_ARG (exp, 0);
40016       arg1 = CALL_EXPR_ARG (exp, 1);
40017       arg2 = CALL_EXPR_ARG (exp, 2);
40018       arg3 = CALL_EXPR_ARG (exp, 3);
40019       arg4 = CALL_EXPR_ARG (exp, 4);
40020       op0 = expand_normal (arg0);
40021       op1 = expand_normal (arg1);
40022       op2 = expand_normal (arg2);
40023       op3 = expand_normal (arg3);
40024       op4 = expand_normal (arg4);
40025       mode1 = insn_data[icode].operand[1].mode;
40026       mode2 = insn_data[icode].operand[2].mode;
40027       mode3 = insn_data[icode].operand[3].mode;
40028       mode4 = insn_data[icode].operand[4].mode;
40029
40030       /* Force memory operand only with base register here.  But we
40031          don't want to do it on memory operand for other builtin
40032          functions.  */
40033       op0 = force_reg (Pmode, convert_to_mode (Pmode, op0, 1));
40034
40035       if (!insn_data[icode].operand[0].predicate (op0, Pmode))
40036         op0 = copy_to_mode_reg (Pmode, op0);
40037
40038       op1 = fixup_modeless_constant (op1, mode1);
40039
40040       if (GET_MODE (op1) == mode1 || GET_MODE (op1) == VOIDmode)
40041         {
40042           if (!insn_data[icode].operand[1].predicate (op1, mode1))
40043             op1 = copy_to_mode_reg (mode1, op1);
40044         }
40045       else
40046         {
40047           op1 = copy_to_reg (op1);
40048           op1 = simplify_gen_subreg (mode1, op1, GET_MODE (op1), 0);
40049         }
40050
40051       if (!insn_data[icode].operand[2].predicate (op2, mode2))
40052         op2 = copy_to_mode_reg (mode2, op2);
40053
40054       if (!insn_data[icode].operand[3].predicate (op3, mode3))
40055         op3 = copy_to_mode_reg (mode3, op3);
40056
40057       if (!insn_data[icode].operand[4].predicate (op4, mode4))
40058         {
40059           error ("the last argument must be scale 1, 2, 4, 8");
40060           return const0_rtx;
40061         }
40062
40063       pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
40064       if (! pat)
40065         return const0_rtx;
40066
40067       emit_insn (pat);
40068       return 0;
40069
40070     vec_prefetch_gen:
40071       arg0 = CALL_EXPR_ARG (exp, 0);
40072       arg1 = CALL_EXPR_ARG (exp, 1);
40073       arg2 = CALL_EXPR_ARG (exp, 2);
40074       arg3 = CALL_EXPR_ARG (exp, 3);
40075       arg4 = CALL_EXPR_ARG (exp, 4);
40076       op0 = expand_normal (arg0);
40077       op1 = expand_normal (arg1);
40078       op2 = expand_normal (arg2);
40079       op3 = expand_normal (arg3);
40080       op4 = expand_normal (arg4);
40081       mode0 = insn_data[icode].operand[0].mode;
40082       mode1 = insn_data[icode].operand[1].mode;
40083       mode3 = insn_data[icode].operand[3].mode;
40084       mode4 = insn_data[icode].operand[4].mode;
40085
40086       op0 = fixup_modeless_constant (op0, mode0);
40087
40088       if (GET_MODE (op0) == mode0
40089           || (GET_MODE (op0) == VOIDmode && op0 != constm1_rtx))
40090         {
40091           if (!insn_data[icode].operand[0].predicate (op0, mode0))
40092             op0 = copy_to_mode_reg (mode0, op0);
40093         }
40094       else if (op0 != constm1_rtx)
40095         {
40096           op0 = copy_to_reg (op0);
40097           op0 = simplify_gen_subreg (mode0, op0, GET_MODE (op0), 0);
40098         }
40099
40100       if (!insn_data[icode].operand[1].predicate (op1, mode1))
40101         op1 = copy_to_mode_reg (mode1, op1);
40102
40103       /* Force memory operand only with base register here.  But we
40104          don't want to do it on memory operand for other builtin
40105          functions.  */
40106       op2 = force_reg (Pmode, convert_to_mode (Pmode, op2, 1));
40107
40108       if (!insn_data[icode].operand[2].predicate (op2, Pmode))
40109         op2 = copy_to_mode_reg (Pmode, op2);
40110
40111       if (!insn_data[icode].operand[3].predicate (op3, mode3))
40112         {
40113           error ("the forth argument must be scale 1, 2, 4, 8");
40114           return const0_rtx;
40115         }
40116
40117       if (!insn_data[icode].operand[4].predicate (op4, mode4))
40118         {
40119           error ("incorrect hint operand");
40120           return const0_rtx;
40121         }
40122
40123       pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
40124       if (! pat)
40125         return const0_rtx;
40126
40127       emit_insn (pat);
40128
40129       return 0;
40130
40131     case IX86_BUILTIN_XABORT:
40132       icode = CODE_FOR_xabort;
40133       arg0 = CALL_EXPR_ARG (exp, 0);
40134       op0 = expand_normal (arg0);
40135       mode0 = insn_data[icode].operand[0].mode;
40136       if (!insn_data[icode].operand[0].predicate (op0, mode0))
40137         {
40138           error ("the xabort's argument must be an 8-bit immediate");
40139           return const0_rtx;
40140         }
40141       emit_insn (gen_xabort (op0));
40142       return 0;
40143
40144     default:
40145       break;
40146     }
40147
40148   for (i = 0, d = bdesc_special_args;
40149        i < ARRAY_SIZE (bdesc_special_args);
40150        i++, d++)
40151     if (d->code == fcode)
40152       return ix86_expand_special_args_builtin (d, exp, target);
40153
40154   for (i = 0, d = bdesc_args;
40155        i < ARRAY_SIZE (bdesc_args);
40156        i++, d++)
40157     if (d->code == fcode)
40158       switch (fcode)
40159         {
40160         case IX86_BUILTIN_FABSQ:
40161         case IX86_BUILTIN_COPYSIGNQ:
40162           if (!TARGET_SSE)
40163             /* Emit a normal call if SSE isn't available.  */
40164             return expand_call (exp, target, ignore);
40165         default:
40166           return ix86_expand_args_builtin (d, exp, target);
40167         }
40168
40169   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
40170     if (d->code == fcode)
40171       return ix86_expand_sse_comi (d, exp, target);
40172
40173   for (i = 0, d = bdesc_round_args; i < ARRAY_SIZE (bdesc_round_args); i++, d++)
40174     if (d->code == fcode)
40175       return ix86_expand_round_builtin (d, exp, target);
40176
40177   for (i = 0, d = bdesc_pcmpestr;
40178        i < ARRAY_SIZE (bdesc_pcmpestr);
40179        i++, d++)
40180     if (d->code == fcode)
40181       return ix86_expand_sse_pcmpestr (d, exp, target);
40182
40183   for (i = 0, d = bdesc_pcmpistr;
40184        i < ARRAY_SIZE (bdesc_pcmpistr);
40185        i++, d++)
40186     if (d->code == fcode)
40187       return ix86_expand_sse_pcmpistr (d, exp, target);
40188
40189   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
40190     if (d->code == fcode)
40191       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
40192                                             (enum ix86_builtin_func_type)
40193                                             d->flag, d->comparison);
40194
40195   gcc_unreachable ();
40196 }
40197
40198 /* This returns the target-specific builtin with code CODE if
40199    current_function_decl has visibility on this builtin, which is checked
40200    using isa flags.  Returns NULL_TREE otherwise.  */
40201
40202 static tree ix86_get_builtin (enum ix86_builtins code)
40203 {
40204   struct cl_target_option *opts;
40205   tree target_tree = NULL_TREE;
40206
40207   /* Determine the isa flags of current_function_decl.  */
40208
40209   if (current_function_decl)
40210     target_tree = DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl);
40211
40212   if (target_tree == NULL)
40213     target_tree = target_option_default_node;
40214
40215   opts = TREE_TARGET_OPTION (target_tree);
40216
40217   if (ix86_builtins_isa[(int) code].isa & opts->x_ix86_isa_flags)
40218     return ix86_builtin_decl (code, true);
40219   else
40220     return NULL_TREE;
40221 }
40222
40223 /* Return function decl for target specific builtin
40224    for given MPX builtin passed i FCODE.  */
40225 static tree
40226 ix86_builtin_mpx_function (unsigned fcode)
40227 {
40228   switch (fcode)
40229     {
40230     case BUILT_IN_CHKP_BNDMK:
40231       return ix86_builtins[IX86_BUILTIN_BNDMK];
40232
40233     case BUILT_IN_CHKP_BNDSTX:
40234       return ix86_builtins[IX86_BUILTIN_BNDSTX];
40235
40236     case BUILT_IN_CHKP_BNDLDX:
40237       return ix86_builtins[IX86_BUILTIN_BNDLDX];
40238
40239     case BUILT_IN_CHKP_BNDCL:
40240       return ix86_builtins[IX86_BUILTIN_BNDCL];
40241
40242     case BUILT_IN_CHKP_BNDCU:
40243       return ix86_builtins[IX86_BUILTIN_BNDCU];
40244
40245     case BUILT_IN_CHKP_BNDRET:
40246       return ix86_builtins[IX86_BUILTIN_BNDRET];
40247
40248     case BUILT_IN_CHKP_INTERSECT:
40249       return ix86_builtins[IX86_BUILTIN_BNDINT];
40250
40251     case BUILT_IN_CHKP_NARROW:
40252       return ix86_builtins[IX86_BUILTIN_BNDNARROW];
40253
40254     case BUILT_IN_CHKP_SIZEOF:
40255       return ix86_builtins[IX86_BUILTIN_SIZEOF];
40256
40257     case BUILT_IN_CHKP_EXTRACT_LOWER:
40258       return ix86_builtins[IX86_BUILTIN_BNDLOWER];
40259
40260     case BUILT_IN_CHKP_EXTRACT_UPPER:
40261       return ix86_builtins[IX86_BUILTIN_BNDUPPER];
40262
40263     default:
40264       return NULL_TREE;
40265     }
40266
40267   gcc_unreachable ();
40268 }
40269
40270 /* Helper function for ix86_load_bounds and ix86_store_bounds.
40271
40272    Return an address to be used to load/store bounds for pointer
40273    passed in SLOT.
40274
40275    SLOT_NO is an integer constant holding number of a target
40276    dependent special slot to be used in case SLOT is not a memory.
40277
40278    SPECIAL_BASE is a pointer to be used as a base of fake address
40279    to access special slots in Bounds Table.  SPECIAL_BASE[-1],
40280    SPECIAL_BASE[-2] etc. will be used as fake pointer locations.  */
40281
40282 static rtx
40283 ix86_get_arg_address_for_bt (rtx slot, rtx slot_no, rtx special_base)
40284 {
40285   rtx addr = NULL;
40286
40287   /* NULL slot means we pass bounds for pointer not passed to the
40288      function at all.  Register slot means we pass pointer in a
40289      register.  In both these cases bounds are passed via Bounds
40290      Table.  Since we do not have actual pointer stored in memory,
40291      we have to use fake addresses to access Bounds Table.  We
40292      start with (special_base - sizeof (void*)) and decrease this
40293      address by pointer size to get addresses for other slots.  */
40294   if (!slot || REG_P (slot))
40295     {
40296       gcc_assert (CONST_INT_P (slot_no));
40297       addr = plus_constant (Pmode, special_base,
40298                             -(INTVAL (slot_no) + 1) * GET_MODE_SIZE (Pmode));
40299     }
40300   /* If pointer is passed in a memory then its address is used to
40301      access Bounds Table.  */
40302   else if (MEM_P (slot))
40303     {
40304       addr = XEXP (slot, 0);
40305       if (!register_operand (addr, Pmode))
40306         addr = copy_addr_to_reg (addr);
40307     }
40308   else
40309     gcc_unreachable ();
40310
40311   return addr;
40312 }
40313
40314 /* Expand pass uses this hook to load bounds for function parameter
40315    PTR passed in SLOT in case its bounds are not passed in a register.
40316
40317    If SLOT is a memory, then bounds are loaded as for regular pointer
40318    loaded from memory.  PTR may be NULL in case SLOT is a memory.
40319    In such case value of PTR (if required) may be loaded from SLOT.
40320
40321    If SLOT is NULL or a register then SLOT_NO is an integer constant
40322    holding number of the target dependent special slot which should be
40323    used to obtain bounds.
40324
40325    Return loaded bounds.  */
40326
40327 static rtx
40328 ix86_load_bounds (rtx slot, rtx ptr, rtx slot_no)
40329 {
40330   rtx reg = gen_reg_rtx (BNDmode);
40331   rtx addr;
40332
40333   /* Get address to be used to access Bounds Table.  Special slots start
40334      at the location of return address of the current function.  */
40335   addr = ix86_get_arg_address_for_bt (slot, slot_no, arg_pointer_rtx);
40336
40337   /* Load pointer value from a memory if we don't have it.  */
40338   if (!ptr)
40339     {
40340       gcc_assert (MEM_P (slot));
40341       ptr = copy_addr_to_reg (slot);
40342     }
40343
40344   emit_insn (BNDmode == BND64mode
40345              ? gen_bnd64_ldx (reg, addr, ptr)
40346              : gen_bnd32_ldx (reg, addr, ptr));
40347
40348   return reg;
40349 }
40350
40351 /* Expand pass uses this hook to store BOUNDS for call argument PTR
40352    passed in SLOT in case BOUNDS are not passed in a register.
40353
40354    If SLOT is a memory, then BOUNDS are stored as for regular pointer
40355    stored in memory.  PTR may be NULL in case SLOT is a memory.
40356    In such case value of PTR (if required) may be loaded from SLOT.
40357
40358    If SLOT is NULL or a register then SLOT_NO is an integer constant
40359    holding number of the target dependent special slot which should be
40360    used to store BOUNDS.  */
40361
40362 static void
40363 ix86_store_bounds (rtx ptr, rtx slot, rtx bounds, rtx slot_no)
40364 {
40365   rtx addr;
40366
40367   /* Get address to be used to access Bounds Table.  Special slots start
40368      at the location of return address of a called function.  */
40369   addr = ix86_get_arg_address_for_bt (slot, slot_no, stack_pointer_rtx);
40370
40371   /* Load pointer value from a memory if we don't have it.  */
40372   if (!ptr)
40373     {
40374       gcc_assert (MEM_P (slot));
40375       ptr = copy_addr_to_reg (slot);
40376     }
40377
40378   gcc_assert (POINTER_BOUNDS_MODE_P (GET_MODE (bounds)));
40379   if (!register_operand (bounds, BNDmode))
40380     bounds = copy_to_mode_reg (BNDmode, bounds);
40381
40382   emit_insn (BNDmode == BND64mode
40383              ? gen_bnd64_stx (addr, ptr, bounds)
40384              : gen_bnd32_stx (addr, ptr, bounds));
40385 }
40386
40387 /* Load and return bounds returned by function in SLOT.  */
40388
40389 static rtx
40390 ix86_load_returned_bounds (rtx slot)
40391 {
40392   rtx res;
40393
40394   gcc_assert (REG_P (slot));
40395   res = gen_reg_rtx (BNDmode);
40396   emit_move_insn (res, slot);
40397
40398   return res;
40399 }
40400
40401 /* Store BOUNDS returned by function into SLOT.  */
40402
40403 static void
40404 ix86_store_returned_bounds (rtx slot, rtx bounds)
40405 {
40406   gcc_assert (REG_P (slot));
40407   emit_move_insn (slot, bounds);
40408 }
40409
40410 /* Returns a function decl for a vectorized version of the builtin function
40411    with builtin function code FN and the result vector type TYPE, or NULL_TREE
40412    if it is not available.  */
40413
40414 static tree
40415 ix86_builtin_vectorized_function (tree fndecl, tree type_out,
40416                                   tree type_in)
40417 {
40418   machine_mode in_mode, out_mode;
40419   int in_n, out_n;
40420   enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
40421
40422   if (TREE_CODE (type_out) != VECTOR_TYPE
40423       || TREE_CODE (type_in) != VECTOR_TYPE
40424       || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
40425     return NULL_TREE;
40426
40427   out_mode = TYPE_MODE (TREE_TYPE (type_out));
40428   out_n = TYPE_VECTOR_SUBPARTS (type_out);
40429   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40430   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40431
40432   switch (fn)
40433     {
40434     case BUILT_IN_SQRT:
40435       if (out_mode == DFmode && in_mode == DFmode)
40436         {
40437           if (out_n == 2 && in_n == 2)
40438             return ix86_get_builtin (IX86_BUILTIN_SQRTPD);
40439           else if (out_n == 4 && in_n == 4)
40440             return ix86_get_builtin (IX86_BUILTIN_SQRTPD256);
40441           else if (out_n == 8 && in_n == 8)
40442             return ix86_get_builtin (IX86_BUILTIN_SQRTPD512);
40443         }
40444       break;
40445
40446     case BUILT_IN_EXP2F:
40447       if (out_mode == SFmode && in_mode == SFmode)
40448         {
40449           if (out_n == 16 && in_n == 16)
40450             return ix86_get_builtin (IX86_BUILTIN_EXP2PS);
40451         }
40452       break;
40453
40454     case BUILT_IN_SQRTF:
40455       if (out_mode == SFmode && in_mode == SFmode)
40456         {
40457           if (out_n == 4 && in_n == 4)
40458             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR);
40459           else if (out_n == 8 && in_n == 8)
40460             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR256);
40461           else if (out_n == 16 && in_n == 16)
40462             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR512);
40463         }
40464       break;
40465
40466     case BUILT_IN_IFLOOR:
40467     case BUILT_IN_LFLOOR:
40468     case BUILT_IN_LLFLOOR:
40469       /* The round insn does not trap on denormals.  */
40470       if (flag_trapping_math || !TARGET_ROUND)
40471         break;
40472
40473       if (out_mode == SImode && in_mode == DFmode)
40474         {
40475           if (out_n == 4 && in_n == 2)
40476             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX);
40477           else if (out_n == 8 && in_n == 4)
40478             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256);
40479           else if (out_n == 16 && in_n == 8)
40480             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512);
40481         }
40482       break;
40483
40484     case BUILT_IN_IFLOORF:
40485     case BUILT_IN_LFLOORF:
40486     case BUILT_IN_LLFLOORF:
40487       /* The round insn does not trap on denormals.  */
40488       if (flag_trapping_math || !TARGET_ROUND)
40489         break;
40490
40491       if (out_mode == SImode && in_mode == SFmode)
40492         {
40493           if (out_n == 4 && in_n == 4)
40494             return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX);
40495           else if (out_n == 8 && in_n == 8)
40496             return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX256);
40497         }
40498       break;
40499
40500     case BUILT_IN_ICEIL:
40501     case BUILT_IN_LCEIL:
40502     case BUILT_IN_LLCEIL:
40503       /* The round insn does not trap on denormals.  */
40504       if (flag_trapping_math || !TARGET_ROUND)
40505         break;
40506
40507       if (out_mode == SImode && in_mode == DFmode)
40508         {
40509           if (out_n == 4 && in_n == 2)
40510             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX);
40511           else if (out_n == 8 && in_n == 4)
40512             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256);
40513           else if (out_n == 16 && in_n == 8)
40514             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512);
40515         }
40516       break;
40517
40518     case BUILT_IN_ICEILF:
40519     case BUILT_IN_LCEILF:
40520     case BUILT_IN_LLCEILF:
40521       /* The round insn does not trap on denormals.  */
40522       if (flag_trapping_math || !TARGET_ROUND)
40523         break;
40524
40525       if (out_mode == SImode && in_mode == SFmode)
40526         {
40527           if (out_n == 4 && in_n == 4)
40528             return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX);
40529           else if (out_n == 8 && in_n == 8)
40530             return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX256);
40531         }
40532       break;
40533
40534     case BUILT_IN_IRINT:
40535     case BUILT_IN_LRINT:
40536     case BUILT_IN_LLRINT:
40537       if (out_mode == SImode && in_mode == DFmode)
40538         {
40539           if (out_n == 4 && in_n == 2)
40540             return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX);
40541           else if (out_n == 8 && in_n == 4)
40542             return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX256);
40543         }
40544       break;
40545
40546     case BUILT_IN_IRINTF:
40547     case BUILT_IN_LRINTF:
40548     case BUILT_IN_LLRINTF:
40549       if (out_mode == SImode && in_mode == SFmode)
40550         {
40551           if (out_n == 4 && in_n == 4)
40552             return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ);
40553           else if (out_n == 8 && in_n == 8)
40554             return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ256);
40555         }
40556       break;
40557
40558     case BUILT_IN_IROUND:
40559     case BUILT_IN_LROUND:
40560     case BUILT_IN_LLROUND:
40561       /* The round insn does not trap on denormals.  */
40562       if (flag_trapping_math || !TARGET_ROUND)
40563         break;
40564
40565       if (out_mode == SImode && in_mode == DFmode)
40566         {
40567           if (out_n == 4 && in_n == 2)
40568             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX);
40569           else if (out_n == 8 && in_n == 4)
40570             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256);
40571           else if (out_n == 16 && in_n == 8)
40572             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512);
40573         }
40574       break;
40575
40576     case BUILT_IN_IROUNDF:
40577     case BUILT_IN_LROUNDF:
40578     case BUILT_IN_LLROUNDF:
40579       /* The round insn does not trap on denormals.  */
40580       if (flag_trapping_math || !TARGET_ROUND)
40581         break;
40582
40583       if (out_mode == SImode && in_mode == SFmode)
40584         {
40585           if (out_n == 4 && in_n == 4)
40586             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX);
40587           else if (out_n == 8 && in_n == 8)
40588             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX256);
40589         }
40590       break;
40591
40592     case BUILT_IN_COPYSIGN:
40593       if (out_mode == DFmode && in_mode == DFmode)
40594         {
40595           if (out_n == 2 && in_n == 2)
40596             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD);
40597           else if (out_n == 4 && in_n == 4)
40598             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD256);
40599           else if (out_n == 8 && in_n == 8)
40600             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD512);
40601         }
40602       break;
40603
40604     case BUILT_IN_COPYSIGNF:
40605       if (out_mode == SFmode && in_mode == SFmode)
40606         {
40607           if (out_n == 4 && in_n == 4)
40608             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS);
40609           else if (out_n == 8 && in_n == 8)
40610             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS256);
40611           else if (out_n == 16 && in_n == 16)
40612             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS512);
40613         }
40614       break;
40615
40616     case BUILT_IN_FLOOR:
40617       /* The round insn does not trap on denormals.  */
40618       if (flag_trapping_math || !TARGET_ROUND)
40619         break;
40620
40621       if (out_mode == DFmode && in_mode == DFmode)
40622         {
40623           if (out_n == 2 && in_n == 2)
40624             return ix86_get_builtin (IX86_BUILTIN_FLOORPD);
40625           else if (out_n == 4 && in_n == 4)
40626             return ix86_get_builtin (IX86_BUILTIN_FLOORPD256);
40627         }
40628       break;
40629
40630     case BUILT_IN_FLOORF:
40631       /* The round insn does not trap on denormals.  */
40632       if (flag_trapping_math || !TARGET_ROUND)
40633         break;
40634
40635       if (out_mode == SFmode && in_mode == SFmode)
40636         {
40637           if (out_n == 4 && in_n == 4)
40638             return ix86_get_builtin (IX86_BUILTIN_FLOORPS);
40639           else if (out_n == 8 && in_n == 8)
40640             return ix86_get_builtin (IX86_BUILTIN_FLOORPS256);
40641         }
40642       break;
40643
40644     case BUILT_IN_CEIL:
40645       /* The round insn does not trap on denormals.  */
40646       if (flag_trapping_math || !TARGET_ROUND)
40647         break;
40648
40649       if (out_mode == DFmode && in_mode == DFmode)
40650         {
40651           if (out_n == 2 && in_n == 2)
40652             return ix86_get_builtin (IX86_BUILTIN_CEILPD);
40653           else if (out_n == 4 && in_n == 4)
40654             return ix86_get_builtin (IX86_BUILTIN_CEILPD256);
40655         }
40656       break;
40657
40658     case BUILT_IN_CEILF:
40659       /* The round insn does not trap on denormals.  */
40660       if (flag_trapping_math || !TARGET_ROUND)
40661         break;
40662
40663       if (out_mode == SFmode && in_mode == SFmode)
40664         {
40665           if (out_n == 4 && in_n == 4)
40666             return ix86_get_builtin (IX86_BUILTIN_CEILPS);
40667           else if (out_n == 8 && in_n == 8)
40668             return ix86_get_builtin (IX86_BUILTIN_CEILPS256);
40669         }
40670       break;
40671
40672     case BUILT_IN_TRUNC:
40673       /* The round insn does not trap on denormals.  */
40674       if (flag_trapping_math || !TARGET_ROUND)
40675         break;
40676
40677       if (out_mode == DFmode && in_mode == DFmode)
40678         {
40679           if (out_n == 2 && in_n == 2)
40680             return ix86_get_builtin (IX86_BUILTIN_TRUNCPD);
40681           else if (out_n == 4 && in_n == 4)
40682             return ix86_get_builtin (IX86_BUILTIN_TRUNCPD256);
40683         }
40684       break;
40685
40686     case BUILT_IN_TRUNCF:
40687       /* The round insn does not trap on denormals.  */
40688       if (flag_trapping_math || !TARGET_ROUND)
40689         break;
40690
40691       if (out_mode == SFmode && in_mode == SFmode)
40692         {
40693           if (out_n == 4 && in_n == 4)
40694             return ix86_get_builtin (IX86_BUILTIN_TRUNCPS);
40695           else if (out_n == 8 && in_n == 8)
40696             return ix86_get_builtin (IX86_BUILTIN_TRUNCPS256);
40697         }
40698       break;
40699
40700     case BUILT_IN_RINT:
40701       /* The round insn does not trap on denormals.  */
40702       if (flag_trapping_math || !TARGET_ROUND)
40703         break;
40704
40705       if (out_mode == DFmode && in_mode == DFmode)
40706         {
40707           if (out_n == 2 && in_n == 2)
40708             return ix86_get_builtin (IX86_BUILTIN_RINTPD);
40709           else if (out_n == 4 && in_n == 4)
40710             return ix86_get_builtin (IX86_BUILTIN_RINTPD256);
40711         }
40712       break;
40713
40714     case BUILT_IN_RINTF:
40715       /* The round insn does not trap on denormals.  */
40716       if (flag_trapping_math || !TARGET_ROUND)
40717         break;
40718
40719       if (out_mode == SFmode && in_mode == SFmode)
40720         {
40721           if (out_n == 4 && in_n == 4)
40722             return ix86_get_builtin (IX86_BUILTIN_RINTPS);
40723           else if (out_n == 8 && in_n == 8)
40724             return ix86_get_builtin (IX86_BUILTIN_RINTPS256);
40725         }
40726       break;
40727
40728     case BUILT_IN_ROUND:
40729       /* The round insn does not trap on denormals.  */
40730       if (flag_trapping_math || !TARGET_ROUND)
40731         break;
40732
40733       if (out_mode == DFmode && in_mode == DFmode)
40734         {
40735           if (out_n == 2 && in_n == 2)
40736             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ);
40737           else if (out_n == 4 && in_n == 4)
40738             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ256);
40739         }
40740       break;
40741
40742     case BUILT_IN_ROUNDF:
40743       /* The round insn does not trap on denormals.  */
40744       if (flag_trapping_math || !TARGET_ROUND)
40745         break;
40746
40747       if (out_mode == SFmode && in_mode == SFmode)
40748         {
40749           if (out_n == 4 && in_n == 4)
40750             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ);
40751           else if (out_n == 8 && in_n == 8)
40752             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ256);
40753         }
40754       break;
40755
40756     case BUILT_IN_FMA:
40757       if (out_mode == DFmode && in_mode == DFmode)
40758         {
40759           if (out_n == 2 && in_n == 2)
40760             return ix86_get_builtin (IX86_BUILTIN_VFMADDPD);
40761           if (out_n == 4 && in_n == 4)
40762             return ix86_get_builtin (IX86_BUILTIN_VFMADDPD256);
40763         }
40764       break;
40765
40766     case BUILT_IN_FMAF:
40767       if (out_mode == SFmode && in_mode == SFmode)
40768         {
40769           if (out_n == 4 && in_n == 4)
40770             return ix86_get_builtin (IX86_BUILTIN_VFMADDPS);
40771           if (out_n == 8 && in_n == 8)
40772             return ix86_get_builtin (IX86_BUILTIN_VFMADDPS256);
40773         }
40774       break;
40775
40776     default:
40777       break;
40778     }
40779
40780   /* Dispatch to a handler for a vectorization library.  */
40781   if (ix86_veclib_handler)
40782     return ix86_veclib_handler ((enum built_in_function) fn, type_out,
40783                                 type_in);
40784
40785   return NULL_TREE;
40786 }
40787
40788 /* Handler for an SVML-style interface to
40789    a library with vectorized intrinsics.  */
40790
40791 static tree
40792 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
40793 {
40794   char name[20];
40795   tree fntype, new_fndecl, args;
40796   unsigned arity;
40797   const char *bname;
40798   machine_mode el_mode, in_mode;
40799   int n, in_n;
40800
40801   /* The SVML is suitable for unsafe math only.  */
40802   if (!flag_unsafe_math_optimizations)
40803     return NULL_TREE;
40804
40805   el_mode = TYPE_MODE (TREE_TYPE (type_out));
40806   n = TYPE_VECTOR_SUBPARTS (type_out);
40807   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40808   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40809   if (el_mode != in_mode
40810       || n != in_n)
40811     return NULL_TREE;
40812
40813   switch (fn)
40814     {
40815     case BUILT_IN_EXP:
40816     case BUILT_IN_LOG:
40817     case BUILT_IN_LOG10:
40818     case BUILT_IN_POW:
40819     case BUILT_IN_TANH:
40820     case BUILT_IN_TAN:
40821     case BUILT_IN_ATAN:
40822     case BUILT_IN_ATAN2:
40823     case BUILT_IN_ATANH:
40824     case BUILT_IN_CBRT:
40825     case BUILT_IN_SINH:
40826     case BUILT_IN_SIN:
40827     case BUILT_IN_ASINH:
40828     case BUILT_IN_ASIN:
40829     case BUILT_IN_COSH:
40830     case BUILT_IN_COS:
40831     case BUILT_IN_ACOSH:
40832     case BUILT_IN_ACOS:
40833       if (el_mode != DFmode || n != 2)
40834         return NULL_TREE;
40835       break;
40836
40837     case BUILT_IN_EXPF:
40838     case BUILT_IN_LOGF:
40839     case BUILT_IN_LOG10F:
40840     case BUILT_IN_POWF:
40841     case BUILT_IN_TANHF:
40842     case BUILT_IN_TANF:
40843     case BUILT_IN_ATANF:
40844     case BUILT_IN_ATAN2F:
40845     case BUILT_IN_ATANHF:
40846     case BUILT_IN_CBRTF:
40847     case BUILT_IN_SINHF:
40848     case BUILT_IN_SINF:
40849     case BUILT_IN_ASINHF:
40850     case BUILT_IN_ASINF:
40851     case BUILT_IN_COSHF:
40852     case BUILT_IN_COSF:
40853     case BUILT_IN_ACOSHF:
40854     case BUILT_IN_ACOSF:
40855       if (el_mode != SFmode || n != 4)
40856         return NULL_TREE;
40857       break;
40858
40859     default:
40860       return NULL_TREE;
40861     }
40862
40863   bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
40864
40865   if (fn == BUILT_IN_LOGF)
40866     strcpy (name, "vmlsLn4");
40867   else if (fn == BUILT_IN_LOG)
40868     strcpy (name, "vmldLn2");
40869   else if (n == 4)
40870     {
40871       sprintf (name, "vmls%s", bname+10);
40872       name[strlen (name)-1] = '4';
40873     }
40874   else
40875     sprintf (name, "vmld%s2", bname+10);
40876
40877   /* Convert to uppercase. */
40878   name[4] &= ~0x20;
40879
40880   arity = 0;
40881   for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
40882        args;
40883        args = TREE_CHAIN (args))
40884     arity++;
40885
40886   if (arity == 1)
40887     fntype = build_function_type_list (type_out, type_in, NULL);
40888   else
40889     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
40890
40891   /* Build a function declaration for the vectorized function.  */
40892   new_fndecl = build_decl (BUILTINS_LOCATION,
40893                            FUNCTION_DECL, get_identifier (name), fntype);
40894   TREE_PUBLIC (new_fndecl) = 1;
40895   DECL_EXTERNAL (new_fndecl) = 1;
40896   DECL_IS_NOVOPS (new_fndecl) = 1;
40897   TREE_READONLY (new_fndecl) = 1;
40898
40899   return new_fndecl;
40900 }
40901
40902 /* Handler for an ACML-style interface to
40903    a library with vectorized intrinsics.  */
40904
40905 static tree
40906 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
40907 {
40908   char name[20] = "__vr.._";
40909   tree fntype, new_fndecl, args;
40910   unsigned arity;
40911   const char *bname;
40912   machine_mode el_mode, in_mode;
40913   int n, in_n;
40914
40915   /* The ACML is 64bits only and suitable for unsafe math only as
40916      it does not correctly support parts of IEEE with the required
40917      precision such as denormals.  */
40918   if (!TARGET_64BIT
40919       || !flag_unsafe_math_optimizations)
40920     return NULL_TREE;
40921
40922   el_mode = TYPE_MODE (TREE_TYPE (type_out));
40923   n = TYPE_VECTOR_SUBPARTS (type_out);
40924   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40925   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40926   if (el_mode != in_mode
40927       || n != in_n)
40928     return NULL_TREE;
40929
40930   switch (fn)
40931     {
40932     case BUILT_IN_SIN:
40933     case BUILT_IN_COS:
40934     case BUILT_IN_EXP:
40935     case BUILT_IN_LOG:
40936     case BUILT_IN_LOG2:
40937     case BUILT_IN_LOG10:
40938       name[4] = 'd';
40939       name[5] = '2';
40940       if (el_mode != DFmode
40941           || n != 2)
40942         return NULL_TREE;
40943       break;
40944
40945     case BUILT_IN_SINF:
40946     case BUILT_IN_COSF:
40947     case BUILT_IN_EXPF:
40948     case BUILT_IN_POWF:
40949     case BUILT_IN_LOGF:
40950     case BUILT_IN_LOG2F:
40951     case BUILT_IN_LOG10F:
40952       name[4] = 's';
40953       name[5] = '4';
40954       if (el_mode != SFmode
40955           || n != 4)
40956         return NULL_TREE;
40957       break;
40958
40959     default:
40960       return NULL_TREE;
40961     }
40962
40963   bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
40964   sprintf (name + 7, "%s", bname+10);
40965
40966   arity = 0;
40967   for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
40968        args;
40969        args = TREE_CHAIN (args))
40970     arity++;
40971
40972   if (arity == 1)
40973     fntype = build_function_type_list (type_out, type_in, NULL);
40974   else
40975     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
40976
40977   /* Build a function declaration for the vectorized function.  */
40978   new_fndecl = build_decl (BUILTINS_LOCATION,
40979                            FUNCTION_DECL, get_identifier (name), fntype);
40980   TREE_PUBLIC (new_fndecl) = 1;
40981   DECL_EXTERNAL (new_fndecl) = 1;
40982   DECL_IS_NOVOPS (new_fndecl) = 1;
40983   TREE_READONLY (new_fndecl) = 1;
40984
40985   return new_fndecl;
40986 }
40987
40988 /* Returns a decl of a function that implements gather load with
40989    memory type MEM_VECTYPE and index type INDEX_VECTYPE and SCALE.
40990    Return NULL_TREE if it is not available.  */
40991
40992 static tree
40993 ix86_vectorize_builtin_gather (const_tree mem_vectype,
40994                                const_tree index_type, int scale)
40995 {
40996   bool si;
40997   enum ix86_builtins code;
40998
40999   if (! TARGET_AVX2)
41000     return NULL_TREE;
41001
41002   if ((TREE_CODE (index_type) != INTEGER_TYPE
41003        && !POINTER_TYPE_P (index_type))
41004       || (TYPE_MODE (index_type) != SImode
41005           && TYPE_MODE (index_type) != DImode))
41006     return NULL_TREE;
41007
41008   if (TYPE_PRECISION (index_type) > POINTER_SIZE)
41009     return NULL_TREE;
41010
41011   /* v*gather* insn sign extends index to pointer mode.  */
41012   if (TYPE_PRECISION (index_type) < POINTER_SIZE
41013       && TYPE_UNSIGNED (index_type))
41014     return NULL_TREE;
41015
41016   if (scale <= 0
41017       || scale > 8
41018       || (scale & (scale - 1)) != 0)
41019     return NULL_TREE;
41020
41021   si = TYPE_MODE (index_type) == SImode;
41022   switch (TYPE_MODE (mem_vectype))
41023     {
41024     case V2DFmode:
41025       if (TARGET_AVX512VL)
41026         code = si ? IX86_BUILTIN_GATHER3SIV2DF : IX86_BUILTIN_GATHER3DIV2DF;
41027       else
41028         code = si ? IX86_BUILTIN_GATHERSIV2DF : IX86_BUILTIN_GATHERDIV2DF;
41029       break;
41030     case V4DFmode:
41031       if (TARGET_AVX512VL)
41032         code = si ? IX86_BUILTIN_GATHER3ALTSIV4DF : IX86_BUILTIN_GATHER3DIV4DF;
41033       else
41034         code = si ? IX86_BUILTIN_GATHERALTSIV4DF : IX86_BUILTIN_GATHERDIV4DF;
41035       break;
41036     case V2DImode:
41037       if (TARGET_AVX512VL)
41038         code = si ? IX86_BUILTIN_GATHER3SIV2DI : IX86_BUILTIN_GATHER3DIV2DI;
41039       else
41040         code = si ? IX86_BUILTIN_GATHERSIV2DI : IX86_BUILTIN_GATHERDIV2DI;
41041       break;
41042     case V4DImode:
41043       if (TARGET_AVX512VL)
41044         code = si ? IX86_BUILTIN_GATHER3ALTSIV4DI : IX86_BUILTIN_GATHER3DIV4DI;
41045       else
41046         code = si ? IX86_BUILTIN_GATHERALTSIV4DI : IX86_BUILTIN_GATHERDIV4DI;
41047       break;
41048     case V4SFmode:
41049       if (TARGET_AVX512VL)
41050         code = si ? IX86_BUILTIN_GATHER3SIV4SF : IX86_BUILTIN_GATHER3DIV4SF;
41051       else
41052         code = si ? IX86_BUILTIN_GATHERSIV4SF : IX86_BUILTIN_GATHERDIV4SF;
41053       break;
41054     case V8SFmode:
41055       if (TARGET_AVX512VL)
41056         code = si ? IX86_BUILTIN_GATHER3SIV8SF : IX86_BUILTIN_GATHER3ALTDIV8SF;
41057       else
41058         code = si ? IX86_BUILTIN_GATHERSIV8SF : IX86_BUILTIN_GATHERALTDIV8SF;
41059       break;
41060     case V4SImode:
41061       if (TARGET_AVX512VL)
41062         code = si ? IX86_BUILTIN_GATHER3SIV4SI : IX86_BUILTIN_GATHER3DIV4SI;
41063       else
41064         code = si ? IX86_BUILTIN_GATHERSIV4SI : IX86_BUILTIN_GATHERDIV4SI;
41065       break;
41066     case V8SImode:
41067       if (TARGET_AVX512VL)
41068         code = si ? IX86_BUILTIN_GATHER3SIV8SI : IX86_BUILTIN_GATHER3ALTDIV8SI;
41069       else
41070         code = si ? IX86_BUILTIN_GATHERSIV8SI : IX86_BUILTIN_GATHERALTDIV8SI;
41071       break;
41072     case V8DFmode:
41073       if (TARGET_AVX512F)
41074         code = si ? IX86_BUILTIN_GATHER3ALTSIV8DF : IX86_BUILTIN_GATHER3DIV8DF;
41075       else
41076         return NULL_TREE;
41077       break;
41078     case V8DImode:
41079       if (TARGET_AVX512F)
41080         code = si ? IX86_BUILTIN_GATHER3ALTSIV8DI : IX86_BUILTIN_GATHER3DIV8DI;
41081       else
41082         return NULL_TREE;
41083       break;
41084     case V16SFmode:
41085       if (TARGET_AVX512F)
41086         code = si ? IX86_BUILTIN_GATHER3SIV16SF : IX86_BUILTIN_GATHER3ALTDIV16SF;
41087       else
41088         return NULL_TREE;
41089       break;
41090     case V16SImode:
41091       if (TARGET_AVX512F)
41092         code = si ? IX86_BUILTIN_GATHER3SIV16SI : IX86_BUILTIN_GATHER3ALTDIV16SI;
41093       else
41094         return NULL_TREE;
41095       break;
41096     default:
41097       return NULL_TREE;
41098     }
41099
41100   return ix86_get_builtin (code);
41101 }
41102
41103 /* Returns a code for a target-specific builtin that implements
41104    reciprocal of the function, or NULL_TREE if not available.  */
41105
41106 static tree
41107 ix86_builtin_reciprocal (unsigned int fn, bool md_fn, bool)
41108 {
41109   if (! (TARGET_SSE_MATH && !optimize_insn_for_size_p ()
41110          && flag_finite_math_only && !flag_trapping_math
41111          && flag_unsafe_math_optimizations))
41112     return NULL_TREE;
41113
41114   if (md_fn)
41115     /* Machine dependent builtins.  */
41116     switch (fn)
41117       {
41118         /* Vectorized version of sqrt to rsqrt conversion.  */
41119       case IX86_BUILTIN_SQRTPS_NR:
41120         return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR);
41121
41122       case IX86_BUILTIN_SQRTPS_NR256:
41123         return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR256);
41124
41125       default:
41126         return NULL_TREE;
41127       }
41128   else
41129     /* Normal builtins.  */
41130     switch (fn)
41131       {
41132         /* Sqrt to rsqrt conversion.  */
41133       case BUILT_IN_SQRTF:
41134         return ix86_get_builtin (IX86_BUILTIN_RSQRTF);
41135
41136       default:
41137         return NULL_TREE;
41138       }
41139 }
41140 \f
41141 /* Helper for avx_vpermilps256_operand et al.  This is also used by
41142    the expansion functions to turn the parallel back into a mask.
41143    The return value is 0 for no match and the imm8+1 for a match.  */
41144
41145 int
41146 avx_vpermilp_parallel (rtx par, machine_mode mode)
41147 {
41148   unsigned i, nelt = GET_MODE_NUNITS (mode);
41149   unsigned mask = 0;
41150   unsigned char ipar[16] = {};  /* Silence -Wuninitialized warning.  */
41151
41152   if (XVECLEN (par, 0) != (int) nelt)
41153     return 0;
41154
41155   /* Validate that all of the elements are constants, and not totally
41156      out of range.  Copy the data into an integral array to make the
41157      subsequent checks easier.  */
41158   for (i = 0; i < nelt; ++i)
41159     {
41160       rtx er = XVECEXP (par, 0, i);
41161       unsigned HOST_WIDE_INT ei;
41162
41163       if (!CONST_INT_P (er))
41164         return 0;
41165       ei = INTVAL (er);
41166       if (ei >= nelt)
41167         return 0;
41168       ipar[i] = ei;
41169     }
41170
41171   switch (mode)
41172     {
41173     case V8DFmode:
41174       /* In the 512-bit DFmode case, we can only move elements within
41175          a 128-bit lane.  First fill the second part of the mask,
41176          then fallthru.  */
41177       for (i = 4; i < 6; ++i)
41178         {
41179           if (ipar[i] < 4 || ipar[i] >= 6)
41180             return 0;
41181           mask |= (ipar[i] - 4) << i;
41182         }
41183       for (i = 6; i < 8; ++i)
41184         {
41185           if (ipar[i] < 6)
41186             return 0;
41187           mask |= (ipar[i] - 6) << i;
41188         }
41189       /* FALLTHRU */
41190
41191     case V4DFmode:
41192       /* In the 256-bit DFmode case, we can only move elements within
41193          a 128-bit lane.  */
41194       for (i = 0; i < 2; ++i)
41195         {
41196           if (ipar[i] >= 2)
41197             return 0;
41198           mask |= ipar[i] << i;
41199         }
41200       for (i = 2; i < 4; ++i)
41201         {
41202           if (ipar[i] < 2)
41203             return 0;
41204           mask |= (ipar[i] - 2) << i;
41205         }
41206       break;
41207
41208     case V16SFmode:
41209       /* In 512 bit SFmode case, permutation in the upper 256 bits
41210          must mirror the permutation in the lower 256-bits.  */
41211       for (i = 0; i < 8; ++i)
41212         if (ipar[i] + 8 != ipar[i + 8])
41213           return 0;
41214       /* FALLTHRU */
41215
41216     case V8SFmode:
41217       /* In 256 bit SFmode case, we have full freedom of
41218          movement within the low 128-bit lane, but the high 128-bit
41219          lane must mirror the exact same pattern.  */
41220       for (i = 0; i < 4; ++i)
41221         if (ipar[i] + 4 != ipar[i + 4])
41222           return 0;
41223       nelt = 4;
41224       /* FALLTHRU */
41225
41226     case V2DFmode:
41227     case V4SFmode:
41228       /* In the 128-bit case, we've full freedom in the placement of
41229          the elements from the source operand.  */
41230       for (i = 0; i < nelt; ++i)
41231         mask |= ipar[i] << (i * (nelt / 2));
41232       break;
41233
41234     default:
41235       gcc_unreachable ();
41236     }
41237
41238   /* Make sure success has a non-zero value by adding one.  */
41239   return mask + 1;
41240 }
41241
41242 /* Helper for avx_vperm2f128_v4df_operand et al.  This is also used by
41243    the expansion functions to turn the parallel back into a mask.
41244    The return value is 0 for no match and the imm8+1 for a match.  */
41245
41246 int
41247 avx_vperm2f128_parallel (rtx par, machine_mode mode)
41248 {
41249   unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2;
41250   unsigned mask = 0;
41251   unsigned char ipar[8] = {};  /* Silence -Wuninitialized warning.  */
41252
41253   if (XVECLEN (par, 0) != (int) nelt)
41254     return 0;
41255
41256   /* Validate that all of the elements are constants, and not totally
41257      out of range.  Copy the data into an integral array to make the
41258      subsequent checks easier.  */
41259   for (i = 0; i < nelt; ++i)
41260     {
41261       rtx er = XVECEXP (par, 0, i);
41262       unsigned HOST_WIDE_INT ei;
41263
41264       if (!CONST_INT_P (er))
41265         return 0;
41266       ei = INTVAL (er);
41267       if (ei >= 2 * nelt)
41268         return 0;
41269       ipar[i] = ei;
41270     }
41271
41272   /* Validate that the halves of the permute are halves.  */
41273   for (i = 0; i < nelt2 - 1; ++i)
41274     if (ipar[i] + 1 != ipar[i + 1])
41275       return 0;
41276   for (i = nelt2; i < nelt - 1; ++i)
41277     if (ipar[i] + 1 != ipar[i + 1])
41278       return 0;
41279
41280   /* Reconstruct the mask.  */
41281   for (i = 0; i < 2; ++i)
41282     {
41283       unsigned e = ipar[i * nelt2];
41284       if (e % nelt2)
41285         return 0;
41286       e /= nelt2;
41287       mask |= e << (i * 4);
41288     }
41289
41290   /* Make sure success has a non-zero value by adding one.  */
41291   return mask + 1;
41292 }
41293 \f
41294 /* Return a register priority for hard reg REGNO.  */
41295 static int
41296 ix86_register_priority (int hard_regno)
41297 {
41298   /* ebp and r13 as the base always wants a displacement, r12 as the
41299      base always wants an index.  So discourage their usage in an
41300      address.  */
41301   if (hard_regno == R12_REG || hard_regno == R13_REG)
41302     return 0;
41303   if (hard_regno == BP_REG)
41304     return 1;
41305   /* New x86-64 int registers result in bigger code size.  Discourage
41306      them.  */
41307   if (FIRST_REX_INT_REG <= hard_regno && hard_regno <= LAST_REX_INT_REG)
41308     return 2;
41309   /* New x86-64 SSE registers result in bigger code size.  Discourage
41310      them.  */
41311   if (FIRST_REX_SSE_REG <= hard_regno && hard_regno <= LAST_REX_SSE_REG)
41312     return 2;
41313   /* Usage of AX register results in smaller code.  Prefer it.  */
41314   if (hard_regno == AX_REG)
41315     return 4;
41316   return 3;
41317 }
41318
41319 /* Implement TARGET_PREFERRED_RELOAD_CLASS.
41320
41321    Put float CONST_DOUBLE in the constant pool instead of fp regs.
41322    QImode must go into class Q_REGS.
41323    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
41324    movdf to do mem-to-mem moves through integer regs.  */
41325
41326 static reg_class_t
41327 ix86_preferred_reload_class (rtx x, reg_class_t regclass)
41328 {
41329   machine_mode mode = GET_MODE (x);
41330
41331   /* We're only allowed to return a subclass of CLASS.  Many of the
41332      following checks fail for NO_REGS, so eliminate that early.  */
41333   if (regclass == NO_REGS)
41334     return NO_REGS;
41335
41336   /* All classes can load zeros.  */
41337   if (x == CONST0_RTX (mode))
41338     return regclass;
41339
41340   /* Force constants into memory if we are loading a (nonzero) constant into
41341      an MMX, SSE or MASK register.  This is because there are no MMX/SSE/MASK
41342      instructions to load from a constant.  */
41343   if (CONSTANT_P (x)
41344       && (MAYBE_MMX_CLASS_P (regclass)
41345           || MAYBE_SSE_CLASS_P (regclass)
41346           || MAYBE_MASK_CLASS_P (regclass)))
41347     return NO_REGS;
41348
41349   /* Prefer SSE regs only, if we can use them for math.  */
41350   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
41351     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
41352
41353   /* Floating-point constants need more complex checks.  */
41354   if (CONST_DOUBLE_P (x))
41355     {
41356       /* General regs can load everything.  */
41357       if (reg_class_subset_p (regclass, GENERAL_REGS))
41358         return regclass;
41359
41360       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
41361          zero above.  We only want to wind up preferring 80387 registers if
41362          we plan on doing computation with them.  */
41363       if (TARGET_80387
41364           && standard_80387_constant_p (x) > 0)
41365         {
41366           /* Limit class to non-sse.  */
41367           if (regclass == FLOAT_SSE_REGS)
41368             return FLOAT_REGS;
41369           if (regclass == FP_TOP_SSE_REGS)
41370             return FP_TOP_REG;
41371           if (regclass == FP_SECOND_SSE_REGS)
41372             return FP_SECOND_REG;
41373           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
41374             return regclass;
41375         }
41376
41377       return NO_REGS;
41378     }
41379
41380   /* Generally when we see PLUS here, it's the function invariant
41381      (plus soft-fp const_int).  Which can only be computed into general
41382      regs.  */
41383   if (GET_CODE (x) == PLUS)
41384     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
41385
41386   /* QImode constants are easy to load, but non-constant QImode data
41387      must go into Q_REGS.  */
41388   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
41389     {
41390       if (reg_class_subset_p (regclass, Q_REGS))
41391         return regclass;
41392       if (reg_class_subset_p (Q_REGS, regclass))
41393         return Q_REGS;
41394       return NO_REGS;
41395     }
41396
41397   return regclass;
41398 }
41399
41400 /* Discourage putting floating-point values in SSE registers unless
41401    SSE math is being used, and likewise for the 387 registers.  */
41402 static reg_class_t
41403 ix86_preferred_output_reload_class (rtx x, reg_class_t regclass)
41404 {
41405   machine_mode mode = GET_MODE (x);
41406
41407   /* Restrict the output reload class to the register bank that we are doing
41408      math on.  If we would like not to return a subset of CLASS, reject this
41409      alternative: if reload cannot do this, it will still use its choice.  */
41410   mode = GET_MODE (x);
41411   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
41412     return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS;
41413
41414   if (X87_FLOAT_MODE_P (mode))
41415     {
41416       if (regclass == FP_TOP_SSE_REGS)
41417         return FP_TOP_REG;
41418       else if (regclass == FP_SECOND_SSE_REGS)
41419         return FP_SECOND_REG;
41420       else
41421         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
41422     }
41423
41424   return regclass;
41425 }
41426
41427 static reg_class_t
41428 ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
41429                        machine_mode mode, secondary_reload_info *sri)
41430 {
41431   /* Double-word spills from general registers to non-offsettable memory
41432      references (zero-extended addresses) require special handling.  */
41433   if (TARGET_64BIT
41434       && MEM_P (x)
41435       && GET_MODE_SIZE (mode) > UNITS_PER_WORD
41436       && INTEGER_CLASS_P (rclass)
41437       && !offsettable_memref_p (x))
41438     {
41439       sri->icode = (in_p
41440                     ? CODE_FOR_reload_noff_load
41441                     : CODE_FOR_reload_noff_store);
41442       /* Add the cost of moving address to a temporary.  */
41443       sri->extra_cost = 1;
41444
41445       return NO_REGS;
41446     }
41447
41448   /* QImode spills from non-QI registers require
41449      intermediate register on 32bit targets.  */
41450   if (mode == QImode
41451       && (MAYBE_MASK_CLASS_P (rclass)
41452           || (!TARGET_64BIT && !in_p
41453               && INTEGER_CLASS_P (rclass)
41454               && MAYBE_NON_Q_CLASS_P (rclass))))
41455     {
41456       int regno;
41457
41458       if (REG_P (x))
41459         regno = REGNO (x);
41460       else
41461         regno = -1;
41462
41463       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
41464         regno = true_regnum (x);
41465
41466       /* Return Q_REGS if the operand is in memory.  */
41467       if (regno == -1)
41468         return Q_REGS;
41469     }
41470
41471   /* This condition handles corner case where an expression involving
41472      pointers gets vectorized.  We're trying to use the address of a
41473      stack slot as a vector initializer.
41474
41475      (set (reg:V2DI 74 [ vect_cst_.2 ])
41476           (vec_duplicate:V2DI (reg/f:DI 20 frame)))
41477
41478      Eventually frame gets turned into sp+offset like this:
41479
41480      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41481           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
41482                                        (const_int 392 [0x188]))))
41483
41484      That later gets turned into:
41485
41486      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41487           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
41488             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))))
41489
41490      We'll have the following reload recorded:
41491
41492      Reload 0: reload_in (DI) =
41493            (plus:DI (reg/f:DI 7 sp)
41494             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))
41495      reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41496      SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine
41497      reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188]))
41498      reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41499      reload_reg_rtx: (reg:V2DI 22 xmm1)
41500
41501      Which isn't going to work since SSE instructions can't handle scalar
41502      additions.  Returning GENERAL_REGS forces the addition into integer
41503      register and reload can handle subsequent reloads without problems.  */
41504
41505   if (in_p && GET_CODE (x) == PLUS
41506       && SSE_CLASS_P (rclass)
41507       && SCALAR_INT_MODE_P (mode))
41508     return GENERAL_REGS;
41509
41510   return NO_REGS;
41511 }
41512
41513 /* Implement TARGET_CLASS_LIKELY_SPILLED_P.  */
41514
41515 static bool
41516 ix86_class_likely_spilled_p (reg_class_t rclass)
41517 {
41518   switch (rclass)
41519     {
41520       case AREG:
41521       case DREG:
41522       case CREG:
41523       case BREG:
41524       case AD_REGS:
41525       case SIREG:
41526       case DIREG:
41527       case SSE_FIRST_REG:
41528       case FP_TOP_REG:
41529       case FP_SECOND_REG:
41530       case BND_REGS:
41531         return true;
41532
41533       default:
41534         break;
41535     }
41536
41537   return false;
41538 }
41539
41540 /* If we are copying between general and FP registers, we need a memory
41541    location. The same is true for SSE and MMX registers.
41542
41543    To optimize register_move_cost performance, allow inline variant.
41544
41545    The macro can't work reliably when one of the CLASSES is class containing
41546    registers from multiple units (SSE, MMX, integer).  We avoid this by never
41547    combining those units in single alternative in the machine description.
41548    Ensure that this constraint holds to avoid unexpected surprises.
41549
41550    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
41551    enforce these sanity checks.  */
41552
41553 static inline bool
41554 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
41555                                 machine_mode mode, int strict)
41556 {
41557   if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
41558     return false;
41559   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
41560       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
41561       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
41562       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
41563       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
41564       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
41565     {
41566       gcc_assert (!strict || lra_in_progress);
41567       return true;
41568     }
41569
41570   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
41571     return true;
41572
41573   /* Between mask and general, we have moves no larger than word size.  */
41574   if ((MAYBE_MASK_CLASS_P (class1) != MAYBE_MASK_CLASS_P (class2))
41575       && (GET_MODE_SIZE (mode) > UNITS_PER_WORD))
41576   return true;
41577
41578   /* ??? This is a lie.  We do have moves between mmx/general, and for
41579      mmx/sse2.  But by saying we need secondary memory we discourage the
41580      register allocator from using the mmx registers unless needed.  */
41581   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
41582     return true;
41583
41584   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
41585     {
41586       /* SSE1 doesn't have any direct moves from other classes.  */
41587       if (!TARGET_SSE2)
41588         return true;
41589
41590       /* If the target says that inter-unit moves are more expensive
41591          than moving through memory, then don't generate them.  */
41592       if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC)
41593           || (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC))
41594         return true;
41595
41596       /* Between SSE and general, we have moves no larger than word size.  */
41597       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
41598         return true;
41599     }
41600
41601   return false;
41602 }
41603
41604 bool
41605 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
41606                               machine_mode mode, int strict)
41607 {
41608   return inline_secondary_memory_needed (class1, class2, mode, strict);
41609 }
41610
41611 /* Implement the TARGET_CLASS_MAX_NREGS hook.
41612
41613    On the 80386, this is the size of MODE in words,
41614    except in the FP regs, where a single reg is always enough.  */
41615
41616 static unsigned char
41617 ix86_class_max_nregs (reg_class_t rclass, machine_mode mode)
41618 {
41619   if (MAYBE_INTEGER_CLASS_P (rclass))
41620     {
41621       if (mode == XFmode)
41622         return (TARGET_64BIT ? 2 : 3);
41623       else if (mode == XCmode)
41624         return (TARGET_64BIT ? 4 : 6);
41625       else
41626         return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
41627     }
41628   else
41629     {
41630       if (COMPLEX_MODE_P (mode))
41631         return 2;
41632       else
41633         return 1;
41634     }
41635 }
41636
41637 /* Return true if the registers in CLASS cannot represent the change from
41638    modes FROM to TO.  */
41639
41640 bool
41641 ix86_cannot_change_mode_class (machine_mode from, machine_mode to,
41642                                enum reg_class regclass)
41643 {
41644   if (from == to)
41645     return false;
41646
41647   /* x87 registers can't do subreg at all, as all values are reformatted
41648      to extended precision.  */
41649   if (MAYBE_FLOAT_CLASS_P (regclass))
41650     return true;
41651
41652   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
41653     {
41654       /* Vector registers do not support QI or HImode loads.  If we don't
41655          disallow a change to these modes, reload will assume it's ok to
41656          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
41657          the vec_dupv4hi pattern.  */
41658       if (GET_MODE_SIZE (from) < 4)
41659         return true;
41660     }
41661
41662   return false;
41663 }
41664
41665 /* Return the cost of moving data of mode M between a
41666    register and memory.  A value of 2 is the default; this cost is
41667    relative to those in `REGISTER_MOVE_COST'.
41668
41669    This function is used extensively by register_move_cost that is used to
41670    build tables at startup.  Make it inline in this case.
41671    When IN is 2, return maximum of in and out move cost.
41672
41673    If moving between registers and memory is more expensive than
41674    between two registers, you should define this macro to express the
41675    relative cost.
41676
41677    Model also increased moving costs of QImode registers in non
41678    Q_REGS classes.
41679  */
41680 static inline int
41681 inline_memory_move_cost (machine_mode mode, enum reg_class regclass,
41682                          int in)
41683 {
41684   int cost;
41685   if (FLOAT_CLASS_P (regclass))
41686     {
41687       int index;
41688       switch (mode)
41689         {
41690           case SFmode:
41691             index = 0;
41692             break;
41693           case DFmode:
41694             index = 1;
41695             break;
41696           case XFmode:
41697             index = 2;
41698             break;
41699           default:
41700             return 100;
41701         }
41702       if (in == 2)
41703         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
41704       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
41705     }
41706   if (SSE_CLASS_P (regclass))
41707     {
41708       int index;
41709       switch (GET_MODE_SIZE (mode))
41710         {
41711           case 4:
41712             index = 0;
41713             break;
41714           case 8:
41715             index = 1;
41716             break;
41717           case 16:
41718             index = 2;
41719             break;
41720           default:
41721             return 100;
41722         }
41723       if (in == 2)
41724         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
41725       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
41726     }
41727   if (MMX_CLASS_P (regclass))
41728     {
41729       int index;
41730       switch (GET_MODE_SIZE (mode))
41731         {
41732           case 4:
41733             index = 0;
41734             break;
41735           case 8:
41736             index = 1;
41737             break;
41738           default:
41739             return 100;
41740         }
41741       if (in)
41742         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
41743       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
41744     }
41745   switch (GET_MODE_SIZE (mode))
41746     {
41747       case 1:
41748         if (Q_CLASS_P (regclass) || TARGET_64BIT)
41749           {
41750             if (!in)
41751               return ix86_cost->int_store[0];
41752             if (TARGET_PARTIAL_REG_DEPENDENCY
41753                 && optimize_function_for_speed_p (cfun))
41754               cost = ix86_cost->movzbl_load;
41755             else
41756               cost = ix86_cost->int_load[0];
41757             if (in == 2)
41758               return MAX (cost, ix86_cost->int_store[0]);
41759             return cost;
41760           }
41761         else
41762           {
41763            if (in == 2)
41764              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
41765            if (in)
41766              return ix86_cost->movzbl_load;
41767            else
41768              return ix86_cost->int_store[0] + 4;
41769           }
41770         break;
41771       case 2:
41772         if (in == 2)
41773           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
41774         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
41775       default:
41776         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
41777         if (mode == TFmode)
41778           mode = XFmode;
41779         if (in == 2)
41780           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
41781         else if (in)
41782           cost = ix86_cost->int_load[2];
41783         else
41784           cost = ix86_cost->int_store[2];
41785         return (cost * (((int) GET_MODE_SIZE (mode)
41786                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
41787     }
41788 }
41789
41790 static int
41791 ix86_memory_move_cost (machine_mode mode, reg_class_t regclass,
41792                        bool in)
41793 {
41794   return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0);
41795 }
41796
41797
41798 /* Return the cost of moving data from a register in class CLASS1 to
41799    one in class CLASS2.
41800
41801    It is not required that the cost always equal 2 when FROM is the same as TO;
41802    on some machines it is expensive to move between registers if they are not
41803    general registers.  */
41804
41805 static int
41806 ix86_register_move_cost (machine_mode mode, reg_class_t class1_i,
41807                          reg_class_t class2_i)
41808 {
41809   enum reg_class class1 = (enum reg_class) class1_i;
41810   enum reg_class class2 = (enum reg_class) class2_i;
41811
41812   /* In case we require secondary memory, compute cost of the store followed
41813      by load.  In order to avoid bad register allocation choices, we need
41814      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
41815
41816   if (inline_secondary_memory_needed (class1, class2, mode, 0))
41817     {
41818       int cost = 1;
41819
41820       cost += inline_memory_move_cost (mode, class1, 2);
41821       cost += inline_memory_move_cost (mode, class2, 2);
41822
41823       /* In case of copying from general_purpose_register we may emit multiple
41824          stores followed by single load causing memory size mismatch stall.
41825          Count this as arbitrarily high cost of 20.  */
41826       if (targetm.class_max_nregs (class1, mode)
41827           > targetm.class_max_nregs (class2, mode))
41828         cost += 20;
41829
41830       /* In the case of FP/MMX moves, the registers actually overlap, and we
41831          have to switch modes in order to treat them differently.  */
41832       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
41833           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
41834         cost += 20;
41835
41836       return cost;
41837     }
41838
41839   /* Moves between SSE/MMX and integer unit are expensive.  */
41840   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
41841       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
41842
41843     /* ??? By keeping returned value relatively high, we limit the number
41844        of moves between integer and MMX/SSE registers for all targets.
41845        Additionally, high value prevents problem with x86_modes_tieable_p(),
41846        where integer modes in MMX/SSE registers are not tieable
41847        because of missing QImode and HImode moves to, from or between
41848        MMX/SSE registers.  */
41849     return MAX (8, ix86_cost->mmxsse_to_integer);
41850
41851   if (MAYBE_FLOAT_CLASS_P (class1))
41852     return ix86_cost->fp_move;
41853   if (MAYBE_SSE_CLASS_P (class1))
41854     return ix86_cost->sse_move;
41855   if (MAYBE_MMX_CLASS_P (class1))
41856     return ix86_cost->mmx_move;
41857   return 2;
41858 }
41859
41860 /* Return TRUE if hard register REGNO can hold a value of machine-mode
41861    MODE.  */
41862
41863 bool
41864 ix86_hard_regno_mode_ok (int regno, machine_mode mode)
41865 {
41866   /* Flags and only flags can only hold CCmode values.  */
41867   if (CC_REGNO_P (regno))
41868     return GET_MODE_CLASS (mode) == MODE_CC;
41869   if (GET_MODE_CLASS (mode) == MODE_CC
41870       || GET_MODE_CLASS (mode) == MODE_RANDOM
41871       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
41872     return false;
41873   if (STACK_REGNO_P (regno))
41874     return VALID_FP_MODE_P (mode);
41875   if (MASK_REGNO_P (regno))
41876     return (VALID_MASK_REG_MODE (mode)
41877             || (TARGET_AVX512BW
41878                 && VALID_MASK_AVX512BW_MODE (mode)));
41879   if (BND_REGNO_P (regno))
41880     return VALID_BND_REG_MODE (mode);
41881   if (SSE_REGNO_P (regno))
41882     {
41883       /* We implement the move patterns for all vector modes into and
41884          out of SSE registers, even when no operation instructions
41885          are available.  */
41886
41887       /* For AVX-512 we allow, regardless of regno:
41888           - XI mode
41889           - any of 512-bit wide vector mode
41890           - any scalar mode.  */
41891       if (TARGET_AVX512F
41892           && (mode == XImode
41893               || VALID_AVX512F_REG_MODE (mode)
41894               || VALID_AVX512F_SCALAR_MODE (mode)))
41895         return true;
41896
41897       /* TODO check for QI/HI scalars.  */
41898       /* AVX512VL allows sse regs16+ for 128/256 bit modes.  */
41899       if (TARGET_AVX512VL
41900           && (mode == OImode
41901               || mode == TImode
41902               || VALID_AVX256_REG_MODE (mode)
41903               || VALID_AVX512VL_128_REG_MODE (mode)))
41904         return true;
41905
41906       /* xmm16-xmm31 are only available for AVX-512.  */
41907       if (EXT_REX_SSE_REGNO_P (regno))
41908         return false;
41909
41910       /* OImode and AVX modes are available only when AVX is enabled.  */
41911       return ((TARGET_AVX
41912                && VALID_AVX256_REG_OR_OI_MODE (mode))
41913               || VALID_SSE_REG_MODE (mode)
41914               || VALID_SSE2_REG_MODE (mode)
41915               || VALID_MMX_REG_MODE (mode)
41916               || VALID_MMX_REG_MODE_3DNOW (mode));
41917     }
41918   if (MMX_REGNO_P (regno))
41919     {
41920       /* We implement the move patterns for 3DNOW modes even in MMX mode,
41921          so if the register is available at all, then we can move data of
41922          the given mode into or out of it.  */
41923       return (VALID_MMX_REG_MODE (mode)
41924               || VALID_MMX_REG_MODE_3DNOW (mode));
41925     }
41926
41927   if (mode == QImode)
41928     {
41929       /* Take care for QImode values - they can be in non-QI regs,
41930          but then they do cause partial register stalls.  */
41931       if (ANY_QI_REGNO_P (regno))
41932         return true;
41933       if (!TARGET_PARTIAL_REG_STALL)
41934         return true;
41935       /* LRA checks if the hard register is OK for the given mode.
41936          QImode values can live in non-QI regs, so we allow all
41937          registers here.  */
41938       if (lra_in_progress)
41939        return true;
41940       return !can_create_pseudo_p ();
41941     }
41942   /* We handle both integer and floats in the general purpose registers.  */
41943   else if (VALID_INT_MODE_P (mode))
41944     return true;
41945   else if (VALID_FP_MODE_P (mode))
41946     return true;
41947   else if (VALID_DFP_MODE_P (mode))
41948     return true;
41949   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
41950      on to use that value in smaller contexts, this can easily force a
41951      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
41952      supporting DImode, allow it.  */
41953   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
41954     return true;
41955
41956   return false;
41957 }
41958
41959 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
41960    tieable integer mode.  */
41961
41962 static bool
41963 ix86_tieable_integer_mode_p (machine_mode mode)
41964 {
41965   switch (mode)
41966     {
41967     case HImode:
41968     case SImode:
41969       return true;
41970
41971     case QImode:
41972       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
41973
41974     case DImode:
41975       return TARGET_64BIT;
41976
41977     default:
41978       return false;
41979     }
41980 }
41981
41982 /* Return true if MODE1 is accessible in a register that can hold MODE2
41983    without copying.  That is, all register classes that can hold MODE2
41984    can also hold MODE1.  */
41985
41986 bool
41987 ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2)
41988 {
41989   if (mode1 == mode2)
41990     return true;
41991
41992   if (ix86_tieable_integer_mode_p (mode1)
41993       && ix86_tieable_integer_mode_p (mode2))
41994     return true;
41995
41996   /* MODE2 being XFmode implies fp stack or general regs, which means we
41997      can tie any smaller floating point modes to it.  Note that we do not
41998      tie this with TFmode.  */
41999   if (mode2 == XFmode)
42000     return mode1 == SFmode || mode1 == DFmode;
42001
42002   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
42003      that we can tie it with SFmode.  */
42004   if (mode2 == DFmode)
42005     return mode1 == SFmode;
42006
42007   /* If MODE2 is only appropriate for an SSE register, then tie with
42008      any other mode acceptable to SSE registers.  */
42009   if (GET_MODE_SIZE (mode2) == 32
42010       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
42011     return (GET_MODE_SIZE (mode1) == 32
42012             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
42013   if (GET_MODE_SIZE (mode2) == 16
42014       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
42015     return (GET_MODE_SIZE (mode1) == 16
42016             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
42017
42018   /* If MODE2 is appropriate for an MMX register, then tie
42019      with any other mode acceptable to MMX registers.  */
42020   if (GET_MODE_SIZE (mode2) == 8
42021       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
42022     return (GET_MODE_SIZE (mode1) == 8
42023             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
42024
42025   return false;
42026 }
42027
42028 /* Return the cost of moving between two registers of mode MODE.  */
42029
42030 static int
42031 ix86_set_reg_reg_cost (machine_mode mode)
42032 {
42033   unsigned int units = UNITS_PER_WORD;
42034
42035   switch (GET_MODE_CLASS (mode))
42036     {
42037     default:
42038       break;
42039
42040     case MODE_CC:
42041       units = GET_MODE_SIZE (CCmode);
42042       break;
42043
42044     case MODE_FLOAT:
42045       if ((TARGET_SSE && mode == TFmode)
42046           || (TARGET_80387 && mode == XFmode)
42047           || ((TARGET_80387 || TARGET_SSE2) && mode == DFmode)
42048           || ((TARGET_80387 || TARGET_SSE) && mode == SFmode))
42049         units = GET_MODE_SIZE (mode);
42050       break;
42051
42052     case MODE_COMPLEX_FLOAT:
42053       if ((TARGET_SSE && mode == TCmode)
42054           || (TARGET_80387 && mode == XCmode)
42055           || ((TARGET_80387 || TARGET_SSE2) && mode == DCmode)
42056           || ((TARGET_80387 || TARGET_SSE) && mode == SCmode))
42057         units = GET_MODE_SIZE (mode);
42058       break;
42059
42060     case MODE_VECTOR_INT:
42061     case MODE_VECTOR_FLOAT:
42062       if ((TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
42063           || (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
42064           || (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
42065           || (TARGET_SSE && VALID_SSE_REG_MODE (mode))
42066           || (TARGET_MMX && VALID_MMX_REG_MODE (mode)))
42067         units = GET_MODE_SIZE (mode);
42068     }
42069
42070   /* Return the cost of moving between two registers of mode MODE,
42071      assuming that the move will be in pieces of at most UNITS bytes.  */
42072   return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
42073 }
42074
42075 /* Compute a (partial) cost for rtx X.  Return true if the complete
42076    cost has been computed, and false if subexpressions should be
42077    scanned.  In either case, *TOTAL contains the cost result.  */
42078
42079 static bool
42080 ix86_rtx_costs (rtx x, int code_i, int outer_code_i, int opno, int *total,
42081                 bool speed)
42082 {
42083   rtx mask;
42084   enum rtx_code code = (enum rtx_code) code_i;
42085   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
42086   machine_mode mode = GET_MODE (x);
42087   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
42088
42089   switch (code)
42090     {
42091     case SET:
42092       if (register_operand (SET_DEST (x), VOIDmode)
42093           && reg_or_0_operand (SET_SRC (x), VOIDmode))
42094         {
42095           *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
42096           return true;
42097         }
42098       return false;
42099
42100     case CONST_INT:
42101     case CONST:
42102     case LABEL_REF:
42103     case SYMBOL_REF:
42104       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
42105         *total = 3;
42106       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
42107         *total = 2;
42108       else if (flag_pic && SYMBOLIC_CONST (x)
42109                && !(TARGET_64BIT
42110                     && (GET_CODE (x) == LABEL_REF
42111                         || (GET_CODE (x) == SYMBOL_REF
42112                             && SYMBOL_REF_LOCAL_P (x))))
42113                /* Use 0 cost for CONST to improve its propagation.  */
42114                && (TARGET_64BIT || GET_CODE (x) != CONST))
42115         *total = 1;
42116       else
42117         *total = 0;
42118       return true;
42119
42120     case CONST_WIDE_INT:
42121       *total = 0;
42122       return true;
42123
42124     case CONST_DOUBLE:
42125       switch (standard_80387_constant_p (x))
42126         {
42127         case 1: /* 0.0 */
42128           *total = 1;
42129           return true;
42130         default: /* Other constants */
42131           *total = 2;
42132           return true;
42133         case 0:
42134         case -1:
42135           break;
42136         }
42137       if (SSE_FLOAT_MODE_P (mode))
42138         {
42139     case CONST_VECTOR:
42140           switch (standard_sse_constant_p (x))
42141             {
42142             case 0:
42143               break;
42144             case 1:  /* 0: xor eliminates false dependency */
42145               *total = 0;
42146               return true;
42147             default: /* -1: cmp contains false dependency */
42148               *total = 1;
42149               return true;
42150             }
42151         }
42152       /* Fall back to (MEM (SYMBOL_REF)), since that's where
42153          it'll probably end up.  Add a penalty for size.  */
42154       *total = (COSTS_N_INSNS (1)
42155                 + (flag_pic != 0 && !TARGET_64BIT)
42156                 + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
42157       return true;
42158
42159     case ZERO_EXTEND:
42160       /* The zero extensions is often completely free on x86_64, so make
42161          it as cheap as possible.  */
42162       if (TARGET_64BIT && mode == DImode
42163           && GET_MODE (XEXP (x, 0)) == SImode)
42164         *total = 1;
42165       else if (TARGET_ZERO_EXTEND_WITH_AND)
42166         *total = cost->add;
42167       else
42168         *total = cost->movzx;
42169       return false;
42170
42171     case SIGN_EXTEND:
42172       *total = cost->movsx;
42173       return false;
42174
42175     case ASHIFT:
42176       if (SCALAR_INT_MODE_P (mode)
42177           && GET_MODE_SIZE (mode) < UNITS_PER_WORD
42178           && CONST_INT_P (XEXP (x, 1)))
42179         {
42180           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
42181           if (value == 1)
42182             {
42183               *total = cost->add;
42184               return false;
42185             }
42186           if ((value == 2 || value == 3)
42187               && cost->lea <= cost->shift_const)
42188             {
42189               *total = cost->lea;
42190               return false;
42191             }
42192         }
42193       /* FALLTHRU */
42194
42195     case ROTATE:
42196     case ASHIFTRT:
42197     case LSHIFTRT:
42198     case ROTATERT:
42199       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42200         {
42201           /* ??? Should be SSE vector operation cost.  */
42202           /* At least for published AMD latencies, this really is the same
42203              as the latency for a simple fpu operation like fabs.  */
42204           /* V*QImode is emulated with 1-11 insns.  */
42205           if (mode == V16QImode || mode == V32QImode)
42206             {
42207               int count = 11;
42208               if (TARGET_XOP && mode == V16QImode)
42209                 {
42210                   /* For XOP we use vpshab, which requires a broadcast of the
42211                      value to the variable shift insn.  For constants this
42212                      means a V16Q const in mem; even when we can perform the
42213                      shift with one insn set the cost to prefer paddb.  */
42214                   if (CONSTANT_P (XEXP (x, 1)))
42215                     {
42216                       *total = (cost->fabs
42217                                 + rtx_cost (XEXP (x, 0), code, 0, speed)
42218                                 + (speed ? 2 : COSTS_N_BYTES (16)));
42219                       return true;
42220                     }
42221                   count = 3;
42222                 }
42223               else if (TARGET_SSSE3)
42224                 count = 7;
42225               *total = cost->fabs * count;
42226             }
42227           else
42228             *total = cost->fabs;
42229         }
42230       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42231         {
42232           if (CONST_INT_P (XEXP (x, 1)))
42233             {
42234               if (INTVAL (XEXP (x, 1)) > 32)
42235                 *total = cost->shift_const + COSTS_N_INSNS (2);
42236               else
42237                 *total = cost->shift_const * 2;
42238             }
42239           else
42240             {
42241               if (GET_CODE (XEXP (x, 1)) == AND)
42242                 *total = cost->shift_var * 2;
42243               else
42244                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
42245             }
42246         }
42247       else
42248         {
42249           if (CONST_INT_P (XEXP (x, 1)))
42250             *total = cost->shift_const;
42251           else if (GET_CODE (XEXP (x, 1)) == SUBREG
42252                    && GET_CODE (XEXP (XEXP (x, 1), 0)) == AND)
42253             {
42254               /* Return the cost after shift-and truncation.  */
42255               *total = cost->shift_var;
42256               return true;
42257             }
42258           else
42259             *total = cost->shift_var;
42260         }
42261       return false;
42262
42263     case FMA:
42264       {
42265         rtx sub;
42266
42267         gcc_assert (FLOAT_MODE_P (mode));
42268         gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F);
42269
42270         /* ??? SSE scalar/vector cost should be used here.  */
42271         /* ??? Bald assumption that fma has the same cost as fmul.  */
42272         *total = cost->fmul;
42273         *total += rtx_cost (XEXP (x, 1), FMA, 1, speed);
42274
42275         /* Negate in op0 or op2 is free: FMS, FNMA, FNMS.  */
42276         sub = XEXP (x, 0);
42277         if (GET_CODE (sub) == NEG)
42278           sub = XEXP (sub, 0);
42279         *total += rtx_cost (sub, FMA, 0, speed);
42280
42281         sub = XEXP (x, 2);
42282         if (GET_CODE (sub) == NEG)
42283           sub = XEXP (sub, 0);
42284         *total += rtx_cost (sub, FMA, 2, speed);
42285         return true;
42286       }
42287
42288     case MULT:
42289       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42290         {
42291           /* ??? SSE scalar cost should be used here.  */
42292           *total = cost->fmul;
42293           return false;
42294         }
42295       else if (X87_FLOAT_MODE_P (mode))
42296         {
42297           *total = cost->fmul;
42298           return false;
42299         }
42300       else if (FLOAT_MODE_P (mode))
42301         {
42302           /* ??? SSE vector cost should be used here.  */
42303           *total = cost->fmul;
42304           return false;
42305         }
42306       else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42307         {
42308           /* V*QImode is emulated with 7-13 insns.  */
42309           if (mode == V16QImode || mode == V32QImode)
42310             {
42311               int extra = 11;
42312               if (TARGET_XOP && mode == V16QImode)
42313                 extra = 5;
42314               else if (TARGET_SSSE3)
42315                 extra = 6;
42316               *total = cost->fmul * 2 + cost->fabs * extra;
42317             }
42318           /* V*DImode is emulated with 5-8 insns.  */
42319           else if (mode == V2DImode || mode == V4DImode)
42320             {
42321               if (TARGET_XOP && mode == V2DImode)
42322                 *total = cost->fmul * 2 + cost->fabs * 3;
42323               else
42324                 *total = cost->fmul * 3 + cost->fabs * 5;
42325             }
42326           /* Without sse4.1, we don't have PMULLD; it's emulated with 7
42327              insns, including two PMULUDQ.  */
42328           else if (mode == V4SImode && !(TARGET_SSE4_1 || TARGET_AVX))
42329             *total = cost->fmul * 2 + cost->fabs * 5;
42330           else
42331             *total = cost->fmul;
42332           return false;
42333         }
42334       else
42335         {
42336           rtx op0 = XEXP (x, 0);
42337           rtx op1 = XEXP (x, 1);
42338           int nbits;
42339           if (CONST_INT_P (XEXP (x, 1)))
42340             {
42341               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
42342               for (nbits = 0; value != 0; value &= value - 1)
42343                 nbits++;
42344             }
42345           else
42346             /* This is arbitrary.  */
42347             nbits = 7;
42348
42349           /* Compute costs correctly for widening multiplication.  */
42350           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
42351               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
42352                  == GET_MODE_SIZE (mode))
42353             {
42354               int is_mulwiden = 0;
42355               machine_mode inner_mode = GET_MODE (op0);
42356
42357               if (GET_CODE (op0) == GET_CODE (op1))
42358                 is_mulwiden = 1, op1 = XEXP (op1, 0);
42359               else if (CONST_INT_P (op1))
42360                 {
42361                   if (GET_CODE (op0) == SIGN_EXTEND)
42362                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
42363                                   == INTVAL (op1);
42364                   else
42365                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
42366                 }
42367
42368               if (is_mulwiden)
42369                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
42370             }
42371
42372           *total = (cost->mult_init[MODE_INDEX (mode)]
42373                     + nbits * cost->mult_bit
42374                     + rtx_cost (op0, outer_code, opno, speed)
42375                     + rtx_cost (op1, outer_code, opno, speed));
42376
42377           return true;
42378         }
42379
42380     case DIV:
42381     case UDIV:
42382     case MOD:
42383     case UMOD:
42384       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42385         /* ??? SSE cost should be used here.  */
42386         *total = cost->fdiv;
42387       else if (X87_FLOAT_MODE_P (mode))
42388         *total = cost->fdiv;
42389       else if (FLOAT_MODE_P (mode))
42390         /* ??? SSE vector cost should be used here.  */
42391         *total = cost->fdiv;
42392       else
42393         *total = cost->divide[MODE_INDEX (mode)];
42394       return false;
42395
42396     case PLUS:
42397       if (GET_MODE_CLASS (mode) == MODE_INT
42398           && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
42399         {
42400           if (GET_CODE (XEXP (x, 0)) == PLUS
42401               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
42402               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
42403               && CONSTANT_P (XEXP (x, 1)))
42404             {
42405               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
42406               if (val == 2 || val == 4 || val == 8)
42407                 {
42408                   *total = cost->lea;
42409                   *total += rtx_cost (XEXP (XEXP (x, 0), 1),
42410                                       outer_code, opno, speed);
42411                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
42412                                       outer_code, opno, speed);
42413                   *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42414                   return true;
42415                 }
42416             }
42417           else if (GET_CODE (XEXP (x, 0)) == MULT
42418                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
42419             {
42420               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
42421               if (val == 2 || val == 4 || val == 8)
42422                 {
42423                   *total = cost->lea;
42424                   *total += rtx_cost (XEXP (XEXP (x, 0), 0),
42425                                       outer_code, opno, speed);
42426                   *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42427                   return true;
42428                 }
42429             }
42430           else if (GET_CODE (XEXP (x, 0)) == PLUS)
42431             {
42432               *total = cost->lea;
42433               *total += rtx_cost (XEXP (XEXP (x, 0), 0),
42434                                   outer_code, opno, speed);
42435               *total += rtx_cost (XEXP (XEXP (x, 0), 1),
42436                                   outer_code, opno, speed);
42437               *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42438               return true;
42439             }
42440         }
42441       /* FALLTHRU */
42442
42443     case MINUS:
42444       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42445         {
42446           /* ??? SSE cost should be used here.  */
42447           *total = cost->fadd;
42448           return false;
42449         }
42450       else if (X87_FLOAT_MODE_P (mode))
42451         {
42452           *total = cost->fadd;
42453           return false;
42454         }
42455       else if (FLOAT_MODE_P (mode))
42456         {
42457           /* ??? SSE vector cost should be used here.  */
42458           *total = cost->fadd;
42459           return false;
42460         }
42461       /* FALLTHRU */
42462
42463     case AND:
42464     case IOR:
42465     case XOR:
42466       if (GET_MODE_CLASS (mode) == MODE_INT
42467           && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42468         {
42469           *total = (cost->add * 2
42470                     + (rtx_cost (XEXP (x, 0), outer_code, opno, speed)
42471                        << (GET_MODE (XEXP (x, 0)) != DImode))
42472                     + (rtx_cost (XEXP (x, 1), outer_code, opno, speed)
42473                        << (GET_MODE (XEXP (x, 1)) != DImode)));
42474           return true;
42475         }
42476       /* FALLTHRU */
42477
42478     case NEG:
42479       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42480         {
42481           /* ??? SSE cost should be used here.  */
42482           *total = cost->fchs;
42483           return false;
42484         }
42485       else if (X87_FLOAT_MODE_P (mode))
42486         {
42487           *total = cost->fchs;
42488           return false;
42489         }
42490       else if (FLOAT_MODE_P (mode))
42491         {
42492           /* ??? SSE vector cost should be used here.  */
42493           *total = cost->fchs;
42494           return false;
42495         }
42496       /* FALLTHRU */
42497
42498     case NOT:
42499       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42500         {
42501           /* ??? Should be SSE vector operation cost.  */
42502           /* At least for published AMD latencies, this really is the same
42503              as the latency for a simple fpu operation like fabs.  */
42504           *total = cost->fabs;
42505         }
42506       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42507         *total = cost->add * 2;
42508       else
42509         *total = cost->add;
42510       return false;
42511
42512     case COMPARE:
42513       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
42514           && XEXP (XEXP (x, 0), 1) == const1_rtx
42515           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
42516           && XEXP (x, 1) == const0_rtx)
42517         {
42518           /* This kind of construct is implemented using test[bwl].
42519              Treat it as if we had an AND.  */
42520           *total = (cost->add
42521                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, opno, speed)
42522                     + rtx_cost (const1_rtx, outer_code, opno, speed));
42523           return true;
42524         }
42525       return false;
42526
42527     case FLOAT_EXTEND:
42528       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
42529         *total = 0;
42530       return false;
42531
42532     case ABS:
42533       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42534         /* ??? SSE cost should be used here.  */
42535         *total = cost->fabs;
42536       else if (X87_FLOAT_MODE_P (mode))
42537         *total = cost->fabs;
42538       else if (FLOAT_MODE_P (mode))
42539         /* ??? SSE vector cost should be used here.  */
42540         *total = cost->fabs;
42541       return false;
42542
42543     case SQRT:
42544       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42545         /* ??? SSE cost should be used here.  */
42546         *total = cost->fsqrt;
42547       else if (X87_FLOAT_MODE_P (mode))
42548         *total = cost->fsqrt;
42549       else if (FLOAT_MODE_P (mode))
42550         /* ??? SSE vector cost should be used here.  */
42551         *total = cost->fsqrt;
42552       return false;
42553
42554     case UNSPEC:
42555       if (XINT (x, 1) == UNSPEC_TP)
42556         *total = 0;
42557       return false;
42558
42559     case VEC_SELECT:
42560     case VEC_CONCAT:
42561     case VEC_DUPLICATE:
42562       /* ??? Assume all of these vector manipulation patterns are
42563          recognizable.  In which case they all pretty much have the
42564          same cost.  */
42565      *total = cost->fabs;
42566      return true;
42567     case VEC_MERGE:
42568       mask = XEXP (x, 2);
42569       /* This is masked instruction, assume the same cost,
42570          as nonmasked variant.  */
42571       if (TARGET_AVX512F && register_operand (mask, GET_MODE (mask)))
42572         *total = rtx_cost (XEXP (x, 0), outer_code, opno, speed);
42573       else
42574         *total = cost->fabs;
42575       return true;
42576
42577     default:
42578       return false;
42579     }
42580 }
42581
42582 #if TARGET_MACHO
42583
42584 static int current_machopic_label_num;
42585
42586 /* Given a symbol name and its associated stub, write out the
42587    definition of the stub.  */
42588
42589 void
42590 machopic_output_stub (FILE *file, const char *symb, const char *stub)
42591 {
42592   unsigned int length;
42593   char *binder_name, *symbol_name, lazy_ptr_name[32];
42594   int label = ++current_machopic_label_num;
42595
42596   /* For 64-bit we shouldn't get here.  */
42597   gcc_assert (!TARGET_64BIT);
42598
42599   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
42600   symb = targetm.strip_name_encoding (symb);
42601
42602   length = strlen (stub);
42603   binder_name = XALLOCAVEC (char, length + 32);
42604   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
42605
42606   length = strlen (symb);
42607   symbol_name = XALLOCAVEC (char, length + 32);
42608   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
42609
42610   sprintf (lazy_ptr_name, "L%d$lz", label);
42611
42612   if (MACHOPIC_ATT_STUB)
42613     switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]);
42614   else if (MACHOPIC_PURE)
42615     switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]);
42616   else
42617     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
42618
42619   fprintf (file, "%s:\n", stub);
42620   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
42621
42622   if (MACHOPIC_ATT_STUB)
42623     {
42624       fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n");
42625     }
42626   else if (MACHOPIC_PURE)
42627     {
42628       /* PIC stub.  */
42629       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
42630       rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */);
42631       output_set_got (tmp, NULL_RTX);   /* "CALL ___<cpu>.get_pc_thunk.cx".  */
42632       fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n",
42633                label, lazy_ptr_name, label);
42634       fprintf (file, "\tjmp\t*%%ecx\n");
42635     }
42636   else
42637     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
42638
42639   /* The AT&T-style ("self-modifying") stub is not lazily bound, thus
42640      it needs no stub-binding-helper.  */
42641   if (MACHOPIC_ATT_STUB)
42642     return;
42643
42644   fprintf (file, "%s:\n", binder_name);
42645
42646   if (MACHOPIC_PURE)
42647     {
42648       fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name);
42649       fprintf (file, "\tpushl\t%%ecx\n");
42650     }
42651   else
42652     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
42653
42654   fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
42655
42656   /* N.B. Keep the correspondence of these
42657      'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the
42658      old-pic/new-pic/non-pic stubs; altering this will break
42659      compatibility with existing dylibs.  */
42660   if (MACHOPIC_PURE)
42661     {
42662       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
42663       switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]);
42664     }
42665   else
42666     /* 16-byte -mdynamic-no-pic stub.  */
42667     switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]);
42668
42669   fprintf (file, "%s:\n", lazy_ptr_name);
42670   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
42671   fprintf (file, ASM_LONG "%s\n", binder_name);
42672 }
42673 #endif /* TARGET_MACHO */
42674
42675 /* Order the registers for register allocator.  */
42676
42677 void
42678 x86_order_regs_for_local_alloc (void)
42679 {
42680    int pos = 0;
42681    int i;
42682
42683    /* First allocate the local general purpose registers.  */
42684    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
42685      if (GENERAL_REGNO_P (i) && call_used_regs[i])
42686         reg_alloc_order [pos++] = i;
42687
42688    /* Global general purpose registers.  */
42689    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
42690      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
42691         reg_alloc_order [pos++] = i;
42692
42693    /* x87 registers come first in case we are doing FP math
42694       using them.  */
42695    if (!TARGET_SSE_MATH)
42696      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
42697        reg_alloc_order [pos++] = i;
42698
42699    /* SSE registers.  */
42700    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
42701      reg_alloc_order [pos++] = i;
42702    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
42703      reg_alloc_order [pos++] = i;
42704
42705    /* Extended REX SSE registers.  */
42706    for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
42707      reg_alloc_order [pos++] = i;
42708
42709    /* Mask register.  */
42710    for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
42711      reg_alloc_order [pos++] = i;
42712
42713    /* MPX bound registers.  */
42714    for (i = FIRST_BND_REG; i <= LAST_BND_REG; i++)
42715      reg_alloc_order [pos++] = i;
42716
42717    /* x87 registers.  */
42718    if (TARGET_SSE_MATH)
42719      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
42720        reg_alloc_order [pos++] = i;
42721
42722    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
42723      reg_alloc_order [pos++] = i;
42724
42725    /* Initialize the rest of array as we do not allocate some registers
42726       at all.  */
42727    while (pos < FIRST_PSEUDO_REGISTER)
42728      reg_alloc_order [pos++] = 0;
42729 }
42730
42731 /* Handle a "callee_pop_aggregate_return" attribute; arguments as
42732    in struct attribute_spec handler.  */
42733 static tree
42734 ix86_handle_callee_pop_aggregate_return (tree *node, tree name,
42735                                               tree args,
42736                                               int,
42737                                               bool *no_add_attrs)
42738 {
42739   if (TREE_CODE (*node) != FUNCTION_TYPE
42740       && TREE_CODE (*node) != METHOD_TYPE
42741       && TREE_CODE (*node) != FIELD_DECL
42742       && TREE_CODE (*node) != TYPE_DECL)
42743     {
42744       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42745                name);
42746       *no_add_attrs = true;
42747       return NULL_TREE;
42748     }
42749   if (TARGET_64BIT)
42750     {
42751       warning (OPT_Wattributes, "%qE attribute only available for 32-bit",
42752                name);
42753       *no_add_attrs = true;
42754       return NULL_TREE;
42755     }
42756   if (is_attribute_p ("callee_pop_aggregate_return", name))
42757     {
42758       tree cst;
42759
42760       cst = TREE_VALUE (args);
42761       if (TREE_CODE (cst) != INTEGER_CST)
42762         {
42763           warning (OPT_Wattributes,
42764                    "%qE attribute requires an integer constant argument",
42765                    name);
42766           *no_add_attrs = true;
42767         }
42768       else if (compare_tree_int (cst, 0) != 0
42769                && compare_tree_int (cst, 1) != 0)
42770         {
42771           warning (OPT_Wattributes,
42772                    "argument to %qE attribute is neither zero, nor one",
42773                    name);
42774           *no_add_attrs = true;
42775         }
42776
42777       return NULL_TREE;
42778     }
42779
42780   return NULL_TREE;
42781 }
42782
42783 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
42784    struct attribute_spec.handler.  */
42785 static tree
42786 ix86_handle_abi_attribute (tree *node, tree name, tree, int,
42787                            bool *no_add_attrs)
42788 {
42789   if (TREE_CODE (*node) != FUNCTION_TYPE
42790       && TREE_CODE (*node) != METHOD_TYPE
42791       && TREE_CODE (*node) != FIELD_DECL
42792       && TREE_CODE (*node) != TYPE_DECL)
42793     {
42794       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42795                name);
42796       *no_add_attrs = true;
42797       return NULL_TREE;
42798     }
42799
42800   /* Can combine regparm with all attributes but fastcall.  */
42801   if (is_attribute_p ("ms_abi", name))
42802     {
42803       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
42804         {
42805           error ("ms_abi and sysv_abi attributes are not compatible");
42806         }
42807
42808       return NULL_TREE;
42809     }
42810   else if (is_attribute_p ("sysv_abi", name))
42811     {
42812       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
42813         {
42814           error ("ms_abi and sysv_abi attributes are not compatible");
42815         }
42816
42817       return NULL_TREE;
42818     }
42819
42820   return NULL_TREE;
42821 }
42822
42823 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
42824    struct attribute_spec.handler.  */
42825 static tree
42826 ix86_handle_struct_attribute (tree *node, tree name, tree, int,
42827                               bool *no_add_attrs)
42828 {
42829   tree *type = NULL;
42830   if (DECL_P (*node))
42831     {
42832       if (TREE_CODE (*node) == TYPE_DECL)
42833         type = &TREE_TYPE (*node);
42834     }
42835   else
42836     type = node;
42837
42838   if (!(type && RECORD_OR_UNION_TYPE_P (*type)))
42839     {
42840       warning (OPT_Wattributes, "%qE attribute ignored",
42841                name);
42842       *no_add_attrs = true;
42843     }
42844
42845   else if ((is_attribute_p ("ms_struct", name)
42846             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
42847            || ((is_attribute_p ("gcc_struct", name)
42848                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
42849     {
42850       warning (OPT_Wattributes, "%qE incompatible attribute ignored",
42851                name);
42852       *no_add_attrs = true;
42853     }
42854
42855   return NULL_TREE;
42856 }
42857
42858 static tree
42859 ix86_handle_fndecl_attribute (tree *node, tree name, tree, int,
42860                               bool *no_add_attrs)
42861 {
42862   if (TREE_CODE (*node) != FUNCTION_DECL)
42863     {
42864       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42865                name);
42866       *no_add_attrs = true;
42867     }
42868   return NULL_TREE;
42869 }
42870
42871 static bool
42872 ix86_ms_bitfield_layout_p (const_tree record_type)
42873 {
42874   return ((TARGET_MS_BITFIELD_LAYOUT
42875            && !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
42876           || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type)));
42877 }
42878
42879 /* Returns an expression indicating where the this parameter is
42880    located on entry to the FUNCTION.  */
42881
42882 static rtx
42883 x86_this_parameter (tree function)
42884 {
42885   tree type = TREE_TYPE (function);
42886   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
42887   int nregs;
42888
42889   if (TARGET_64BIT)
42890     {
42891       const int *parm_regs;
42892
42893       if (ix86_function_type_abi (type) == MS_ABI)
42894         parm_regs = x86_64_ms_abi_int_parameter_registers;
42895       else
42896         parm_regs = x86_64_int_parameter_registers;
42897       return gen_rtx_REG (Pmode, parm_regs[aggr]);
42898     }
42899
42900   nregs = ix86_function_regparm (type, function);
42901
42902   if (nregs > 0 && !stdarg_p (type))
42903     {
42904       int regno;
42905       unsigned int ccvt = ix86_get_callcvt (type);
42906
42907       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
42908         regno = aggr ? DX_REG : CX_REG;
42909       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
42910         {
42911           regno = CX_REG;
42912           if (aggr)
42913             return gen_rtx_MEM (SImode,
42914                                 plus_constant (Pmode, stack_pointer_rtx, 4));
42915         }
42916       else
42917         {
42918           regno = AX_REG;
42919           if (aggr)
42920             {
42921               regno = DX_REG;
42922               if (nregs == 1)
42923                 return gen_rtx_MEM (SImode,
42924                                     plus_constant (Pmode,
42925                                                    stack_pointer_rtx, 4));
42926             }
42927         }
42928       return gen_rtx_REG (SImode, regno);
42929     }
42930
42931   return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx,
42932                                              aggr ? 8 : 4));
42933 }
42934
42935 /* Determine whether x86_output_mi_thunk can succeed.  */
42936
42937 static bool
42938 x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset,
42939                          const_tree function)
42940 {
42941   /* 64-bit can handle anything.  */
42942   if (TARGET_64BIT)
42943     return true;
42944
42945   /* For 32-bit, everything's fine if we have one free register.  */
42946   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
42947     return true;
42948
42949   /* Need a free register for vcall_offset.  */
42950   if (vcall_offset)
42951     return false;
42952
42953   /* Need a free register for GOT references.  */
42954   if (flag_pic && !targetm.binds_local_p (function))
42955     return false;
42956
42957   /* Otherwise ok.  */
42958   return true;
42959 }
42960
42961 /* Output the assembler code for a thunk function.  THUNK_DECL is the
42962    declaration for the thunk function itself, FUNCTION is the decl for
42963    the target function.  DELTA is an immediate constant offset to be
42964    added to THIS.  If VCALL_OFFSET is nonzero, the word at
42965    *(*this + vcall_offset) should be added to THIS.  */
42966
42967 static void
42968 x86_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta,
42969                      HOST_WIDE_INT vcall_offset, tree function)
42970 {
42971   rtx this_param = x86_this_parameter (function);
42972   rtx this_reg, tmp, fnaddr;
42973   unsigned int tmp_regno;
42974   rtx_insn *insn;
42975
42976   if (TARGET_64BIT)
42977     tmp_regno = R10_REG;
42978   else
42979     {
42980       unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
42981       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
42982         tmp_regno = AX_REG;
42983       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
42984         tmp_regno = DX_REG;
42985       else
42986         tmp_regno = CX_REG;
42987     }
42988
42989   emit_note (NOTE_INSN_PROLOGUE_END);
42990
42991   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
42992      pull it in now and let DELTA benefit.  */
42993   if (REG_P (this_param))
42994     this_reg = this_param;
42995   else if (vcall_offset)
42996     {
42997       /* Put the this parameter into %eax.  */
42998       this_reg = gen_rtx_REG (Pmode, AX_REG);
42999       emit_move_insn (this_reg, this_param);
43000     }
43001   else
43002     this_reg = NULL_RTX;
43003
43004   /* Adjust the this parameter by a fixed constant.  */
43005   if (delta)
43006     {
43007       rtx delta_rtx = GEN_INT (delta);
43008       rtx delta_dst = this_reg ? this_reg : this_param;
43009
43010       if (TARGET_64BIT)
43011         {
43012           if (!x86_64_general_operand (delta_rtx, Pmode))
43013             {
43014               tmp = gen_rtx_REG (Pmode, tmp_regno);
43015               emit_move_insn (tmp, delta_rtx);
43016               delta_rtx = tmp;
43017             }
43018         }
43019
43020       ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx);
43021     }
43022
43023   /* Adjust the this parameter by a value stored in the vtable.  */
43024   if (vcall_offset)
43025     {
43026       rtx vcall_addr, vcall_mem, this_mem;
43027
43028       tmp = gen_rtx_REG (Pmode, tmp_regno);
43029
43030       this_mem = gen_rtx_MEM (ptr_mode, this_reg);
43031       if (Pmode != ptr_mode)
43032         this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem);
43033       emit_move_insn (tmp, this_mem);
43034
43035       /* Adjust the this parameter.  */
43036       vcall_addr = plus_constant (Pmode, tmp, vcall_offset);
43037       if (TARGET_64BIT
43038           && !ix86_legitimate_address_p (ptr_mode, vcall_addr, true))
43039         {
43040           rtx tmp2 = gen_rtx_REG (Pmode, R11_REG);
43041           emit_move_insn (tmp2, GEN_INT (vcall_offset));
43042           vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2);
43043         }
43044
43045       vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr);
43046       if (Pmode != ptr_mode)
43047         emit_insn (gen_addsi_1_zext (this_reg,
43048                                      gen_rtx_REG (ptr_mode,
43049                                                   REGNO (this_reg)),
43050                                      vcall_mem));
43051       else
43052         ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem);
43053     }
43054
43055   /* If necessary, drop THIS back to its stack slot.  */
43056   if (this_reg && this_reg != this_param)
43057     emit_move_insn (this_param, this_reg);
43058
43059   fnaddr = XEXP (DECL_RTL (function), 0);
43060   if (TARGET_64BIT)
43061     {
43062       if (!flag_pic || targetm.binds_local_p (function)
43063           || TARGET_PECOFF)
43064         ;
43065       else
43066         {
43067           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL);
43068           tmp = gen_rtx_CONST (Pmode, tmp);
43069           fnaddr = gen_const_mem (Pmode, tmp);
43070         }
43071     }
43072   else
43073     {
43074       if (!flag_pic || targetm.binds_local_p (function))
43075         ;
43076 #if TARGET_MACHO
43077       else if (TARGET_MACHO)
43078         {
43079           fnaddr = machopic_indirect_call_target (DECL_RTL (function));
43080           fnaddr = XEXP (fnaddr, 0);
43081         }
43082 #endif /* TARGET_MACHO */
43083       else
43084         {
43085           tmp = gen_rtx_REG (Pmode, CX_REG);
43086           output_set_got (tmp, NULL_RTX);
43087
43088           fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT);
43089           fnaddr = gen_rtx_CONST (Pmode, fnaddr);
43090           fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr);
43091           fnaddr = gen_const_mem (Pmode, fnaddr);
43092         }
43093     }
43094
43095   /* Our sibling call patterns do not allow memories, because we have no
43096      predicate that can distinguish between frame and non-frame memory.
43097      For our purposes here, we can get away with (ab)using a jump pattern,
43098      because we're going to do no optimization.  */
43099   if (MEM_P (fnaddr))
43100     {
43101       if (sibcall_insn_operand (fnaddr, word_mode))
43102         {
43103           fnaddr = XEXP (DECL_RTL (function), 0);
43104           tmp = gen_rtx_MEM (QImode, fnaddr);
43105           tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
43106           tmp = emit_call_insn (tmp);
43107           SIBLING_CALL_P (tmp) = 1;
43108         }
43109       else
43110         emit_jump_insn (gen_indirect_jump (fnaddr));
43111     }
43112   else
43113     {
43114       if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr))
43115         {
43116           // CM_LARGE_PIC always uses pseudo PIC register which is
43117           // uninitialized.  Since FUNCTION is local and calling it
43118           // doesn't go through PLT, we use scratch register %r11 as
43119           // PIC register and initialize it here.
43120           pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG);
43121           ix86_init_large_pic_reg (tmp_regno);
43122           fnaddr = legitimize_pic_address (fnaddr,
43123                                            gen_rtx_REG (Pmode, tmp_regno));
43124         }
43125
43126       if (!sibcall_insn_operand (fnaddr, word_mode))
43127         {
43128           tmp = gen_rtx_REG (word_mode, tmp_regno);
43129           if (GET_MODE (fnaddr) != word_mode)
43130             fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr);
43131           emit_move_insn (tmp, fnaddr);
43132           fnaddr = tmp;
43133         }
43134
43135       tmp = gen_rtx_MEM (QImode, fnaddr);
43136       tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
43137       tmp = emit_call_insn (tmp);
43138       SIBLING_CALL_P (tmp) = 1;
43139     }
43140   emit_barrier ();
43141
43142   /* Emit just enough of rest_of_compilation to get the insns emitted.
43143      Note that use_thunk calls assemble_start_function et al.  */
43144   insn = get_insns ();
43145   shorten_branches (insn);
43146   final_start_function (insn, file, 1);
43147   final (insn, file, 1);
43148   final_end_function ();
43149 }
43150
43151 static void
43152 x86_file_start (void)
43153 {
43154   default_file_start ();
43155   if (TARGET_16BIT)
43156     fputs ("\t.code16gcc\n", asm_out_file);
43157 #if TARGET_MACHO
43158   darwin_file_start ();
43159 #endif
43160   if (X86_FILE_START_VERSION_DIRECTIVE)
43161     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
43162   if (X86_FILE_START_FLTUSED)
43163     fputs ("\t.global\t__fltused\n", asm_out_file);
43164   if (ix86_asm_dialect == ASM_INTEL)
43165     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
43166 }
43167
43168 int
43169 x86_field_alignment (tree field, int computed)
43170 {
43171   machine_mode mode;
43172   tree type = TREE_TYPE (field);
43173
43174   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
43175     return computed;
43176   mode = TYPE_MODE (strip_array_types (type));
43177   if (mode == DFmode || mode == DCmode
43178       || GET_MODE_CLASS (mode) == MODE_INT
43179       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
43180     return MIN (32, computed);
43181   return computed;
43182 }
43183
43184 /* Print call to TARGET to FILE.  */
43185
43186 static void
43187 x86_print_call_or_nop (FILE *file, const char *target)
43188 {
43189   if (flag_nop_mcount)
43190     fprintf (file, "1:\tnopl 0x00(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
43191   else
43192     fprintf (file, "1:\tcall\t%s\n", target);
43193 }
43194
43195 /* Output assembler code to FILE to increment profiler label # LABELNO
43196    for profiling a function entry.  */
43197 void
43198 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
43199 {
43200   const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE
43201                                          : MCOUNT_NAME);
43202   if (TARGET_64BIT)
43203     {
43204 #ifndef NO_PROFILE_COUNTERS
43205       fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
43206 #endif
43207
43208       if (!TARGET_PECOFF && flag_pic)
43209         fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
43210       else
43211         x86_print_call_or_nop (file, mcount_name);
43212     }
43213   else if (flag_pic)
43214     {
43215 #ifndef NO_PROFILE_COUNTERS
43216       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n",
43217                LPREFIX, labelno);
43218 #endif
43219       fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
43220     }
43221   else
43222     {
43223 #ifndef NO_PROFILE_COUNTERS
43224       fprintf (file, "\tmovl\t$%sP%d,%%" PROFILE_COUNT_REGISTER "\n",
43225                LPREFIX, labelno);
43226 #endif
43227       x86_print_call_or_nop (file, mcount_name);
43228     }
43229
43230   if (flag_record_mcount)
43231     {
43232       fprintf (file, "\t.section __mcount_loc, \"a\",@progbits\n");
43233       fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
43234       fprintf (file, "\t.previous\n");
43235     }
43236 }
43237
43238 /* We don't have exact information about the insn sizes, but we may assume
43239    quite safely that we are informed about all 1 byte insns and memory
43240    address sizes.  This is enough to eliminate unnecessary padding in
43241    99% of cases.  */
43242
43243 static int
43244 min_insn_size (rtx_insn *insn)
43245 {
43246   int l = 0, len;
43247
43248   if (!INSN_P (insn) || !active_insn_p (insn))
43249     return 0;
43250
43251   /* Discard alignments we've emit and jump instructions.  */
43252   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
43253       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
43254     return 0;
43255
43256   /* Important case - calls are always 5 bytes.
43257      It is common to have many calls in the row.  */
43258   if (CALL_P (insn)
43259       && symbolic_reference_mentioned_p (PATTERN (insn))
43260       && !SIBLING_CALL_P (insn))
43261     return 5;
43262   len = get_attr_length (insn);
43263   if (len <= 1)
43264     return 1;
43265
43266   /* For normal instructions we rely on get_attr_length being exact,
43267      with a few exceptions.  */
43268   if (!JUMP_P (insn))
43269     {
43270       enum attr_type type = get_attr_type (insn);
43271
43272       switch (type)
43273         {
43274         case TYPE_MULTI:
43275           if (GET_CODE (PATTERN (insn)) == ASM_INPUT
43276               || asm_noperands (PATTERN (insn)) >= 0)
43277             return 0;
43278           break;
43279         case TYPE_OTHER:
43280         case TYPE_FCMP:
43281           break;
43282         default:
43283           /* Otherwise trust get_attr_length.  */
43284           return len;
43285         }
43286
43287       l = get_attr_length_address (insn);
43288       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
43289         l = 4;
43290     }
43291   if (l)
43292     return 1+l;
43293   else
43294     return 2;
43295 }
43296
43297 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
43298
43299 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
43300    window.  */
43301
43302 static void
43303 ix86_avoid_jump_mispredicts (void)
43304 {
43305   rtx_insn *insn, *start = get_insns ();
43306   int nbytes = 0, njumps = 0;
43307   bool isjump = false;
43308
43309   /* Look for all minimal intervals of instructions containing 4 jumps.
43310      The intervals are bounded by START and INSN.  NBYTES is the total
43311      size of instructions in the interval including INSN and not including
43312      START.  When the NBYTES is smaller than 16 bytes, it is possible
43313      that the end of START and INSN ends up in the same 16byte page.
43314
43315      The smallest offset in the page INSN can start is the case where START
43316      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
43317      We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
43318
43319      Don't consider asm goto as jump, while it can contain a jump, it doesn't
43320      have to, control transfer to label(s) can be performed through other
43321      means, and also we estimate minimum length of all asm stmts as 0.  */
43322   for (insn = start; insn; insn = NEXT_INSN (insn))
43323     {
43324       int min_size;
43325
43326       if (LABEL_P (insn))
43327         {
43328           int align = label_to_alignment (insn);
43329           int max_skip = label_to_max_skip (insn);
43330
43331           if (max_skip > 15)
43332             max_skip = 15;
43333           /* If align > 3, only up to 16 - max_skip - 1 bytes can be
43334              already in the current 16 byte page, because otherwise
43335              ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
43336              bytes to reach 16 byte boundary.  */
43337           if (align <= 0
43338               || (align <= 3 && max_skip != (1 << align) - 1))
43339             max_skip = 0;
43340           if (dump_file)
43341             fprintf (dump_file, "Label %i with max_skip %i\n",
43342                      INSN_UID (insn), max_skip);
43343           if (max_skip)
43344             {
43345               while (nbytes + max_skip >= 16)
43346                 {
43347                   start = NEXT_INSN (start);
43348                   if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
43349                       || CALL_P (start))
43350                     njumps--, isjump = true;
43351                   else
43352                     isjump = false;
43353                   nbytes -= min_insn_size (start);
43354                 }
43355             }
43356           continue;
43357         }
43358
43359       min_size = min_insn_size (insn);
43360       nbytes += min_size;
43361       if (dump_file)
43362         fprintf (dump_file, "Insn %i estimated to %i bytes\n",
43363                  INSN_UID (insn), min_size);
43364       if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0)
43365           || CALL_P (insn))
43366         njumps++;
43367       else
43368         continue;
43369
43370       while (njumps > 3)
43371         {
43372           start = NEXT_INSN (start);
43373           if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
43374               || CALL_P (start))
43375             njumps--, isjump = true;
43376           else
43377             isjump = false;
43378           nbytes -= min_insn_size (start);
43379         }
43380       gcc_assert (njumps >= 0);
43381       if (dump_file)
43382         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
43383                  INSN_UID (start), INSN_UID (insn), nbytes);
43384
43385       if (njumps == 3 && isjump && nbytes < 16)
43386         {
43387           int padsize = 15 - nbytes + min_insn_size (insn);
43388
43389           if (dump_file)
43390             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
43391                      INSN_UID (insn), padsize);
43392           emit_insn_before (gen_pad (GEN_INT (padsize)), insn);
43393         }
43394     }
43395 }
43396 #endif
43397
43398 /* AMD Athlon works faster
43399    when RET is not destination of conditional jump or directly preceded
43400    by other jump instruction.  We avoid the penalty by inserting NOP just
43401    before the RET instructions in such cases.  */
43402 static void
43403 ix86_pad_returns (void)
43404 {
43405   edge e;
43406   edge_iterator ei;
43407
43408   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43409     {
43410       basic_block bb = e->src;
43411       rtx_insn *ret = BB_END (bb);
43412       rtx_insn *prev;
43413       bool replace = false;
43414
43415       if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret))
43416           || optimize_bb_for_size_p (bb))
43417         continue;
43418       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
43419         if (active_insn_p (prev) || LABEL_P (prev))
43420           break;
43421       if (prev && LABEL_P (prev))
43422         {
43423           edge e;
43424           edge_iterator ei;
43425
43426           FOR_EACH_EDGE (e, ei, bb->preds)
43427             if (EDGE_FREQUENCY (e) && e->src->index >= 0
43428                 && !(e->flags & EDGE_FALLTHRU))
43429               {
43430                 replace = true;
43431                 break;
43432               }
43433         }
43434       if (!replace)
43435         {
43436           prev = prev_active_insn (ret);
43437           if (prev
43438               && ((JUMP_P (prev) && any_condjump_p (prev))
43439                   || CALL_P (prev)))
43440             replace = true;
43441           /* Empty functions get branch mispredict even when
43442              the jump destination is not visible to us.  */
43443           if (!prev && !optimize_function_for_size_p (cfun))
43444             replace = true;
43445         }
43446       if (replace)
43447         {
43448           emit_jump_insn_before (gen_simple_return_internal_long (), ret);
43449           delete_insn (ret);
43450         }
43451     }
43452 }
43453
43454 /* Count the minimum number of instructions in BB.  Return 4 if the
43455    number of instructions >= 4.  */
43456
43457 static int
43458 ix86_count_insn_bb (basic_block bb)
43459 {
43460   rtx_insn *insn;
43461   int insn_count = 0;
43462
43463   /* Count number of instructions in this block.  Return 4 if the number
43464      of instructions >= 4.  */
43465   FOR_BB_INSNS (bb, insn)
43466     {
43467       /* Only happen in exit blocks.  */
43468       if (JUMP_P (insn)
43469           && ANY_RETURN_P (PATTERN (insn)))
43470         break;
43471
43472       if (NONDEBUG_INSN_P (insn)
43473           && GET_CODE (PATTERN (insn)) != USE
43474           && GET_CODE (PATTERN (insn)) != CLOBBER)
43475         {
43476           insn_count++;
43477           if (insn_count >= 4)
43478             return insn_count;
43479         }
43480     }
43481
43482   return insn_count;
43483 }
43484
43485
43486 /* Count the minimum number of instructions in code path in BB.
43487    Return 4 if the number of instructions >= 4.  */
43488
43489 static int
43490 ix86_count_insn (basic_block bb)
43491 {
43492   edge e;
43493   edge_iterator ei;
43494   int min_prev_count;
43495
43496   /* Only bother counting instructions along paths with no
43497      more than 2 basic blocks between entry and exit.  Given
43498      that BB has an edge to exit, determine if a predecessor
43499      of BB has an edge from entry.  If so, compute the number
43500      of instructions in the predecessor block.  If there
43501      happen to be multiple such blocks, compute the minimum.  */
43502   min_prev_count = 4;
43503   FOR_EACH_EDGE (e, ei, bb->preds)
43504     {
43505       edge prev_e;
43506       edge_iterator prev_ei;
43507
43508       if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
43509         {
43510           min_prev_count = 0;
43511           break;
43512         }
43513       FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds)
43514         {
43515           if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
43516             {
43517               int count = ix86_count_insn_bb (e->src);
43518               if (count < min_prev_count)
43519                 min_prev_count = count;
43520               break;
43521             }
43522         }
43523     }
43524
43525   if (min_prev_count < 4)
43526     min_prev_count += ix86_count_insn_bb (bb);
43527
43528   return min_prev_count;
43529 }
43530
43531 /* Pad short function to 4 instructions.   */
43532
43533 static void
43534 ix86_pad_short_function (void)
43535 {
43536   edge e;
43537   edge_iterator ei;
43538
43539   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43540     {
43541       rtx_insn *ret = BB_END (e->src);
43542       if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret)))
43543         {
43544           int insn_count = ix86_count_insn (e->src);
43545
43546           /* Pad short function.  */
43547           if (insn_count < 4)
43548             {
43549               rtx_insn *insn = ret;
43550
43551               /* Find epilogue.  */
43552               while (insn
43553                      && (!NOTE_P (insn)
43554                          || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG))
43555                 insn = PREV_INSN (insn);
43556
43557               if (!insn)
43558                 insn = ret;
43559
43560               /* Two NOPs count as one instruction.  */
43561               insn_count = 2 * (4 - insn_count);
43562               emit_insn_before (gen_nops (GEN_INT (insn_count)), insn);
43563             }
43564         }
43565     }
43566 }
43567
43568 /* Fix up a Windows system unwinder issue.  If an EH region falls through into
43569    the epilogue, the Windows system unwinder will apply epilogue logic and
43570    produce incorrect offsets.  This can be avoided by adding a nop between
43571    the last insn that can throw and the first insn of the epilogue.  */
43572
43573 static void
43574 ix86_seh_fixup_eh_fallthru (void)
43575 {
43576   edge e;
43577   edge_iterator ei;
43578
43579   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43580     {
43581       rtx_insn *insn, *next;
43582
43583       /* Find the beginning of the epilogue.  */
43584       for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn))
43585         if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
43586           break;
43587       if (insn == NULL)
43588         continue;
43589
43590       /* We only care about preceding insns that can throw.  */
43591       insn = prev_active_insn (insn);
43592       if (insn == NULL || !can_throw_internal (insn))
43593         continue;
43594
43595       /* Do not separate calls from their debug information.  */
43596       for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next))
43597         if (NOTE_P (next)
43598             && (NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION
43599                 || NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION))
43600           insn = next;
43601         else
43602           break;
43603
43604       emit_insn_after (gen_nops (const1_rtx), insn);
43605     }
43606 }
43607
43608 /* Implement machine specific optimizations.  We implement padding of returns
43609    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
43610 static void
43611 ix86_reorg (void)
43612 {
43613   /* We are freeing block_for_insn in the toplev to keep compatibility
43614      with old MDEP_REORGS that are not CFG based.  Recompute it now.  */
43615   compute_bb_for_insn ();
43616
43617   if (TARGET_SEH && current_function_has_exception_handlers ())
43618     ix86_seh_fixup_eh_fallthru ();
43619
43620   if (optimize && optimize_function_for_speed_p (cfun))
43621     {
43622       if (TARGET_PAD_SHORT_FUNCTION)
43623         ix86_pad_short_function ();
43624       else if (TARGET_PAD_RETURNS)
43625         ix86_pad_returns ();
43626 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
43627       if (TARGET_FOUR_JUMP_LIMIT)
43628         ix86_avoid_jump_mispredicts ();
43629 #endif
43630     }
43631 }
43632
43633 /* Return nonzero when QImode register that must be represented via REX prefix
43634    is used.  */
43635 bool
43636 x86_extended_QIreg_mentioned_p (rtx_insn *insn)
43637 {
43638   int i;
43639   extract_insn_cached (insn);
43640   for (i = 0; i < recog_data.n_operands; i++)
43641     if (GENERAL_REG_P (recog_data.operand[i])
43642         && !QI_REGNO_P (REGNO (recog_data.operand[i])))
43643        return true;
43644   return false;
43645 }
43646
43647 /* Return true when INSN mentions register that must be encoded using REX
43648    prefix.  */
43649 bool
43650 x86_extended_reg_mentioned_p (rtx insn)
43651 {
43652   subrtx_iterator::array_type array;
43653   FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
43654     {
43655       const_rtx x = *iter;
43656       if (REG_P (x)
43657           && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x))))
43658         return true;
43659     }
43660   return false;
43661 }
43662
43663 /* If profitable, negate (without causing overflow) integer constant
43664    of mode MODE at location LOC.  Return true in this case.  */
43665 bool
43666 x86_maybe_negate_const_int (rtx *loc, machine_mode mode)
43667 {
43668   HOST_WIDE_INT val;
43669
43670   if (!CONST_INT_P (*loc))
43671     return false;
43672
43673   switch (mode)
43674     {
43675     case DImode:
43676       /* DImode x86_64 constants must fit in 32 bits.  */
43677       gcc_assert (x86_64_immediate_operand (*loc, mode));
43678
43679       mode = SImode;
43680       break;
43681
43682     case SImode:
43683     case HImode:
43684     case QImode:
43685       break;
43686
43687     default:
43688       gcc_unreachable ();
43689     }
43690
43691   /* Avoid overflows.  */
43692   if (mode_signbit_p (mode, *loc))
43693     return false;
43694
43695   val = INTVAL (*loc);
43696
43697   /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
43698      Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
43699   if ((val < 0 && val != -128)
43700       || val == 128)
43701     {
43702       *loc = GEN_INT (-val);
43703       return true;
43704     }
43705
43706   return false;
43707 }
43708
43709 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
43710    optabs would emit if we didn't have TFmode patterns.  */
43711
43712 void
43713 x86_emit_floatuns (rtx operands[2])
43714 {
43715   rtx_code_label *neglab, *donelab;
43716   rtx i0, i1, f0, in, out;
43717   machine_mode mode, inmode;
43718
43719   inmode = GET_MODE (operands[1]);
43720   gcc_assert (inmode == SImode || inmode == DImode);
43721
43722   out = operands[0];
43723   in = force_reg (inmode, operands[1]);
43724   mode = GET_MODE (out);
43725   neglab = gen_label_rtx ();
43726   donelab = gen_label_rtx ();
43727   f0 = gen_reg_rtx (mode);
43728
43729   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
43730
43731   expand_float (out, in, 0);
43732
43733   emit_jump_insn (gen_jump (donelab));
43734   emit_barrier ();
43735
43736   emit_label (neglab);
43737
43738   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
43739                             1, OPTAB_DIRECT);
43740   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
43741                             1, OPTAB_DIRECT);
43742   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
43743
43744   expand_float (f0, i0, 0);
43745
43746   emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0)));
43747
43748   emit_label (donelab);
43749 }
43750 \f
43751 static bool canonicalize_perm (struct expand_vec_perm_d *d);
43752 static bool expand_vec_perm_1 (struct expand_vec_perm_d *d);
43753 static bool expand_vec_perm_broadcast_1 (struct expand_vec_perm_d *d);
43754 static bool expand_vec_perm_palignr (struct expand_vec_perm_d *d, bool);
43755
43756 /* Get a vector mode of the same size as the original but with elements
43757    twice as wide.  This is only guaranteed to apply to integral vectors.  */
43758
43759 static inline machine_mode
43760 get_mode_wider_vector (machine_mode o)
43761 {
43762   /* ??? Rely on the ordering that genmodes.c gives to vectors.  */
43763   machine_mode n = GET_MODE_WIDER_MODE (o);
43764   gcc_assert (GET_MODE_NUNITS (o) == GET_MODE_NUNITS (n) * 2);
43765   gcc_assert (GET_MODE_SIZE (o) == GET_MODE_SIZE (n));
43766   return n;
43767 }
43768
43769 /* A subroutine of ix86_expand_vector_init_duplicate.  Tries to
43770    fill target with val via vec_duplicate.  */
43771
43772 static bool
43773 ix86_vector_duplicate_value (machine_mode mode, rtx target, rtx val)
43774 {
43775   bool ok;
43776   rtx_insn *insn;
43777   rtx dup;
43778
43779   /* First attempt to recognize VAL as-is.  */
43780   dup = gen_rtx_VEC_DUPLICATE (mode, val);
43781   insn = emit_insn (gen_rtx_SET (target, dup));
43782   if (recog_memoized (insn) < 0)
43783     {
43784       rtx_insn *seq;
43785       /* If that fails, force VAL into a register.  */
43786
43787       start_sequence ();
43788       XEXP (dup, 0) = force_reg (GET_MODE_INNER (mode), val);
43789       seq = get_insns ();
43790       end_sequence ();
43791       if (seq)
43792         emit_insn_before (seq, insn);
43793
43794       ok = recog_memoized (insn) >= 0;
43795       gcc_assert (ok);
43796     }
43797   return true;
43798 }
43799
43800 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43801    with all elements equal to VAR.  Return true if successful.  */
43802
43803 static bool
43804 ix86_expand_vector_init_duplicate (bool mmx_ok, machine_mode mode,
43805                                    rtx target, rtx val)
43806 {
43807   bool ok;
43808
43809   switch (mode)
43810     {
43811     case V2SImode:
43812     case V2SFmode:
43813       if (!mmx_ok)
43814         return false;
43815       /* FALLTHRU */
43816
43817     case V4DFmode:
43818     case V4DImode:
43819     case V8SFmode:
43820     case V8SImode:
43821     case V2DFmode:
43822     case V2DImode:
43823     case V4SFmode:
43824     case V4SImode:
43825     case V16SImode:
43826     case V8DImode:
43827     case V16SFmode:
43828     case V8DFmode:
43829       return ix86_vector_duplicate_value (mode, target, val);
43830
43831     case V4HImode:
43832       if (!mmx_ok)
43833         return false;
43834       if (TARGET_SSE || TARGET_3DNOW_A)
43835         {
43836           rtx x;
43837
43838           val = gen_lowpart (SImode, val);
43839           x = gen_rtx_TRUNCATE (HImode, val);
43840           x = gen_rtx_VEC_DUPLICATE (mode, x);
43841           emit_insn (gen_rtx_SET (target, x));
43842           return true;
43843         }
43844       goto widen;
43845
43846     case V8QImode:
43847       if (!mmx_ok)
43848         return false;
43849       goto widen;
43850
43851     case V8HImode:
43852       if (TARGET_AVX2)
43853         return ix86_vector_duplicate_value (mode, target, val);
43854
43855       if (TARGET_SSE2)
43856         {
43857           struct expand_vec_perm_d dperm;
43858           rtx tmp1, tmp2;
43859
43860         permute:
43861           memset (&dperm, 0, sizeof (dperm));
43862           dperm.target = target;
43863           dperm.vmode = mode;
43864           dperm.nelt = GET_MODE_NUNITS (mode);
43865           dperm.op0 = dperm.op1 = gen_reg_rtx (mode);
43866           dperm.one_operand_p = true;
43867
43868           /* Extend to SImode using a paradoxical SUBREG.  */
43869           tmp1 = gen_reg_rtx (SImode);
43870           emit_move_insn (tmp1, gen_lowpart (SImode, val));
43871
43872           /* Insert the SImode value as low element of a V4SImode vector. */
43873           tmp2 = gen_reg_rtx (V4SImode);
43874           emit_insn (gen_vec_setv4si_0 (tmp2, CONST0_RTX (V4SImode), tmp1));
43875           emit_move_insn (dperm.op0, gen_lowpart (mode, tmp2));
43876
43877           ok = (expand_vec_perm_1 (&dperm)
43878                 || expand_vec_perm_broadcast_1 (&dperm));
43879           gcc_assert (ok);
43880           return ok;
43881         }
43882       goto widen;
43883
43884     case V16QImode:
43885       if (TARGET_AVX2)
43886         return ix86_vector_duplicate_value (mode, target, val);
43887
43888       if (TARGET_SSE2)
43889         goto permute;
43890       goto widen;
43891
43892     widen:
43893       /* Replicate the value once into the next wider mode and recurse.  */
43894       {
43895         machine_mode smode, wsmode, wvmode;
43896         rtx x;
43897
43898         smode = GET_MODE_INNER (mode);
43899         wvmode = get_mode_wider_vector (mode);
43900         wsmode = GET_MODE_INNER (wvmode);
43901
43902         val = convert_modes (wsmode, smode, val, true);
43903         x = expand_simple_binop (wsmode, ASHIFT, val,
43904                                  GEN_INT (GET_MODE_BITSIZE (smode)),
43905                                  NULL_RTX, 1, OPTAB_LIB_WIDEN);
43906         val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
43907
43908         x = gen_reg_rtx (wvmode);
43909         ok = ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val);
43910         gcc_assert (ok);
43911         emit_move_insn (target, gen_lowpart (GET_MODE (target), x));
43912         return ok;
43913       }
43914
43915     case V16HImode:
43916     case V32QImode:
43917       if (TARGET_AVX2)
43918         return ix86_vector_duplicate_value (mode, target, val);
43919       else
43920         {
43921           machine_mode hvmode = (mode == V16HImode ? V8HImode : V16QImode);
43922           rtx x = gen_reg_rtx (hvmode);
43923
43924           ok = ix86_expand_vector_init_duplicate (false, hvmode, x, val);
43925           gcc_assert (ok);
43926
43927           x = gen_rtx_VEC_CONCAT (mode, x, x);
43928           emit_insn (gen_rtx_SET (target, x));
43929         }
43930       return true;
43931
43932     case V64QImode:
43933     case V32HImode:
43934       if (TARGET_AVX512BW)
43935         return ix86_vector_duplicate_value (mode, target, val);
43936       else
43937         {
43938           machine_mode hvmode = (mode == V32HImode ? V16HImode : V32QImode);
43939           rtx x = gen_reg_rtx (hvmode);
43940
43941           ok = ix86_expand_vector_init_duplicate (false, hvmode, x, val);
43942           gcc_assert (ok);
43943
43944           x = gen_rtx_VEC_CONCAT (mode, x, x);
43945           emit_insn (gen_rtx_SET (target, x));
43946         }
43947       return true;
43948
43949     default:
43950       return false;
43951     }
43952 }
43953
43954 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43955    whose ONE_VAR element is VAR, and other elements are zero.  Return true
43956    if successful.  */
43957
43958 static bool
43959 ix86_expand_vector_init_one_nonzero (bool mmx_ok, machine_mode mode,
43960                                      rtx target, rtx var, int one_var)
43961 {
43962   machine_mode vsimode;
43963   rtx new_target;
43964   rtx x, tmp;
43965   bool use_vector_set = false;
43966
43967   switch (mode)
43968     {
43969     case V2DImode:
43970       /* For SSE4.1, we normally use vector set.  But if the second
43971          element is zero and inter-unit moves are OK, we use movq
43972          instead.  */
43973       use_vector_set = (TARGET_64BIT && TARGET_SSE4_1
43974                         && !(TARGET_INTER_UNIT_MOVES_TO_VEC
43975                              && one_var == 0));
43976       break;
43977     case V16QImode:
43978     case V4SImode:
43979     case V4SFmode:
43980       use_vector_set = TARGET_SSE4_1;
43981       break;
43982     case V8HImode:
43983       use_vector_set = TARGET_SSE2;
43984       break;
43985     case V4HImode:
43986       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
43987       break;
43988     case V32QImode:
43989     case V16HImode:
43990     case V8SImode:
43991     case V8SFmode:
43992     case V4DFmode:
43993       use_vector_set = TARGET_AVX;
43994       break;
43995     case V4DImode:
43996       /* Use ix86_expand_vector_set in 64bit mode only.  */
43997       use_vector_set = TARGET_AVX && TARGET_64BIT;
43998       break;
43999     default:
44000       break;
44001     }
44002
44003   if (use_vector_set)
44004     {
44005       emit_insn (gen_rtx_SET (target, CONST0_RTX (mode)));
44006       var = force_reg (GET_MODE_INNER (mode), var);
44007       ix86_expand_vector_set (mmx_ok, target, var, one_var);
44008       return true;
44009     }
44010
44011   switch (mode)
44012     {
44013     case V2SFmode:
44014     case V2SImode:
44015       if (!mmx_ok)
44016         return false;
44017       /* FALLTHRU */
44018
44019     case V2DFmode:
44020     case V2DImode:
44021       if (one_var != 0)
44022         return false;
44023       var = force_reg (GET_MODE_INNER (mode), var);
44024       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
44025       emit_insn (gen_rtx_SET (target, x));
44026       return true;
44027
44028     case V4SFmode:
44029     case V4SImode:
44030       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
44031         new_target = gen_reg_rtx (mode);
44032       else
44033         new_target = target;
44034       var = force_reg (GET_MODE_INNER (mode), var);
44035       x = gen_rtx_VEC_DUPLICATE (mode, var);
44036       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
44037       emit_insn (gen_rtx_SET (new_target, x));
44038       if (one_var != 0)
44039         {
44040           /* We need to shuffle the value to the correct position, so
44041              create a new pseudo to store the intermediate result.  */
44042
44043           /* With SSE2, we can use the integer shuffle insns.  */
44044           if (mode != V4SFmode && TARGET_SSE2)
44045             {
44046               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
44047                                             const1_rtx,
44048                                             GEN_INT (one_var == 1 ? 0 : 1),
44049                                             GEN_INT (one_var == 2 ? 0 : 1),
44050                                             GEN_INT (one_var == 3 ? 0 : 1)));
44051               if (target != new_target)
44052                 emit_move_insn (target, new_target);
44053               return true;
44054             }
44055
44056           /* Otherwise convert the intermediate result to V4SFmode and
44057              use the SSE1 shuffle instructions.  */
44058           if (mode != V4SFmode)
44059             {
44060               tmp = gen_reg_rtx (V4SFmode);
44061               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
44062             }
44063           else
44064             tmp = new_target;
44065
44066           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
44067                                        const1_rtx,
44068                                        GEN_INT (one_var == 1 ? 0 : 1),
44069                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
44070                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
44071
44072           if (mode != V4SFmode)
44073             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
44074           else if (tmp != target)
44075             emit_move_insn (target, tmp);
44076         }
44077       else if (target != new_target)
44078         emit_move_insn (target, new_target);
44079       return true;
44080
44081     case V8HImode:
44082     case V16QImode:
44083       vsimode = V4SImode;
44084       goto widen;
44085     case V4HImode:
44086     case V8QImode:
44087       if (!mmx_ok)
44088         return false;
44089       vsimode = V2SImode;
44090       goto widen;
44091     widen:
44092       if (one_var != 0)
44093         return false;
44094
44095       /* Zero extend the variable element to SImode and recurse.  */
44096       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
44097
44098       x = gen_reg_rtx (vsimode);
44099       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
44100                                                 var, one_var))
44101         gcc_unreachable ();
44102
44103       emit_move_insn (target, gen_lowpart (mode, x));
44104       return true;
44105
44106     default:
44107       return false;
44108     }
44109 }
44110
44111 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
44112    consisting of the values in VALS.  It is known that all elements
44113    except ONE_VAR are constants.  Return true if successful.  */
44114
44115 static bool
44116 ix86_expand_vector_init_one_var (bool mmx_ok, machine_mode mode,
44117                                  rtx target, rtx vals, int one_var)
44118 {
44119   rtx var = XVECEXP (vals, 0, one_var);
44120   machine_mode wmode;
44121   rtx const_vec, x;
44122
44123   const_vec = copy_rtx (vals);
44124   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
44125   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
44126
44127   switch (mode)
44128     {
44129     case V2DFmode:
44130     case V2DImode:
44131     case V2SFmode:
44132     case V2SImode:
44133       /* For the two element vectors, it's just as easy to use
44134          the general case.  */
44135       return false;
44136
44137     case V4DImode:
44138       /* Use ix86_expand_vector_set in 64bit mode only.  */
44139       if (!TARGET_64BIT)
44140         return false;
44141     case V4DFmode:
44142     case V8SFmode:
44143     case V8SImode:
44144     case V16HImode:
44145     case V32QImode:
44146     case V4SFmode:
44147     case V4SImode:
44148     case V8HImode:
44149     case V4HImode:
44150       break;
44151
44152     case V16QImode:
44153       if (TARGET_SSE4_1)
44154         break;
44155       wmode = V8HImode;
44156       goto widen;
44157     case V8QImode:
44158       wmode = V4HImode;
44159       goto widen;
44160     widen:
44161       /* There's no way to set one QImode entry easily.  Combine
44162          the variable value with its adjacent constant value, and
44163          promote to an HImode set.  */
44164       x = XVECEXP (vals, 0, one_var ^ 1);
44165       if (one_var & 1)
44166         {
44167           var = convert_modes (HImode, QImode, var, true);
44168           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
44169                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
44170           x = GEN_INT (INTVAL (x) & 0xff);
44171         }
44172       else
44173         {
44174           var = convert_modes (HImode, QImode, var, true);
44175           x = gen_int_mode (INTVAL (x) << 8, HImode);
44176         }
44177       if (x != const0_rtx)
44178         var = expand_simple_binop (HImode, IOR, var, x, var,
44179                                    1, OPTAB_LIB_WIDEN);
44180
44181       x = gen_reg_rtx (wmode);
44182       emit_move_insn (x, gen_lowpart (wmode, const_vec));
44183       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
44184
44185       emit_move_insn (target, gen_lowpart (mode, x));
44186       return true;
44187
44188     default:
44189       return false;
44190     }
44191
44192   emit_move_insn (target, const_vec);
44193   ix86_expand_vector_set (mmx_ok, target, var, one_var);
44194   return true;
44195 }
44196
44197 /* A subroutine of ix86_expand_vector_init_general.  Use vector
44198    concatenate to handle the most general case: all values variable,
44199    and none identical.  */
44200
44201 static void
44202 ix86_expand_vector_init_concat (machine_mode mode,
44203                                 rtx target, rtx *ops, int n)
44204 {
44205   machine_mode cmode, hmode = VOIDmode, gmode = VOIDmode;
44206   rtx first[16], second[8], third[4];
44207   rtvec v;
44208   int i, j;
44209
44210   switch (n)
44211     {
44212     case 2:
44213       switch (mode)
44214         {
44215         case V16SImode:
44216           cmode = V8SImode;
44217           break;
44218         case V16SFmode:
44219           cmode = V8SFmode;
44220           break;
44221         case V8DImode:
44222           cmode = V4DImode;
44223           break;
44224         case V8DFmode:
44225           cmode = V4DFmode;
44226           break;
44227         case V8SImode:
44228           cmode = V4SImode;
44229           break;
44230         case V8SFmode:
44231           cmode = V4SFmode;
44232           break;
44233         case V4DImode:
44234           cmode = V2DImode;
44235           break;
44236         case V4DFmode:
44237           cmode = V2DFmode;
44238           break;
44239         case V4SImode:
44240           cmode = V2SImode;
44241           break;
44242         case V4SFmode:
44243           cmode = V2SFmode;
44244           break;
44245         case V2DImode:
44246           cmode = DImode;
44247           break;
44248         case V2SImode:
44249           cmode = SImode;
44250           break;
44251         case V2DFmode:
44252           cmode = DFmode;
44253           break;
44254         case V2SFmode:
44255           cmode = SFmode;
44256           break;
44257         default:
44258           gcc_unreachable ();
44259         }
44260
44261       if (!register_operand (ops[1], cmode))
44262         ops[1] = force_reg (cmode, ops[1]);
44263       if (!register_operand (ops[0], cmode))
44264         ops[0] = force_reg (cmode, ops[0]);
44265       emit_insn (gen_rtx_SET (target, gen_rtx_VEC_CONCAT (mode, ops[0],
44266                                                           ops[1])));
44267       break;
44268
44269     case 4:
44270       switch (mode)
44271         {
44272         case V4DImode:
44273           cmode = V2DImode;
44274           break;
44275         case V4DFmode:
44276           cmode = V2DFmode;
44277           break;
44278         case V4SImode:
44279           cmode = V2SImode;
44280           break;
44281         case V4SFmode:
44282           cmode = V2SFmode;
44283           break;
44284         default:
44285           gcc_unreachable ();
44286         }
44287       goto half;
44288
44289     case 8:
44290       switch (mode)
44291         {
44292         case V8DImode:
44293           cmode = V2DImode;
44294           hmode = V4DImode;
44295           break;
44296         case V8DFmode:
44297           cmode = V2DFmode;
44298           hmode = V4DFmode;
44299           break;
44300         case V8SImode:
44301           cmode = V2SImode;
44302           hmode = V4SImode;
44303           break;
44304         case V8SFmode:
44305           cmode = V2SFmode;
44306           hmode = V4SFmode;
44307           break;
44308         default:
44309           gcc_unreachable ();
44310         }
44311       goto half;
44312
44313     case 16:
44314       switch (mode)
44315         {
44316         case V16SImode:
44317           cmode = V2SImode;
44318           hmode = V4SImode;
44319           gmode = V8SImode;
44320           break;
44321         case V16SFmode:
44322           cmode = V2SFmode;
44323           hmode = V4SFmode;
44324           gmode = V8SFmode;
44325           break;
44326         default:
44327           gcc_unreachable ();
44328         }
44329       goto half;
44330
44331 half:
44332       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
44333       i = n - 1;
44334       j = (n >> 1) - 1;
44335       for (; i > 0; i -= 2, j--)
44336         {
44337           first[j] = gen_reg_rtx (cmode);
44338           v = gen_rtvec (2, ops[i - 1], ops[i]);
44339           ix86_expand_vector_init (false, first[j],
44340                                    gen_rtx_PARALLEL (cmode, v));
44341         }
44342
44343       n >>= 1;
44344       if (n > 4)
44345         {
44346           gcc_assert (hmode != VOIDmode);
44347           gcc_assert (gmode != VOIDmode);
44348           for (i = j = 0; i < n; i += 2, j++)
44349             {
44350               second[j] = gen_reg_rtx (hmode);
44351               ix86_expand_vector_init_concat (hmode, second [j],
44352                                               &first [i], 2);
44353             }
44354           n >>= 1;
44355           for (i = j = 0; i < n; i += 2, j++)
44356             {
44357               third[j] = gen_reg_rtx (gmode);
44358               ix86_expand_vector_init_concat (gmode, third[j],
44359                                               &second[i], 2);
44360             }
44361           n >>= 1;
44362           ix86_expand_vector_init_concat (mode, target, third, n);
44363         }
44364       else if (n > 2)
44365         {
44366           gcc_assert (hmode != VOIDmode);
44367           for (i = j = 0; i < n; i += 2, j++)
44368             {
44369               second[j] = gen_reg_rtx (hmode);
44370               ix86_expand_vector_init_concat (hmode, second [j],
44371                                               &first [i], 2);
44372             }
44373           n >>= 1;
44374           ix86_expand_vector_init_concat (mode, target, second, n);
44375         }
44376       else
44377         ix86_expand_vector_init_concat (mode, target, first, n);
44378       break;
44379
44380     default:
44381       gcc_unreachable ();
44382     }
44383 }
44384
44385 /* A subroutine of ix86_expand_vector_init_general.  Use vector
44386    interleave to handle the most general case: all values variable,
44387    and none identical.  */
44388
44389 static void
44390 ix86_expand_vector_init_interleave (machine_mode mode,
44391                                     rtx target, rtx *ops, int n)
44392 {
44393   machine_mode first_imode, second_imode, third_imode, inner_mode;
44394   int i, j;
44395   rtx op0, op1;
44396   rtx (*gen_load_even) (rtx, rtx, rtx);
44397   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
44398   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
44399
44400   switch (mode)
44401     {
44402     case V8HImode:
44403       gen_load_even = gen_vec_setv8hi;
44404       gen_interleave_first_low = gen_vec_interleave_lowv4si;
44405       gen_interleave_second_low = gen_vec_interleave_lowv2di;
44406       inner_mode = HImode;
44407       first_imode = V4SImode;
44408       second_imode = V2DImode;
44409       third_imode = VOIDmode;
44410       break;
44411     case V16QImode:
44412       gen_load_even = gen_vec_setv16qi;
44413       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
44414       gen_interleave_second_low = gen_vec_interleave_lowv4si;
44415       inner_mode = QImode;
44416       first_imode = V8HImode;
44417       second_imode = V4SImode;
44418       third_imode = V2DImode;
44419       break;
44420     default:
44421       gcc_unreachable ();
44422     }
44423
44424   for (i = 0; i < n; i++)
44425     {
44426       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
44427       op0 = gen_reg_rtx (SImode);
44428       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
44429
44430       /* Insert the SImode value as low element of V4SImode vector. */
44431       op1 = gen_reg_rtx (V4SImode);
44432       op0 = gen_rtx_VEC_MERGE (V4SImode,
44433                                gen_rtx_VEC_DUPLICATE (V4SImode,
44434                                                       op0),
44435                                CONST0_RTX (V4SImode),
44436                                const1_rtx);
44437       emit_insn (gen_rtx_SET (op1, op0));
44438
44439       /* Cast the V4SImode vector back to a vector in orignal mode.  */
44440       op0 = gen_reg_rtx (mode);
44441       emit_move_insn (op0, gen_lowpart (mode, op1));
44442
44443       /* Load even elements into the second position.  */
44444       emit_insn (gen_load_even (op0,
44445                                 force_reg (inner_mode,
44446                                            ops [i + i + 1]),
44447                                 const1_rtx));
44448
44449       /* Cast vector to FIRST_IMODE vector.  */
44450       ops[i] = gen_reg_rtx (first_imode);
44451       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
44452     }
44453
44454   /* Interleave low FIRST_IMODE vectors.  */
44455   for (i = j = 0; i < n; i += 2, j++)
44456     {
44457       op0 = gen_reg_rtx (first_imode);
44458       emit_insn (gen_interleave_first_low (op0, ops[i], ops[i + 1]));
44459
44460       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
44461       ops[j] = gen_reg_rtx (second_imode);
44462       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
44463     }
44464
44465   /* Interleave low SECOND_IMODE vectors.  */
44466   switch (second_imode)
44467     {
44468     case V4SImode:
44469       for (i = j = 0; i < n / 2; i += 2, j++)
44470         {
44471           op0 = gen_reg_rtx (second_imode);
44472           emit_insn (gen_interleave_second_low (op0, ops[i],
44473                                                 ops[i + 1]));
44474
44475           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
44476              vector.  */
44477           ops[j] = gen_reg_rtx (third_imode);
44478           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
44479         }
44480       second_imode = V2DImode;
44481       gen_interleave_second_low = gen_vec_interleave_lowv2di;
44482       /* FALLTHRU */
44483
44484     case V2DImode:
44485       op0 = gen_reg_rtx (second_imode);
44486       emit_insn (gen_interleave_second_low (op0, ops[0],
44487                                             ops[1]));
44488
44489       /* Cast the SECOND_IMODE vector back to a vector on original
44490          mode.  */
44491       emit_insn (gen_rtx_SET (target, gen_lowpart (mode, op0)));
44492       break;
44493
44494     default:
44495       gcc_unreachable ();
44496     }
44497 }
44498
44499 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
44500    all values variable, and none identical.  */
44501
44502 static void
44503 ix86_expand_vector_init_general (bool mmx_ok, machine_mode mode,
44504                                  rtx target, rtx vals)
44505 {
44506   rtx ops[64], op0, op1, op2, op3, op4, op5;
44507   machine_mode half_mode = VOIDmode;
44508   machine_mode quarter_mode = VOIDmode;
44509   int n, i;
44510
44511   switch (mode)
44512     {
44513     case V2SFmode:
44514     case V2SImode:
44515       if (!mmx_ok && !TARGET_SSE)
44516         break;
44517       /* FALLTHRU */
44518
44519     case V16SImode:
44520     case V16SFmode:
44521     case V8DFmode:
44522     case V8DImode:
44523     case V8SFmode:
44524     case V8SImode:
44525     case V4DFmode:
44526     case V4DImode:
44527     case V4SFmode:
44528     case V4SImode:
44529     case V2DFmode:
44530     case V2DImode:
44531       n = GET_MODE_NUNITS (mode);
44532       for (i = 0; i < n; i++)
44533         ops[i] = XVECEXP (vals, 0, i);
44534       ix86_expand_vector_init_concat (mode, target, ops, n);
44535       return;
44536
44537     case V32QImode:
44538       half_mode = V16QImode;
44539       goto half;
44540
44541     case V16HImode:
44542       half_mode = V8HImode;
44543       goto half;
44544
44545 half:
44546       n = GET_MODE_NUNITS (mode);
44547       for (i = 0; i < n; i++)
44548         ops[i] = XVECEXP (vals, 0, i);
44549       op0 = gen_reg_rtx (half_mode);
44550       op1 = gen_reg_rtx (half_mode);
44551       ix86_expand_vector_init_interleave (half_mode, op0, ops,
44552                                           n >> 2);
44553       ix86_expand_vector_init_interleave (half_mode, op1,
44554                                           &ops [n >> 1], n >> 2);
44555       emit_insn (gen_rtx_SET (target, gen_rtx_VEC_CONCAT (mode, op0, op1)));
44556       return;
44557
44558     case V64QImode:
44559       quarter_mode = V16QImode;
44560       half_mode = V32QImode;
44561       goto quarter;
44562
44563     case V32HImode:
44564       quarter_mode = V8HImode;
44565       half_mode = V16HImode;
44566       goto quarter;
44567
44568 quarter:
44569       n = GET_MODE_NUNITS (mode);
44570       for (i = 0; i < n; i++)
44571         ops[i] = XVECEXP (vals, 0, i);
44572       op0 = gen_reg_rtx (quarter_mode);
44573       op1 = gen_reg_rtx (quarter_mode);
44574       op2 = gen_reg_rtx (quarter_mode);
44575       op3 = gen_reg_rtx (quarter_mode);
44576       op4 = gen_reg_rtx (half_mode);
44577       op5 = gen_reg_rtx (half_mode);
44578       ix86_expand_vector_init_interleave (quarter_mode, op0, ops,
44579                                           n >> 3);
44580       ix86_expand_vector_init_interleave (quarter_mode, op1,
44581                                           &ops [n >> 2], n >> 3);
44582       ix86_expand_vector_init_interleave (quarter_mode, op2,
44583                                           &ops [n >> 1], n >> 3);
44584       ix86_expand_vector_init_interleave (quarter_mode, op3,
44585                                           &ops [(n >> 1) | (n >> 2)], n >> 3);
44586       emit_insn (gen_rtx_SET (op4, gen_rtx_VEC_CONCAT (half_mode, op0, op1)));
44587       emit_insn (gen_rtx_SET (op5, gen_rtx_VEC_CONCAT (half_mode, op2, op3)));
44588       emit_insn (gen_rtx_SET (target, gen_rtx_VEC_CONCAT (mode, op4, op5)));
44589       return;
44590
44591     case V16QImode:
44592       if (!TARGET_SSE4_1)
44593         break;
44594       /* FALLTHRU */
44595
44596     case V8HImode:
44597       if (!TARGET_SSE2)
44598         break;
44599
44600       /* Don't use ix86_expand_vector_init_interleave if we can't
44601          move from GPR to SSE register directly.  */
44602       if (!TARGET_INTER_UNIT_MOVES_TO_VEC)
44603         break;
44604
44605       n = GET_MODE_NUNITS (mode);
44606       for (i = 0; i < n; i++)
44607         ops[i] = XVECEXP (vals, 0, i);
44608       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
44609       return;
44610
44611     case V4HImode:
44612     case V8QImode:
44613       break;
44614
44615     default:
44616       gcc_unreachable ();
44617     }
44618
44619     {
44620       int i, j, n_elts, n_words, n_elt_per_word;
44621       machine_mode inner_mode;
44622       rtx words[4], shift;
44623
44624       inner_mode = GET_MODE_INNER (mode);
44625       n_elts = GET_MODE_NUNITS (mode);
44626       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
44627       n_elt_per_word = n_elts / n_words;
44628       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
44629
44630       for (i = 0; i < n_words; ++i)
44631         {
44632           rtx word = NULL_RTX;
44633
44634           for (j = 0; j < n_elt_per_word; ++j)
44635             {
44636               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
44637               elt = convert_modes (word_mode, inner_mode, elt, true);
44638
44639               if (j == 0)
44640                 word = elt;
44641               else
44642                 {
44643                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
44644                                               word, 1, OPTAB_LIB_WIDEN);
44645                   word = expand_simple_binop (word_mode, IOR, word, elt,
44646                                               word, 1, OPTAB_LIB_WIDEN);
44647                 }
44648             }
44649
44650           words[i] = word;
44651         }
44652
44653       if (n_words == 1)
44654         emit_move_insn (target, gen_lowpart (mode, words[0]));
44655       else if (n_words == 2)
44656         {
44657           rtx tmp = gen_reg_rtx (mode);
44658           emit_clobber (tmp);
44659           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
44660           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
44661           emit_move_insn (target, tmp);
44662         }
44663       else if (n_words == 4)
44664         {
44665           rtx tmp = gen_reg_rtx (V4SImode);
44666           gcc_assert (word_mode == SImode);
44667           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
44668           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
44669           emit_move_insn (target, gen_lowpart (mode, tmp));
44670         }
44671       else
44672         gcc_unreachable ();
44673     }
44674 }
44675
44676 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
44677    instructions unless MMX_OK is true.  */
44678
44679 void
44680 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
44681 {
44682   machine_mode mode = GET_MODE (target);
44683   machine_mode inner_mode = GET_MODE_INNER (mode);
44684   int n_elts = GET_MODE_NUNITS (mode);
44685   int n_var = 0, one_var = -1;
44686   bool all_same = true, all_const_zero = true;
44687   int i;
44688   rtx x;
44689
44690   for (i = 0; i < n_elts; ++i)
44691     {
44692       x = XVECEXP (vals, 0, i);
44693       if (!(CONST_SCALAR_INT_P (x)
44694             || CONST_DOUBLE_P (x)
44695             || CONST_FIXED_P (x)))
44696         n_var++, one_var = i;
44697       else if (x != CONST0_RTX (inner_mode))
44698         all_const_zero = false;
44699       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
44700         all_same = false;
44701     }
44702
44703   /* Constants are best loaded from the constant pool.  */
44704   if (n_var == 0)
44705     {
44706       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
44707       return;
44708     }
44709
44710   /* If all values are identical, broadcast the value.  */
44711   if (all_same
44712       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
44713                                             XVECEXP (vals, 0, 0)))
44714     return;
44715
44716   /* Values where only one field is non-constant are best loaded from
44717      the pool and overwritten via move later.  */
44718   if (n_var == 1)
44719     {
44720       if (all_const_zero
44721           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
44722                                                   XVECEXP (vals, 0, one_var),
44723                                                   one_var))
44724         return;
44725
44726       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
44727         return;
44728     }
44729
44730   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
44731 }
44732
44733 void
44734 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
44735 {
44736   machine_mode mode = GET_MODE (target);
44737   machine_mode inner_mode = GET_MODE_INNER (mode);
44738   machine_mode half_mode;
44739   bool use_vec_merge = false;
44740   rtx tmp;
44741   static rtx (*gen_extract[6][2]) (rtx, rtx)
44742     = {
44743         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
44744         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
44745         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
44746         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
44747         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
44748         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
44749       };
44750   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
44751     = {
44752         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
44753         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
44754         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
44755         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
44756         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
44757         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
44758       };
44759   int i, j, n;
44760   machine_mode mmode = VOIDmode;
44761   rtx (*gen_blendm) (rtx, rtx, rtx, rtx);
44762
44763   switch (mode)
44764     {
44765     case V2SFmode:
44766     case V2SImode:
44767       if (mmx_ok)
44768         {
44769           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
44770           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
44771           if (elt == 0)
44772             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
44773           else
44774             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
44775           emit_insn (gen_rtx_SET (target, tmp));
44776           return;
44777         }
44778       break;
44779
44780     case V2DImode:
44781       use_vec_merge = TARGET_SSE4_1 && TARGET_64BIT;
44782       if (use_vec_merge)
44783         break;
44784
44785       tmp = gen_reg_rtx (GET_MODE_INNER (mode));
44786       ix86_expand_vector_extract (false, tmp, target, 1 - elt);
44787       if (elt == 0)
44788         tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
44789       else
44790         tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
44791       emit_insn (gen_rtx_SET (target, tmp));
44792       return;
44793
44794     case V2DFmode:
44795       {
44796         rtx op0, op1;
44797
44798         /* For the two element vectors, we implement a VEC_CONCAT with
44799            the extraction of the other element.  */
44800
44801         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
44802         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
44803
44804         if (elt == 0)
44805           op0 = val, op1 = tmp;
44806         else
44807           op0 = tmp, op1 = val;
44808
44809         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
44810         emit_insn (gen_rtx_SET (target, tmp));
44811       }
44812       return;
44813
44814     case V4SFmode:
44815       use_vec_merge = TARGET_SSE4_1;
44816       if (use_vec_merge)
44817         break;
44818
44819       switch (elt)
44820         {
44821         case 0:
44822           use_vec_merge = true;
44823           break;
44824
44825         case 1:
44826           /* tmp = target = A B C D */
44827           tmp = copy_to_reg (target);
44828           /* target = A A B B */
44829           emit_insn (gen_vec_interleave_lowv4sf (target, target, target));
44830           /* target = X A B B */
44831           ix86_expand_vector_set (false, target, val, 0);
44832           /* target = A X C D  */
44833           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44834                                           const1_rtx, const0_rtx,
44835                                           GEN_INT (2+4), GEN_INT (3+4)));
44836           return;
44837
44838         case 2:
44839           /* tmp = target = A B C D */
44840           tmp = copy_to_reg (target);
44841           /* tmp = X B C D */
44842           ix86_expand_vector_set (false, tmp, val, 0);
44843           /* target = A B X D */
44844           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44845                                           const0_rtx, const1_rtx,
44846                                           GEN_INT (0+4), GEN_INT (3+4)));
44847           return;
44848
44849         case 3:
44850           /* tmp = target = A B C D */
44851           tmp = copy_to_reg (target);
44852           /* tmp = X B C D */
44853           ix86_expand_vector_set (false, tmp, val, 0);
44854           /* target = A B X D */
44855           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44856                                           const0_rtx, const1_rtx,
44857                                           GEN_INT (2+4), GEN_INT (0+4)));
44858           return;
44859
44860         default:
44861           gcc_unreachable ();
44862         }
44863       break;
44864
44865     case V4SImode:
44866       use_vec_merge = TARGET_SSE4_1;
44867       if (use_vec_merge)
44868         break;
44869
44870       /* Element 0 handled by vec_merge below.  */
44871       if (elt == 0)
44872         {
44873           use_vec_merge = true;
44874           break;
44875         }
44876
44877       if (TARGET_SSE2)
44878         {
44879           /* With SSE2, use integer shuffles to swap element 0 and ELT,
44880              store into element 0, then shuffle them back.  */
44881
44882           rtx order[4];
44883
44884           order[0] = GEN_INT (elt);
44885           order[1] = const1_rtx;
44886           order[2] = const2_rtx;
44887           order[3] = GEN_INT (3);
44888           order[elt] = const0_rtx;
44889
44890           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
44891                                         order[1], order[2], order[3]));
44892
44893           ix86_expand_vector_set (false, target, val, 0);
44894
44895           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
44896                                         order[1], order[2], order[3]));
44897         }
44898       else
44899         {
44900           /* For SSE1, we have to reuse the V4SF code.  */
44901           rtx t = gen_reg_rtx (V4SFmode);
44902           ix86_expand_vector_set (false, t, gen_lowpart (SFmode, val), elt);
44903           emit_move_insn (target, gen_lowpart (mode, t));
44904         }
44905       return;
44906
44907     case V8HImode:
44908       use_vec_merge = TARGET_SSE2;
44909       break;
44910     case V4HImode:
44911       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
44912       break;
44913
44914     case V16QImode:
44915       use_vec_merge = TARGET_SSE4_1;
44916       break;
44917
44918     case V8QImode:
44919       break;
44920
44921     case V32QImode:
44922       half_mode = V16QImode;
44923       j = 0;
44924       n = 16;
44925       goto half;
44926
44927     case V16HImode:
44928       half_mode = V8HImode;
44929       j = 1;
44930       n = 8;
44931       goto half;
44932
44933     case V8SImode:
44934       half_mode = V4SImode;
44935       j = 2;
44936       n = 4;
44937       goto half;
44938
44939     case V4DImode:
44940       half_mode = V2DImode;
44941       j = 3;
44942       n = 2;
44943       goto half;
44944
44945     case V8SFmode:
44946       half_mode = V4SFmode;
44947       j = 4;
44948       n = 4;
44949       goto half;
44950
44951     case V4DFmode:
44952       half_mode = V2DFmode;
44953       j = 5;
44954       n = 2;
44955       goto half;
44956
44957 half:
44958       /* Compute offset.  */
44959       i = elt / n;
44960       elt %= n;
44961
44962       gcc_assert (i <= 1);
44963
44964       /* Extract the half.  */
44965       tmp = gen_reg_rtx (half_mode);
44966       emit_insn (gen_extract[j][i] (tmp, target));
44967
44968       /* Put val in tmp at elt.  */
44969       ix86_expand_vector_set (false, tmp, val, elt);
44970
44971       /* Put it back.  */
44972       emit_insn (gen_insert[j][i] (target, target, tmp));
44973       return;
44974
44975     case V8DFmode:
44976       if (TARGET_AVX512F)
44977         {
44978           mmode = QImode;
44979           gen_blendm = gen_avx512f_blendmv8df;
44980         }
44981       break;
44982
44983     case V8DImode:
44984       if (TARGET_AVX512F)
44985         {
44986           mmode = QImode;
44987           gen_blendm = gen_avx512f_blendmv8di;
44988         }
44989       break;
44990
44991     case V16SFmode:
44992       if (TARGET_AVX512F)
44993         {
44994           mmode = HImode;
44995           gen_blendm = gen_avx512f_blendmv16sf;
44996         }
44997       break;
44998
44999     case V16SImode:
45000       if (TARGET_AVX512F)
45001         {
45002           mmode = HImode;
45003           gen_blendm = gen_avx512f_blendmv16si;
45004         }
45005       break;
45006
45007     case V32HImode:
45008       if (TARGET_AVX512F && TARGET_AVX512BW)
45009         {
45010           mmode = SImode;
45011           gen_blendm = gen_avx512bw_blendmv32hi;
45012         }
45013       break;
45014
45015     case V64QImode:
45016       if (TARGET_AVX512F && TARGET_AVX512BW)
45017         {
45018           mmode = DImode;
45019           gen_blendm = gen_avx512bw_blendmv64qi;
45020         }
45021       break;
45022
45023     default:
45024       break;
45025     }
45026
45027   if (mmode != VOIDmode)
45028     {
45029       tmp = gen_reg_rtx (mode);
45030       emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
45031       emit_insn (gen_blendm (target, tmp, target,
45032                              force_reg (mmode,
45033                                         gen_int_mode (1 << elt, mmode))));
45034     }
45035   else if (use_vec_merge)
45036     {
45037       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
45038       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
45039       emit_insn (gen_rtx_SET (target, tmp));
45040     }
45041   else
45042     {
45043       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
45044
45045       emit_move_insn (mem, target);
45046
45047       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
45048       emit_move_insn (tmp, val);
45049
45050       emit_move_insn (target, mem);
45051     }
45052 }
45053
45054 void
45055 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
45056 {
45057   machine_mode mode = GET_MODE (vec);
45058   machine_mode inner_mode = GET_MODE_INNER (mode);
45059   bool use_vec_extr = false;
45060   rtx tmp;
45061
45062   switch (mode)
45063     {
45064     case V2SImode:
45065     case V2SFmode:
45066       if (!mmx_ok)
45067         break;
45068       /* FALLTHRU */
45069
45070     case V2DFmode:
45071     case V2DImode:
45072       use_vec_extr = true;
45073       break;
45074
45075     case V4SFmode:
45076       use_vec_extr = TARGET_SSE4_1;
45077       if (use_vec_extr)
45078         break;
45079
45080       switch (elt)
45081         {
45082         case 0:
45083           tmp = vec;
45084           break;
45085
45086         case 1:
45087         case 3:
45088           tmp = gen_reg_rtx (mode);
45089           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
45090                                        GEN_INT (elt), GEN_INT (elt),
45091                                        GEN_INT (elt+4), GEN_INT (elt+4)));
45092           break;
45093
45094         case 2:
45095           tmp = gen_reg_rtx (mode);
45096           emit_insn (gen_vec_interleave_highv4sf (tmp, vec, vec));
45097           break;
45098
45099         default:
45100           gcc_unreachable ();
45101         }
45102       vec = tmp;
45103       use_vec_extr = true;
45104       elt = 0;
45105       break;
45106
45107     case V4SImode:
45108       use_vec_extr = TARGET_SSE4_1;
45109       if (use_vec_extr)
45110         break;
45111
45112       if (TARGET_SSE2)
45113         {
45114           switch (elt)
45115             {
45116             case 0:
45117               tmp = vec;
45118               break;
45119
45120             case 1:
45121             case 3:
45122               tmp = gen_reg_rtx (mode);
45123               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
45124                                             GEN_INT (elt), GEN_INT (elt),
45125                                             GEN_INT (elt), GEN_INT (elt)));
45126               break;
45127
45128             case 2:
45129               tmp = gen_reg_rtx (mode);
45130               emit_insn (gen_vec_interleave_highv4si (tmp, vec, vec));
45131               break;
45132
45133             default:
45134               gcc_unreachable ();
45135             }
45136           vec = tmp;
45137           use_vec_extr = true;
45138           elt = 0;
45139         }
45140       else
45141         {
45142           /* For SSE1, we have to reuse the V4SF code.  */
45143           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
45144                                       gen_lowpart (V4SFmode, vec), elt);
45145           return;
45146         }
45147       break;
45148
45149     case V8HImode:
45150       use_vec_extr = TARGET_SSE2;
45151       break;
45152     case V4HImode:
45153       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
45154       break;
45155
45156     case V16QImode:
45157       use_vec_extr = TARGET_SSE4_1;
45158       break;
45159
45160     case V8SFmode:
45161       if (TARGET_AVX)
45162         {
45163           tmp = gen_reg_rtx (V4SFmode);
45164           if (elt < 4)
45165             emit_insn (gen_vec_extract_lo_v8sf (tmp, vec));
45166           else
45167             emit_insn (gen_vec_extract_hi_v8sf (tmp, vec));
45168           ix86_expand_vector_extract (false, target, tmp, elt & 3);
45169           return;
45170         }
45171       break;
45172
45173     case V4DFmode:
45174       if (TARGET_AVX)
45175         {
45176           tmp = gen_reg_rtx (V2DFmode);
45177           if (elt < 2)
45178             emit_insn (gen_vec_extract_lo_v4df (tmp, vec));
45179           else
45180             emit_insn (gen_vec_extract_hi_v4df (tmp, vec));
45181           ix86_expand_vector_extract (false, target, tmp, elt & 1);
45182           return;
45183         }
45184       break;
45185
45186     case V32QImode:
45187       if (TARGET_AVX)
45188         {
45189           tmp = gen_reg_rtx (V16QImode);
45190           if (elt < 16)
45191             emit_insn (gen_vec_extract_lo_v32qi (tmp, vec));
45192           else
45193             emit_insn (gen_vec_extract_hi_v32qi (tmp, vec));
45194           ix86_expand_vector_extract (false, target, tmp, elt & 15);
45195           return;
45196         }
45197       break;
45198
45199     case V16HImode:
45200       if (TARGET_AVX)
45201         {
45202           tmp = gen_reg_rtx (V8HImode);
45203           if (elt < 8)
45204             emit_insn (gen_vec_extract_lo_v16hi (tmp, vec));
45205           else
45206             emit_insn (gen_vec_extract_hi_v16hi (tmp, vec));
45207           ix86_expand_vector_extract (false, target, tmp, elt & 7);
45208           return;
45209         }
45210       break;
45211
45212     case V8SImode:
45213       if (TARGET_AVX)
45214         {
45215           tmp = gen_reg_rtx (V4SImode);
45216           if (elt < 4)
45217             emit_insn (gen_vec_extract_lo_v8si (tmp, vec));
45218           else
45219             emit_insn (gen_vec_extract_hi_v8si (tmp, vec));
45220           ix86_expand_vector_extract (false, target, tmp, elt & 3);
45221           return;
45222         }
45223       break;
45224
45225     case V4DImode:
45226       if (TARGET_AVX)
45227         {
45228           tmp = gen_reg_rtx (V2DImode);
45229           if (elt < 2)
45230             emit_insn (gen_vec_extract_lo_v4di (tmp, vec));
45231           else
45232             emit_insn (gen_vec_extract_hi_v4di (tmp, vec));
45233           ix86_expand_vector_extract (false, target, tmp, elt & 1);
45234           return;
45235         }
45236       break;
45237
45238     case V32HImode:
45239       if (TARGET_AVX512BW)
45240         {
45241           tmp = gen_reg_rtx (V16HImode);
45242           if (elt < 16)
45243             emit_insn (gen_vec_extract_lo_v32hi (tmp, vec));
45244           else
45245             emit_insn (gen_vec_extract_hi_v32hi (tmp, vec));
45246           ix86_expand_vector_extract (false, target, tmp, elt & 15);
45247           return;
45248         }
45249       break;
45250
45251     case V64QImode:
45252       if (TARGET_AVX512BW)
45253         {
45254           tmp = gen_reg_rtx (V32QImode);
45255           if (elt < 32)
45256             emit_insn (gen_vec_extract_lo_v64qi (tmp, vec));
45257           else
45258             emit_insn (gen_vec_extract_hi_v64qi (tmp, vec));
45259           ix86_expand_vector_extract (false, target, tmp, elt & 31);
45260           return;
45261         }
45262       break;
45263
45264     case V16SFmode:
45265       tmp = gen_reg_rtx (V8SFmode);
45266       if (elt < 8)
45267         emit_insn (gen_vec_extract_lo_v16sf (tmp, vec));
45268       else
45269         emit_insn (gen_vec_extract_hi_v16sf (tmp, vec));
45270       ix86_expand_vector_extract (false, target, tmp, elt & 7);
45271       return;
45272
45273     case V8DFmode:
45274       tmp = gen_reg_rtx (V4DFmode);
45275       if (elt < 4)
45276         emit_insn (gen_vec_extract_lo_v8df (tmp, vec));
45277       else
45278         emit_insn (gen_vec_extract_hi_v8df (tmp, vec));
45279       ix86_expand_vector_extract (false, target, tmp, elt & 3);
45280       return;
45281
45282     case V16SImode:
45283       tmp = gen_reg_rtx (V8SImode);
45284       if (elt < 8)
45285         emit_insn (gen_vec_extract_lo_v16si (tmp, vec));
45286       else
45287         emit_insn (gen_vec_extract_hi_v16si (tmp, vec));
45288       ix86_expand_vector_extract (false, target, tmp, elt & 7);
45289       return;
45290
45291     case V8DImode:
45292       tmp = gen_reg_rtx (V4DImode);
45293       if (elt < 4)
45294         emit_insn (gen_vec_extract_lo_v8di (tmp, vec));
45295       else
45296         emit_insn (gen_vec_extract_hi_v8di (tmp, vec));
45297       ix86_expand_vector_extract (false, target, tmp, elt & 3);
45298       return;
45299
45300     case V8QImode:
45301       /* ??? Could extract the appropriate HImode element and shift.  */
45302     default:
45303       break;
45304     }
45305
45306   if (use_vec_extr)
45307     {
45308       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
45309       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
45310
45311       /* Let the rtl optimizers know about the zero extension performed.  */
45312       if (inner_mode == QImode || inner_mode == HImode)
45313         {
45314           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
45315           target = gen_lowpart (SImode, target);
45316         }
45317
45318       emit_insn (gen_rtx_SET (target, tmp));
45319     }
45320   else
45321     {
45322       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
45323
45324       emit_move_insn (mem, vec);
45325
45326       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
45327       emit_move_insn (target, tmp);
45328     }
45329 }
45330
45331 /* Generate code to copy vector bits i / 2 ... i - 1 from vector SRC
45332    to bits 0 ... i / 2 - 1 of vector DEST, which has the same mode.
45333    The upper bits of DEST are undefined, though they shouldn't cause
45334    exceptions (some bits from src or all zeros are ok).  */
45335
45336 static void
45337 emit_reduc_half (rtx dest, rtx src, int i)
45338 {
45339   rtx tem, d = dest;
45340   switch (GET_MODE (src))
45341     {
45342     case V4SFmode:
45343       if (i == 128)
45344         tem = gen_sse_movhlps (dest, src, src);
45345       else
45346         tem = gen_sse_shufps_v4sf (dest, src, src, const1_rtx, const1_rtx,
45347                                    GEN_INT (1 + 4), GEN_INT (1 + 4));
45348       break;
45349     case V2DFmode:
45350       tem = gen_vec_interleave_highv2df (dest, src, src);
45351       break;
45352     case V16QImode:
45353     case V8HImode:
45354     case V4SImode:
45355     case V2DImode:
45356       d = gen_reg_rtx (V1TImode);
45357       tem = gen_sse2_lshrv1ti3 (d, gen_lowpart (V1TImode, src),
45358                                 GEN_INT (i / 2));
45359       break;
45360     case V8SFmode:
45361       if (i == 256)
45362         tem = gen_avx_vperm2f128v8sf3 (dest, src, src, const1_rtx);
45363       else
45364         tem = gen_avx_shufps256 (dest, src, src,
45365                                  GEN_INT (i == 128 ? 2 + (3 << 2) : 1));
45366       break;
45367     case V4DFmode:
45368       if (i == 256)
45369         tem = gen_avx_vperm2f128v4df3 (dest, src, src, const1_rtx);
45370       else
45371         tem = gen_avx_shufpd256 (dest, src, src, const1_rtx);
45372       break;
45373     case V32QImode:
45374     case V16HImode:
45375     case V8SImode:
45376     case V4DImode:
45377       if (i == 256)
45378         {
45379           if (GET_MODE (dest) != V4DImode)
45380             d = gen_reg_rtx (V4DImode);
45381           tem = gen_avx2_permv2ti (d, gen_lowpart (V4DImode, src),
45382                                    gen_lowpart (V4DImode, src),
45383                                    const1_rtx);
45384         }
45385       else
45386         {
45387           d = gen_reg_rtx (V2TImode);
45388           tem = gen_avx2_lshrv2ti3 (d, gen_lowpart (V2TImode, src),
45389                                     GEN_INT (i / 2));
45390         }
45391       break;
45392     case V64QImode:
45393     case V32HImode:
45394     case V16SImode:
45395     case V16SFmode:
45396     case V8DImode:
45397     case V8DFmode:
45398       if (i > 128)
45399         tem = gen_avx512f_shuf_i32x4_1 (gen_lowpart (V16SImode, dest),
45400                                       gen_lowpart (V16SImode, src),
45401                                       gen_lowpart (V16SImode, src),
45402                                       GEN_INT (0x4 + (i == 512 ? 4 : 0)),
45403                                       GEN_INT (0x5 + (i == 512 ? 4 : 0)),
45404                                       GEN_INT (0x6 + (i == 512 ? 4 : 0)),
45405                                       GEN_INT (0x7 + (i == 512 ? 4 : 0)),
45406                                       GEN_INT (0xC), GEN_INT (0xD),
45407                                       GEN_INT (0xE), GEN_INT (0xF),
45408                                       GEN_INT (0x10), GEN_INT (0x11),
45409                                       GEN_INT (0x12), GEN_INT (0x13),
45410                                       GEN_INT (0x14), GEN_INT (0x15),
45411                                       GEN_INT (0x16), GEN_INT (0x17));
45412       else
45413         tem = gen_avx512f_pshufd_1 (gen_lowpart (V16SImode, dest),
45414                                    gen_lowpart (V16SImode, src),
45415                                    GEN_INT (i == 128 ? 0x2 : 0x1),
45416                                    GEN_INT (0x3),
45417                                    GEN_INT (0x3),
45418                                    GEN_INT (0x3),
45419                                    GEN_INT (i == 128 ? 0x6 : 0x5),
45420                                    GEN_INT (0x7),
45421                                    GEN_INT (0x7),
45422                                    GEN_INT (0x7),
45423                                    GEN_INT (i == 128 ? 0xA : 0x9),
45424                                    GEN_INT (0xB),
45425                                    GEN_INT (0xB),
45426                                    GEN_INT (0xB),
45427                                    GEN_INT (i == 128 ? 0xE : 0xD),
45428                                    GEN_INT (0xF),
45429                                    GEN_INT (0xF),
45430                                    GEN_INT (0xF));
45431       break;
45432     default:
45433       gcc_unreachable ();
45434     }
45435   emit_insn (tem);
45436   if (d != dest)
45437     emit_move_insn (dest, gen_lowpart (GET_MODE (dest), d));
45438 }
45439
45440 /* Expand a vector reduction.  FN is the binary pattern to reduce;
45441    DEST is the destination; IN is the input vector.  */
45442
45443 void
45444 ix86_expand_reduc (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
45445 {
45446   rtx half, dst, vec = in;
45447   machine_mode mode = GET_MODE (in);
45448   int i;
45449
45450   /* SSE4 has a special instruction for V8HImode UMIN reduction.  */
45451   if (TARGET_SSE4_1
45452       && mode == V8HImode
45453       && fn == gen_uminv8hi3)
45454     {
45455       emit_insn (gen_sse4_1_phminposuw (dest, in));
45456       return;
45457     }
45458
45459   for (i = GET_MODE_BITSIZE (mode);
45460        i > GET_MODE_BITSIZE (GET_MODE_INNER (mode));
45461        i >>= 1)
45462     {
45463       half = gen_reg_rtx (mode);
45464       emit_reduc_half (half, vec, i);
45465       if (i == GET_MODE_BITSIZE (GET_MODE_INNER (mode)) * 2)
45466         dst = dest;
45467       else
45468         dst = gen_reg_rtx (mode);
45469       emit_insn (fn (dst, half, vec));
45470       vec = dst;
45471     }
45472 }
45473 \f
45474 /* Target hook for scalar_mode_supported_p.  */
45475 static bool
45476 ix86_scalar_mode_supported_p (machine_mode mode)
45477 {
45478   if (DECIMAL_FLOAT_MODE_P (mode))
45479     return default_decimal_float_supported_p ();
45480   else if (mode == TFmode)
45481     return true;
45482   else
45483     return default_scalar_mode_supported_p (mode);
45484 }
45485
45486 /* Implements target hook vector_mode_supported_p.  */
45487 static bool
45488 ix86_vector_mode_supported_p (machine_mode mode)
45489 {
45490   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
45491     return true;
45492   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
45493     return true;
45494   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
45495     return true;
45496   if (TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
45497     return true;
45498   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
45499     return true;
45500   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
45501     return true;
45502   return false;
45503 }
45504
45505 /* Implement target hook libgcc_floating_mode_supported_p.  */
45506 static bool
45507 ix86_libgcc_floating_mode_supported_p (machine_mode mode)
45508 {
45509   switch (mode)
45510     {
45511     case SFmode:
45512     case DFmode:
45513     case XFmode:
45514       return true;
45515
45516     case TFmode:
45517 #ifdef IX86_NO_LIBGCC_TFMODE
45518       return false;
45519 #elif defined IX86_MAYBE_NO_LIBGCC_TFMODE
45520       return TARGET_LONG_DOUBLE_128;
45521 #else
45522       return true;
45523 #endif
45524
45525     default:
45526       return false;
45527     }
45528 }
45529
45530 /* Target hook for c_mode_for_suffix.  */
45531 static machine_mode
45532 ix86_c_mode_for_suffix (char suffix)
45533 {
45534   if (suffix == 'q')
45535     return TFmode;
45536   if (suffix == 'w')
45537     return XFmode;
45538
45539   return VOIDmode;
45540 }
45541
45542 /* Worker function for TARGET_MD_ASM_ADJUST.
45543
45544    We do this in the new i386 backend to maintain source compatibility
45545    with the old cc0-based compiler.  */
45546
45547 static rtx_insn *
45548 ix86_md_asm_adjust (vec<rtx> &/*outputs*/, vec<rtx> &/*inputs*/,
45549                     vec<const char *> &/*constraints*/,
45550                     vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs)
45551 {
45552   clobbers.safe_push (gen_rtx_REG (CCmode, FLAGS_REG));
45553   clobbers.safe_push (gen_rtx_REG (CCFPmode, FPSR_REG));
45554
45555   SET_HARD_REG_BIT (clobbered_regs, FLAGS_REG);
45556   SET_HARD_REG_BIT (clobbered_regs, FPSR_REG);
45557
45558   return NULL;
45559 }
45560
45561 /* Implements target vector targetm.asm.encode_section_info.  */
45562
45563 static void ATTRIBUTE_UNUSED
45564 ix86_encode_section_info (tree decl, rtx rtl, int first)
45565 {
45566   default_encode_section_info (decl, rtl, first);
45567
45568   if (ix86_in_large_data_p (decl))
45569     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
45570 }
45571
45572 /* Worker function for REVERSE_CONDITION.  */
45573
45574 enum rtx_code
45575 ix86_reverse_condition (enum rtx_code code, machine_mode mode)
45576 {
45577   return (mode != CCFPmode && mode != CCFPUmode
45578           ? reverse_condition (code)
45579           : reverse_condition_maybe_unordered (code));
45580 }
45581
45582 /* Output code to perform an x87 FP register move, from OPERANDS[1]
45583    to OPERANDS[0].  */
45584
45585 const char *
45586 output_387_reg_move (rtx insn, rtx *operands)
45587 {
45588   if (REG_P (operands[0]))
45589     {
45590       if (REG_P (operands[1])
45591           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
45592         {
45593           if (REGNO (operands[0]) == FIRST_STACK_REG)
45594             return output_387_ffreep (operands, 0);
45595           return "fstp\t%y0";
45596         }
45597       if (STACK_TOP_P (operands[0]))
45598         return "fld%Z1\t%y1";
45599       return "fst\t%y0";
45600     }
45601   else if (MEM_P (operands[0]))
45602     {
45603       gcc_assert (REG_P (operands[1]));
45604       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
45605         return "fstp%Z0\t%y0";
45606       else
45607         {
45608           /* There is no non-popping store to memory for XFmode.
45609              So if we need one, follow the store with a load.  */
45610           if (GET_MODE (operands[0]) == XFmode)
45611             return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
45612           else
45613             return "fst%Z0\t%y0";
45614         }
45615     }
45616   else
45617     gcc_unreachable();
45618 }
45619
45620 /* Output code to perform a conditional jump to LABEL, if C2 flag in
45621    FP status register is set.  */
45622
45623 void
45624 ix86_emit_fp_unordered_jump (rtx label)
45625 {
45626   rtx reg = gen_reg_rtx (HImode);
45627   rtx temp;
45628
45629   emit_insn (gen_x86_fnstsw_1 (reg));
45630
45631   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
45632     {
45633       emit_insn (gen_x86_sahf_1 (reg));
45634
45635       temp = gen_rtx_REG (CCmode, FLAGS_REG);
45636       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
45637     }
45638   else
45639     {
45640       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
45641
45642       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
45643       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
45644     }
45645
45646   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
45647                               gen_rtx_LABEL_REF (VOIDmode, label),
45648                               pc_rtx);
45649   temp = gen_rtx_SET (pc_rtx, temp);
45650
45651   emit_jump_insn (temp);
45652   predict_jump (REG_BR_PROB_BASE * 10 / 100);
45653 }
45654
45655 /* Output code to perform a log1p XFmode calculation.  */
45656
45657 void ix86_emit_i387_log1p (rtx op0, rtx op1)
45658 {
45659   rtx_code_label *label1 = gen_label_rtx ();
45660   rtx_code_label *label2 = gen_label_rtx ();
45661
45662   rtx tmp = gen_reg_rtx (XFmode);
45663   rtx tmp2 = gen_reg_rtx (XFmode);
45664   rtx test;
45665
45666   emit_insn (gen_absxf2 (tmp, op1));
45667   test = gen_rtx_GE (VOIDmode, tmp,
45668     CONST_DOUBLE_FROM_REAL_VALUE (
45669        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
45670        XFmode));
45671   emit_jump_insn (gen_cbranchxf4 (test, XEXP (test, 0), XEXP (test, 1), label1));
45672
45673   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
45674   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
45675   emit_jump (label2);
45676
45677   emit_label (label1);
45678   emit_move_insn (tmp, CONST1_RTX (XFmode));
45679   emit_insn (gen_addxf3 (tmp, op1, tmp));
45680   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
45681   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
45682
45683   emit_label (label2);
45684 }
45685
45686 /* Emit code for round calculation.  */
45687 void ix86_emit_i387_round (rtx op0, rtx op1)
45688 {
45689   machine_mode inmode = GET_MODE (op1);
45690   machine_mode outmode = GET_MODE (op0);
45691   rtx e1, e2, res, tmp, tmp1, half;
45692   rtx scratch = gen_reg_rtx (HImode);
45693   rtx flags = gen_rtx_REG (CCNOmode, FLAGS_REG);
45694   rtx_code_label *jump_label = gen_label_rtx ();
45695   rtx insn;
45696   rtx (*gen_abs) (rtx, rtx);
45697   rtx (*gen_neg) (rtx, rtx);
45698
45699   switch (inmode)
45700     {
45701     case SFmode:
45702       gen_abs = gen_abssf2;
45703       break;
45704     case DFmode:
45705       gen_abs = gen_absdf2;
45706       break;
45707     case XFmode:
45708       gen_abs = gen_absxf2;
45709       break;
45710     default:
45711       gcc_unreachable ();
45712     }
45713
45714   switch (outmode)
45715     {
45716     case SFmode:
45717       gen_neg = gen_negsf2;
45718       break;
45719     case DFmode:
45720       gen_neg = gen_negdf2;
45721       break;
45722     case XFmode:
45723       gen_neg = gen_negxf2;
45724       break;
45725     case HImode:
45726       gen_neg = gen_neghi2;
45727       break;
45728     case SImode:
45729       gen_neg = gen_negsi2;
45730       break;
45731     case DImode:
45732       gen_neg = gen_negdi2;
45733       break;
45734     default:
45735       gcc_unreachable ();
45736     }
45737
45738   e1 = gen_reg_rtx (inmode);
45739   e2 = gen_reg_rtx (inmode);
45740   res = gen_reg_rtx (outmode);
45741
45742   half = CONST_DOUBLE_FROM_REAL_VALUE (dconsthalf, inmode);
45743
45744   /* round(a) = sgn(a) * floor(fabs(a) + 0.5) */
45745
45746   /* scratch = fxam(op1) */
45747   emit_insn (gen_rtx_SET (scratch,
45748                           gen_rtx_UNSPEC (HImode, gen_rtvec (1, op1),
45749                                           UNSPEC_FXAM)));
45750   /* e1 = fabs(op1) */
45751   emit_insn (gen_abs (e1, op1));
45752
45753   /* e2 = e1 + 0.5 */
45754   half = force_reg (inmode, half);
45755   emit_insn (gen_rtx_SET (e2, gen_rtx_PLUS (inmode, e1, half)));
45756
45757   /* res = floor(e2) */
45758   if (inmode != XFmode)
45759     {
45760       tmp1 = gen_reg_rtx (XFmode);
45761
45762       emit_insn (gen_rtx_SET (tmp1, gen_rtx_FLOAT_EXTEND (XFmode, e2)));
45763     }
45764   else
45765     tmp1 = e2;
45766
45767   switch (outmode)
45768     {
45769     case SFmode:
45770     case DFmode:
45771       {
45772         rtx tmp0 = gen_reg_rtx (XFmode);
45773
45774         emit_insn (gen_frndintxf2_floor (tmp0, tmp1));
45775
45776         emit_insn (gen_rtx_SET (res,
45777                                 gen_rtx_UNSPEC (outmode, gen_rtvec (1, tmp0),
45778                                                 UNSPEC_TRUNC_NOOP)));
45779       }
45780       break;
45781     case XFmode:
45782       emit_insn (gen_frndintxf2_floor (res, tmp1));
45783       break;
45784     case HImode:
45785       emit_insn (gen_lfloorxfhi2 (res, tmp1));
45786       break;
45787     case SImode:
45788       emit_insn (gen_lfloorxfsi2 (res, tmp1));
45789       break;
45790     case DImode:
45791       emit_insn (gen_lfloorxfdi2 (res, tmp1));
45792         break;
45793     default:
45794       gcc_unreachable ();
45795     }
45796
45797   /* flags = signbit(a) */
45798   emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x02)));
45799
45800   /* if (flags) then res = -res */
45801   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
45802                               gen_rtx_EQ (VOIDmode, flags, const0_rtx),
45803                               gen_rtx_LABEL_REF (VOIDmode, jump_label),
45804                               pc_rtx);
45805   insn = emit_jump_insn (gen_rtx_SET (pc_rtx, tmp));
45806   predict_jump (REG_BR_PROB_BASE * 50 / 100);
45807   JUMP_LABEL (insn) = jump_label;
45808
45809   emit_insn (gen_neg (res, res));
45810
45811   emit_label (jump_label);
45812   LABEL_NUSES (jump_label) = 1;
45813
45814   emit_move_insn (op0, res);
45815 }
45816
45817 /* Output code to perform a Newton-Rhapson approximation of a single precision
45818    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
45819
45820 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, machine_mode mode)
45821 {
45822   rtx x0, x1, e0, e1;
45823
45824   x0 = gen_reg_rtx (mode);
45825   e0 = gen_reg_rtx (mode);
45826   e1 = gen_reg_rtx (mode);
45827   x1 = gen_reg_rtx (mode);
45828
45829   /* a / b = a * ((rcp(b) + rcp(b)) - (b * rcp(b) * rcp (b))) */
45830
45831   b = force_reg (mode, b);
45832
45833   /* x0 = rcp(b) estimate */
45834   if (mode == V16SFmode || mode == V8DFmode)
45835     emit_insn (gen_rtx_SET (x0, gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
45836                                                 UNSPEC_RCP14)));
45837   else
45838     emit_insn (gen_rtx_SET (x0, gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
45839                                                 UNSPEC_RCP)));
45840
45841   /* e0 = x0 * b */
45842   emit_insn (gen_rtx_SET (e0, gen_rtx_MULT (mode, x0, b)));
45843
45844   /* e0 = x0 * e0 */
45845   emit_insn (gen_rtx_SET (e0, gen_rtx_MULT (mode, x0, e0)));
45846
45847   /* e1 = x0 + x0 */
45848   emit_insn (gen_rtx_SET (e1, gen_rtx_PLUS (mode, x0, x0)));
45849
45850   /* x1 = e1 - e0 */
45851   emit_insn (gen_rtx_SET (x1, gen_rtx_MINUS (mode, e1, e0)));
45852
45853   /* res = a * x1 */
45854   emit_insn (gen_rtx_SET (res, gen_rtx_MULT (mode, a, x1)));
45855 }
45856
45857 /* Output code to perform a Newton-Rhapson approximation of a
45858    single precision floating point [reciprocal] square root.  */
45859
45860 void ix86_emit_swsqrtsf (rtx res, rtx a, machine_mode mode,
45861                          bool recip)
45862 {
45863   rtx x0, e0, e1, e2, e3, mthree, mhalf;
45864   REAL_VALUE_TYPE r;
45865   int unspec;
45866
45867   x0 = gen_reg_rtx (mode);
45868   e0 = gen_reg_rtx (mode);
45869   e1 = gen_reg_rtx (mode);
45870   e2 = gen_reg_rtx (mode);
45871   e3 = gen_reg_rtx (mode);
45872
45873   real_from_integer (&r, VOIDmode, -3, SIGNED);
45874   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
45875
45876   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
45877   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
45878   unspec = UNSPEC_RSQRT;
45879
45880   if (VECTOR_MODE_P (mode))
45881     {
45882       mthree = ix86_build_const_vector (mode, true, mthree);
45883       mhalf = ix86_build_const_vector (mode, true, mhalf);
45884       /* There is no 512-bit rsqrt.  There is however rsqrt14.  */
45885       if (GET_MODE_SIZE (mode) == 64)
45886         unspec = UNSPEC_RSQRT14;
45887     }
45888
45889   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
45890      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
45891
45892   a = force_reg (mode, a);
45893
45894   /* x0 = rsqrt(a) estimate */
45895   emit_insn (gen_rtx_SET (x0, gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
45896                                               unspec)));
45897
45898   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
45899   if (!recip)
45900     {
45901       rtx zero, mask;
45902
45903       zero = gen_reg_rtx (mode);
45904       mask = gen_reg_rtx (mode);
45905
45906       zero = force_reg (mode, CONST0_RTX(mode));
45907
45908       /* Handle masked compare.  */
45909       if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
45910         {
45911           mask = gen_reg_rtx (HImode);
45912           /* Imm value 0x4 corresponds to not-equal comparison.  */
45913           emit_insn (gen_avx512f_cmpv16sf3 (mask, zero, a, GEN_INT (0x4)));
45914           emit_insn (gen_avx512f_blendmv16sf (x0, zero, x0, mask));
45915         }
45916       else
45917         {
45918           emit_insn (gen_rtx_SET (mask, gen_rtx_NE (mode, zero, a)));
45919
45920           emit_insn (gen_rtx_SET (x0, gen_rtx_AND (mode, x0, mask)));
45921         }
45922     }
45923
45924   /* e0 = x0 * a */
45925   emit_insn (gen_rtx_SET (e0, gen_rtx_MULT (mode, x0, a)));
45926   /* e1 = e0 * x0 */
45927   emit_insn (gen_rtx_SET (e1, gen_rtx_MULT (mode, e0, x0)));
45928
45929   /* e2 = e1 - 3. */
45930   mthree = force_reg (mode, mthree);
45931   emit_insn (gen_rtx_SET (e2, gen_rtx_PLUS (mode, e1, mthree)));
45932
45933   mhalf = force_reg (mode, mhalf);
45934   if (recip)
45935     /* e3 = -.5 * x0 */
45936     emit_insn (gen_rtx_SET (e3, gen_rtx_MULT (mode, x0, mhalf)));
45937   else
45938     /* e3 = -.5 * e0 */
45939     emit_insn (gen_rtx_SET (e3, gen_rtx_MULT (mode, e0, mhalf)));
45940   /* ret = e2 * e3 */
45941   emit_insn (gen_rtx_SET (res, gen_rtx_MULT (mode, e2, e3)));
45942 }
45943
45944 #ifdef TARGET_SOLARIS
45945 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
45946
45947 static void
45948 i386_solaris_elf_named_section (const char *name, unsigned int flags,
45949                                 tree decl)
45950 {
45951   /* With Binutils 2.15, the "@unwind" marker must be specified on
45952      every occurrence of the ".eh_frame" section, not just the first
45953      one.  */
45954   if (TARGET_64BIT
45955       && strcmp (name, ".eh_frame") == 0)
45956     {
45957       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
45958                flags & SECTION_WRITE ? "aw" : "a");
45959       return;
45960     }
45961
45962 #ifndef USE_GAS
45963   if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
45964     {
45965       solaris_elf_asm_comdat_section (name, flags, decl);
45966       return;
45967     }
45968 #endif
45969
45970   default_elf_asm_named_section (name, flags, decl);
45971 }
45972 #endif /* TARGET_SOLARIS */
45973
45974 /* Return the mangling of TYPE if it is an extended fundamental type.  */
45975
45976 static const char *
45977 ix86_mangle_type (const_tree type)
45978 {
45979   type = TYPE_MAIN_VARIANT (type);
45980
45981   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
45982       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
45983     return NULL;
45984
45985   switch (TYPE_MODE (type))
45986     {
45987     case TFmode:
45988       /* __float128 is "g".  */
45989       return "g";
45990     case XFmode:
45991       /* "long double" or __float80 is "e".  */
45992       return "e";
45993     default:
45994       return NULL;
45995     }
45996 }
45997
45998 /* For 32-bit code we can save PIC register setup by using
45999    __stack_chk_fail_local hidden function instead of calling
46000    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
46001    register, so it is better to call __stack_chk_fail directly.  */
46002
46003 static tree ATTRIBUTE_UNUSED
46004 ix86_stack_protect_fail (void)
46005 {
46006   return TARGET_64BIT
46007          ? default_external_stack_protect_fail ()
46008          : default_hidden_stack_protect_fail ();
46009 }
46010
46011 /* Select a format to encode pointers in exception handling data.  CODE
46012    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
46013    true if the symbol may be affected by dynamic relocations.
46014
46015    ??? All x86 object file formats are capable of representing this.
46016    After all, the relocation needed is the same as for the call insn.
46017    Whether or not a particular assembler allows us to enter such, I
46018    guess we'll have to see.  */
46019 int
46020 asm_preferred_eh_data_format (int code, int global)
46021 {
46022   if (flag_pic)
46023     {
46024       int type = DW_EH_PE_sdata8;
46025       if (!TARGET_64BIT
46026           || ix86_cmodel == CM_SMALL_PIC
46027           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
46028         type = DW_EH_PE_sdata4;
46029       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
46030     }
46031   if (ix86_cmodel == CM_SMALL
46032       || (ix86_cmodel == CM_MEDIUM && code))
46033     return DW_EH_PE_udata4;
46034   return DW_EH_PE_absptr;
46035 }
46036 \f
46037 /* Expand copysign from SIGN to the positive value ABS_VALUE
46038    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
46039    the sign-bit.  */
46040 static void
46041 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
46042 {
46043   machine_mode mode = GET_MODE (sign);
46044   rtx sgn = gen_reg_rtx (mode);
46045   if (mask == NULL_RTX)
46046     {
46047       machine_mode vmode;
46048
46049       if (mode == SFmode)
46050         vmode = V4SFmode;
46051       else if (mode == DFmode)
46052         vmode = V2DFmode;
46053       else
46054         vmode = mode;
46055
46056       mask = ix86_build_signbit_mask (vmode, VECTOR_MODE_P (mode), false);
46057       if (!VECTOR_MODE_P (mode))
46058         {
46059           /* We need to generate a scalar mode mask in this case.  */
46060           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
46061           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
46062           mask = gen_reg_rtx (mode);
46063           emit_insn (gen_rtx_SET (mask, tmp));
46064         }
46065     }
46066   else
46067     mask = gen_rtx_NOT (mode, mask);
46068   emit_insn (gen_rtx_SET (sgn, gen_rtx_AND (mode, mask, sign)));
46069   emit_insn (gen_rtx_SET (result, gen_rtx_IOR (mode, abs_value, sgn)));
46070 }
46071
46072 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
46073    mask for masking out the sign-bit is stored in *SMASK, if that is
46074    non-null.  */
46075 static rtx
46076 ix86_expand_sse_fabs (rtx op0, rtx *smask)
46077 {
46078   machine_mode vmode, mode = GET_MODE (op0);
46079   rtx xa, mask;
46080
46081   xa = gen_reg_rtx (mode);
46082   if (mode == SFmode)
46083     vmode = V4SFmode;
46084   else if (mode == DFmode)
46085     vmode = V2DFmode;
46086   else
46087     vmode = mode;
46088   mask = ix86_build_signbit_mask (vmode, VECTOR_MODE_P (mode), true);
46089   if (!VECTOR_MODE_P (mode))
46090     {
46091       /* We need to generate a scalar mode mask in this case.  */
46092       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
46093       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
46094       mask = gen_reg_rtx (mode);
46095       emit_insn (gen_rtx_SET (mask, tmp));
46096     }
46097   emit_insn (gen_rtx_SET (xa, gen_rtx_AND (mode, op0, mask)));
46098
46099   if (smask)
46100     *smask = mask;
46101
46102   return xa;
46103 }
46104
46105 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
46106    swapping the operands if SWAP_OPERANDS is true.  The expanded
46107    code is a forward jump to a newly created label in case the
46108    comparison is true.  The generated label rtx is returned.  */
46109 static rtx_code_label *
46110 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
46111                                   bool swap_operands)
46112 {
46113   machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
46114   rtx_code_label *label;
46115   rtx tmp;
46116
46117   if (swap_operands)
46118     std::swap (op0, op1);
46119
46120   label = gen_label_rtx ();
46121   tmp = gen_rtx_REG (fpcmp_mode, FLAGS_REG);
46122   emit_insn (gen_rtx_SET (tmp, gen_rtx_COMPARE (fpcmp_mode, op0, op1)));
46123   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
46124   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
46125                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
46126   tmp = emit_jump_insn (gen_rtx_SET (pc_rtx, tmp));
46127   JUMP_LABEL (tmp) = label;
46128
46129   return label;
46130 }
46131
46132 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
46133    using comparison code CODE.  Operands are swapped for the comparison if
46134    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
46135 static rtx
46136 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
46137                               bool swap_operands)
46138 {
46139   rtx (*insn)(rtx, rtx, rtx, rtx);
46140   machine_mode mode = GET_MODE (op0);
46141   rtx mask = gen_reg_rtx (mode);
46142
46143   if (swap_operands)
46144     std::swap (op0, op1);
46145
46146   insn = mode == DFmode ? gen_setcc_df_sse : gen_setcc_sf_sse;
46147
46148   emit_insn (insn (mask, op0, op1,
46149                    gen_rtx_fmt_ee (code, mode, op0, op1)));
46150   return mask;
46151 }
46152
46153 /* Generate and return a rtx of mode MODE for 2**n where n is the number
46154    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
46155 static rtx
46156 ix86_gen_TWO52 (machine_mode mode)
46157 {
46158   REAL_VALUE_TYPE TWO52r;
46159   rtx TWO52;
46160
46161   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
46162   TWO52 = const_double_from_real_value (TWO52r, mode);
46163   TWO52 = force_reg (mode, TWO52);
46164
46165   return TWO52;
46166 }
46167
46168 /* Expand SSE sequence for computing lround from OP1 storing
46169    into OP0.  */
46170 void
46171 ix86_expand_lround (rtx op0, rtx op1)
46172 {
46173   /* C code for the stuff we're doing below:
46174        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
46175        return (long)tmp;
46176    */
46177   machine_mode mode = GET_MODE (op1);
46178   const struct real_format *fmt;
46179   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46180   rtx adj;
46181
46182   /* load nextafter (0.5, 0.0) */
46183   fmt = REAL_MODE_FORMAT (mode);
46184   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46185   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46186
46187   /* adj = copysign (0.5, op1) */
46188   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
46189   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
46190
46191   /* adj = op1 + adj */
46192   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
46193
46194   /* op0 = (imode)adj */
46195   expand_fix (op0, adj, 0);
46196 }
46197
46198 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
46199    into OPERAND0.  */
46200 void
46201 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
46202 {
46203   /* C code for the stuff we're doing below (for do_floor):
46204         xi = (long)op1;
46205         xi -= (double)xi > op1 ? 1 : 0;
46206         return xi;
46207    */
46208   machine_mode fmode = GET_MODE (op1);
46209   machine_mode imode = GET_MODE (op0);
46210   rtx ireg, freg, tmp;
46211   rtx_code_label *label;
46212
46213   /* reg = (long)op1 */
46214   ireg = gen_reg_rtx (imode);
46215   expand_fix (ireg, op1, 0);
46216
46217   /* freg = (double)reg */
46218   freg = gen_reg_rtx (fmode);
46219   expand_float (freg, ireg, 0);
46220
46221   /* ireg = (freg > op1) ? ireg - 1 : ireg */
46222   label = ix86_expand_sse_compare_and_jump (UNLE,
46223                                             freg, op1, !do_floor);
46224   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
46225                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
46226   emit_move_insn (ireg, tmp);
46227
46228   emit_label (label);
46229   LABEL_NUSES (label) = 1;
46230
46231   emit_move_insn (op0, ireg);
46232 }
46233
46234 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
46235    result in OPERAND0.  */
46236 void
46237 ix86_expand_rint (rtx operand0, rtx operand1)
46238 {
46239   /* C code for the stuff we're doing below:
46240         xa = fabs (operand1);
46241         if (!isless (xa, 2**52))
46242           return operand1;
46243         xa = xa + 2**52 - 2**52;
46244         return copysign (xa, operand1);
46245    */
46246   machine_mode mode = GET_MODE (operand0);
46247   rtx res, xa, TWO52, mask;
46248   rtx_code_label *label;
46249
46250   res = gen_reg_rtx (mode);
46251   emit_move_insn (res, operand1);
46252
46253   /* xa = abs (operand1) */
46254   xa = ix86_expand_sse_fabs (res, &mask);
46255
46256   /* if (!isless (xa, TWO52)) goto label; */
46257   TWO52 = ix86_gen_TWO52 (mode);
46258   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46259
46260   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46261   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
46262
46263   ix86_sse_copysign_to_positive (res, xa, res, mask);
46264
46265   emit_label (label);
46266   LABEL_NUSES (label) = 1;
46267
46268   emit_move_insn (operand0, res);
46269 }
46270
46271 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
46272    into OPERAND0.  */
46273 void
46274 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
46275 {
46276   /* C code for the stuff we expand below.
46277         double xa = fabs (x), x2;
46278         if (!isless (xa, TWO52))
46279           return x;
46280         xa = xa + TWO52 - TWO52;
46281         x2 = copysign (xa, x);
46282      Compensate.  Floor:
46283         if (x2 > x)
46284           x2 -= 1;
46285      Compensate.  Ceil:
46286         if (x2 < x)
46287           x2 -= -1;
46288         return x2;
46289    */
46290   machine_mode mode = GET_MODE (operand0);
46291   rtx xa, TWO52, tmp, one, res, mask;
46292   rtx_code_label *label;
46293
46294   TWO52 = ix86_gen_TWO52 (mode);
46295
46296   /* Temporary for holding the result, initialized to the input
46297      operand to ease control flow.  */
46298   res = gen_reg_rtx (mode);
46299   emit_move_insn (res, operand1);
46300
46301   /* xa = abs (operand1) */
46302   xa = ix86_expand_sse_fabs (res, &mask);
46303
46304   /* if (!isless (xa, TWO52)) goto label; */
46305   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46306
46307   /* xa = xa + TWO52 - TWO52; */
46308   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46309   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
46310
46311   /* xa = copysign (xa, operand1) */
46312   ix86_sse_copysign_to_positive (xa, xa, res, mask);
46313
46314   /* generate 1.0 or -1.0 */
46315   one = force_reg (mode,
46316                    const_double_from_real_value (do_floor
46317                                                  ? dconst1 : dconstm1, mode));
46318
46319   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
46320   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
46321   emit_insn (gen_rtx_SET (tmp, gen_rtx_AND (mode, one, tmp)));
46322   /* We always need to subtract here to preserve signed zero.  */
46323   tmp = expand_simple_binop (mode, MINUS,
46324                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46325   emit_move_insn (res, tmp);
46326
46327   emit_label (label);
46328   LABEL_NUSES (label) = 1;
46329
46330   emit_move_insn (operand0, res);
46331 }
46332
46333 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
46334    into OPERAND0.  */
46335 void
46336 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
46337 {
46338   /* C code for the stuff we expand below.
46339         double xa = fabs (x), x2;
46340         if (!isless (xa, TWO52))
46341           return x;
46342         x2 = (double)(long)x;
46343      Compensate.  Floor:
46344         if (x2 > x)
46345           x2 -= 1;
46346      Compensate.  Ceil:
46347         if (x2 < x)
46348           x2 += 1;
46349         if (HONOR_SIGNED_ZEROS (mode))
46350           return copysign (x2, x);
46351         return x2;
46352    */
46353   machine_mode mode = GET_MODE (operand0);
46354   rtx xa, xi, TWO52, tmp, one, res, mask;
46355   rtx_code_label *label;
46356
46357   TWO52 = ix86_gen_TWO52 (mode);
46358
46359   /* Temporary for holding the result, initialized to the input
46360      operand to ease control flow.  */
46361   res = gen_reg_rtx (mode);
46362   emit_move_insn (res, operand1);
46363
46364   /* xa = abs (operand1) */
46365   xa = ix86_expand_sse_fabs (res, &mask);
46366
46367   /* if (!isless (xa, TWO52)) goto label; */
46368   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46369
46370   /* xa = (double)(long)x */
46371   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46372   expand_fix (xi, res, 0);
46373   expand_float (xa, xi, 0);
46374
46375   /* generate 1.0 */
46376   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
46377
46378   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
46379   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
46380   emit_insn (gen_rtx_SET (tmp, gen_rtx_AND (mode, one, tmp)));
46381   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
46382                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46383   emit_move_insn (res, tmp);
46384
46385   if (HONOR_SIGNED_ZEROS (mode))
46386     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
46387
46388   emit_label (label);
46389   LABEL_NUSES (label) = 1;
46390
46391   emit_move_insn (operand0, res);
46392 }
46393
46394 /* Expand SSE sequence for computing round from OPERAND1 storing
46395    into OPERAND0.  Sequence that works without relying on DImode truncation
46396    via cvttsd2siq that is only available on 64bit targets.  */
46397 void
46398 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
46399 {
46400   /* C code for the stuff we expand below.
46401         double xa = fabs (x), xa2, x2;
46402         if (!isless (xa, TWO52))
46403           return x;
46404      Using the absolute value and copying back sign makes
46405      -0.0 -> -0.0 correct.
46406         xa2 = xa + TWO52 - TWO52;
46407      Compensate.
46408         dxa = xa2 - xa;
46409         if (dxa <= -0.5)
46410           xa2 += 1;
46411         else if (dxa > 0.5)
46412           xa2 -= 1;
46413         x2 = copysign (xa2, x);
46414         return x2;
46415    */
46416   machine_mode mode = GET_MODE (operand0);
46417   rtx xa, xa2, dxa, TWO52, tmp, half, mhalf, one, res, mask;
46418   rtx_code_label *label;
46419
46420   TWO52 = ix86_gen_TWO52 (mode);
46421
46422   /* Temporary for holding the result, initialized to the input
46423      operand to ease control flow.  */
46424   res = gen_reg_rtx (mode);
46425   emit_move_insn (res, operand1);
46426
46427   /* xa = abs (operand1) */
46428   xa = ix86_expand_sse_fabs (res, &mask);
46429
46430   /* if (!isless (xa, TWO52)) goto label; */
46431   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46432
46433   /* xa2 = xa + TWO52 - TWO52; */
46434   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46435   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
46436
46437   /* dxa = xa2 - xa; */
46438   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
46439
46440   /* generate 0.5, 1.0 and -0.5 */
46441   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
46442   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
46443   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
46444                                0, OPTAB_DIRECT);
46445
46446   /* Compensate.  */
46447   tmp = gen_reg_rtx (mode);
46448   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
46449   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
46450   emit_insn (gen_rtx_SET (tmp, gen_rtx_AND (mode, one, tmp)));
46451   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46452   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
46453   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
46454   emit_insn (gen_rtx_SET (tmp, gen_rtx_AND (mode, one, tmp)));
46455   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46456
46457   /* res = copysign (xa2, operand1) */
46458   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
46459
46460   emit_label (label);
46461   LABEL_NUSES (label) = 1;
46462
46463   emit_move_insn (operand0, res);
46464 }
46465
46466 /* Expand SSE sequence for computing trunc from OPERAND1 storing
46467    into OPERAND0.  */
46468 void
46469 ix86_expand_trunc (rtx operand0, rtx operand1)
46470 {
46471   /* C code for SSE variant we expand below.
46472         double xa = fabs (x), x2;
46473         if (!isless (xa, TWO52))
46474           return x;
46475         x2 = (double)(long)x;
46476         if (HONOR_SIGNED_ZEROS (mode))
46477           return copysign (x2, x);
46478         return x2;
46479    */
46480   machine_mode mode = GET_MODE (operand0);
46481   rtx xa, xi, TWO52, res, mask;
46482   rtx_code_label *label;
46483
46484   TWO52 = ix86_gen_TWO52 (mode);
46485
46486   /* Temporary for holding the result, initialized to the input
46487      operand to ease control flow.  */
46488   res = gen_reg_rtx (mode);
46489   emit_move_insn (res, operand1);
46490
46491   /* xa = abs (operand1) */
46492   xa = ix86_expand_sse_fabs (res, &mask);
46493
46494   /* if (!isless (xa, TWO52)) goto label; */
46495   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46496
46497   /* x = (double)(long)x */
46498   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46499   expand_fix (xi, res, 0);
46500   expand_float (res, xi, 0);
46501
46502   if (HONOR_SIGNED_ZEROS (mode))
46503     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
46504
46505   emit_label (label);
46506   LABEL_NUSES (label) = 1;
46507
46508   emit_move_insn (operand0, res);
46509 }
46510
46511 /* Expand SSE sequence for computing trunc from OPERAND1 storing
46512    into OPERAND0.  */
46513 void
46514 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
46515 {
46516   machine_mode mode = GET_MODE (operand0);
46517   rtx xa, mask, TWO52, one, res, smask, tmp;
46518   rtx_code_label *label;
46519
46520   /* C code for SSE variant we expand below.
46521         double xa = fabs (x), x2;
46522         if (!isless (xa, TWO52))
46523           return x;
46524         xa2 = xa + TWO52 - TWO52;
46525      Compensate:
46526         if (xa2 > xa)
46527           xa2 -= 1.0;
46528         x2 = copysign (xa2, x);
46529         return x2;
46530    */
46531
46532   TWO52 = ix86_gen_TWO52 (mode);
46533
46534   /* Temporary for holding the result, initialized to the input
46535      operand to ease control flow.  */
46536   res = gen_reg_rtx (mode);
46537   emit_move_insn (res, operand1);
46538
46539   /* xa = abs (operand1) */
46540   xa = ix86_expand_sse_fabs (res, &smask);
46541
46542   /* if (!isless (xa, TWO52)) goto label; */
46543   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46544
46545   /* res = xa + TWO52 - TWO52; */
46546   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46547   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
46548   emit_move_insn (res, tmp);
46549
46550   /* generate 1.0 */
46551   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
46552
46553   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
46554   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
46555   emit_insn (gen_rtx_SET (mask, gen_rtx_AND (mode, mask, one)));
46556   tmp = expand_simple_binop (mode, MINUS,
46557                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
46558   emit_move_insn (res, tmp);
46559
46560   /* res = copysign (res, operand1) */
46561   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
46562
46563   emit_label (label);
46564   LABEL_NUSES (label) = 1;
46565
46566   emit_move_insn (operand0, res);
46567 }
46568
46569 /* Expand SSE sequence for computing round from OPERAND1 storing
46570    into OPERAND0.  */
46571 void
46572 ix86_expand_round (rtx operand0, rtx operand1)
46573 {
46574   /* C code for the stuff we're doing below:
46575         double xa = fabs (x);
46576         if (!isless (xa, TWO52))
46577           return x;
46578         xa = (double)(long)(xa + nextafter (0.5, 0.0));
46579         return copysign (xa, x);
46580    */
46581   machine_mode mode = GET_MODE (operand0);
46582   rtx res, TWO52, xa, xi, half, mask;
46583   rtx_code_label *label;
46584   const struct real_format *fmt;
46585   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46586
46587   /* Temporary for holding the result, initialized to the input
46588      operand to ease control flow.  */
46589   res = gen_reg_rtx (mode);
46590   emit_move_insn (res, operand1);
46591
46592   TWO52 = ix86_gen_TWO52 (mode);
46593   xa = ix86_expand_sse_fabs (res, &mask);
46594   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46595
46596   /* load nextafter (0.5, 0.0) */
46597   fmt = REAL_MODE_FORMAT (mode);
46598   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46599   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46600
46601   /* xa = xa + 0.5 */
46602   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
46603   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
46604
46605   /* xa = (double)(int64_t)xa */
46606   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46607   expand_fix (xi, xa, 0);
46608   expand_float (xa, xi, 0);
46609
46610   /* res = copysign (xa, operand1) */
46611   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
46612
46613   emit_label (label);
46614   LABEL_NUSES (label) = 1;
46615
46616   emit_move_insn (operand0, res);
46617 }
46618
46619 /* Expand SSE sequence for computing round
46620    from OP1 storing into OP0 using sse4 round insn.  */
46621 void
46622 ix86_expand_round_sse4 (rtx op0, rtx op1)
46623 {
46624   machine_mode mode = GET_MODE (op0);
46625   rtx e1, e2, res, half;
46626   const struct real_format *fmt;
46627   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46628   rtx (*gen_copysign) (rtx, rtx, rtx);
46629   rtx (*gen_round) (rtx, rtx, rtx);
46630
46631   switch (mode)
46632     {
46633     case SFmode:
46634       gen_copysign = gen_copysignsf3;
46635       gen_round = gen_sse4_1_roundsf2;
46636       break;
46637     case DFmode:
46638       gen_copysign = gen_copysigndf3;
46639       gen_round = gen_sse4_1_rounddf2;
46640       break;
46641     default:
46642       gcc_unreachable ();
46643     }
46644
46645   /* round (a) = trunc (a + copysign (0.5, a)) */
46646
46647   /* load nextafter (0.5, 0.0) */
46648   fmt = REAL_MODE_FORMAT (mode);
46649   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46650   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46651   half = const_double_from_real_value (pred_half, mode);
46652
46653   /* e1 = copysign (0.5, op1) */
46654   e1 = gen_reg_rtx (mode);
46655   emit_insn (gen_copysign (e1, half, op1));
46656
46657   /* e2 = op1 + e1 */
46658   e2 = expand_simple_binop (mode, PLUS, op1, e1, NULL_RTX, 0, OPTAB_DIRECT);
46659
46660   /* res = trunc (e2) */
46661   res = gen_reg_rtx (mode);
46662   emit_insn (gen_round (res, e2, GEN_INT (ROUND_TRUNC)));
46663
46664   emit_move_insn (op0, res);
46665 }
46666 \f
46667
46668 /* Table of valid machine attributes.  */
46669 static const struct attribute_spec ix86_attribute_table[] =
46670 {
46671   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
46672        affects_type_identity } */
46673   /* Stdcall attribute says callee is responsible for popping arguments
46674      if they are not variable.  */
46675   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46676     true },
46677   /* Fastcall attribute says callee is responsible for popping arguments
46678      if they are not variable.  */
46679   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46680     true },
46681   /* Thiscall attribute says callee is responsible for popping arguments
46682      if they are not variable.  */
46683   { "thiscall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46684     true },
46685   /* Cdecl attribute says the callee is a normal C declaration */
46686   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46687     true },
46688   /* Regparm attribute specifies how many integer arguments are to be
46689      passed in registers.  */
46690   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute,
46691     true },
46692   /* Sseregparm attribute says we are using x86_64 calling conventions
46693      for FP arguments.  */
46694   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute,
46695     true },
46696   /* The transactional memory builtins are implicitly regparm or fastcall
46697      depending on the ABI.  Override the generic do-nothing attribute that
46698      these builtins were declared with.  */
46699   { "*tm regparm", 0, 0, false, true, true, ix86_handle_tm_regparm_attribute,
46700     true },
46701   /* force_align_arg_pointer says this function realigns the stack at entry.  */
46702   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
46703     false, true,  true, ix86_handle_cconv_attribute, false },
46704 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
46705   { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false },
46706   { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false },
46707   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute,
46708     false },
46709 #endif
46710   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute,
46711     false },
46712   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute,
46713     false },
46714 #ifdef SUBTARGET_ATTRIBUTE_TABLE
46715   SUBTARGET_ATTRIBUTE_TABLE,
46716 #endif
46717   /* ms_abi and sysv_abi calling convention function attributes.  */
46718   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute, true },
46719   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute, true },
46720   { "ms_hook_prologue", 0, 0, true, false, false, ix86_handle_fndecl_attribute,
46721     false },
46722   { "callee_pop_aggregate_return", 1, 1, false, true, true,
46723     ix86_handle_callee_pop_aggregate_return, true },
46724   /* End element.  */
46725   { NULL,        0, 0, false, false, false, NULL, false }
46726 };
46727
46728 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
46729 static int
46730 ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
46731                                  tree vectype, int)
46732 {
46733   unsigned elements;
46734
46735   switch (type_of_cost)
46736     {
46737       case scalar_stmt:
46738         return ix86_cost->scalar_stmt_cost;
46739
46740       case scalar_load:
46741         return ix86_cost->scalar_load_cost;
46742
46743       case scalar_store:
46744         return ix86_cost->scalar_store_cost;
46745
46746       case vector_stmt:
46747         return ix86_cost->vec_stmt_cost;
46748
46749       case vector_load:
46750         return ix86_cost->vec_align_load_cost;
46751
46752       case vector_store:
46753         return ix86_cost->vec_store_cost;
46754
46755       case vec_to_scalar:
46756         return ix86_cost->vec_to_scalar_cost;
46757
46758       case scalar_to_vec:
46759         return ix86_cost->scalar_to_vec_cost;
46760
46761       case unaligned_load:
46762       case unaligned_store:
46763         return ix86_cost->vec_unalign_load_cost;
46764
46765       case cond_branch_taken:
46766         return ix86_cost->cond_taken_branch_cost;
46767
46768       case cond_branch_not_taken:
46769         return ix86_cost->cond_not_taken_branch_cost;
46770
46771       case vec_perm:
46772       case vec_promote_demote:
46773         return ix86_cost->vec_stmt_cost;
46774
46775       case vec_construct:
46776         elements = TYPE_VECTOR_SUBPARTS (vectype);
46777         return ix86_cost->vec_stmt_cost * (elements / 2 + 1);
46778
46779       default:
46780         gcc_unreachable ();
46781     }
46782 }
46783
46784 /* A cached (set (nil) (vselect (vconcat (nil) (nil)) (parallel [])))
46785    insn, so that expand_vselect{,_vconcat} doesn't have to create a fresh
46786    insn every time.  */
46787
46788 static GTY(()) rtx_insn *vselect_insn;
46789
46790 /* Initialize vselect_insn.  */
46791
46792 static void
46793 init_vselect_insn (void)
46794 {
46795   unsigned i;
46796   rtx x;
46797
46798   x = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (MAX_VECT_LEN));
46799   for (i = 0; i < MAX_VECT_LEN; ++i)
46800     XVECEXP (x, 0, i) = const0_rtx;
46801   x = gen_rtx_VEC_SELECT (V2DFmode, gen_rtx_VEC_CONCAT (V4DFmode, const0_rtx,
46802                                                         const0_rtx), x);
46803   x = gen_rtx_SET (const0_rtx, x);
46804   start_sequence ();
46805   vselect_insn = emit_insn (x);
46806   end_sequence ();
46807 }
46808
46809 /* Construct (set target (vec_select op0 (parallel perm))) and
46810    return true if that's a valid instruction in the active ISA.  */
46811
46812 static bool
46813 expand_vselect (rtx target, rtx op0, const unsigned char *perm,
46814                 unsigned nelt, bool testing_p)
46815 {
46816   unsigned int i;
46817   rtx x, save_vconcat;
46818   int icode;
46819
46820   if (vselect_insn == NULL_RTX)
46821     init_vselect_insn ();
46822
46823   x = XEXP (SET_SRC (PATTERN (vselect_insn)), 1);
46824   PUT_NUM_ELEM (XVEC (x, 0), nelt);
46825   for (i = 0; i < nelt; ++i)
46826     XVECEXP (x, 0, i) = GEN_INT (perm[i]);
46827   save_vconcat = XEXP (SET_SRC (PATTERN (vselect_insn)), 0);
46828   XEXP (SET_SRC (PATTERN (vselect_insn)), 0) = op0;
46829   PUT_MODE (SET_SRC (PATTERN (vselect_insn)), GET_MODE (target));
46830   SET_DEST (PATTERN (vselect_insn)) = target;
46831   icode = recog_memoized (vselect_insn);
46832
46833   if (icode >= 0 && !testing_p)
46834     emit_insn (copy_rtx (PATTERN (vselect_insn)));
46835
46836   SET_DEST (PATTERN (vselect_insn)) = const0_rtx;
46837   XEXP (SET_SRC (PATTERN (vselect_insn)), 0) = save_vconcat;
46838   INSN_CODE (vselect_insn) = -1;
46839
46840   return icode >= 0;
46841 }
46842
46843 /* Similar, but generate a vec_concat from op0 and op1 as well.  */
46844
46845 static bool
46846 expand_vselect_vconcat (rtx target, rtx op0, rtx op1,
46847                         const unsigned char *perm, unsigned nelt,
46848                         bool testing_p)
46849 {
46850   machine_mode v2mode;
46851   rtx x;
46852   bool ok;
46853
46854   if (vselect_insn == NULL_RTX)
46855     init_vselect_insn ();
46856
46857   v2mode = GET_MODE_2XWIDER_MODE (GET_MODE (op0));
46858   x = XEXP (SET_SRC (PATTERN (vselect_insn)), 0);
46859   PUT_MODE (x, v2mode);
46860   XEXP (x, 0) = op0;
46861   XEXP (x, 1) = op1;
46862   ok = expand_vselect (target, x, perm, nelt, testing_p);
46863   XEXP (x, 0) = const0_rtx;
46864   XEXP (x, 1) = const0_rtx;
46865   return ok;
46866 }
46867
46868 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
46869    in terms of blendp[sd] / pblendw / pblendvb / vpblendd.  */
46870
46871 static bool
46872 expand_vec_perm_blend (struct expand_vec_perm_d *d)
46873 {
46874   machine_mode mmode, vmode = d->vmode;
46875   unsigned i, mask, nelt = d->nelt;
46876   rtx target, op0, op1, maskop, x;
46877   rtx rperm[32], vperm;
46878
46879   if (d->one_operand_p)
46880     return false;
46881   if (TARGET_AVX512F && GET_MODE_SIZE (vmode) == 64
46882       && (TARGET_AVX512BW
46883           || GET_MODE_SIZE (GET_MODE_INNER (vmode)) >= 4))
46884     ;
46885   else if (TARGET_AVX2 && GET_MODE_SIZE (vmode) == 32)
46886     ;
46887   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
46888     ;
46889   else if (TARGET_SSE4_1 && GET_MODE_SIZE (vmode) == 16)
46890     ;
46891   else
46892     return false;
46893
46894   /* This is a blend, not a permute.  Elements must stay in their
46895      respective lanes.  */
46896   for (i = 0; i < nelt; ++i)
46897     {
46898       unsigned e = d->perm[i];
46899       if (!(e == i || e == i + nelt))
46900         return false;
46901     }
46902
46903   if (d->testing_p)
46904     return true;
46905
46906   /* ??? Without SSE4.1, we could implement this with and/andn/or.  This
46907      decision should be extracted elsewhere, so that we only try that
46908      sequence once all budget==3 options have been tried.  */
46909   target = d->target;
46910   op0 = d->op0;
46911   op1 = d->op1;
46912   mask = 0;
46913
46914   switch (vmode)
46915     {
46916     case V8DFmode:
46917     case V16SFmode:
46918     case V4DFmode:
46919     case V8SFmode:
46920     case V2DFmode:
46921     case V4SFmode:
46922     case V8HImode:
46923     case V8SImode:
46924     case V32HImode:
46925     case V64QImode:
46926     case V16SImode:
46927     case V8DImode:
46928       for (i = 0; i < nelt; ++i)
46929         mask |= (d->perm[i] >= nelt) << i;
46930       break;
46931
46932     case V2DImode:
46933       for (i = 0; i < 2; ++i)
46934         mask |= (d->perm[i] >= 2 ? 15 : 0) << (i * 4);
46935       vmode = V8HImode;
46936       goto do_subreg;
46937
46938     case V4SImode:
46939       for (i = 0; i < 4; ++i)
46940         mask |= (d->perm[i] >= 4 ? 3 : 0) << (i * 2);
46941       vmode = V8HImode;
46942       goto do_subreg;
46943
46944     case V16QImode:
46945       /* See if bytes move in pairs so we can use pblendw with
46946          an immediate argument, rather than pblendvb with a vector
46947          argument.  */
46948       for (i = 0; i < 16; i += 2)
46949         if (d->perm[i] + 1 != d->perm[i + 1])
46950           {
46951           use_pblendvb:
46952             for (i = 0; i < nelt; ++i)
46953               rperm[i] = (d->perm[i] < nelt ? const0_rtx : constm1_rtx);
46954
46955           finish_pblendvb:
46956             vperm = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (nelt, rperm));
46957             vperm = force_reg (vmode, vperm);
46958
46959             if (GET_MODE_SIZE (vmode) == 16)
46960               emit_insn (gen_sse4_1_pblendvb (target, op0, op1, vperm));
46961             else
46962               emit_insn (gen_avx2_pblendvb (target, op0, op1, vperm));
46963             if (target != d->target)
46964               emit_move_insn (d->target, gen_lowpart (d->vmode, target));
46965             return true;
46966           }
46967
46968       for (i = 0; i < 8; ++i)
46969         mask |= (d->perm[i * 2] >= 16) << i;
46970       vmode = V8HImode;
46971       /* FALLTHRU */
46972
46973     do_subreg:
46974       target = gen_reg_rtx (vmode);
46975       op0 = gen_lowpart (vmode, op0);
46976       op1 = gen_lowpart (vmode, op1);
46977       break;
46978
46979     case V32QImode:
46980       /* See if bytes move in pairs.  If not, vpblendvb must be used.  */
46981       for (i = 0; i < 32; i += 2)
46982         if (d->perm[i] + 1 != d->perm[i + 1])
46983           goto use_pblendvb;
46984       /* See if bytes move in quadruplets.  If yes, vpblendd
46985          with immediate can be used.  */
46986       for (i = 0; i < 32; i += 4)
46987         if (d->perm[i] + 2 != d->perm[i + 2])
46988           break;
46989       if (i < 32)
46990         {
46991           /* See if bytes move the same in both lanes.  If yes,
46992              vpblendw with immediate can be used.  */
46993           for (i = 0; i < 16; i += 2)
46994             if (d->perm[i] + 16 != d->perm[i + 16])
46995               goto use_pblendvb;
46996
46997           /* Use vpblendw.  */
46998           for (i = 0; i < 16; ++i)
46999             mask |= (d->perm[i * 2] >= 32) << i;
47000           vmode = V16HImode;
47001           goto do_subreg;
47002         }
47003
47004       /* Use vpblendd.  */
47005       for (i = 0; i < 8; ++i)
47006         mask |= (d->perm[i * 4] >= 32) << i;
47007       vmode = V8SImode;
47008       goto do_subreg;
47009
47010     case V16HImode:
47011       /* See if words move in pairs.  If yes, vpblendd can be used.  */
47012       for (i = 0; i < 16; i += 2)
47013         if (d->perm[i] + 1 != d->perm[i + 1])
47014           break;
47015       if (i < 16)
47016         {
47017           /* See if words move the same in both lanes.  If not,
47018              vpblendvb must be used.  */
47019           for (i = 0; i < 8; i++)
47020             if (d->perm[i] + 8 != d->perm[i + 8])
47021               {
47022                 /* Use vpblendvb.  */
47023                 for (i = 0; i < 32; ++i)
47024                   rperm[i] = (d->perm[i / 2] < 16 ? const0_rtx : constm1_rtx);
47025
47026                 vmode = V32QImode;
47027                 nelt = 32;
47028                 target = gen_reg_rtx (vmode);
47029                 op0 = gen_lowpart (vmode, op0);
47030                 op1 = gen_lowpart (vmode, op1);
47031                 goto finish_pblendvb;
47032               }
47033
47034           /* Use vpblendw.  */
47035           for (i = 0; i < 16; ++i)
47036             mask |= (d->perm[i] >= 16) << i;
47037           break;
47038         }
47039
47040       /* Use vpblendd.  */
47041       for (i = 0; i < 8; ++i)
47042         mask |= (d->perm[i * 2] >= 16) << i;
47043       vmode = V8SImode;
47044       goto do_subreg;
47045
47046     case V4DImode:
47047       /* Use vpblendd.  */
47048       for (i = 0; i < 4; ++i)
47049         mask |= (d->perm[i] >= 4 ? 3 : 0) << (i * 2);
47050       vmode = V8SImode;
47051       goto do_subreg;
47052
47053     default:
47054       gcc_unreachable ();
47055     }
47056
47057   switch (vmode)
47058     {
47059     case V8DFmode:
47060     case V8DImode:
47061       mmode = QImode;
47062       break;
47063     case V16SFmode:
47064     case V16SImode:
47065       mmode = HImode;
47066       break;
47067     case V32HImode:
47068       mmode = SImode;
47069       break;
47070     case V64QImode:
47071       mmode = DImode;
47072       break;
47073     default:
47074       mmode = VOIDmode;
47075     }
47076
47077   if (mmode != VOIDmode)
47078     maskop = force_reg (mmode, gen_int_mode (mask, mmode));
47079   else
47080     maskop = GEN_INT (mask);
47081
47082   /* This matches five different patterns with the different modes.  */
47083   x = gen_rtx_VEC_MERGE (vmode, op1, op0, maskop);
47084   x = gen_rtx_SET (target, x);
47085   emit_insn (x);
47086   if (target != d->target)
47087     emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47088
47089   return true;
47090 }
47091
47092 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
47093    in terms of the variable form of vpermilps.
47094
47095    Note that we will have already failed the immediate input vpermilps,
47096    which requires that the high and low part shuffle be identical; the
47097    variable form doesn't require that.  */
47098
47099 static bool
47100 expand_vec_perm_vpermil (struct expand_vec_perm_d *d)
47101 {
47102   rtx rperm[8], vperm;
47103   unsigned i;
47104
47105   if (!TARGET_AVX || d->vmode != V8SFmode || !d->one_operand_p)
47106     return false;
47107
47108   /* We can only permute within the 128-bit lane.  */
47109   for (i = 0; i < 8; ++i)
47110     {
47111       unsigned e = d->perm[i];
47112       if (i < 4 ? e >= 4 : e < 4)
47113         return false;
47114     }
47115
47116   if (d->testing_p)
47117     return true;
47118
47119   for (i = 0; i < 8; ++i)
47120     {
47121       unsigned e = d->perm[i];
47122
47123       /* Within each 128-bit lane, the elements of op0 are numbered
47124          from 0 and the elements of op1 are numbered from 4.  */
47125       if (e >= 8 + 4)
47126         e -= 8;
47127       else if (e >= 4)
47128         e -= 4;
47129
47130       rperm[i] = GEN_INT (e);
47131     }
47132
47133   vperm = gen_rtx_CONST_VECTOR (V8SImode, gen_rtvec_v (8, rperm));
47134   vperm = force_reg (V8SImode, vperm);
47135   emit_insn (gen_avx_vpermilvarv8sf3 (d->target, d->op0, vperm));
47136
47137   return true;
47138 }
47139
47140 /* Return true if permutation D can be performed as VMODE permutation
47141    instead.  */
47142
47143 static bool
47144 valid_perm_using_mode_p (machine_mode vmode, struct expand_vec_perm_d *d)
47145 {
47146   unsigned int i, j, chunk;
47147
47148   if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT
47149       || GET_MODE_CLASS (d->vmode) != MODE_VECTOR_INT
47150       || GET_MODE_SIZE (vmode) != GET_MODE_SIZE (d->vmode))
47151     return false;
47152
47153   if (GET_MODE_NUNITS (vmode) >= d->nelt)
47154     return true;
47155
47156   chunk = d->nelt / GET_MODE_NUNITS (vmode);
47157   for (i = 0; i < d->nelt; i += chunk)
47158     if (d->perm[i] & (chunk - 1))
47159       return false;
47160     else
47161       for (j = 1; j < chunk; ++j)
47162         if (d->perm[i] + j != d->perm[i + j])
47163           return false;
47164
47165   return true;
47166 }
47167
47168 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
47169    in terms of pshufb, vpperm, vpermq, vpermd, vpermps or vperm2i128.  */
47170
47171 static bool
47172 expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
47173 {
47174   unsigned i, nelt, eltsz, mask;
47175   unsigned char perm[64];
47176   machine_mode vmode = V16QImode;
47177   rtx rperm[64], vperm, target, op0, op1;
47178
47179   nelt = d->nelt;
47180
47181   if (!d->one_operand_p)
47182     {
47183       if (!TARGET_XOP || GET_MODE_SIZE (d->vmode) != 16)
47184         {
47185           if (TARGET_AVX2
47186               && valid_perm_using_mode_p (V2TImode, d))
47187             {
47188               if (d->testing_p)
47189                 return true;
47190
47191               /* Use vperm2i128 insn.  The pattern uses
47192                  V4DImode instead of V2TImode.  */
47193               target = d->target;
47194               if (d->vmode != V4DImode)
47195                 target = gen_reg_rtx (V4DImode);
47196               op0 = gen_lowpart (V4DImode, d->op0);
47197               op1 = gen_lowpart (V4DImode, d->op1);
47198               rperm[0]
47199                 = GEN_INT ((d->perm[0] / (nelt / 2))
47200                            | ((d->perm[nelt / 2] / (nelt / 2)) * 16));
47201               emit_insn (gen_avx2_permv2ti (target, op0, op1, rperm[0]));
47202               if (target != d->target)
47203                 emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47204               return true;
47205             }
47206           return false;
47207         }
47208     }
47209   else
47210     {
47211       if (GET_MODE_SIZE (d->vmode) == 16)
47212         {
47213           if (!TARGET_SSSE3)
47214             return false;
47215         }
47216       else if (GET_MODE_SIZE (d->vmode) == 32)
47217         {
47218           if (!TARGET_AVX2)
47219             return false;
47220
47221           /* V4DImode should be already handled through
47222              expand_vselect by vpermq instruction.  */
47223           gcc_assert (d->vmode != V4DImode);
47224
47225           vmode = V32QImode;
47226           if (d->vmode == V8SImode
47227               || d->vmode == V16HImode
47228               || d->vmode == V32QImode)
47229             {
47230               /* First see if vpermq can be used for
47231                  V8SImode/V16HImode/V32QImode.  */
47232               if (valid_perm_using_mode_p (V4DImode, d))
47233                 {
47234                   for (i = 0; i < 4; i++)
47235                     perm[i] = (d->perm[i * nelt / 4] * 4 / nelt) & 3;
47236                   if (d->testing_p)
47237                     return true;
47238                   target = gen_reg_rtx (V4DImode);
47239                   if (expand_vselect (target, gen_lowpart (V4DImode, d->op0),
47240                                       perm, 4, false))
47241                     {
47242                       emit_move_insn (d->target,
47243                                       gen_lowpart (d->vmode, target));
47244                       return true;
47245                     }
47246                   return false;
47247                 }
47248
47249               /* Next see if vpermd can be used.  */
47250               if (valid_perm_using_mode_p (V8SImode, d))
47251                 vmode = V8SImode;
47252             }
47253           /* Or if vpermps can be used.  */
47254           else if (d->vmode == V8SFmode)
47255             vmode = V8SImode;
47256
47257           if (vmode == V32QImode)
47258             {
47259               /* vpshufb only works intra lanes, it is not
47260                  possible to shuffle bytes in between the lanes.  */
47261               for (i = 0; i < nelt; ++i)
47262                 if ((d->perm[i] ^ i) & (nelt / 2))
47263                   return false;
47264             }
47265         }
47266       else if (GET_MODE_SIZE (d->vmode) == 64)
47267         {
47268           if (!TARGET_AVX512BW)
47269             return false;
47270
47271           /* If vpermq didn't work, vpshufb won't work either.  */
47272           if (d->vmode == V8DFmode || d->vmode == V8DImode)
47273             return false;
47274
47275           vmode = V64QImode;
47276           if (d->vmode == V16SImode
47277               || d->vmode == V32HImode
47278               || d->vmode == V64QImode)
47279             {
47280               /* First see if vpermq can be used for
47281                  V16SImode/V32HImode/V64QImode.  */
47282               if (valid_perm_using_mode_p (V8DImode, d))
47283                 {
47284                   for (i = 0; i < 8; i++)
47285                     perm[i] = (d->perm[i * nelt / 8] * 8 / nelt) & 7;
47286                   if (d->testing_p)
47287                     return true;
47288                   target = gen_reg_rtx (V8DImode);
47289                   if (expand_vselect (target, gen_lowpart (V8DImode, d->op0),
47290                                       perm, 8, false))
47291                     {
47292                       emit_move_insn (d->target,
47293                                       gen_lowpart (d->vmode, target));
47294                       return true;
47295                     }
47296                   return false;
47297                 }
47298
47299               /* Next see if vpermd can be used.  */
47300               if (valid_perm_using_mode_p (V16SImode, d))
47301                 vmode = V16SImode;
47302             }
47303           /* Or if vpermps can be used.  */
47304           else if (d->vmode == V16SFmode)
47305             vmode = V16SImode;
47306           if (vmode == V64QImode)
47307             {
47308               /* vpshufb only works intra lanes, it is not
47309                  possible to shuffle bytes in between the lanes.  */
47310               for (i = 0; i < nelt; ++i)
47311                 if ((d->perm[i] ^ i) & (nelt / 4))
47312                   return false;
47313             }
47314         }
47315       else
47316         return false;
47317     }
47318
47319   if (d->testing_p)
47320     return true;
47321
47322   if (vmode == V8SImode)
47323     for (i = 0; i < 8; ++i)
47324       rperm[i] = GEN_INT ((d->perm[i * nelt / 8] * 8 / nelt) & 7);
47325   else if (vmode == V16SImode)
47326     for (i = 0; i < 16; ++i)
47327       rperm[i] = GEN_INT ((d->perm[i * nelt / 16] * 16 / nelt) & 15);
47328   else
47329     {
47330       eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
47331       if (!d->one_operand_p)
47332         mask = 2 * nelt - 1;
47333       else if (vmode == V16QImode)
47334         mask = nelt - 1;
47335       else if (vmode == V64QImode)
47336         mask = nelt / 4 - 1;
47337       else
47338         mask = nelt / 2 - 1;
47339
47340       for (i = 0; i < nelt; ++i)
47341         {
47342           unsigned j, e = d->perm[i] & mask;
47343           for (j = 0; j < eltsz; ++j)
47344             rperm[i * eltsz + j] = GEN_INT (e * eltsz + j);
47345         }
47346     }
47347
47348   vperm = gen_rtx_CONST_VECTOR (vmode,
47349                                 gen_rtvec_v (GET_MODE_NUNITS (vmode), rperm));
47350   vperm = force_reg (vmode, vperm);
47351
47352   target = d->target;
47353   if (d->vmode != vmode)
47354     target = gen_reg_rtx (vmode);
47355   op0 = gen_lowpart (vmode, d->op0);
47356   if (d->one_operand_p)
47357     {
47358       if (vmode == V16QImode)
47359         emit_insn (gen_ssse3_pshufbv16qi3 (target, op0, vperm));
47360       else if (vmode == V32QImode)
47361         emit_insn (gen_avx2_pshufbv32qi3 (target, op0, vperm));
47362       else if (vmode == V64QImode)
47363         emit_insn (gen_avx512bw_pshufbv64qi3 (target, op0, vperm));
47364       else if (vmode == V8SFmode)
47365         emit_insn (gen_avx2_permvarv8sf (target, op0, vperm));
47366       else if (vmode == V8SImode)
47367         emit_insn (gen_avx2_permvarv8si (target, op0, vperm));
47368       else if (vmode == V16SFmode)
47369         emit_insn (gen_avx512f_permvarv16sf (target, op0, vperm));
47370       else if (vmode == V16SImode)
47371         emit_insn (gen_avx512f_permvarv16si (target, op0, vperm));
47372       else
47373         gcc_unreachable ();
47374     }
47375   else
47376     {
47377       op1 = gen_lowpart (vmode, d->op1);
47378       emit_insn (gen_xop_pperm (target, op0, op1, vperm));
47379     }
47380   if (target != d->target)
47381     emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47382
47383   return true;
47384 }
47385
47386 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to instantiate D
47387    in a single instruction.  */
47388
47389 static bool
47390 expand_vec_perm_1 (struct expand_vec_perm_d *d)
47391 {
47392   unsigned i, nelt = d->nelt;
47393   unsigned char perm2[MAX_VECT_LEN];
47394
47395   /* Check plain VEC_SELECT first, because AVX has instructions that could
47396      match both SEL and SEL+CONCAT, but the plain SEL will allow a memory
47397      input where SEL+CONCAT may not.  */
47398   if (d->one_operand_p)
47399     {
47400       int mask = nelt - 1;
47401       bool identity_perm = true;
47402       bool broadcast_perm = true;
47403
47404       for (i = 0; i < nelt; i++)
47405         {
47406           perm2[i] = d->perm[i] & mask;
47407           if (perm2[i] != i)
47408             identity_perm = false;
47409           if (perm2[i])
47410             broadcast_perm = false;
47411         }
47412
47413       if (identity_perm)
47414         {
47415           if (!d->testing_p)
47416             emit_move_insn (d->target, d->op0);
47417           return true;
47418         }
47419       else if (broadcast_perm && TARGET_AVX2)
47420         {
47421           /* Use vpbroadcast{b,w,d}.  */
47422           rtx (*gen) (rtx, rtx) = NULL;
47423           switch (d->vmode)
47424             {
47425             case V64QImode:
47426               if (TARGET_AVX512BW)
47427                 gen = gen_avx512bw_vec_dupv64qi_1;
47428               break;
47429             case V32QImode:
47430               gen = gen_avx2_pbroadcastv32qi_1;
47431               break;
47432             case V32HImode:
47433               if (TARGET_AVX512BW)
47434                 gen = gen_avx512bw_vec_dupv32hi_1;
47435               break;
47436             case V16HImode:
47437               gen = gen_avx2_pbroadcastv16hi_1;
47438               break;
47439             case V16SImode:
47440               if (TARGET_AVX512F)
47441                 gen = gen_avx512f_vec_dupv16si_1;
47442               break;
47443             case V8SImode:
47444               gen = gen_avx2_pbroadcastv8si_1;
47445               break;
47446             case V16QImode:
47447               gen = gen_avx2_pbroadcastv16qi;
47448               break;
47449             case V8HImode:
47450               gen = gen_avx2_pbroadcastv8hi;
47451               break;
47452             case V16SFmode:
47453               if (TARGET_AVX512F)
47454                 gen = gen_avx512f_vec_dupv16sf_1;
47455               break;
47456             case V8SFmode:
47457               gen = gen_avx2_vec_dupv8sf_1;
47458               break;
47459             case V8DFmode:
47460               if (TARGET_AVX512F)
47461                 gen = gen_avx512f_vec_dupv8df_1;
47462               break;
47463             case V8DImode:
47464               if (TARGET_AVX512F)
47465                 gen = gen_avx512f_vec_dupv8di_1;
47466               break;
47467             /* For other modes prefer other shuffles this function creates.  */
47468             default: break;
47469             }
47470           if (gen != NULL)
47471             {
47472               if (!d->testing_p)
47473                 emit_insn (gen (d->target, d->op0));
47474               return true;
47475             }
47476         }
47477
47478       if (expand_vselect (d->target, d->op0, perm2, nelt, d->testing_p))
47479         return true;
47480
47481       /* There are plenty of patterns in sse.md that are written for
47482          SEL+CONCAT and are not replicated for a single op.  Perhaps
47483          that should be changed, to avoid the nastiness here.  */
47484
47485       /* Recognize interleave style patterns, which means incrementing
47486          every other permutation operand.  */
47487       for (i = 0; i < nelt; i += 2)
47488         {
47489           perm2[i] = d->perm[i] & mask;
47490           perm2[i + 1] = (d->perm[i + 1] & mask) + nelt;
47491         }
47492       if (expand_vselect_vconcat (d->target, d->op0, d->op0, perm2, nelt,
47493                                   d->testing_p))
47494         return true;
47495
47496       /* Recognize shufps, which means adding {0, 0, nelt, nelt}.  */
47497       if (nelt >= 4)
47498         {
47499           for (i = 0; i < nelt; i += 4)
47500             {
47501               perm2[i + 0] = d->perm[i + 0] & mask;
47502               perm2[i + 1] = d->perm[i + 1] & mask;
47503               perm2[i + 2] = (d->perm[i + 2] & mask) + nelt;
47504               perm2[i + 3] = (d->perm[i + 3] & mask) + nelt;
47505             }
47506
47507           if (expand_vselect_vconcat (d->target, d->op0, d->op0, perm2, nelt,
47508                                       d->testing_p))
47509             return true;
47510         }
47511     }
47512
47513   /* Finally, try the fully general two operand permute.  */
47514   if (expand_vselect_vconcat (d->target, d->op0, d->op1, d->perm, nelt,
47515                               d->testing_p))
47516     return true;
47517
47518   /* Recognize interleave style patterns with reversed operands.  */
47519   if (!d->one_operand_p)
47520     {
47521       for (i = 0; i < nelt; ++i)
47522         {
47523           unsigned e = d->perm[i];
47524           if (e >= nelt)
47525             e -= nelt;
47526           else
47527             e += nelt;
47528           perm2[i] = e;
47529         }
47530
47531       if (expand_vselect_vconcat (d->target, d->op1, d->op0, perm2, nelt,
47532                                   d->testing_p))
47533         return true;
47534     }
47535
47536   /* Try the SSE4.1 blend variable merge instructions.  */
47537   if (expand_vec_perm_blend (d))
47538     return true;
47539
47540   /* Try one of the AVX vpermil variable permutations.  */
47541   if (expand_vec_perm_vpermil (d))
47542     return true;
47543
47544   /* Try the SSSE3 pshufb or XOP vpperm or AVX2 vperm2i128,
47545      vpshufb, vpermd, vpermps or vpermq variable permutation.  */
47546   if (expand_vec_perm_pshufb (d))
47547     return true;
47548
47549   /* Try the AVX2 vpalignr instruction.  */
47550   if (expand_vec_perm_palignr (d, true))
47551     return true;
47552
47553   /* Try the AVX512F vpermi2 instructions.  */
47554   if (ix86_expand_vec_perm_vpermi2 (NULL_RTX, NULL_RTX, NULL_RTX, NULL_RTX, d))
47555     return true;
47556
47557   return false;
47558 }
47559
47560 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
47561    in terms of a pair of pshuflw + pshufhw instructions.  */
47562
47563 static bool
47564 expand_vec_perm_pshuflw_pshufhw (struct expand_vec_perm_d *d)
47565 {
47566   unsigned char perm2[MAX_VECT_LEN];
47567   unsigned i;
47568   bool ok;
47569
47570   if (d->vmode != V8HImode || !d->one_operand_p)
47571     return false;
47572
47573   /* The two permutations only operate in 64-bit lanes.  */
47574   for (i = 0; i < 4; ++i)
47575     if (d->perm[i] >= 4)
47576       return false;
47577   for (i = 4; i < 8; ++i)
47578     if (d->perm[i] < 4)
47579       return false;
47580
47581   if (d->testing_p)
47582     return true;
47583
47584   /* Emit the pshuflw.  */
47585   memcpy (perm2, d->perm, 4);
47586   for (i = 4; i < 8; ++i)
47587     perm2[i] = i;
47588   ok = expand_vselect (d->target, d->op0, perm2, 8, d->testing_p);
47589   gcc_assert (ok);
47590
47591   /* Emit the pshufhw.  */
47592   memcpy (perm2 + 4, d->perm + 4, 4);
47593   for (i = 0; i < 4; ++i)
47594     perm2[i] = i;
47595   ok = expand_vselect (d->target, d->target, perm2, 8, d->testing_p);
47596   gcc_assert (ok);
47597
47598   return true;
47599 }
47600
47601 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47602    the permutation using the SSSE3 palignr instruction.  This succeeds
47603    when all of the elements in PERM fit within one vector and we merely
47604    need to shift them down so that a single vector permutation has a
47605    chance to succeed.  If SINGLE_INSN_ONLY_P, succeed if only
47606    the vpalignr instruction itself can perform the requested permutation.  */
47607
47608 static bool
47609 expand_vec_perm_palignr (struct expand_vec_perm_d *d, bool single_insn_only_p)
47610 {
47611   unsigned i, nelt = d->nelt;
47612   unsigned min, max, minswap, maxswap;
47613   bool in_order, ok, swap = false;
47614   rtx shift, target;
47615   struct expand_vec_perm_d dcopy;
47616
47617   /* Even with AVX, palignr only operates on 128-bit vectors,
47618      in AVX2 palignr operates on both 128-bit lanes.  */
47619   if ((!TARGET_SSSE3 || GET_MODE_SIZE (d->vmode) != 16)
47620       && (!TARGET_AVX2 || GET_MODE_SIZE (d->vmode) != 32))
47621     return false;
47622
47623   min = 2 * nelt;
47624   max = 0;
47625   minswap = 2 * nelt;
47626   maxswap = 0;
47627   for (i = 0; i < nelt; ++i)
47628     {
47629       unsigned e = d->perm[i];
47630       unsigned eswap = d->perm[i] ^ nelt;
47631       if (GET_MODE_SIZE (d->vmode) == 32)
47632         {
47633           e = (e & ((nelt / 2) - 1)) | ((e & nelt) >> 1);
47634           eswap = e ^ (nelt / 2);
47635         }
47636       if (e < min)
47637         min = e;
47638       if (e > max)
47639         max = e;
47640       if (eswap < minswap)
47641         minswap = eswap;
47642       if (eswap > maxswap)
47643         maxswap = eswap;
47644     }
47645   if (min == 0
47646       || max - min >= (GET_MODE_SIZE (d->vmode) == 32 ? nelt / 2 : nelt))
47647     {
47648       if (d->one_operand_p
47649           || minswap == 0
47650           || maxswap - minswap >= (GET_MODE_SIZE (d->vmode) == 32
47651                                    ? nelt / 2 : nelt))
47652         return false;
47653       swap = true;
47654       min = minswap;
47655       max = maxswap;
47656     }
47657
47658   /* Given that we have SSSE3, we know we'll be able to implement the
47659      single operand permutation after the palignr with pshufb for
47660      128-bit vectors.  If SINGLE_INSN_ONLY_P, in_order has to be computed
47661      first.  */
47662   if (d->testing_p && GET_MODE_SIZE (d->vmode) == 16 && !single_insn_only_p)
47663     return true;
47664
47665   dcopy = *d;
47666   if (swap)
47667     {
47668       dcopy.op0 = d->op1;
47669       dcopy.op1 = d->op0;
47670       for (i = 0; i < nelt; ++i)
47671         dcopy.perm[i] ^= nelt;
47672     }
47673
47674   in_order = true;
47675   for (i = 0; i < nelt; ++i)
47676     {
47677       unsigned e = dcopy.perm[i];
47678       if (GET_MODE_SIZE (d->vmode) == 32
47679           && e >= nelt
47680           && (e & (nelt / 2 - 1)) < min)
47681         e = e - min - (nelt / 2);
47682       else
47683         e = e - min;
47684       if (e != i)
47685         in_order = false;
47686       dcopy.perm[i] = e;
47687     }
47688   dcopy.one_operand_p = true;
47689
47690   if (single_insn_only_p && !in_order)
47691     return false;
47692
47693   /* For AVX2, test whether we can permute the result in one instruction.  */
47694   if (d->testing_p)
47695     {
47696       if (in_order)
47697         return true;
47698       dcopy.op1 = dcopy.op0;
47699       return expand_vec_perm_1 (&dcopy);
47700     }
47701
47702   shift = GEN_INT (min * GET_MODE_BITSIZE (GET_MODE_INNER (d->vmode)));
47703   if (GET_MODE_SIZE (d->vmode) == 16)
47704     {
47705       target = gen_reg_rtx (TImode);
47706       emit_insn (gen_ssse3_palignrti (target, gen_lowpart (TImode, dcopy.op1),
47707                                       gen_lowpart (TImode, dcopy.op0), shift));
47708     }
47709   else
47710     {
47711       target = gen_reg_rtx (V2TImode);
47712       emit_insn (gen_avx2_palignrv2ti (target,
47713                                        gen_lowpart (V2TImode, dcopy.op1),
47714                                        gen_lowpart (V2TImode, dcopy.op0),
47715                                        shift));
47716     }
47717
47718   dcopy.op0 = dcopy.op1 = gen_lowpart (d->vmode, target);
47719
47720   /* Test for the degenerate case where the alignment by itself
47721      produces the desired permutation.  */
47722   if (in_order)
47723     {
47724       emit_move_insn (d->target, dcopy.op0);
47725       return true;
47726     }
47727
47728   ok = expand_vec_perm_1 (&dcopy);
47729   gcc_assert (ok || GET_MODE_SIZE (d->vmode) == 32);
47730
47731   return ok;
47732 }
47733
47734 /* A subroutine of ix86_expand_vec_perm_const_1.  Try to simplify
47735    the permutation using the SSE4_1 pblendv instruction.  Potentially
47736    reduces permutation from 2 pshufb and or to 1 pshufb and pblendv.  */
47737
47738 static bool
47739 expand_vec_perm_pblendv (struct expand_vec_perm_d *d)
47740 {
47741   unsigned i, which, nelt = d->nelt;
47742   struct expand_vec_perm_d dcopy, dcopy1;
47743   machine_mode vmode = d->vmode;
47744   bool ok;
47745
47746   /* Use the same checks as in expand_vec_perm_blend.  */
47747   if (d->one_operand_p)
47748     return false;
47749   if (TARGET_AVX2 && GET_MODE_SIZE (vmode) == 32)
47750     ;
47751   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
47752     ;
47753   else if (TARGET_SSE4_1 && GET_MODE_SIZE (vmode) == 16)
47754     ;
47755   else
47756     return false;
47757
47758   /* Figure out where permutation elements stay not in their
47759      respective lanes.  */
47760   for (i = 0, which = 0; i < nelt; ++i)
47761     {
47762       unsigned e = d->perm[i];
47763       if (e != i)
47764         which |= (e < nelt ? 1 : 2);
47765     }
47766   /* We can pblend the part where elements stay not in their
47767      respective lanes only when these elements are all in one
47768      half of a permutation.
47769      {0 1 8 3 4 5 9 7} is ok as 8, 9 are at not at their respective
47770      lanes, but both 8 and 9 >= 8
47771      {0 1 8 3 4 5 2 7} is not ok as 2 and 8 are not at their
47772      respective lanes and 8 >= 8, but 2 not.  */
47773   if (which != 1 && which != 2)
47774     return false;
47775   if (d->testing_p && GET_MODE_SIZE (vmode) == 16)
47776     return true;
47777
47778   /* First we apply one operand permutation to the part where
47779      elements stay not in their respective lanes.  */
47780   dcopy = *d;
47781   if (which == 2)
47782     dcopy.op0 = dcopy.op1 = d->op1;
47783   else
47784     dcopy.op0 = dcopy.op1 = d->op0;
47785   if (!d->testing_p)
47786     dcopy.target = gen_reg_rtx (vmode);
47787   dcopy.one_operand_p = true;
47788
47789   for (i = 0; i < nelt; ++i)
47790     dcopy.perm[i] = d->perm[i] & (nelt - 1);
47791
47792   ok = expand_vec_perm_1 (&dcopy);
47793   if (GET_MODE_SIZE (vmode) != 16 && !ok)
47794     return false;
47795   else
47796     gcc_assert (ok);
47797   if (d->testing_p)
47798     return true;
47799
47800   /* Next we put permuted elements into their positions.  */
47801   dcopy1 = *d;
47802   if (which == 2)
47803     dcopy1.op1 = dcopy.target;
47804   else
47805     dcopy1.op0 = dcopy.target;
47806
47807   for (i = 0; i < nelt; ++i)
47808     dcopy1.perm[i] = ((d->perm[i] >= nelt) ? (nelt + i) : i);
47809
47810   ok = expand_vec_perm_blend (&dcopy1);
47811   gcc_assert (ok);
47812
47813   return true;
47814 }
47815
47816 static bool expand_vec_perm_interleave3 (struct expand_vec_perm_d *d);
47817
47818 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47819    a two vector permutation into a single vector permutation by using
47820    an interleave operation to merge the vectors.  */
47821
47822 static bool
47823 expand_vec_perm_interleave2 (struct expand_vec_perm_d *d)
47824 {
47825   struct expand_vec_perm_d dremap, dfinal;
47826   unsigned i, nelt = d->nelt, nelt2 = nelt / 2;
47827   unsigned HOST_WIDE_INT contents;
47828   unsigned char remap[2 * MAX_VECT_LEN];
47829   rtx_insn *seq;
47830   bool ok, same_halves = false;
47831
47832   if (GET_MODE_SIZE (d->vmode) == 16)
47833     {
47834       if (d->one_operand_p)
47835         return false;
47836     }
47837   else if (GET_MODE_SIZE (d->vmode) == 32)
47838     {
47839       if (!TARGET_AVX)
47840         return false;
47841       /* For 32-byte modes allow even d->one_operand_p.
47842          The lack of cross-lane shuffling in some instructions
47843          might prevent a single insn shuffle.  */
47844       dfinal = *d;
47845       dfinal.testing_p = true;
47846       /* If expand_vec_perm_interleave3 can expand this into
47847          a 3 insn sequence, give up and let it be expanded as
47848          3 insn sequence.  While that is one insn longer,
47849          it doesn't need a memory operand and in the common
47850          case that both interleave low and high permutations
47851          with the same operands are adjacent needs 4 insns
47852          for both after CSE.  */
47853       if (expand_vec_perm_interleave3 (&dfinal))
47854         return false;
47855     }
47856   else
47857     return false;
47858
47859   /* Examine from whence the elements come.  */
47860   contents = 0;
47861   for (i = 0; i < nelt; ++i)
47862     contents |= HOST_WIDE_INT_1U << d->perm[i];
47863
47864   memset (remap, 0xff, sizeof (remap));
47865   dremap = *d;
47866
47867   if (GET_MODE_SIZE (d->vmode) == 16)
47868     {
47869       unsigned HOST_WIDE_INT h1, h2, h3, h4;
47870
47871       /* Split the two input vectors into 4 halves.  */
47872       h1 = (HOST_WIDE_INT_1U << nelt2) - 1;
47873       h2 = h1 << nelt2;
47874       h3 = h2 << nelt2;
47875       h4 = h3 << nelt2;
47876
47877       /* If the elements from the low halves use interleave low, and similarly
47878          for interleave high.  If the elements are from mis-matched halves, we
47879          can use shufps for V4SF/V4SI or do a DImode shuffle.  */
47880       if ((contents & (h1 | h3)) == contents)
47881         {
47882           /* punpckl* */
47883           for (i = 0; i < nelt2; ++i)
47884             {
47885               remap[i] = i * 2;
47886               remap[i + nelt] = i * 2 + 1;
47887               dremap.perm[i * 2] = i;
47888               dremap.perm[i * 2 + 1] = i + nelt;
47889             }
47890           if (!TARGET_SSE2 && d->vmode == V4SImode)
47891             dremap.vmode = V4SFmode;
47892         }
47893       else if ((contents & (h2 | h4)) == contents)
47894         {
47895           /* punpckh* */
47896           for (i = 0; i < nelt2; ++i)
47897             {
47898               remap[i + nelt2] = i * 2;
47899               remap[i + nelt + nelt2] = i * 2 + 1;
47900               dremap.perm[i * 2] = i + nelt2;
47901               dremap.perm[i * 2 + 1] = i + nelt + nelt2;
47902             }
47903           if (!TARGET_SSE2 && d->vmode == V4SImode)
47904             dremap.vmode = V4SFmode;
47905         }
47906       else if ((contents & (h1 | h4)) == contents)
47907         {
47908           /* shufps */
47909           for (i = 0; i < nelt2; ++i)
47910             {
47911               remap[i] = i;
47912               remap[i + nelt + nelt2] = i + nelt2;
47913               dremap.perm[i] = i;
47914               dremap.perm[i + nelt2] = i + nelt + nelt2;
47915             }
47916           if (nelt != 4)
47917             {
47918               /* shufpd */
47919               dremap.vmode = V2DImode;
47920               dremap.nelt = 2;
47921               dremap.perm[0] = 0;
47922               dremap.perm[1] = 3;
47923             }
47924         }
47925       else if ((contents & (h2 | h3)) == contents)
47926         {
47927           /* shufps */
47928           for (i = 0; i < nelt2; ++i)
47929             {
47930               remap[i + nelt2] = i;
47931               remap[i + nelt] = i + nelt2;
47932               dremap.perm[i] = i + nelt2;
47933               dremap.perm[i + nelt2] = i + nelt;
47934             }
47935           if (nelt != 4)
47936             {
47937               /* shufpd */
47938               dremap.vmode = V2DImode;
47939               dremap.nelt = 2;
47940               dremap.perm[0] = 1;
47941               dremap.perm[1] = 2;
47942             }
47943         }
47944       else
47945         return false;
47946     }
47947   else
47948     {
47949       unsigned int nelt4 = nelt / 4, nzcnt = 0;
47950       unsigned HOST_WIDE_INT q[8];
47951       unsigned int nonzero_halves[4];
47952
47953       /* Split the two input vectors into 8 quarters.  */
47954       q[0] = (HOST_WIDE_INT_1U << nelt4) - 1;
47955       for (i = 1; i < 8; ++i)
47956         q[i] = q[0] << (nelt4 * i);
47957       for (i = 0; i < 4; ++i)
47958         if (((q[2 * i] | q[2 * i + 1]) & contents) != 0)
47959           {
47960             nonzero_halves[nzcnt] = i;
47961             ++nzcnt;
47962           }
47963
47964       if (nzcnt == 1)
47965         {
47966           gcc_assert (d->one_operand_p);
47967           nonzero_halves[1] = nonzero_halves[0];
47968           same_halves = true;
47969         }
47970       else if (d->one_operand_p)
47971         {
47972           gcc_assert (nonzero_halves[0] == 0);
47973           gcc_assert (nonzero_halves[1] == 1);
47974         }
47975
47976       if (nzcnt <= 2)
47977         {
47978           if (d->perm[0] / nelt2 == nonzero_halves[1])
47979             {
47980               /* Attempt to increase the likelihood that dfinal
47981                  shuffle will be intra-lane.  */
47982               char tmph = nonzero_halves[0];
47983               nonzero_halves[0] = nonzero_halves[1];
47984               nonzero_halves[1] = tmph;
47985             }
47986
47987           /* vperm2f128 or vperm2i128.  */
47988           for (i = 0; i < nelt2; ++i)
47989             {
47990               remap[i + nonzero_halves[1] * nelt2] = i + nelt2;
47991               remap[i + nonzero_halves[0] * nelt2] = i;
47992               dremap.perm[i + nelt2] = i + nonzero_halves[1] * nelt2;
47993               dremap.perm[i] = i + nonzero_halves[0] * nelt2;
47994             }
47995
47996           if (d->vmode != V8SFmode
47997               && d->vmode != V4DFmode
47998               && d->vmode != V8SImode)
47999             {
48000               dremap.vmode = V8SImode;
48001               dremap.nelt = 8;
48002               for (i = 0; i < 4; ++i)
48003                 {
48004                   dremap.perm[i] = i + nonzero_halves[0] * 4;
48005                   dremap.perm[i + 4] = i + nonzero_halves[1] * 4;
48006                 }
48007             }
48008         }
48009       else if (d->one_operand_p)
48010         return false;
48011       else if (TARGET_AVX2
48012                && (contents & (q[0] | q[2] | q[4] | q[6])) == contents)
48013         {
48014           /* vpunpckl* */
48015           for (i = 0; i < nelt4; ++i)
48016             {
48017               remap[i] = i * 2;
48018               remap[i + nelt] = i * 2 + 1;
48019               remap[i + nelt2] = i * 2 + nelt2;
48020               remap[i + nelt + nelt2] = i * 2 + nelt2 + 1;
48021               dremap.perm[i * 2] = i;
48022               dremap.perm[i * 2 + 1] = i + nelt;
48023               dremap.perm[i * 2 + nelt2] = i + nelt2;
48024               dremap.perm[i * 2 + nelt2 + 1] = i + nelt + nelt2;
48025             }
48026         }
48027       else if (TARGET_AVX2
48028                && (contents & (q[1] | q[3] | q[5] | q[7])) == contents)
48029         {
48030           /* vpunpckh* */
48031           for (i = 0; i < nelt4; ++i)
48032             {
48033               remap[i + nelt4] = i * 2;
48034               remap[i + nelt + nelt4] = i * 2 + 1;
48035               remap[i + nelt2 + nelt4] = i * 2 + nelt2;
48036               remap[i + nelt + nelt2 + nelt4] = i * 2 + nelt2 + 1;
48037               dremap.perm[i * 2] = i + nelt4;
48038               dremap.perm[i * 2 + 1] = i + nelt + nelt4;
48039               dremap.perm[i * 2 + nelt2] = i + nelt2 + nelt4;
48040               dremap.perm[i * 2 + nelt2 + 1] = i + nelt + nelt2 + nelt4;
48041             }
48042         }
48043       else
48044         return false;
48045     }
48046
48047   /* Use the remapping array set up above to move the elements from their
48048      swizzled locations into their final destinations.  */
48049   dfinal = *d;
48050   for (i = 0; i < nelt; ++i)
48051     {
48052       unsigned e = remap[d->perm[i]];
48053       gcc_assert (e < nelt);
48054       /* If same_halves is true, both halves of the remapped vector are the
48055          same.  Avoid cross-lane accesses if possible.  */
48056       if (same_halves && i >= nelt2)
48057         {
48058           gcc_assert (e < nelt2);
48059           dfinal.perm[i] = e + nelt2;
48060         }
48061       else
48062         dfinal.perm[i] = e;
48063     }
48064   if (!d->testing_p)
48065     {
48066       dremap.target = gen_reg_rtx (dremap.vmode);
48067       dfinal.op0 = gen_lowpart (dfinal.vmode, dremap.target);
48068     }
48069   dfinal.op1 = dfinal.op0;
48070   dfinal.one_operand_p = true;
48071
48072   /* Test if the final remap can be done with a single insn.  For V4SFmode or
48073      V4SImode this *will* succeed.  For V8HImode or V16QImode it may not.  */
48074   start_sequence ();
48075   ok = expand_vec_perm_1 (&dfinal);
48076   seq = get_insns ();
48077   end_sequence ();
48078
48079   if (!ok)
48080     return false;
48081
48082   if (d->testing_p)
48083     return true;
48084
48085   if (dremap.vmode != dfinal.vmode)
48086     {
48087       dremap.op0 = gen_lowpart (dremap.vmode, dremap.op0);
48088       dremap.op1 = gen_lowpart (dremap.vmode, dremap.op1);
48089     }
48090
48091   ok = expand_vec_perm_1 (&dremap);
48092   gcc_assert (ok);
48093
48094   emit_insn (seq);
48095   return true;
48096 }
48097
48098 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
48099    a single vector cross-lane permutation into vpermq followed
48100    by any of the single insn permutations.  */
48101
48102 static bool
48103 expand_vec_perm_vpermq_perm_1 (struct expand_vec_perm_d *d)
48104 {
48105   struct expand_vec_perm_d dremap, dfinal;
48106   unsigned i, j, nelt = d->nelt, nelt2 = nelt / 2, nelt4 = nelt / 4;
48107   unsigned contents[2];
48108   bool ok;
48109
48110   if (!(TARGET_AVX2
48111         && (d->vmode == V32QImode || d->vmode == V16HImode)
48112         && d->one_operand_p))
48113     return false;
48114
48115   contents[0] = 0;
48116   contents[1] = 0;
48117   for (i = 0; i < nelt2; ++i)
48118     {
48119       contents[0] |= 1u << (d->perm[i] / nelt4);
48120       contents[1] |= 1u << (d->perm[i + nelt2] / nelt4);
48121     }
48122
48123   for (i = 0; i < 2; ++i)
48124     {
48125       unsigned int cnt = 0;
48126       for (j = 0; j < 4; ++j)
48127         if ((contents[i] & (1u << j)) != 0 && ++cnt > 2)
48128           return false;
48129     }
48130
48131   if (d->testing_p)
48132     return true;
48133
48134   dremap = *d;
48135   dremap.vmode = V4DImode;
48136   dremap.nelt = 4;
48137   dremap.target = gen_reg_rtx (V4DImode);
48138   dremap.op0 = gen_lowpart (V4DImode, d->op0);
48139   dremap.op1 = dremap.op0;
48140   dremap.one_operand_p = true;
48141   for (i = 0; i < 2; ++i)
48142     {
48143       unsigned int cnt = 0;
48144       for (j = 0; j < 4; ++j)
48145         if ((contents[i] & (1u << j)) != 0)
48146           dremap.perm[2 * i + cnt++] = j;
48147       for (; cnt < 2; ++cnt)
48148         dremap.perm[2 * i + cnt] = 0;
48149     }
48150
48151   dfinal = *d;
48152   dfinal.op0 = gen_lowpart (dfinal.vmode, dremap.target);
48153   dfinal.op1 = dfinal.op0;
48154   dfinal.one_operand_p = true;
48155   for (i = 0, j = 0; i < nelt; ++i)
48156     {
48157       if (i == nelt2)
48158         j = 2;
48159       dfinal.perm[i] = (d->perm[i] & (nelt4 - 1)) | (j ? nelt2 : 0);
48160       if ((d->perm[i] / nelt4) == dremap.perm[j])
48161         ;
48162       else if ((d->perm[i] / nelt4) == dremap.perm[j + 1])
48163         dfinal.perm[i] |= nelt4;
48164       else
48165         gcc_unreachable ();
48166     }
48167
48168   ok = expand_vec_perm_1 (&dremap);
48169   gcc_assert (ok);
48170
48171   ok = expand_vec_perm_1 (&dfinal);
48172   gcc_assert (ok);
48173
48174   return true;
48175 }
48176
48177 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to expand
48178    a vector permutation using two instructions, vperm2f128 resp.
48179    vperm2i128 followed by any single in-lane permutation.  */
48180
48181 static bool
48182 expand_vec_perm_vperm2f128 (struct expand_vec_perm_d *d)
48183 {
48184   struct expand_vec_perm_d dfirst, dsecond;
48185   unsigned i, j, nelt = d->nelt, nelt2 = nelt / 2, perm;
48186   bool ok;
48187
48188   if (!TARGET_AVX
48189       || GET_MODE_SIZE (d->vmode) != 32
48190       || (d->vmode != V8SFmode && d->vmode != V4DFmode && !TARGET_AVX2))
48191     return false;
48192
48193   dsecond = *d;
48194   dsecond.one_operand_p = false;
48195   dsecond.testing_p = true;
48196
48197   /* ((perm << 2)|perm) & 0x33 is the vperm2[fi]128
48198      immediate.  For perm < 16 the second permutation uses
48199      d->op0 as first operand, for perm >= 16 it uses d->op1
48200      as first operand.  The second operand is the result of
48201      vperm2[fi]128.  */
48202   for (perm = 0; perm < 32; perm++)
48203     {
48204       /* Ignore permutations which do not move anything cross-lane.  */
48205       if (perm < 16)
48206         {
48207           /* The second shuffle for e.g. V4DFmode has
48208              0123 and ABCD operands.
48209              Ignore AB23, as 23 is already in the second lane
48210              of the first operand.  */
48211           if ((perm & 0xc) == (1 << 2)) continue;
48212           /* And 01CD, as 01 is in the first lane of the first
48213              operand.  */
48214           if ((perm & 3) == 0) continue;
48215           /* And 4567, as then the vperm2[fi]128 doesn't change
48216              anything on the original 4567 second operand.  */
48217           if ((perm & 0xf) == ((3 << 2) | 2)) continue;
48218         }
48219       else
48220         {
48221           /* The second shuffle for e.g. V4DFmode has
48222              4567 and ABCD operands.
48223              Ignore AB67, as 67 is already in the second lane
48224              of the first operand.  */
48225           if ((perm & 0xc) == (3 << 2)) continue;
48226           /* And 45CD, as 45 is in the first lane of the first
48227              operand.  */
48228           if ((perm & 3) == 2) continue;
48229           /* And 0123, as then the vperm2[fi]128 doesn't change
48230              anything on the original 0123 first operand.  */
48231           if ((perm & 0xf) == (1 << 2)) continue;
48232         }
48233
48234       for (i = 0; i < nelt; i++)
48235         {
48236           j = d->perm[i] / nelt2;
48237           if (j == ((perm >> (2 * (i >= nelt2))) & 3))
48238             dsecond.perm[i] = nelt + (i & nelt2) + (d->perm[i] & (nelt2 - 1));
48239           else if (j == (unsigned) (i >= nelt2) + 2 * (perm >= 16))
48240             dsecond.perm[i] = d->perm[i] & (nelt - 1);
48241           else
48242             break;
48243         }
48244
48245       if (i == nelt)
48246         {
48247           start_sequence ();
48248           ok = expand_vec_perm_1 (&dsecond);
48249           end_sequence ();
48250         }
48251       else
48252         ok = false;
48253
48254       if (ok)
48255         {
48256           if (d->testing_p)
48257             return true;
48258
48259           /* Found a usable second shuffle.  dfirst will be
48260              vperm2f128 on d->op0 and d->op1.  */
48261           dsecond.testing_p = false;
48262           dfirst = *d;
48263           dfirst.target = gen_reg_rtx (d->vmode);
48264           for (i = 0; i < nelt; i++)
48265             dfirst.perm[i] = (i & (nelt2 - 1))
48266                              + ((perm >> (2 * (i >= nelt2))) & 3) * nelt2;
48267
48268           canonicalize_perm (&dfirst);
48269           ok = expand_vec_perm_1 (&dfirst);
48270           gcc_assert (ok);
48271
48272           /* And dsecond is some single insn shuffle, taking
48273              d->op0 and result of vperm2f128 (if perm < 16) or
48274              d->op1 and result of vperm2f128 (otherwise).  */
48275           if (perm >= 16)
48276             dsecond.op0 = dsecond.op1;
48277           dsecond.op1 = dfirst.target;
48278
48279           ok = expand_vec_perm_1 (&dsecond);
48280           gcc_assert (ok);
48281
48282           return true;
48283         }
48284
48285       /* For one operand, the only useful vperm2f128 permutation is 0x01
48286          aka lanes swap.  */
48287       if (d->one_operand_p)
48288         return false;
48289     }
48290
48291   return false;
48292 }
48293
48294 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
48295    a two vector permutation using 2 intra-lane interleave insns
48296    and cross-lane shuffle for 32-byte vectors.  */
48297
48298 static bool
48299 expand_vec_perm_interleave3 (struct expand_vec_perm_d *d)
48300 {
48301   unsigned i, nelt;
48302   rtx (*gen) (rtx, rtx, rtx);
48303
48304   if (d->one_operand_p)
48305     return false;
48306   if (TARGET_AVX2 && GET_MODE_SIZE (d->vmode) == 32)
48307     ;
48308   else if (TARGET_AVX && (d->vmode == V8SFmode || d->vmode == V4DFmode))
48309     ;
48310   else
48311     return false;
48312
48313   nelt = d->nelt;
48314   if (d->perm[0] != 0 && d->perm[0] != nelt / 2)
48315     return false;
48316   for (i = 0; i < nelt; i += 2)
48317     if (d->perm[i] != d->perm[0] + i / 2
48318         || d->perm[i + 1] != d->perm[0] + i / 2 + nelt)
48319       return false;
48320
48321   if (d->testing_p)
48322     return true;
48323
48324   switch (d->vmode)
48325     {
48326     case V32QImode:
48327       if (d->perm[0])
48328         gen = gen_vec_interleave_highv32qi;
48329       else
48330         gen = gen_vec_interleave_lowv32qi;
48331       break;
48332     case V16HImode:
48333       if (d->perm[0])
48334         gen = gen_vec_interleave_highv16hi;
48335       else
48336         gen = gen_vec_interleave_lowv16hi;
48337       break;
48338     case V8SImode:
48339       if (d->perm[0])
48340         gen = gen_vec_interleave_highv8si;
48341       else
48342         gen = gen_vec_interleave_lowv8si;
48343       break;
48344     case V4DImode:
48345       if (d->perm[0])
48346         gen = gen_vec_interleave_highv4di;
48347       else
48348         gen = gen_vec_interleave_lowv4di;
48349       break;
48350     case V8SFmode:
48351       if (d->perm[0])
48352         gen = gen_vec_interleave_highv8sf;
48353       else
48354         gen = gen_vec_interleave_lowv8sf;
48355       break;
48356     case V4DFmode:
48357       if (d->perm[0])
48358         gen = gen_vec_interleave_highv4df;
48359       else
48360         gen = gen_vec_interleave_lowv4df;
48361       break;
48362     default:
48363       gcc_unreachable ();
48364     }
48365
48366   emit_insn (gen (d->target, d->op0, d->op1));
48367   return true;
48368 }
48369
48370 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement
48371    a single vector permutation using a single intra-lane vector
48372    permutation, vperm2f128 swapping the lanes and vblend* insn blending
48373    the non-swapped and swapped vectors together.  */
48374
48375 static bool
48376 expand_vec_perm_vperm2f128_vblend (struct expand_vec_perm_d *d)
48377 {
48378   struct expand_vec_perm_d dfirst, dsecond;
48379   unsigned i, j, msk, nelt = d->nelt, nelt2 = nelt / 2;
48380   rtx_insn *seq;
48381   bool ok;
48382   rtx (*blend) (rtx, rtx, rtx, rtx) = NULL;
48383
48384   if (!TARGET_AVX
48385       || TARGET_AVX2
48386       || (d->vmode != V8SFmode && d->vmode != V4DFmode)
48387       || !d->one_operand_p)
48388     return false;
48389
48390   dfirst = *d;
48391   for (i = 0; i < nelt; i++)
48392     dfirst.perm[i] = 0xff;
48393   for (i = 0, msk = 0; i < nelt; i++)
48394     {
48395       j = (d->perm[i] & nelt2) ? i | nelt2 : i & ~nelt2;
48396       if (dfirst.perm[j] != 0xff && dfirst.perm[j] != d->perm[i])
48397         return false;
48398       dfirst.perm[j] = d->perm[i];
48399       if (j != i)
48400         msk |= (1 << i);
48401     }
48402   for (i = 0; i < nelt; i++)
48403     if (dfirst.perm[i] == 0xff)
48404       dfirst.perm[i] = i;
48405
48406   if (!d->testing_p)
48407     dfirst.target = gen_reg_rtx (dfirst.vmode);
48408
48409   start_sequence ();
48410   ok = expand_vec_perm_1 (&dfirst);
48411   seq = get_insns ();
48412   end_sequence ();
48413
48414   if (!ok)
48415     return false;
48416
48417   if (d->testing_p)
48418     return true;
48419
48420   emit_insn (seq);
48421
48422   dsecond = *d;
48423   dsecond.op0 = dfirst.target;
48424   dsecond.op1 = dfirst.target;
48425   dsecond.one_operand_p = true;
48426   dsecond.target = gen_reg_rtx (dsecond.vmode);
48427   for (i = 0; i < nelt; i++)
48428     dsecond.perm[i] = i ^ nelt2;
48429
48430   ok = expand_vec_perm_1 (&dsecond);
48431   gcc_assert (ok);
48432
48433   blend = d->vmode == V8SFmode ? gen_avx_blendps256 : gen_avx_blendpd256;
48434   emit_insn (blend (d->target, dfirst.target, dsecond.target, GEN_INT (msk)));
48435   return true;
48436 }
48437
48438 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement a V4DF
48439    permutation using two vperm2f128, followed by a vshufpd insn blending
48440    the two vectors together.  */
48441
48442 static bool
48443 expand_vec_perm_2vperm2f128_vshuf (struct expand_vec_perm_d *d)
48444 {
48445   struct expand_vec_perm_d dfirst, dsecond, dthird;
48446   bool ok;
48447
48448   if (!TARGET_AVX || (d->vmode != V4DFmode))
48449     return false;
48450
48451   if (d->testing_p)
48452     return true;
48453
48454   dfirst = *d;
48455   dsecond = *d;
48456   dthird = *d;
48457
48458   dfirst.perm[0] = (d->perm[0] & ~1);
48459   dfirst.perm[1] = (d->perm[0] & ~1) + 1;
48460   dfirst.perm[2] = (d->perm[2] & ~1);
48461   dfirst.perm[3] = (d->perm[2] & ~1) + 1;
48462   dsecond.perm[0] = (d->perm[1] & ~1);
48463   dsecond.perm[1] = (d->perm[1] & ~1) + 1;
48464   dsecond.perm[2] = (d->perm[3] & ~1);
48465   dsecond.perm[3] = (d->perm[3] & ~1) + 1;
48466   dthird.perm[0] = (d->perm[0] % 2);
48467   dthird.perm[1] = (d->perm[1] % 2) + 4;
48468   dthird.perm[2] = (d->perm[2] % 2) + 2;
48469   dthird.perm[3] = (d->perm[3] % 2) + 6;
48470
48471   dfirst.target = gen_reg_rtx (dfirst.vmode);
48472   dsecond.target = gen_reg_rtx (dsecond.vmode);
48473   dthird.op0 = dfirst.target;
48474   dthird.op1 = dsecond.target;
48475   dthird.one_operand_p = false;
48476
48477   canonicalize_perm (&dfirst);
48478   canonicalize_perm (&dsecond);
48479
48480   ok = expand_vec_perm_1 (&dfirst)
48481        && expand_vec_perm_1 (&dsecond)
48482        && expand_vec_perm_1 (&dthird);
48483
48484   gcc_assert (ok);
48485
48486   return true;
48487 }
48488
48489 /* A subroutine of expand_vec_perm_even_odd_1.  Implement the double-word
48490    permutation with two pshufb insns and an ior.  We should have already
48491    failed all two instruction sequences.  */
48492
48493 static bool
48494 expand_vec_perm_pshufb2 (struct expand_vec_perm_d *d)
48495 {
48496   rtx rperm[2][16], vperm, l, h, op, m128;
48497   unsigned int i, nelt, eltsz;
48498
48499   if (!TARGET_SSSE3 || GET_MODE_SIZE (d->vmode) != 16)
48500     return false;
48501   gcc_assert (!d->one_operand_p);
48502
48503   if (d->testing_p)
48504     return true;
48505
48506   nelt = d->nelt;
48507   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48508
48509   /* Generate two permutation masks.  If the required element is within
48510      the given vector it is shuffled into the proper lane.  If the required
48511      element is in the other vector, force a zero into the lane by setting
48512      bit 7 in the permutation mask.  */
48513   m128 = GEN_INT (-128);
48514   for (i = 0; i < nelt; ++i)
48515     {
48516       unsigned j, e = d->perm[i];
48517       unsigned which = (e >= nelt);
48518       if (e >= nelt)
48519         e -= nelt;
48520
48521       for (j = 0; j < eltsz; ++j)
48522         {
48523           rperm[which][i*eltsz + j] = GEN_INT (e*eltsz + j);
48524           rperm[1-which][i*eltsz + j] = m128;
48525         }
48526     }
48527
48528   vperm = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, rperm[0]));
48529   vperm = force_reg (V16QImode, vperm);
48530
48531   l = gen_reg_rtx (V16QImode);
48532   op = gen_lowpart (V16QImode, d->op0);
48533   emit_insn (gen_ssse3_pshufbv16qi3 (l, op, vperm));
48534
48535   vperm = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, rperm[1]));
48536   vperm = force_reg (V16QImode, vperm);
48537
48538   h = gen_reg_rtx (V16QImode);
48539   op = gen_lowpart (V16QImode, d->op1);
48540   emit_insn (gen_ssse3_pshufbv16qi3 (h, op, vperm));
48541
48542   op = d->target;
48543   if (d->vmode != V16QImode)
48544     op = gen_reg_rtx (V16QImode);
48545   emit_insn (gen_iorv16qi3 (op, l, h));
48546   if (op != d->target)
48547     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48548
48549   return true;
48550 }
48551
48552 /* Implement arbitrary permutation of one V32QImode and V16QImode operand
48553    with two vpshufb insns, vpermq and vpor.  We should have already failed
48554    all two or three instruction sequences.  */
48555
48556 static bool
48557 expand_vec_perm_vpshufb2_vpermq (struct expand_vec_perm_d *d)
48558 {
48559   rtx rperm[2][32], vperm, l, h, hp, op, m128;
48560   unsigned int i, nelt, eltsz;
48561
48562   if (!TARGET_AVX2
48563       || !d->one_operand_p
48564       || (d->vmode != V32QImode && d->vmode != V16HImode))
48565     return false;
48566
48567   if (d->testing_p)
48568     return true;
48569
48570   nelt = d->nelt;
48571   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48572
48573   /* Generate two permutation masks.  If the required element is within
48574      the same lane, it is shuffled in.  If the required element from the
48575      other lane, force a zero by setting bit 7 in the permutation mask.
48576      In the other mask the mask has non-negative elements if element
48577      is requested from the other lane, but also moved to the other lane,
48578      so that the result of vpshufb can have the two V2TImode halves
48579      swapped.  */
48580   m128 = GEN_INT (-128);
48581   for (i = 0; i < nelt; ++i)
48582     {
48583       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
48584       unsigned which = ((d->perm[i] ^ i) & (nelt / 2)) * eltsz;
48585
48586       for (j = 0; j < eltsz; ++j)
48587         {
48588           rperm[!!which][(i * eltsz + j) ^ which] = GEN_INT (e * eltsz + j);
48589           rperm[!which][(i * eltsz + j) ^ (which ^ 16)] = m128;
48590         }
48591     }
48592
48593   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[1]));
48594   vperm = force_reg (V32QImode, vperm);
48595
48596   h = gen_reg_rtx (V32QImode);
48597   op = gen_lowpart (V32QImode, d->op0);
48598   emit_insn (gen_avx2_pshufbv32qi3 (h, op, vperm));
48599
48600   /* Swap the 128-byte lanes of h into hp.  */
48601   hp = gen_reg_rtx (V4DImode);
48602   op = gen_lowpart (V4DImode, h);
48603   emit_insn (gen_avx2_permv4di_1 (hp, op, const2_rtx, GEN_INT (3), const0_rtx,
48604                                   const1_rtx));
48605
48606   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[0]));
48607   vperm = force_reg (V32QImode, vperm);
48608
48609   l = gen_reg_rtx (V32QImode);
48610   op = gen_lowpart (V32QImode, d->op0);
48611   emit_insn (gen_avx2_pshufbv32qi3 (l, op, vperm));
48612
48613   op = d->target;
48614   if (d->vmode != V32QImode)
48615     op = gen_reg_rtx (V32QImode);
48616   emit_insn (gen_iorv32qi3 (op, l, gen_lowpart (V32QImode, hp)));
48617   if (op != d->target)
48618     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48619
48620   return true;
48621 }
48622
48623 /* A subroutine of expand_vec_perm_even_odd_1.  Implement extract-even
48624    and extract-odd permutations of two V32QImode and V16QImode operand
48625    with two vpshufb insns, vpor and vpermq.  We should have already
48626    failed all two or three instruction sequences.  */
48627
48628 static bool
48629 expand_vec_perm_vpshufb2_vpermq_even_odd (struct expand_vec_perm_d *d)
48630 {
48631   rtx rperm[2][32], vperm, l, h, ior, op, m128;
48632   unsigned int i, nelt, eltsz;
48633
48634   if (!TARGET_AVX2
48635       || d->one_operand_p
48636       || (d->vmode != V32QImode && d->vmode != V16HImode))
48637     return false;
48638
48639   for (i = 0; i < d->nelt; ++i)
48640     if ((d->perm[i] ^ (i * 2)) & (3 * d->nelt / 2))
48641       return false;
48642
48643   if (d->testing_p)
48644     return true;
48645
48646   nelt = d->nelt;
48647   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48648
48649   /* Generate two permutation masks.  In the first permutation mask
48650      the first quarter will contain indexes for the first half
48651      of the op0, the second quarter will contain bit 7 set, third quarter
48652      will contain indexes for the second half of the op0 and the
48653      last quarter bit 7 set.  In the second permutation mask
48654      the first quarter will contain bit 7 set, the second quarter
48655      indexes for the first half of the op1, the third quarter bit 7 set
48656      and last quarter indexes for the second half of the op1.
48657      I.e. the first mask e.g. for V32QImode extract even will be:
48658      0, 2, ..., 0xe, -128, ..., -128, 0, 2, ..., 0xe, -128, ..., -128
48659      (all values masked with 0xf except for -128) and second mask
48660      for extract even will be
48661      -128, ..., -128, 0, 2, ..., 0xe, -128, ..., -128, 0, 2, ..., 0xe.  */
48662   m128 = GEN_INT (-128);
48663   for (i = 0; i < nelt; ++i)
48664     {
48665       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
48666       unsigned which = d->perm[i] >= nelt;
48667       unsigned xorv = (i >= nelt / 4 && i < 3 * nelt / 4) ? 24 : 0;
48668
48669       for (j = 0; j < eltsz; ++j)
48670         {
48671           rperm[which][(i * eltsz + j) ^ xorv] = GEN_INT (e * eltsz + j);
48672           rperm[1 - which][(i * eltsz + j) ^ xorv] = m128;
48673         }
48674     }
48675
48676   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[0]));
48677   vperm = force_reg (V32QImode, vperm);
48678
48679   l = gen_reg_rtx (V32QImode);
48680   op = gen_lowpart (V32QImode, d->op0);
48681   emit_insn (gen_avx2_pshufbv32qi3 (l, op, vperm));
48682
48683   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[1]));
48684   vperm = force_reg (V32QImode, vperm);
48685
48686   h = gen_reg_rtx (V32QImode);
48687   op = gen_lowpart (V32QImode, d->op1);
48688   emit_insn (gen_avx2_pshufbv32qi3 (h, op, vperm));
48689
48690   ior = gen_reg_rtx (V32QImode);
48691   emit_insn (gen_iorv32qi3 (ior, l, h));
48692
48693   /* Permute the V4DImode quarters using { 0, 2, 1, 3 } permutation.  */
48694   op = gen_reg_rtx (V4DImode);
48695   ior = gen_lowpart (V4DImode, ior);
48696   emit_insn (gen_avx2_permv4di_1 (op, ior, const0_rtx, const2_rtx,
48697                                   const1_rtx, GEN_INT (3)));
48698   emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48699
48700   return true;
48701 }
48702
48703 /* A subroutine of expand_vec_perm_even_odd_1.  Implement extract-even
48704    and extract-odd permutations of two V16QI, V8HI, V16HI or V32QI operands
48705    with two "and" and "pack" or two "shift" and "pack" insns.  We should
48706    have already failed all two instruction sequences.  */
48707
48708 static bool
48709 expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d)
48710 {
48711   rtx op, dop0, dop1, t, rperm[16];
48712   unsigned i, odd, c, s, nelt = d->nelt;
48713   bool end_perm = false;
48714   machine_mode half_mode;
48715   rtx (*gen_and) (rtx, rtx, rtx);
48716   rtx (*gen_pack) (rtx, rtx, rtx);
48717   rtx (*gen_shift) (rtx, rtx, rtx);
48718
48719   if (d->one_operand_p)
48720     return false;
48721
48722   switch (d->vmode)
48723     {
48724     case V8HImode:
48725       /* Required for "pack".  */
48726       if (!TARGET_SSE4_1)
48727         return false;
48728       c = 0xffff;
48729       s = 16;
48730       half_mode = V4SImode;
48731       gen_and = gen_andv4si3;
48732       gen_pack = gen_sse4_1_packusdw;
48733       gen_shift = gen_lshrv4si3;
48734       break;
48735     case V16QImode:
48736       /* No check as all instructions are SSE2.  */
48737       c = 0xff;
48738       s = 8;
48739       half_mode = V8HImode;
48740       gen_and = gen_andv8hi3;
48741       gen_pack = gen_sse2_packuswb;
48742       gen_shift = gen_lshrv8hi3;
48743       break;
48744     case V16HImode:
48745       if (!TARGET_AVX2)
48746         return false;
48747       c = 0xffff;
48748       s = 16;
48749       half_mode = V8SImode;
48750       gen_and = gen_andv8si3;
48751       gen_pack = gen_avx2_packusdw;
48752       gen_shift = gen_lshrv8si3;
48753       end_perm = true;
48754       break;
48755     case V32QImode:
48756       if (!TARGET_AVX2)
48757         return false;
48758       c = 0xff;
48759       s = 8;
48760       half_mode = V16HImode;
48761       gen_and = gen_andv16hi3;
48762       gen_pack = gen_avx2_packuswb;
48763       gen_shift = gen_lshrv16hi3;
48764       end_perm = true;
48765       break;
48766     default:
48767       /* Only V8HI, V16QI, V16HI and V32QI modes are more profitable than
48768          general shuffles.  */
48769       return false;
48770     }
48771
48772   /* Check that permutation is even or odd.  */
48773   odd = d->perm[0];
48774   if (odd > 1)
48775     return false;
48776
48777   for (i = 1; i < nelt; ++i)
48778     if (d->perm[i] != 2 * i + odd)
48779       return false;
48780
48781   if (d->testing_p)
48782     return true;
48783
48784   dop0 = gen_reg_rtx (half_mode);
48785   dop1 = gen_reg_rtx (half_mode);
48786   if (odd == 0)
48787     {
48788       for (i = 0; i < nelt / 2; i++)
48789         rperm[i] = GEN_INT (c);
48790       t = gen_rtx_CONST_VECTOR (half_mode, gen_rtvec_v (nelt / 2, rperm));
48791       t = force_reg (half_mode, t);
48792       emit_insn (gen_and (dop0, t, gen_lowpart (half_mode, d->op0)));
48793       emit_insn (gen_and (dop1, t, gen_lowpart (half_mode, d->op1)));
48794     }
48795   else
48796     {
48797       emit_insn (gen_shift (dop0,
48798                             gen_lowpart (half_mode, d->op0),
48799                             GEN_INT (s)));
48800       emit_insn (gen_shift (dop1,
48801                             gen_lowpart (half_mode, d->op1),
48802                             GEN_INT (s)));
48803     }
48804   /* In AVX2 for 256 bit case we need to permute pack result.  */
48805   if (TARGET_AVX2 && end_perm)
48806     {
48807       op = gen_reg_rtx (d->vmode);
48808       t = gen_reg_rtx (V4DImode);
48809       emit_insn (gen_pack (op, dop0, dop1));
48810       emit_insn (gen_avx2_permv4di_1 (t,
48811                                       gen_lowpart (V4DImode, op),
48812                                       const0_rtx,
48813                                       const2_rtx,
48814                                       const1_rtx,
48815                                       GEN_INT (3)));
48816       emit_move_insn (d->target, gen_lowpart (d->vmode, t));
48817     }
48818   else
48819     emit_insn (gen_pack (d->target, dop0, dop1));
48820
48821   return true;
48822 }
48823
48824 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement extract-even
48825    and extract-odd permutations.  */
48826
48827 static bool
48828 expand_vec_perm_even_odd_1 (struct expand_vec_perm_d *d, unsigned odd)
48829 {
48830   rtx t1, t2, t3, t4, t5;
48831
48832   switch (d->vmode)
48833     {
48834     case V4DFmode:
48835       if (d->testing_p)
48836         break;
48837       t1 = gen_reg_rtx (V4DFmode);
48838       t2 = gen_reg_rtx (V4DFmode);
48839
48840       /* Shuffle the lanes around into { 0 1 4 5 } and { 2 3 6 7 }.  */
48841       emit_insn (gen_avx_vperm2f128v4df3 (t1, d->op0, d->op1, GEN_INT (0x20)));
48842       emit_insn (gen_avx_vperm2f128v4df3 (t2, d->op0, d->op1, GEN_INT (0x31)));
48843
48844       /* Now an unpck[lh]pd will produce the result required.  */
48845       if (odd)
48846         t3 = gen_avx_unpckhpd256 (d->target, t1, t2);
48847       else
48848         t3 = gen_avx_unpcklpd256 (d->target, t1, t2);
48849       emit_insn (t3);
48850       break;
48851
48852     case V8SFmode:
48853       {
48854         int mask = odd ? 0xdd : 0x88;
48855
48856         if (d->testing_p)
48857           break;
48858         t1 = gen_reg_rtx (V8SFmode);
48859         t2 = gen_reg_rtx (V8SFmode);
48860         t3 = gen_reg_rtx (V8SFmode);
48861
48862         /* Shuffle within the 128-bit lanes to produce:
48863            { 0 2 8 a 4 6 c e } | { 1 3 9 b 5 7 d f }.  */
48864         emit_insn (gen_avx_shufps256 (t1, d->op0, d->op1,
48865                                       GEN_INT (mask)));
48866
48867         /* Shuffle the lanes around to produce:
48868            { 4 6 c e 0 2 8 a } and { 5 7 d f 1 3 9 b }.  */
48869         emit_insn (gen_avx_vperm2f128v8sf3 (t2, t1, t1,
48870                                             GEN_INT (0x3)));
48871
48872         /* Shuffle within the 128-bit lanes to produce:
48873            { 0 2 4 6 4 6 0 2 } | { 1 3 5 7 5 7 1 3 }.  */
48874         emit_insn (gen_avx_shufps256 (t3, t1, t2, GEN_INT (0x44)));
48875
48876         /* Shuffle within the 128-bit lanes to produce:
48877            { 8 a c e c e 8 a } | { 9 b d f d f 9 b }.  */
48878         emit_insn (gen_avx_shufps256 (t2, t1, t2, GEN_INT (0xee)));
48879
48880         /* Shuffle the lanes around to produce:
48881            { 0 2 4 6 8 a c e } | { 1 3 5 7 9 b d f }.  */
48882         emit_insn (gen_avx_vperm2f128v8sf3 (d->target, t3, t2,
48883                                             GEN_INT (0x20)));
48884       }
48885       break;
48886
48887     case V2DFmode:
48888     case V4SFmode:
48889     case V2DImode:
48890     case V4SImode:
48891       /* These are always directly implementable by expand_vec_perm_1.  */
48892       gcc_unreachable ();
48893
48894     case V8HImode:
48895       if (TARGET_SSE4_1)
48896         return expand_vec_perm_even_odd_pack (d);
48897       else if (TARGET_SSSE3 && !TARGET_SLOW_PSHUFB)
48898         return expand_vec_perm_pshufb2 (d);
48899       else
48900         {
48901           if (d->testing_p)
48902             break;
48903           /* We need 2*log2(N)-1 operations to achieve odd/even
48904              with interleave. */
48905           t1 = gen_reg_rtx (V8HImode);
48906           t2 = gen_reg_rtx (V8HImode);
48907           emit_insn (gen_vec_interleave_highv8hi (t1, d->op0, d->op1));
48908           emit_insn (gen_vec_interleave_lowv8hi (d->target, d->op0, d->op1));
48909           emit_insn (gen_vec_interleave_highv8hi (t2, d->target, t1));
48910           emit_insn (gen_vec_interleave_lowv8hi (d->target, d->target, t1));
48911           if (odd)
48912             t3 = gen_vec_interleave_highv8hi (d->target, d->target, t2);
48913           else
48914             t3 = gen_vec_interleave_lowv8hi (d->target, d->target, t2);
48915           emit_insn (t3);
48916         }
48917       break;
48918
48919     case V16QImode:
48920       return expand_vec_perm_even_odd_pack (d);
48921
48922     case V16HImode:
48923     case V32QImode:
48924       return expand_vec_perm_even_odd_pack (d);
48925
48926     case V4DImode:
48927       if (!TARGET_AVX2)
48928         {
48929           struct expand_vec_perm_d d_copy = *d;
48930           d_copy.vmode = V4DFmode;
48931           if (d->testing_p)
48932             d_copy.target = gen_lowpart (V4DFmode, d->target);
48933           else
48934             d_copy.target = gen_reg_rtx (V4DFmode);
48935           d_copy.op0 = gen_lowpart (V4DFmode, d->op0);
48936           d_copy.op1 = gen_lowpart (V4DFmode, d->op1);
48937           if (expand_vec_perm_even_odd_1 (&d_copy, odd))
48938             {
48939               if (!d->testing_p)
48940                 emit_move_insn (d->target,
48941                                 gen_lowpart (V4DImode, d_copy.target));
48942               return true;
48943             }
48944           return false;
48945         }
48946
48947       if (d->testing_p)
48948         break;
48949
48950       t1 = gen_reg_rtx (V4DImode);
48951       t2 = gen_reg_rtx (V4DImode);
48952
48953       /* Shuffle the lanes around into { 0 1 4 5 } and { 2 3 6 7 }.  */
48954       emit_insn (gen_avx2_permv2ti (t1, d->op0, d->op1, GEN_INT (0x20)));
48955       emit_insn (gen_avx2_permv2ti (t2, d->op0, d->op1, GEN_INT (0x31)));
48956
48957       /* Now an vpunpck[lh]qdq will produce the result required.  */
48958       if (odd)
48959         t3 = gen_avx2_interleave_highv4di (d->target, t1, t2);
48960       else
48961         t3 = gen_avx2_interleave_lowv4di (d->target, t1, t2);
48962       emit_insn (t3);
48963       break;
48964
48965     case V8SImode:
48966       if (!TARGET_AVX2)
48967         {
48968           struct expand_vec_perm_d d_copy = *d;
48969           d_copy.vmode = V8SFmode;
48970           if (d->testing_p)
48971             d_copy.target = gen_lowpart (V8SFmode, d->target);
48972           else
48973             d_copy.target = gen_reg_rtx (V8SFmode);
48974           d_copy.op0 = gen_lowpart (V8SFmode, d->op0);
48975           d_copy.op1 = gen_lowpart (V8SFmode, d->op1);
48976           if (expand_vec_perm_even_odd_1 (&d_copy, odd))
48977             {
48978               if (!d->testing_p)
48979                 emit_move_insn (d->target,
48980                                 gen_lowpart (V8SImode, d_copy.target));
48981               return true;
48982             }
48983           return false;
48984         }
48985
48986       if (d->testing_p)
48987         break;
48988
48989       t1 = gen_reg_rtx (V8SImode);
48990       t2 = gen_reg_rtx (V8SImode);
48991       t3 = gen_reg_rtx (V4DImode);
48992       t4 = gen_reg_rtx (V4DImode);
48993       t5 = gen_reg_rtx (V4DImode);
48994
48995       /* Shuffle the lanes around into
48996          { 0 1 2 3 8 9 a b } and { 4 5 6 7 c d e f }.  */
48997       emit_insn (gen_avx2_permv2ti (t3, gen_lowpart (V4DImode, d->op0),
48998                                     gen_lowpart (V4DImode, d->op1),
48999                                     GEN_INT (0x20)));
49000       emit_insn (gen_avx2_permv2ti (t4, gen_lowpart (V4DImode, d->op0),
49001                                     gen_lowpart (V4DImode, d->op1),
49002                                     GEN_INT (0x31)));
49003
49004       /* Swap the 2nd and 3rd position in each lane into
49005          { 0 2 1 3 8 a 9 b } and { 4 6 5 7 c e d f }.  */
49006       emit_insn (gen_avx2_pshufdv3 (t1, gen_lowpart (V8SImode, t3),
49007                                     GEN_INT (2 * 4 + 1 * 16 + 3 * 64)));
49008       emit_insn (gen_avx2_pshufdv3 (t2, gen_lowpart (V8SImode, t4),
49009                                     GEN_INT (2 * 4 + 1 * 16 + 3 * 64)));
49010
49011       /* Now an vpunpck[lh]qdq will produce
49012          { 0 2 4 6 8 a c e } resp. { 1 3 5 7 9 b d f }.  */
49013       if (odd)
49014         t3 = gen_avx2_interleave_highv4di (t5, gen_lowpart (V4DImode, t1),
49015                                            gen_lowpart (V4DImode, t2));
49016       else
49017         t3 = gen_avx2_interleave_lowv4di (t5, gen_lowpart (V4DImode, t1),
49018                                           gen_lowpart (V4DImode, t2));
49019       emit_insn (t3);
49020       emit_move_insn (d->target, gen_lowpart (V8SImode, t5));
49021       break;
49022
49023     default:
49024       gcc_unreachable ();
49025     }
49026
49027   return true;
49028 }
49029
49030 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Pattern match
49031    extract-even and extract-odd permutations.  */
49032
49033 static bool
49034 expand_vec_perm_even_odd (struct expand_vec_perm_d *d)
49035 {
49036   unsigned i, odd, nelt = d->nelt;
49037
49038   odd = d->perm[0];
49039   if (odd != 0 && odd != 1)
49040     return false;
49041
49042   for (i = 1; i < nelt; ++i)
49043     if (d->perm[i] != 2 * i + odd)
49044       return false;
49045
49046   return expand_vec_perm_even_odd_1 (d, odd);
49047 }
49048
49049 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement broadcast
49050    permutations.  We assume that expand_vec_perm_1 has already failed.  */
49051
49052 static bool
49053 expand_vec_perm_broadcast_1 (struct expand_vec_perm_d *d)
49054 {
49055   unsigned elt = d->perm[0], nelt2 = d->nelt / 2;
49056   machine_mode vmode = d->vmode;
49057   unsigned char perm2[4];
49058   rtx op0 = d->op0, dest;
49059   bool ok;
49060
49061   switch (vmode)
49062     {
49063     case V4DFmode:
49064     case V8SFmode:
49065       /* These are special-cased in sse.md so that we can optionally
49066          use the vbroadcast instruction.  They expand to two insns
49067          if the input happens to be in a register.  */
49068       gcc_unreachable ();
49069
49070     case V2DFmode:
49071     case V2DImode:
49072     case V4SFmode:
49073     case V4SImode:
49074       /* These are always implementable using standard shuffle patterns.  */
49075       gcc_unreachable ();
49076
49077     case V8HImode:
49078     case V16QImode:
49079       /* These can be implemented via interleave.  We save one insn by
49080          stopping once we have promoted to V4SImode and then use pshufd.  */
49081       if (d->testing_p)
49082         return true;
49083       do
49084         {
49085           rtx dest;
49086           rtx (*gen) (rtx, rtx, rtx)
49087             = vmode == V16QImode ? gen_vec_interleave_lowv16qi
49088                                  : gen_vec_interleave_lowv8hi;
49089
49090           if (elt >= nelt2)
49091             {
49092               gen = vmode == V16QImode ? gen_vec_interleave_highv16qi
49093                                        : gen_vec_interleave_highv8hi;
49094               elt -= nelt2;
49095             }
49096           nelt2 /= 2;
49097
49098           dest = gen_reg_rtx (vmode);
49099           emit_insn (gen (dest, op0, op0));
49100           vmode = get_mode_wider_vector (vmode);
49101           op0 = gen_lowpart (vmode, dest);
49102         }
49103       while (vmode != V4SImode);
49104
49105       memset (perm2, elt, 4);
49106       dest = gen_reg_rtx (V4SImode);
49107       ok = expand_vselect (dest, op0, perm2, 4, d->testing_p);
49108       gcc_assert (ok);
49109       if (!d->testing_p)
49110         emit_move_insn (d->target, gen_lowpart (d->vmode, dest));
49111       return true;
49112
49113     case V64QImode:
49114     case V32QImode:
49115     case V16HImode:
49116     case V8SImode:
49117     case V4DImode:
49118       /* For AVX2 broadcasts of the first element vpbroadcast* or
49119          vpermq should be used by expand_vec_perm_1.  */
49120       gcc_assert (!TARGET_AVX2 || d->perm[0]);
49121       return false;
49122
49123     default:
49124       gcc_unreachable ();
49125     }
49126 }
49127
49128 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Pattern match
49129    broadcast permutations.  */
49130
49131 static bool
49132 expand_vec_perm_broadcast (struct expand_vec_perm_d *d)
49133 {
49134   unsigned i, elt, nelt = d->nelt;
49135
49136   if (!d->one_operand_p)
49137     return false;
49138
49139   elt = d->perm[0];
49140   for (i = 1; i < nelt; ++i)
49141     if (d->perm[i] != elt)
49142       return false;
49143
49144   return expand_vec_perm_broadcast_1 (d);
49145 }
49146
49147 /* Implement arbitrary permutations of two V64QImode operands
49148    will 2 vpermi2w, 2 vpshufb and one vpor instruction.  */
49149 static bool
49150 expand_vec_perm_vpermi2_vpshub2 (struct expand_vec_perm_d *d)
49151 {
49152   if (!TARGET_AVX512BW || !(d->vmode == V64QImode))
49153     return false;
49154
49155   if (d->testing_p)
49156     return true;
49157
49158   struct expand_vec_perm_d ds[2];
49159   rtx rperm[128], vperm, target0, target1;
49160   unsigned int i, nelt;
49161   machine_mode vmode;
49162
49163   nelt = d->nelt;
49164   vmode = V64QImode;
49165
49166   for (i = 0; i < 2; i++)
49167     {
49168       ds[i] = *d;
49169       ds[i].vmode = V32HImode;
49170       ds[i].nelt = 32;
49171       ds[i].target = gen_reg_rtx (V32HImode);
49172       ds[i].op0 = gen_lowpart (V32HImode, d->op0);
49173       ds[i].op1 = gen_lowpart (V32HImode, d->op1);
49174     }
49175
49176   /* Prepare permutations such that the first one takes care of
49177      putting the even bytes into the right positions or one higher
49178      positions (ds[0]) and the second one takes care of
49179      putting the odd bytes into the right positions or one below
49180      (ds[1]).  */
49181
49182   for (i = 0; i < nelt; i++)
49183     {
49184       ds[i & 1].perm[i / 2] = d->perm[i] / 2;
49185       if (i & 1)
49186         {
49187           rperm[i] = constm1_rtx;
49188           rperm[i + 64] = GEN_INT ((i & 14) + (d->perm[i] & 1));
49189         }
49190       else
49191         {
49192           rperm[i] = GEN_INT ((i & 14) + (d->perm[i] & 1));
49193           rperm[i + 64] = constm1_rtx;
49194         }
49195     }
49196
49197   bool ok = expand_vec_perm_1 (&ds[0]);
49198   gcc_assert (ok);
49199   ds[0].target = gen_lowpart (V64QImode, ds[0].target);
49200
49201   ok = expand_vec_perm_1 (&ds[1]);
49202   gcc_assert (ok);
49203   ds[1].target = gen_lowpart (V64QImode, ds[1].target);
49204
49205   vperm = gen_rtx_CONST_VECTOR (V64QImode, gen_rtvec_v (64, rperm));
49206   vperm = force_reg (vmode, vperm);
49207   target0 = gen_reg_rtx (V64QImode);
49208   emit_insn (gen_avx512bw_pshufbv64qi3 (target0, ds[0].target, vperm));
49209
49210   vperm = gen_rtx_CONST_VECTOR (V64QImode, gen_rtvec_v (64, rperm + 64));
49211   vperm = force_reg (vmode, vperm);
49212   target1 = gen_reg_rtx (V64QImode);
49213   emit_insn (gen_avx512bw_pshufbv64qi3 (target1, ds[1].target, vperm));
49214
49215   emit_insn (gen_iorv64qi3 (d->target, target0, target1));
49216   return true;
49217 }
49218
49219 /* Implement arbitrary permutation of two V32QImode and V16QImode operands
49220    with 4 vpshufb insns, 2 vpermq and 3 vpor.  We should have already failed
49221    all the shorter instruction sequences.  */
49222
49223 static bool
49224 expand_vec_perm_vpshufb4_vpermq2 (struct expand_vec_perm_d *d)
49225 {
49226   rtx rperm[4][32], vperm, l[2], h[2], op, m128;
49227   unsigned int i, nelt, eltsz;
49228   bool used[4];
49229
49230   if (!TARGET_AVX2
49231       || d->one_operand_p
49232       || (d->vmode != V32QImode && d->vmode != V16HImode))
49233     return false;
49234
49235   if (d->testing_p)
49236     return true;
49237
49238   nelt = d->nelt;
49239   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
49240
49241   /* Generate 4 permutation masks.  If the required element is within
49242      the same lane, it is shuffled in.  If the required element from the
49243      other lane, force a zero by setting bit 7 in the permutation mask.
49244      In the other mask the mask has non-negative elements if element
49245      is requested from the other lane, but also moved to the other lane,
49246      so that the result of vpshufb can have the two V2TImode halves
49247      swapped.  */
49248   m128 = GEN_INT (-128);
49249   for (i = 0; i < 32; ++i)
49250     {
49251       rperm[0][i] = m128;
49252       rperm[1][i] = m128;
49253       rperm[2][i] = m128;
49254       rperm[3][i] = m128;
49255     }
49256   used[0] = false;
49257   used[1] = false;
49258   used[2] = false;
49259   used[3] = false;
49260   for (i = 0; i < nelt; ++i)
49261     {
49262       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
49263       unsigned xlane = ((d->perm[i] ^ i) & (nelt / 2)) * eltsz;
49264       unsigned int which = ((d->perm[i] & nelt) ? 2 : 0) + (xlane ? 1 : 0);
49265
49266       for (j = 0; j < eltsz; ++j)
49267         rperm[which][(i * eltsz + j) ^ xlane] = GEN_INT (e * eltsz + j);
49268       used[which] = true;
49269     }
49270
49271   for (i = 0; i < 2; ++i)
49272     {
49273       if (!used[2 * i + 1])
49274         {
49275           h[i] = NULL_RTX;
49276           continue;
49277         }
49278       vperm = gen_rtx_CONST_VECTOR (V32QImode,
49279                                     gen_rtvec_v (32, rperm[2 * i + 1]));
49280       vperm = force_reg (V32QImode, vperm);
49281       h[i] = gen_reg_rtx (V32QImode);
49282       op = gen_lowpart (V32QImode, i ? d->op1 : d->op0);
49283       emit_insn (gen_avx2_pshufbv32qi3 (h[i], op, vperm));
49284     }
49285
49286   /* Swap the 128-byte lanes of h[X].  */
49287   for (i = 0; i < 2; ++i)
49288    {
49289      if (h[i] == NULL_RTX)
49290        continue;
49291      op = gen_reg_rtx (V4DImode);
49292      emit_insn (gen_avx2_permv4di_1 (op, gen_lowpart (V4DImode, h[i]),
49293                                      const2_rtx, GEN_INT (3), const0_rtx,
49294                                      const1_rtx));
49295      h[i] = gen_lowpart (V32QImode, op);
49296    }
49297
49298   for (i = 0; i < 2; ++i)
49299     {
49300       if (!used[2 * i])
49301         {
49302           l[i] = NULL_RTX;
49303           continue;
49304         }
49305       vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[2 * i]));
49306       vperm = force_reg (V32QImode, vperm);
49307       l[i] = gen_reg_rtx (V32QImode);
49308       op = gen_lowpart (V32QImode, i ? d->op1 : d->op0);
49309       emit_insn (gen_avx2_pshufbv32qi3 (l[i], op, vperm));
49310     }
49311
49312   for (i = 0; i < 2; ++i)
49313     {
49314       if (h[i] && l[i])
49315         {
49316           op = gen_reg_rtx (V32QImode);
49317           emit_insn (gen_iorv32qi3 (op, l[i], h[i]));
49318           l[i] = op;
49319         }
49320       else if (h[i])
49321         l[i] = h[i];
49322     }
49323
49324   gcc_assert (l[0] && l[1]);
49325   op = d->target;
49326   if (d->vmode != V32QImode)
49327     op = gen_reg_rtx (V32QImode);
49328   emit_insn (gen_iorv32qi3 (op, l[0], l[1]));
49329   if (op != d->target)
49330     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
49331   return true;
49332 }
49333
49334 /* The guts of ix86_expand_vec_perm_const, also used by the ok hook.
49335    With all of the interface bits taken care of, perform the expansion
49336    in D and return true on success.  */
49337
49338 static bool
49339 ix86_expand_vec_perm_const_1 (struct expand_vec_perm_d *d)
49340 {
49341   /* Try a single instruction expansion.  */
49342   if (expand_vec_perm_1 (d))
49343     return true;
49344
49345   /* Try sequences of two instructions.  */
49346
49347   if (expand_vec_perm_pshuflw_pshufhw (d))
49348     return true;
49349
49350   if (expand_vec_perm_palignr (d, false))
49351     return true;
49352
49353   if (expand_vec_perm_interleave2 (d))
49354     return true;
49355
49356   if (expand_vec_perm_broadcast (d))
49357     return true;
49358
49359   if (expand_vec_perm_vpermq_perm_1 (d))
49360     return true;
49361
49362   if (expand_vec_perm_vperm2f128 (d))
49363     return true;
49364
49365   if (expand_vec_perm_pblendv (d))
49366     return true;
49367
49368   /* Try sequences of three instructions.  */
49369
49370   if (expand_vec_perm_even_odd_pack (d))
49371     return true;
49372
49373   if (expand_vec_perm_2vperm2f128_vshuf (d))
49374     return true;
49375
49376   if (expand_vec_perm_pshufb2 (d))
49377     return true;
49378
49379   if (expand_vec_perm_interleave3 (d))
49380     return true;
49381
49382   if (expand_vec_perm_vperm2f128_vblend (d))
49383     return true;
49384
49385   /* Try sequences of four instructions.  */
49386
49387   if (expand_vec_perm_vpshufb2_vpermq (d))
49388     return true;
49389
49390   if (expand_vec_perm_vpshufb2_vpermq_even_odd (d))
49391     return true;
49392
49393   if (expand_vec_perm_vpermi2_vpshub2 (d))
49394     return true;
49395
49396   /* ??? Look for narrow permutations whose element orderings would
49397      allow the promotion to a wider mode.  */
49398
49399   /* ??? Look for sequences of interleave or a wider permute that place
49400      the data into the correct lanes for a half-vector shuffle like
49401      pshuf[lh]w or vpermilps.  */
49402
49403   /* ??? Look for sequences of interleave that produce the desired results.
49404      The combinatorics of punpck[lh] get pretty ugly... */
49405
49406   if (expand_vec_perm_even_odd (d))
49407     return true;
49408
49409   /* Even longer sequences.  */
49410   if (expand_vec_perm_vpshufb4_vpermq2 (d))
49411     return true;
49412
49413   return false;
49414 }
49415
49416 /* If a permutation only uses one operand, make it clear. Returns true
49417    if the permutation references both operands.  */
49418
49419 static bool
49420 canonicalize_perm (struct expand_vec_perm_d *d)
49421 {
49422   int i, which, nelt = d->nelt;
49423
49424   for (i = which = 0; i < nelt; ++i)
49425       which |= (d->perm[i] < nelt ? 1 : 2);
49426
49427   d->one_operand_p = true;
49428   switch (which)
49429     {
49430     default:
49431       gcc_unreachable();
49432
49433     case 3:
49434       if (!rtx_equal_p (d->op0, d->op1))
49435         {
49436           d->one_operand_p = false;
49437           break;
49438         }
49439       /* The elements of PERM do not suggest that only the first operand
49440          is used, but both operands are identical.  Allow easier matching
49441          of the permutation by folding the permutation into the single
49442          input vector.  */
49443       /* FALLTHRU */
49444
49445     case 2:
49446       for (i = 0; i < nelt; ++i)
49447         d->perm[i] &= nelt - 1;
49448       d->op0 = d->op1;
49449       break;
49450
49451     case 1:
49452       d->op1 = d->op0;
49453       break;
49454     }
49455
49456   return (which == 3);
49457 }
49458
49459 bool
49460 ix86_expand_vec_perm_const (rtx operands[4])
49461 {
49462   struct expand_vec_perm_d d;
49463   unsigned char perm[MAX_VECT_LEN];
49464   int i, nelt;
49465   bool two_args;
49466   rtx sel;
49467
49468   d.target = operands[0];
49469   d.op0 = operands[1];
49470   d.op1 = operands[2];
49471   sel = operands[3];
49472
49473   d.vmode = GET_MODE (d.target);
49474   gcc_assert (VECTOR_MODE_P (d.vmode));
49475   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49476   d.testing_p = false;
49477
49478   gcc_assert (GET_CODE (sel) == CONST_VECTOR);
49479   gcc_assert (XVECLEN (sel, 0) == nelt);
49480   gcc_checking_assert (sizeof (d.perm) == sizeof (perm));
49481
49482   for (i = 0; i < nelt; ++i)
49483     {
49484       rtx e = XVECEXP (sel, 0, i);
49485       int ei = INTVAL (e) & (2 * nelt - 1);
49486       d.perm[i] = ei;
49487       perm[i] = ei;
49488     }
49489
49490   two_args = canonicalize_perm (&d);
49491
49492   if (ix86_expand_vec_perm_const_1 (&d))
49493     return true;
49494
49495   /* If the selector says both arguments are needed, but the operands are the
49496      same, the above tried to expand with one_operand_p and flattened selector.
49497      If that didn't work, retry without one_operand_p; we succeeded with that
49498      during testing.  */
49499   if (two_args && d.one_operand_p)
49500     {
49501       d.one_operand_p = false;
49502       memcpy (d.perm, perm, sizeof (perm));
49503       return ix86_expand_vec_perm_const_1 (&d);
49504     }
49505
49506   return false;
49507 }
49508
49509 /* Implement targetm.vectorize.vec_perm_const_ok.  */
49510
49511 static bool
49512 ix86_vectorize_vec_perm_const_ok (machine_mode vmode,
49513                                   const unsigned char *sel)
49514 {
49515   struct expand_vec_perm_d d;
49516   unsigned int i, nelt, which;
49517   bool ret;
49518
49519   d.vmode = vmode;
49520   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49521   d.testing_p = true;
49522
49523   /* Given sufficient ISA support we can just return true here
49524      for selected vector modes.  */
49525   switch (d.vmode)
49526     {
49527     case V16SFmode:
49528     case V16SImode:
49529     case V8DImode:
49530     case V8DFmode:
49531       if (TARGET_AVX512F)
49532         /* All implementable with a single vpermi2 insn.  */
49533         return true;
49534       break;
49535     case V32HImode:
49536       if (TARGET_AVX512BW)
49537         /* All implementable with a single vpermi2 insn.  */
49538         return true;
49539       break;
49540     case V64QImode:
49541       if (TARGET_AVX512BW)
49542         /* Implementable with 2 vpermi2, 2 vpshufb and 1 or insn.  */
49543         return true;
49544       break;
49545     case V8SImode:
49546     case V8SFmode:
49547     case V4DFmode:
49548     case V4DImode:
49549       if (TARGET_AVX512VL)
49550         /* All implementable with a single vpermi2 insn.  */
49551         return true;
49552       break;
49553     case V16HImode:
49554       if (TARGET_AVX2)
49555         /* Implementable with 4 vpshufb insns, 2 vpermq and 3 vpor insns.  */
49556         return true;
49557       break;
49558     case V32QImode:
49559       if (TARGET_AVX2)
49560         /* Implementable with 4 vpshufb insns, 2 vpermq and 3 vpor insns.  */
49561         return true;
49562       break;
49563     case V4SImode:
49564     case V4SFmode:
49565     case V8HImode:
49566     case V16QImode:
49567       /* All implementable with a single vpperm insn.  */
49568       if (TARGET_XOP)
49569         return true;
49570       /* All implementable with 2 pshufb + 1 ior.  */
49571       if (TARGET_SSSE3)
49572         return true;
49573       break;
49574     case V2DImode:
49575     case V2DFmode:
49576       /* All implementable with shufpd or unpck[lh]pd.  */
49577       return true;
49578     default:
49579       return false;
49580     }
49581
49582   /* Extract the values from the vector CST into the permutation
49583      array in D.  */
49584   memcpy (d.perm, sel, nelt);
49585   for (i = which = 0; i < nelt; ++i)
49586     {
49587       unsigned char e = d.perm[i];
49588       gcc_assert (e < 2 * nelt);
49589       which |= (e < nelt ? 1 : 2);
49590     }
49591
49592   /* For all elements from second vector, fold the elements to first.  */
49593   if (which == 2)
49594     for (i = 0; i < nelt; ++i)
49595       d.perm[i] -= nelt;
49596
49597   /* Check whether the mask can be applied to the vector type.  */
49598   d.one_operand_p = (which != 3);
49599
49600   /* Implementable with shufps or pshufd.  */
49601   if (d.one_operand_p && (d.vmode == V4SFmode || d.vmode == V4SImode))
49602     return true;
49603
49604   /* Otherwise we have to go through the motions and see if we can
49605      figure out how to generate the requested permutation.  */
49606   d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1);
49607   d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2);
49608   if (!d.one_operand_p)
49609     d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3);
49610
49611   start_sequence ();
49612   ret = ix86_expand_vec_perm_const_1 (&d);
49613   end_sequence ();
49614
49615   return ret;
49616 }
49617
49618 void
49619 ix86_expand_vec_extract_even_odd (rtx targ, rtx op0, rtx op1, unsigned odd)
49620 {
49621   struct expand_vec_perm_d d;
49622   unsigned i, nelt;
49623
49624   d.target = targ;
49625   d.op0 = op0;
49626   d.op1 = op1;
49627   d.vmode = GET_MODE (targ);
49628   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49629   d.one_operand_p = false;
49630   d.testing_p = false;
49631
49632   for (i = 0; i < nelt; ++i)
49633     d.perm[i] = i * 2 + odd;
49634
49635   /* We'll either be able to implement the permutation directly...  */
49636   if (expand_vec_perm_1 (&d))
49637     return;
49638
49639   /* ... or we use the special-case patterns.  */
49640   expand_vec_perm_even_odd_1 (&d, odd);
49641 }
49642
49643 static void
49644 ix86_expand_vec_interleave (rtx targ, rtx op0, rtx op1, bool high_p)
49645 {
49646   struct expand_vec_perm_d d;
49647   unsigned i, nelt, base;
49648   bool ok;
49649
49650   d.target = targ;
49651   d.op0 = op0;
49652   d.op1 = op1;
49653   d.vmode = GET_MODE (targ);
49654   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49655   d.one_operand_p = false;
49656   d.testing_p = false;
49657
49658   base = high_p ? nelt / 2 : 0;
49659   for (i = 0; i < nelt / 2; ++i)
49660     {
49661       d.perm[i * 2] = i + base;
49662       d.perm[i * 2 + 1] = i + base + nelt;
49663     }
49664
49665   /* Note that for AVX this isn't one instruction.  */
49666   ok = ix86_expand_vec_perm_const_1 (&d);
49667   gcc_assert (ok);
49668 }
49669
49670
49671 /* Expand a vector operation CODE for a V*QImode in terms of the
49672    same operation on V*HImode.  */
49673
49674 void
49675 ix86_expand_vecop_qihi (enum rtx_code code, rtx dest, rtx op1, rtx op2)
49676 {
49677   machine_mode qimode = GET_MODE (dest);
49678   machine_mode himode;
49679   rtx (*gen_il) (rtx, rtx, rtx);
49680   rtx (*gen_ih) (rtx, rtx, rtx);
49681   rtx op1_l, op1_h, op2_l, op2_h, res_l, res_h;
49682   struct expand_vec_perm_d d;
49683   bool ok, full_interleave;
49684   bool uns_p = false;
49685   int i;
49686
49687   switch (qimode)
49688     {
49689     case V16QImode:
49690       himode = V8HImode;
49691       gen_il = gen_vec_interleave_lowv16qi;
49692       gen_ih = gen_vec_interleave_highv16qi;
49693       break;
49694     case V32QImode:
49695       himode = V16HImode;
49696       gen_il = gen_avx2_interleave_lowv32qi;
49697       gen_ih = gen_avx2_interleave_highv32qi;
49698       break;
49699     case V64QImode:
49700       himode = V32HImode;
49701       gen_il = gen_avx512bw_interleave_lowv64qi;
49702       gen_ih = gen_avx512bw_interleave_highv64qi;
49703       break;
49704     default:
49705       gcc_unreachable ();
49706     }
49707
49708   op2_l = op2_h = op2;
49709   switch (code)
49710     {
49711     case MULT:
49712       /* Unpack data such that we've got a source byte in each low byte of
49713          each word.  We don't care what goes into the high byte of each word.
49714          Rather than trying to get zero in there, most convenient is to let
49715          it be a copy of the low byte.  */
49716       op2_l = gen_reg_rtx (qimode);
49717       op2_h = gen_reg_rtx (qimode);
49718       emit_insn (gen_il (op2_l, op2, op2));
49719       emit_insn (gen_ih (op2_h, op2, op2));
49720       /* FALLTHRU */
49721
49722       op1_l = gen_reg_rtx (qimode);
49723       op1_h = gen_reg_rtx (qimode);
49724       emit_insn (gen_il (op1_l, op1, op1));
49725       emit_insn (gen_ih (op1_h, op1, op1));
49726       full_interleave = qimode == V16QImode;
49727       break;
49728
49729     case ASHIFT:
49730     case LSHIFTRT:
49731       uns_p = true;
49732       /* FALLTHRU */
49733     case ASHIFTRT:
49734       op1_l = gen_reg_rtx (himode);
49735       op1_h = gen_reg_rtx (himode);
49736       ix86_expand_sse_unpack (op1_l, op1, uns_p, false);
49737       ix86_expand_sse_unpack (op1_h, op1, uns_p, true);
49738       full_interleave = true;
49739       break;
49740     default:
49741       gcc_unreachable ();
49742     }
49743
49744   /* Perform the operation.  */
49745   res_l = expand_simple_binop (himode, code, op1_l, op2_l, NULL_RTX,
49746                                1, OPTAB_DIRECT);
49747   res_h = expand_simple_binop (himode, code, op1_h, op2_h, NULL_RTX,
49748                                1, OPTAB_DIRECT);
49749   gcc_assert (res_l && res_h);
49750
49751   /* Merge the data back into the right place.  */
49752   d.target = dest;
49753   d.op0 = gen_lowpart (qimode, res_l);
49754   d.op1 = gen_lowpart (qimode, res_h);
49755   d.vmode = qimode;
49756   d.nelt = GET_MODE_NUNITS (qimode);
49757   d.one_operand_p = false;
49758   d.testing_p = false;
49759
49760   if (full_interleave)
49761     {
49762       /* For SSE2, we used an full interleave, so the desired
49763          results are in the even elements.  */
49764       for (i = 0; i < 64; ++i)
49765         d.perm[i] = i * 2;
49766     }
49767   else
49768     {
49769       /* For AVX, the interleave used above was not cross-lane.  So the
49770          extraction is evens but with the second and third quarter swapped.
49771          Happily, that is even one insn shorter than even extraction.  */
49772       for (i = 0; i < 64; ++i)
49773         d.perm[i] = i * 2 + ((i & 24) == 8 ? 16 : (i & 24) == 16 ? -16 : 0);
49774     }
49775
49776   ok = ix86_expand_vec_perm_const_1 (&d);
49777   gcc_assert (ok);
49778
49779   set_unique_reg_note (get_last_insn (), REG_EQUAL,
49780                        gen_rtx_fmt_ee (code, qimode, op1, op2));
49781 }
49782
49783 /* Helper function of ix86_expand_mul_widen_evenodd.  Return true
49784    if op is CONST_VECTOR with all odd elements equal to their
49785    preceding element.  */
49786
49787 static bool
49788 const_vector_equal_evenodd_p (rtx op)
49789 {
49790   machine_mode mode = GET_MODE (op);
49791   int i, nunits = GET_MODE_NUNITS (mode);
49792   if (GET_CODE (op) != CONST_VECTOR
49793       || nunits != CONST_VECTOR_NUNITS (op))
49794     return false;
49795   for (i = 0; i < nunits; i += 2)
49796     if (CONST_VECTOR_ELT (op, i) != CONST_VECTOR_ELT (op, i + 1))
49797       return false;
49798   return true;
49799 }
49800
49801 void
49802 ix86_expand_mul_widen_evenodd (rtx dest, rtx op1, rtx op2,
49803                                bool uns_p, bool odd_p)
49804 {
49805   machine_mode mode = GET_MODE (op1);
49806   machine_mode wmode = GET_MODE (dest);
49807   rtx x;
49808   rtx orig_op1 = op1, orig_op2 = op2;
49809
49810   if (!nonimmediate_operand (op1, mode))
49811     op1 = force_reg (mode, op1);
49812   if (!nonimmediate_operand (op2, mode))
49813     op2 = force_reg (mode, op2);
49814
49815   /* We only play even/odd games with vectors of SImode.  */
49816   gcc_assert (mode == V4SImode || mode == V8SImode || mode == V16SImode);
49817
49818   /* If we're looking for the odd results, shift those members down to
49819      the even slots.  For some cpus this is faster than a PSHUFD.  */
49820   if (odd_p)
49821     {
49822       /* For XOP use vpmacsdqh, but only for smult, as it is only
49823          signed.  */
49824       if (TARGET_XOP && mode == V4SImode && !uns_p)
49825         {
49826           x = force_reg (wmode, CONST0_RTX (wmode));
49827           emit_insn (gen_xop_pmacsdqh (dest, op1, op2, x));
49828           return;
49829         }
49830
49831       x = GEN_INT (GET_MODE_UNIT_BITSIZE (mode));
49832       if (!const_vector_equal_evenodd_p (orig_op1))
49833         op1 = expand_binop (wmode, lshr_optab, gen_lowpart (wmode, op1),
49834                             x, NULL, 1, OPTAB_DIRECT);
49835       if (!const_vector_equal_evenodd_p (orig_op2))
49836         op2 = expand_binop (wmode, lshr_optab, gen_lowpart (wmode, op2),
49837                             x, NULL, 1, OPTAB_DIRECT);
49838       op1 = gen_lowpart (mode, op1);
49839       op2 = gen_lowpart (mode, op2);
49840     }
49841
49842   if (mode == V16SImode)
49843     {
49844       if (uns_p)
49845         x = gen_vec_widen_umult_even_v16si (dest, op1, op2);
49846       else
49847         x = gen_vec_widen_smult_even_v16si (dest, op1, op2);
49848     }
49849   else if (mode == V8SImode)
49850     {
49851       if (uns_p)
49852         x = gen_vec_widen_umult_even_v8si (dest, op1, op2);
49853       else
49854         x = gen_vec_widen_smult_even_v8si (dest, op1, op2);
49855     }
49856   else if (uns_p)
49857     x = gen_vec_widen_umult_even_v4si (dest, op1, op2);
49858   else if (TARGET_SSE4_1)
49859     x = gen_sse4_1_mulv2siv2di3 (dest, op1, op2);
49860   else
49861     {
49862       rtx s1, s2, t0, t1, t2;
49863
49864       /* The easiest way to implement this without PMULDQ is to go through
49865          the motions as if we are performing a full 64-bit multiply.  With
49866          the exception that we need to do less shuffling of the elements.  */
49867
49868       /* Compute the sign-extension, aka highparts, of the two operands.  */
49869       s1 = ix86_expand_sse_cmp (gen_reg_rtx (mode), GT, CONST0_RTX (mode),
49870                                 op1, pc_rtx, pc_rtx);
49871       s2 = ix86_expand_sse_cmp (gen_reg_rtx (mode), GT, CONST0_RTX (mode),
49872                                 op2, pc_rtx, pc_rtx);
49873
49874       /* Multiply LO(A) * HI(B), and vice-versa.  */
49875       t1 = gen_reg_rtx (wmode);
49876       t2 = gen_reg_rtx (wmode);
49877       emit_insn (gen_vec_widen_umult_even_v4si (t1, s1, op2));
49878       emit_insn (gen_vec_widen_umult_even_v4si (t2, s2, op1));
49879
49880       /* Multiply LO(A) * LO(B).  */
49881       t0 = gen_reg_rtx (wmode);
49882       emit_insn (gen_vec_widen_umult_even_v4si (t0, op1, op2));
49883
49884       /* Combine and shift the highparts into place.  */
49885       t1 = expand_binop (wmode, add_optab, t1, t2, t1, 1, OPTAB_DIRECT);
49886       t1 = expand_binop (wmode, ashl_optab, t1, GEN_INT (32), t1,
49887                          1, OPTAB_DIRECT);
49888
49889       /* Combine high and low parts.  */
49890       force_expand_binop (wmode, add_optab, t0, t1, dest, 1, OPTAB_DIRECT);
49891       return;
49892     }
49893   emit_insn (x);
49894 }
49895
49896 void
49897 ix86_expand_mul_widen_hilo (rtx dest, rtx op1, rtx op2,
49898                             bool uns_p, bool high_p)
49899 {
49900   machine_mode wmode = GET_MODE (dest);
49901   machine_mode mode = GET_MODE (op1);
49902   rtx t1, t2, t3, t4, mask;
49903
49904   switch (mode)
49905     {
49906     case V4SImode:
49907       t1 = gen_reg_rtx (mode);
49908       t2 = gen_reg_rtx (mode);
49909       if (TARGET_XOP && !uns_p)
49910         {
49911           /* With XOP, we have pmacsdqh, aka mul_widen_odd.  In this case,
49912              shuffle the elements once so that all elements are in the right
49913              place for immediate use: { A C B D }.  */
49914           emit_insn (gen_sse2_pshufd_1 (t1, op1, const0_rtx, const2_rtx,
49915                                         const1_rtx, GEN_INT (3)));
49916           emit_insn (gen_sse2_pshufd_1 (t2, op2, const0_rtx, const2_rtx,
49917                                         const1_rtx, GEN_INT (3)));
49918         }
49919       else
49920         {
49921           /* Put the elements into place for the multiply.  */
49922           ix86_expand_vec_interleave (t1, op1, op1, high_p);
49923           ix86_expand_vec_interleave (t2, op2, op2, high_p);
49924           high_p = false;
49925         }
49926       ix86_expand_mul_widen_evenodd (dest, t1, t2, uns_p, high_p);
49927       break;
49928
49929     case V8SImode:
49930       /* Shuffle the elements between the lanes.  After this we
49931          have { A B E F | C D G H } for each operand.  */
49932       t1 = gen_reg_rtx (V4DImode);
49933       t2 = gen_reg_rtx (V4DImode);
49934       emit_insn (gen_avx2_permv4di_1 (t1, gen_lowpart (V4DImode, op1),
49935                                       const0_rtx, const2_rtx,
49936                                       const1_rtx, GEN_INT (3)));
49937       emit_insn (gen_avx2_permv4di_1 (t2, gen_lowpart (V4DImode, op2),
49938                                       const0_rtx, const2_rtx,
49939                                       const1_rtx, GEN_INT (3)));
49940
49941       /* Shuffle the elements within the lanes.  After this we
49942          have { A A B B | C C D D } or { E E F F | G G H H }.  */
49943       t3 = gen_reg_rtx (V8SImode);
49944       t4 = gen_reg_rtx (V8SImode);
49945       mask = GEN_INT (high_p
49946                       ? 2 + (2 << 2) + (3 << 4) + (3 << 6)
49947                       : 0 + (0 << 2) + (1 << 4) + (1 << 6));
49948       emit_insn (gen_avx2_pshufdv3 (t3, gen_lowpart (V8SImode, t1), mask));
49949       emit_insn (gen_avx2_pshufdv3 (t4, gen_lowpart (V8SImode, t2), mask));
49950
49951       ix86_expand_mul_widen_evenodd (dest, t3, t4, uns_p, false);
49952       break;
49953
49954     case V8HImode:
49955     case V16HImode:
49956       t1 = expand_binop (mode, smul_optab, op1, op2, NULL_RTX,
49957                          uns_p, OPTAB_DIRECT);
49958       t2 = expand_binop (mode,
49959                          uns_p ? umul_highpart_optab : smul_highpart_optab,
49960                          op1, op2, NULL_RTX, uns_p, OPTAB_DIRECT);
49961       gcc_assert (t1 && t2);
49962
49963       t3 = gen_reg_rtx (mode);
49964       ix86_expand_vec_interleave (t3, t1, t2, high_p);
49965       emit_move_insn (dest, gen_lowpart (wmode, t3));
49966       break;
49967
49968     case V16QImode:
49969     case V32QImode:
49970     case V32HImode:
49971     case V16SImode:
49972     case V64QImode:
49973       t1 = gen_reg_rtx (wmode);
49974       t2 = gen_reg_rtx (wmode);
49975       ix86_expand_sse_unpack (t1, op1, uns_p, high_p);
49976       ix86_expand_sse_unpack (t2, op2, uns_p, high_p);
49977
49978       emit_insn (gen_rtx_SET (dest, gen_rtx_MULT (wmode, t1, t2)));
49979       break;
49980
49981     default:
49982       gcc_unreachable ();
49983     }
49984 }
49985
49986 void
49987 ix86_expand_sse2_mulv4si3 (rtx op0, rtx op1, rtx op2)
49988 {
49989   rtx res_1, res_2, res_3, res_4;
49990
49991   res_1 = gen_reg_rtx (V4SImode);
49992   res_2 = gen_reg_rtx (V4SImode);
49993   res_3 = gen_reg_rtx (V2DImode);
49994   res_4 = gen_reg_rtx (V2DImode);
49995   ix86_expand_mul_widen_evenodd (res_3, op1, op2, true, false);
49996   ix86_expand_mul_widen_evenodd (res_4, op1, op2, true, true);
49997
49998   /* Move the results in element 2 down to element 1; we don't care
49999      what goes in elements 2 and 3.  Then we can merge the parts
50000      back together with an interleave.
50001
50002      Note that two other sequences were tried:
50003      (1) Use interleaves at the start instead of psrldq, which allows
50004      us to use a single shufps to merge things back at the end.
50005      (2) Use shufps here to combine the two vectors, then pshufd to
50006      put the elements in the correct order.
50007      In both cases the cost of the reformatting stall was too high
50008      and the overall sequence slower.  */
50009
50010   emit_insn (gen_sse2_pshufd_1 (res_1, gen_lowpart (V4SImode, res_3),
50011                                 const0_rtx, const2_rtx,
50012                                 const0_rtx, const0_rtx));
50013   emit_insn (gen_sse2_pshufd_1 (res_2, gen_lowpart (V4SImode, res_4),
50014                                 const0_rtx, const2_rtx,
50015                                 const0_rtx, const0_rtx));
50016   res_1 = emit_insn (gen_vec_interleave_lowv4si (op0, res_1, res_2));
50017
50018   set_unique_reg_note (res_1, REG_EQUAL, gen_rtx_MULT (V4SImode, op1, op2));
50019 }
50020
50021 void
50022 ix86_expand_sse2_mulvxdi3 (rtx op0, rtx op1, rtx op2)
50023 {
50024   machine_mode mode = GET_MODE (op0);
50025   rtx t1, t2, t3, t4, t5, t6;
50026
50027   if (TARGET_AVX512DQ && mode == V8DImode)
50028     emit_insn (gen_avx512dq_mulv8di3 (op0, op1, op2));
50029   else if (TARGET_AVX512DQ && TARGET_AVX512VL && mode == V4DImode)
50030     emit_insn (gen_avx512dq_mulv4di3 (op0, op1, op2));
50031   else if (TARGET_AVX512DQ && TARGET_AVX512VL && mode == V2DImode)
50032     emit_insn (gen_avx512dq_mulv2di3 (op0, op1, op2));
50033   else if (TARGET_XOP && mode == V2DImode)
50034     {
50035       /* op1: A,B,C,D, op2: E,F,G,H */
50036       op1 = gen_lowpart (V4SImode, op1);
50037       op2 = gen_lowpart (V4SImode, op2);
50038
50039       t1 = gen_reg_rtx (V4SImode);
50040       t2 = gen_reg_rtx (V4SImode);
50041       t3 = gen_reg_rtx (V2DImode);
50042       t4 = gen_reg_rtx (V2DImode);
50043
50044       /* t1: B,A,D,C */
50045       emit_insn (gen_sse2_pshufd_1 (t1, op1,
50046                                     GEN_INT (1),
50047                                     GEN_INT (0),
50048                                     GEN_INT (3),
50049                                     GEN_INT (2)));
50050
50051       /* t2: (B*E),(A*F),(D*G),(C*H) */
50052       emit_insn (gen_mulv4si3 (t2, t1, op2));
50053
50054       /* t3: (B*E)+(A*F), (D*G)+(C*H) */
50055       emit_insn (gen_xop_phadddq (t3, t2));
50056
50057       /* t4: ((B*E)+(A*F))<<32, ((D*G)+(C*H))<<32 */
50058       emit_insn (gen_ashlv2di3 (t4, t3, GEN_INT (32)));
50059
50060       /* Multiply lower parts and add all */
50061       t5 = gen_reg_rtx (V2DImode);
50062       emit_insn (gen_vec_widen_umult_even_v4si (t5, 
50063                                         gen_lowpart (V4SImode, op1),
50064                                         gen_lowpart (V4SImode, op2)));
50065       op0 = expand_binop (mode, add_optab, t5, t4, op0, 1, OPTAB_DIRECT);
50066
50067     }
50068   else
50069     {
50070       machine_mode nmode;
50071       rtx (*umul) (rtx, rtx, rtx);
50072
50073       if (mode == V2DImode)
50074         {
50075           umul = gen_vec_widen_umult_even_v4si;
50076           nmode = V4SImode;
50077         }
50078       else if (mode == V4DImode)
50079         {
50080           umul = gen_vec_widen_umult_even_v8si;
50081           nmode = V8SImode;
50082         }
50083       else if (mode == V8DImode)
50084         {
50085           umul = gen_vec_widen_umult_even_v16si;
50086           nmode = V16SImode;
50087         }
50088       else
50089         gcc_unreachable ();
50090
50091
50092       /* Multiply low parts.  */
50093       t1 = gen_reg_rtx (mode);
50094       emit_insn (umul (t1, gen_lowpart (nmode, op1), gen_lowpart (nmode, op2)));
50095
50096       /* Shift input vectors right 32 bits so we can multiply high parts.  */
50097       t6 = GEN_INT (32);
50098       t2 = expand_binop (mode, lshr_optab, op1, t6, NULL, 1, OPTAB_DIRECT);
50099       t3 = expand_binop (mode, lshr_optab, op2, t6, NULL, 1, OPTAB_DIRECT);
50100
50101       /* Multiply high parts by low parts.  */
50102       t4 = gen_reg_rtx (mode);
50103       t5 = gen_reg_rtx (mode);
50104       emit_insn (umul (t4, gen_lowpart (nmode, t2), gen_lowpart (nmode, op2)));
50105       emit_insn (umul (t5, gen_lowpart (nmode, t3), gen_lowpart (nmode, op1)));
50106
50107       /* Combine and shift the highparts back.  */
50108       t4 = expand_binop (mode, add_optab, t4, t5, t4, 1, OPTAB_DIRECT);
50109       t4 = expand_binop (mode, ashl_optab, t4, t6, t4, 1, OPTAB_DIRECT);
50110
50111       /* Combine high and low parts.  */
50112       force_expand_binop (mode, add_optab, t1, t4, op0, 1, OPTAB_DIRECT);
50113     }
50114
50115   set_unique_reg_note (get_last_insn (), REG_EQUAL,
50116                        gen_rtx_MULT (mode, op1, op2));
50117 }
50118
50119 /* Return 1 if control tansfer instruction INSN
50120    should be encoded with bnd prefix.
50121    If insn is NULL then return 1 when control
50122    transfer instructions should be prefixed with
50123    bnd by default for current function.  */
50124
50125 bool
50126 ix86_bnd_prefixed_insn_p (rtx insn)
50127 {
50128   /* For call insns check special flag.  */
50129   if (insn && CALL_P (insn))
50130     {
50131       rtx call = get_call_rtx_from (insn);
50132       if (call)
50133         return CALL_EXPR_WITH_BOUNDS_P (call);
50134     }
50135
50136   /* All other insns are prefixed only if function is instrumented.  */
50137   return chkp_function_instrumented_p (current_function_decl);
50138 }
50139
50140 /* Calculate integer abs() using only SSE2 instructions.  */
50141
50142 void
50143 ix86_expand_sse2_abs (rtx target, rtx input)
50144 {
50145   machine_mode mode = GET_MODE (target);
50146   rtx tmp0, tmp1, x;
50147
50148   switch (mode)
50149     {
50150       /* For 32-bit signed integer X, the best way to calculate the absolute
50151          value of X is (((signed) X >> (W-1)) ^ X) - ((signed) X >> (W-1)).  */
50152       case V4SImode:
50153         tmp0 = expand_simple_binop (mode, ASHIFTRT, input,
50154                                     GEN_INT (GET_MODE_BITSIZE
50155                                              (GET_MODE_INNER (mode)) - 1),
50156                                     NULL, 0, OPTAB_DIRECT);
50157         tmp1 = expand_simple_binop (mode, XOR, tmp0, input,
50158                                     NULL, 0, OPTAB_DIRECT);
50159         x = expand_simple_binop (mode, MINUS, tmp1, tmp0,
50160                                  target, 0, OPTAB_DIRECT);
50161         break;
50162
50163       /* For 16-bit signed integer X, the best way to calculate the absolute
50164          value of X is max (X, -X), as SSE2 provides the PMAXSW insn.  */
50165       case V8HImode:
50166         tmp0 = expand_unop (mode, neg_optab, input, NULL_RTX, 0);
50167
50168         x = expand_simple_binop (mode, SMAX, tmp0, input,
50169                                  target, 0, OPTAB_DIRECT);
50170         break;
50171
50172       /* For 8-bit signed integer X, the best way to calculate the absolute
50173          value of X is min ((unsigned char) X, (unsigned char) (-X)),
50174          as SSE2 provides the PMINUB insn.  */
50175       case V16QImode:
50176         tmp0 = expand_unop (mode, neg_optab, input, NULL_RTX, 0);
50177
50178         x = expand_simple_binop (V16QImode, UMIN, tmp0, input,
50179                                  target, 0, OPTAB_DIRECT);
50180         break;
50181
50182       default:
50183         gcc_unreachable ();
50184     }
50185
50186   if (x != target)
50187     emit_move_insn (target, x);
50188 }
50189
50190 /* Expand an insert into a vector register through pinsr insn.
50191    Return true if successful.  */
50192
50193 bool
50194 ix86_expand_pinsr (rtx *operands)
50195 {
50196   rtx dst = operands[0];
50197   rtx src = operands[3];
50198
50199   unsigned int size = INTVAL (operands[1]);
50200   unsigned int pos = INTVAL (operands[2]);
50201
50202   if (GET_CODE (dst) == SUBREG)
50203     {
50204       pos += SUBREG_BYTE (dst) * BITS_PER_UNIT;
50205       dst = SUBREG_REG (dst);
50206     }
50207
50208   if (GET_CODE (src) == SUBREG)
50209     src = SUBREG_REG (src);
50210
50211   switch (GET_MODE (dst))
50212     {
50213     case V16QImode:
50214     case V8HImode:
50215     case V4SImode:
50216     case V2DImode:
50217       {
50218         machine_mode srcmode, dstmode;
50219         rtx (*pinsr)(rtx, rtx, rtx, rtx);
50220
50221         srcmode = mode_for_size (size, MODE_INT, 0);
50222
50223         switch (srcmode)
50224           {
50225           case QImode:
50226             if (!TARGET_SSE4_1)
50227               return false;
50228             dstmode = V16QImode;
50229             pinsr = gen_sse4_1_pinsrb;
50230             break;
50231
50232           case HImode:
50233             if (!TARGET_SSE2)
50234               return false;
50235             dstmode = V8HImode;
50236             pinsr = gen_sse2_pinsrw;
50237             break;
50238
50239           case SImode:
50240             if (!TARGET_SSE4_1)
50241               return false;
50242             dstmode = V4SImode;
50243             pinsr = gen_sse4_1_pinsrd;
50244             break;
50245
50246           case DImode:
50247             gcc_assert (TARGET_64BIT);
50248             if (!TARGET_SSE4_1)
50249               return false;
50250             dstmode = V2DImode;
50251             pinsr = gen_sse4_1_pinsrq;
50252             break;
50253
50254           default:
50255             return false;
50256           }
50257
50258         rtx d = dst;
50259         if (GET_MODE (dst) != dstmode)
50260           d = gen_reg_rtx (dstmode);
50261         src = gen_lowpart (srcmode, src);
50262
50263         pos /= size;
50264
50265         emit_insn (pinsr (d, gen_lowpart (dstmode, dst), src,
50266                           GEN_INT (1 << pos)));
50267         if (d != dst)
50268           emit_move_insn (dst, gen_lowpart (GET_MODE (dst), d));
50269         return true;
50270       }
50271
50272     default:
50273       return false;
50274     }
50275 }
50276 \f
50277 /* This function returns the calling abi specific va_list type node.
50278    It returns  the FNDECL specific va_list type.  */
50279
50280 static tree
50281 ix86_fn_abi_va_list (tree fndecl)
50282 {
50283   if (!TARGET_64BIT)
50284     return va_list_type_node;
50285   gcc_assert (fndecl != NULL_TREE);
50286
50287   if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
50288     return ms_va_list_type_node;
50289   else
50290     return sysv_va_list_type_node;
50291 }
50292
50293 /* Returns the canonical va_list type specified by TYPE. If there
50294    is no valid TYPE provided, it return NULL_TREE.  */
50295
50296 static tree
50297 ix86_canonical_va_list_type (tree type)
50298 {
50299   tree wtype, htype;
50300
50301   /* Resolve references and pointers to va_list type.  */
50302   if (TREE_CODE (type) == MEM_REF)
50303     type = TREE_TYPE (type);
50304   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
50305     type = TREE_TYPE (type);
50306   else if (POINTER_TYPE_P (type) && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
50307     type = TREE_TYPE (type);
50308
50309   if (TARGET_64BIT && va_list_type_node != NULL_TREE)
50310     {
50311       wtype = va_list_type_node;
50312           gcc_assert (wtype != NULL_TREE);
50313       htype = type;
50314       if (TREE_CODE (wtype) == ARRAY_TYPE)
50315         {
50316           /* If va_list is an array type, the argument may have decayed
50317              to a pointer type, e.g. by being passed to another function.
50318              In that case, unwrap both types so that we can compare the
50319              underlying records.  */
50320           if (TREE_CODE (htype) == ARRAY_TYPE
50321               || POINTER_TYPE_P (htype))
50322             {
50323               wtype = TREE_TYPE (wtype);
50324               htype = TREE_TYPE (htype);
50325             }
50326         }
50327       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50328         return va_list_type_node;
50329       wtype = sysv_va_list_type_node;
50330           gcc_assert (wtype != NULL_TREE);
50331       htype = type;
50332       if (TREE_CODE (wtype) == ARRAY_TYPE)
50333         {
50334           /* If va_list is an array type, the argument may have decayed
50335              to a pointer type, e.g. by being passed to another function.
50336              In that case, unwrap both types so that we can compare the
50337              underlying records.  */
50338           if (TREE_CODE (htype) == ARRAY_TYPE
50339               || POINTER_TYPE_P (htype))
50340             {
50341               wtype = TREE_TYPE (wtype);
50342               htype = TREE_TYPE (htype);
50343             }
50344         }
50345       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50346         return sysv_va_list_type_node;
50347       wtype = ms_va_list_type_node;
50348           gcc_assert (wtype != NULL_TREE);
50349       htype = type;
50350       if (TREE_CODE (wtype) == ARRAY_TYPE)
50351         {
50352           /* If va_list is an array type, the argument may have decayed
50353              to a pointer type, e.g. by being passed to another function.
50354              In that case, unwrap both types so that we can compare the
50355              underlying records.  */
50356           if (TREE_CODE (htype) == ARRAY_TYPE
50357               || POINTER_TYPE_P (htype))
50358             {
50359               wtype = TREE_TYPE (wtype);
50360               htype = TREE_TYPE (htype);
50361             }
50362         }
50363       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50364         return ms_va_list_type_node;
50365       return NULL_TREE;
50366     }
50367   return std_canonical_va_list_type (type);
50368 }
50369
50370 /* Iterate through the target-specific builtin types for va_list.
50371    IDX denotes the iterator, *PTREE is set to the result type of
50372    the va_list builtin, and *PNAME to its internal type.
50373    Returns zero if there is no element for this index, otherwise
50374    IDX should be increased upon the next call.
50375    Note, do not iterate a base builtin's name like __builtin_va_list.
50376    Used from c_common_nodes_and_builtins.  */
50377
50378 static int
50379 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
50380 {
50381   if (TARGET_64BIT)
50382     {
50383       switch (idx)
50384         {
50385         default:
50386           break;
50387
50388         case 0:
50389           *ptree = ms_va_list_type_node;
50390           *pname = "__builtin_ms_va_list";
50391           return 1;
50392
50393         case 1:
50394           *ptree = sysv_va_list_type_node;
50395           *pname = "__builtin_sysv_va_list";
50396           return 1;
50397         }
50398     }
50399
50400   return 0;
50401 }
50402
50403 #undef TARGET_SCHED_DISPATCH
50404 #define TARGET_SCHED_DISPATCH has_dispatch
50405 #undef TARGET_SCHED_DISPATCH_DO
50406 #define TARGET_SCHED_DISPATCH_DO do_dispatch
50407 #undef TARGET_SCHED_REASSOCIATION_WIDTH
50408 #define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width
50409 #undef TARGET_SCHED_REORDER
50410 #define TARGET_SCHED_REORDER ix86_sched_reorder
50411 #undef TARGET_SCHED_ADJUST_PRIORITY
50412 #define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority
50413 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
50414 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
50415   ix86_dependencies_evaluation_hook
50416
50417 /* The size of the dispatch window is the total number of bytes of
50418    object code allowed in a window.  */
50419 #define DISPATCH_WINDOW_SIZE 16
50420
50421 /* Number of dispatch windows considered for scheduling.  */
50422 #define MAX_DISPATCH_WINDOWS 3
50423
50424 /* Maximum number of instructions in a window.  */
50425 #define MAX_INSN 4
50426
50427 /* Maximum number of immediate operands in a window.  */
50428 #define MAX_IMM 4
50429
50430 /* Maximum number of immediate bits allowed in a window.  */
50431 #define MAX_IMM_SIZE 128
50432
50433 /* Maximum number of 32 bit immediates allowed in a window.  */
50434 #define MAX_IMM_32 4
50435
50436 /* Maximum number of 64 bit immediates allowed in a window.  */
50437 #define MAX_IMM_64 2
50438
50439 /* Maximum total of loads or prefetches allowed in a window.  */
50440 #define MAX_LOAD 2
50441
50442 /* Maximum total of stores allowed in a window.  */
50443 #define MAX_STORE 1
50444
50445 #undef BIG
50446 #define BIG 100
50447
50448
50449 /* Dispatch groups.  Istructions that affect the mix in a dispatch window.  */
50450 enum dispatch_group {
50451   disp_no_group = 0,
50452   disp_load,
50453   disp_store,
50454   disp_load_store,
50455   disp_prefetch,
50456   disp_imm,
50457   disp_imm_32,
50458   disp_imm_64,
50459   disp_branch,
50460   disp_cmp,
50461   disp_jcc,
50462   disp_last
50463 };
50464
50465 /* Number of allowable groups in a dispatch window.  It is an array
50466    indexed by dispatch_group enum.  100 is used as a big number,
50467    because the number of these kind of operations does not have any
50468    effect in dispatch window, but we need them for other reasons in
50469    the table.  */
50470 static unsigned int num_allowable_groups[disp_last] = {
50471   0, 2, 1, 1, 2, 4, 4, 2, 1, BIG, BIG
50472 };
50473
50474 char group_name[disp_last + 1][16] = {
50475   "disp_no_group", "disp_load", "disp_store", "disp_load_store",
50476   "disp_prefetch", "disp_imm", "disp_imm_32", "disp_imm_64",
50477   "disp_branch", "disp_cmp", "disp_jcc", "disp_last"
50478 };
50479
50480 /* Instruction path.  */
50481 enum insn_path {
50482   no_path = 0,
50483   path_single, /* Single micro op.  */
50484   path_double, /* Double micro op.  */
50485   path_multi,  /* Instructions with more than 2 micro op..  */
50486   last_path
50487 };
50488
50489 /* sched_insn_info defines a window to the instructions scheduled in
50490    the basic block.  It contains a pointer to the insn_info table and
50491    the instruction scheduled.
50492
50493    Windows are allocated for each basic block and are linked
50494    together.  */
50495 typedef struct sched_insn_info_s {
50496   rtx insn;
50497   enum dispatch_group group;
50498   enum insn_path path;
50499   int byte_len;
50500   int imm_bytes;
50501 } sched_insn_info;
50502
50503 /* Linked list of dispatch windows.  This is a two way list of
50504    dispatch windows of a basic block.  It contains information about
50505    the number of uops in the window and the total number of
50506    instructions and of bytes in the object code for this dispatch
50507    window.  */
50508 typedef struct dispatch_windows_s {
50509   int num_insn;            /* Number of insn in the window.  */
50510   int num_uops;            /* Number of uops in the window.  */
50511   int window_size;         /* Number of bytes in the window.  */
50512   int window_num;          /* Window number between 0 or 1.  */
50513   int num_imm;             /* Number of immediates in an insn.  */
50514   int num_imm_32;          /* Number of 32 bit immediates in an insn.  */
50515   int num_imm_64;          /* Number of 64 bit immediates in an insn.  */
50516   int imm_size;            /* Total immediates in the window.  */
50517   int num_loads;           /* Total memory loads in the window.  */
50518   int num_stores;          /* Total memory stores in the window.  */
50519   int violation;          /* Violation exists in window.  */
50520   sched_insn_info *window; /* Pointer to the window.  */
50521   struct dispatch_windows_s *next;
50522   struct dispatch_windows_s *prev;
50523 } dispatch_windows;
50524
50525 /* Immediate valuse used in an insn.  */
50526 typedef struct imm_info_s
50527   {
50528     int imm;
50529     int imm32;
50530     int imm64;
50531   } imm_info;
50532
50533 static dispatch_windows *dispatch_window_list;
50534 static dispatch_windows *dispatch_window_list1;
50535
50536 /* Get dispatch group of insn.  */
50537
50538 static enum dispatch_group
50539 get_mem_group (rtx_insn *insn)
50540 {
50541   enum attr_memory memory;
50542
50543   if (INSN_CODE (insn) < 0)
50544     return disp_no_group;
50545   memory = get_attr_memory (insn);
50546   if (memory == MEMORY_STORE)
50547     return disp_store;
50548
50549   if (memory == MEMORY_LOAD)
50550     return disp_load;
50551
50552   if (memory == MEMORY_BOTH)
50553     return disp_load_store;
50554
50555   return disp_no_group;
50556 }
50557
50558 /* Return true if insn is a compare instruction.  */
50559
50560 static bool
50561 is_cmp (rtx_insn *insn)
50562 {
50563   enum attr_type type;
50564
50565   type = get_attr_type (insn);
50566   return (type == TYPE_TEST
50567           || type == TYPE_ICMP
50568           || type == TYPE_FCMP
50569           || GET_CODE (PATTERN (insn)) == COMPARE);
50570 }
50571
50572 /* Return true if a dispatch violation encountered.  */
50573
50574 static bool
50575 dispatch_violation (void)
50576 {
50577   if (dispatch_window_list->next)
50578     return dispatch_window_list->next->violation;
50579   return dispatch_window_list->violation;
50580 }
50581
50582 /* Return true if insn is a branch instruction.  */
50583
50584 static bool
50585 is_branch (rtx_insn *insn)
50586 {
50587   return (CALL_P (insn) || JUMP_P (insn));
50588 }
50589
50590 /* Return true if insn is a prefetch instruction.  */
50591
50592 static bool
50593 is_prefetch (rtx_insn *insn)
50594 {
50595   return NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == PREFETCH;
50596 }
50597
50598 /* This function initializes a dispatch window and the list container holding a
50599    pointer to the window.  */
50600
50601 static void
50602 init_window (int window_num)
50603 {
50604   int i;
50605   dispatch_windows *new_list;
50606
50607   if (window_num == 0)
50608     new_list = dispatch_window_list;
50609   else
50610     new_list = dispatch_window_list1;
50611
50612   new_list->num_insn = 0;
50613   new_list->num_uops = 0;
50614   new_list->window_size = 0;
50615   new_list->next = NULL;
50616   new_list->prev = NULL;
50617   new_list->window_num = window_num;
50618   new_list->num_imm = 0;
50619   new_list->num_imm_32 = 0;
50620   new_list->num_imm_64 = 0;
50621   new_list->imm_size = 0;
50622   new_list->num_loads = 0;
50623   new_list->num_stores = 0;
50624   new_list->violation = false;
50625
50626   for (i = 0; i < MAX_INSN; i++)
50627     {
50628       new_list->window[i].insn = NULL;
50629       new_list->window[i].group = disp_no_group;
50630       new_list->window[i].path = no_path;
50631       new_list->window[i].byte_len = 0;
50632       new_list->window[i].imm_bytes = 0;
50633     }
50634   return;
50635 }
50636
50637 /* This function allocates and initializes a dispatch window and the
50638    list container holding a pointer to the window.  */
50639
50640 static dispatch_windows *
50641 allocate_window (void)
50642 {
50643   dispatch_windows *new_list = XNEW (struct dispatch_windows_s);
50644   new_list->window = XNEWVEC (struct sched_insn_info_s, MAX_INSN + 1);
50645
50646   return new_list;
50647 }
50648
50649 /* This routine initializes the dispatch scheduling information.  It
50650    initiates building dispatch scheduler tables and constructs the
50651    first dispatch window.  */
50652
50653 static void
50654 init_dispatch_sched (void)
50655 {
50656   /* Allocate a dispatch list and a window.  */
50657   dispatch_window_list = allocate_window ();
50658   dispatch_window_list1 = allocate_window ();
50659   init_window (0);
50660   init_window (1);
50661 }
50662
50663 /* This function returns true if a branch is detected.  End of a basic block
50664    does not have to be a branch, but here we assume only branches end a
50665    window.  */
50666
50667 static bool
50668 is_end_basic_block (enum dispatch_group group)
50669 {
50670   return group == disp_branch;
50671 }
50672
50673 /* This function is called when the end of a window processing is reached.  */
50674
50675 static void
50676 process_end_window (void)
50677 {
50678   gcc_assert (dispatch_window_list->num_insn <= MAX_INSN);
50679   if (dispatch_window_list->next)
50680     {
50681       gcc_assert (dispatch_window_list1->num_insn <= MAX_INSN);
50682       gcc_assert (dispatch_window_list->window_size
50683                   + dispatch_window_list1->window_size <= 48);
50684       init_window (1);
50685     }
50686   init_window (0);
50687 }
50688
50689 /* Allocates a new dispatch window and adds it to WINDOW_LIST.
50690    WINDOW_NUM is either 0 or 1.  A maximum of two windows are generated
50691    for 48 bytes of instructions.  Note that these windows are not dispatch
50692    windows that their sizes are DISPATCH_WINDOW_SIZE.  */
50693
50694 static dispatch_windows *
50695 allocate_next_window (int window_num)
50696 {
50697   if (window_num == 0)
50698     {
50699       if (dispatch_window_list->next)
50700           init_window (1);
50701       init_window (0);
50702       return dispatch_window_list;
50703     }
50704
50705   dispatch_window_list->next = dispatch_window_list1;
50706   dispatch_window_list1->prev = dispatch_window_list;
50707
50708   return dispatch_window_list1;
50709 }
50710
50711 /* Compute number of immediate operands of an instruction.  */
50712
50713 static void
50714 find_constant (rtx in_rtx, imm_info *imm_values)
50715 {
50716   if (INSN_P (in_rtx))
50717     in_rtx = PATTERN (in_rtx);
50718   subrtx_iterator::array_type array;
50719   FOR_EACH_SUBRTX (iter, array, in_rtx, ALL)
50720     if (const_rtx x = *iter)
50721       switch (GET_CODE (x))
50722         {
50723         case CONST:
50724         case SYMBOL_REF:
50725         case CONST_INT:
50726           (imm_values->imm)++;
50727           if (x86_64_immediate_operand (CONST_CAST_RTX (x), SImode))
50728             (imm_values->imm32)++;
50729           else
50730             (imm_values->imm64)++;
50731           break;
50732
50733         case CONST_DOUBLE:
50734         case CONST_WIDE_INT:
50735           (imm_values->imm)++;
50736           (imm_values->imm64)++;
50737           break;
50738
50739         case CODE_LABEL:
50740           if (LABEL_KIND (x) == LABEL_NORMAL)
50741             {
50742               (imm_values->imm)++;
50743               (imm_values->imm32)++;
50744             }
50745           break;
50746
50747         default:
50748           break;
50749         }
50750 }
50751
50752 /* Return total size of immediate operands of an instruction along with number
50753    of corresponding immediate-operands.  It initializes its parameters to zero
50754    befor calling FIND_CONSTANT.
50755    INSN is the input instruction.  IMM is the total of immediates.
50756    IMM32 is the number of 32 bit immediates.  IMM64 is the number of 64
50757    bit immediates.  */
50758
50759 static int
50760 get_num_immediates (rtx_insn *insn, int *imm, int *imm32, int *imm64)
50761 {
50762   imm_info imm_values = {0, 0, 0};
50763
50764   find_constant (insn, &imm_values);
50765   *imm = imm_values.imm;
50766   *imm32 = imm_values.imm32;
50767   *imm64 = imm_values.imm64;
50768   return imm_values.imm32 * 4 + imm_values.imm64 * 8;
50769 }
50770
50771 /* This function indicates if an operand of an instruction is an
50772    immediate.  */
50773
50774 static bool
50775 has_immediate (rtx_insn *insn)
50776 {
50777   int num_imm_operand;
50778   int num_imm32_operand;
50779   int num_imm64_operand;
50780
50781   if (insn)
50782     return get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50783                                &num_imm64_operand);
50784   return false;
50785 }
50786
50787 /* Return single or double path for instructions.  */
50788
50789 static enum insn_path
50790 get_insn_path (rtx_insn *insn)
50791 {
50792   enum attr_amdfam10_decode path = get_attr_amdfam10_decode (insn);
50793
50794   if ((int)path == 0)
50795     return path_single;
50796
50797   if ((int)path == 1)
50798     return path_double;
50799
50800   return path_multi;
50801 }
50802
50803 /* Return insn dispatch group.  */
50804
50805 static enum dispatch_group
50806 get_insn_group (rtx_insn *insn)
50807 {
50808   enum dispatch_group group = get_mem_group (insn);
50809   if (group)
50810     return group;
50811
50812   if (is_branch (insn))
50813     return disp_branch;
50814
50815   if (is_cmp (insn))
50816     return disp_cmp;
50817
50818   if (has_immediate (insn))
50819     return disp_imm;
50820
50821   if (is_prefetch (insn))
50822     return disp_prefetch;
50823
50824   return disp_no_group;
50825 }
50826
50827 /* Count number of GROUP restricted instructions in a dispatch
50828    window WINDOW_LIST.  */
50829
50830 static int
50831 count_num_restricted (rtx_insn *insn, dispatch_windows *window_list)
50832 {
50833   enum dispatch_group group = get_insn_group (insn);
50834   int imm_size;
50835   int num_imm_operand;
50836   int num_imm32_operand;
50837   int num_imm64_operand;
50838
50839   if (group == disp_no_group)
50840     return 0;
50841
50842   if (group == disp_imm)
50843     {
50844       imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50845                               &num_imm64_operand);
50846       if (window_list->imm_size + imm_size > MAX_IMM_SIZE
50847           || num_imm_operand + window_list->num_imm > MAX_IMM
50848           || (num_imm32_operand > 0
50849               && (window_list->num_imm_32 + num_imm32_operand > MAX_IMM_32
50850                   || window_list->num_imm_64 * 2 + num_imm32_operand > MAX_IMM_32))
50851           || (num_imm64_operand > 0
50852               && (window_list->num_imm_64 + num_imm64_operand > MAX_IMM_64
50853                   || window_list->num_imm_32 + num_imm64_operand * 2 > MAX_IMM_32))
50854           || (window_list->imm_size + imm_size == MAX_IMM_SIZE
50855               && num_imm64_operand > 0
50856               && ((window_list->num_imm_64 > 0
50857                    && window_list->num_insn >= 2)
50858                   || window_list->num_insn >= 3)))
50859         return BIG;
50860
50861       return 1;
50862     }
50863
50864   if ((group == disp_load_store
50865        && (window_list->num_loads >= MAX_LOAD
50866            || window_list->num_stores >= MAX_STORE))
50867       || ((group == disp_load
50868            || group == disp_prefetch)
50869           && window_list->num_loads >= MAX_LOAD)
50870       || (group == disp_store
50871           && window_list->num_stores >= MAX_STORE))
50872     return BIG;
50873
50874   return 1;
50875 }
50876
50877 /* This function returns true if insn satisfies dispatch rules on the
50878    last window scheduled.  */
50879
50880 static bool
50881 fits_dispatch_window (rtx_insn *insn)
50882 {
50883   dispatch_windows *window_list = dispatch_window_list;
50884   dispatch_windows *window_list_next = dispatch_window_list->next;
50885   unsigned int num_restrict;
50886   enum dispatch_group group = get_insn_group (insn);
50887   enum insn_path path = get_insn_path (insn);
50888   int sum;
50889
50890   /* Make disp_cmp and disp_jcc get scheduled at the latest.  These
50891      instructions should be given the lowest priority in the
50892      scheduling process in Haifa scheduler to make sure they will be
50893      scheduled in the same dispatch window as the reference to them.  */
50894   if (group == disp_jcc || group == disp_cmp)
50895     return false;
50896
50897   /* Check nonrestricted.  */
50898   if (group == disp_no_group || group == disp_branch)
50899     return true;
50900
50901   /* Get last dispatch window.  */
50902   if (window_list_next)
50903     window_list = window_list_next;
50904
50905   if (window_list->window_num == 1)
50906     {
50907       sum = window_list->prev->window_size + window_list->window_size;
50908
50909       if (sum == 32
50910           || (min_insn_size (insn) + sum) >= 48)
50911         /* Window 1 is full.  Go for next window.  */
50912         return true;
50913     }
50914
50915   num_restrict = count_num_restricted (insn, window_list);
50916
50917   if (num_restrict > num_allowable_groups[group])
50918     return false;
50919
50920   /* See if it fits in the first window.  */
50921   if (window_list->window_num == 0)
50922     {
50923       /* The first widow should have only single and double path
50924          uops.  */
50925       if (path == path_double
50926           && (window_list->num_uops + 2) > MAX_INSN)
50927         return false;
50928       else if (path != path_single)
50929         return false;
50930     }
50931   return true;
50932 }
50933
50934 /* Add an instruction INSN with NUM_UOPS micro-operations to the
50935    dispatch window WINDOW_LIST.  */
50936
50937 static void
50938 add_insn_window (rtx_insn *insn, dispatch_windows *window_list, int num_uops)
50939 {
50940   int byte_len = min_insn_size (insn);
50941   int num_insn = window_list->num_insn;
50942   int imm_size;
50943   sched_insn_info *window = window_list->window;
50944   enum dispatch_group group = get_insn_group (insn);
50945   enum insn_path path = get_insn_path (insn);
50946   int num_imm_operand;
50947   int num_imm32_operand;
50948   int num_imm64_operand;
50949
50950   if (!window_list->violation && group != disp_cmp
50951       && !fits_dispatch_window (insn))
50952     window_list->violation = true;
50953
50954   imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50955                                  &num_imm64_operand);
50956
50957   /* Initialize window with new instruction.  */
50958   window[num_insn].insn = insn;
50959   window[num_insn].byte_len = byte_len;
50960   window[num_insn].group = group;
50961   window[num_insn].path = path;
50962   window[num_insn].imm_bytes = imm_size;
50963
50964   window_list->window_size += byte_len;
50965   window_list->num_insn = num_insn + 1;
50966   window_list->num_uops = window_list->num_uops + num_uops;
50967   window_list->imm_size += imm_size;
50968   window_list->num_imm += num_imm_operand;
50969   window_list->num_imm_32 += num_imm32_operand;
50970   window_list->num_imm_64 += num_imm64_operand;
50971
50972   if (group == disp_store)
50973     window_list->num_stores += 1;
50974   else if (group == disp_load
50975            || group == disp_prefetch)
50976     window_list->num_loads += 1;
50977   else if (group == disp_load_store)
50978     {
50979       window_list->num_stores += 1;
50980       window_list->num_loads += 1;
50981     }
50982 }
50983
50984 /* Adds a scheduled instruction, INSN, to the current dispatch window.
50985    If the total bytes of instructions or the number of instructions in
50986    the window exceed allowable, it allocates a new window.  */
50987
50988 static void
50989 add_to_dispatch_window (rtx_insn *insn)
50990 {
50991   int byte_len;
50992   dispatch_windows *window_list;
50993   dispatch_windows *next_list;
50994   dispatch_windows *window0_list;
50995   enum insn_path path;
50996   enum dispatch_group insn_group;
50997   bool insn_fits;
50998   int num_insn;
50999   int num_uops;
51000   int window_num;
51001   int insn_num_uops;
51002   int sum;
51003
51004   if (INSN_CODE (insn) < 0)
51005     return;
51006
51007   byte_len = min_insn_size (insn);
51008   window_list = dispatch_window_list;
51009   next_list = window_list->next;
51010   path = get_insn_path (insn);
51011   insn_group = get_insn_group (insn);
51012
51013   /* Get the last dispatch window.  */
51014   if (next_list)
51015       window_list = dispatch_window_list->next;
51016
51017   if (path == path_single)
51018     insn_num_uops = 1;
51019   else if (path == path_double)
51020     insn_num_uops = 2;
51021   else
51022     insn_num_uops = (int) path;
51023
51024   /* If current window is full, get a new window.
51025      Window number zero is full, if MAX_INSN uops are scheduled in it.
51026      Window number one is full, if window zero's bytes plus window
51027      one's bytes is 32, or if the bytes of the new instruction added
51028      to the total makes it greater than 48, or it has already MAX_INSN
51029      instructions in it.  */
51030   num_insn = window_list->num_insn;
51031   num_uops = window_list->num_uops;
51032   window_num = window_list->window_num;
51033   insn_fits = fits_dispatch_window (insn);
51034
51035   if (num_insn >= MAX_INSN
51036       || num_uops + insn_num_uops > MAX_INSN
51037       || !(insn_fits))
51038     {
51039       window_num = ~window_num & 1;
51040       window_list = allocate_next_window (window_num);
51041     }
51042
51043   if (window_num == 0)
51044     {
51045       add_insn_window (insn, window_list, insn_num_uops);
51046       if (window_list->num_insn >= MAX_INSN
51047           && insn_group == disp_branch)
51048         {
51049           process_end_window ();
51050           return;
51051         }
51052     }
51053   else if (window_num == 1)
51054     {
51055       window0_list = window_list->prev;
51056       sum = window0_list->window_size + window_list->window_size;
51057       if (sum == 32
51058           || (byte_len + sum) >= 48)
51059         {
51060           process_end_window ();
51061           window_list = dispatch_window_list;
51062         }
51063
51064       add_insn_window (insn, window_list, insn_num_uops);
51065     }
51066   else
51067     gcc_unreachable ();
51068
51069   if (is_end_basic_block (insn_group))
51070     {
51071       /* End of basic block is reached do end-basic-block process.  */
51072       process_end_window ();
51073       return;
51074     }
51075 }
51076
51077 /* Print the dispatch window, WINDOW_NUM, to FILE.  */
51078
51079 DEBUG_FUNCTION static void
51080 debug_dispatch_window_file (FILE *file, int window_num)
51081 {
51082   dispatch_windows *list;
51083   int i;
51084
51085   if (window_num == 0)
51086     list = dispatch_window_list;
51087   else
51088     list = dispatch_window_list1;
51089
51090   fprintf (file, "Window #%d:\n", list->window_num);
51091   fprintf (file, "  num_insn = %d, num_uops = %d, window_size = %d\n",
51092           list->num_insn, list->num_uops, list->window_size);
51093   fprintf (file, "  num_imm = %d, num_imm_32 = %d, num_imm_64 = %d, imm_size = %d\n",
51094            list->num_imm, list->num_imm_32, list->num_imm_64, list->imm_size);
51095
51096   fprintf (file, "  num_loads = %d, num_stores = %d\n", list->num_loads,
51097           list->num_stores);
51098   fprintf (file, " insn info:\n");
51099
51100   for (i = 0; i < MAX_INSN; i++)
51101     {
51102       if (!list->window[i].insn)
51103         break;
51104       fprintf (file, "    group[%d] = %s, insn[%d] = %p, path[%d] = %d byte_len[%d] = %d, imm_bytes[%d] = %d\n",
51105               i, group_name[list->window[i].group],
51106               i, (void *)list->window[i].insn,
51107               i, list->window[i].path,
51108               i, list->window[i].byte_len,
51109               i, list->window[i].imm_bytes);
51110     }
51111 }
51112
51113 /* Print to stdout a dispatch window.  */
51114
51115 DEBUG_FUNCTION void
51116 debug_dispatch_window (int window_num)
51117 {
51118   debug_dispatch_window_file (stdout, window_num);
51119 }
51120
51121 /* Print INSN dispatch information to FILE.  */
51122
51123 DEBUG_FUNCTION static void
51124 debug_insn_dispatch_info_file (FILE *file, rtx_insn *insn)
51125 {
51126   int byte_len;
51127   enum insn_path path;
51128   enum dispatch_group group;
51129   int imm_size;
51130   int num_imm_operand;
51131   int num_imm32_operand;
51132   int num_imm64_operand;
51133
51134   if (INSN_CODE (insn) < 0)
51135     return;
51136
51137   byte_len = min_insn_size (insn);
51138   path = get_insn_path (insn);
51139   group = get_insn_group (insn);
51140   imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
51141                                  &num_imm64_operand);
51142
51143   fprintf (file, " insn info:\n");
51144   fprintf (file, "  group = %s, path = %d, byte_len = %d\n",
51145            group_name[group], path, byte_len);
51146   fprintf (file, "  num_imm = %d, num_imm_32 = %d, num_imm_64 = %d, imm_size = %d\n",
51147            num_imm_operand, num_imm32_operand, num_imm64_operand, imm_size);
51148 }
51149
51150 /* Print to STDERR the status of the ready list with respect to
51151    dispatch windows.  */
51152
51153 DEBUG_FUNCTION void
51154 debug_ready_dispatch (void)
51155 {
51156   int i;
51157   int no_ready = number_in_ready ();
51158
51159   fprintf (stdout, "Number of ready: %d\n", no_ready);
51160
51161   for (i = 0; i < no_ready; i++)
51162     debug_insn_dispatch_info_file (stdout, get_ready_element (i));
51163 }
51164
51165 /* This routine is the driver of the dispatch scheduler.  */
51166
51167 static void
51168 do_dispatch (rtx_insn *insn, int mode)
51169 {
51170   if (mode == DISPATCH_INIT)
51171     init_dispatch_sched ();
51172   else if (mode == ADD_TO_DISPATCH_WINDOW)
51173     add_to_dispatch_window (insn);
51174 }
51175
51176 /* Return TRUE if Dispatch Scheduling is supported.  */
51177
51178 static bool
51179 has_dispatch (rtx_insn *insn, int action)
51180 {
51181   if ((TARGET_BDVER1 || TARGET_BDVER2 || TARGET_BDVER3 || TARGET_BDVER4)
51182       && flag_dispatch_scheduler)
51183     switch (action)
51184       {
51185       default:
51186         return false;
51187
51188       case IS_DISPATCH_ON:
51189         return true;
51190         break;
51191
51192       case IS_CMP:
51193         return is_cmp (insn);
51194
51195       case DISPATCH_VIOLATION:
51196         return dispatch_violation ();
51197
51198       case FITS_DISPATCH_WINDOW:
51199         return fits_dispatch_window (insn);
51200       }
51201
51202   return false;
51203 }
51204
51205 /* Implementation of reassociation_width target hook used by
51206    reassoc phase to identify parallelism level in reassociated
51207    tree.  Statements tree_code is passed in OPC.  Arguments type
51208    is passed in MODE.
51209
51210    Currently parallel reassociation is enabled for Atom
51211    processors only and we set reassociation width to be 2
51212    because Atom may issue up to 2 instructions per cycle.
51213
51214    Return value should be fixed if parallel reassociation is
51215    enabled for other processors.  */
51216
51217 static int
51218 ix86_reassociation_width (unsigned int, machine_mode mode)
51219 {
51220   /* Vector part.  */
51221   if (VECTOR_MODE_P (mode))
51222     {
51223       if (TARGET_VECTOR_PARALLEL_EXECUTION)
51224         return 2;
51225       else
51226         return 1;
51227     }
51228
51229   /* Scalar part.  */
51230   if (INTEGRAL_MODE_P (mode) && TARGET_REASSOC_INT_TO_PARALLEL)
51231     return 2;
51232   else if (FLOAT_MODE_P (mode) && TARGET_REASSOC_FP_TO_PARALLEL)
51233     return 2;
51234   else
51235     return 1;
51236 }
51237
51238 /* ??? No autovectorization into MMX or 3DNOW until we can reliably
51239    place emms and femms instructions.  */
51240
51241 static machine_mode
51242 ix86_preferred_simd_mode (machine_mode mode)
51243 {
51244   if (!TARGET_SSE)
51245     return word_mode;
51246
51247   switch (mode)
51248     {
51249     case QImode:
51250       return TARGET_AVX512BW ? V64QImode :
51251        (TARGET_AVX && !TARGET_PREFER_AVX128) ? V32QImode : V16QImode;
51252     case HImode:
51253       return TARGET_AVX512BW ? V32HImode :
51254        (TARGET_AVX && !TARGET_PREFER_AVX128) ? V16HImode : V8HImode;
51255     case SImode:
51256       return TARGET_AVX512F ? V16SImode :
51257         (TARGET_AVX && !TARGET_PREFER_AVX128) ? V8SImode : V4SImode;
51258     case DImode:
51259       return TARGET_AVX512F ? V8DImode :
51260         (TARGET_AVX && !TARGET_PREFER_AVX128) ? V4DImode : V2DImode;
51261
51262     case SFmode:
51263       if (TARGET_AVX512F)
51264         return V16SFmode;
51265       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
51266         return V8SFmode;
51267       else
51268         return V4SFmode;
51269
51270     case DFmode:
51271       if (!TARGET_VECTORIZE_DOUBLE)
51272         return word_mode;
51273       else if (TARGET_AVX512F)
51274         return V8DFmode;
51275       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
51276         return V4DFmode;
51277       else if (TARGET_SSE2)
51278         return V2DFmode;
51279       /* FALLTHRU */
51280
51281     default:
51282       return word_mode;
51283     }
51284 }
51285
51286 /* If AVX is enabled then try vectorizing with both 256bit and 128bit
51287    vectors.  If AVX512F is enabled then try vectorizing with 512bit,
51288    256bit and 128bit vectors.  */
51289
51290 static unsigned int
51291 ix86_autovectorize_vector_sizes (void)
51292 {
51293   return TARGET_AVX512F ? 64 | 32 | 16 :
51294     (TARGET_AVX && !TARGET_PREFER_AVX128) ? 32 | 16 : 0;
51295 }
51296
51297 \f
51298
51299 /* Return class of registers which could be used for pseudo of MODE
51300    and of class RCLASS for spilling instead of memory.  Return NO_REGS
51301    if it is not possible or non-profitable.  */
51302 static reg_class_t
51303 ix86_spill_class (reg_class_t rclass, machine_mode mode)
51304 {
51305   if (TARGET_SSE && TARGET_GENERAL_REGS_SSE_SPILL && ! TARGET_MMX
51306       && (mode == SImode || (TARGET_64BIT && mode == DImode))
51307       && rclass != NO_REGS && INTEGER_CLASS_P (rclass))
51308     return ALL_SSE_REGS;
51309   return NO_REGS;
51310 }
51311
51312 /* Implement targetm.vectorize.init_cost.  */
51313
51314 static void *
51315 ix86_init_cost (struct loop *)
51316 {
51317   unsigned *cost = XNEWVEC (unsigned, 3);
51318   cost[vect_prologue] = cost[vect_body] = cost[vect_epilogue] = 0;
51319   return cost;
51320 }
51321
51322 /* Implement targetm.vectorize.add_stmt_cost.  */
51323
51324 static unsigned
51325 ix86_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
51326                     struct _stmt_vec_info *stmt_info, int misalign,
51327                     enum vect_cost_model_location where)
51328 {
51329   unsigned *cost = (unsigned *) data;
51330   unsigned retval = 0;
51331
51332   tree vectype = stmt_info ? stmt_vectype (stmt_info) : NULL_TREE;
51333   int stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
51334
51335   /* Statements in an inner loop relative to the loop being
51336      vectorized are weighted more heavily.  The value here is
51337       arbitrary and could potentially be improved with analysis.  */
51338   if (where == vect_body && stmt_info && stmt_in_inner_loop_p (stmt_info))
51339     count *= 50;  /* FIXME.  */
51340
51341   retval = (unsigned) (count * stmt_cost);
51342
51343   /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
51344      for Silvermont as it has out of order integer pipeline and can execute
51345      2 scalar instruction per tick, but has in order SIMD pipeline.  */
51346   if (TARGET_SILVERMONT || TARGET_INTEL)
51347     if (stmt_info && stmt_info->stmt)
51348       {
51349         tree lhs_op = gimple_get_lhs (stmt_info->stmt);
51350         if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE)
51351           retval = (retval * 17) / 10;
51352       }
51353
51354   cost[where] += retval;
51355
51356   return retval;
51357 }
51358
51359 /* Implement targetm.vectorize.finish_cost.  */
51360
51361 static void
51362 ix86_finish_cost (void *data, unsigned *prologue_cost,
51363                   unsigned *body_cost, unsigned *epilogue_cost)
51364 {
51365   unsigned *cost = (unsigned *) data;
51366   *prologue_cost = cost[vect_prologue];
51367   *body_cost     = cost[vect_body];
51368   *epilogue_cost = cost[vect_epilogue];
51369 }
51370
51371 /* Implement targetm.vectorize.destroy_cost_data.  */
51372
51373 static void
51374 ix86_destroy_cost_data (void *data)
51375 {
51376   free (data);
51377 }
51378
51379 /* Validate target specific memory model bits in VAL. */
51380
51381 static unsigned HOST_WIDE_INT
51382 ix86_memmodel_check (unsigned HOST_WIDE_INT val)
51383 {
51384   enum memmodel model = memmodel_from_int (val);
51385   bool strong;
51386
51387   if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE
51388                                       |MEMMODEL_MASK)
51389       || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE)))
51390     {
51391       warning (OPT_Winvalid_memory_model,
51392                "Unknown architecture specific memory model");
51393       return MEMMODEL_SEQ_CST;
51394     }
51395   strong = (is_mm_acq_rel (model) || is_mm_seq_cst (model));
51396   if (val & IX86_HLE_ACQUIRE && !(is_mm_acquire (model) || strong))
51397     {
51398       warning (OPT_Winvalid_memory_model,
51399               "HLE_ACQUIRE not used with ACQUIRE or stronger memory model");
51400       return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE;
51401     }
51402   if (val & IX86_HLE_RELEASE && !(is_mm_release (model) || strong))
51403     {
51404       warning (OPT_Winvalid_memory_model,
51405               "HLE_RELEASE not used with RELEASE or stronger memory model");
51406       return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE;
51407     }
51408   return val;
51409 }
51410
51411 /* Set CLONEI->vecsize_mangle, CLONEI->vecsize_int,
51412    CLONEI->vecsize_float and if CLONEI->simdlen is 0, also
51413    CLONEI->simdlen.  Return 0 if SIMD clones shouldn't be emitted,
51414    or number of vecsize_mangle variants that should be emitted.  */
51415
51416 static int
51417 ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node,
51418                                              struct cgraph_simd_clone *clonei,
51419                                              tree base_type, int num)
51420 {
51421   int ret = 1;
51422
51423   if (clonei->simdlen
51424       && (clonei->simdlen < 2
51425           || clonei->simdlen > 16
51426           || (clonei->simdlen & (clonei->simdlen - 1)) != 0))
51427     {
51428       warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51429                   "unsupported simdlen %d", clonei->simdlen);
51430       return 0;
51431     }
51432
51433   tree ret_type = TREE_TYPE (TREE_TYPE (node->decl));
51434   if (TREE_CODE (ret_type) != VOID_TYPE)
51435     switch (TYPE_MODE (ret_type))
51436       {
51437       case QImode:
51438       case HImode:
51439       case SImode:
51440       case DImode:
51441       case SFmode:
51442       case DFmode:
51443       /* case SCmode: */
51444       /* case DCmode: */
51445         break;
51446       default:
51447         warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51448                     "unsupported return type %qT for simd\n", ret_type);
51449         return 0;
51450       }
51451
51452   tree t;
51453   int i;
51454
51455   for (t = DECL_ARGUMENTS (node->decl), i = 0; t; t = DECL_CHAIN (t), i++)
51456     /* FIXME: Shouldn't we allow such arguments if they are uniform?  */
51457     switch (TYPE_MODE (TREE_TYPE (t)))
51458       {
51459       case QImode:
51460       case HImode:
51461       case SImode:
51462       case DImode:
51463       case SFmode:
51464       case DFmode:
51465       /* case SCmode: */
51466       /* case DCmode: */
51467         break;
51468       default:
51469         warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51470                     "unsupported argument type %qT for simd\n", TREE_TYPE (t));
51471         return 0;
51472       }
51473
51474   if (clonei->cilk_elemental)
51475     {
51476       /* Parse here processor clause.  If not present, default to 'b'.  */
51477       clonei->vecsize_mangle = 'b';
51478     }
51479   else if (!TREE_PUBLIC (node->decl))
51480     {
51481       /* If the function isn't exported, we can pick up just one ISA
51482          for the clones.  */
51483       if (TARGET_AVX2)
51484         clonei->vecsize_mangle = 'd';
51485       else if (TARGET_AVX)
51486         clonei->vecsize_mangle = 'c';
51487       else
51488         clonei->vecsize_mangle = 'b';
51489       ret = 1;
51490     }
51491   else
51492     {
51493       clonei->vecsize_mangle = "bcd"[num];
51494       ret = 3;
51495     }
51496   switch (clonei->vecsize_mangle)
51497     {
51498     case 'b':
51499       clonei->vecsize_int = 128;
51500       clonei->vecsize_float = 128;
51501       break;
51502     case 'c':
51503       clonei->vecsize_int = 128;
51504       clonei->vecsize_float = 256;
51505       break;
51506     case 'd':
51507       clonei->vecsize_int = 256;
51508       clonei->vecsize_float = 256;
51509       break;
51510     }
51511   if (clonei->simdlen == 0)
51512     {
51513       if (SCALAR_INT_MODE_P (TYPE_MODE (base_type)))
51514         clonei->simdlen = clonei->vecsize_int;
51515       else
51516         clonei->simdlen = clonei->vecsize_float;
51517       clonei->simdlen /= GET_MODE_BITSIZE (TYPE_MODE (base_type));
51518       if (clonei->simdlen > 16)
51519         clonei->simdlen = 16;
51520     }
51521   return ret;
51522 }
51523
51524 /* Add target attribute to SIMD clone NODE if needed.  */
51525
51526 static void
51527 ix86_simd_clone_adjust (struct cgraph_node *node)
51528 {
51529   const char *str = NULL;
51530   gcc_assert (node->decl == cfun->decl);
51531   switch (node->simdclone->vecsize_mangle)
51532     {
51533     case 'b':
51534       if (!TARGET_SSE2)
51535         str = "sse2";
51536       break;
51537     case 'c':
51538       if (!TARGET_AVX)
51539         str = "avx";
51540       break;
51541     case 'd':
51542       if (!TARGET_AVX2)
51543         str = "avx2";
51544       break;
51545     default:
51546       gcc_unreachable ();
51547     }
51548   if (str == NULL)
51549     return;
51550   push_cfun (NULL);
51551   tree args = build_tree_list (NULL_TREE, build_string (strlen (str), str));
51552   bool ok = ix86_valid_target_attribute_p (node->decl, NULL, args, 0);
51553   gcc_assert (ok);
51554   pop_cfun ();
51555   ix86_reset_previous_fndecl ();
51556   ix86_set_current_function (node->decl);
51557 }
51558
51559 /* If SIMD clone NODE can't be used in a vectorized loop
51560    in current function, return -1, otherwise return a badness of using it
51561    (0 if it is most desirable from vecsize_mangle point of view, 1
51562    slightly less desirable, etc.).  */
51563
51564 static int
51565 ix86_simd_clone_usable (struct cgraph_node *node)
51566 {
51567   switch (node->simdclone->vecsize_mangle)
51568     {
51569     case 'b':
51570       if (!TARGET_SSE2)
51571         return -1;
51572       if (!TARGET_AVX)
51573         return 0;
51574       return TARGET_AVX2 ? 2 : 1;
51575     case 'c':
51576       if (!TARGET_AVX)
51577         return -1;
51578       return TARGET_AVX2 ? 1 : 0;
51579       break;
51580     case 'd':
51581       if (!TARGET_AVX2)
51582         return -1;
51583       return 0;
51584     default:
51585       gcc_unreachable ();
51586     }
51587 }
51588
51589 /* This function adjusts the unroll factor based on
51590    the hardware capabilities. For ex, bdver3 has
51591    a loop buffer which makes unrolling of smaller
51592    loops less important. This function decides the
51593    unroll factor using number of memory references
51594    (value 32 is used) as a heuristic. */
51595
51596 static unsigned
51597 ix86_loop_unroll_adjust (unsigned nunroll, struct loop *loop)
51598 {
51599   basic_block *bbs;
51600   rtx_insn *insn;
51601   unsigned i;
51602   unsigned mem_count = 0;
51603
51604   if (!TARGET_ADJUST_UNROLL)
51605      return nunroll;
51606
51607   /* Count the number of memory references within the loop body.
51608      This value determines the unrolling factor for bdver3 and bdver4
51609      architectures. */
51610   subrtx_iterator::array_type array;
51611   bbs = get_loop_body (loop);
51612   for (i = 0; i < loop->num_nodes; i++)
51613     FOR_BB_INSNS (bbs[i], insn)
51614       if (NONDEBUG_INSN_P (insn))
51615         FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
51616           if (const_rtx x = *iter)
51617             if (MEM_P (x))
51618               {
51619                 machine_mode mode = GET_MODE (x);
51620                 unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
51621                 if (n_words > 4)
51622                   mem_count += 2;
51623                 else
51624                   mem_count += 1;
51625               }
51626   free (bbs);
51627
51628   if (mem_count && mem_count <=32)
51629     return 32/mem_count;
51630
51631   return nunroll;
51632 }
51633
51634
51635 /* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P.  */
51636
51637 static bool
51638 ix86_float_exceptions_rounding_supported_p (void)
51639 {
51640   /* For x87 floating point with standard excess precision handling,
51641      there is no adddf3 pattern (since x87 floating point only has
51642      XFmode operations) so the default hook implementation gets this
51643      wrong.  */
51644   return TARGET_80387 || TARGET_SSE_MATH;
51645 }
51646
51647 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV.  */
51648
51649 static void
51650 ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
51651 {
51652   if (!TARGET_80387 && !TARGET_SSE_MATH)
51653     return;
51654   tree exceptions_var = create_tmp_var (integer_type_node);
51655   if (TARGET_80387)
51656     {
51657       tree fenv_index_type = build_index_type (size_int (6));
51658       tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
51659       tree fenv_var = create_tmp_var (fenv_type);
51660       mark_addressable (fenv_var);
51661       tree fenv_ptr = build_pointer_type (fenv_type);
51662       tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
51663       fenv_addr = fold_convert (ptr_type_node, fenv_addr);
51664       tree fnstenv = ix86_builtins[IX86_BUILTIN_FNSTENV];
51665       tree fldenv = ix86_builtins[IX86_BUILTIN_FLDENV];
51666       tree fnstsw = ix86_builtins[IX86_BUILTIN_FNSTSW];
51667       tree fnclex = ix86_builtins[IX86_BUILTIN_FNCLEX];
51668       tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
51669       tree hold_fnclex = build_call_expr (fnclex, 0);
51670       *hold = build2 (COMPOUND_EXPR, void_type_node, hold_fnstenv,
51671                       hold_fnclex);
51672       *clear = build_call_expr (fnclex, 0);
51673       tree sw_var = create_tmp_var (short_unsigned_type_node);
51674       tree fnstsw_call = build_call_expr (fnstsw, 0);
51675       tree sw_mod = build2 (MODIFY_EXPR, short_unsigned_type_node,
51676                             sw_var, fnstsw_call);
51677       tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
51678       tree update_mod = build2 (MODIFY_EXPR, integer_type_node,
51679                                 exceptions_var, exceptions_x87);
51680       *update = build2 (COMPOUND_EXPR, integer_type_node,
51681                         sw_mod, update_mod);
51682       tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
51683       *update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv);
51684     }
51685   if (TARGET_SSE_MATH)
51686     {
51687       tree mxcsr_orig_var = create_tmp_var (unsigned_type_node);
51688       tree mxcsr_mod_var = create_tmp_var (unsigned_type_node);
51689       tree stmxcsr = ix86_builtins[IX86_BUILTIN_STMXCSR];
51690       tree ldmxcsr = ix86_builtins[IX86_BUILTIN_LDMXCSR];
51691       tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
51692       tree hold_assign_orig = build2 (MODIFY_EXPR, unsigned_type_node,
51693                                       mxcsr_orig_var, stmxcsr_hold_call);
51694       tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
51695                                   mxcsr_orig_var,
51696                                   build_int_cst (unsigned_type_node, 0x1f80));
51697       hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
51698                              build_int_cst (unsigned_type_node, 0xffffffc0));
51699       tree hold_assign_mod = build2 (MODIFY_EXPR, unsigned_type_node,
51700                                      mxcsr_mod_var, hold_mod_val);
51701       tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
51702       tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
51703                               hold_assign_orig, hold_assign_mod);
51704       hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all,
51705                          ldmxcsr_hold_call);
51706       if (*hold)
51707         *hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all);
51708       else
51709         *hold = hold_all;
51710       tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
51711       if (*clear)
51712         *clear = build2 (COMPOUND_EXPR, void_type_node, *clear,
51713                          ldmxcsr_clear_call);
51714       else
51715         *clear = ldmxcsr_clear_call;
51716       tree stxmcsr_update_call = build_call_expr (stmxcsr, 0);
51717       tree exceptions_sse = fold_convert (integer_type_node,
51718                                           stxmcsr_update_call);
51719       if (*update)
51720         {
51721           tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node,
51722                                         exceptions_var, exceptions_sse);
51723           tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node,
51724                                            exceptions_var, exceptions_mod);
51725           *update = build2 (COMPOUND_EXPR, integer_type_node, *update,
51726                             exceptions_assign);
51727         }
51728       else
51729         *update = build2 (MODIFY_EXPR, integer_type_node,
51730                           exceptions_var, exceptions_sse);
51731       tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
51732       *update = build2 (COMPOUND_EXPR, void_type_node, *update,
51733                         ldmxcsr_update_call);
51734     }
51735   tree atomic_feraiseexcept
51736     = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
51737   tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
51738                                                     1, exceptions_var);
51739   *update = build2 (COMPOUND_EXPR, void_type_node, *update,
51740                     atomic_feraiseexcept_call);
51741 }
51742
51743 /* Return mode to be used for bounds or VOIDmode
51744    if bounds are not supported.  */
51745
51746 static enum machine_mode
51747 ix86_mpx_bound_mode ()
51748 {
51749   /* Do not support pointer checker if MPX
51750      is not enabled.  */
51751   if (!TARGET_MPX)
51752     {
51753       if (flag_check_pointer_bounds)
51754         warning (0, "Pointer Checker requires MPX support on this target."
51755                  " Use -mmpx options to enable MPX.");
51756       return VOIDmode;
51757     }
51758
51759   return BNDmode;
51760 }
51761
51762 /*  Return constant used to statically initialize constant bounds.
51763
51764     This function is used to create special bound values.  For now
51765     only INIT bounds and NONE bounds are expected.  More special
51766     values may be added later.  */
51767
51768 static tree
51769 ix86_make_bounds_constant (HOST_WIDE_INT lb, HOST_WIDE_INT ub)
51770 {
51771   tree low = lb ? build_minus_one_cst (pointer_sized_int_node)
51772     : build_zero_cst (pointer_sized_int_node);
51773   tree high = ub ? build_zero_cst (pointer_sized_int_node)
51774     : build_minus_one_cst (pointer_sized_int_node);
51775
51776   /* This function is supposed to be used to create INIT and
51777      NONE bounds only.  */
51778   gcc_assert ((lb == 0 && ub == -1)
51779               || (lb == -1 && ub == 0));
51780
51781   return build_complex (NULL, low, high);
51782 }
51783
51784 /* Generate a list of statements STMTS to initialize pointer bounds
51785    variable VAR with bounds LB and UB.  Return the number of generated
51786    statements.  */
51787
51788 static int
51789 ix86_initialize_bounds (tree var, tree lb, tree ub, tree *stmts)
51790 {
51791   tree bnd_ptr = build_pointer_type (pointer_sized_int_node);
51792   tree lhs, modify, var_p;
51793
51794   ub = build1 (BIT_NOT_EXPR, pointer_sized_int_node, ub);
51795   var_p = fold_convert (bnd_ptr, build_fold_addr_expr (var));
51796
51797   lhs = build1 (INDIRECT_REF, pointer_sized_int_node, var_p);
51798   modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, lb);
51799   append_to_statement_list (modify, stmts);
51800
51801   lhs = build1 (INDIRECT_REF, pointer_sized_int_node,
51802                 build2 (POINTER_PLUS_EXPR, bnd_ptr, var_p,
51803                         TYPE_SIZE_UNIT (pointer_sized_int_node)));
51804   modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, ub);
51805   append_to_statement_list (modify, stmts);
51806
51807   return 2;
51808 }
51809
51810 #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
51811 /* For i386, common symbol is local only for non-PIE binaries.  For
51812    x86-64, common symbol is local only for non-PIE binaries or linker
51813    supports copy reloc in PIE binaries.   */
51814
51815 static bool
51816 ix86_binds_local_p (const_tree exp)
51817 {
51818   return default_binds_local_p_3 (exp, flag_shlib != 0, true, true,
51819                                   (!flag_pic
51820                                    || (TARGET_64BIT
51821                                        && HAVE_LD_PIE_COPYRELOC != 0)));
51822 }
51823 #endif
51824
51825 /* If MEM is in the form of [base+offset], extract the two parts
51826    of address and set to BASE and OFFSET, otherwise return false.  */
51827
51828 static bool
51829 extract_base_offset_in_addr (rtx mem, rtx *base, rtx *offset)
51830 {
51831   rtx addr;
51832
51833   gcc_assert (MEM_P (mem));
51834
51835   addr = XEXP (mem, 0);
51836   
51837   if (GET_CODE (addr) == CONST)
51838     addr = XEXP (addr, 0);
51839
51840   if (REG_P (addr) || GET_CODE (addr) == SYMBOL_REF)
51841     {
51842       *base = addr;
51843       *offset = const0_rtx;
51844       return true;
51845     }
51846
51847   if (GET_CODE (addr) == PLUS
51848       && (REG_P (XEXP (addr, 0))
51849           || GET_CODE (XEXP (addr, 0)) == SYMBOL_REF)
51850       && CONST_INT_P (XEXP (addr, 1)))
51851     {
51852       *base = XEXP (addr, 0);
51853       *offset = XEXP (addr, 1);
51854       return true;
51855     }
51856
51857   return false;
51858 }
51859
51860 /* Given OPERANDS of consecutive load/store, check if we can merge
51861    them into move multiple.  LOAD is true if they are load instructions.
51862    MODE is the mode of memory operands.  */
51863
51864 bool
51865 ix86_operands_ok_for_move_multiple (rtx *operands, bool load,
51866                                     enum machine_mode mode)
51867 {
51868   HOST_WIDE_INT offval_1, offval_2, msize;
51869   rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2, offset_1, offset_2;
51870
51871   if (load)
51872     {
51873       mem_1 = operands[1];
51874       mem_2 = operands[3];
51875       reg_1 = operands[0];
51876       reg_2 = operands[2];
51877     }
51878   else
51879     {
51880       mem_1 = operands[0];
51881       mem_2 = operands[2];
51882       reg_1 = operands[1];
51883       reg_2 = operands[3];
51884     }
51885
51886   gcc_assert (REG_P (reg_1) && REG_P (reg_2));
51887
51888   if (REGNO (reg_1) != REGNO (reg_2))
51889     return false;
51890
51891   /* Check if the addresses are in the form of [base+offset].  */
51892   if (!extract_base_offset_in_addr (mem_1, &base_1, &offset_1))
51893     return false;
51894   if (!extract_base_offset_in_addr (mem_2, &base_2, &offset_2))
51895     return false;
51896
51897   /* Check if the bases are the same.  */
51898   if (!rtx_equal_p (base_1, base_2))
51899     return false;
51900
51901   offval_1 = INTVAL (offset_1);
51902   offval_2 = INTVAL (offset_2);
51903   msize = GET_MODE_SIZE (mode);
51904   /* Check if mem_1 is adjacent to mem_2 and mem_1 has lower address.  */
51905   if (offval_1 + msize != offval_2)
51906     return false;
51907
51908   return true;
51909 }
51910
51911 /* Initialize the GCC target structure.  */
51912 #undef TARGET_RETURN_IN_MEMORY
51913 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
51914
51915 #undef TARGET_LEGITIMIZE_ADDRESS
51916 #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
51917
51918 #undef TARGET_ATTRIBUTE_TABLE
51919 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
51920 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
51921 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
51922 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
51923 #  undef TARGET_MERGE_DECL_ATTRIBUTES
51924 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
51925 #endif
51926
51927 #undef TARGET_COMP_TYPE_ATTRIBUTES
51928 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
51929
51930 #undef TARGET_INIT_BUILTINS
51931 #define TARGET_INIT_BUILTINS ix86_init_builtins
51932 #undef TARGET_BUILTIN_DECL
51933 #define TARGET_BUILTIN_DECL ix86_builtin_decl
51934 #undef TARGET_EXPAND_BUILTIN
51935 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
51936
51937 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
51938 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
51939   ix86_builtin_vectorized_function
51940
51941 #undef TARGET_VECTORIZE_BUILTIN_TM_LOAD
51942 #define TARGET_VECTORIZE_BUILTIN_TM_LOAD ix86_builtin_tm_load
51943
51944 #undef TARGET_VECTORIZE_BUILTIN_TM_STORE
51945 #define TARGET_VECTORIZE_BUILTIN_TM_STORE ix86_builtin_tm_store
51946
51947 #undef TARGET_VECTORIZE_BUILTIN_GATHER
51948 #define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather
51949
51950 #undef TARGET_BUILTIN_RECIPROCAL
51951 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
51952
51953 #undef TARGET_ASM_FUNCTION_EPILOGUE
51954 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
51955
51956 #undef TARGET_ENCODE_SECTION_INFO
51957 #ifndef SUBTARGET_ENCODE_SECTION_INFO
51958 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
51959 #else
51960 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
51961 #endif
51962
51963 #undef TARGET_ASM_OPEN_PAREN
51964 #define TARGET_ASM_OPEN_PAREN ""
51965 #undef TARGET_ASM_CLOSE_PAREN
51966 #define TARGET_ASM_CLOSE_PAREN ""
51967
51968 #undef TARGET_ASM_BYTE_OP
51969 #define TARGET_ASM_BYTE_OP ASM_BYTE
51970
51971 #undef TARGET_ASM_ALIGNED_HI_OP
51972 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
51973 #undef TARGET_ASM_ALIGNED_SI_OP
51974 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
51975 #ifdef ASM_QUAD
51976 #undef TARGET_ASM_ALIGNED_DI_OP
51977 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
51978 #endif
51979
51980 #undef TARGET_PROFILE_BEFORE_PROLOGUE
51981 #define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
51982
51983 #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
51984 #define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name
51985
51986 #undef TARGET_ASM_UNALIGNED_HI_OP
51987 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
51988 #undef TARGET_ASM_UNALIGNED_SI_OP
51989 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
51990 #undef TARGET_ASM_UNALIGNED_DI_OP
51991 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
51992
51993 #undef TARGET_PRINT_OPERAND
51994 #define TARGET_PRINT_OPERAND ix86_print_operand
51995 #undef TARGET_PRINT_OPERAND_ADDRESS
51996 #define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address
51997 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
51998 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p
51999 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
52000 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra
52001
52002 #undef TARGET_SCHED_INIT_GLOBAL
52003 #define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global
52004 #undef TARGET_SCHED_ADJUST_COST
52005 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
52006 #undef TARGET_SCHED_ISSUE_RATE
52007 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
52008 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
52009 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
52010   ia32_multipass_dfa_lookahead
52011 #undef TARGET_SCHED_MACRO_FUSION_P
52012 #define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p
52013 #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
52014 #define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p
52015
52016 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
52017 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
52018
52019 #undef TARGET_MEMMODEL_CHECK
52020 #define TARGET_MEMMODEL_CHECK ix86_memmodel_check
52021
52022 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
52023 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv
52024
52025 #ifdef HAVE_AS_TLS
52026 #undef TARGET_HAVE_TLS
52027 #define TARGET_HAVE_TLS true
52028 #endif
52029 #undef TARGET_CANNOT_FORCE_CONST_MEM
52030 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
52031 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
52032 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
52033
52034 #undef TARGET_DELEGITIMIZE_ADDRESS
52035 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
52036
52037 #undef TARGET_MS_BITFIELD_LAYOUT_P
52038 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
52039
52040 #if TARGET_MACHO
52041 #undef TARGET_BINDS_LOCAL_P
52042 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
52043 #else
52044 #undef TARGET_BINDS_LOCAL_P
52045 #define TARGET_BINDS_LOCAL_P ix86_binds_local_p
52046 #endif
52047 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
52048 #undef TARGET_BINDS_LOCAL_P
52049 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
52050 #endif
52051
52052 #undef TARGET_ASM_OUTPUT_MI_THUNK
52053 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
52054 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
52055 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
52056
52057 #undef TARGET_ASM_FILE_START
52058 #define TARGET_ASM_FILE_START x86_file_start
52059
52060 #undef TARGET_OPTION_OVERRIDE
52061 #define TARGET_OPTION_OVERRIDE ix86_option_override
52062
52063 #undef TARGET_REGISTER_MOVE_COST
52064 #define TARGET_REGISTER_MOVE_COST ix86_register_move_cost
52065 #undef TARGET_MEMORY_MOVE_COST
52066 #define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost
52067 #undef TARGET_RTX_COSTS
52068 #define TARGET_RTX_COSTS ix86_rtx_costs
52069 #undef TARGET_ADDRESS_COST
52070 #define TARGET_ADDRESS_COST ix86_address_cost
52071
52072 #undef TARGET_FIXED_CONDITION_CODE_REGS
52073 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
52074 #undef TARGET_CC_MODES_COMPATIBLE
52075 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
52076
52077 #undef TARGET_MACHINE_DEPENDENT_REORG
52078 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
52079
52080 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
52081 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE ix86_builtin_setjmp_frame_value
52082
52083 #undef TARGET_BUILD_BUILTIN_VA_LIST
52084 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
52085
52086 #undef TARGET_FOLD_BUILTIN
52087 #define TARGET_FOLD_BUILTIN ix86_fold_builtin
52088
52089 #undef TARGET_COMPARE_VERSION_PRIORITY
52090 #define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority
52091
52092 #undef TARGET_GENERATE_VERSION_DISPATCHER_BODY
52093 #define TARGET_GENERATE_VERSION_DISPATCHER_BODY \
52094   ix86_generate_version_dispatcher_body
52095
52096 #undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
52097 #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
52098   ix86_get_function_versions_dispatcher
52099
52100 #undef TARGET_ENUM_VA_LIST_P
52101 #define TARGET_ENUM_VA_LIST_P ix86_enum_va_list
52102
52103 #undef TARGET_FN_ABI_VA_LIST
52104 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
52105
52106 #undef TARGET_CANONICAL_VA_LIST_TYPE
52107 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
52108
52109 #undef TARGET_EXPAND_BUILTIN_VA_START
52110 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
52111
52112 #undef TARGET_MD_ASM_ADJUST
52113 #define TARGET_MD_ASM_ADJUST ix86_md_asm_adjust
52114
52115 #undef TARGET_PROMOTE_PROTOTYPES
52116 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
52117 #undef TARGET_SETUP_INCOMING_VARARGS
52118 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
52119 #undef TARGET_MUST_PASS_IN_STACK
52120 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
52121 #undef TARGET_FUNCTION_ARG_ADVANCE
52122 #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance
52123 #undef TARGET_FUNCTION_ARG
52124 #define TARGET_FUNCTION_ARG ix86_function_arg
52125 #undef TARGET_INIT_PIC_REG
52126 #define TARGET_INIT_PIC_REG ix86_init_pic_reg
52127 #undef TARGET_USE_PSEUDO_PIC_REG
52128 #define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg
52129 #undef TARGET_FUNCTION_ARG_BOUNDARY
52130 #define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary
52131 #undef TARGET_PASS_BY_REFERENCE
52132 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
52133 #undef TARGET_INTERNAL_ARG_POINTER
52134 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
52135 #undef TARGET_UPDATE_STACK_BOUNDARY
52136 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
52137 #undef TARGET_GET_DRAP_RTX
52138 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
52139 #undef TARGET_STRICT_ARGUMENT_NAMING
52140 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
52141 #undef TARGET_STATIC_CHAIN
52142 #define TARGET_STATIC_CHAIN ix86_static_chain
52143 #undef TARGET_TRAMPOLINE_INIT
52144 #define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
52145 #undef TARGET_RETURN_POPS_ARGS
52146 #define TARGET_RETURN_POPS_ARGS ix86_return_pops_args
52147
52148 #undef TARGET_LEGITIMATE_COMBINED_INSN
52149 #define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn
52150
52151 #undef TARGET_ASAN_SHADOW_OFFSET
52152 #define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset
52153
52154 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
52155 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
52156
52157 #undef TARGET_SCALAR_MODE_SUPPORTED_P
52158 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
52159
52160 #undef TARGET_VECTOR_MODE_SUPPORTED_P
52161 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
52162
52163 #undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
52164 #define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \
52165   ix86_libgcc_floating_mode_supported_p
52166
52167 #undef TARGET_C_MODE_FOR_SUFFIX
52168 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
52169
52170 #ifdef HAVE_AS_TLS
52171 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
52172 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
52173 #endif
52174
52175 #ifdef SUBTARGET_INSERT_ATTRIBUTES
52176 #undef TARGET_INSERT_ATTRIBUTES
52177 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
52178 #endif
52179
52180 #undef TARGET_MANGLE_TYPE
52181 #define TARGET_MANGLE_TYPE ix86_mangle_type
52182
52183 #if !TARGET_MACHO
52184 #undef TARGET_STACK_PROTECT_FAIL
52185 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
52186 #endif
52187
52188 #undef TARGET_FUNCTION_VALUE
52189 #define TARGET_FUNCTION_VALUE ix86_function_value
52190
52191 #undef TARGET_FUNCTION_VALUE_REGNO_P
52192 #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
52193
52194 #undef TARGET_PROMOTE_FUNCTION_MODE
52195 #define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
52196
52197 #undef  TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
52198 #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE ix86_override_options_after_change
52199
52200 #undef TARGET_MEMBER_TYPE_FORCES_BLK
52201 #define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk
52202
52203 #undef TARGET_INSTANTIATE_DECLS
52204 #define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls
52205
52206 #undef TARGET_SECONDARY_RELOAD
52207 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
52208
52209 #undef TARGET_CLASS_MAX_NREGS
52210 #define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs
52211
52212 #undef TARGET_PREFERRED_RELOAD_CLASS
52213 #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
52214 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
52215 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
52216 #undef TARGET_CLASS_LIKELY_SPILLED_P
52217 #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
52218
52219 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
52220 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
52221   ix86_builtin_vectorization_cost
52222 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
52223 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
52224   ix86_vectorize_vec_perm_const_ok
52225 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
52226 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
52227   ix86_preferred_simd_mode
52228 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
52229 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
52230   ix86_autovectorize_vector_sizes
52231 #undef TARGET_VECTORIZE_INIT_COST
52232 #define TARGET_VECTORIZE_INIT_COST ix86_init_cost
52233 #undef TARGET_VECTORIZE_ADD_STMT_COST
52234 #define TARGET_VECTORIZE_ADD_STMT_COST ix86_add_stmt_cost
52235 #undef TARGET_VECTORIZE_FINISH_COST
52236 #define TARGET_VECTORIZE_FINISH_COST ix86_finish_cost
52237 #undef TARGET_VECTORIZE_DESTROY_COST_DATA
52238 #define TARGET_VECTORIZE_DESTROY_COST_DATA ix86_destroy_cost_data
52239
52240 #undef TARGET_SET_CURRENT_FUNCTION
52241 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
52242
52243 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
52244 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
52245
52246 #undef TARGET_OPTION_SAVE
52247 #define TARGET_OPTION_SAVE ix86_function_specific_save
52248
52249 #undef TARGET_OPTION_RESTORE
52250 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
52251
52252 #undef TARGET_OPTION_POST_STREAM_IN
52253 #define TARGET_OPTION_POST_STREAM_IN ix86_function_specific_post_stream_in
52254
52255 #undef TARGET_OPTION_PRINT
52256 #define TARGET_OPTION_PRINT ix86_function_specific_print
52257
52258 #undef TARGET_OPTION_FUNCTION_VERSIONS
52259 #define TARGET_OPTION_FUNCTION_VERSIONS ix86_function_versions
52260
52261 #undef TARGET_CAN_INLINE_P
52262 #define TARGET_CAN_INLINE_P ix86_can_inline_p
52263
52264 #undef TARGET_EXPAND_TO_RTL_HOOK
52265 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
52266
52267 #undef TARGET_LEGITIMATE_ADDRESS_P
52268 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
52269
52270 #undef TARGET_LRA_P
52271 #define TARGET_LRA_P hook_bool_void_true
52272
52273 #undef TARGET_REGISTER_PRIORITY
52274 #define TARGET_REGISTER_PRIORITY ix86_register_priority
52275
52276 #undef TARGET_REGISTER_USAGE_LEVELING_P
52277 #define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true
52278
52279 #undef TARGET_LEGITIMATE_CONSTANT_P
52280 #define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p
52281
52282 #undef TARGET_FRAME_POINTER_REQUIRED
52283 #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
52284
52285 #undef TARGET_CAN_ELIMINATE
52286 #define TARGET_CAN_ELIMINATE ix86_can_eliminate
52287
52288 #undef TARGET_EXTRA_LIVE_ON_ENTRY
52289 #define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry
52290
52291 #undef TARGET_ASM_CODE_END
52292 #define TARGET_ASM_CODE_END ix86_code_end
52293
52294 #undef TARGET_CONDITIONAL_REGISTER_USAGE
52295 #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
52296
52297 #if TARGET_MACHO
52298 #undef TARGET_INIT_LIBFUNCS
52299 #define TARGET_INIT_LIBFUNCS darwin_rename_builtins
52300 #endif
52301
52302 #undef TARGET_LOOP_UNROLL_ADJUST
52303 #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust
52304
52305 #undef TARGET_SPILL_CLASS
52306 #define TARGET_SPILL_CLASS ix86_spill_class
52307
52308 #undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
52309 #define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
52310   ix86_simd_clone_compute_vecsize_and_simdlen
52311
52312 #undef TARGET_SIMD_CLONE_ADJUST
52313 #define TARGET_SIMD_CLONE_ADJUST \
52314   ix86_simd_clone_adjust
52315
52316 #undef TARGET_SIMD_CLONE_USABLE
52317 #define TARGET_SIMD_CLONE_USABLE \
52318   ix86_simd_clone_usable
52319
52320 #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
52321 #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
52322   ix86_float_exceptions_rounding_supported_p
52323
52324 #undef TARGET_MODE_EMIT
52325 #define TARGET_MODE_EMIT ix86_emit_mode_set
52326
52327 #undef TARGET_MODE_NEEDED
52328 #define TARGET_MODE_NEEDED ix86_mode_needed
52329
52330 #undef TARGET_MODE_AFTER
52331 #define TARGET_MODE_AFTER ix86_mode_after
52332
52333 #undef TARGET_MODE_ENTRY
52334 #define TARGET_MODE_ENTRY ix86_mode_entry
52335
52336 #undef TARGET_MODE_EXIT
52337 #define TARGET_MODE_EXIT ix86_mode_exit
52338
52339 #undef TARGET_MODE_PRIORITY
52340 #define TARGET_MODE_PRIORITY ix86_mode_priority
52341
52342 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
52343 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
52344
52345 #undef TARGET_LOAD_BOUNDS_FOR_ARG
52346 #define TARGET_LOAD_BOUNDS_FOR_ARG ix86_load_bounds
52347
52348 #undef TARGET_STORE_BOUNDS_FOR_ARG
52349 #define TARGET_STORE_BOUNDS_FOR_ARG ix86_store_bounds
52350
52351 #undef TARGET_LOAD_RETURNED_BOUNDS
52352 #define TARGET_LOAD_RETURNED_BOUNDS ix86_load_returned_bounds
52353
52354 #undef TARGET_STORE_RETURNED_BOUNDS
52355 #define TARGET_STORE_RETURNED_BOUNDS ix86_store_returned_bounds
52356
52357 #undef TARGET_CHKP_BOUND_MODE
52358 #define TARGET_CHKP_BOUND_MODE ix86_mpx_bound_mode
52359
52360 #undef TARGET_BUILTIN_CHKP_FUNCTION
52361 #define TARGET_BUILTIN_CHKP_FUNCTION ix86_builtin_mpx_function
52362
52363 #undef TARGET_CHKP_FUNCTION_VALUE_BOUNDS
52364 #define TARGET_CHKP_FUNCTION_VALUE_BOUNDS ix86_function_value_bounds
52365
52366 #undef TARGET_CHKP_MAKE_BOUNDS_CONSTANT
52367 #define TARGET_CHKP_MAKE_BOUNDS_CONSTANT ix86_make_bounds_constant
52368
52369 #undef TARGET_CHKP_INITIALIZE_BOUNDS
52370 #define TARGET_CHKP_INITIALIZE_BOUNDS ix86_initialize_bounds
52371
52372 #undef TARGET_SETUP_INCOMING_VARARG_BOUNDS
52373 #define TARGET_SETUP_INCOMING_VARARG_BOUNDS ix86_setup_incoming_vararg_bounds
52374
52375 #undef TARGET_OFFLOAD_OPTIONS
52376 #define TARGET_OFFLOAD_OPTIONS \
52377   ix86_offload_options
52378
52379 #undef TARGET_ABSOLUTE_BIGGEST_ALIGNMENT
52380 #define TARGET_ABSOLUTE_BIGGEST_ALIGNMENT 512
52381
52382 struct gcc_target targetm = TARGET_INITIALIZER;
52383 \f
52384 #include "gt-i386.h"