re PR target/64386 (ICE: in extract_insn, at recog.c:2327 (unrecognizable insn) with...
[platform/upstream/gcc.git] / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "fold-const.h"
36 #include "stringpool.h"
37 #include "attribs.h"
38 #include "calls.h"
39 #include "stor-layout.h"
40 #include "varasm.h"
41 #include "tm_p.h"
42 #include "regs.h"
43 #include "hard-reg-set.h"
44 #include "insn-config.h"
45 #include "conditions.h"
46 #include "output.h"
47 #include "insn-codes.h"
48 #include "insn-attr.h"
49 #include "flags.h"
50 #include "except.h"
51 #include "input.h"
52 #include "function.h"
53 #include "recog.h"
54 #include "expr.h"
55 #include "optabs.h"
56 #include "diagnostic-core.h"
57 #include "toplev.h"
58 #include "predict.h"
59 #include "dominance.h"
60 #include "cfg.h"
61 #include "cfgrtl.h"
62 #include "cfganal.h"
63 #include "lcm.h"
64 #include "cfgbuild.h"
65 #include "cfgcleanup.h"
66 #include "basic-block.h"
67 #include "ggc.h"
68 #include "target.h"
69 #include "target-def.h"
70 #include "common/common-target.h"
71 #include "langhooks.h"
72 #include "reload.h"
73 #include "hash-map.h"
74 #include "is-a.h"
75 #include "plugin-api.h"
76 #include "ipa-ref.h"
77 #include "cgraph.h"
78 #include "hash-table.h"
79 #include "tree-ssa-alias.h"
80 #include "internal-fn.h"
81 #include "gimple-fold.h"
82 #include "tree-eh.h"
83 #include "gimple-expr.h"
84 #include "gimple.h"
85 #include "gimplify.h"
86 #include "cfgloop.h"
87 #include "dwarf2.h"
88 #include "df.h"
89 #include "tm-constrs.h"
90 #include "params.h"
91 #include "cselib.h"
92 #include "debug.h"
93 #include "sched-int.h"
94 #include "sbitmap.h"
95 #include "fibheap.h"
96 #include "opts.h"
97 #include "diagnostic.h"
98 #include "dumpfile.h"
99 #include "tree-pass.h"
100 #include "wide-int.h"
101 #include "context.h"
102 #include "pass_manager.h"
103 #include "target-globals.h"
104 #include "tree-vectorizer.h"
105 #include "shrink-wrap.h"
106 #include "builtins.h"
107 #include "rtl-iter.h"
108 #include "tree-iterator.h"
109 #include "tree-chkp.h"
110 #include "rtl-chkp.h"
111
112 static rtx legitimize_dllimport_symbol (rtx, bool);
113 static rtx legitimize_pe_coff_extern_decl (rtx, bool);
114 static rtx legitimize_pe_coff_symbol (rtx, bool);
115
116 #ifndef CHECK_STACK_LIMIT
117 #define CHECK_STACK_LIMIT (-1)
118 #endif
119
120 /* Return index of given mode in mult and division cost tables.  */
121 #define MODE_INDEX(mode)                                        \
122   ((mode) == QImode ? 0                                         \
123    : (mode) == HImode ? 1                                       \
124    : (mode) == SImode ? 2                                       \
125    : (mode) == DImode ? 3                                       \
126    : 4)
127
128 /* Processor costs (relative to an add) */
129 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
130 #define COSTS_N_BYTES(N) ((N) * 2)
131
132 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall, false}}}
133
134 static stringop_algs ix86_size_memcpy[2] = {
135   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
136   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}}};
137 static stringop_algs ix86_size_memset[2] = {
138   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
139   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}}};
140
141 const
142 struct processor_costs ix86_size_cost = {/* costs for tuning for size */
143   COSTS_N_BYTES (2),                    /* cost of an add instruction */
144   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
145   COSTS_N_BYTES (2),                    /* variable shift costs */
146   COSTS_N_BYTES (3),                    /* constant shift costs */
147   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
148    COSTS_N_BYTES (3),                   /*                               HI */
149    COSTS_N_BYTES (3),                   /*                               SI */
150    COSTS_N_BYTES (3),                   /*                               DI */
151    COSTS_N_BYTES (5)},                  /*                            other */
152   0,                                    /* cost of multiply per each bit set */
153   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
154    COSTS_N_BYTES (3),                   /*                          HI */
155    COSTS_N_BYTES (3),                   /*                          SI */
156    COSTS_N_BYTES (3),                   /*                          DI */
157    COSTS_N_BYTES (5)},                  /*                          other */
158   COSTS_N_BYTES (3),                    /* cost of movsx */
159   COSTS_N_BYTES (3),                    /* cost of movzx */
160   0,                                    /* "large" insn */
161   2,                                    /* MOVE_RATIO */
162   2,                                 /* cost for loading QImode using movzbl */
163   {2, 2, 2},                            /* cost of loading integer registers
164                                            in QImode, HImode and SImode.
165                                            Relative to reg-reg move (2).  */
166   {2, 2, 2},                            /* cost of storing integer registers */
167   2,                                    /* cost of reg,reg fld/fst */
168   {2, 2, 2},                            /* cost of loading fp registers
169                                            in SFmode, DFmode and XFmode */
170   {2, 2, 2},                            /* cost of storing fp registers
171                                            in SFmode, DFmode and XFmode */
172   3,                                    /* cost of moving MMX register */
173   {3, 3},                               /* cost of loading MMX registers
174                                            in SImode and DImode */
175   {3, 3},                               /* cost of storing MMX registers
176                                            in SImode and DImode */
177   3,                                    /* cost of moving SSE register */
178   {3, 3, 3},                            /* cost of loading SSE registers
179                                            in SImode, DImode and TImode */
180   {3, 3, 3},                            /* cost of storing SSE registers
181                                            in SImode, DImode and TImode */
182   3,                                    /* MMX or SSE register to integer */
183   0,                                    /* size of l1 cache  */
184   0,                                    /* size of l2 cache  */
185   0,                                    /* size of prefetch block */
186   0,                                    /* number of parallel prefetches */
187   2,                                    /* Branch cost */
188   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
189   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
190   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
191   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
192   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
193   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
194   ix86_size_memcpy,
195   ix86_size_memset,
196   1,                                    /* scalar_stmt_cost.  */
197   1,                                    /* scalar load_cost.  */
198   1,                                    /* scalar_store_cost.  */
199   1,                                    /* vec_stmt_cost.  */
200   1,                                    /* vec_to_scalar_cost.  */
201   1,                                    /* scalar_to_vec_cost.  */
202   1,                                    /* vec_align_load_cost.  */
203   1,                                    /* vec_unalign_load_cost.  */
204   1,                                    /* vec_store_cost.  */
205   1,                                    /* cond_taken_branch_cost.  */
206   1,                                    /* cond_not_taken_branch_cost.  */
207 };
208
209 /* Processor costs (relative to an add) */
210 static stringop_algs i386_memcpy[2] = {
211   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
212   DUMMY_STRINGOP_ALGS};
213 static stringop_algs i386_memset[2] = {
214   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
215   DUMMY_STRINGOP_ALGS};
216
217 static const
218 struct processor_costs i386_cost = {    /* 386 specific costs */
219   COSTS_N_INSNS (1),                    /* cost of an add instruction */
220   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
221   COSTS_N_INSNS (3),                    /* variable shift costs */
222   COSTS_N_INSNS (2),                    /* constant shift costs */
223   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
224    COSTS_N_INSNS (6),                   /*                               HI */
225    COSTS_N_INSNS (6),                   /*                               SI */
226    COSTS_N_INSNS (6),                   /*                               DI */
227    COSTS_N_INSNS (6)},                  /*                            other */
228   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
229   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
230    COSTS_N_INSNS (23),                  /*                          HI */
231    COSTS_N_INSNS (23),                  /*                          SI */
232    COSTS_N_INSNS (23),                  /*                          DI */
233    COSTS_N_INSNS (23)},                 /*                          other */
234   COSTS_N_INSNS (3),                    /* cost of movsx */
235   COSTS_N_INSNS (2),                    /* cost of movzx */
236   15,                                   /* "large" insn */
237   3,                                    /* MOVE_RATIO */
238   4,                                 /* cost for loading QImode using movzbl */
239   {2, 4, 2},                            /* cost of loading integer registers
240                                            in QImode, HImode and SImode.
241                                            Relative to reg-reg move (2).  */
242   {2, 4, 2},                            /* cost of storing integer registers */
243   2,                                    /* cost of reg,reg fld/fst */
244   {8, 8, 8},                            /* cost of loading fp registers
245                                            in SFmode, DFmode and XFmode */
246   {8, 8, 8},                            /* cost of storing fp registers
247                                            in SFmode, DFmode and XFmode */
248   2,                                    /* cost of moving MMX register */
249   {4, 8},                               /* cost of loading MMX registers
250                                            in SImode and DImode */
251   {4, 8},                               /* cost of storing MMX registers
252                                            in SImode and DImode */
253   2,                                    /* cost of moving SSE register */
254   {4, 8, 16},                           /* cost of loading SSE registers
255                                            in SImode, DImode and TImode */
256   {4, 8, 16},                           /* cost of storing SSE registers
257                                            in SImode, DImode and TImode */
258   3,                                    /* MMX or SSE register to integer */
259   0,                                    /* size of l1 cache  */
260   0,                                    /* size of l2 cache  */
261   0,                                    /* size of prefetch block */
262   0,                                    /* number of parallel prefetches */
263   1,                                    /* Branch cost */
264   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
265   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
266   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
267   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
268   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
269   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
270   i386_memcpy,
271   i386_memset,
272   1,                                    /* scalar_stmt_cost.  */
273   1,                                    /* scalar load_cost.  */
274   1,                                    /* scalar_store_cost.  */
275   1,                                    /* vec_stmt_cost.  */
276   1,                                    /* vec_to_scalar_cost.  */
277   1,                                    /* scalar_to_vec_cost.  */
278   1,                                    /* vec_align_load_cost.  */
279   2,                                    /* vec_unalign_load_cost.  */
280   1,                                    /* vec_store_cost.  */
281   3,                                    /* cond_taken_branch_cost.  */
282   1,                                    /* cond_not_taken_branch_cost.  */
283 };
284
285 static stringop_algs i486_memcpy[2] = {
286   {rep_prefix_4_byte, {{-1, rep_prefix_4_byte, false}}},
287   DUMMY_STRINGOP_ALGS};
288 static stringop_algs i486_memset[2] = {
289   {rep_prefix_4_byte, {{-1, rep_prefix_4_byte, false}}},
290   DUMMY_STRINGOP_ALGS};
291
292 static const
293 struct processor_costs i486_cost = {    /* 486 specific costs */
294   COSTS_N_INSNS (1),                    /* cost of an add instruction */
295   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
296   COSTS_N_INSNS (3),                    /* variable shift costs */
297   COSTS_N_INSNS (2),                    /* constant shift costs */
298   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
299    COSTS_N_INSNS (12),                  /*                               HI */
300    COSTS_N_INSNS (12),                  /*                               SI */
301    COSTS_N_INSNS (12),                  /*                               DI */
302    COSTS_N_INSNS (12)},                 /*                            other */
303   1,                                    /* cost of multiply per each bit set */
304   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
305    COSTS_N_INSNS (40),                  /*                          HI */
306    COSTS_N_INSNS (40),                  /*                          SI */
307    COSTS_N_INSNS (40),                  /*                          DI */
308    COSTS_N_INSNS (40)},                 /*                          other */
309   COSTS_N_INSNS (3),                    /* cost of movsx */
310   COSTS_N_INSNS (2),                    /* cost of movzx */
311   15,                                   /* "large" insn */
312   3,                                    /* MOVE_RATIO */
313   4,                                 /* cost for loading QImode using movzbl */
314   {2, 4, 2},                            /* cost of loading integer registers
315                                            in QImode, HImode and SImode.
316                                            Relative to reg-reg move (2).  */
317   {2, 4, 2},                            /* cost of storing integer registers */
318   2,                                    /* cost of reg,reg fld/fst */
319   {8, 8, 8},                            /* cost of loading fp registers
320                                            in SFmode, DFmode and XFmode */
321   {8, 8, 8},                            /* cost of storing fp registers
322                                            in SFmode, DFmode and XFmode */
323   2,                                    /* cost of moving MMX register */
324   {4, 8},                               /* cost of loading MMX registers
325                                            in SImode and DImode */
326   {4, 8},                               /* cost of storing MMX registers
327                                            in SImode and DImode */
328   2,                                    /* cost of moving SSE register */
329   {4, 8, 16},                           /* cost of loading SSE registers
330                                            in SImode, DImode and TImode */
331   {4, 8, 16},                           /* cost of storing SSE registers
332                                            in SImode, DImode and TImode */
333   3,                                    /* MMX or SSE register to integer */
334   4,                                    /* size of l1 cache.  486 has 8kB cache
335                                            shared for code and data, so 4kB is
336                                            not really precise.  */
337   4,                                    /* size of l2 cache  */
338   0,                                    /* size of prefetch block */
339   0,                                    /* number of parallel prefetches */
340   1,                                    /* Branch cost */
341   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
342   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
343   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
344   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
345   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
346   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
347   i486_memcpy,
348   i486_memset,
349   1,                                    /* scalar_stmt_cost.  */
350   1,                                    /* scalar load_cost.  */
351   1,                                    /* scalar_store_cost.  */
352   1,                                    /* vec_stmt_cost.  */
353   1,                                    /* vec_to_scalar_cost.  */
354   1,                                    /* scalar_to_vec_cost.  */
355   1,                                    /* vec_align_load_cost.  */
356   2,                                    /* vec_unalign_load_cost.  */
357   1,                                    /* vec_store_cost.  */
358   3,                                    /* cond_taken_branch_cost.  */
359   1,                                    /* cond_not_taken_branch_cost.  */
360 };
361
362 static stringop_algs pentium_memcpy[2] = {
363   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
364   DUMMY_STRINGOP_ALGS};
365 static stringop_algs pentium_memset[2] = {
366   {libcall, {{-1, rep_prefix_4_byte, false}}},
367   DUMMY_STRINGOP_ALGS};
368
369 static const
370 struct processor_costs pentium_cost = {
371   COSTS_N_INSNS (1),                    /* cost of an add instruction */
372   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
373   COSTS_N_INSNS (4),                    /* variable shift costs */
374   COSTS_N_INSNS (1),                    /* constant shift costs */
375   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
376    COSTS_N_INSNS (11),                  /*                               HI */
377    COSTS_N_INSNS (11),                  /*                               SI */
378    COSTS_N_INSNS (11),                  /*                               DI */
379    COSTS_N_INSNS (11)},                 /*                            other */
380   0,                                    /* cost of multiply per each bit set */
381   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
382    COSTS_N_INSNS (25),                  /*                          HI */
383    COSTS_N_INSNS (25),                  /*                          SI */
384    COSTS_N_INSNS (25),                  /*                          DI */
385    COSTS_N_INSNS (25)},                 /*                          other */
386   COSTS_N_INSNS (3),                    /* cost of movsx */
387   COSTS_N_INSNS (2),                    /* cost of movzx */
388   8,                                    /* "large" insn */
389   6,                                    /* MOVE_RATIO */
390   6,                                 /* cost for loading QImode using movzbl */
391   {2, 4, 2},                            /* cost of loading integer registers
392                                            in QImode, HImode and SImode.
393                                            Relative to reg-reg move (2).  */
394   {2, 4, 2},                            /* cost of storing integer registers */
395   2,                                    /* cost of reg,reg fld/fst */
396   {2, 2, 6},                            /* cost of loading fp registers
397                                            in SFmode, DFmode and XFmode */
398   {4, 4, 6},                            /* cost of storing fp registers
399                                            in SFmode, DFmode and XFmode */
400   8,                                    /* cost of moving MMX register */
401   {8, 8},                               /* cost of loading MMX registers
402                                            in SImode and DImode */
403   {8, 8},                               /* cost of storing MMX registers
404                                            in SImode and DImode */
405   2,                                    /* cost of moving SSE register */
406   {4, 8, 16},                           /* cost of loading SSE registers
407                                            in SImode, DImode and TImode */
408   {4, 8, 16},                           /* cost of storing SSE registers
409                                            in SImode, DImode and TImode */
410   3,                                    /* MMX or SSE register to integer */
411   8,                                    /* size of l1 cache.  */
412   8,                                    /* size of l2 cache  */
413   0,                                    /* size of prefetch block */
414   0,                                    /* number of parallel prefetches */
415   2,                                    /* Branch cost */
416   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
417   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
418   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
419   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
420   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
421   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
422   pentium_memcpy,
423   pentium_memset,
424   1,                                    /* scalar_stmt_cost.  */
425   1,                                    /* scalar load_cost.  */
426   1,                                    /* scalar_store_cost.  */
427   1,                                    /* vec_stmt_cost.  */
428   1,                                    /* vec_to_scalar_cost.  */
429   1,                                    /* scalar_to_vec_cost.  */
430   1,                                    /* vec_align_load_cost.  */
431   2,                                    /* vec_unalign_load_cost.  */
432   1,                                    /* vec_store_cost.  */
433   3,                                    /* cond_taken_branch_cost.  */
434   1,                                    /* cond_not_taken_branch_cost.  */
435 };
436
437 /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes
438    (we ensure the alignment).  For small blocks inline loop is still a
439    noticeable win, for bigger blocks either rep movsl or rep movsb is
440    way to go.  Rep movsb has apparently more expensive startup time in CPU,
441    but after 4K the difference is down in the noise.  */
442 static stringop_algs pentiumpro_memcpy[2] = {
443   {rep_prefix_4_byte, {{128, loop, false}, {1024, unrolled_loop, false},
444                        {8192, rep_prefix_4_byte, false},
445                        {-1, rep_prefix_1_byte, false}}},
446   DUMMY_STRINGOP_ALGS};
447 static stringop_algs pentiumpro_memset[2] = {
448   {rep_prefix_4_byte, {{1024, unrolled_loop, false},
449                        {8192, rep_prefix_4_byte, false},
450                        {-1, libcall, false}}},
451   DUMMY_STRINGOP_ALGS};
452 static const
453 struct processor_costs pentiumpro_cost = {
454   COSTS_N_INSNS (1),                    /* cost of an add instruction */
455   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
456   COSTS_N_INSNS (1),                    /* variable shift costs */
457   COSTS_N_INSNS (1),                    /* constant shift costs */
458   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
459    COSTS_N_INSNS (4),                   /*                               HI */
460    COSTS_N_INSNS (4),                   /*                               SI */
461    COSTS_N_INSNS (4),                   /*                               DI */
462    COSTS_N_INSNS (4)},                  /*                            other */
463   0,                                    /* cost of multiply per each bit set */
464   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
465    COSTS_N_INSNS (17),                  /*                          HI */
466    COSTS_N_INSNS (17),                  /*                          SI */
467    COSTS_N_INSNS (17),                  /*                          DI */
468    COSTS_N_INSNS (17)},                 /*                          other */
469   COSTS_N_INSNS (1),                    /* cost of movsx */
470   COSTS_N_INSNS (1),                    /* cost of movzx */
471   8,                                    /* "large" insn */
472   6,                                    /* MOVE_RATIO */
473   2,                                 /* cost for loading QImode using movzbl */
474   {4, 4, 4},                            /* cost of loading integer registers
475                                            in QImode, HImode and SImode.
476                                            Relative to reg-reg move (2).  */
477   {2, 2, 2},                            /* cost of storing integer registers */
478   2,                                    /* cost of reg,reg fld/fst */
479   {2, 2, 6},                            /* cost of loading fp registers
480                                            in SFmode, DFmode and XFmode */
481   {4, 4, 6},                            /* cost of storing fp registers
482                                            in SFmode, DFmode and XFmode */
483   2,                                    /* cost of moving MMX register */
484   {2, 2},                               /* cost of loading MMX registers
485                                            in SImode and DImode */
486   {2, 2},                               /* cost of storing MMX registers
487                                            in SImode and DImode */
488   2,                                    /* cost of moving SSE register */
489   {2, 2, 8},                            /* cost of loading SSE registers
490                                            in SImode, DImode and TImode */
491   {2, 2, 8},                            /* cost of storing SSE registers
492                                            in SImode, DImode and TImode */
493   3,                                    /* MMX or SSE register to integer */
494   8,                                    /* size of l1 cache.  */
495   256,                                  /* size of l2 cache  */
496   32,                                   /* size of prefetch block */
497   6,                                    /* number of parallel prefetches */
498   2,                                    /* Branch cost */
499   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
500   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
501   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
502   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
503   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
504   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
505   pentiumpro_memcpy,
506   pentiumpro_memset,
507   1,                                    /* scalar_stmt_cost.  */
508   1,                                    /* scalar load_cost.  */
509   1,                                    /* scalar_store_cost.  */
510   1,                                    /* vec_stmt_cost.  */
511   1,                                    /* vec_to_scalar_cost.  */
512   1,                                    /* scalar_to_vec_cost.  */
513   1,                                    /* vec_align_load_cost.  */
514   2,                                    /* vec_unalign_load_cost.  */
515   1,                                    /* vec_store_cost.  */
516   3,                                    /* cond_taken_branch_cost.  */
517   1,                                    /* cond_not_taken_branch_cost.  */
518 };
519
520 static stringop_algs geode_memcpy[2] = {
521   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
522   DUMMY_STRINGOP_ALGS};
523 static stringop_algs geode_memset[2] = {
524   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
525   DUMMY_STRINGOP_ALGS};
526 static const
527 struct processor_costs geode_cost = {
528   COSTS_N_INSNS (1),                    /* cost of an add instruction */
529   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
530   COSTS_N_INSNS (2),                    /* variable shift costs */
531   COSTS_N_INSNS (1),                    /* constant shift costs */
532   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
533    COSTS_N_INSNS (4),                   /*                               HI */
534    COSTS_N_INSNS (7),                   /*                               SI */
535    COSTS_N_INSNS (7),                   /*                               DI */
536    COSTS_N_INSNS (7)},                  /*                            other */
537   0,                                    /* cost of multiply per each bit set */
538   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
539    COSTS_N_INSNS (23),                  /*                          HI */
540    COSTS_N_INSNS (39),                  /*                          SI */
541    COSTS_N_INSNS (39),                  /*                          DI */
542    COSTS_N_INSNS (39)},                 /*                          other */
543   COSTS_N_INSNS (1),                    /* cost of movsx */
544   COSTS_N_INSNS (1),                    /* cost of movzx */
545   8,                                    /* "large" insn */
546   4,                                    /* MOVE_RATIO */
547   1,                                 /* cost for loading QImode using movzbl */
548   {1, 1, 1},                            /* cost of loading integer registers
549                                            in QImode, HImode and SImode.
550                                            Relative to reg-reg move (2).  */
551   {1, 1, 1},                            /* cost of storing integer registers */
552   1,                                    /* cost of reg,reg fld/fst */
553   {1, 1, 1},                            /* cost of loading fp registers
554                                            in SFmode, DFmode and XFmode */
555   {4, 6, 6},                            /* cost of storing fp registers
556                                            in SFmode, DFmode and XFmode */
557
558   1,                                    /* cost of moving MMX register */
559   {1, 1},                               /* cost of loading MMX registers
560                                            in SImode and DImode */
561   {1, 1},                               /* cost of storing MMX registers
562                                            in SImode and DImode */
563   1,                                    /* cost of moving SSE register */
564   {1, 1, 1},                            /* cost of loading SSE registers
565                                            in SImode, DImode and TImode */
566   {1, 1, 1},                            /* cost of storing SSE registers
567                                            in SImode, DImode and TImode */
568   1,                                    /* MMX or SSE register to integer */
569   64,                                   /* size of l1 cache.  */
570   128,                                  /* size of l2 cache.  */
571   32,                                   /* size of prefetch block */
572   1,                                    /* number of parallel prefetches */
573   1,                                    /* Branch cost */
574   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
575   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
576   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
577   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
578   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
579   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
580   geode_memcpy,
581   geode_memset,
582   1,                                    /* scalar_stmt_cost.  */
583   1,                                    /* scalar load_cost.  */
584   1,                                    /* scalar_store_cost.  */
585   1,                                    /* vec_stmt_cost.  */
586   1,                                    /* vec_to_scalar_cost.  */
587   1,                                    /* scalar_to_vec_cost.  */
588   1,                                    /* vec_align_load_cost.  */
589   2,                                    /* vec_unalign_load_cost.  */
590   1,                                    /* vec_store_cost.  */
591   3,                                    /* cond_taken_branch_cost.  */
592   1,                                    /* cond_not_taken_branch_cost.  */
593 };
594
595 static stringop_algs k6_memcpy[2] = {
596   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
597   DUMMY_STRINGOP_ALGS};
598 static stringop_algs k6_memset[2] = {
599   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
600   DUMMY_STRINGOP_ALGS};
601 static const
602 struct processor_costs k6_cost = {
603   COSTS_N_INSNS (1),                    /* cost of an add instruction */
604   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
605   COSTS_N_INSNS (1),                    /* variable shift costs */
606   COSTS_N_INSNS (1),                    /* constant shift costs */
607   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
608    COSTS_N_INSNS (3),                   /*                               HI */
609    COSTS_N_INSNS (3),                   /*                               SI */
610    COSTS_N_INSNS (3),                   /*                               DI */
611    COSTS_N_INSNS (3)},                  /*                            other */
612   0,                                    /* cost of multiply per each bit set */
613   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
614    COSTS_N_INSNS (18),                  /*                          HI */
615    COSTS_N_INSNS (18),                  /*                          SI */
616    COSTS_N_INSNS (18),                  /*                          DI */
617    COSTS_N_INSNS (18)},                 /*                          other */
618   COSTS_N_INSNS (2),                    /* cost of movsx */
619   COSTS_N_INSNS (2),                    /* cost of movzx */
620   8,                                    /* "large" insn */
621   4,                                    /* MOVE_RATIO */
622   3,                                 /* cost for loading QImode using movzbl */
623   {4, 5, 4},                            /* cost of loading integer registers
624                                            in QImode, HImode and SImode.
625                                            Relative to reg-reg move (2).  */
626   {2, 3, 2},                            /* cost of storing integer registers */
627   4,                                    /* cost of reg,reg fld/fst */
628   {6, 6, 6},                            /* cost of loading fp registers
629                                            in SFmode, DFmode and XFmode */
630   {4, 4, 4},                            /* cost of storing fp registers
631                                            in SFmode, DFmode and XFmode */
632   2,                                    /* cost of moving MMX register */
633   {2, 2},                               /* cost of loading MMX registers
634                                            in SImode and DImode */
635   {2, 2},                               /* cost of storing MMX registers
636                                            in SImode and DImode */
637   2,                                    /* cost of moving SSE register */
638   {2, 2, 8},                            /* cost of loading SSE registers
639                                            in SImode, DImode and TImode */
640   {2, 2, 8},                            /* cost of storing SSE registers
641                                            in SImode, DImode and TImode */
642   6,                                    /* MMX or SSE register to integer */
643   32,                                   /* size of l1 cache.  */
644   32,                                   /* size of l2 cache.  Some models
645                                            have integrated l2 cache, but
646                                            optimizing for k6 is not important
647                                            enough to worry about that.  */
648   32,                                   /* size of prefetch block */
649   1,                                    /* number of parallel prefetches */
650   1,                                    /* Branch cost */
651   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
652   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
653   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
654   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
655   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
656   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
657   k6_memcpy,
658   k6_memset,
659   1,                                    /* scalar_stmt_cost.  */
660   1,                                    /* scalar load_cost.  */
661   1,                                    /* scalar_store_cost.  */
662   1,                                    /* vec_stmt_cost.  */
663   1,                                    /* vec_to_scalar_cost.  */
664   1,                                    /* scalar_to_vec_cost.  */
665   1,                                    /* vec_align_load_cost.  */
666   2,                                    /* vec_unalign_load_cost.  */
667   1,                                    /* vec_store_cost.  */
668   3,                                    /* cond_taken_branch_cost.  */
669   1,                                    /* cond_not_taken_branch_cost.  */
670 };
671
672 /* For some reason, Athlon deals better with REP prefix (relative to loops)
673    compared to K8. Alignment becomes important after 8 bytes for memcpy and
674    128 bytes for memset.  */
675 static stringop_algs athlon_memcpy[2] = {
676   {libcall, {{2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
677   DUMMY_STRINGOP_ALGS};
678 static stringop_algs athlon_memset[2] = {
679   {libcall, {{2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
680   DUMMY_STRINGOP_ALGS};
681 static const
682 struct processor_costs athlon_cost = {
683   COSTS_N_INSNS (1),                    /* cost of an add instruction */
684   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
685   COSTS_N_INSNS (1),                    /* variable shift costs */
686   COSTS_N_INSNS (1),                    /* constant shift costs */
687   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
688    COSTS_N_INSNS (5),                   /*                               HI */
689    COSTS_N_INSNS (5),                   /*                               SI */
690    COSTS_N_INSNS (5),                   /*                               DI */
691    COSTS_N_INSNS (5)},                  /*                            other */
692   0,                                    /* cost of multiply per each bit set */
693   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
694    COSTS_N_INSNS (26),                  /*                          HI */
695    COSTS_N_INSNS (42),                  /*                          SI */
696    COSTS_N_INSNS (74),                  /*                          DI */
697    COSTS_N_INSNS (74)},                 /*                          other */
698   COSTS_N_INSNS (1),                    /* cost of movsx */
699   COSTS_N_INSNS (1),                    /* cost of movzx */
700   8,                                    /* "large" insn */
701   9,                                    /* MOVE_RATIO */
702   4,                                 /* cost for loading QImode using movzbl */
703   {3, 4, 3},                            /* cost of loading integer registers
704                                            in QImode, HImode and SImode.
705                                            Relative to reg-reg move (2).  */
706   {3, 4, 3},                            /* cost of storing integer registers */
707   4,                                    /* cost of reg,reg fld/fst */
708   {4, 4, 12},                           /* cost of loading fp registers
709                                            in SFmode, DFmode and XFmode */
710   {6, 6, 8},                            /* cost of storing fp registers
711                                            in SFmode, DFmode and XFmode */
712   2,                                    /* cost of moving MMX register */
713   {4, 4},                               /* cost of loading MMX registers
714                                            in SImode and DImode */
715   {4, 4},                               /* cost of storing MMX registers
716                                            in SImode and DImode */
717   2,                                    /* cost of moving SSE register */
718   {4, 4, 6},                            /* cost of loading SSE registers
719                                            in SImode, DImode and TImode */
720   {4, 4, 5},                            /* cost of storing SSE registers
721                                            in SImode, DImode and TImode */
722   5,                                    /* MMX or SSE register to integer */
723   64,                                   /* size of l1 cache.  */
724   256,                                  /* size of l2 cache.  */
725   64,                                   /* size of prefetch block */
726   6,                                    /* number of parallel prefetches */
727   5,                                    /* Branch cost */
728   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
729   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
730   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
731   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
732   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
733   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
734   athlon_memcpy,
735   athlon_memset,
736   1,                                    /* scalar_stmt_cost.  */
737   1,                                    /* scalar load_cost.  */
738   1,                                    /* scalar_store_cost.  */
739   1,                                    /* vec_stmt_cost.  */
740   1,                                    /* vec_to_scalar_cost.  */
741   1,                                    /* scalar_to_vec_cost.  */
742   1,                                    /* vec_align_load_cost.  */
743   2,                                    /* vec_unalign_load_cost.  */
744   1,                                    /* vec_store_cost.  */
745   3,                                    /* cond_taken_branch_cost.  */
746   1,                                    /* cond_not_taken_branch_cost.  */
747 };
748
749 /* K8 has optimized REP instruction for medium sized blocks, but for very
750    small blocks it is better to use loop. For large blocks, libcall can
751    do nontemporary accesses and beat inline considerably.  */
752 static stringop_algs k8_memcpy[2] = {
753   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
754              {-1, rep_prefix_4_byte, false}}},
755   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
756              {-1, libcall, false}}}};
757 static stringop_algs k8_memset[2] = {
758   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
759              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
760   {libcall, {{48, unrolled_loop, false},
761              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
762 static const
763 struct processor_costs k8_cost = {
764   COSTS_N_INSNS (1),                    /* cost of an add instruction */
765   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
766   COSTS_N_INSNS (1),                    /* variable shift costs */
767   COSTS_N_INSNS (1),                    /* constant shift costs */
768   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
769    COSTS_N_INSNS (4),                   /*                               HI */
770    COSTS_N_INSNS (3),                   /*                               SI */
771    COSTS_N_INSNS (4),                   /*                               DI */
772    COSTS_N_INSNS (5)},                  /*                            other */
773   0,                                    /* cost of multiply per each bit set */
774   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
775    COSTS_N_INSNS (26),                  /*                          HI */
776    COSTS_N_INSNS (42),                  /*                          SI */
777    COSTS_N_INSNS (74),                  /*                          DI */
778    COSTS_N_INSNS (74)},                 /*                          other */
779   COSTS_N_INSNS (1),                    /* cost of movsx */
780   COSTS_N_INSNS (1),                    /* cost of movzx */
781   8,                                    /* "large" insn */
782   9,                                    /* MOVE_RATIO */
783   4,                                 /* cost for loading QImode using movzbl */
784   {3, 4, 3},                            /* cost of loading integer registers
785                                            in QImode, HImode and SImode.
786                                            Relative to reg-reg move (2).  */
787   {3, 4, 3},                            /* cost of storing integer registers */
788   4,                                    /* cost of reg,reg fld/fst */
789   {4, 4, 12},                           /* cost of loading fp registers
790                                            in SFmode, DFmode and XFmode */
791   {6, 6, 8},                            /* cost of storing fp registers
792                                            in SFmode, DFmode and XFmode */
793   2,                                    /* cost of moving MMX register */
794   {3, 3},                               /* cost of loading MMX registers
795                                            in SImode and DImode */
796   {4, 4},                               /* cost of storing MMX registers
797                                            in SImode and DImode */
798   2,                                    /* cost of moving SSE register */
799   {4, 3, 6},                            /* cost of loading SSE registers
800                                            in SImode, DImode and TImode */
801   {4, 4, 5},                            /* cost of storing SSE registers
802                                            in SImode, DImode and TImode */
803   5,                                    /* MMX or SSE register to integer */
804   64,                                   /* size of l1 cache.  */
805   512,                                  /* size of l2 cache.  */
806   64,                                   /* size of prefetch block */
807   /* New AMD processors never drop prefetches; if they cannot be performed
808      immediately, they are queued.  We set number of simultaneous prefetches
809      to a large constant to reflect this (it probably is not a good idea not
810      to limit number of prefetches at all, as their execution also takes some
811      time).  */
812   100,                                  /* number of parallel prefetches */
813   3,                                    /* Branch cost */
814   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
815   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
816   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
817   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
818   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
819   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
820
821   k8_memcpy,
822   k8_memset,
823   4,                                    /* scalar_stmt_cost.  */
824   2,                                    /* scalar load_cost.  */
825   2,                                    /* scalar_store_cost.  */
826   5,                                    /* vec_stmt_cost.  */
827   0,                                    /* vec_to_scalar_cost.  */
828   2,                                    /* scalar_to_vec_cost.  */
829   2,                                    /* vec_align_load_cost.  */
830   3,                                    /* vec_unalign_load_cost.  */
831   3,                                    /* vec_store_cost.  */
832   3,                                    /* cond_taken_branch_cost.  */
833   2,                                    /* cond_not_taken_branch_cost.  */
834 };
835
836 /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
837    very small blocks it is better to use loop. For large blocks, libcall can
838    do nontemporary accesses and beat inline considerably.  */
839 static stringop_algs amdfam10_memcpy[2] = {
840   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
841              {-1, rep_prefix_4_byte, false}}},
842   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
843              {-1, libcall, false}}}};
844 static stringop_algs amdfam10_memset[2] = {
845   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
846              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
847   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
848              {-1, libcall, false}}}};
849 struct processor_costs amdfam10_cost = {
850   COSTS_N_INSNS (1),                    /* cost of an add instruction */
851   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
852   COSTS_N_INSNS (1),                    /* variable shift costs */
853   COSTS_N_INSNS (1),                    /* constant shift costs */
854   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
855    COSTS_N_INSNS (4),                   /*                               HI */
856    COSTS_N_INSNS (3),                   /*                               SI */
857    COSTS_N_INSNS (4),                   /*                               DI */
858    COSTS_N_INSNS (5)},                  /*                            other */
859   0,                                    /* cost of multiply per each bit set */
860   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
861    COSTS_N_INSNS (35),                  /*                          HI */
862    COSTS_N_INSNS (51),                  /*                          SI */
863    COSTS_N_INSNS (83),                  /*                          DI */
864    COSTS_N_INSNS (83)},                 /*                          other */
865   COSTS_N_INSNS (1),                    /* cost of movsx */
866   COSTS_N_INSNS (1),                    /* cost of movzx */
867   8,                                    /* "large" insn */
868   9,                                    /* MOVE_RATIO */
869   4,                                 /* cost for loading QImode using movzbl */
870   {3, 4, 3},                            /* cost of loading integer registers
871                                            in QImode, HImode and SImode.
872                                            Relative to reg-reg move (2).  */
873   {3, 4, 3},                            /* cost of storing integer registers */
874   4,                                    /* cost of reg,reg fld/fst */
875   {4, 4, 12},                           /* cost of loading fp registers
876                                            in SFmode, DFmode and XFmode */
877   {6, 6, 8},                            /* cost of storing fp registers
878                                            in SFmode, DFmode and XFmode */
879   2,                                    /* cost of moving MMX register */
880   {3, 3},                               /* cost of loading MMX registers
881                                            in SImode and DImode */
882   {4, 4},                               /* cost of storing MMX registers
883                                            in SImode and DImode */
884   2,                                    /* cost of moving SSE register */
885   {4, 4, 3},                            /* cost of loading SSE registers
886                                            in SImode, DImode and TImode */
887   {4, 4, 5},                            /* cost of storing SSE registers
888                                            in SImode, DImode and TImode */
889   3,                                    /* MMX or SSE register to integer */
890                                         /* On K8:
891                                             MOVD reg64, xmmreg Double FSTORE 4
892                                             MOVD reg32, xmmreg Double FSTORE 4
893                                            On AMDFAM10:
894                                             MOVD reg64, xmmreg Double FADD 3
895                                                                1/1  1/1
896                                             MOVD reg32, xmmreg Double FADD 3
897                                                                1/1  1/1 */
898   64,                                   /* size of l1 cache.  */
899   512,                                  /* size of l2 cache.  */
900   64,                                   /* size of prefetch block */
901   /* New AMD processors never drop prefetches; if they cannot be performed
902      immediately, they are queued.  We set number of simultaneous prefetches
903      to a large constant to reflect this (it probably is not a good idea not
904      to limit number of prefetches at all, as their execution also takes some
905      time).  */
906   100,                                  /* number of parallel prefetches */
907   2,                                    /* Branch cost */
908   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
909   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
910   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
911   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
912   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
913   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
914
915   amdfam10_memcpy,
916   amdfam10_memset,
917   4,                                    /* scalar_stmt_cost.  */
918   2,                                    /* scalar load_cost.  */
919   2,                                    /* scalar_store_cost.  */
920   6,                                    /* vec_stmt_cost.  */
921   0,                                    /* vec_to_scalar_cost.  */
922   2,                                    /* scalar_to_vec_cost.  */
923   2,                                    /* vec_align_load_cost.  */
924   2,                                    /* vec_unalign_load_cost.  */
925   2,                                    /* vec_store_cost.  */
926   2,                                    /* cond_taken_branch_cost.  */
927   1,                                    /* cond_not_taken_branch_cost.  */
928 };
929
930 /*  BDVER1 has optimized REP instruction for medium sized blocks, but for
931     very small blocks it is better to use loop. For large blocks, libcall
932     can do nontemporary accesses and beat inline considerably.  */
933 static stringop_algs bdver1_memcpy[2] = {
934   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
935              {-1, rep_prefix_4_byte, false}}},
936   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
937              {-1, libcall, false}}}};
938 static stringop_algs bdver1_memset[2] = {
939   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
940              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
941   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
942              {-1, libcall, false}}}};
943
944 const struct processor_costs bdver1_cost = {
945   COSTS_N_INSNS (1),                    /* cost of an add instruction */
946   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
947   COSTS_N_INSNS (1),                    /* variable shift costs */
948   COSTS_N_INSNS (1),                    /* constant shift costs */
949   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
950    COSTS_N_INSNS (4),                   /*                               HI */
951    COSTS_N_INSNS (4),                   /*                               SI */
952    COSTS_N_INSNS (6),                   /*                               DI */
953    COSTS_N_INSNS (6)},                  /*                            other */
954   0,                                    /* cost of multiply per each bit set */
955   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
956    COSTS_N_INSNS (35),                  /*                          HI */
957    COSTS_N_INSNS (51),                  /*                          SI */
958    COSTS_N_INSNS (83),                  /*                          DI */
959    COSTS_N_INSNS (83)},                 /*                          other */
960   COSTS_N_INSNS (1),                    /* cost of movsx */
961   COSTS_N_INSNS (1),                    /* cost of movzx */
962   8,                                    /* "large" insn */
963   9,                                    /* MOVE_RATIO */
964   4,                                 /* cost for loading QImode using movzbl */
965   {5, 5, 4},                            /* cost of loading integer registers
966                                            in QImode, HImode and SImode.
967                                            Relative to reg-reg move (2).  */
968   {4, 4, 4},                            /* cost of storing integer registers */
969   2,                                    /* cost of reg,reg fld/fst */
970   {5, 5, 12},                           /* cost of loading fp registers
971                                            in SFmode, DFmode and XFmode */
972   {4, 4, 8},                            /* cost of storing fp registers
973                                            in SFmode, DFmode and XFmode */
974   2,                                    /* cost of moving MMX register */
975   {4, 4},                               /* cost of loading MMX registers
976                                            in SImode and DImode */
977   {4, 4},                               /* cost of storing MMX registers
978                                            in SImode and DImode */
979   2,                                    /* cost of moving SSE register */
980   {4, 4, 4},                            /* cost of loading SSE registers
981                                            in SImode, DImode and TImode */
982   {4, 4, 4},                            /* cost of storing SSE registers
983                                            in SImode, DImode and TImode */
984   2,                                    /* MMX or SSE register to integer */
985                                         /* On K8:
986                                             MOVD reg64, xmmreg Double FSTORE 4
987                                             MOVD reg32, xmmreg Double FSTORE 4
988                                            On AMDFAM10:
989                                             MOVD reg64, xmmreg Double FADD 3
990                                                                1/1  1/1
991                                             MOVD reg32, xmmreg Double FADD 3
992                                                                1/1  1/1 */
993   16,                                   /* size of l1 cache.  */
994   2048,                                 /* size of l2 cache.  */
995   64,                                   /* size of prefetch block */
996   /* New AMD processors never drop prefetches; if they cannot be performed
997      immediately, they are queued.  We set number of simultaneous prefetches
998      to a large constant to reflect this (it probably is not a good idea not
999      to limit number of prefetches at all, as their execution also takes some
1000      time).  */
1001   100,                                  /* number of parallel prefetches */
1002   2,                                    /* Branch cost */
1003   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1004   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1005   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1006   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1007   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1008   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1009
1010   bdver1_memcpy,
1011   bdver1_memset,
1012   6,                                    /* scalar_stmt_cost.  */
1013   4,                                    /* scalar load_cost.  */
1014   4,                                    /* scalar_store_cost.  */
1015   6,                                    /* vec_stmt_cost.  */
1016   0,                                    /* vec_to_scalar_cost.  */
1017   2,                                    /* scalar_to_vec_cost.  */
1018   4,                                    /* vec_align_load_cost.  */
1019   4,                                    /* vec_unalign_load_cost.  */
1020   4,                                    /* vec_store_cost.  */
1021   2,                                    /* cond_taken_branch_cost.  */
1022   1,                                    /* cond_not_taken_branch_cost.  */
1023 };
1024
1025 /*  BDVER2 has optimized REP instruction for medium sized blocks, but for
1026     very small blocks it is better to use loop. For large blocks, libcall
1027     can do nontemporary accesses and beat inline considerably.  */
1028
1029 static stringop_algs bdver2_memcpy[2] = {
1030   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1031              {-1, rep_prefix_4_byte, false}}},
1032   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1033              {-1, libcall, false}}}};
1034 static stringop_algs bdver2_memset[2] = {
1035   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1036              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1037   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1038              {-1, libcall, false}}}};
1039
1040 const struct processor_costs bdver2_cost = {
1041   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1042   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1043   COSTS_N_INSNS (1),                    /* variable shift costs */
1044   COSTS_N_INSNS (1),                    /* constant shift costs */
1045   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1046    COSTS_N_INSNS (4),                   /*                               HI */
1047    COSTS_N_INSNS (4),                   /*                               SI */
1048    COSTS_N_INSNS (6),                   /*                               DI */
1049    COSTS_N_INSNS (6)},                  /*                            other */
1050   0,                                    /* cost of multiply per each bit set */
1051   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1052    COSTS_N_INSNS (35),                  /*                          HI */
1053    COSTS_N_INSNS (51),                  /*                          SI */
1054    COSTS_N_INSNS (83),                  /*                          DI */
1055    COSTS_N_INSNS (83)},                 /*                          other */
1056   COSTS_N_INSNS (1),                    /* cost of movsx */
1057   COSTS_N_INSNS (1),                    /* cost of movzx */
1058   8,                                    /* "large" insn */
1059   9,                                    /* MOVE_RATIO */
1060   4,                                 /* cost for loading QImode using movzbl */
1061   {5, 5, 4},                            /* cost of loading integer registers
1062                                            in QImode, HImode and SImode.
1063                                            Relative to reg-reg move (2).  */
1064   {4, 4, 4},                            /* cost of storing integer registers */
1065   2,                                    /* cost of reg,reg fld/fst */
1066   {5, 5, 12},                           /* cost of loading fp registers
1067                                            in SFmode, DFmode and XFmode */
1068   {4, 4, 8},                            /* cost of storing fp registers
1069                                            in SFmode, DFmode and XFmode */
1070   2,                                    /* cost of moving MMX register */
1071   {4, 4},                               /* cost of loading MMX registers
1072                                            in SImode and DImode */
1073   {4, 4},                               /* cost of storing MMX registers
1074                                            in SImode and DImode */
1075   2,                                    /* cost of moving SSE register */
1076   {4, 4, 4},                            /* cost of loading SSE registers
1077                                            in SImode, DImode and TImode */
1078   {4, 4, 4},                            /* cost of storing SSE registers
1079                                            in SImode, DImode and TImode */
1080   2,                                    /* MMX or SSE register to integer */
1081                                         /* On K8:
1082                                             MOVD reg64, xmmreg Double FSTORE 4
1083                                             MOVD reg32, xmmreg Double FSTORE 4
1084                                            On AMDFAM10:
1085                                             MOVD reg64, xmmreg Double FADD 3
1086                                                                1/1  1/1
1087                                             MOVD reg32, xmmreg Double FADD 3
1088                                                                1/1  1/1 */
1089   16,                                   /* size of l1 cache.  */
1090   2048,                                 /* size of l2 cache.  */
1091   64,                                   /* size of prefetch block */
1092   /* New AMD processors never drop prefetches; if they cannot be performed
1093      immediately, they are queued.  We set number of simultaneous prefetches
1094      to a large constant to reflect this (it probably is not a good idea not
1095      to limit number of prefetches at all, as their execution also takes some
1096      time).  */
1097   100,                                  /* number of parallel prefetches */
1098   2,                                    /* Branch cost */
1099   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1100   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1101   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1102   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1103   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1104   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1105
1106   bdver2_memcpy,
1107   bdver2_memset,
1108   6,                                    /* scalar_stmt_cost.  */
1109   4,                                    /* scalar load_cost.  */
1110   4,                                    /* scalar_store_cost.  */
1111   6,                                    /* vec_stmt_cost.  */
1112   0,                                    /* vec_to_scalar_cost.  */
1113   2,                                    /* scalar_to_vec_cost.  */
1114   4,                                    /* vec_align_load_cost.  */
1115   4,                                    /* vec_unalign_load_cost.  */
1116   4,                                    /* vec_store_cost.  */
1117   2,                                    /* cond_taken_branch_cost.  */
1118   1,                                    /* cond_not_taken_branch_cost.  */
1119 };
1120
1121
1122   /*  BDVER3 has optimized REP instruction for medium sized blocks, but for
1123       very small blocks it is better to use loop. For large blocks, libcall
1124       can do nontemporary accesses and beat inline considerably.  */
1125 static stringop_algs bdver3_memcpy[2] = {
1126   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1127              {-1, rep_prefix_4_byte, false}}},
1128   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1129              {-1, libcall, false}}}};
1130 static stringop_algs bdver3_memset[2] = {
1131   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1132              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1133   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1134              {-1, libcall, false}}}};
1135 struct processor_costs bdver3_cost = {
1136   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1137   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1138   COSTS_N_INSNS (1),                    /* variable shift costs */
1139   COSTS_N_INSNS (1),                    /* constant shift costs */
1140   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1141    COSTS_N_INSNS (4),                   /*                               HI */
1142    COSTS_N_INSNS (4),                   /*                               SI */
1143    COSTS_N_INSNS (6),                   /*                               DI */
1144    COSTS_N_INSNS (6)},                  /*                            other */
1145   0,                                    /* cost of multiply per each bit set */
1146   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1147    COSTS_N_INSNS (35),                  /*                          HI */
1148    COSTS_N_INSNS (51),                  /*                          SI */
1149    COSTS_N_INSNS (83),                  /*                          DI */
1150    COSTS_N_INSNS (83)},                 /*                          other */
1151   COSTS_N_INSNS (1),                    /* cost of movsx */
1152   COSTS_N_INSNS (1),                    /* cost of movzx */
1153   8,                                    /* "large" insn */
1154   9,                                    /* MOVE_RATIO */
1155   4,                                 /* cost for loading QImode using movzbl */
1156   {5, 5, 4},                            /* cost of loading integer registers
1157                                            in QImode, HImode and SImode.
1158                                            Relative to reg-reg move (2).  */
1159   {4, 4, 4},                            /* cost of storing integer registers */
1160   2,                                    /* cost of reg,reg fld/fst */
1161   {5, 5, 12},                           /* cost of loading fp registers
1162                                            in SFmode, DFmode and XFmode */
1163   {4, 4, 8},                            /* cost of storing fp registers
1164                                            in SFmode, DFmode and XFmode */
1165   2,                                    /* cost of moving MMX register */
1166   {4, 4},                               /* cost of loading MMX registers
1167                                            in SImode and DImode */
1168   {4, 4},                               /* cost of storing MMX registers
1169                                            in SImode and DImode */
1170   2,                                    /* cost of moving SSE register */
1171   {4, 4, 4},                            /* cost of loading SSE registers
1172                                            in SImode, DImode and TImode */
1173   {4, 4, 4},                            /* cost of storing SSE registers
1174                                            in SImode, DImode and TImode */
1175   2,                                    /* MMX or SSE register to integer */
1176   16,                                   /* size of l1 cache.  */
1177   2048,                                 /* size of l2 cache.  */
1178   64,                                   /* size of prefetch block */
1179   /* New AMD processors never drop prefetches; if they cannot be performed
1180      immediately, they are queued.  We set number of simultaneous prefetches
1181      to a large constant to reflect this (it probably is not a good idea not
1182      to limit number of prefetches at all, as their execution also takes some
1183      time).  */
1184   100,                                  /* number of parallel prefetches */
1185   2,                                    /* Branch cost */
1186   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1187   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1188   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1189   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1190   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1191   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1192
1193   bdver3_memcpy,
1194   bdver3_memset,
1195   6,                                    /* scalar_stmt_cost.  */
1196   4,                                    /* scalar load_cost.  */
1197   4,                                    /* scalar_store_cost.  */
1198   6,                                    /* vec_stmt_cost.  */
1199   0,                                    /* vec_to_scalar_cost.  */
1200   2,                                    /* scalar_to_vec_cost.  */
1201   4,                                    /* vec_align_load_cost.  */
1202   4,                                    /* vec_unalign_load_cost.  */
1203   4,                                    /* vec_store_cost.  */
1204   2,                                    /* cond_taken_branch_cost.  */
1205   1,                                    /* cond_not_taken_branch_cost.  */
1206 };
1207
1208 /*  BDVER4 has optimized REP instruction for medium sized blocks, but for
1209     very small blocks it is better to use loop. For large blocks, libcall
1210     can do nontemporary accesses and beat inline considerably.  */
1211 static stringop_algs bdver4_memcpy[2] = {
1212   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1213              {-1, rep_prefix_4_byte, false}}},
1214   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1215              {-1, libcall, false}}}};
1216 static stringop_algs bdver4_memset[2] = {
1217   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1218              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1219   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1220              {-1, libcall, false}}}};
1221 struct processor_costs bdver4_cost = {
1222   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1223   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1224   COSTS_N_INSNS (1),                    /* variable shift costs */
1225   COSTS_N_INSNS (1),                    /* constant shift costs */
1226   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1227    COSTS_N_INSNS (4),                   /*                               HI */
1228    COSTS_N_INSNS (4),                   /*                               SI */
1229    COSTS_N_INSNS (6),                   /*                               DI */
1230    COSTS_N_INSNS (6)},                  /*                            other */
1231   0,                                    /* cost of multiply per each bit set */
1232   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1233    COSTS_N_INSNS (35),                  /*                          HI */
1234    COSTS_N_INSNS (51),                  /*                          SI */
1235    COSTS_N_INSNS (83),                  /*                          DI */
1236    COSTS_N_INSNS (83)},                 /*                          other */
1237   COSTS_N_INSNS (1),                    /* cost of movsx */
1238   COSTS_N_INSNS (1),                    /* cost of movzx */
1239   8,                                    /* "large" insn */
1240   9,                                    /* MOVE_RATIO */
1241   4,                                 /* cost for loading QImode using movzbl */
1242   {5, 5, 4},                            /* cost of loading integer registers
1243                                            in QImode, HImode and SImode.
1244                                            Relative to reg-reg move (2).  */
1245   {4, 4, 4},                            /* cost of storing integer registers */
1246   2,                                    /* cost of reg,reg fld/fst */
1247   {5, 5, 12},                           /* cost of loading fp registers
1248                                            in SFmode, DFmode and XFmode */
1249   {4, 4, 8},                            /* cost of storing fp registers
1250                                            in SFmode, DFmode and XFmode */
1251   2,                                    /* cost of moving MMX register */
1252   {4, 4},                               /* cost of loading MMX registers
1253                                            in SImode and DImode */
1254   {4, 4},                               /* cost of storing MMX registers
1255                                            in SImode and DImode */
1256   2,                                    /* cost of moving SSE register */
1257   {4, 4, 4},                            /* cost of loading SSE registers
1258                                            in SImode, DImode and TImode */
1259   {4, 4, 4},                            /* cost of storing SSE registers
1260                                            in SImode, DImode and TImode */
1261   2,                                    /* MMX or SSE register to integer */
1262   16,                                   /* size of l1 cache.  */
1263   2048,                                 /* size of l2 cache.  */
1264   64,                                   /* size of prefetch block */
1265   /* New AMD processors never drop prefetches; if they cannot be performed
1266      immediately, they are queued.  We set number of simultaneous prefetches
1267      to a large constant to reflect this (it probably is not a good idea not
1268      to limit number of prefetches at all, as their execution also takes some
1269      time).  */
1270   100,                                  /* number of parallel prefetches */
1271   2,                                    /* Branch cost */
1272   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1273   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1274   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1275   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1276   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1277   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1278
1279   bdver4_memcpy,
1280   bdver4_memset,
1281   6,                                    /* scalar_stmt_cost.  */
1282   4,                                    /* scalar load_cost.  */
1283   4,                                    /* scalar_store_cost.  */
1284   6,                                    /* vec_stmt_cost.  */
1285   0,                                    /* vec_to_scalar_cost.  */
1286   2,                                    /* scalar_to_vec_cost.  */
1287   4,                                    /* vec_align_load_cost.  */
1288   4,                                    /* vec_unalign_load_cost.  */
1289   4,                                    /* vec_store_cost.  */
1290   2,                                    /* cond_taken_branch_cost.  */
1291   1,                                    /* cond_not_taken_branch_cost.  */
1292 };
1293
1294   /* BTVER1 has optimized REP instruction for medium sized blocks, but for
1295      very small blocks it is better to use loop. For large blocks, libcall can
1296      do nontemporary accesses and beat inline considerably.  */
1297 static stringop_algs btver1_memcpy[2] = {
1298   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1299              {-1, rep_prefix_4_byte, false}}},
1300   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1301              {-1, libcall, false}}}};
1302 static stringop_algs btver1_memset[2] = {
1303   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1304              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1305   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1306              {-1, libcall, false}}}};
1307 const struct processor_costs btver1_cost = {
1308   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1309   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
1310   COSTS_N_INSNS (1),                    /* variable shift costs */
1311   COSTS_N_INSNS (1),                    /* constant shift costs */
1312   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1313    COSTS_N_INSNS (4),                   /*                               HI */
1314    COSTS_N_INSNS (3),                   /*                               SI */
1315    COSTS_N_INSNS (4),                   /*                               DI */
1316    COSTS_N_INSNS (5)},                  /*                            other */
1317   0,                                    /* cost of multiply per each bit set */
1318   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1319    COSTS_N_INSNS (35),                  /*                          HI */
1320    COSTS_N_INSNS (51),                  /*                          SI */
1321    COSTS_N_INSNS (83),                  /*                          DI */
1322    COSTS_N_INSNS (83)},                 /*                          other */
1323   COSTS_N_INSNS (1),                    /* cost of movsx */
1324   COSTS_N_INSNS (1),                    /* cost of movzx */
1325   8,                                    /* "large" insn */
1326   9,                                    /* MOVE_RATIO */
1327   4,                                 /* cost for loading QImode using movzbl */
1328   {3, 4, 3},                            /* cost of loading integer registers
1329                                            in QImode, HImode and SImode.
1330                                            Relative to reg-reg move (2).  */
1331   {3, 4, 3},                            /* cost of storing integer registers */
1332   4,                                    /* cost of reg,reg fld/fst */
1333   {4, 4, 12},                           /* cost of loading fp registers
1334                                            in SFmode, DFmode and XFmode */
1335   {6, 6, 8},                            /* cost of storing fp registers
1336                                            in SFmode, DFmode and XFmode */
1337   2,                                    /* cost of moving MMX register */
1338   {3, 3},                               /* cost of loading MMX registers
1339                                            in SImode and DImode */
1340   {4, 4},                               /* cost of storing MMX registers
1341                                            in SImode and DImode */
1342   2,                                    /* cost of moving SSE register */
1343   {4, 4, 3},                            /* cost of loading SSE registers
1344                                            in SImode, DImode and TImode */
1345   {4, 4, 5},                            /* cost of storing SSE registers
1346                                            in SImode, DImode and TImode */
1347   3,                                    /* MMX or SSE register to integer */
1348                                         /* On K8:
1349                                            MOVD reg64, xmmreg Double FSTORE 4
1350                                            MOVD reg32, xmmreg Double FSTORE 4
1351                                            On AMDFAM10:
1352                                            MOVD reg64, xmmreg Double FADD 3
1353                                                                1/1  1/1
1354                                             MOVD reg32, xmmreg Double FADD 3
1355                                                                1/1  1/1 */
1356   32,                                   /* size of l1 cache.  */
1357   512,                                  /* size of l2 cache.  */
1358   64,                                   /* size of prefetch block */
1359   100,                                  /* number of parallel prefetches */
1360   2,                                    /* Branch cost */
1361   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
1362   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
1363   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
1364   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1365   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1366   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
1367
1368   btver1_memcpy,
1369   btver1_memset,
1370   4,                                    /* scalar_stmt_cost.  */
1371   2,                                    /* scalar load_cost.  */
1372   2,                                    /* scalar_store_cost.  */
1373   6,                                    /* vec_stmt_cost.  */
1374   0,                                    /* vec_to_scalar_cost.  */
1375   2,                                    /* scalar_to_vec_cost.  */
1376   2,                                    /* vec_align_load_cost.  */
1377   2,                                    /* vec_unalign_load_cost.  */
1378   2,                                    /* vec_store_cost.  */
1379   2,                                    /* cond_taken_branch_cost.  */
1380   1,                                    /* cond_not_taken_branch_cost.  */
1381 };
1382
1383 static stringop_algs btver2_memcpy[2] = {
1384   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1385              {-1, rep_prefix_4_byte, false}}},
1386   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1387              {-1, libcall, false}}}};
1388 static stringop_algs btver2_memset[2] = {
1389   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1390              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1391   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1392              {-1, libcall, false}}}};
1393 const struct processor_costs btver2_cost = {
1394   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1395   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
1396   COSTS_N_INSNS (1),                    /* variable shift costs */
1397   COSTS_N_INSNS (1),                    /* constant shift costs */
1398   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1399    COSTS_N_INSNS (4),                   /*                               HI */
1400    COSTS_N_INSNS (3),                   /*                               SI */
1401    COSTS_N_INSNS (4),                   /*                               DI */
1402    COSTS_N_INSNS (5)},                  /*                            other */
1403   0,                                    /* cost of multiply per each bit set */
1404   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1405    COSTS_N_INSNS (35),                  /*                          HI */
1406    COSTS_N_INSNS (51),                  /*                          SI */
1407    COSTS_N_INSNS (83),                  /*                          DI */
1408    COSTS_N_INSNS (83)},                 /*                          other */
1409   COSTS_N_INSNS (1),                    /* cost of movsx */
1410   COSTS_N_INSNS (1),                    /* cost of movzx */
1411   8,                                    /* "large" insn */
1412   9,                                    /* MOVE_RATIO */
1413   4,                                 /* cost for loading QImode using movzbl */
1414   {3, 4, 3},                            /* cost of loading integer registers
1415                                            in QImode, HImode and SImode.
1416                                            Relative to reg-reg move (2).  */
1417   {3, 4, 3},                            /* cost of storing integer registers */
1418   4,                                    /* cost of reg,reg fld/fst */
1419   {4, 4, 12},                           /* cost of loading fp registers
1420                                            in SFmode, DFmode and XFmode */
1421   {6, 6, 8},                            /* cost of storing fp registers
1422                                            in SFmode, DFmode and XFmode */
1423   2,                                    /* cost of moving MMX register */
1424   {3, 3},                               /* cost of loading MMX registers
1425                                            in SImode and DImode */
1426   {4, 4},                               /* cost of storing MMX registers
1427                                            in SImode and DImode */
1428   2,                                    /* cost of moving SSE register */
1429   {4, 4, 3},                            /* cost of loading SSE registers
1430                                            in SImode, DImode and TImode */
1431   {4, 4, 5},                            /* cost of storing SSE registers
1432                                            in SImode, DImode and TImode */
1433   3,                                    /* MMX or SSE register to integer */
1434                                         /* On K8:
1435                                            MOVD reg64, xmmreg Double FSTORE 4
1436                                            MOVD reg32, xmmreg Double FSTORE 4
1437                                            On AMDFAM10:
1438                                            MOVD reg64, xmmreg Double FADD 3
1439                                                                1/1  1/1
1440                                             MOVD reg32, xmmreg Double FADD 3
1441                                                                1/1  1/1 */
1442   32,                                   /* size of l1 cache.  */
1443   2048,                                 /* size of l2 cache.  */
1444   64,                                   /* size of prefetch block */
1445   100,                                  /* number of parallel prefetches */
1446   2,                                    /* Branch cost */
1447   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
1448   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
1449   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
1450   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1451   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1452   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
1453   btver2_memcpy,
1454   btver2_memset,
1455   4,                                    /* scalar_stmt_cost.  */
1456   2,                                    /* scalar load_cost.  */
1457   2,                                    /* scalar_store_cost.  */
1458   6,                                    /* vec_stmt_cost.  */
1459   0,                                    /* vec_to_scalar_cost.  */
1460   2,                                    /* scalar_to_vec_cost.  */
1461   2,                                    /* vec_align_load_cost.  */
1462   2,                                    /* vec_unalign_load_cost.  */
1463   2,                                    /* vec_store_cost.  */
1464   2,                                    /* cond_taken_branch_cost.  */
1465   1,                                    /* cond_not_taken_branch_cost.  */
1466 };
1467
1468 static stringop_algs pentium4_memcpy[2] = {
1469   {libcall, {{12, loop_1_byte, false}, {-1, rep_prefix_4_byte, false}}},
1470   DUMMY_STRINGOP_ALGS};
1471 static stringop_algs pentium4_memset[2] = {
1472   {libcall, {{6, loop_1_byte, false}, {48, loop, false},
1473              {20480, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1474   DUMMY_STRINGOP_ALGS};
1475
1476 static const
1477 struct processor_costs pentium4_cost = {
1478   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1479   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
1480   COSTS_N_INSNS (4),                    /* variable shift costs */
1481   COSTS_N_INSNS (4),                    /* constant shift costs */
1482   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
1483    COSTS_N_INSNS (15),                  /*                               HI */
1484    COSTS_N_INSNS (15),                  /*                               SI */
1485    COSTS_N_INSNS (15),                  /*                               DI */
1486    COSTS_N_INSNS (15)},                 /*                            other */
1487   0,                                    /* cost of multiply per each bit set */
1488   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
1489    COSTS_N_INSNS (56),                  /*                          HI */
1490    COSTS_N_INSNS (56),                  /*                          SI */
1491    COSTS_N_INSNS (56),                  /*                          DI */
1492    COSTS_N_INSNS (56)},                 /*                          other */
1493   COSTS_N_INSNS (1),                    /* cost of movsx */
1494   COSTS_N_INSNS (1),                    /* cost of movzx */
1495   16,                                   /* "large" insn */
1496   6,                                    /* MOVE_RATIO */
1497   2,                                 /* cost for loading QImode using movzbl */
1498   {4, 5, 4},                            /* cost of loading integer registers
1499                                            in QImode, HImode and SImode.
1500                                            Relative to reg-reg move (2).  */
1501   {2, 3, 2},                            /* cost of storing integer registers */
1502   2,                                    /* cost of reg,reg fld/fst */
1503   {2, 2, 6},                            /* cost of loading fp registers
1504                                            in SFmode, DFmode and XFmode */
1505   {4, 4, 6},                            /* cost of storing fp registers
1506                                            in SFmode, DFmode and XFmode */
1507   2,                                    /* cost of moving MMX register */
1508   {2, 2},                               /* cost of loading MMX registers
1509                                            in SImode and DImode */
1510   {2, 2},                               /* cost of storing MMX registers
1511                                            in SImode and DImode */
1512   12,                                   /* cost of moving SSE register */
1513   {12, 12, 12},                         /* cost of loading SSE registers
1514                                            in SImode, DImode and TImode */
1515   {2, 2, 8},                            /* cost of storing SSE registers
1516                                            in SImode, DImode and TImode */
1517   10,                                   /* MMX or SSE register to integer */
1518   8,                                    /* size of l1 cache.  */
1519   256,                                  /* size of l2 cache.  */
1520   64,                                   /* size of prefetch block */
1521   6,                                    /* number of parallel prefetches */
1522   2,                                    /* Branch cost */
1523   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
1524   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
1525   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
1526   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1527   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1528   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
1529   pentium4_memcpy,
1530   pentium4_memset,
1531   1,                                    /* scalar_stmt_cost.  */
1532   1,                                    /* scalar load_cost.  */
1533   1,                                    /* scalar_store_cost.  */
1534   1,                                    /* vec_stmt_cost.  */
1535   1,                                    /* vec_to_scalar_cost.  */
1536   1,                                    /* scalar_to_vec_cost.  */
1537   1,                                    /* vec_align_load_cost.  */
1538   2,                                    /* vec_unalign_load_cost.  */
1539   1,                                    /* vec_store_cost.  */
1540   3,                                    /* cond_taken_branch_cost.  */
1541   1,                                    /* cond_not_taken_branch_cost.  */
1542 };
1543
1544 static stringop_algs nocona_memcpy[2] = {
1545   {libcall, {{12, loop_1_byte, false}, {-1, rep_prefix_4_byte, false}}},
1546   {libcall, {{32, loop, false}, {20000, rep_prefix_8_byte, false},
1547              {100000, unrolled_loop, false}, {-1, libcall, false}}}};
1548
1549 static stringop_algs nocona_memset[2] = {
1550   {libcall, {{6, loop_1_byte, false}, {48, loop, false},
1551              {20480, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1552   {libcall, {{24, loop, false}, {64, unrolled_loop, false},
1553              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1554
1555 static const
1556 struct processor_costs nocona_cost = {
1557   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1558   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1559   COSTS_N_INSNS (1),                    /* variable shift costs */
1560   COSTS_N_INSNS (1),                    /* constant shift costs */
1561   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
1562    COSTS_N_INSNS (10),                  /*                               HI */
1563    COSTS_N_INSNS (10),                  /*                               SI */
1564    COSTS_N_INSNS (10),                  /*                               DI */
1565    COSTS_N_INSNS (10)},                 /*                            other */
1566   0,                                    /* cost of multiply per each bit set */
1567   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
1568    COSTS_N_INSNS (66),                  /*                          HI */
1569    COSTS_N_INSNS (66),                  /*                          SI */
1570    COSTS_N_INSNS (66),                  /*                          DI */
1571    COSTS_N_INSNS (66)},                 /*                          other */
1572   COSTS_N_INSNS (1),                    /* cost of movsx */
1573   COSTS_N_INSNS (1),                    /* cost of movzx */
1574   16,                                   /* "large" insn */
1575   17,                                   /* MOVE_RATIO */
1576   4,                                 /* cost for loading QImode using movzbl */
1577   {4, 4, 4},                            /* cost of loading integer registers
1578                                            in QImode, HImode and SImode.
1579                                            Relative to reg-reg move (2).  */
1580   {4, 4, 4},                            /* cost of storing integer registers */
1581   3,                                    /* cost of reg,reg fld/fst */
1582   {12, 12, 12},                         /* cost of loading fp registers
1583                                            in SFmode, DFmode and XFmode */
1584   {4, 4, 4},                            /* cost of storing fp registers
1585                                            in SFmode, DFmode and XFmode */
1586   6,                                    /* cost of moving MMX register */
1587   {12, 12},                             /* cost of loading MMX registers
1588                                            in SImode and DImode */
1589   {12, 12},                             /* cost of storing MMX registers
1590                                            in SImode and DImode */
1591   6,                                    /* cost of moving SSE register */
1592   {12, 12, 12},                         /* cost of loading SSE registers
1593                                            in SImode, DImode and TImode */
1594   {12, 12, 12},                         /* cost of storing SSE registers
1595                                            in SImode, DImode and TImode */
1596   8,                                    /* MMX or SSE register to integer */
1597   8,                                    /* size of l1 cache.  */
1598   1024,                                 /* size of l2 cache.  */
1599   64,                                   /* size of prefetch block */
1600   8,                                    /* number of parallel prefetches */
1601   1,                                    /* Branch cost */
1602   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1603   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1604   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
1605   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
1606   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
1607   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
1608   nocona_memcpy,
1609   nocona_memset,
1610   1,                                    /* scalar_stmt_cost.  */
1611   1,                                    /* scalar load_cost.  */
1612   1,                                    /* scalar_store_cost.  */
1613   1,                                    /* vec_stmt_cost.  */
1614   1,                                    /* vec_to_scalar_cost.  */
1615   1,                                    /* scalar_to_vec_cost.  */
1616   1,                                    /* vec_align_load_cost.  */
1617   2,                                    /* vec_unalign_load_cost.  */
1618   1,                                    /* vec_store_cost.  */
1619   3,                                    /* cond_taken_branch_cost.  */
1620   1,                                    /* cond_not_taken_branch_cost.  */
1621 };
1622
1623 static stringop_algs atom_memcpy[2] = {
1624   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1625   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1626              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1627 static stringop_algs atom_memset[2] = {
1628   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1629              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1630   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1631              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1632 static const
1633 struct processor_costs atom_cost = {
1634   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1635   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1636   COSTS_N_INSNS (1),                    /* variable shift costs */
1637   COSTS_N_INSNS (1),                    /* constant shift costs */
1638   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1639    COSTS_N_INSNS (4),                   /*                               HI */
1640    COSTS_N_INSNS (3),                   /*                               SI */
1641    COSTS_N_INSNS (4),                   /*                               DI */
1642    COSTS_N_INSNS (2)},                  /*                            other */
1643   0,                                    /* cost of multiply per each bit set */
1644   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1645    COSTS_N_INSNS (26),                  /*                          HI */
1646    COSTS_N_INSNS (42),                  /*                          SI */
1647    COSTS_N_INSNS (74),                  /*                          DI */
1648    COSTS_N_INSNS (74)},                 /*                          other */
1649   COSTS_N_INSNS (1),                    /* cost of movsx */
1650   COSTS_N_INSNS (1),                    /* cost of movzx */
1651   8,                                    /* "large" insn */
1652   17,                                   /* MOVE_RATIO */
1653   4,                                    /* cost for loading QImode using movzbl */
1654   {4, 4, 4},                            /* cost of loading integer registers
1655                                            in QImode, HImode and SImode.
1656                                            Relative to reg-reg move (2).  */
1657   {4, 4, 4},                            /* cost of storing integer registers */
1658   4,                                    /* cost of reg,reg fld/fst */
1659   {12, 12, 12},                         /* cost of loading fp registers
1660                                            in SFmode, DFmode and XFmode */
1661   {6, 6, 8},                            /* cost of storing fp registers
1662                                            in SFmode, DFmode and XFmode */
1663   2,                                    /* cost of moving MMX register */
1664   {8, 8},                               /* cost of loading MMX registers
1665                                            in SImode and DImode */
1666   {8, 8},                               /* cost of storing MMX registers
1667                                            in SImode and DImode */
1668   2,                                    /* cost of moving SSE register */
1669   {8, 8, 8},                            /* cost of loading SSE registers
1670                                            in SImode, DImode and TImode */
1671   {8, 8, 8},                            /* cost of storing SSE registers
1672                                            in SImode, DImode and TImode */
1673   5,                                    /* MMX or SSE register to integer */
1674   32,                                   /* size of l1 cache.  */
1675   256,                                  /* size of l2 cache.  */
1676   64,                                   /* size of prefetch block */
1677   6,                                    /* number of parallel prefetches */
1678   3,                                    /* Branch cost */
1679   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1680   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1681   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1682   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1683   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1684   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1685   atom_memcpy,
1686   atom_memset,
1687   1,                                    /* scalar_stmt_cost.  */
1688   1,                                    /* scalar load_cost.  */
1689   1,                                    /* scalar_store_cost.  */
1690   1,                                    /* vec_stmt_cost.  */
1691   1,                                    /* vec_to_scalar_cost.  */
1692   1,                                    /* scalar_to_vec_cost.  */
1693   1,                                    /* vec_align_load_cost.  */
1694   2,                                    /* vec_unalign_load_cost.  */
1695   1,                                    /* vec_store_cost.  */
1696   3,                                    /* cond_taken_branch_cost.  */
1697   1,                                    /* cond_not_taken_branch_cost.  */
1698 };
1699
1700 static stringop_algs slm_memcpy[2] = {
1701   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1702   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1703              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1704 static stringop_algs slm_memset[2] = {
1705   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1706              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1707   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1708              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1709 static const
1710 struct processor_costs slm_cost = {
1711   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1712   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1713   COSTS_N_INSNS (1),                    /* variable shift costs */
1714   COSTS_N_INSNS (1),                    /* constant shift costs */
1715   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1716    COSTS_N_INSNS (3),                   /*                               HI */
1717    COSTS_N_INSNS (3),                   /*                               SI */
1718    COSTS_N_INSNS (4),                   /*                               DI */
1719    COSTS_N_INSNS (2)},                  /*                            other */
1720   0,                                    /* cost of multiply per each bit set */
1721   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1722    COSTS_N_INSNS (26),                  /*                          HI */
1723    COSTS_N_INSNS (42),                  /*                          SI */
1724    COSTS_N_INSNS (74),                  /*                          DI */
1725    COSTS_N_INSNS (74)},                 /*                          other */
1726   COSTS_N_INSNS (1),                    /* cost of movsx */
1727   COSTS_N_INSNS (1),                    /* cost of movzx */
1728   8,                                    /* "large" insn */
1729   17,                                   /* MOVE_RATIO */
1730   4,                                    /* cost for loading QImode using movzbl */
1731   {4, 4, 4},                            /* cost of loading integer registers
1732                                            in QImode, HImode and SImode.
1733                                            Relative to reg-reg move (2).  */
1734   {4, 4, 4},                            /* cost of storing integer registers */
1735   4,                                    /* cost of reg,reg fld/fst */
1736   {12, 12, 12},                         /* cost of loading fp registers
1737                                            in SFmode, DFmode and XFmode */
1738   {6, 6, 8},                            /* cost of storing fp registers
1739                                            in SFmode, DFmode and XFmode */
1740   2,                                    /* cost of moving MMX register */
1741   {8, 8},                               /* cost of loading MMX registers
1742                                            in SImode and DImode */
1743   {8, 8},                               /* cost of storing MMX registers
1744                                            in SImode and DImode */
1745   2,                                    /* cost of moving SSE register */
1746   {8, 8, 8},                            /* cost of loading SSE registers
1747                                            in SImode, DImode and TImode */
1748   {8, 8, 8},                            /* cost of storing SSE registers
1749                                            in SImode, DImode and TImode */
1750   5,                                    /* MMX or SSE register to integer */
1751   32,                                   /* size of l1 cache.  */
1752   256,                                  /* size of l2 cache.  */
1753   64,                                   /* size of prefetch block */
1754   6,                                    /* number of parallel prefetches */
1755   3,                                    /* Branch cost */
1756   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1757   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1758   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1759   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1760   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1761   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1762   slm_memcpy,
1763   slm_memset,
1764   1,                                    /* scalar_stmt_cost.  */
1765   1,                                    /* scalar load_cost.  */
1766   1,                                    /* scalar_store_cost.  */
1767   1,                                    /* vec_stmt_cost.  */
1768   4,                                    /* vec_to_scalar_cost.  */
1769   1,                                    /* scalar_to_vec_cost.  */
1770   1,                                    /* vec_align_load_cost.  */
1771   2,                                    /* vec_unalign_load_cost.  */
1772   1,                                    /* vec_store_cost.  */
1773   3,                                    /* cond_taken_branch_cost.  */
1774   1,                                    /* cond_not_taken_branch_cost.  */
1775 };
1776
1777 static stringop_algs intel_memcpy[2] = {
1778   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1779   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1780              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1781 static stringop_algs intel_memset[2] = {
1782   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1783              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1784   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1785              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1786 static const
1787 struct processor_costs intel_cost = {
1788   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1789   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1790   COSTS_N_INSNS (1),                    /* variable shift costs */
1791   COSTS_N_INSNS (1),                    /* constant shift costs */
1792   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1793    COSTS_N_INSNS (3),                   /*                               HI */
1794    COSTS_N_INSNS (3),                   /*                               SI */
1795    COSTS_N_INSNS (4),                   /*                               DI */
1796    COSTS_N_INSNS (2)},                  /*                            other */
1797   0,                                    /* cost of multiply per each bit set */
1798   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1799    COSTS_N_INSNS (26),                  /*                          HI */
1800    COSTS_N_INSNS (42),                  /*                          SI */
1801    COSTS_N_INSNS (74),                  /*                          DI */
1802    COSTS_N_INSNS (74)},                 /*                          other */
1803   COSTS_N_INSNS (1),                    /* cost of movsx */
1804   COSTS_N_INSNS (1),                    /* cost of movzx */
1805   8,                                    /* "large" insn */
1806   17,                                   /* MOVE_RATIO */
1807   4,                                    /* cost for loading QImode using movzbl */
1808   {4, 4, 4},                            /* cost of loading integer registers
1809                                            in QImode, HImode and SImode.
1810                                            Relative to reg-reg move (2).  */
1811   {4, 4, 4},                            /* cost of storing integer registers */
1812   4,                                    /* cost of reg,reg fld/fst */
1813   {12, 12, 12},                         /* cost of loading fp registers
1814                                            in SFmode, DFmode and XFmode */
1815   {6, 6, 8},                            /* cost of storing fp registers
1816                                            in SFmode, DFmode and XFmode */
1817   2,                                    /* cost of moving MMX register */
1818   {8, 8},                               /* cost of loading MMX registers
1819                                            in SImode and DImode */
1820   {8, 8},                               /* cost of storing MMX registers
1821                                            in SImode and DImode */
1822   2,                                    /* cost of moving SSE register */
1823   {8, 8, 8},                            /* cost of loading SSE registers
1824                                            in SImode, DImode and TImode */
1825   {8, 8, 8},                            /* cost of storing SSE registers
1826                                            in SImode, DImode and TImode */
1827   5,                                    /* MMX or SSE register to integer */
1828   32,                                   /* size of l1 cache.  */
1829   256,                                  /* size of l2 cache.  */
1830   64,                                   /* size of prefetch block */
1831   6,                                    /* number of parallel prefetches */
1832   3,                                    /* Branch cost */
1833   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1834   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1835   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1836   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1837   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1838   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1839   intel_memcpy,
1840   intel_memset,
1841   1,                                    /* scalar_stmt_cost.  */
1842   1,                                    /* scalar load_cost.  */
1843   1,                                    /* scalar_store_cost.  */
1844   1,                                    /* vec_stmt_cost.  */
1845   4,                                    /* vec_to_scalar_cost.  */
1846   1,                                    /* scalar_to_vec_cost.  */
1847   1,                                    /* vec_align_load_cost.  */
1848   2,                                    /* vec_unalign_load_cost.  */
1849   1,                                    /* vec_store_cost.  */
1850   3,                                    /* cond_taken_branch_cost.  */
1851   1,                                    /* cond_not_taken_branch_cost.  */
1852 };
1853
1854 /* Generic should produce code tuned for Core-i7 (and newer chips)
1855    and btver1 (and newer chips).  */
1856
1857 static stringop_algs generic_memcpy[2] = {
1858   {libcall, {{32, loop, false}, {8192, rep_prefix_4_byte, false},
1859              {-1, libcall, false}}},
1860   {libcall, {{32, loop, false}, {8192, rep_prefix_8_byte, false},
1861              {-1, libcall, false}}}};
1862 static stringop_algs generic_memset[2] = {
1863   {libcall, {{32, loop, false}, {8192, rep_prefix_4_byte, false},
1864              {-1, libcall, false}}},
1865   {libcall, {{32, loop, false}, {8192, rep_prefix_8_byte, false},
1866              {-1, libcall, false}}}};
1867 static const
1868 struct processor_costs generic_cost = {
1869   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1870   /* On all chips taken into consideration lea is 2 cycles and more.  With
1871      this cost however our current implementation of synth_mult results in
1872      use of unnecessary temporary registers causing regression on several
1873      SPECfp benchmarks.  */
1874   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1875   COSTS_N_INSNS (1),                    /* variable shift costs */
1876   COSTS_N_INSNS (1),                    /* constant shift costs */
1877   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1878    COSTS_N_INSNS (4),                   /*                               HI */
1879    COSTS_N_INSNS (3),                   /*                               SI */
1880    COSTS_N_INSNS (4),                   /*                               DI */
1881    COSTS_N_INSNS (2)},                  /*                            other */
1882   0,                                    /* cost of multiply per each bit set */
1883   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1884    COSTS_N_INSNS (26),                  /*                          HI */
1885    COSTS_N_INSNS (42),                  /*                          SI */
1886    COSTS_N_INSNS (74),                  /*                          DI */
1887    COSTS_N_INSNS (74)},                 /*                          other */
1888   COSTS_N_INSNS (1),                    /* cost of movsx */
1889   COSTS_N_INSNS (1),                    /* cost of movzx */
1890   8,                                    /* "large" insn */
1891   17,                                   /* MOVE_RATIO */
1892   4,                                 /* cost for loading QImode using movzbl */
1893   {4, 4, 4},                            /* cost of loading integer registers
1894                                            in QImode, HImode and SImode.
1895                                            Relative to reg-reg move (2).  */
1896   {4, 4, 4},                            /* cost of storing integer registers */
1897   4,                                    /* cost of reg,reg fld/fst */
1898   {12, 12, 12},                         /* cost of loading fp registers
1899                                            in SFmode, DFmode and XFmode */
1900   {6, 6, 8},                            /* cost of storing fp registers
1901                                            in SFmode, DFmode and XFmode */
1902   2,                                    /* cost of moving MMX register */
1903   {8, 8},                               /* cost of loading MMX registers
1904                                            in SImode and DImode */
1905   {8, 8},                               /* cost of storing MMX registers
1906                                            in SImode and DImode */
1907   2,                                    /* cost of moving SSE register */
1908   {8, 8, 8},                            /* cost of loading SSE registers
1909                                            in SImode, DImode and TImode */
1910   {8, 8, 8},                            /* cost of storing SSE registers
1911                                            in SImode, DImode and TImode */
1912   5,                                    /* MMX or SSE register to integer */
1913   32,                                   /* size of l1 cache.  */
1914   512,                                  /* size of l2 cache.  */
1915   64,                                   /* size of prefetch block */
1916   6,                                    /* number of parallel prefetches */
1917   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this
1918      value is increased to perhaps more appropriate value of 5.  */
1919   3,                                    /* Branch cost */
1920   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1921   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1922   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1923   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1924   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1925   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1926   generic_memcpy,
1927   generic_memset,
1928   1,                                    /* scalar_stmt_cost.  */
1929   1,                                    /* scalar load_cost.  */
1930   1,                                    /* scalar_store_cost.  */
1931   1,                                    /* vec_stmt_cost.  */
1932   1,                                    /* vec_to_scalar_cost.  */
1933   1,                                    /* scalar_to_vec_cost.  */
1934   1,                                    /* vec_align_load_cost.  */
1935   2,                                    /* vec_unalign_load_cost.  */
1936   1,                                    /* vec_store_cost.  */
1937   3,                                    /* cond_taken_branch_cost.  */
1938   1,                                    /* cond_not_taken_branch_cost.  */
1939 };
1940
1941 /* core_cost should produce code tuned for Core familly of CPUs.  */
1942 static stringop_algs core_memcpy[2] = {
1943   {libcall, {{1024, rep_prefix_4_byte, true}, {-1, libcall, false}}},
1944   {libcall, {{24, loop, true}, {128, rep_prefix_8_byte, true},
1945              {-1, libcall, false}}}};
1946 static stringop_algs core_memset[2] = {
1947   {libcall, {{6, loop_1_byte, true},
1948              {24, loop, true},
1949              {8192, rep_prefix_4_byte, true},
1950              {-1, libcall, false}}},
1951   {libcall, {{24, loop, true}, {512, rep_prefix_8_byte, true},
1952              {-1, libcall, false}}}};
1953
1954 static const
1955 struct processor_costs core_cost = {
1956   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1957   /* On all chips taken into consideration lea is 2 cycles and more.  With
1958      this cost however our current implementation of synth_mult results in
1959      use of unnecessary temporary registers causing regression on several
1960      SPECfp benchmarks.  */
1961   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1962   COSTS_N_INSNS (1),                    /* variable shift costs */
1963   COSTS_N_INSNS (1),                    /* constant shift costs */
1964   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1965    COSTS_N_INSNS (4),                   /*                               HI */
1966    COSTS_N_INSNS (3),                   /*                               SI */
1967    COSTS_N_INSNS (4),                   /*                               DI */
1968    COSTS_N_INSNS (2)},                  /*                            other */
1969   0,                                    /* cost of multiply per each bit set */
1970   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1971    COSTS_N_INSNS (26),                  /*                          HI */
1972    COSTS_N_INSNS (42),                  /*                          SI */
1973    COSTS_N_INSNS (74),                  /*                          DI */
1974    COSTS_N_INSNS (74)},                 /*                          other */
1975   COSTS_N_INSNS (1),                    /* cost of movsx */
1976   COSTS_N_INSNS (1),                    /* cost of movzx */
1977   8,                                    /* "large" insn */
1978   17,                                   /* MOVE_RATIO */
1979   4,                                 /* cost for loading QImode using movzbl */
1980   {4, 4, 4},                            /* cost of loading integer registers
1981                                            in QImode, HImode and SImode.
1982                                            Relative to reg-reg move (2).  */
1983   {4, 4, 4},                            /* cost of storing integer registers */
1984   4,                                    /* cost of reg,reg fld/fst */
1985   {12, 12, 12},                         /* cost of loading fp registers
1986                                            in SFmode, DFmode and XFmode */
1987   {6, 6, 8},                            /* cost of storing fp registers
1988                                            in SFmode, DFmode and XFmode */
1989   2,                                    /* cost of moving MMX register */
1990   {8, 8},                               /* cost of loading MMX registers
1991                                            in SImode and DImode */
1992   {8, 8},                               /* cost of storing MMX registers
1993                                            in SImode and DImode */
1994   2,                                    /* cost of moving SSE register */
1995   {8, 8, 8},                            /* cost of loading SSE registers
1996                                            in SImode, DImode and TImode */
1997   {8, 8, 8},                            /* cost of storing SSE registers
1998                                            in SImode, DImode and TImode */
1999   5,                                    /* MMX or SSE register to integer */
2000   64,                                   /* size of l1 cache.  */
2001   512,                                  /* size of l2 cache.  */
2002   64,                                   /* size of prefetch block */
2003   6,                                    /* number of parallel prefetches */
2004   /* FIXME perhaps more appropriate value is 5.  */
2005   3,                                    /* Branch cost */
2006   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
2007   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
2008   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
2009   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
2010   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
2011   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
2012   core_memcpy,
2013   core_memset,
2014   1,                                    /* scalar_stmt_cost.  */
2015   1,                                    /* scalar load_cost.  */
2016   1,                                    /* scalar_store_cost.  */
2017   1,                                    /* vec_stmt_cost.  */
2018   1,                                    /* vec_to_scalar_cost.  */
2019   1,                                    /* scalar_to_vec_cost.  */
2020   1,                                    /* vec_align_load_cost.  */
2021   2,                                    /* vec_unalign_load_cost.  */
2022   1,                                    /* vec_store_cost.  */
2023   3,                                    /* cond_taken_branch_cost.  */
2024   1,                                    /* cond_not_taken_branch_cost.  */
2025 };
2026
2027
2028 /* Set by -mtune.  */
2029 const struct processor_costs *ix86_tune_cost = &pentium_cost;
2030
2031 /* Set by -mtune or -Os.  */
2032 const struct processor_costs *ix86_cost = &pentium_cost;
2033
2034 /* Processor feature/optimization bitmasks.  */
2035 #define m_386 (1<<PROCESSOR_I386)
2036 #define m_486 (1<<PROCESSOR_I486)
2037 #define m_PENT (1<<PROCESSOR_PENTIUM)
2038 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
2039 #define m_PENT4 (1<<PROCESSOR_PENTIUM4)
2040 #define m_NOCONA (1<<PROCESSOR_NOCONA)
2041 #define m_P4_NOCONA (m_PENT4 | m_NOCONA)
2042 #define m_CORE2 (1<<PROCESSOR_CORE2)
2043 #define m_NEHALEM (1<<PROCESSOR_NEHALEM)
2044 #define m_SANDYBRIDGE (1<<PROCESSOR_SANDYBRIDGE)
2045 #define m_HASWELL (1<<PROCESSOR_HASWELL)
2046 #define m_CORE_ALL (m_CORE2 | m_NEHALEM  | m_SANDYBRIDGE | m_HASWELL)
2047 #define m_BONNELL (1<<PROCESSOR_BONNELL)
2048 #define m_SILVERMONT (1<<PROCESSOR_SILVERMONT)
2049 #define m_KNL (1<<PROCESSOR_KNL)
2050 #define m_INTEL (1<<PROCESSOR_INTEL)
2051
2052 #define m_GEODE (1<<PROCESSOR_GEODE)
2053 #define m_K6 (1<<PROCESSOR_K6)
2054 #define m_K6_GEODE (m_K6 | m_GEODE)
2055 #define m_K8 (1<<PROCESSOR_K8)
2056 #define m_ATHLON (1<<PROCESSOR_ATHLON)
2057 #define m_ATHLON_K8 (m_K8 | m_ATHLON)
2058 #define m_AMDFAM10 (1<<PROCESSOR_AMDFAM10)
2059 #define m_BDVER1 (1<<PROCESSOR_BDVER1)
2060 #define m_BDVER2 (1<<PROCESSOR_BDVER2)
2061 #define m_BDVER3 (1<<PROCESSOR_BDVER3)
2062 #define m_BDVER4 (1<<PROCESSOR_BDVER4)
2063 #define m_BTVER1 (1<<PROCESSOR_BTVER1)
2064 #define m_BTVER2 (1<<PROCESSOR_BTVER2)
2065 #define m_BDVER (m_BDVER1 | m_BDVER2 | m_BDVER3 | m_BDVER4)
2066 #define m_BTVER (m_BTVER1 | m_BTVER2)
2067 #define m_AMD_MULTIPLE (m_ATHLON_K8 | m_AMDFAM10 | m_BDVER | m_BTVER)
2068
2069 #define m_GENERIC (1<<PROCESSOR_GENERIC)
2070
2071 const char* ix86_tune_feature_names[X86_TUNE_LAST] = {
2072 #undef DEF_TUNE
2073 #define DEF_TUNE(tune, name, selector) name,
2074 #include "x86-tune.def"
2075 #undef DEF_TUNE
2076 };
2077
2078 /* Feature tests against the various tunings.  */
2079 unsigned char ix86_tune_features[X86_TUNE_LAST];
2080
2081 /* Feature tests against the various tunings used to create ix86_tune_features
2082    based on the processor mask.  */
2083 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
2084 #undef DEF_TUNE
2085 #define DEF_TUNE(tune, name, selector) selector,
2086 #include "x86-tune.def"
2087 #undef DEF_TUNE
2088 };
2089
2090 /* Feature tests against the various architecture variations.  */
2091 unsigned char ix86_arch_features[X86_ARCH_LAST];
2092
2093 /* Feature tests against the various architecture variations, used to create
2094    ix86_arch_features based on the processor mask.  */
2095 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
2096   /* X86_ARCH_CMOV: Conditional move was added for pentiumpro.  */
2097   ~(m_386 | m_486 | m_PENT | m_K6),
2098
2099   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
2100   ~m_386,
2101
2102   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
2103   ~(m_386 | m_486),
2104
2105   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
2106   ~m_386,
2107
2108   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
2109   ~m_386,
2110 };
2111
2112 /* In case the average insn count for single function invocation is
2113    lower than this constant, emit fast (but longer) prologue and
2114    epilogue code.  */
2115 #define FAST_PROLOGUE_INSN_COUNT 20
2116
2117 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
2118 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
2119 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
2120 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
2121
2122 /* Array of the smallest class containing reg number REGNO, indexed by
2123    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
2124
2125 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
2126 {
2127   /* ax, dx, cx, bx */
2128   AREG, DREG, CREG, BREG,
2129   /* si, di, bp, sp */
2130   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
2131   /* FP registers */
2132   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
2133   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
2134   /* arg pointer */
2135   NON_Q_REGS,
2136   /* flags, fpsr, fpcr, frame */
2137   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
2138   /* SSE registers */
2139   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
2140   SSE_REGS, SSE_REGS,
2141   /* MMX registers */
2142   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
2143   MMX_REGS, MMX_REGS,
2144   /* REX registers */
2145   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
2146   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
2147   /* SSE REX registers */
2148   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
2149   SSE_REGS, SSE_REGS,
2150   /* AVX-512 SSE registers */
2151   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2152   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2153   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2154   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2155   /* Mask registers.  */
2156   MASK_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS,
2157   MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS,
2158   /* MPX bound registers */
2159   BND_REGS, BND_REGS, BND_REGS, BND_REGS,
2160 };
2161
2162 /* The "default" register map used in 32bit mode.  */
2163
2164 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
2165 {
2166   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
2167   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
2168   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
2169   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
2170   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
2171   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
2172   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
2173   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 16-23*/
2174   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 24-31*/
2175   93, 94, 95, 96, 97, 98, 99, 100,      /* Mask registers */
2176   101, 102, 103, 104,                   /* bound registers */
2177 };
2178
2179 /* The "default" register map used in 64bit mode.  */
2180
2181 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
2182 {
2183   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
2184   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
2185   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
2186   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
2187   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
2188   8,9,10,11,12,13,14,15,                /* extended integer registers */
2189   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
2190   67, 68, 69, 70, 71, 72, 73, 74,       /* AVX-512 registers 16-23 */
2191   75, 76, 77, 78, 79, 80, 81, 82,       /* AVX-512 registers 24-31 */
2192   118, 119, 120, 121, 122, 123, 124, 125, /* Mask registers */
2193   126, 127, 128, 129,                   /* bound registers */
2194 };
2195
2196 /* Define the register numbers to be used in Dwarf debugging information.
2197    The SVR4 reference port C compiler uses the following register numbers
2198    in its Dwarf output code:
2199         0 for %eax (gcc regno = 0)
2200         1 for %ecx (gcc regno = 2)
2201         2 for %edx (gcc regno = 1)
2202         3 for %ebx (gcc regno = 3)
2203         4 for %esp (gcc regno = 7)
2204         5 for %ebp (gcc regno = 6)
2205         6 for %esi (gcc regno = 4)
2206         7 for %edi (gcc regno = 5)
2207    The following three DWARF register numbers are never generated by
2208    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
2209    believes these numbers have these meanings.
2210         8  for %eip    (no gcc equivalent)
2211         9  for %eflags (gcc regno = 17)
2212         10 for %trapno (no gcc equivalent)
2213    It is not at all clear how we should number the FP stack registers
2214    for the x86 architecture.  If the version of SDB on x86/svr4 were
2215    a bit less brain dead with respect to floating-point then we would
2216    have a precedent to follow with respect to DWARF register numbers
2217    for x86 FP registers, but the SDB on x86/svr4 is so completely
2218    broken with respect to FP registers that it is hardly worth thinking
2219    of it as something to strive for compatibility with.
2220    The version of x86/svr4 SDB I have at the moment does (partially)
2221    seem to believe that DWARF register number 11 is associated with
2222    the x86 register %st(0), but that's about all.  Higher DWARF
2223    register numbers don't seem to be associated with anything in
2224    particular, and even for DWARF regno 11, SDB only seems to under-
2225    stand that it should say that a variable lives in %st(0) (when
2226    asked via an `=' command) if we said it was in DWARF regno 11,
2227    but SDB still prints garbage when asked for the value of the
2228    variable in question (via a `/' command).
2229    (Also note that the labels SDB prints for various FP stack regs
2230    when doing an `x' command are all wrong.)
2231    Note that these problems generally don't affect the native SVR4
2232    C compiler because it doesn't allow the use of -O with -g and
2233    because when it is *not* optimizing, it allocates a memory
2234    location for each floating-point variable, and the memory
2235    location is what gets described in the DWARF AT_location
2236    attribute for the variable in question.
2237    Regardless of the severe mental illness of the x86/svr4 SDB, we
2238    do something sensible here and we use the following DWARF
2239    register numbers.  Note that these are all stack-top-relative
2240    numbers.
2241         11 for %st(0) (gcc regno = 8)
2242         12 for %st(1) (gcc regno = 9)
2243         13 for %st(2) (gcc regno = 10)
2244         14 for %st(3) (gcc regno = 11)
2245         15 for %st(4) (gcc regno = 12)
2246         16 for %st(5) (gcc regno = 13)
2247         17 for %st(6) (gcc regno = 14)
2248         18 for %st(7) (gcc regno = 15)
2249 */
2250 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
2251 {
2252   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
2253   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
2254   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
2255   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
2256   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
2257   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
2258   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
2259   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 16-23*/
2260   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 24-31*/
2261   93, 94, 95, 96, 97, 98, 99, 100,      /* Mask registers */
2262   101, 102, 103, 104,                   /* bound registers */
2263 };
2264
2265 /* Define parameter passing and return registers.  */
2266
2267 static int const x86_64_int_parameter_registers[6] =
2268 {
2269   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
2270 };
2271
2272 static int const x86_64_ms_abi_int_parameter_registers[4] =
2273 {
2274   CX_REG, DX_REG, R8_REG, R9_REG
2275 };
2276
2277 static int const x86_64_int_return_registers[4] =
2278 {
2279   AX_REG, DX_REG, DI_REG, SI_REG
2280 };
2281
2282 /* Additional registers that are clobbered by SYSV calls.  */
2283
2284 int const x86_64_ms_sysv_extra_clobbered_registers[12] =
2285 {
2286   SI_REG, DI_REG,
2287   XMM6_REG, XMM7_REG,
2288   XMM8_REG, XMM9_REG, XMM10_REG, XMM11_REG,
2289   XMM12_REG, XMM13_REG, XMM14_REG, XMM15_REG
2290 };
2291
2292 /* Define the structure for the machine field in struct function.  */
2293
2294 struct GTY(()) stack_local_entry {
2295   unsigned short mode;
2296   unsigned short n;
2297   rtx rtl;
2298   struct stack_local_entry *next;
2299 };
2300
2301 /* Structure describing stack frame layout.
2302    Stack grows downward:
2303
2304    [arguments]
2305                                         <- ARG_POINTER
2306    saved pc
2307
2308    saved static chain                   if ix86_static_chain_on_stack
2309
2310    saved frame pointer                  if frame_pointer_needed
2311                                         <- HARD_FRAME_POINTER
2312    [saved regs]
2313                                         <- regs_save_offset
2314    [padding0]
2315
2316    [saved SSE regs]
2317                                         <- sse_regs_save_offset
2318    [padding1]          |
2319                        |                <- FRAME_POINTER
2320    [va_arg registers]  |
2321                        |
2322    [frame]             |
2323                        |
2324    [padding2]          | = to_allocate
2325                                         <- STACK_POINTER
2326   */
2327 struct ix86_frame
2328 {
2329   int nsseregs;
2330   int nregs;
2331   int va_arg_size;
2332   int red_zone_size;
2333   int outgoing_arguments_size;
2334
2335   /* The offsets relative to ARG_POINTER.  */
2336   HOST_WIDE_INT frame_pointer_offset;
2337   HOST_WIDE_INT hard_frame_pointer_offset;
2338   HOST_WIDE_INT stack_pointer_offset;
2339   HOST_WIDE_INT hfp_save_offset;
2340   HOST_WIDE_INT reg_save_offset;
2341   HOST_WIDE_INT sse_reg_save_offset;
2342
2343   /* When save_regs_using_mov is set, emit prologue using
2344      move instead of push instructions.  */
2345   bool save_regs_using_mov;
2346 };
2347
2348 /* Which cpu are we scheduling for.  */
2349 enum attr_cpu ix86_schedule;
2350
2351 /* Which cpu are we optimizing for.  */
2352 enum processor_type ix86_tune;
2353
2354 /* Which instruction set architecture to use.  */
2355 enum processor_type ix86_arch;
2356
2357 /* True if processor has SSE prefetch instruction.  */
2358 unsigned char x86_prefetch_sse;
2359
2360 /* -mstackrealign option */
2361 static const char ix86_force_align_arg_pointer_string[]
2362   = "force_align_arg_pointer";
2363
2364 static rtx (*ix86_gen_leave) (void);
2365 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
2366 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
2367 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx, rtx);
2368 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
2369 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
2370 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
2371 static rtx (*ix86_gen_allocate_stack_worker) (rtx, rtx);
2372 static rtx (*ix86_gen_adjust_stack_and_probe) (rtx, rtx, rtx);
2373 static rtx (*ix86_gen_probe_stack_range) (rtx, rtx, rtx);
2374 static rtx (*ix86_gen_tls_global_dynamic_64) (rtx, rtx, rtx);
2375 static rtx (*ix86_gen_tls_local_dynamic_base_64) (rtx, rtx);
2376
2377 /* Preferred alignment for stack boundary in bits.  */
2378 unsigned int ix86_preferred_stack_boundary;
2379
2380 /* Alignment for incoming stack boundary in bits specified at
2381    command line.  */
2382 static unsigned int ix86_user_incoming_stack_boundary;
2383
2384 /* Default alignment for incoming stack boundary in bits.  */
2385 static unsigned int ix86_default_incoming_stack_boundary;
2386
2387 /* Alignment for incoming stack boundary in bits.  */
2388 unsigned int ix86_incoming_stack_boundary;
2389
2390 /* Calling abi specific va_list type nodes.  */
2391 static GTY(()) tree sysv_va_list_type_node;
2392 static GTY(()) tree ms_va_list_type_node;
2393
2394 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
2395 char internal_label_prefix[16];
2396 int internal_label_prefix_len;
2397
2398 /* Fence to use after loop using movnt.  */
2399 tree x86_mfence;
2400
2401 /* Register class used for passing given 64bit part of the argument.
2402    These represent classes as documented by the PS ABI, with the exception
2403    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
2404    use SF or DFmode move instead of DImode to avoid reformatting penalties.
2405
2406    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
2407    whenever possible (upper half does contain padding).  */
2408 enum x86_64_reg_class
2409   {
2410     X86_64_NO_CLASS,
2411     X86_64_INTEGER_CLASS,
2412     X86_64_INTEGERSI_CLASS,
2413     X86_64_SSE_CLASS,
2414     X86_64_SSESF_CLASS,
2415     X86_64_SSEDF_CLASS,
2416     X86_64_SSEUP_CLASS,
2417     X86_64_X87_CLASS,
2418     X86_64_X87UP_CLASS,
2419     X86_64_COMPLEX_X87_CLASS,
2420     X86_64_MEMORY_CLASS
2421   };
2422
2423 #define MAX_CLASSES 8
2424
2425 /* Table of constants used by fldpi, fldln2, etc....  */
2426 static REAL_VALUE_TYPE ext_80387_constants_table [5];
2427 static bool ext_80387_constants_init = 0;
2428
2429 \f
2430 static struct machine_function * ix86_init_machine_status (void);
2431 static rtx ix86_function_value (const_tree, const_tree, bool);
2432 static bool ix86_function_value_regno_p (const unsigned int);
2433 static unsigned int ix86_function_arg_boundary (machine_mode,
2434                                                 const_tree);
2435 static rtx ix86_static_chain (const_tree, bool);
2436 static int ix86_function_regparm (const_tree, const_tree);
2437 static void ix86_compute_frame_layout (struct ix86_frame *);
2438 static bool ix86_expand_vector_init_one_nonzero (bool, machine_mode,
2439                                                  rtx, rtx, int);
2440 static void ix86_add_new_builtins (HOST_WIDE_INT);
2441 static tree ix86_canonical_va_list_type (tree);
2442 static void predict_jump (int);
2443 static unsigned int split_stack_prologue_scratch_regno (void);
2444 static bool i386_asm_output_addr_const_extra (FILE *, rtx);
2445
2446 enum ix86_function_specific_strings
2447 {
2448   IX86_FUNCTION_SPECIFIC_ARCH,
2449   IX86_FUNCTION_SPECIFIC_TUNE,
2450   IX86_FUNCTION_SPECIFIC_MAX
2451 };
2452
2453 static char *ix86_target_string (HOST_WIDE_INT, int, const char *,
2454                                  const char *, enum fpmath_unit, bool);
2455 static void ix86_function_specific_save (struct cl_target_option *,
2456                                          struct gcc_options *opts);
2457 static void ix86_function_specific_restore (struct gcc_options *opts,
2458                                             struct cl_target_option *);
2459 static void ix86_function_specific_print (FILE *, int,
2460                                           struct cl_target_option *);
2461 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
2462 static bool ix86_valid_target_attribute_inner_p (tree, char *[],
2463                                                  struct gcc_options *,
2464                                                  struct gcc_options *,
2465                                                  struct gcc_options *);
2466 static bool ix86_can_inline_p (tree, tree);
2467 static void ix86_set_current_function (tree);
2468 static unsigned int ix86_minimum_incoming_stack_boundary (bool);
2469
2470 static enum calling_abi ix86_function_abi (const_tree);
2471
2472 \f
2473 #ifndef SUBTARGET32_DEFAULT_CPU
2474 #define SUBTARGET32_DEFAULT_CPU "i386"
2475 #endif
2476
2477 /* Whether -mtune= or -march= were specified */
2478 static int ix86_tune_defaulted;
2479 static int ix86_arch_specified;
2480
2481 /* Vectorization library interface and handlers.  */
2482 static tree (*ix86_veclib_handler) (enum built_in_function, tree, tree);
2483
2484 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
2485 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
2486
2487 /* Processor target table, indexed by processor number */
2488 struct ptt
2489 {
2490   const char *const name;                       /* processor name  */
2491   const struct processor_costs *cost;           /* Processor costs */
2492   const int align_loop;                         /* Default alignments.  */
2493   const int align_loop_max_skip;
2494   const int align_jump;
2495   const int align_jump_max_skip;
2496   const int align_func;
2497 };
2498
2499 /* This table must be in sync with enum processor_type in i386.h.  */ 
2500 static const struct ptt processor_target_table[PROCESSOR_max] =
2501 {
2502   {"generic", &generic_cost, 16, 10, 16, 10, 16},
2503   {"i386", &i386_cost, 4, 3, 4, 3, 4},
2504   {"i486", &i486_cost, 16, 15, 16, 15, 16},
2505   {"pentium", &pentium_cost, 16, 7, 16, 7, 16},
2506   {"pentiumpro", &pentiumpro_cost, 16, 15, 16, 10, 16},
2507   {"pentium4", &pentium4_cost, 0, 0, 0, 0, 0},
2508   {"nocona", &nocona_cost, 0, 0, 0, 0, 0},
2509   {"core2", &core_cost, 16, 10, 16, 10, 16},
2510   {"nehalem", &core_cost, 16, 10, 16, 10, 16},
2511   {"sandybridge", &core_cost, 16, 10, 16, 10, 16},
2512   {"haswell", &core_cost, 16, 10, 16, 10, 16},
2513   {"bonnell", &atom_cost, 16, 15, 16, 7, 16},
2514   {"silvermont", &slm_cost, 16, 15, 16, 7, 16},
2515   {"knl", &slm_cost, 16, 15, 16, 7, 16},
2516   {"intel", &intel_cost, 16, 15, 16, 7, 16},
2517   {"geode", &geode_cost, 0, 0, 0, 0, 0},
2518   {"k6", &k6_cost, 32, 7, 32, 7, 32},
2519   {"athlon", &athlon_cost, 16, 7, 16, 7, 16},
2520   {"k8", &k8_cost, 16, 7, 16, 7, 16},
2521   {"amdfam10", &amdfam10_cost, 32, 24, 32, 7, 32},
2522   {"bdver1", &bdver1_cost, 16, 10, 16, 7, 11},
2523   {"bdver2", &bdver2_cost, 16, 10, 16, 7, 11},
2524   {"bdver3", &bdver3_cost, 16, 10, 16, 7, 11},
2525   {"bdver4", &bdver4_cost, 16, 10, 16, 7, 11},
2526   {"btver1", &btver1_cost, 16, 10, 16, 7, 11},
2527   {"btver2", &btver2_cost, 16, 10, 16, 7, 11}
2528 };
2529 \f
2530 static unsigned int
2531 rest_of_handle_insert_vzeroupper (void)
2532 {
2533   int i;
2534
2535   /* vzeroupper instructions are inserted immediately after reload to
2536      account for possible spills from 256bit registers.  The pass
2537      reuses mode switching infrastructure by re-running mode insertion
2538      pass, so disable entities that have already been processed.  */
2539   for (i = 0; i < MAX_386_ENTITIES; i++)
2540     ix86_optimize_mode_switching[i] = 0;
2541
2542   ix86_optimize_mode_switching[AVX_U128] = 1;
2543
2544   /* Call optimize_mode_switching.  */
2545   g->get_passes ()->execute_pass_mode_switching ();
2546   return 0;
2547 }
2548
2549 namespace {
2550
2551 const pass_data pass_data_insert_vzeroupper =
2552 {
2553   RTL_PASS, /* type */
2554   "vzeroupper", /* name */
2555   OPTGROUP_NONE, /* optinfo_flags */
2556   TV_NONE, /* tv_id */
2557   0, /* properties_required */
2558   0, /* properties_provided */
2559   0, /* properties_destroyed */
2560   0, /* todo_flags_start */
2561   TODO_df_finish, /* todo_flags_finish */
2562 };
2563
2564 class pass_insert_vzeroupper : public rtl_opt_pass
2565 {
2566 public:
2567   pass_insert_vzeroupper(gcc::context *ctxt)
2568     : rtl_opt_pass(pass_data_insert_vzeroupper, ctxt)
2569   {}
2570
2571   /* opt_pass methods: */
2572   virtual bool gate (function *)
2573     {
2574       return TARGET_AVX && !TARGET_AVX512F && TARGET_VZEROUPPER;
2575     }
2576
2577   virtual unsigned int execute (function *)
2578     {
2579       return rest_of_handle_insert_vzeroupper ();
2580     }
2581
2582 }; // class pass_insert_vzeroupper
2583
2584 } // anon namespace
2585
2586 rtl_opt_pass *
2587 make_pass_insert_vzeroupper (gcc::context *ctxt)
2588 {
2589   return new pass_insert_vzeroupper (ctxt);
2590 }
2591
2592 /* Return true if a red-zone is in use.  */
2593
2594 static inline bool
2595 ix86_using_red_zone (void)
2596 {
2597   return TARGET_RED_ZONE && !TARGET_64BIT_MS_ABI;
2598 }
2599 \f
2600 /* Return a string that documents the current -m options.  The caller is
2601    responsible for freeing the string.  */
2602
2603 static char *
2604 ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch,
2605                     const char *tune, enum fpmath_unit fpmath,
2606                     bool add_nl_p)
2607 {
2608   struct ix86_target_opts
2609   {
2610     const char *option;         /* option string */
2611     HOST_WIDE_INT mask;         /* isa mask options */
2612   };
2613
2614   /* This table is ordered so that options like -msse4.2 that imply
2615      preceding options while match those first.  */
2616   static struct ix86_target_opts isa_opts[] =
2617   {
2618     { "-mfma4",         OPTION_MASK_ISA_FMA4 },
2619     { "-mfma",          OPTION_MASK_ISA_FMA },
2620     { "-mxop",          OPTION_MASK_ISA_XOP },
2621     { "-mlwp",          OPTION_MASK_ISA_LWP },
2622     { "-mavx512f",      OPTION_MASK_ISA_AVX512F },
2623     { "-mavx512er",     OPTION_MASK_ISA_AVX512ER },
2624     { "-mavx512cd",     OPTION_MASK_ISA_AVX512CD },
2625     { "-mavx512pf",     OPTION_MASK_ISA_AVX512PF },
2626     { "-mavx512dq",     OPTION_MASK_ISA_AVX512DQ },
2627     { "-mavx512bw",     OPTION_MASK_ISA_AVX512BW },
2628     { "-mavx512vl",     OPTION_MASK_ISA_AVX512VL },
2629     { "-mavx512ifma",   OPTION_MASK_ISA_AVX512IFMA },
2630     { "-mavx512vbmi",   OPTION_MASK_ISA_AVX512VBMI },
2631     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2632     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2633     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2634     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2635     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2636     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2637     { "-msse",          OPTION_MASK_ISA_SSE },
2638     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2639     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2640     { "-mmmx",          OPTION_MASK_ISA_MMX },
2641     { "-mabm",          OPTION_MASK_ISA_ABM },
2642     { "-mbmi",          OPTION_MASK_ISA_BMI },
2643     { "-mbmi2",         OPTION_MASK_ISA_BMI2 },
2644     { "-mlzcnt",        OPTION_MASK_ISA_LZCNT },
2645     { "-mhle",          OPTION_MASK_ISA_HLE },
2646     { "-mfxsr",         OPTION_MASK_ISA_FXSR },
2647     { "-mrdseed",       OPTION_MASK_ISA_RDSEED },
2648     { "-mprfchw",       OPTION_MASK_ISA_PRFCHW },
2649     { "-madx",          OPTION_MASK_ISA_ADX },
2650     { "-mtbm",          OPTION_MASK_ISA_TBM },
2651     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2652     { "-mmovbe",        OPTION_MASK_ISA_MOVBE },
2653     { "-mcrc32",        OPTION_MASK_ISA_CRC32 },
2654     { "-maes",          OPTION_MASK_ISA_AES },
2655     { "-msha",          OPTION_MASK_ISA_SHA },
2656     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2657     { "-mfsgsbase",     OPTION_MASK_ISA_FSGSBASE },
2658     { "-mrdrnd",        OPTION_MASK_ISA_RDRND },
2659     { "-mf16c",         OPTION_MASK_ISA_F16C },
2660     { "-mrtm",          OPTION_MASK_ISA_RTM },
2661     { "-mxsave",        OPTION_MASK_ISA_XSAVE },
2662     { "-mxsaveopt",     OPTION_MASK_ISA_XSAVEOPT },
2663     { "-mprefetchwt1",  OPTION_MASK_ISA_PREFETCHWT1 },
2664     { "-mclflushopt",   OPTION_MASK_ISA_CLFLUSHOPT },
2665     { "-mxsavec",       OPTION_MASK_ISA_XSAVEC },
2666     { "-mxsaves",       OPTION_MASK_ISA_XSAVES },
2667     { "-mmpx",          OPTION_MASK_ISA_MPX },
2668     { "-mclwb",         OPTION_MASK_ISA_CLWB },
2669     { "-mpcommit",      OPTION_MASK_ISA_PCOMMIT },
2670   };
2671
2672   /* Flag options.  */
2673   static struct ix86_target_opts flag_opts[] =
2674   {
2675     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2676     { "-mlong-double-128",              MASK_LONG_DOUBLE_128 },
2677     { "-mlong-double-64",               MASK_LONG_DOUBLE_64 },
2678     { "-m80387",                        MASK_80387 },
2679     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2680     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2681     { "-mcld",                          MASK_CLD },
2682     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2683     { "-mieee-fp",                      MASK_IEEE_FP },
2684     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2685     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2686     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2687     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2688     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2689     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2690     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2691     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2692     { "-mrecip",                        MASK_RECIP },
2693     { "-mrtd",                          MASK_RTD },
2694     { "-msseregparm",                   MASK_SSEREGPARM },
2695     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2696     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2697     { "-mvect8-ret-in-mem",             MASK_VECT8_RETURNS },
2698     { "-m8bit-idiv",                    MASK_USE_8BIT_IDIV },
2699     { "-mvzeroupper",                   MASK_VZEROUPPER },
2700     { "-mavx256-split-unaligned-load",  MASK_AVX256_SPLIT_UNALIGNED_LOAD},
2701     { "-mavx256-split-unaligned-store", MASK_AVX256_SPLIT_UNALIGNED_STORE},
2702     { "-mprefer-avx128",                MASK_PREFER_AVX128},
2703   };
2704
2705   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (flag_opts) + 6][2];
2706
2707   char isa_other[40];
2708   char target_other[40];
2709   unsigned num = 0;
2710   unsigned i, j;
2711   char *ret;
2712   char *ptr;
2713   size_t len;
2714   size_t line_len;
2715   size_t sep_len;
2716   const char *abi;
2717
2718   memset (opts, '\0', sizeof (opts));
2719
2720   /* Add -march= option.  */
2721   if (arch)
2722     {
2723       opts[num][0] = "-march=";
2724       opts[num++][1] = arch;
2725     }
2726
2727   /* Add -mtune= option.  */
2728   if (tune)
2729     {
2730       opts[num][0] = "-mtune=";
2731       opts[num++][1] = tune;
2732     }
2733
2734   /* Add -m32/-m64/-mx32.  */
2735   if ((isa & OPTION_MASK_ISA_64BIT) != 0)
2736     {
2737       if ((isa & OPTION_MASK_ABI_64) != 0)
2738         abi = "-m64";
2739       else
2740         abi = "-mx32";
2741       isa &= ~ (OPTION_MASK_ISA_64BIT
2742                 | OPTION_MASK_ABI_64
2743                 | OPTION_MASK_ABI_X32);
2744     }
2745   else
2746     abi = "-m32";
2747   opts[num++][0] = abi;
2748
2749   /* Pick out the options in isa options.  */
2750   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
2751     {
2752       if ((isa & isa_opts[i].mask) != 0)
2753         {
2754           opts[num++][0] = isa_opts[i].option;
2755           isa &= ~ isa_opts[i].mask;
2756         }
2757     }
2758
2759   if (isa && add_nl_p)
2760     {
2761       opts[num++][0] = isa_other;
2762       sprintf (isa_other, "(other isa: %#" HOST_WIDE_INT_PRINT "x)",
2763                isa);
2764     }
2765
2766   /* Add flag options.  */
2767   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
2768     {
2769       if ((flags & flag_opts[i].mask) != 0)
2770         {
2771           opts[num++][0] = flag_opts[i].option;
2772           flags &= ~ flag_opts[i].mask;
2773         }
2774     }
2775
2776   if (flags && add_nl_p)
2777     {
2778       opts[num++][0] = target_other;
2779       sprintf (target_other, "(other flags: %#x)", flags);
2780     }
2781
2782   /* Add -fpmath= option.  */
2783   if (fpmath)
2784     {
2785       opts[num][0] = "-mfpmath=";
2786       switch ((int) fpmath)
2787         {
2788         case FPMATH_387:
2789           opts[num++][1] = "387";
2790           break;
2791
2792         case FPMATH_SSE:
2793           opts[num++][1] = "sse";
2794           break;
2795
2796         case FPMATH_387 | FPMATH_SSE:
2797           opts[num++][1] = "sse+387";
2798           break;
2799
2800         default:
2801           gcc_unreachable ();
2802         }
2803     }
2804
2805   /* Any options?  */
2806   if (num == 0)
2807     return NULL;
2808
2809   gcc_assert (num < ARRAY_SIZE (opts));
2810
2811   /* Size the string.  */
2812   len = 0;
2813   sep_len = (add_nl_p) ? 3 : 1;
2814   for (i = 0; i < num; i++)
2815     {
2816       len += sep_len;
2817       for (j = 0; j < 2; j++)
2818         if (opts[i][j])
2819           len += strlen (opts[i][j]);
2820     }
2821
2822   /* Build the string.  */
2823   ret = ptr = (char *) xmalloc (len);
2824   line_len = 0;
2825
2826   for (i = 0; i < num; i++)
2827     {
2828       size_t len2[2];
2829
2830       for (j = 0; j < 2; j++)
2831         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2832
2833       if (i != 0)
2834         {
2835           *ptr++ = ' ';
2836           line_len++;
2837
2838           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2839             {
2840               *ptr++ = '\\';
2841               *ptr++ = '\n';
2842               line_len = 0;
2843             }
2844         }
2845
2846       for (j = 0; j < 2; j++)
2847         if (opts[i][j])
2848           {
2849             memcpy (ptr, opts[i][j], len2[j]);
2850             ptr += len2[j];
2851             line_len += len2[j];
2852           }
2853     }
2854
2855   *ptr = '\0';
2856   gcc_assert (ret + len >= ptr);
2857
2858   return ret;
2859 }
2860
2861 /* Return true, if profiling code should be emitted before
2862    prologue. Otherwise it returns false.
2863    Note: For x86 with "hotfix" it is sorried.  */
2864 static bool
2865 ix86_profile_before_prologue (void)
2866 {
2867   return flag_fentry != 0;
2868 }
2869
2870 /* Function that is callable from the debugger to print the current
2871    options.  */
2872 void ATTRIBUTE_UNUSED
2873 ix86_debug_options (void)
2874 {
2875   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2876                                    ix86_arch_string, ix86_tune_string,
2877                                    ix86_fpmath, true);
2878
2879   if (opts)
2880     {
2881       fprintf (stderr, "%s\n\n", opts);
2882       free (opts);
2883     }
2884   else
2885     fputs ("<no options>\n\n", stderr);
2886
2887   return;
2888 }
2889
2890 static const char *stringop_alg_names[] = {
2891 #define DEF_ENUM
2892 #define DEF_ALG(alg, name) #name,
2893 #include "stringop.def"
2894 #undef DEF_ENUM
2895 #undef DEF_ALG
2896 };
2897
2898 /* Parse parameter string passed to -mmemcpy-strategy= or -mmemset-strategy=.
2899    The string is of the following form (or comma separated list of it):
2900
2901      strategy_alg:max_size:[align|noalign]
2902
2903    where the full size range for the strategy is either [0, max_size] or
2904    [min_size, max_size], in which min_size is the max_size + 1 of the
2905    preceding range.  The last size range must have max_size == -1.
2906
2907    Examples:
2908
2909     1.
2910        -mmemcpy-strategy=libcall:-1:noalign
2911
2912       this is equivalent to (for known size memcpy) -mstringop-strategy=libcall
2913
2914
2915    2.
2916       -mmemset-strategy=rep_8byte:16:noalign,vector_loop:2048:align,libcall:-1:noalign
2917
2918       This is to tell the compiler to use the following strategy for memset
2919       1) when the expected size is between [1, 16], use rep_8byte strategy;
2920       2) when the size is between [17, 2048], use vector_loop;
2921       3) when the size is > 2048, use libcall.  */
2922
2923 struct stringop_size_range
2924 {
2925   int max;
2926   stringop_alg alg;
2927   bool noalign;
2928 };
2929
2930 static void
2931 ix86_parse_stringop_strategy_string (char *strategy_str, bool is_memset)
2932 {
2933   const struct stringop_algs *default_algs;
2934   stringop_size_range input_ranges[MAX_STRINGOP_ALGS];
2935   char *curr_range_str, *next_range_str;
2936   int i = 0, n = 0;
2937
2938   if (is_memset)
2939     default_algs = &ix86_cost->memset[TARGET_64BIT != 0];
2940   else
2941     default_algs = &ix86_cost->memcpy[TARGET_64BIT != 0];
2942
2943   curr_range_str = strategy_str;
2944
2945   do
2946     {
2947       int maxs;
2948       char alg_name[128];
2949       char align[16];
2950       next_range_str = strchr (curr_range_str, ',');
2951       if (next_range_str)
2952         *next_range_str++ = '\0';
2953
2954       if (3 != sscanf (curr_range_str, "%20[^:]:%d:%10s",
2955                        alg_name, &maxs, align))
2956         {
2957           error ("wrong arg %s to option %s", curr_range_str,
2958                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2959           return;
2960         }
2961
2962       if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1))
2963         {
2964           error ("size ranges of option %s should be increasing",
2965                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2966           return;
2967         }
2968
2969       for (i = 0; i < last_alg; i++)
2970         if (!strcmp (alg_name, stringop_alg_names[i]))
2971           break;
2972
2973       if (i == last_alg)
2974         {
2975           error ("wrong stringop strategy name %s specified for option %s",
2976                  alg_name,
2977                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2978           return;
2979         }
2980
2981       input_ranges[n].max = maxs;
2982       input_ranges[n].alg = (stringop_alg) i;
2983       if (!strcmp (align, "align"))
2984         input_ranges[n].noalign = false;
2985       else if (!strcmp (align, "noalign"))
2986         input_ranges[n].noalign = true;
2987       else
2988         {
2989           error ("unknown alignment %s specified for option %s",
2990                  align, is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2991           return;
2992         }
2993       n++;
2994       curr_range_str = next_range_str;
2995     }
2996   while (curr_range_str);
2997
2998   if (input_ranges[n - 1].max != -1)
2999     {
3000       error ("the max value for the last size range should be -1"
3001              " for option %s",
3002              is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3003       return;
3004     }
3005
3006   if (n > MAX_STRINGOP_ALGS)
3007     {
3008       error ("too many size ranges specified in option %s",
3009              is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3010       return;
3011     }
3012
3013   /* Now override the default algs array.  */
3014   for (i = 0; i < n; i++)
3015     {
3016       *const_cast<int *>(&default_algs->size[i].max) = input_ranges[i].max;
3017       *const_cast<stringop_alg *>(&default_algs->size[i].alg)
3018           = input_ranges[i].alg;
3019       *const_cast<int *>(&default_algs->size[i].noalign)
3020           = input_ranges[i].noalign;
3021     }
3022 }
3023
3024 \f
3025 /* parse -mtune-ctrl= option. When DUMP is true,
3026    print the features that are explicitly set.  */
3027
3028 static void
3029 parse_mtune_ctrl_str (bool dump)
3030 {
3031   if (!ix86_tune_ctrl_string)
3032     return;
3033
3034   char *next_feature_string = NULL;
3035   char *curr_feature_string = xstrdup (ix86_tune_ctrl_string);
3036   char *orig = curr_feature_string;
3037   int i;
3038   do
3039     {
3040       bool clear = false;
3041
3042       next_feature_string = strchr (curr_feature_string, ',');
3043       if (next_feature_string)
3044         *next_feature_string++ = '\0';
3045       if (*curr_feature_string == '^')
3046         {
3047           curr_feature_string++;
3048           clear = true;
3049         }
3050       for (i = 0; i < X86_TUNE_LAST; i++)
3051         {
3052           if (!strcmp (curr_feature_string, ix86_tune_feature_names[i]))
3053             {
3054               ix86_tune_features[i] = !clear;
3055               if (dump)
3056                 fprintf (stderr, "Explicitly %s feature %s\n",
3057                          clear ? "clear" : "set", ix86_tune_feature_names[i]);
3058               break;
3059             }
3060         }
3061       if (i == X86_TUNE_LAST)
3062         error ("Unknown parameter to option -mtune-ctrl: %s",
3063                clear ? curr_feature_string - 1 : curr_feature_string);
3064       curr_feature_string = next_feature_string;
3065     }
3066   while (curr_feature_string);
3067   free (orig);
3068 }
3069
3070 /* Helper function to set ix86_tune_features. IX86_TUNE is the
3071    processor type.  */
3072
3073 static void
3074 set_ix86_tune_features (enum processor_type ix86_tune, bool dump)
3075 {
3076   unsigned int ix86_tune_mask = 1u << ix86_tune;
3077   int i;
3078
3079   for (i = 0; i < X86_TUNE_LAST; ++i)
3080     {
3081       if (ix86_tune_no_default)
3082         ix86_tune_features[i] = 0;
3083       else
3084         ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3085     }
3086
3087   if (dump)
3088     {
3089       fprintf (stderr, "List of x86 specific tuning parameter names:\n");
3090       for (i = 0; i < X86_TUNE_LAST; i++)
3091         fprintf (stderr, "%s : %s\n", ix86_tune_feature_names[i],
3092                  ix86_tune_features[i] ? "on" : "off");
3093     }
3094
3095   parse_mtune_ctrl_str (dump);
3096 }
3097
3098
3099 /* Override various settings based on options.  If MAIN_ARGS_P, the
3100    options are from the command line, otherwise they are from
3101    attributes.  */
3102
3103 static void
3104 ix86_option_override_internal (bool main_args_p,
3105                                struct gcc_options *opts,
3106                                struct gcc_options *opts_set)
3107 {
3108   int i;
3109   unsigned int ix86_arch_mask;
3110   const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL);
3111   const char *prefix;
3112   const char *suffix;
3113   const char *sw;
3114
3115 #define PTA_3DNOW               (HOST_WIDE_INT_1 << 0)
3116 #define PTA_3DNOW_A             (HOST_WIDE_INT_1 << 1)
3117 #define PTA_64BIT               (HOST_WIDE_INT_1 << 2)
3118 #define PTA_ABM                 (HOST_WIDE_INT_1 << 3)
3119 #define PTA_AES                 (HOST_WIDE_INT_1 << 4)
3120 #define PTA_AVX                 (HOST_WIDE_INT_1 << 5)
3121 #define PTA_BMI                 (HOST_WIDE_INT_1 << 6)
3122 #define PTA_CX16                (HOST_WIDE_INT_1 << 7)
3123 #define PTA_F16C                (HOST_WIDE_INT_1 << 8)
3124 #define PTA_FMA                 (HOST_WIDE_INT_1 << 9)
3125 #define PTA_FMA4                (HOST_WIDE_INT_1 << 10)
3126 #define PTA_FSGSBASE            (HOST_WIDE_INT_1 << 11)
3127 #define PTA_LWP                 (HOST_WIDE_INT_1 << 12)
3128 #define PTA_LZCNT               (HOST_WIDE_INT_1 << 13)
3129 #define PTA_MMX                 (HOST_WIDE_INT_1 << 14)
3130 #define PTA_MOVBE               (HOST_WIDE_INT_1 << 15)
3131 #define PTA_NO_SAHF             (HOST_WIDE_INT_1 << 16)
3132 #define PTA_PCLMUL              (HOST_WIDE_INT_1 << 17)
3133 #define PTA_POPCNT              (HOST_WIDE_INT_1 << 18)
3134 #define PTA_PREFETCH_SSE        (HOST_WIDE_INT_1 << 19)
3135 #define PTA_RDRND               (HOST_WIDE_INT_1 << 20)
3136 #define PTA_SSE                 (HOST_WIDE_INT_1 << 21)
3137 #define PTA_SSE2                (HOST_WIDE_INT_1 << 22)
3138 #define PTA_SSE3                (HOST_WIDE_INT_1 << 23)
3139 #define PTA_SSE4_1              (HOST_WIDE_INT_1 << 24)
3140 #define PTA_SSE4_2              (HOST_WIDE_INT_1 << 25)
3141 #define PTA_SSE4A               (HOST_WIDE_INT_1 << 26)
3142 #define PTA_SSSE3               (HOST_WIDE_INT_1 << 27)
3143 #define PTA_TBM                 (HOST_WIDE_INT_1 << 28)
3144 #define PTA_XOP                 (HOST_WIDE_INT_1 << 29)
3145 #define PTA_AVX2                (HOST_WIDE_INT_1 << 30)
3146 #define PTA_BMI2                (HOST_WIDE_INT_1 << 31)
3147 #define PTA_RTM                 (HOST_WIDE_INT_1 << 32)
3148 #define PTA_HLE                 (HOST_WIDE_INT_1 << 33)
3149 #define PTA_PRFCHW              (HOST_WIDE_INT_1 << 34)
3150 #define PTA_RDSEED              (HOST_WIDE_INT_1 << 35)
3151 #define PTA_ADX                 (HOST_WIDE_INT_1 << 36)
3152 #define PTA_FXSR                (HOST_WIDE_INT_1 << 37)
3153 #define PTA_XSAVE               (HOST_WIDE_INT_1 << 38)
3154 #define PTA_XSAVEOPT            (HOST_WIDE_INT_1 << 39)
3155 #define PTA_AVX512F             (HOST_WIDE_INT_1 << 40)
3156 #define PTA_AVX512ER            (HOST_WIDE_INT_1 << 41)
3157 #define PTA_AVX512PF            (HOST_WIDE_INT_1 << 42)
3158 #define PTA_AVX512CD            (HOST_WIDE_INT_1 << 43)
3159 #define PTA_MPX                 (HOST_WIDE_INT_1 << 44)
3160 #define PTA_SHA                 (HOST_WIDE_INT_1 << 45)
3161 #define PTA_PREFETCHWT1         (HOST_WIDE_INT_1 << 46)
3162 #define PTA_CLFLUSHOPT          (HOST_WIDE_INT_1 << 47)
3163 #define PTA_XSAVEC              (HOST_WIDE_INT_1 << 48)
3164 #define PTA_XSAVES              (HOST_WIDE_INT_1 << 49)
3165 #define PTA_AVX512DQ            (HOST_WIDE_INT_1 << 50)
3166 #define PTA_AVX512BW            (HOST_WIDE_INT_1 << 51)
3167 #define PTA_AVX512VL            (HOST_WIDE_INT_1 << 52)
3168 #define PTA_AVX512IFMA          (HOST_WIDE_INT_1 << 53)
3169 #define PTA_AVX512VBMI          (HOST_WIDE_INT_1 << 54)
3170 #define PTA_CLWB                (HOST_WIDE_INT_1 << 55)
3171 #define PTA_PCOMMIT             (HOST_WIDE_INT_1 << 56)
3172
3173 #define PTA_CORE2 \
3174   (PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_SSSE3 \
3175    | PTA_CX16 | PTA_FXSR)
3176 #define PTA_NEHALEM \
3177   (PTA_CORE2 | PTA_SSE4_1 | PTA_SSE4_2 | PTA_POPCNT)
3178 #define PTA_WESTMERE \
3179   (PTA_NEHALEM | PTA_AES | PTA_PCLMUL)
3180 #define PTA_SANDYBRIDGE \
3181   (PTA_WESTMERE | PTA_AVX | PTA_XSAVE | PTA_XSAVEOPT)
3182 #define PTA_IVYBRIDGE \
3183   (PTA_SANDYBRIDGE | PTA_FSGSBASE | PTA_RDRND | PTA_F16C)
3184 #define PTA_HASWELL \
3185   (PTA_IVYBRIDGE | PTA_AVX2 | PTA_BMI | PTA_BMI2 | PTA_LZCNT \
3186    | PTA_FMA | PTA_MOVBE | PTA_HLE)
3187 #define PTA_BROADWELL \
3188   (PTA_HASWELL | PTA_ADX | PTA_PRFCHW | PTA_RDSEED)
3189 #define PTA_KNL \
3190   (PTA_BROADWELL | PTA_AVX512PF | PTA_AVX512ER | PTA_AVX512F | PTA_AVX512CD)
3191 #define PTA_BONNELL \
3192   (PTA_CORE2 | PTA_MOVBE)
3193 #define PTA_SILVERMONT \
3194   (PTA_WESTMERE | PTA_MOVBE)
3195
3196 /* if this reaches 64, need to widen struct pta flags below */
3197
3198   static struct pta
3199     {
3200       const char *const name;           /* processor name or nickname.  */
3201       const enum processor_type processor;
3202       const enum attr_cpu schedule;
3203       const unsigned HOST_WIDE_INT flags;
3204     }
3205   const processor_alias_table[] =
3206     {
3207       {"i386", PROCESSOR_I386, CPU_NONE, 0},
3208       {"i486", PROCESSOR_I486, CPU_NONE, 0},
3209       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
3210       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
3211       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
3212       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
3213       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3214       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3215       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3216         PTA_MMX | PTA_SSE | PTA_FXSR},
3217       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
3218       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
3219       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_FXSR},
3220       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3221         PTA_MMX | PTA_SSE | PTA_FXSR},
3222       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3223         PTA_MMX | PTA_SSE | PTA_FXSR},
3224       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3225         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_FXSR},
3226       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
3227         PTA_MMX |PTA_SSE | PTA_SSE2 | PTA_FXSR},
3228       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
3229         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_FXSR},
3230       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
3231         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_FXSR},
3232       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
3233         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3234         | PTA_CX16 | PTA_NO_SAHF | PTA_FXSR},
3235       {"core2", PROCESSOR_CORE2, CPU_CORE2, PTA_CORE2},
3236       {"nehalem", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_NEHALEM},
3237       {"corei7", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_NEHALEM},
3238       {"westmere", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_WESTMERE},
3239       {"sandybridge", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3240         PTA_SANDYBRIDGE},
3241       {"corei7-avx", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3242         PTA_SANDYBRIDGE},
3243       {"ivybridge", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3244         PTA_IVYBRIDGE},
3245       {"core-avx-i", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3246         PTA_IVYBRIDGE},
3247       {"haswell", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_HASWELL},
3248       {"core-avx2", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_HASWELL},
3249       {"broadwell", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_BROADWELL},
3250       {"bonnell", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL},
3251       {"atom", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL},
3252       {"silvermont", PROCESSOR_SILVERMONT, CPU_SLM, PTA_SILVERMONT},
3253       {"slm", PROCESSOR_SILVERMONT, CPU_SLM, PTA_SILVERMONT},
3254       {"knl", PROCESSOR_KNL, CPU_KNL, PTA_KNL},
3255       {"intel", PROCESSOR_INTEL, CPU_SLM, PTA_NEHALEM},
3256       {"geode", PROCESSOR_GEODE, CPU_GEODE,
3257         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3258       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
3259       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3260       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3261       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
3262         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3263       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
3264         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3265       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
3266         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3267       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
3268         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3269       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
3270         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3271       {"x86-64", PROCESSOR_K8, CPU_K8,
3272         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF | PTA_FXSR},
3273       {"k8", PROCESSOR_K8, CPU_K8,
3274         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3275         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3276       {"k8-sse3", PROCESSOR_K8, CPU_K8,
3277         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3278         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3279       {"opteron", PROCESSOR_K8, CPU_K8,
3280         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3281         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3282       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
3283         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3284         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3285       {"athlon64", PROCESSOR_K8, CPU_K8,
3286         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3287         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3288       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
3289         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3290         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3291       {"athlon-fx", PROCESSOR_K8, CPU_K8,
3292         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3293         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3294       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
3295         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_SSE2
3296         | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_PRFCHW | PTA_FXSR},
3297       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
3298         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_SSE2
3299         | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_PRFCHW | PTA_FXSR},
3300       {"bdver1", PROCESSOR_BDVER1, CPU_BDVER1,
3301         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3302         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3303         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3304         | PTA_XOP | PTA_LWP | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE},
3305       {"bdver2", PROCESSOR_BDVER2, CPU_BDVER2,
3306         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3307         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3308         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3309         | PTA_XOP | PTA_LWP | PTA_BMI | PTA_TBM | PTA_F16C
3310         | PTA_FMA | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE},
3311       {"bdver3", PROCESSOR_BDVER3, CPU_BDVER3,
3312         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3313         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3314         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3315         | PTA_XOP | PTA_LWP | PTA_BMI | PTA_TBM | PTA_F16C
3316         | PTA_FMA | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE 
3317         | PTA_XSAVEOPT | PTA_FSGSBASE},
3318      {"bdver4", PROCESSOR_BDVER4, CPU_BDVER4,
3319         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3320         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3321         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_AVX2 
3322         | PTA_FMA4 | PTA_XOP | PTA_LWP | PTA_BMI | PTA_BMI2 
3323         | PTA_TBM | PTA_F16C | PTA_FMA | PTA_PRFCHW | PTA_FXSR 
3324         | PTA_XSAVE | PTA_XSAVEOPT | PTA_FSGSBASE | PTA_RDRND
3325         | PTA_MOVBE},
3326       {"btver1", PROCESSOR_BTVER1, CPU_GENERIC,
3327         PTA_64BIT | PTA_MMX |  PTA_SSE  | PTA_SSE2 | PTA_SSE3
3328         | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16 | PTA_PRFCHW
3329         | PTA_FXSR | PTA_XSAVE},
3330       {"btver2", PROCESSOR_BTVER2, CPU_BTVER2,
3331         PTA_64BIT | PTA_MMX |  PTA_SSE  | PTA_SSE2 | PTA_SSE3
3332         | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16 | PTA_SSE4_1
3333         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX
3334         | PTA_BMI | PTA_F16C | PTA_MOVBE | PTA_PRFCHW
3335         | PTA_FXSR | PTA_XSAVE | PTA_XSAVEOPT},
3336
3337       {"generic", PROCESSOR_GENERIC, CPU_GENERIC,
3338         PTA_64BIT
3339         | PTA_HLE /* flags are only used for -march switch.  */ },
3340     };
3341
3342   /* -mrecip options.  */
3343   static struct
3344     {
3345       const char *string;           /* option name */
3346       unsigned int mask;            /* mask bits to set */
3347     }
3348   const recip_options[] =
3349     {
3350       { "all",       RECIP_MASK_ALL },
3351       { "none",      RECIP_MASK_NONE },
3352       { "div",       RECIP_MASK_DIV },
3353       { "sqrt",      RECIP_MASK_SQRT },
3354       { "vec-div",   RECIP_MASK_VEC_DIV },
3355       { "vec-sqrt",  RECIP_MASK_VEC_SQRT },
3356     };
3357
3358   int const pta_size = ARRAY_SIZE (processor_alias_table);
3359
3360   /* Set up prefix/suffix so the error messages refer to either the command
3361      line argument, or the attribute(target).  */
3362   if (main_args_p)
3363     {
3364       prefix = "-m";
3365       suffix = "";
3366       sw = "switch";
3367     }
3368   else
3369     {
3370       prefix = "option(\"";
3371       suffix = "\")";
3372       sw = "attribute";
3373     }
3374
3375   /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if
3376      TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false.  */
3377   if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
3378     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
3379 #ifdef TARGET_BI_ARCH
3380   else
3381     {
3382 #if TARGET_BI_ARCH == 1
3383       /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
3384          is on and OPTION_MASK_ABI_X32 is off.  We turn off
3385          OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
3386          -mx32.  */
3387       if (TARGET_X32_P (opts->x_ix86_isa_flags))
3388         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
3389 #else
3390       /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
3391          on and OPTION_MASK_ABI_64 is off.  We turn off
3392          OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
3393          -m64 or OPTION_MASK_CODE16 is turned on by -m16.  */
3394       if (TARGET_LP64_P (opts->x_ix86_isa_flags)
3395           || TARGET_16BIT_P (opts->x_ix86_isa_flags))
3396         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
3397 #endif
3398     }
3399 #endif
3400
3401   if (TARGET_X32_P (opts->x_ix86_isa_flags))
3402     {
3403       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
3404          OPTION_MASK_ABI_64 for TARGET_X32.  */
3405       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
3406       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
3407     }
3408   else if (TARGET_16BIT_P (opts->x_ix86_isa_flags))
3409     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ISA_64BIT
3410                                 | OPTION_MASK_ABI_X32
3411                                 | OPTION_MASK_ABI_64);
3412   else if (TARGET_LP64_P (opts->x_ix86_isa_flags))
3413     {
3414       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
3415          OPTION_MASK_ABI_X32 for TARGET_LP64.  */
3416       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
3417       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
3418     }
3419
3420 #ifdef SUBTARGET_OVERRIDE_OPTIONS
3421   SUBTARGET_OVERRIDE_OPTIONS;
3422 #endif
3423
3424 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
3425   SUBSUBTARGET_OVERRIDE_OPTIONS;
3426 #endif
3427
3428   /* -fPIC is the default for x86_64.  */
3429   if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags))
3430     opts->x_flag_pic = 2;
3431
3432   /* Need to check -mtune=generic first.  */
3433   if (opts->x_ix86_tune_string)
3434     {
3435       /* As special support for cross compilers we read -mtune=native
3436              as -mtune=generic.  With native compilers we won't see the
3437              -mtune=native, as it was changed by the driver.  */
3438       if (!strcmp (opts->x_ix86_tune_string, "native"))
3439         {
3440           opts->x_ix86_tune_string = "generic";
3441         }
3442       else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
3443         warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated; use "
3444                  "%stune=k8%s or %stune=generic%s instead as appropriate",
3445                  prefix, suffix, prefix, suffix, prefix, suffix);
3446     }
3447   else
3448     {
3449       if (opts->x_ix86_arch_string)
3450         opts->x_ix86_tune_string = opts->x_ix86_arch_string;
3451       if (!opts->x_ix86_tune_string)
3452         {
3453           opts->x_ix86_tune_string
3454             = processor_target_table[TARGET_CPU_DEFAULT].name;
3455           ix86_tune_defaulted = 1;
3456         }
3457
3458       /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
3459          or defaulted.  We need to use a sensible tune option.  */
3460       if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
3461         {
3462           opts->x_ix86_tune_string = "generic";
3463         }
3464     }
3465
3466   if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
3467       && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
3468     {
3469       /* rep; movq isn't available in 32-bit code.  */
3470       error ("-mstringop-strategy=rep_8byte not supported for 32-bit code");
3471       opts->x_ix86_stringop_alg = no_stringop;
3472     }
3473
3474   if (!opts->x_ix86_arch_string)
3475     opts->x_ix86_arch_string
3476       = TARGET_64BIT_P (opts->x_ix86_isa_flags)
3477         ? "x86-64" : SUBTARGET32_DEFAULT_CPU;
3478   else
3479     ix86_arch_specified = 1;
3480
3481   if (opts_set->x_ix86_pmode)
3482     {
3483       if ((TARGET_LP64_P (opts->x_ix86_isa_flags)
3484            && opts->x_ix86_pmode == PMODE_SI)
3485           || (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
3486                && opts->x_ix86_pmode == PMODE_DI))
3487         error ("address mode %qs not supported in the %s bit mode",
3488                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "short" : "long",
3489                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "64" : "32");
3490     }
3491   else
3492     opts->x_ix86_pmode = TARGET_LP64_P (opts->x_ix86_isa_flags)
3493                          ? PMODE_DI : PMODE_SI;
3494
3495   if (!opts_set->x_ix86_abi)
3496     opts->x_ix86_abi = DEFAULT_ABI;
3497
3498   /* For targets using ms ABI enable ms-extensions, if not
3499      explicit turned off.  For non-ms ABI we turn off this
3500      option.  */
3501   if (!opts_set->x_flag_ms_extensions)
3502     opts->x_flag_ms_extensions = (MS_ABI == DEFAULT_ABI);
3503
3504   if (opts_set->x_ix86_cmodel)
3505     {
3506       switch (opts->x_ix86_cmodel)
3507         {
3508         case CM_SMALL:
3509         case CM_SMALL_PIC:
3510           if (opts->x_flag_pic)
3511             opts->x_ix86_cmodel = CM_SMALL_PIC;
3512           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3513             error ("code model %qs not supported in the %s bit mode",
3514                    "small", "32");
3515           break;
3516
3517         case CM_MEDIUM:
3518         case CM_MEDIUM_PIC:
3519           if (opts->x_flag_pic)
3520             opts->x_ix86_cmodel = CM_MEDIUM_PIC;
3521           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3522             error ("code model %qs not supported in the %s bit mode",
3523                    "medium", "32");
3524           else if (TARGET_X32_P (opts->x_ix86_isa_flags))
3525             error ("code model %qs not supported in x32 mode",
3526                    "medium");
3527           break;
3528
3529         case CM_LARGE:
3530         case CM_LARGE_PIC:
3531           if (opts->x_flag_pic)
3532             opts->x_ix86_cmodel = CM_LARGE_PIC;
3533           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3534             error ("code model %qs not supported in the %s bit mode",
3535                    "large", "32");
3536           else if (TARGET_X32_P (opts->x_ix86_isa_flags))
3537             error ("code model %qs not supported in x32 mode",
3538                    "large");
3539           break;
3540
3541         case CM_32:
3542           if (opts->x_flag_pic)
3543             error ("code model %s does not support PIC mode", "32");
3544           if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3545             error ("code model %qs not supported in the %s bit mode",
3546                    "32", "64");
3547           break;
3548
3549         case CM_KERNEL:
3550           if (opts->x_flag_pic)
3551             {
3552               error ("code model %s does not support PIC mode", "kernel");
3553               opts->x_ix86_cmodel = CM_32;
3554             }
3555           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3556             error ("code model %qs not supported in the %s bit mode",
3557                    "kernel", "32");
3558           break;
3559
3560         default:
3561           gcc_unreachable ();
3562         }
3563     }
3564   else
3565     {
3566       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
3567          use of rip-relative addressing.  This eliminates fixups that
3568          would otherwise be needed if this object is to be placed in a
3569          DLL, and is essentially just as efficient as direct addressing.  */
3570       if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3571           && (TARGET_RDOS || TARGET_PECOFF))
3572         opts->x_ix86_cmodel = CM_MEDIUM_PIC, opts->x_flag_pic = 1;
3573       else if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3574         opts->x_ix86_cmodel = opts->x_flag_pic ? CM_SMALL_PIC : CM_SMALL;
3575       else
3576         opts->x_ix86_cmodel = CM_32;
3577     }
3578   if (TARGET_MACHO && opts->x_ix86_asm_dialect == ASM_INTEL)
3579     {
3580       error ("-masm=intel not supported in this configuration");
3581       opts->x_ix86_asm_dialect = ASM_ATT;
3582     }
3583   if ((TARGET_64BIT_P (opts->x_ix86_isa_flags) != 0)
3584       != ((opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
3585     sorry ("%i-bit mode not compiled in",
3586            (opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
3587
3588   for (i = 0; i < pta_size; i++)
3589     if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name))
3590       {
3591         ix86_schedule = processor_alias_table[i].schedule;
3592         ix86_arch = processor_alias_table[i].processor;
3593         /* Default cpu tuning to the architecture.  */
3594         ix86_tune = ix86_arch;
3595
3596         if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3597             && !(processor_alias_table[i].flags & PTA_64BIT))
3598           error ("CPU you selected does not support x86-64 "
3599                  "instruction set");
3600
3601         if (processor_alias_table[i].flags & PTA_MMX
3602             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
3603           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MMX;
3604         if (processor_alias_table[i].flags & PTA_3DNOW
3605             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
3606           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
3607         if (processor_alias_table[i].flags & PTA_3DNOW_A
3608             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
3609           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
3610         if (processor_alias_table[i].flags & PTA_SSE
3611             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
3612           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE;
3613         if (processor_alias_table[i].flags & PTA_SSE2
3614             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
3615           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
3616         if (processor_alias_table[i].flags & PTA_SSE3
3617             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
3618           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
3619         if (processor_alias_table[i].flags & PTA_SSSE3
3620             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
3621           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
3622         if (processor_alias_table[i].flags & PTA_SSE4_1
3623             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
3624           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
3625         if (processor_alias_table[i].flags & PTA_SSE4_2
3626             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
3627           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
3628         if (processor_alias_table[i].flags & PTA_AVX
3629             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
3630           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX;
3631         if (processor_alias_table[i].flags & PTA_AVX2
3632             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX2))
3633           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX2;
3634         if (processor_alias_table[i].flags & PTA_FMA
3635             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
3636           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA;
3637         if (processor_alias_table[i].flags & PTA_SSE4A
3638             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
3639           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
3640         if (processor_alias_table[i].flags & PTA_FMA4
3641             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA4))
3642           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA4;
3643         if (processor_alias_table[i].flags & PTA_XOP
3644             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XOP))
3645           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XOP;
3646         if (processor_alias_table[i].flags & PTA_LWP
3647             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LWP))
3648           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LWP;
3649         if (processor_alias_table[i].flags & PTA_ABM
3650             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
3651           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ABM;
3652         if (processor_alias_table[i].flags & PTA_BMI
3653             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_BMI))
3654           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_BMI;
3655         if (processor_alias_table[i].flags & (PTA_LZCNT | PTA_ABM)
3656             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LZCNT))
3657           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LZCNT;
3658         if (processor_alias_table[i].flags & PTA_TBM
3659             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_TBM))
3660           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_TBM;
3661         if (processor_alias_table[i].flags & PTA_BMI2
3662             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_BMI2))
3663           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_BMI2;
3664         if (processor_alias_table[i].flags & PTA_CX16
3665             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
3666           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CX16;
3667         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
3668             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
3669           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
3670         if (!(TARGET_64BIT_P (opts->x_ix86_isa_flags)
3671             && (processor_alias_table[i].flags & PTA_NO_SAHF))
3672             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
3673           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
3674         if (processor_alias_table[i].flags & PTA_MOVBE
3675             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MOVBE))
3676           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MOVBE;
3677         if (processor_alias_table[i].flags & PTA_AES
3678             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
3679           ix86_isa_flags |= OPTION_MASK_ISA_AES;
3680         if (processor_alias_table[i].flags & PTA_SHA
3681             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SHA))
3682           ix86_isa_flags |= OPTION_MASK_ISA_SHA;
3683         if (processor_alias_table[i].flags & PTA_PCLMUL
3684             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
3685           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
3686         if (processor_alias_table[i].flags & PTA_FSGSBASE
3687             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FSGSBASE))
3688           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FSGSBASE;
3689         if (processor_alias_table[i].flags & PTA_RDRND
3690             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RDRND))
3691           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RDRND;
3692         if (processor_alias_table[i].flags & PTA_F16C
3693             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_F16C))
3694           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_F16C;
3695         if (processor_alias_table[i].flags & PTA_RTM
3696             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RTM))
3697           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RTM;
3698         if (processor_alias_table[i].flags & PTA_HLE
3699             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_HLE))
3700           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_HLE;
3701         if (processor_alias_table[i].flags & PTA_PRFCHW
3702             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PRFCHW))
3703           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PRFCHW;
3704         if (processor_alias_table[i].flags & PTA_RDSEED
3705             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RDSEED))
3706           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RDSEED;
3707         if (processor_alias_table[i].flags & PTA_ADX
3708             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ADX))
3709           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ADX;
3710         if (processor_alias_table[i].flags & PTA_FXSR
3711             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FXSR))
3712           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FXSR;
3713         if (processor_alias_table[i].flags & PTA_XSAVE
3714             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVE))
3715           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVE;
3716         if (processor_alias_table[i].flags & PTA_XSAVEOPT
3717             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVEOPT))
3718           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVEOPT;
3719         if (processor_alias_table[i].flags & PTA_AVX512F
3720             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512F))
3721           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512F;
3722         if (processor_alias_table[i].flags & PTA_AVX512ER
3723             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512ER))
3724           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512ER;
3725         if (processor_alias_table[i].flags & PTA_AVX512PF
3726             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512PF))
3727           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512PF;
3728         if (processor_alias_table[i].flags & PTA_AVX512CD
3729             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512CD))
3730           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512CD;
3731         if (processor_alias_table[i].flags & PTA_PREFETCHWT1
3732             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PREFETCHWT1))
3733           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PREFETCHWT1;
3734         if (processor_alias_table[i].flags & PTA_PCOMMIT
3735             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PCOMMIT))
3736           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCOMMIT;
3737         if (processor_alias_table[i].flags & PTA_CLWB
3738             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CLWB))
3739           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CLWB;
3740         if (processor_alias_table[i].flags & PTA_CLFLUSHOPT
3741             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CLFLUSHOPT))
3742           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CLFLUSHOPT;
3743         if (processor_alias_table[i].flags & PTA_XSAVEC
3744             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVEC))
3745           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVEC;
3746         if (processor_alias_table[i].flags & PTA_XSAVES
3747             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVES))
3748           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVES;
3749         if (processor_alias_table[i].flags & PTA_AVX512DQ
3750             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512DQ))
3751           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512DQ;
3752         if (processor_alias_table[i].flags & PTA_AVX512BW
3753             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512BW))
3754           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512BW;
3755         if (processor_alias_table[i].flags & PTA_AVX512VL
3756             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512VL))
3757           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512VL;
3758         if (processor_alias_table[i].flags & PTA_MPX
3759             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MPX))
3760           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MPX;
3761         if (processor_alias_table[i].flags & PTA_AVX512VBMI
3762             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512VBMI))
3763           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512VBMI;
3764         if (processor_alias_table[i].flags & PTA_AVX512IFMA
3765             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512IFMA))
3766           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512IFMA;
3767         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
3768           x86_prefetch_sse = true;
3769
3770         break;
3771       }
3772
3773   if (TARGET_X32 && (opts->x_ix86_isa_flags & OPTION_MASK_ISA_MPX))
3774     error ("Intel MPX does not support x32");
3775
3776   if (TARGET_X32 && (ix86_isa_flags & OPTION_MASK_ISA_MPX))
3777     error ("Intel MPX does not support x32");
3778
3779   if (!strcmp (opts->x_ix86_arch_string, "generic"))
3780     error ("generic CPU can be used only for %stune=%s %s",
3781            prefix, suffix, sw);
3782   else if (!strcmp (opts->x_ix86_arch_string, "intel"))
3783     error ("intel CPU can be used only for %stune=%s %s",
3784            prefix, suffix, sw);
3785   else if (i == pta_size)
3786     error ("bad value (%s) for %sarch=%s %s",
3787            opts->x_ix86_arch_string, prefix, suffix, sw);
3788
3789   ix86_arch_mask = 1u << ix86_arch;
3790   for (i = 0; i < X86_ARCH_LAST; ++i)
3791     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3792
3793   for (i = 0; i < pta_size; i++)
3794     if (! strcmp (opts->x_ix86_tune_string, processor_alias_table[i].name))
3795       {
3796         ix86_schedule = processor_alias_table[i].schedule;
3797         ix86_tune = processor_alias_table[i].processor;
3798         if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3799           {
3800             if (!(processor_alias_table[i].flags & PTA_64BIT))
3801               {
3802                 if (ix86_tune_defaulted)
3803                   {
3804                     opts->x_ix86_tune_string = "x86-64";
3805                     for (i = 0; i < pta_size; i++)
3806                       if (! strcmp (opts->x_ix86_tune_string,
3807                                     processor_alias_table[i].name))
3808                         break;
3809                     ix86_schedule = processor_alias_table[i].schedule;
3810                     ix86_tune = processor_alias_table[i].processor;
3811                   }
3812                 else
3813                   error ("CPU you selected does not support x86-64 "
3814                          "instruction set");
3815               }
3816           }
3817         /* Intel CPUs have always interpreted SSE prefetch instructions as
3818            NOPs; so, we can enable SSE prefetch instructions even when
3819            -mtune (rather than -march) points us to a processor that has them.
3820            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
3821            higher processors.  */
3822         if (TARGET_CMOV
3823             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
3824           x86_prefetch_sse = true;
3825         break;
3826       }
3827
3828   if (ix86_tune_specified && i == pta_size)
3829     error ("bad value (%s) for %stune=%s %s",
3830            opts->x_ix86_tune_string, prefix, suffix, sw);
3831
3832   set_ix86_tune_features (ix86_tune, opts->x_ix86_dump_tunes);
3833
3834 #ifndef USE_IX86_FRAME_POINTER
3835 #define USE_IX86_FRAME_POINTER 0
3836 #endif
3837
3838 #ifndef USE_X86_64_FRAME_POINTER
3839 #define USE_X86_64_FRAME_POINTER 0
3840 #endif
3841
3842   /* Set the default values for switches whose default depends on TARGET_64BIT
3843      in case they weren't overwritten by command line options.  */
3844   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3845     {
3846       if (opts->x_optimize >= 1 && !opts_set->x_flag_omit_frame_pointer)
3847         opts->x_flag_omit_frame_pointer = !USE_X86_64_FRAME_POINTER;
3848       if (opts->x_flag_asynchronous_unwind_tables
3849           && !opts_set->x_flag_unwind_tables
3850           && TARGET_64BIT_MS_ABI)
3851         opts->x_flag_unwind_tables = 1;
3852       if (opts->x_flag_asynchronous_unwind_tables == 2)
3853         opts->x_flag_unwind_tables
3854           = opts->x_flag_asynchronous_unwind_tables = 1;
3855       if (opts->x_flag_pcc_struct_return == 2)
3856         opts->x_flag_pcc_struct_return = 0;
3857     }
3858   else
3859     {
3860       if (opts->x_optimize >= 1 && !opts_set->x_flag_omit_frame_pointer)
3861         opts->x_flag_omit_frame_pointer
3862           = !(USE_IX86_FRAME_POINTER || opts->x_optimize_size);
3863       if (opts->x_flag_asynchronous_unwind_tables == 2)
3864         opts->x_flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
3865       if (opts->x_flag_pcc_struct_return == 2)
3866         opts->x_flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
3867     }
3868
3869   ix86_tune_cost = processor_target_table[ix86_tune].cost;
3870   if (opts->x_optimize_size)
3871     ix86_cost = &ix86_size_cost;
3872   else
3873     ix86_cost = ix86_tune_cost;
3874
3875   /* Arrange to set up i386_stack_locals for all functions.  */
3876   init_machine_status = ix86_init_machine_status;
3877
3878   /* Validate -mregparm= value.  */
3879   if (opts_set->x_ix86_regparm)
3880     {
3881       if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3882         warning (0, "-mregparm is ignored in 64-bit mode");
3883       if (opts->x_ix86_regparm > REGPARM_MAX)
3884         {
3885           error ("-mregparm=%d is not between 0 and %d",
3886                  opts->x_ix86_regparm, REGPARM_MAX);
3887           opts->x_ix86_regparm = 0;
3888         }
3889     }
3890   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3891     opts->x_ix86_regparm = REGPARM_MAX;
3892
3893   /* Default align_* from the processor table.  */
3894   if (opts->x_align_loops == 0)
3895     {
3896       opts->x_align_loops = processor_target_table[ix86_tune].align_loop;
3897       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
3898     }
3899   if (opts->x_align_jumps == 0)
3900     {
3901       opts->x_align_jumps = processor_target_table[ix86_tune].align_jump;
3902       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
3903     }
3904   if (opts->x_align_functions == 0)
3905     {
3906       opts->x_align_functions = processor_target_table[ix86_tune].align_func;
3907     }
3908
3909   /* Provide default for -mbranch-cost= value.  */
3910   if (!opts_set->x_ix86_branch_cost)
3911     opts->x_ix86_branch_cost = ix86_cost->branch_cost;
3912
3913   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3914     {
3915       opts->x_target_flags
3916         |= TARGET_SUBTARGET64_DEFAULT & ~opts_set->x_target_flags;
3917
3918       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3919          explicitly disable any of these.  In particular, disabling SSE and
3920          MMX for kernel code is extremely useful.  */
3921       if (!ix86_arch_specified)
3922       opts->x_ix86_isa_flags
3923         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3924              | TARGET_SUBTARGET64_ISA_DEFAULT)
3925             & ~opts->x_ix86_isa_flags_explicit);
3926
3927       if (TARGET_RTD_P (opts->x_target_flags))
3928         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3929     }
3930   else
3931     {
3932       opts->x_target_flags
3933         |= TARGET_SUBTARGET32_DEFAULT & ~opts_set->x_target_flags;
3934
3935       if (!ix86_arch_specified)
3936         opts->x_ix86_isa_flags
3937           |= TARGET_SUBTARGET32_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit;
3938
3939       /* i386 ABI does not specify red zone.  It still makes sense to use it
3940          when programmer takes care to stack from being destroyed.  */
3941       if (!(opts_set->x_target_flags & MASK_NO_RED_ZONE))
3942         opts->x_target_flags |= MASK_NO_RED_ZONE;
3943     }
3944
3945   /* Keep nonleaf frame pointers.  */
3946   if (opts->x_flag_omit_frame_pointer)
3947     opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3948   else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags))
3949     opts->x_flag_omit_frame_pointer = 1;
3950
3951   /* If we're doing fast math, we don't care about comparison order
3952      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3953   if (opts->x_flag_finite_math_only)
3954     opts->x_target_flags &= ~MASK_IEEE_FP;
3955
3956   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3957      since the insns won't need emulation.  */
3958   if (ix86_tune_features [X86_TUNE_ALWAYS_FANCY_MATH_387])
3959     opts->x_target_flags &= ~MASK_NO_FANCY_MATH_387;
3960
3961   /* Likewise, if the target doesn't have a 387, or we've specified
3962      software floating point, don't use 387 inline intrinsics.  */
3963   if (!TARGET_80387_P (opts->x_target_flags))
3964     opts->x_target_flags |= MASK_NO_FANCY_MATH_387;
3965
3966   /* Turn on MMX builtins for -msse.  */
3967   if (TARGET_SSE_P (opts->x_ix86_isa_flags))
3968     opts->x_ix86_isa_flags
3969       |= OPTION_MASK_ISA_MMX & ~opts->x_ix86_isa_flags_explicit;
3970
3971   /* Enable SSE prefetch.  */
3972   if (TARGET_SSE_P (opts->x_ix86_isa_flags)
3973       || (TARGET_PRFCHW && !TARGET_3DNOW_P (opts->x_ix86_isa_flags)))
3974     x86_prefetch_sse = true;
3975
3976   /* Enable prefetch{,w} instructions for -m3dnow and -mprefetchwt1.  */
3977   if (TARGET_3DNOW_P (opts->x_ix86_isa_flags)
3978       || TARGET_PREFETCHWT1_P (opts->x_ix86_isa_flags))
3979     opts->x_ix86_isa_flags
3980       |= OPTION_MASK_ISA_PRFCHW & ~opts->x_ix86_isa_flags_explicit;
3981
3982   /* Enable popcnt instruction for -msse4.2 or -mabm.  */
3983   if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags)
3984       || TARGET_ABM_P (opts->x_ix86_isa_flags))
3985     opts->x_ix86_isa_flags
3986       |= OPTION_MASK_ISA_POPCNT & ~opts->x_ix86_isa_flags_explicit;
3987
3988   /* Enable lzcnt instruction for -mabm.  */
3989   if (TARGET_ABM_P(opts->x_ix86_isa_flags))
3990     opts->x_ix86_isa_flags
3991       |= OPTION_MASK_ISA_LZCNT & ~opts->x_ix86_isa_flags_explicit;
3992
3993   /* Validate -mpreferred-stack-boundary= value or default it to
3994      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3995   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3996   if (opts_set->x_ix86_preferred_stack_boundary_arg)
3997     {
3998       int min = (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3999                  ? (TARGET_SSE_P (opts->x_ix86_isa_flags) ? 4 : 3) : 2);
4000       int max = (TARGET_SEH ? 4 : 12);
4001
4002       if (opts->x_ix86_preferred_stack_boundary_arg < min
4003           || opts->x_ix86_preferred_stack_boundary_arg > max)
4004         {
4005           if (min == max)
4006             error ("-mpreferred-stack-boundary is not supported "
4007                    "for this target");
4008           else
4009             error ("-mpreferred-stack-boundary=%d is not between %d and %d",
4010                    opts->x_ix86_preferred_stack_boundary_arg, min, max);
4011         }
4012       else
4013         ix86_preferred_stack_boundary
4014           = (1 << opts->x_ix86_preferred_stack_boundary_arg) * BITS_PER_UNIT;
4015     }
4016
4017   /* Set the default value for -mstackrealign.  */
4018   if (opts->x_ix86_force_align_arg_pointer == -1)
4019     opts->x_ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
4020
4021   ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
4022
4023   /* Validate -mincoming-stack-boundary= value or default it to
4024      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
4025   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
4026   if (opts_set->x_ix86_incoming_stack_boundary_arg)
4027     {
4028       if (opts->x_ix86_incoming_stack_boundary_arg
4029           < (TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 4 : 2)
4030           || opts->x_ix86_incoming_stack_boundary_arg > 12)
4031         error ("-mincoming-stack-boundary=%d is not between %d and 12",
4032                opts->x_ix86_incoming_stack_boundary_arg,
4033                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 4 : 2);
4034       else
4035         {
4036           ix86_user_incoming_stack_boundary
4037             = (1 << opts->x_ix86_incoming_stack_boundary_arg) * BITS_PER_UNIT;
4038           ix86_incoming_stack_boundary
4039             = ix86_user_incoming_stack_boundary;
4040         }
4041     }
4042
4043 #ifndef NO_PROFILE_COUNTERS
4044   if (flag_nop_mcount)
4045     error ("-mnop-mcount is not compatible with this target");
4046 #endif
4047   if (flag_nop_mcount && flag_pic)
4048     error ("-mnop-mcount is not implemented for -fPIC");
4049
4050   /* Accept -msseregparm only if at least SSE support is enabled.  */
4051   if (TARGET_SSEREGPARM_P (opts->x_target_flags)
4052       && ! TARGET_SSE_P (opts->x_ix86_isa_flags))
4053     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
4054
4055   if (opts_set->x_ix86_fpmath)
4056     {
4057       if (opts->x_ix86_fpmath & FPMATH_SSE)
4058         {
4059           if (!TARGET_SSE_P (opts->x_ix86_isa_flags))
4060             {
4061               warning (0, "SSE instruction set disabled, using 387 arithmetics");
4062               opts->x_ix86_fpmath = FPMATH_387;
4063             }
4064           else if ((opts->x_ix86_fpmath & FPMATH_387)
4065                    && !TARGET_80387_P (opts->x_target_flags))
4066             {
4067               warning (0, "387 instruction set disabled, using SSE arithmetics");
4068               opts->x_ix86_fpmath = FPMATH_SSE;
4069             }
4070         }
4071     }
4072   /* For all chips supporting SSE2, -mfpmath=sse performs better than
4073      fpmath=387.  The second is however default at many targets since the
4074      extra 80bit precision of temporaries is considered to be part of ABI.
4075      Overwrite the default at least for -ffast-math. 
4076      TODO: -mfpmath=both seems to produce same performing code with bit
4077      smaller binaries.  It is however not clear if register allocation is
4078      ready for this setting.
4079      Also -mfpmath=387 is overall a lot more compact (bout 4-5%) than SSE
4080      codegen.  We may switch to 387 with -ffast-math for size optimized
4081      functions. */
4082   else if (fast_math_flags_set_p (&global_options)
4083            && TARGET_SSE2_P (opts->x_ix86_isa_flags))
4084     opts->x_ix86_fpmath = FPMATH_SSE;
4085   else
4086     opts->x_ix86_fpmath = TARGET_FPMATH_DEFAULT_P (opts->x_ix86_isa_flags);
4087
4088   /* If the i387 is disabled, then do not return values in it. */
4089   if (!TARGET_80387_P (opts->x_target_flags))
4090     opts->x_target_flags &= ~MASK_FLOAT_RETURNS;
4091
4092   /* Use external vectorized library in vectorizing intrinsics.  */
4093   if (opts_set->x_ix86_veclibabi_type)
4094     switch (opts->x_ix86_veclibabi_type)
4095       {
4096       case ix86_veclibabi_type_svml:
4097         ix86_veclib_handler = ix86_veclibabi_svml;
4098         break;
4099
4100       case ix86_veclibabi_type_acml:
4101         ix86_veclib_handler = ix86_veclibabi_acml;
4102         break;
4103
4104       default:
4105         gcc_unreachable ();
4106       }
4107
4108   if (ix86_tune_features [X86_TUNE_ACCUMULATE_OUTGOING_ARGS]
4109       && !(opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)
4110       && !opts->x_optimize_size)
4111     opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
4112
4113   /* If stack probes are required, the space used for large function
4114      arguments on the stack must also be probed, so enable
4115      -maccumulate-outgoing-args so this happens in the prologue.  */
4116   if (TARGET_STACK_PROBE_P (opts->x_target_flags)
4117       && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
4118     {
4119       if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)
4120         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
4121                  "for correctness", prefix, suffix);
4122       opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
4123     }
4124
4125   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
4126   {
4127     char *p;
4128     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
4129     p = strchr (internal_label_prefix, 'X');
4130     internal_label_prefix_len = p - internal_label_prefix;
4131     *p = '\0';
4132   }
4133
4134   /* When scheduling description is not available, disable scheduler pass
4135      so it won't slow down the compilation and make x87 code slower.  */
4136   if (!TARGET_SCHEDULE)
4137     opts->x_flag_schedule_insns_after_reload = opts->x_flag_schedule_insns = 0;
4138
4139   maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
4140                          ix86_tune_cost->simultaneous_prefetches,
4141                          opts->x_param_values,
4142                          opts_set->x_param_values);
4143   maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
4144                          ix86_tune_cost->prefetch_block,
4145                          opts->x_param_values,
4146                          opts_set->x_param_values);
4147   maybe_set_param_value (PARAM_L1_CACHE_SIZE,
4148                          ix86_tune_cost->l1_cache_size,
4149                          opts->x_param_values,
4150                          opts_set->x_param_values);
4151   maybe_set_param_value (PARAM_L2_CACHE_SIZE,
4152                          ix86_tune_cost->l2_cache_size,
4153                          opts->x_param_values,
4154                          opts_set->x_param_values);
4155
4156   /* Enable sw prefetching at -O3 for CPUS that prefetching is helpful.  */
4157   if (opts->x_flag_prefetch_loop_arrays < 0
4158       && HAVE_prefetch
4159       && (opts->x_optimize >= 3 || opts->x_flag_profile_use)
4160       && TARGET_SOFTWARE_PREFETCHING_BENEFICIAL)
4161     opts->x_flag_prefetch_loop_arrays = 1;
4162
4163   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
4164      can be opts->x_optimized to ap = __builtin_next_arg (0).  */
4165   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && !opts->x_flag_split_stack)
4166     targetm.expand_builtin_va_start = NULL;
4167
4168   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
4169     {
4170       ix86_gen_leave = gen_leave_rex64;
4171       if (Pmode == DImode)
4172         {
4173           ix86_gen_tls_global_dynamic_64 = gen_tls_global_dynamic_64_di;
4174           ix86_gen_tls_local_dynamic_base_64
4175             = gen_tls_local_dynamic_base_64_di;
4176         }
4177       else
4178         {
4179           ix86_gen_tls_global_dynamic_64 = gen_tls_global_dynamic_64_si;
4180           ix86_gen_tls_local_dynamic_base_64
4181             = gen_tls_local_dynamic_base_64_si;
4182         }
4183     }
4184   else
4185     ix86_gen_leave = gen_leave;
4186
4187   if (Pmode == DImode)
4188     {
4189       ix86_gen_add3 = gen_adddi3;
4190       ix86_gen_sub3 = gen_subdi3;
4191       ix86_gen_sub3_carry = gen_subdi3_carry;
4192       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
4193       ix86_gen_andsp = gen_anddi3;
4194       ix86_gen_allocate_stack_worker = gen_allocate_stack_worker_probe_di;
4195       ix86_gen_adjust_stack_and_probe = gen_adjust_stack_and_probedi;
4196       ix86_gen_probe_stack_range = gen_probe_stack_rangedi;
4197       ix86_gen_monitor = gen_sse3_monitor_di;
4198     }
4199   else
4200     {
4201       ix86_gen_add3 = gen_addsi3;
4202       ix86_gen_sub3 = gen_subsi3;
4203       ix86_gen_sub3_carry = gen_subsi3_carry;
4204       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
4205       ix86_gen_andsp = gen_andsi3;
4206       ix86_gen_allocate_stack_worker = gen_allocate_stack_worker_probe_si;
4207       ix86_gen_adjust_stack_and_probe = gen_adjust_stack_and_probesi;
4208       ix86_gen_probe_stack_range = gen_probe_stack_rangesi;
4209       ix86_gen_monitor = gen_sse3_monitor_si;
4210     }
4211
4212 #ifdef USE_IX86_CLD
4213   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
4214   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
4215     opts->x_target_flags |= MASK_CLD & ~opts_set->x_target_flags;
4216 #endif
4217
4218   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && opts->x_flag_pic)
4219     {
4220       if (opts->x_flag_fentry > 0)
4221         sorry ("-mfentry isn%'t supported for 32-bit in combination "
4222                "with -fpic");
4223       opts->x_flag_fentry = 0;
4224     }
4225   else if (TARGET_SEH)
4226     {
4227       if (opts->x_flag_fentry == 0)
4228         sorry ("-mno-fentry isn%'t compatible with SEH");
4229       opts->x_flag_fentry = 1;
4230     }
4231   else if (opts->x_flag_fentry < 0)
4232    {
4233 #if defined(PROFILE_BEFORE_PROLOGUE)
4234      opts->x_flag_fentry = 1;
4235 #else
4236      opts->x_flag_fentry = 0;
4237 #endif
4238    }
4239
4240   /* When not opts->x_optimize for size, enable vzeroupper optimization for
4241      TARGET_AVX with -fexpensive-optimizations and split 32-byte
4242      AVX unaligned load/store.  */
4243   if (!opts->x_optimize_size)
4244     {
4245       if (flag_expensive_optimizations
4246           && !(opts_set->x_target_flags & MASK_VZEROUPPER))
4247         opts->x_target_flags |= MASK_VZEROUPPER;
4248       if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL]
4249           && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_LOAD))
4250         opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_LOAD;
4251       if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL]
4252           && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_STORE))
4253         opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_STORE;
4254       /* Enable 128-bit AVX instruction generation
4255          for the auto-vectorizer.  */
4256       if (TARGET_AVX128_OPTIMAL
4257           && !(opts_set->x_target_flags & MASK_PREFER_AVX128))
4258         opts->x_target_flags |= MASK_PREFER_AVX128;
4259     }
4260
4261   if (opts->x_ix86_recip_name)
4262     {
4263       char *p = ASTRDUP (opts->x_ix86_recip_name);
4264       char *q;
4265       unsigned int mask, i;
4266       bool invert;
4267
4268       while ((q = strtok (p, ",")) != NULL)
4269         {
4270           p = NULL;
4271           if (*q == '!')
4272             {
4273               invert = true;
4274               q++;
4275             }
4276           else
4277             invert = false;
4278
4279           if (!strcmp (q, "default"))
4280             mask = RECIP_MASK_ALL;
4281           else
4282             {
4283               for (i = 0; i < ARRAY_SIZE (recip_options); i++)
4284                 if (!strcmp (q, recip_options[i].string))
4285                   {
4286                     mask = recip_options[i].mask;
4287                     break;
4288                   }
4289
4290               if (i == ARRAY_SIZE (recip_options))
4291                 {
4292                   error ("unknown option for -mrecip=%s", q);
4293                   invert = false;
4294                   mask = RECIP_MASK_NONE;
4295                 }
4296             }
4297
4298           opts->x_recip_mask_explicit |= mask;
4299           if (invert)
4300             opts->x_recip_mask &= ~mask;
4301           else
4302             opts->x_recip_mask |= mask;
4303         }
4304     }
4305
4306   if (TARGET_RECIP_P (opts->x_target_flags))
4307     opts->x_recip_mask |= RECIP_MASK_ALL & ~opts->x_recip_mask_explicit;
4308   else if (opts_set->x_target_flags & MASK_RECIP)
4309     opts->x_recip_mask &= ~(RECIP_MASK_ALL & ~opts->x_recip_mask_explicit);
4310
4311   /* Default long double to 64-bit for 32-bit Bionic and to __float128
4312      for 64-bit Bionic.  */
4313   if (TARGET_HAS_BIONIC
4314       && !(opts_set->x_target_flags
4315            & (MASK_LONG_DOUBLE_64 | MASK_LONG_DOUBLE_128)))
4316     opts->x_target_flags |= (TARGET_64BIT
4317                              ? MASK_LONG_DOUBLE_128
4318                              : MASK_LONG_DOUBLE_64);
4319
4320   /* Only one of them can be active.  */
4321   gcc_assert ((opts->x_target_flags & MASK_LONG_DOUBLE_64) == 0
4322               || (opts->x_target_flags & MASK_LONG_DOUBLE_128) == 0);
4323
4324   /* Save the initial options in case the user does function specific
4325      options.  */
4326   if (main_args_p)
4327     target_option_default_node = target_option_current_node
4328       = build_target_option_node (opts);
4329
4330   /* Handle stack protector */
4331   if (!opts_set->x_ix86_stack_protector_guard)
4332     opts->x_ix86_stack_protector_guard
4333       = TARGET_HAS_BIONIC ? SSP_GLOBAL : SSP_TLS;
4334
4335   /* Handle -mmemcpy-strategy= and -mmemset-strategy=  */
4336   if (opts->x_ix86_tune_memcpy_strategy)
4337     {
4338       char *str = xstrdup (opts->x_ix86_tune_memcpy_strategy);
4339       ix86_parse_stringop_strategy_string (str, false);
4340       free (str);
4341     }
4342
4343   if (opts->x_ix86_tune_memset_strategy)
4344     {
4345       char *str = xstrdup (opts->x_ix86_tune_memset_strategy);
4346       ix86_parse_stringop_strategy_string (str, true);
4347       free (str);
4348     }
4349 }
4350
4351 /* Implement the TARGET_OPTION_OVERRIDE hook.  */
4352
4353 static void
4354 ix86_option_override (void)
4355 {
4356   opt_pass *pass_insert_vzeroupper = make_pass_insert_vzeroupper (g);
4357   struct register_pass_info insert_vzeroupper_info
4358     = { pass_insert_vzeroupper, "reload",
4359         1, PASS_POS_INSERT_AFTER
4360       };
4361
4362   ix86_option_override_internal (true, &global_options, &global_options_set);
4363
4364
4365   /* This needs to be done at start up.  It's convenient to do it here.  */
4366   register_pass (&insert_vzeroupper_info);
4367 }
4368
4369 /* Implement the TARGET_OFFLOAD_OPTIONS hook.  */
4370 static char *
4371 ix86_offload_options (void)
4372 {
4373   if (TARGET_LP64)
4374     return xstrdup ("-foffload-abi=lp64");
4375   return xstrdup ("-foffload-abi=ilp32");
4376 }
4377
4378 /* Update register usage after having seen the compiler flags.  */
4379
4380 static void
4381 ix86_conditional_register_usage (void)
4382 {
4383   int i, c_mask;
4384   unsigned int j;
4385
4386   /* The PIC register, if it exists, is fixed.  */
4387   j = PIC_OFFSET_TABLE_REGNUM;
4388   if (j != INVALID_REGNUM)
4389     fixed_regs[j] = call_used_regs[j] = 1;
4390
4391   /* For 32-bit targets, squash the REX registers.  */
4392   if (! TARGET_64BIT)
4393     {
4394       for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
4395         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4396       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
4397         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4398       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
4399         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4400     }
4401
4402   /*  See the definition of CALL_USED_REGISTERS in i386.h.  */
4403   c_mask = (TARGET_64BIT_MS_ABI ? (1 << 3)
4404             : TARGET_64BIT ? (1 << 2)
4405             : (1 << 1));
4406   
4407   CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
4408
4409   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4410     {
4411       /* Set/reset conditionally defined registers from
4412          CALL_USED_REGISTERS initializer.  */
4413       if (call_used_regs[i] > 1)
4414         call_used_regs[i] = !!(call_used_regs[i] & c_mask);
4415
4416       /* Calculate registers of CLOBBERED_REGS register set
4417          as call used registers from GENERAL_REGS register set.  */
4418       if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
4419           && call_used_regs[i])
4420         SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
4421     }
4422
4423   /* If MMX is disabled, squash the registers.  */
4424   if (! TARGET_MMX)
4425     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4426       if (TEST_HARD_REG_BIT (reg_class_contents[(int)MMX_REGS], i))
4427         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4428
4429   /* If SSE is disabled, squash the registers.  */
4430   if (! TARGET_SSE)
4431     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4432       if (TEST_HARD_REG_BIT (reg_class_contents[(int)SSE_REGS], i))
4433         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4434
4435   /* If the FPU is disabled, squash the registers.  */
4436   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
4437     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4438       if (TEST_HARD_REG_BIT (reg_class_contents[(int)FLOAT_REGS], i))
4439         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4440
4441   /* If AVX512F is disabled, squash the registers.  */
4442   if (! TARGET_AVX512F)
4443     {
4444       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
4445         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4446
4447       for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
4448         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4449     }
4450
4451   /* If MPX is disabled, squash the registers.  */
4452   if (! TARGET_MPX)
4453     for (i = FIRST_BND_REG; i <= LAST_BND_REG; i++)
4454       fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4455 }
4456
4457 \f
4458 /* Save the current options */
4459
4460 static void
4461 ix86_function_specific_save (struct cl_target_option *ptr,
4462                              struct gcc_options *opts)
4463 {
4464   ptr->arch = ix86_arch;
4465   ptr->schedule = ix86_schedule;
4466   ptr->tune = ix86_tune;
4467   ptr->branch_cost = ix86_branch_cost;
4468   ptr->tune_defaulted = ix86_tune_defaulted;
4469   ptr->arch_specified = ix86_arch_specified;
4470   ptr->x_ix86_isa_flags_explicit = opts->x_ix86_isa_flags_explicit;
4471   ptr->x_ix86_target_flags_explicit = opts->x_ix86_target_flags_explicit;
4472   ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit;
4473   ptr->x_ix86_arch_string = opts->x_ix86_arch_string;
4474   ptr->x_ix86_tune_string = opts->x_ix86_tune_string;
4475   ptr->x_ix86_cmodel = opts->x_ix86_cmodel;
4476   ptr->x_ix86_abi = opts->x_ix86_abi;
4477   ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect;
4478   ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost;
4479   ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes;
4480   ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer;
4481   ptr->x_ix86_force_drap = opts->x_ix86_force_drap;
4482   ptr->x_ix86_incoming_stack_boundary_arg = opts->x_ix86_incoming_stack_boundary_arg;
4483   ptr->x_ix86_pmode = opts->x_ix86_pmode;
4484   ptr->x_ix86_preferred_stack_boundary_arg = opts->x_ix86_preferred_stack_boundary_arg;
4485   ptr->x_ix86_recip_name = opts->x_ix86_recip_name;
4486   ptr->x_ix86_regparm = opts->x_ix86_regparm;
4487   ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold;
4488   ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx;
4489   ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard;
4490   ptr->x_ix86_stringop_alg = opts->x_ix86_stringop_alg;
4491   ptr->x_ix86_tls_dialect = opts->x_ix86_tls_dialect;
4492   ptr->x_ix86_tune_ctrl_string = opts->x_ix86_tune_ctrl_string;
4493   ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy;
4494   ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy;
4495   ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default;
4496   ptr->x_ix86_veclibabi_type = opts->x_ix86_veclibabi_type;
4497
4498   /* The fields are char but the variables are not; make sure the
4499      values fit in the fields.  */
4500   gcc_assert (ptr->arch == ix86_arch);
4501   gcc_assert (ptr->schedule == ix86_schedule);
4502   gcc_assert (ptr->tune == ix86_tune);
4503   gcc_assert (ptr->branch_cost == ix86_branch_cost);
4504 }
4505
4506 /* Restore the current options */
4507
4508 static void
4509 ix86_function_specific_restore (struct gcc_options *opts,
4510                                 struct cl_target_option *ptr)
4511 {
4512   enum processor_type old_tune = ix86_tune;
4513   enum processor_type old_arch = ix86_arch;
4514   unsigned int ix86_arch_mask;
4515   int i;
4516
4517   /* We don't change -fPIC.  */
4518   opts->x_flag_pic = flag_pic;
4519
4520   ix86_arch = (enum processor_type) ptr->arch;
4521   ix86_schedule = (enum attr_cpu) ptr->schedule;
4522   ix86_tune = (enum processor_type) ptr->tune;
4523   opts->x_ix86_branch_cost = ptr->branch_cost;
4524   ix86_tune_defaulted = ptr->tune_defaulted;
4525   ix86_arch_specified = ptr->arch_specified;
4526   opts->x_ix86_isa_flags_explicit = ptr->x_ix86_isa_flags_explicit;
4527   opts->x_ix86_target_flags_explicit = ptr->x_ix86_target_flags_explicit;
4528   opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit;
4529   opts->x_ix86_arch_string = ptr->x_ix86_arch_string;
4530   opts->x_ix86_tune_string = ptr->x_ix86_tune_string;
4531   opts->x_ix86_cmodel = ptr->x_ix86_cmodel;
4532   opts->x_ix86_abi = ptr->x_ix86_abi;
4533   opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect;
4534   opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost;
4535   opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes;
4536   opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer;
4537   opts->x_ix86_force_drap = ptr->x_ix86_force_drap;
4538   opts->x_ix86_incoming_stack_boundary_arg = ptr->x_ix86_incoming_stack_boundary_arg;
4539   opts->x_ix86_pmode = ptr->x_ix86_pmode;
4540   opts->x_ix86_preferred_stack_boundary_arg = ptr->x_ix86_preferred_stack_boundary_arg;
4541   opts->x_ix86_recip_name = ptr->x_ix86_recip_name;
4542   opts->x_ix86_regparm = ptr->x_ix86_regparm;
4543   opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold;
4544   opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx;
4545   opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard;
4546   opts->x_ix86_stringop_alg = ptr->x_ix86_stringop_alg;
4547   opts->x_ix86_tls_dialect = ptr->x_ix86_tls_dialect;
4548   opts->x_ix86_tune_ctrl_string = ptr->x_ix86_tune_ctrl_string;
4549   opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy;
4550   opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy;
4551   opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default;
4552   opts->x_ix86_veclibabi_type = ptr->x_ix86_veclibabi_type;
4553
4554   /* Recreate the arch feature tests if the arch changed */
4555   if (old_arch != ix86_arch)
4556     {
4557       ix86_arch_mask = 1u << ix86_arch;
4558       for (i = 0; i < X86_ARCH_LAST; ++i)
4559         ix86_arch_features[i]
4560           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
4561     }
4562
4563   /* Recreate the tune optimization tests */
4564   if (old_tune != ix86_tune)
4565     set_ix86_tune_features (ix86_tune, false);
4566 }
4567
4568 /* Print the current options */
4569
4570 static void
4571 ix86_function_specific_print (FILE *file, int indent,
4572                               struct cl_target_option *ptr)
4573 {
4574   char *target_string
4575     = ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_target_flags,
4576                           NULL, NULL, ptr->x_ix86_fpmath, false);
4577
4578   gcc_assert (ptr->arch < PROCESSOR_max);
4579   fprintf (file, "%*sarch = %d (%s)\n",
4580            indent, "",
4581            ptr->arch, processor_target_table[ptr->arch].name);
4582
4583   gcc_assert (ptr->tune < PROCESSOR_max);
4584   fprintf (file, "%*stune = %d (%s)\n",
4585            indent, "",
4586            ptr->tune, processor_target_table[ptr->tune].name);
4587
4588   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
4589
4590   if (target_string)
4591     {
4592       fprintf (file, "%*s%s\n", indent, "", target_string);
4593       free (target_string);
4594     }
4595 }
4596
4597 \f
4598 /* Inner function to process the attribute((target(...))), take an argument and
4599    set the current options from the argument. If we have a list, recursively go
4600    over the list.  */
4601
4602 static bool
4603 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
4604                                      struct gcc_options *opts,
4605                                      struct gcc_options *opts_set,
4606                                      struct gcc_options *enum_opts_set)
4607 {
4608   char *next_optstr;
4609   bool ret = true;
4610
4611 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
4612 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
4613 #define IX86_ATTR_ENUM(S,O)  { S, sizeof (S)-1, ix86_opt_enum, O, 0 }
4614 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
4615 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
4616
4617   enum ix86_opt_type
4618   {
4619     ix86_opt_unknown,
4620     ix86_opt_yes,
4621     ix86_opt_no,
4622     ix86_opt_str,
4623     ix86_opt_enum,
4624     ix86_opt_isa
4625   };
4626
4627   static const struct
4628   {
4629     const char *string;
4630     size_t len;
4631     enum ix86_opt_type type;
4632     int opt;
4633     int mask;
4634   } attrs[] = {
4635     /* isa options */
4636     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
4637     IX86_ATTR_ISA ("abm",       OPT_mabm),
4638     IX86_ATTR_ISA ("bmi",       OPT_mbmi),
4639     IX86_ATTR_ISA ("bmi2",      OPT_mbmi2),
4640     IX86_ATTR_ISA ("lzcnt",     OPT_mlzcnt),
4641     IX86_ATTR_ISA ("tbm",       OPT_mtbm),
4642     IX86_ATTR_ISA ("aes",       OPT_maes),
4643     IX86_ATTR_ISA ("sha",       OPT_msha),
4644     IX86_ATTR_ISA ("avx",       OPT_mavx),
4645     IX86_ATTR_ISA ("avx2",      OPT_mavx2),
4646     IX86_ATTR_ISA ("avx512f",   OPT_mavx512f),
4647     IX86_ATTR_ISA ("avx512pf",  OPT_mavx512pf),
4648     IX86_ATTR_ISA ("avx512er",  OPT_mavx512er),
4649     IX86_ATTR_ISA ("avx512cd",  OPT_mavx512cd),
4650     IX86_ATTR_ISA ("avx512dq",  OPT_mavx512dq),
4651     IX86_ATTR_ISA ("avx512bw",  OPT_mavx512bw),
4652     IX86_ATTR_ISA ("avx512vl",  OPT_mavx512vl),
4653     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
4654     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
4655     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
4656     IX86_ATTR_ISA ("sse",       OPT_msse),
4657     IX86_ATTR_ISA ("sse2",      OPT_msse2),
4658     IX86_ATTR_ISA ("sse3",      OPT_msse3),
4659     IX86_ATTR_ISA ("sse4",      OPT_msse4),
4660     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
4661     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
4662     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
4663     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
4664     IX86_ATTR_ISA ("fma4",      OPT_mfma4),
4665     IX86_ATTR_ISA ("fma",       OPT_mfma),
4666     IX86_ATTR_ISA ("xop",       OPT_mxop),
4667     IX86_ATTR_ISA ("lwp",       OPT_mlwp),
4668     IX86_ATTR_ISA ("fsgsbase",  OPT_mfsgsbase),
4669     IX86_ATTR_ISA ("rdrnd",     OPT_mrdrnd),
4670     IX86_ATTR_ISA ("f16c",      OPT_mf16c),
4671     IX86_ATTR_ISA ("rtm",       OPT_mrtm),
4672     IX86_ATTR_ISA ("hle",       OPT_mhle),
4673     IX86_ATTR_ISA ("prfchw",    OPT_mprfchw),
4674     IX86_ATTR_ISA ("rdseed",    OPT_mrdseed),
4675     IX86_ATTR_ISA ("adx",       OPT_madx),
4676     IX86_ATTR_ISA ("fxsr",      OPT_mfxsr),
4677     IX86_ATTR_ISA ("xsave",     OPT_mxsave),
4678     IX86_ATTR_ISA ("xsaveopt",  OPT_mxsaveopt),
4679     IX86_ATTR_ISA ("prefetchwt1", OPT_mprefetchwt1),
4680     IX86_ATTR_ISA ("clflushopt",        OPT_mclflushopt),
4681     IX86_ATTR_ISA ("xsavec",    OPT_mxsavec),
4682     IX86_ATTR_ISA ("xsaves",    OPT_mxsaves),
4683     IX86_ATTR_ISA ("avx512vbmi",        OPT_mavx512vbmi),
4684     IX86_ATTR_ISA ("avx512ifma",        OPT_mavx512ifma),
4685     IX86_ATTR_ISA ("clwb",      OPT_mclwb),
4686     IX86_ATTR_ISA ("pcommit",   OPT_mpcommit),
4687
4688     /* enum options */
4689     IX86_ATTR_ENUM ("fpmath=",  OPT_mfpmath_),
4690
4691     /* string options */
4692     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
4693     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
4694
4695     /* flag options */
4696     IX86_ATTR_YES ("cld",
4697                    OPT_mcld,
4698                    MASK_CLD),
4699
4700     IX86_ATTR_NO ("fancy-math-387",
4701                   OPT_mfancy_math_387,
4702                   MASK_NO_FANCY_MATH_387),
4703
4704     IX86_ATTR_YES ("ieee-fp",
4705                    OPT_mieee_fp,
4706                    MASK_IEEE_FP),
4707
4708     IX86_ATTR_YES ("inline-all-stringops",
4709                    OPT_minline_all_stringops,
4710                    MASK_INLINE_ALL_STRINGOPS),
4711
4712     IX86_ATTR_YES ("inline-stringops-dynamically",
4713                    OPT_minline_stringops_dynamically,
4714                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
4715
4716     IX86_ATTR_NO ("align-stringops",
4717                   OPT_mno_align_stringops,
4718                   MASK_NO_ALIGN_STRINGOPS),
4719
4720     IX86_ATTR_YES ("recip",
4721                    OPT_mrecip,
4722                    MASK_RECIP),
4723
4724   };
4725
4726   /* If this is a list, recurse to get the options.  */
4727   if (TREE_CODE (args) == TREE_LIST)
4728     {
4729       bool ret = true;
4730
4731       for (; args; args = TREE_CHAIN (args))
4732         if (TREE_VALUE (args)
4733             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args),
4734                                                      p_strings, opts, opts_set,
4735                                                      enum_opts_set))
4736           ret = false;
4737
4738       return ret;
4739     }
4740
4741   else if (TREE_CODE (args) != STRING_CST)
4742     {
4743       error ("attribute %<target%> argument not a string");
4744       return false;
4745     }
4746
4747   /* Handle multiple arguments separated by commas.  */
4748   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
4749
4750   while (next_optstr && *next_optstr != '\0')
4751     {
4752       char *p = next_optstr;
4753       char *orig_p = p;
4754       char *comma = strchr (next_optstr, ',');
4755       const char *opt_string;
4756       size_t len, opt_len;
4757       int opt;
4758       bool opt_set_p;
4759       char ch;
4760       unsigned i;
4761       enum ix86_opt_type type = ix86_opt_unknown;
4762       int mask = 0;
4763
4764       if (comma)
4765         {
4766           *comma = '\0';
4767           len = comma - next_optstr;
4768           next_optstr = comma + 1;
4769         }
4770       else
4771         {
4772           len = strlen (p);
4773           next_optstr = NULL;
4774         }
4775
4776       /* Recognize no-xxx.  */
4777       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
4778         {
4779           opt_set_p = false;
4780           p += 3;
4781           len -= 3;
4782         }
4783       else
4784         opt_set_p = true;
4785
4786       /* Find the option.  */
4787       ch = *p;
4788       opt = N_OPTS;
4789       for (i = 0; i < ARRAY_SIZE (attrs); i++)
4790         {
4791           type = attrs[i].type;
4792           opt_len = attrs[i].len;
4793           if (ch == attrs[i].string[0]
4794               && ((type != ix86_opt_str && type != ix86_opt_enum)
4795                   ? len == opt_len
4796                   : len > opt_len)
4797               && memcmp (p, attrs[i].string, opt_len) == 0)
4798             {
4799               opt = attrs[i].opt;
4800               mask = attrs[i].mask;
4801               opt_string = attrs[i].string;
4802               break;
4803             }
4804         }
4805
4806       /* Process the option.  */
4807       if (opt == N_OPTS)
4808         {
4809           error ("attribute(target(\"%s\")) is unknown", orig_p);
4810           ret = false;
4811         }
4812
4813       else if (type == ix86_opt_isa)
4814         {
4815           struct cl_decoded_option decoded;
4816
4817           generate_option (opt, NULL, opt_set_p, CL_TARGET, &decoded);
4818           ix86_handle_option (opts, opts_set,
4819                               &decoded, input_location);
4820         }
4821
4822       else if (type == ix86_opt_yes || type == ix86_opt_no)
4823         {
4824           if (type == ix86_opt_no)
4825             opt_set_p = !opt_set_p;
4826
4827           if (opt_set_p)
4828             opts->x_target_flags |= mask;
4829           else
4830             opts->x_target_flags &= ~mask;
4831         }
4832
4833       else if (type == ix86_opt_str)
4834         {
4835           if (p_strings[opt])
4836             {
4837               error ("option(\"%s\") was already specified", opt_string);
4838               ret = false;
4839             }
4840           else
4841             p_strings[opt] = xstrdup (p + opt_len);
4842         }
4843
4844       else if (type == ix86_opt_enum)
4845         {
4846           bool arg_ok;
4847           int value;
4848
4849           arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET);
4850           if (arg_ok)
4851             set_option (opts, enum_opts_set, opt, value,
4852                         p + opt_len, DK_UNSPECIFIED, input_location,
4853                         global_dc);
4854           else
4855             {
4856               error ("attribute(target(\"%s\")) is unknown", orig_p);
4857               ret = false;
4858             }
4859         }
4860
4861       else
4862         gcc_unreachable ();
4863     }
4864
4865   return ret;
4866 }
4867
4868 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
4869
4870 tree
4871 ix86_valid_target_attribute_tree (tree args,
4872                                   struct gcc_options *opts,
4873                                   struct gcc_options *opts_set)
4874 {
4875   const char *orig_arch_string = opts->x_ix86_arch_string;
4876   const char *orig_tune_string = opts->x_ix86_tune_string;
4877   enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath;
4878   int orig_tune_defaulted = ix86_tune_defaulted;
4879   int orig_arch_specified = ix86_arch_specified;
4880   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL };
4881   tree t = NULL_TREE;
4882   int i;
4883   struct cl_target_option *def
4884     = TREE_TARGET_OPTION (target_option_default_node);
4885   struct gcc_options enum_opts_set;
4886
4887   memset (&enum_opts_set, 0, sizeof (enum_opts_set));
4888
4889   /* Process each of the options on the chain.  */
4890   if (! ix86_valid_target_attribute_inner_p (args, option_strings, opts,
4891                                              opts_set, &enum_opts_set))
4892     return error_mark_node;
4893
4894   /* If the changed options are different from the default, rerun
4895      ix86_option_override_internal, and then save the options away.
4896      The string options are are attribute options, and will be undone
4897      when we copy the save structure.  */
4898   if (opts->x_ix86_isa_flags != def->x_ix86_isa_flags
4899       || opts->x_target_flags != def->x_target_flags
4900       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
4901       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
4902       || enum_opts_set.x_ix86_fpmath)
4903     {
4904       /* If we are using the default tune= or arch=, undo the string assigned,
4905          and use the default.  */
4906       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
4907         opts->x_ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
4908       else if (!orig_arch_specified)
4909         opts->x_ix86_arch_string = NULL;
4910
4911       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
4912         opts->x_ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
4913       else if (orig_tune_defaulted)
4914         opts->x_ix86_tune_string = NULL;
4915
4916       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
4917       if (enum_opts_set.x_ix86_fpmath)
4918         opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
4919       else if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
4920                && TARGET_SSE_P (opts->x_ix86_isa_flags))
4921         {
4922           opts->x_ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
4923           opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
4924         }
4925
4926       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
4927       ix86_option_override_internal (false, opts, opts_set);
4928
4929       /* Add any builtin functions with the new isa if any.  */
4930       ix86_add_new_builtins (opts->x_ix86_isa_flags);
4931
4932       /* Save the current options unless we are validating options for
4933          #pragma.  */
4934       t = build_target_option_node (opts);
4935
4936       opts->x_ix86_arch_string = orig_arch_string;
4937       opts->x_ix86_tune_string = orig_tune_string;
4938       opts_set->x_ix86_fpmath = orig_fpmath_set;
4939
4940       /* Free up memory allocated to hold the strings */
4941       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
4942         free (option_strings[i]);
4943     }
4944
4945   return t;
4946 }
4947
4948 /* Hook to validate attribute((target("string"))).  */
4949
4950 static bool
4951 ix86_valid_target_attribute_p (tree fndecl,
4952                                tree ARG_UNUSED (name),
4953                                tree args,
4954                                int ARG_UNUSED (flags))
4955 {
4956   struct gcc_options func_options;
4957   tree new_target, new_optimize;
4958   bool ret = true;
4959
4960   /* attribute((target("default"))) does nothing, beyond
4961      affecting multi-versioning.  */
4962   if (TREE_VALUE (args)
4963       && TREE_CODE (TREE_VALUE (args)) == STRING_CST
4964       && TREE_CHAIN (args) == NULL_TREE
4965       && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0)
4966     return true;
4967
4968   tree old_optimize = build_optimization_node (&global_options);
4969
4970   /* Get the optimization options of the current function.  */  
4971   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
4972  
4973   if (!func_optimize)
4974     func_optimize = old_optimize;
4975
4976   /* Init func_options.  */
4977   memset (&func_options, 0, sizeof (func_options));
4978   init_options_struct (&func_options, NULL);
4979   lang_hooks.init_options_struct (&func_options);
4980  
4981   cl_optimization_restore (&func_options,
4982                            TREE_OPTIMIZATION (func_optimize));
4983
4984   /* Initialize func_options to the default before its target options can
4985      be set.  */
4986   cl_target_option_restore (&func_options,
4987                             TREE_TARGET_OPTION (target_option_default_node));
4988
4989   new_target = ix86_valid_target_attribute_tree (args, &func_options,
4990                                                  &global_options_set);
4991
4992   new_optimize = build_optimization_node (&func_options);
4993
4994   if (new_target == error_mark_node)
4995     ret = false;
4996
4997   else if (fndecl && new_target)
4998     {
4999       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
5000
5001       if (old_optimize != new_optimize)
5002         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
5003     }
5004
5005   return ret;
5006 }
5007
5008 \f
5009 /* Hook to determine if one function can safely inline another.  */
5010
5011 static bool
5012 ix86_can_inline_p (tree caller, tree callee)
5013 {
5014   bool ret = false;
5015   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
5016   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
5017
5018   /* If callee has no option attributes, then it is ok to inline.  */
5019   if (!callee_tree)
5020     ret = true;
5021
5022   /* If caller has no option attributes, but callee does then it is not ok to
5023      inline.  */
5024   else if (!caller_tree)
5025     ret = false;
5026
5027   else
5028     {
5029       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
5030       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
5031
5032       /* Callee's isa options should a subset of the caller's, i.e. a SSE4 function
5033          can inline a SSE2 function but a SSE2 function can't inline a SSE4
5034          function.  */
5035       if ((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags)
5036           != callee_opts->x_ix86_isa_flags)
5037         ret = false;
5038
5039       /* See if we have the same non-isa options.  */
5040       else if (caller_opts->x_target_flags != callee_opts->x_target_flags)
5041         ret = false;
5042
5043       /* See if arch, tune, etc. are the same.  */
5044       else if (caller_opts->arch != callee_opts->arch)
5045         ret = false;
5046
5047       else if (caller_opts->tune != callee_opts->tune)
5048         ret = false;
5049
5050       else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath)
5051         ret = false;
5052
5053       else if (caller_opts->branch_cost != callee_opts->branch_cost)
5054         ret = false;
5055
5056       else
5057         ret = true;
5058     }
5059
5060   return ret;
5061 }
5062
5063 \f
5064 /* Remember the last target of ix86_set_current_function.  */
5065 static GTY(()) tree ix86_previous_fndecl;
5066
5067 /* Set target globals to default.  */
5068
5069 static void
5070 ix86_reset_to_default_globals (void)
5071 {
5072   tree old_tree = (ix86_previous_fndecl
5073                    ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
5074                    : NULL_TREE);
5075
5076   if (old_tree)
5077     {
5078       tree new_tree = target_option_current_node;
5079       cl_target_option_restore (&global_options,
5080                                 TREE_TARGET_OPTION (new_tree));
5081       if (TREE_TARGET_GLOBALS (new_tree))
5082         restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
5083       else if (new_tree == target_option_default_node)
5084         restore_target_globals (&default_target_globals);
5085       else
5086         TREE_TARGET_GLOBALS (new_tree)
5087           = save_target_globals_default_opts ();
5088     }
5089 }
5090
5091 /* Invalidate ix86_previous_fndecl cache.  */
5092 void
5093 ix86_reset_previous_fndecl (void)
5094 {
5095   ix86_reset_to_default_globals ();
5096   ix86_previous_fndecl = NULL_TREE;
5097 }
5098
5099 /* Establish appropriate back-end context for processing the function
5100    FNDECL.  The argument might be NULL to indicate processing at top
5101    level, outside of any function scope.  */
5102 static void
5103 ix86_set_current_function (tree fndecl)
5104 {
5105   /* Only change the context if the function changes.  This hook is called
5106      several times in the course of compiling a function, and we don't want to
5107      slow things down too much or call target_reinit when it isn't safe.  */
5108   if (fndecl && fndecl != ix86_previous_fndecl)
5109     {
5110       tree old_tree = (ix86_previous_fndecl
5111                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
5112                        : NULL_TREE);
5113
5114       tree new_tree = (fndecl
5115                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
5116                        : NULL_TREE);
5117
5118       if (old_tree == new_tree)
5119         ;
5120
5121       else if (new_tree && new_tree != target_option_default_node)
5122         {
5123           cl_target_option_restore (&global_options,
5124                                     TREE_TARGET_OPTION (new_tree));
5125           if (TREE_TARGET_GLOBALS (new_tree))
5126             restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
5127           else
5128             TREE_TARGET_GLOBALS (new_tree)
5129               = save_target_globals_default_opts ();
5130         }
5131
5132       else if (old_tree && old_tree != target_option_default_node)
5133         ix86_reset_to_default_globals ();
5134       ix86_previous_fndecl = fndecl;
5135     }
5136 }
5137
5138 \f
5139 /* Return true if this goes in large data/bss.  */
5140
5141 static bool
5142 ix86_in_large_data_p (tree exp)
5143 {
5144   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
5145     return false;
5146
5147   /* Functions are never large data.  */
5148   if (TREE_CODE (exp) == FUNCTION_DECL)
5149     return false;
5150
5151   /* Automatic variables are never large data.  */
5152   if (TREE_CODE (exp) == VAR_DECL && !is_global_var (exp))
5153     return false;
5154
5155   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
5156     {
5157       const char *section = DECL_SECTION_NAME (exp);
5158       if (strcmp (section, ".ldata") == 0
5159           || strcmp (section, ".lbss") == 0)
5160         return true;
5161       return false;
5162     }
5163   else
5164     {
5165       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
5166
5167       /* If this is an incomplete type with size 0, then we can't put it
5168          in data because it might be too big when completed.  Also,
5169          int_size_in_bytes returns -1 if size can vary or is larger than
5170          an integer in which case also it is safer to assume that it goes in
5171          large data.  */
5172       if (size <= 0 || size > ix86_section_threshold)
5173         return true;
5174     }
5175
5176   return false;
5177 }
5178
5179 /* Switch to the appropriate section for output of DECL.
5180    DECL is either a `VAR_DECL' node or a constant of some sort.
5181    RELOC indicates whether forming the initial value of DECL requires
5182    link-time relocations.  */
5183
5184 ATTRIBUTE_UNUSED static section *
5185 x86_64_elf_select_section (tree decl, int reloc,
5186                            unsigned HOST_WIDE_INT align)
5187 {
5188   if (ix86_in_large_data_p (decl))
5189     {
5190       const char *sname = NULL;
5191       unsigned int flags = SECTION_WRITE;
5192       switch (categorize_decl_for_section (decl, reloc))
5193         {
5194         case SECCAT_DATA:
5195           sname = ".ldata";
5196           break;
5197         case SECCAT_DATA_REL:
5198           sname = ".ldata.rel";
5199           break;
5200         case SECCAT_DATA_REL_LOCAL:
5201           sname = ".ldata.rel.local";
5202           break;
5203         case SECCAT_DATA_REL_RO:
5204           sname = ".ldata.rel.ro";
5205           break;
5206         case SECCAT_DATA_REL_RO_LOCAL:
5207           sname = ".ldata.rel.ro.local";
5208           break;
5209         case SECCAT_BSS:
5210           sname = ".lbss";
5211           flags |= SECTION_BSS;
5212           break;
5213         case SECCAT_RODATA:
5214         case SECCAT_RODATA_MERGE_STR:
5215         case SECCAT_RODATA_MERGE_STR_INIT:
5216         case SECCAT_RODATA_MERGE_CONST:
5217           sname = ".lrodata";
5218           flags = 0;
5219           break;
5220         case SECCAT_SRODATA:
5221         case SECCAT_SDATA:
5222         case SECCAT_SBSS:
5223           gcc_unreachable ();
5224         case SECCAT_TEXT:
5225         case SECCAT_TDATA:
5226         case SECCAT_TBSS:
5227           /* We don't split these for medium model.  Place them into
5228              default sections and hope for best.  */
5229           break;
5230         }
5231       if (sname)
5232         {
5233           /* We might get called with string constants, but get_named_section
5234              doesn't like them as they are not DECLs.  Also, we need to set
5235              flags in that case.  */
5236           if (!DECL_P (decl))
5237             return get_section (sname, flags, NULL);
5238           return get_named_section (decl, sname, reloc);
5239         }
5240     }
5241   return default_elf_select_section (decl, reloc, align);
5242 }
5243
5244 /* Select a set of attributes for section NAME based on the properties
5245    of DECL and whether or not RELOC indicates that DECL's initializer
5246    might contain runtime relocations.  */
5247
5248 static unsigned int ATTRIBUTE_UNUSED
5249 x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
5250 {
5251   unsigned int flags = default_section_type_flags (decl, name, reloc);
5252
5253   if (decl == NULL_TREE
5254       && (strcmp (name, ".ldata.rel.ro") == 0
5255           || strcmp (name, ".ldata.rel.ro.local") == 0))
5256     flags |= SECTION_RELRO;
5257
5258   if (strcmp (name, ".lbss") == 0
5259       || strncmp (name, ".lbss.", 5) == 0
5260       || strncmp (name, ".gnu.linkonce.lb.", 16) == 0)
5261     flags |= SECTION_BSS;
5262
5263   return flags;
5264 }
5265
5266 /* Build up a unique section name, expressed as a
5267    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
5268    RELOC indicates whether the initial value of EXP requires
5269    link-time relocations.  */
5270
5271 static void ATTRIBUTE_UNUSED
5272 x86_64_elf_unique_section (tree decl, int reloc)
5273 {
5274   if (ix86_in_large_data_p (decl))
5275     {
5276       const char *prefix = NULL;
5277       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
5278       bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP;
5279
5280       switch (categorize_decl_for_section (decl, reloc))
5281         {
5282         case SECCAT_DATA:
5283         case SECCAT_DATA_REL:
5284         case SECCAT_DATA_REL_LOCAL:
5285         case SECCAT_DATA_REL_RO:
5286         case SECCAT_DATA_REL_RO_LOCAL:
5287           prefix = one_only ? ".ld" : ".ldata";
5288           break;
5289         case SECCAT_BSS:
5290           prefix = one_only ? ".lb" : ".lbss";
5291           break;
5292         case SECCAT_RODATA:
5293         case SECCAT_RODATA_MERGE_STR:
5294         case SECCAT_RODATA_MERGE_STR_INIT:
5295         case SECCAT_RODATA_MERGE_CONST:
5296           prefix = one_only ? ".lr" : ".lrodata";
5297           break;
5298         case SECCAT_SRODATA:
5299         case SECCAT_SDATA:
5300         case SECCAT_SBSS:
5301           gcc_unreachable ();
5302         case SECCAT_TEXT:
5303         case SECCAT_TDATA:
5304         case SECCAT_TBSS:
5305           /* We don't split these for medium model.  Place them into
5306              default sections and hope for best.  */
5307           break;
5308         }
5309       if (prefix)
5310         {
5311           const char *name, *linkonce;
5312           char *string;
5313
5314           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5315           name = targetm.strip_name_encoding (name);
5316
5317           /* If we're using one_only, then there needs to be a .gnu.linkonce
5318              prefix to the section name.  */
5319           linkonce = one_only ? ".gnu.linkonce" : "";
5320
5321           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
5322
5323           set_decl_section_name (decl, string);
5324           return;
5325         }
5326     }
5327   default_unique_section (decl, reloc);
5328 }
5329
5330 #ifdef COMMON_ASM_OP
5331 /* This says how to output assembler code to declare an
5332    uninitialized external linkage data object.
5333
5334    For medium model x86-64 we need to use .largecomm opcode for
5335    large objects.  */
5336 void
5337 x86_elf_aligned_common (FILE *file,
5338                         const char *name, unsigned HOST_WIDE_INT size,
5339                         int align)
5340 {
5341   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
5342       && size > (unsigned int)ix86_section_threshold)
5343     fputs ("\t.largecomm\t", file);
5344   else
5345     fputs (COMMON_ASM_OP, file);
5346   assemble_name (file, name);
5347   fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
5348            size, align / BITS_PER_UNIT);
5349 }
5350 #endif
5351
5352 /* Utility function for targets to use in implementing
5353    ASM_OUTPUT_ALIGNED_BSS.  */
5354
5355 void
5356 x86_output_aligned_bss (FILE *file, tree decl, const char *name,
5357                         unsigned HOST_WIDE_INT size, int align)
5358 {
5359   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
5360       && size > (unsigned int)ix86_section_threshold)
5361     switch_to_section (get_named_section (decl, ".lbss", 0));
5362   else
5363     switch_to_section (bss_section);
5364   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
5365 #ifdef ASM_DECLARE_OBJECT_NAME
5366   last_assemble_variable_decl = decl;
5367   ASM_DECLARE_OBJECT_NAME (file, name, decl);
5368 #else
5369   /* Standard thing is just output label for the object.  */
5370   ASM_OUTPUT_LABEL (file, name);
5371 #endif /* ASM_DECLARE_OBJECT_NAME */
5372   ASM_OUTPUT_SKIP (file, size ? size : 1);
5373 }
5374 \f
5375 /* Decide whether we must probe the stack before any space allocation
5376    on this target.  It's essentially TARGET_STACK_PROBE except when
5377    -fstack-check causes the stack to be already probed differently.  */
5378
5379 bool
5380 ix86_target_stack_probe (void)
5381 {
5382   /* Do not probe the stack twice if static stack checking is enabled.  */
5383   if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5384     return false;
5385
5386   return TARGET_STACK_PROBE;
5387 }
5388 \f
5389 /* Decide whether we can make a sibling call to a function.  DECL is the
5390    declaration of the function being targeted by the call and EXP is the
5391    CALL_EXPR representing the call.  */
5392
5393 static bool
5394 ix86_function_ok_for_sibcall (tree decl, tree exp)
5395 {
5396   tree type, decl_or_type;
5397   rtx a, b;
5398
5399   /* If we are generating position-independent code, we cannot sibcall
5400      optimize any indirect call, or a direct call to a global function,
5401      as the PLT requires %ebx be live. (Darwin does not have a PLT.)  */
5402   if (!TARGET_MACHO
5403       && !TARGET_64BIT
5404       && flag_pic
5405       && (!decl || !targetm.binds_local_p (decl)))
5406     return false;
5407
5408   /* If we need to align the outgoing stack, then sibcalling would
5409      unalign the stack, which may break the called function.  */
5410   if (ix86_minimum_incoming_stack_boundary (true)
5411       < PREFERRED_STACK_BOUNDARY)
5412     return false;
5413
5414   if (decl)
5415     {
5416       decl_or_type = decl;
5417       type = TREE_TYPE (decl);
5418     }
5419   else
5420     {
5421       /* We're looking at the CALL_EXPR, we need the type of the function.  */
5422       type = CALL_EXPR_FN (exp);                /* pointer expression */
5423       type = TREE_TYPE (type);                  /* pointer type */
5424       type = TREE_TYPE (type);                  /* function type */
5425       decl_or_type = type;
5426     }
5427
5428   /* Check that the return value locations are the same.  Like
5429      if we are returning floats on the 80387 register stack, we cannot
5430      make a sibcall from a function that doesn't return a float to a
5431      function that does or, conversely, from a function that does return
5432      a float to a function that doesn't; the necessary stack adjustment
5433      would not be executed.  This is also the place we notice
5434      differences in the return value ABI.  Note that it is ok for one
5435      of the functions to have void return type as long as the return
5436      value of the other is passed in a register.  */
5437   a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
5438   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
5439                            cfun->decl, false);
5440   if (STACK_REG_P (a) || STACK_REG_P (b))
5441     {
5442       if (!rtx_equal_p (a, b))
5443         return false;
5444     }
5445   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
5446     ;
5447   else if (!rtx_equal_p (a, b))
5448     return false;
5449
5450   if (TARGET_64BIT)
5451     {
5452       /* The SYSV ABI has more call-clobbered registers;
5453          disallow sibcalls from MS to SYSV.  */
5454       if (cfun->machine->call_abi == MS_ABI
5455           && ix86_function_type_abi (type) == SYSV_ABI)
5456         return false;
5457     }
5458   else
5459     {
5460       /* If this call is indirect, we'll need to be able to use a
5461          call-clobbered register for the address of the target function.
5462          Make sure that all such registers are not used for passing
5463          parameters.  Note that DLLIMPORT functions are indirect.  */
5464       if (!decl
5465           || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)))
5466         {
5467           if (ix86_function_regparm (type, NULL) >= 3)
5468             {
5469               /* ??? Need to count the actual number of registers to be used,
5470                  not the possible number of registers.  Fix later.  */
5471               return false;
5472             }
5473         }
5474     }
5475
5476   /* Otherwise okay.  That also includes certain types of indirect calls.  */
5477   return true;
5478 }
5479
5480 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
5481    and "sseregparm" calling convention attributes;
5482    arguments as in struct attribute_spec.handler.  */
5483
5484 static tree
5485 ix86_handle_cconv_attribute (tree *node, tree name,
5486                                    tree args,
5487                                    int,
5488                                    bool *no_add_attrs)
5489 {
5490   if (TREE_CODE (*node) != FUNCTION_TYPE
5491       && TREE_CODE (*node) != METHOD_TYPE
5492       && TREE_CODE (*node) != FIELD_DECL
5493       && TREE_CODE (*node) != TYPE_DECL)
5494     {
5495       warning (OPT_Wattributes, "%qE attribute only applies to functions",
5496                name);
5497       *no_add_attrs = true;
5498       return NULL_TREE;
5499     }
5500
5501   /* Can combine regparm with all attributes but fastcall, and thiscall.  */
5502   if (is_attribute_p ("regparm", name))
5503     {
5504       tree cst;
5505
5506       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5507         {
5508           error ("fastcall and regparm attributes are not compatible");
5509         }
5510
5511       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5512         {
5513           error ("regparam and thiscall attributes are not compatible");
5514         }
5515
5516       cst = TREE_VALUE (args);
5517       if (TREE_CODE (cst) != INTEGER_CST)
5518         {
5519           warning (OPT_Wattributes,
5520                    "%qE attribute requires an integer constant argument",
5521                    name);
5522           *no_add_attrs = true;
5523         }
5524       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
5525         {
5526           warning (OPT_Wattributes, "argument to %qE attribute larger than %d",
5527                    name, REGPARM_MAX);
5528           *no_add_attrs = true;
5529         }
5530
5531       return NULL_TREE;
5532     }
5533
5534   if (TARGET_64BIT)
5535     {
5536       /* Do not warn when emulating the MS ABI.  */
5537       if ((TREE_CODE (*node) != FUNCTION_TYPE
5538            && TREE_CODE (*node) != METHOD_TYPE)
5539           || ix86_function_type_abi (*node) != MS_ABI)
5540         warning (OPT_Wattributes, "%qE attribute ignored",
5541                  name);
5542       *no_add_attrs = true;
5543       return NULL_TREE;
5544     }
5545
5546   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
5547   if (is_attribute_p ("fastcall", name))
5548     {
5549       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5550         {
5551           error ("fastcall and cdecl attributes are not compatible");
5552         }
5553       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5554         {
5555           error ("fastcall and stdcall attributes are not compatible");
5556         }
5557       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
5558         {
5559           error ("fastcall and regparm attributes are not compatible");
5560         }
5561       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5562         {
5563           error ("fastcall and thiscall attributes are not compatible");
5564         }
5565     }
5566
5567   /* Can combine stdcall with fastcall (redundant), regparm and
5568      sseregparm.  */
5569   else if (is_attribute_p ("stdcall", name))
5570     {
5571       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5572         {
5573           error ("stdcall and cdecl attributes are not compatible");
5574         }
5575       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5576         {
5577           error ("stdcall and fastcall attributes are not compatible");
5578         }
5579       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5580         {
5581           error ("stdcall and thiscall attributes are not compatible");
5582         }
5583     }
5584
5585   /* Can combine cdecl with regparm and sseregparm.  */
5586   else if (is_attribute_p ("cdecl", name))
5587     {
5588       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5589         {
5590           error ("stdcall and cdecl attributes are not compatible");
5591         }
5592       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5593         {
5594           error ("fastcall and cdecl attributes are not compatible");
5595         }
5596       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5597         {
5598           error ("cdecl and thiscall attributes are not compatible");
5599         }
5600     }
5601   else if (is_attribute_p ("thiscall", name))
5602     {
5603       if (TREE_CODE (*node) != METHOD_TYPE && pedantic)
5604         warning (OPT_Wattributes, "%qE attribute is used for none class-method",
5605                  name);
5606       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5607         {
5608           error ("stdcall and thiscall attributes are not compatible");
5609         }
5610       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5611         {
5612           error ("fastcall and thiscall attributes are not compatible");
5613         }
5614       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5615         {
5616           error ("cdecl and thiscall attributes are not compatible");
5617         }
5618     }
5619
5620   /* Can combine sseregparm with all attributes.  */
5621
5622   return NULL_TREE;
5623 }
5624
5625 /* The transactional memory builtins are implicitly regparm or fastcall
5626    depending on the ABI.  Override the generic do-nothing attribute that
5627    these builtins were declared with, and replace it with one of the two
5628    attributes that we expect elsewhere.  */
5629
5630 static tree
5631 ix86_handle_tm_regparm_attribute (tree *node, tree, tree,
5632                                   int flags, bool *no_add_attrs)
5633 {
5634   tree alt;
5635
5636   /* In no case do we want to add the placeholder attribute.  */
5637   *no_add_attrs = true;
5638
5639   /* The 64-bit ABI is unchanged for transactional memory.  */
5640   if (TARGET_64BIT)
5641     return NULL_TREE;
5642
5643   /* ??? Is there a better way to validate 32-bit windows?  We have
5644      cfun->machine->call_abi, but that seems to be set only for 64-bit.  */
5645   if (CHECK_STACK_LIMIT > 0)
5646     alt = tree_cons (get_identifier ("fastcall"), NULL, NULL);
5647   else
5648     {
5649       alt = tree_cons (NULL, build_int_cst (NULL, 2), NULL);
5650       alt = tree_cons (get_identifier ("regparm"), alt, NULL);
5651     }
5652   decl_attributes (node, alt, flags);
5653
5654   return NULL_TREE;
5655 }
5656
5657 /* This function determines from TYPE the calling-convention.  */
5658
5659 unsigned int
5660 ix86_get_callcvt (const_tree type)
5661 {
5662   unsigned int ret = 0;
5663   bool is_stdarg;
5664   tree attrs;
5665
5666   if (TARGET_64BIT)
5667     return IX86_CALLCVT_CDECL;
5668
5669   attrs = TYPE_ATTRIBUTES (type);
5670   if (attrs != NULL_TREE)
5671     {
5672       if (lookup_attribute ("cdecl", attrs))
5673         ret |= IX86_CALLCVT_CDECL;
5674       else if (lookup_attribute ("stdcall", attrs))
5675         ret |= IX86_CALLCVT_STDCALL;
5676       else if (lookup_attribute ("fastcall", attrs))
5677         ret |= IX86_CALLCVT_FASTCALL;
5678       else if (lookup_attribute ("thiscall", attrs))
5679         ret |= IX86_CALLCVT_THISCALL;
5680
5681       /* Regparam isn't allowed for thiscall and fastcall.  */
5682       if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
5683         {
5684           if (lookup_attribute ("regparm", attrs))
5685             ret |= IX86_CALLCVT_REGPARM;
5686           if (lookup_attribute ("sseregparm", attrs))
5687             ret |= IX86_CALLCVT_SSEREGPARM;
5688         }
5689
5690       if (IX86_BASE_CALLCVT(ret) != 0)
5691         return ret;
5692     }
5693
5694   is_stdarg = stdarg_p (type);
5695   if (TARGET_RTD && !is_stdarg)
5696     return IX86_CALLCVT_STDCALL | ret;
5697
5698   if (ret != 0
5699       || is_stdarg
5700       || TREE_CODE (type) != METHOD_TYPE
5701       || ix86_function_type_abi (type) != MS_ABI)
5702     return IX86_CALLCVT_CDECL | ret;
5703
5704   return IX86_CALLCVT_THISCALL;
5705 }
5706
5707 /* Return 0 if the attributes for two types are incompatible, 1 if they
5708    are compatible, and 2 if they are nearly compatible (which causes a
5709    warning to be generated).  */
5710
5711 static int
5712 ix86_comp_type_attributes (const_tree type1, const_tree type2)
5713 {
5714   unsigned int ccvt1, ccvt2;
5715
5716   if (TREE_CODE (type1) != FUNCTION_TYPE
5717       && TREE_CODE (type1) != METHOD_TYPE)
5718     return 1;
5719
5720   ccvt1 = ix86_get_callcvt (type1);
5721   ccvt2 = ix86_get_callcvt (type2);
5722   if (ccvt1 != ccvt2)
5723     return 0;
5724   if (ix86_function_regparm (type1, NULL)
5725       != ix86_function_regparm (type2, NULL))
5726     return 0;
5727
5728   return 1;
5729 }
5730 \f
5731 /* Return the regparm value for a function with the indicated TYPE and DECL.
5732    DECL may be NULL when calling function indirectly
5733    or considering a libcall.  */
5734
5735 static int
5736 ix86_function_regparm (const_tree type, const_tree decl)
5737 {
5738   tree attr;
5739   int regparm;
5740   unsigned int ccvt;
5741
5742   if (TARGET_64BIT)
5743     return (ix86_function_type_abi (type) == SYSV_ABI
5744             ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
5745   ccvt = ix86_get_callcvt (type);
5746   regparm = ix86_regparm;
5747
5748   if ((ccvt & IX86_CALLCVT_REGPARM) != 0)
5749     {
5750       attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
5751       if (attr)
5752         {
5753           regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
5754           return regparm;
5755         }
5756     }
5757   else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
5758     return 2;
5759   else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
5760     return 1;
5761
5762   /* Use register calling convention for local functions when possible.  */
5763   if (decl
5764       && TREE_CODE (decl) == FUNCTION_DECL
5765       /* Caller and callee must agree on the calling convention, so
5766          checking here just optimize means that with
5767          __attribute__((optimize (...))) caller could use regparm convention
5768          and callee not, or vice versa.  Instead look at whether the callee
5769          is optimized or not.  */
5770       && opt_for_fn (decl, optimize)
5771       && !(profile_flag && !flag_fentry))
5772     {
5773       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
5774       cgraph_local_info *i = cgraph_node::local_info (CONST_CAST_TREE (decl));
5775       if (i && i->local && i->can_change_signature)
5776         {
5777           int local_regparm, globals = 0, regno;
5778
5779           /* Make sure no regparm register is taken by a
5780              fixed register variable.  */
5781           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
5782             if (fixed_regs[local_regparm])
5783               break;
5784
5785           /* We don't want to use regparm(3) for nested functions as
5786              these use a static chain pointer in the third argument.  */
5787           if (local_regparm == 3 && DECL_STATIC_CHAIN (decl))
5788             local_regparm = 2;
5789
5790           /* In 32-bit mode save a register for the split stack.  */
5791           if (!TARGET_64BIT && local_regparm == 3 && flag_split_stack)
5792             local_regparm = 2;
5793
5794           /* Each fixed register usage increases register pressure,
5795              so less registers should be used for argument passing.
5796              This functionality can be overriden by an explicit
5797              regparm value.  */
5798           for (regno = AX_REG; regno <= DI_REG; regno++)
5799             if (fixed_regs[regno])
5800               globals++;
5801
5802           local_regparm
5803             = globals < local_regparm ? local_regparm - globals : 0;
5804
5805           if (local_regparm > regparm)
5806             regparm = local_regparm;
5807         }
5808     }
5809
5810   return regparm;
5811 }
5812
5813 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
5814    DFmode (2) arguments in SSE registers for a function with the
5815    indicated TYPE and DECL.  DECL may be NULL when calling function
5816    indirectly or considering a libcall.  Otherwise return 0.  */
5817
5818 static int
5819 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
5820 {
5821   gcc_assert (!TARGET_64BIT);
5822
5823   /* Use SSE registers to pass SFmode and DFmode arguments if requested
5824      by the sseregparm attribute.  */
5825   if (TARGET_SSEREGPARM
5826       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
5827     {
5828       if (!TARGET_SSE)
5829         {
5830           if (warn)
5831             {
5832               if (decl)
5833                 error ("calling %qD with attribute sseregparm without "
5834                        "SSE/SSE2 enabled", decl);
5835               else
5836                 error ("calling %qT with attribute sseregparm without "
5837                        "SSE/SSE2 enabled", type);
5838             }
5839           return 0;
5840         }
5841
5842       return 2;
5843     }
5844
5845   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
5846      (and DFmode for SSE2) arguments in SSE registers.  */
5847   if (decl && TARGET_SSE_MATH && optimize
5848       && !(profile_flag && !flag_fentry))
5849     {
5850       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
5851       cgraph_local_info *i = cgraph_node::local_info (CONST_CAST_TREE(decl));
5852       if (i && i->local && i->can_change_signature)
5853         return TARGET_SSE2 ? 2 : 1;
5854     }
5855
5856   return 0;
5857 }
5858
5859 /* Return true if EAX is live at the start of the function.  Used by
5860    ix86_expand_prologue to determine if we need special help before
5861    calling allocate_stack_worker.  */
5862
5863 static bool
5864 ix86_eax_live_at_start_p (void)
5865 {
5866   /* Cheat.  Don't bother working forward from ix86_function_regparm
5867      to the function type to whether an actual argument is located in
5868      eax.  Instead just look at cfg info, which is still close enough
5869      to correct at this point.  This gives false positives for broken
5870      functions that might use uninitialized data that happens to be
5871      allocated in eax, but who cares?  */
5872   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0);
5873 }
5874
5875 static bool
5876 ix86_keep_aggregate_return_pointer (tree fntype)
5877 {
5878   tree attr;
5879
5880   if (!TARGET_64BIT)
5881     {
5882       attr = lookup_attribute ("callee_pop_aggregate_return",
5883                                TYPE_ATTRIBUTES (fntype));
5884       if (attr)
5885         return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0);
5886
5887       /* For 32-bit MS-ABI the default is to keep aggregate
5888          return pointer.  */
5889       if (ix86_function_type_abi (fntype) == MS_ABI)
5890         return true;
5891     }
5892   return KEEP_AGGREGATE_RETURN_POINTER != 0;
5893 }
5894
5895 /* Value is the number of bytes of arguments automatically
5896    popped when returning from a subroutine call.
5897    FUNDECL is the declaration node of the function (as a tree),
5898    FUNTYPE is the data type of the function (as a tree),
5899    or for a library call it is an identifier node for the subroutine name.
5900    SIZE is the number of bytes of arguments passed on the stack.
5901
5902    On the 80386, the RTD insn may be used to pop them if the number
5903      of args is fixed, but if the number is variable then the caller
5904      must pop them all.  RTD can't be used for library calls now
5905      because the library is compiled with the Unix compiler.
5906    Use of RTD is a selectable option, since it is incompatible with
5907    standard Unix calling sequences.  If the option is not selected,
5908    the caller must always pop the args.
5909
5910    The attribute stdcall is equivalent to RTD on a per module basis.  */
5911
5912 static int
5913 ix86_return_pops_args (tree fundecl, tree funtype, int size)
5914 {
5915   unsigned int ccvt;
5916
5917   /* None of the 64-bit ABIs pop arguments.  */
5918   if (TARGET_64BIT)
5919     return 0;
5920
5921   ccvt = ix86_get_callcvt (funtype);
5922
5923   if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL
5924                | IX86_CALLCVT_THISCALL)) != 0
5925       && ! stdarg_p (funtype))
5926     return size;
5927
5928   /* Lose any fake structure return argument if it is passed on the stack.  */
5929   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
5930       && !ix86_keep_aggregate_return_pointer (funtype))
5931     {
5932       int nregs = ix86_function_regparm (funtype, fundecl);
5933       if (nregs == 0)
5934         return GET_MODE_SIZE (Pmode);
5935     }
5936
5937   return 0;
5938 }
5939
5940 /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook.  */
5941
5942 static bool
5943 ix86_legitimate_combined_insn (rtx_insn *insn)
5944 {
5945   /* Check operand constraints in case hard registers were propagated
5946      into insn pattern.  This check prevents combine pass from
5947      generating insn patterns with invalid hard register operands.
5948      These invalid insns can eventually confuse reload to error out
5949      with a spill failure.  See also PRs 46829 and 46843.  */
5950   if ((INSN_CODE (insn) = recog (PATTERN (insn), insn, 0)) >= 0)
5951     {
5952       int i;
5953
5954       extract_insn (insn);
5955       preprocess_constraints (insn);
5956
5957       int n_operands = recog_data.n_operands;
5958       int n_alternatives = recog_data.n_alternatives;
5959       for (i = 0; i < n_operands; i++)
5960         {
5961           rtx op = recog_data.operand[i];
5962           machine_mode mode = GET_MODE (op);
5963           const operand_alternative *op_alt;
5964           int offset = 0;
5965           bool win;
5966           int j;
5967
5968           /* For pre-AVX disallow unaligned loads/stores where the
5969              instructions don't support it.  */
5970           if (!TARGET_AVX
5971               && VECTOR_MODE_P (GET_MODE (op))
5972               && misaligned_operand (op, GET_MODE (op)))
5973             {
5974               int min_align = get_attr_ssememalign (insn);
5975               if (min_align == 0)
5976                 return false;
5977             }
5978
5979           /* A unary operator may be accepted by the predicate, but it
5980              is irrelevant for matching constraints.  */
5981           if (UNARY_P (op))
5982             op = XEXP (op, 0);
5983
5984           if (GET_CODE (op) == SUBREG)
5985             {
5986               if (REG_P (SUBREG_REG (op))
5987                   && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
5988                 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
5989                                               GET_MODE (SUBREG_REG (op)),
5990                                               SUBREG_BYTE (op),
5991                                               GET_MODE (op));
5992               op = SUBREG_REG (op);
5993             }
5994
5995           if (!(REG_P (op) && HARD_REGISTER_P (op)))
5996             continue;
5997
5998           op_alt = recog_op_alt;
5999
6000           /* Operand has no constraints, anything is OK.  */
6001           win = !n_alternatives;
6002
6003           alternative_mask preferred = get_preferred_alternatives (insn);
6004           for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
6005             {
6006               if (!TEST_BIT (preferred, j))
6007                 continue;
6008               if (op_alt[i].anything_ok
6009                   || (op_alt[i].matches != -1
6010                       && operands_match_p
6011                           (recog_data.operand[i],
6012                            recog_data.operand[op_alt[i].matches]))
6013                   || reg_fits_class_p (op, op_alt[i].cl, offset, mode))
6014                 {
6015                   win = true;
6016                   break;
6017                 }
6018             }
6019
6020           if (!win)
6021             return false;
6022         }
6023     }
6024
6025   return true;
6026 }
6027 \f
6028 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook.  */
6029
6030 static unsigned HOST_WIDE_INT
6031 ix86_asan_shadow_offset (void)
6032 {
6033   return TARGET_LP64 ? (TARGET_MACHO ? (HOST_WIDE_INT_1 << 44)
6034                                      : HOST_WIDE_INT_C (0x7fff8000))
6035                      : (HOST_WIDE_INT_1 << 29);
6036 }
6037 \f
6038 /* Argument support functions.  */
6039
6040 /* Return true when register may be used to pass function parameters.  */
6041 bool
6042 ix86_function_arg_regno_p (int regno)
6043 {
6044   int i;
6045   const int *parm_regs;
6046
6047   if (!TARGET_64BIT)
6048     {
6049       if (TARGET_MACHO)
6050         return (regno < REGPARM_MAX
6051                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
6052       else
6053         return (regno < REGPARM_MAX
6054                 || (TARGET_MMX && MMX_REGNO_P (regno)
6055                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
6056                 || (TARGET_SSE && SSE_REGNO_P (regno)
6057                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
6058     }
6059
6060   if (TARGET_SSE && SSE_REGNO_P (regno)
6061       && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
6062     return true;
6063
6064   /* TODO: The function should depend on current function ABI but
6065      builtins.c would need updating then. Therefore we use the
6066      default ABI.  */
6067
6068   /* RAX is used as hidden argument to va_arg functions.  */
6069   if (ix86_abi == SYSV_ABI && regno == AX_REG)
6070     return true;
6071
6072   if (ix86_abi == MS_ABI)
6073     parm_regs = x86_64_ms_abi_int_parameter_registers;
6074   else
6075     parm_regs = x86_64_int_parameter_registers;
6076   for (i = 0; i < (ix86_abi == MS_ABI
6077                    ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
6078     if (regno == parm_regs[i])
6079       return true;
6080   return false;
6081 }
6082
6083 /* Return if we do not know how to pass TYPE solely in registers.  */
6084
6085 static bool
6086 ix86_must_pass_in_stack (machine_mode mode, const_tree type)
6087 {
6088   if (must_pass_in_stack_var_size_or_pad (mode, type))
6089     return true;
6090
6091   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
6092      The layout_type routine is crafty and tries to trick us into passing
6093      currently unsupported vector types on the stack by using TImode.  */
6094   return (!TARGET_64BIT && mode == TImode
6095           && type && TREE_CODE (type) != VECTOR_TYPE);
6096 }
6097
6098 /* It returns the size, in bytes, of the area reserved for arguments passed
6099    in registers for the function represented by fndecl dependent to the used
6100    abi format.  */
6101 int
6102 ix86_reg_parm_stack_space (const_tree fndecl)
6103 {
6104   enum calling_abi call_abi = SYSV_ABI;
6105   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
6106     call_abi = ix86_function_abi (fndecl);
6107   else
6108     call_abi = ix86_function_type_abi (fndecl);
6109   if (TARGET_64BIT && call_abi == MS_ABI)
6110     return 32;
6111   return 0;
6112 }
6113
6114 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
6115    call abi used.  */
6116 enum calling_abi
6117 ix86_function_type_abi (const_tree fntype)
6118 {
6119   if (fntype != NULL_TREE && TYPE_ATTRIBUTES (fntype) != NULL_TREE)
6120     {
6121       enum calling_abi abi = ix86_abi;
6122       if (abi == SYSV_ABI)
6123         {
6124           if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
6125             {
6126               if (TARGET_X32)
6127                 {
6128                   static bool warned = false;
6129                   if (!warned)
6130                     {
6131                       error ("X32 does not support ms_abi attribute");
6132                       warned = true;
6133                     }
6134                 }
6135               abi = MS_ABI;
6136             }
6137         }
6138       else if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
6139         abi = SYSV_ABI;
6140       return abi;
6141     }
6142   return ix86_abi;
6143 }
6144
6145 /* We add this as a workaround in order to use libc_has_function
6146    hook in i386.md.  */
6147 bool
6148 ix86_libc_has_function (enum function_class fn_class)
6149 {
6150   return targetm.libc_has_function (fn_class);
6151 }
6152
6153 static bool
6154 ix86_function_ms_hook_prologue (const_tree fn)
6155 {
6156   if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn)))
6157     {
6158       if (decl_function_context (fn) != NULL_TREE)
6159         error_at (DECL_SOURCE_LOCATION (fn),
6160                   "ms_hook_prologue is not compatible with nested function");
6161       else
6162         return true;
6163     }
6164   return false;
6165 }
6166
6167 static enum calling_abi
6168 ix86_function_abi (const_tree fndecl)
6169 {
6170   if (! fndecl)
6171     return ix86_abi;
6172   return ix86_function_type_abi (TREE_TYPE (fndecl));
6173 }
6174
6175 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
6176    call abi used.  */
6177 enum calling_abi
6178 ix86_cfun_abi (void)
6179 {
6180   if (! cfun)
6181     return ix86_abi;
6182   return cfun->machine->call_abi;
6183 }
6184
6185 /* Write the extra assembler code needed to declare a function properly.  */
6186
6187 void
6188 ix86_asm_output_function_label (FILE *asm_out_file, const char *fname,
6189                                 tree decl)
6190 {
6191   bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
6192
6193   if (is_ms_hook)
6194     {
6195       int i, filler_count = (TARGET_64BIT ? 32 : 16);
6196       unsigned int filler_cc = 0xcccccccc;
6197
6198       for (i = 0; i < filler_count; i += 4)
6199         fprintf (asm_out_file, ASM_LONG " %#x\n", filler_cc);
6200     }
6201
6202 #ifdef SUBTARGET_ASM_UNWIND_INIT
6203   SUBTARGET_ASM_UNWIND_INIT (asm_out_file);
6204 #endif
6205
6206   ASM_OUTPUT_LABEL (asm_out_file, fname);
6207
6208   /* Output magic byte marker, if hot-patch attribute is set.  */
6209   if (is_ms_hook)
6210     {
6211       if (TARGET_64BIT)
6212         {
6213           /* leaq [%rsp + 0], %rsp  */
6214           asm_fprintf (asm_out_file, ASM_BYTE
6215                        "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n");
6216         }
6217       else
6218         {
6219           /* movl.s %edi, %edi
6220              push   %ebp
6221              movl.s %esp, %ebp */
6222           asm_fprintf (asm_out_file, ASM_BYTE
6223                        "0x8b, 0xff, 0x55, 0x8b, 0xec\n");
6224         }
6225     }
6226 }
6227
6228 /* regclass.c  */
6229 extern void init_regs (void);
6230
6231 /* Implementation of call abi switching target hook. Specific to FNDECL
6232    the specific call register sets are set.  See also
6233    ix86_conditional_register_usage for more details.  */
6234 void
6235 ix86_call_abi_override (const_tree fndecl)
6236 {
6237   if (fndecl == NULL_TREE)
6238     cfun->machine->call_abi = ix86_abi;
6239   else
6240     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
6241 }
6242
6243 /* 64-bit MS and SYSV ABI have different set of call used registers.  Avoid
6244    expensive re-initialization of init_regs each time we switch function context
6245    since this is needed only during RTL expansion.  */
6246 static void
6247 ix86_maybe_switch_abi (void)
6248 {
6249   if (TARGET_64BIT &&
6250       call_used_regs[SI_REG] == (cfun->machine->call_abi == MS_ABI))
6251     reinit_regs ();
6252 }
6253
6254 /* Return 1 if pseudo register should be created and used to hold
6255    GOT address for PIC code.  */
6256 static bool
6257 ix86_use_pseudo_pic_reg (void)
6258 {
6259   if ((TARGET_64BIT
6260        && (ix86_cmodel == CM_SMALL_PIC
6261            || TARGET_PECOFF))
6262       || !flag_pic)
6263     return false;
6264   return true;
6265 }
6266
6267 /* Initialize large model PIC register.  */
6268
6269 static void
6270 ix86_init_large_pic_reg (unsigned int tmp_regno)
6271 {
6272   rtx_code_label *label;
6273   rtx tmp_reg;
6274
6275   gcc_assert (Pmode == DImode);
6276   label = gen_label_rtx ();
6277   emit_label (label);
6278   LABEL_PRESERVE_P (label) = 1;
6279   tmp_reg = gen_rtx_REG (Pmode, tmp_regno);
6280   gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno);
6281   emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx,
6282                                 label));
6283   emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
6284   emit_insn (ix86_gen_add3 (pic_offset_table_rtx,
6285                             pic_offset_table_rtx, tmp_reg));
6286 }
6287
6288 /* Create and initialize PIC register if required.  */
6289 static void
6290 ix86_init_pic_reg (void)
6291 {
6292   edge entry_edge;
6293   rtx_insn *seq;
6294
6295   if (!ix86_use_pseudo_pic_reg ())
6296     return;
6297
6298   start_sequence ();
6299
6300   if (TARGET_64BIT)
6301     {
6302       if (ix86_cmodel == CM_LARGE_PIC)
6303         ix86_init_large_pic_reg (R11_REG);
6304       else
6305         emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
6306     }
6307   else
6308     {
6309       /*  If there is future mcount call in the function it is more profitable
6310           to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM.  */
6311       rtx reg = crtl->profile
6312                 ? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM)
6313                 : pic_offset_table_rtx;
6314       rtx insn = emit_insn (gen_set_got (reg));
6315       RTX_FRAME_RELATED_P (insn) = 1;
6316       if (crtl->profile)
6317         emit_move_insn (pic_offset_table_rtx, reg);
6318       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
6319     }
6320
6321   seq = get_insns ();
6322   end_sequence ();
6323
6324   entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6325   insert_insn_on_edge (seq, entry_edge);
6326   commit_one_edge_insertion (entry_edge);
6327 }
6328
6329 /* Initialize a variable CUM of type CUMULATIVE_ARGS
6330    for a call to a function whose data type is FNTYPE.
6331    For a library call, FNTYPE is 0.  */
6332
6333 void
6334 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
6335                       tree fntype,      /* tree ptr for function decl */
6336                       rtx libname,      /* SYMBOL_REF of library name or 0 */
6337                       tree fndecl,
6338                       int caller)
6339 {
6340   struct cgraph_local_info *i;
6341
6342   memset (cum, 0, sizeof (*cum));
6343
6344   if (fndecl)
6345     {
6346       i = cgraph_node::local_info (fndecl);
6347       cum->call_abi = ix86_function_abi (fndecl);
6348     }
6349   else
6350     {
6351       i = NULL;
6352       cum->call_abi = ix86_function_type_abi (fntype);
6353     }
6354
6355   cum->caller = caller;
6356
6357   /* Set up the number of registers to use for passing arguments.  */
6358   cum->nregs = ix86_regparm;
6359   if (TARGET_64BIT)
6360     {
6361       cum->nregs = (cum->call_abi == SYSV_ABI
6362                    ? X86_64_REGPARM_MAX
6363                    : X86_64_MS_REGPARM_MAX);
6364     }
6365   if (TARGET_SSE)
6366     {
6367       cum->sse_nregs = SSE_REGPARM_MAX;
6368       if (TARGET_64BIT)
6369         {
6370           cum->sse_nregs = (cum->call_abi == SYSV_ABI
6371                            ? X86_64_SSE_REGPARM_MAX
6372                            : X86_64_MS_SSE_REGPARM_MAX);
6373         }
6374     }
6375   if (TARGET_MMX)
6376     cum->mmx_nregs = MMX_REGPARM_MAX;
6377   cum->warn_avx512f = true;
6378   cum->warn_avx = true;
6379   cum->warn_sse = true;
6380   cum->warn_mmx = true;
6381
6382   /* Because type might mismatch in between caller and callee, we need to
6383      use actual type of function for local calls.
6384      FIXME: cgraph_analyze can be told to actually record if function uses
6385      va_start so for local functions maybe_vaarg can be made aggressive
6386      helping K&R code.
6387      FIXME: once typesytem is fixed, we won't need this code anymore.  */
6388   if (i && i->local && i->can_change_signature)
6389     fntype = TREE_TYPE (fndecl);
6390   cum->stdarg = stdarg_p (fntype);
6391   cum->maybe_vaarg = (fntype
6392                       ? (!prototype_p (fntype) || stdarg_p (fntype))
6393                       : !libname);
6394
6395   cum->bnd_regno = FIRST_BND_REG;
6396   cum->bnds_in_bt = 0;
6397   cum->force_bnd_pass = 0;
6398
6399   if (!TARGET_64BIT)
6400     {
6401       /* If there are variable arguments, then we won't pass anything
6402          in registers in 32-bit mode. */
6403       if (stdarg_p (fntype))
6404         {
6405           cum->nregs = 0;
6406           cum->sse_nregs = 0;
6407           cum->mmx_nregs = 0;
6408           cum->warn_avx512f = false;
6409           cum->warn_avx = false;
6410           cum->warn_sse = false;
6411           cum->warn_mmx = false;
6412           return;
6413         }
6414
6415       /* Use ecx and edx registers if function has fastcall attribute,
6416          else look for regparm information.  */
6417       if (fntype)
6418         {
6419           unsigned int ccvt = ix86_get_callcvt (fntype);
6420           if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
6421             {
6422               cum->nregs = 1;
6423               cum->fastcall = 1; /* Same first register as in fastcall.  */
6424             }
6425           else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
6426             {
6427               cum->nregs = 2;
6428               cum->fastcall = 1;
6429             }
6430           else
6431             cum->nregs = ix86_function_regparm (fntype, fndecl);
6432         }
6433
6434       /* Set up the number of SSE registers used for passing SFmode
6435          and DFmode arguments.  Warn for mismatching ABI.  */
6436       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
6437     }
6438 }
6439
6440 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
6441    But in the case of vector types, it is some vector mode.
6442
6443    When we have only some of our vector isa extensions enabled, then there
6444    are some modes for which vector_mode_supported_p is false.  For these
6445    modes, the generic vector support in gcc will choose some non-vector mode
6446    in order to implement the type.  By computing the natural mode, we'll
6447    select the proper ABI location for the operand and not depend on whatever
6448    the middle-end decides to do with these vector types.
6449
6450    The midde-end can't deal with the vector types > 16 bytes.  In this
6451    case, we return the original mode and warn ABI change if CUM isn't
6452    NULL. 
6453
6454    If INT_RETURN is true, warn ABI change if the vector mode isn't
6455    available for function return value.  */
6456
6457 static machine_mode
6458 type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum,
6459                    bool in_return)
6460 {
6461   machine_mode mode = TYPE_MODE (type);
6462
6463   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
6464     {
6465       HOST_WIDE_INT size = int_size_in_bytes (type);
6466       if ((size == 8 || size == 16 || size == 32 || size == 64)
6467           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
6468           && TYPE_VECTOR_SUBPARTS (type) > 1)
6469         {
6470           machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
6471
6472           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6473             mode = MIN_MODE_VECTOR_FLOAT;
6474           else
6475             mode = MIN_MODE_VECTOR_INT;
6476
6477           /* Get the mode which has this inner mode and number of units.  */
6478           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
6479             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
6480                 && GET_MODE_INNER (mode) == innermode)
6481               {
6482                 if (size == 64 && !TARGET_AVX512F)
6483                   {
6484                     static bool warnedavx512f;
6485                     static bool warnedavx512f_ret;
6486
6487                     if (cum && cum->warn_avx512f && !warnedavx512f)
6488                       {
6489                         if (warning (OPT_Wpsabi, "AVX512F vector argument "
6490                                      "without AVX512F enabled changes the ABI"))
6491                           warnedavx512f = true;
6492                       }
6493                     else if (in_return && !warnedavx512f_ret)
6494                       {
6495                         if (warning (OPT_Wpsabi, "AVX512F vector return "
6496                                      "without AVX512F enabled changes the ABI"))
6497                           warnedavx512f_ret = true;
6498                       }
6499
6500                     return TYPE_MODE (type);
6501                   }
6502                 else if (size == 32 && !TARGET_AVX)
6503                   {
6504                     static bool warnedavx;
6505                     static bool warnedavx_ret;
6506
6507                     if (cum && cum->warn_avx && !warnedavx)
6508                       {
6509                         if (warning (OPT_Wpsabi, "AVX vector argument "
6510                                      "without AVX enabled changes the ABI"))
6511                           warnedavx = true;
6512                       }
6513                     else if (in_return && !warnedavx_ret)
6514                       {
6515                         if (warning (OPT_Wpsabi, "AVX vector return "
6516                                      "without AVX enabled changes the ABI"))
6517                           warnedavx_ret = true;
6518                       }
6519
6520                     return TYPE_MODE (type);
6521                   }
6522                 else if (((size == 8 && TARGET_64BIT) || size == 16)
6523                          && !TARGET_SSE)
6524                   {
6525                     static bool warnedsse;
6526                     static bool warnedsse_ret;
6527
6528                     if (cum && cum->warn_sse && !warnedsse)
6529                       {
6530                         if (warning (OPT_Wpsabi, "SSE vector argument "
6531                                      "without SSE enabled changes the ABI"))
6532                           warnedsse = true;
6533                       }
6534                     else if (!TARGET_64BIT && in_return && !warnedsse_ret)
6535                       {
6536                         if (warning (OPT_Wpsabi, "SSE vector return "
6537                                      "without SSE enabled changes the ABI"))
6538                           warnedsse_ret = true;
6539                       }
6540                   }
6541                 else if ((size == 8 && !TARGET_64BIT) && !TARGET_MMX)
6542                   {
6543                     static bool warnedmmx;
6544                     static bool warnedmmx_ret;
6545
6546                     if (cum && cum->warn_mmx && !warnedmmx)
6547                       {
6548                         if (warning (OPT_Wpsabi, "MMX vector argument "
6549                                      "without MMX enabled changes the ABI"))
6550                           warnedmmx = true;
6551                       }
6552                     else if (in_return && !warnedmmx_ret)
6553                       {
6554                         if (warning (OPT_Wpsabi, "MMX vector return "
6555                                      "without MMX enabled changes the ABI"))
6556                           warnedmmx_ret = true;
6557                       }
6558                   }
6559                 return mode;
6560               }
6561
6562           gcc_unreachable ();
6563         }
6564     }
6565
6566   return mode;
6567 }
6568
6569 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
6570    this may not agree with the mode that the type system has chosen for the
6571    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
6572    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
6573
6574 static rtx
6575 gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode,
6576                      unsigned int regno)
6577 {
6578   rtx tmp;
6579
6580   if (orig_mode != BLKmode)
6581     tmp = gen_rtx_REG (orig_mode, regno);
6582   else
6583     {
6584       tmp = gen_rtx_REG (mode, regno);
6585       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
6586       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
6587     }
6588
6589   return tmp;
6590 }
6591
6592 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
6593    of this code is to classify each 8bytes of incoming argument by the register
6594    class and assign registers accordingly.  */
6595
6596 /* Return the union class of CLASS1 and CLASS2.
6597    See the x86-64 PS ABI for details.  */
6598
6599 static enum x86_64_reg_class
6600 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
6601 {
6602   /* Rule #1: If both classes are equal, this is the resulting class.  */
6603   if (class1 == class2)
6604     return class1;
6605
6606   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
6607      the other class.  */
6608   if (class1 == X86_64_NO_CLASS)
6609     return class2;
6610   if (class2 == X86_64_NO_CLASS)
6611     return class1;
6612
6613   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
6614   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
6615     return X86_64_MEMORY_CLASS;
6616
6617   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
6618   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
6619       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
6620     return X86_64_INTEGERSI_CLASS;
6621   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
6622       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
6623     return X86_64_INTEGER_CLASS;
6624
6625   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
6626      MEMORY is used.  */
6627   if (class1 == X86_64_X87_CLASS
6628       || class1 == X86_64_X87UP_CLASS
6629       || class1 == X86_64_COMPLEX_X87_CLASS
6630       || class2 == X86_64_X87_CLASS
6631       || class2 == X86_64_X87UP_CLASS
6632       || class2 == X86_64_COMPLEX_X87_CLASS)
6633     return X86_64_MEMORY_CLASS;
6634
6635   /* Rule #6: Otherwise class SSE is used.  */
6636   return X86_64_SSE_CLASS;
6637 }
6638
6639 /* Classify the argument of type TYPE and mode MODE.
6640    CLASSES will be filled by the register class used to pass each word
6641    of the operand.  The number of words is returned.  In case the parameter
6642    should be passed in memory, 0 is returned. As a special case for zero
6643    sized containers, classes[0] will be NO_CLASS and 1 is returned.
6644
6645    BIT_OFFSET is used internally for handling records and specifies offset
6646    of the offset in bits modulo 512 to avoid overflow cases.
6647
6648    See the x86-64 PS ABI for details.
6649 */
6650
6651 static int
6652 classify_argument (machine_mode mode, const_tree type,
6653                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
6654 {
6655   HOST_WIDE_INT bytes =
6656     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
6657   int words
6658     = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6659
6660   /* Variable sized entities are always passed/returned in memory.  */
6661   if (bytes < 0)
6662     return 0;
6663
6664   if (mode != VOIDmode
6665       && targetm.calls.must_pass_in_stack (mode, type))
6666     return 0;
6667
6668   if (type && AGGREGATE_TYPE_P (type))
6669     {
6670       int i;
6671       tree field;
6672       enum x86_64_reg_class subclasses[MAX_CLASSES];
6673
6674       /* On x86-64 we pass structures larger than 64 bytes on the stack.  */
6675       if (bytes > 64)
6676         return 0;
6677
6678       for (i = 0; i < words; i++)
6679         classes[i] = X86_64_NO_CLASS;
6680
6681       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
6682          signalize memory class, so handle it as special case.  */
6683       if (!words)
6684         {
6685           classes[0] = X86_64_NO_CLASS;
6686           return 1;
6687         }
6688
6689       /* Classify each field of record and merge classes.  */
6690       switch (TREE_CODE (type))
6691         {
6692         case RECORD_TYPE:
6693           /* And now merge the fields of structure.  */
6694           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6695             {
6696               if (TREE_CODE (field) == FIELD_DECL)
6697                 {
6698                   int num;
6699
6700                   if (TREE_TYPE (field) == error_mark_node)
6701                     continue;
6702
6703                   /* Bitfields are always classified as integer.  Handle them
6704                      early, since later code would consider them to be
6705                      misaligned integers.  */
6706                   if (DECL_BIT_FIELD (field))
6707                     {
6708                       for (i = (int_bit_position (field)
6709                                 + (bit_offset % 64)) / 8 / 8;
6710                            i < ((int_bit_position (field) + (bit_offset % 64))
6711                                 + tree_to_shwi (DECL_SIZE (field))
6712                                 + 63) / 8 / 8; i++)
6713                         classes[i] =
6714                           merge_classes (X86_64_INTEGER_CLASS,
6715                                          classes[i]);
6716                     }
6717                   else
6718                     {
6719                       int pos;
6720
6721                       type = TREE_TYPE (field);
6722
6723                       /* Flexible array member is ignored.  */
6724                       if (TYPE_MODE (type) == BLKmode
6725                           && TREE_CODE (type) == ARRAY_TYPE
6726                           && TYPE_SIZE (type) == NULL_TREE
6727                           && TYPE_DOMAIN (type) != NULL_TREE
6728                           && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6729                               == NULL_TREE))
6730                         {
6731                           static bool warned;
6732
6733                           if (!warned && warn_psabi)
6734                             {
6735                               warned = true;
6736                               inform (input_location,
6737                                       "the ABI of passing struct with"
6738                                       " a flexible array member has"
6739                                       " changed in GCC 4.4");
6740                             }
6741                           continue;
6742                         }
6743                       num = classify_argument (TYPE_MODE (type), type,
6744                                                subclasses,
6745                                                (int_bit_position (field)
6746                                                 + bit_offset) % 512);
6747                       if (!num)
6748                         return 0;
6749                       pos = (int_bit_position (field)
6750                              + (bit_offset % 64)) / 8 / 8;
6751                       for (i = 0; i < num && (i + pos) < words; i++)
6752                         classes[i + pos] =
6753                           merge_classes (subclasses[i], classes[i + pos]);
6754                     }
6755                 }
6756             }
6757           break;
6758
6759         case ARRAY_TYPE:
6760           /* Arrays are handled as small records.  */
6761           {
6762             int num;
6763             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
6764                                      TREE_TYPE (type), subclasses, bit_offset);
6765             if (!num)
6766               return 0;
6767
6768             /* The partial classes are now full classes.  */
6769             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
6770               subclasses[0] = X86_64_SSE_CLASS;
6771             if (subclasses[0] == X86_64_INTEGERSI_CLASS
6772                 && !((bit_offset % 64) == 0 && bytes == 4))
6773               subclasses[0] = X86_64_INTEGER_CLASS;
6774
6775             for (i = 0; i < words; i++)
6776               classes[i] = subclasses[i % num];
6777
6778             break;
6779           }
6780         case UNION_TYPE:
6781         case QUAL_UNION_TYPE:
6782           /* Unions are similar to RECORD_TYPE but offset is always 0.
6783              */
6784           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6785             {
6786               if (TREE_CODE (field) == FIELD_DECL)
6787                 {
6788                   int num;
6789
6790                   if (TREE_TYPE (field) == error_mark_node)
6791                     continue;
6792
6793                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
6794                                            TREE_TYPE (field), subclasses,
6795                                            bit_offset);
6796                   if (!num)
6797                     return 0;
6798                   for (i = 0; i < num && i < words; i++)
6799                     classes[i] = merge_classes (subclasses[i], classes[i]);
6800                 }
6801             }
6802           break;
6803
6804         default:
6805           gcc_unreachable ();
6806         }
6807
6808       if (words > 2)
6809         {
6810           /* When size > 16 bytes, if the first one isn't
6811              X86_64_SSE_CLASS or any other ones aren't
6812              X86_64_SSEUP_CLASS, everything should be passed in
6813              memory.  */
6814           if (classes[0] != X86_64_SSE_CLASS)
6815               return 0;
6816
6817           for (i = 1; i < words; i++)
6818             if (classes[i] != X86_64_SSEUP_CLASS)
6819               return 0;
6820         }
6821
6822       /* Final merger cleanup.  */
6823       for (i = 0; i < words; i++)
6824         {
6825           /* If one class is MEMORY, everything should be passed in
6826              memory.  */
6827           if (classes[i] == X86_64_MEMORY_CLASS)
6828             return 0;
6829
6830           /* The X86_64_SSEUP_CLASS should be always preceded by
6831              X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
6832           if (classes[i] == X86_64_SSEUP_CLASS
6833               && classes[i - 1] != X86_64_SSE_CLASS
6834               && classes[i - 1] != X86_64_SSEUP_CLASS)
6835             {
6836               /* The first one should never be X86_64_SSEUP_CLASS.  */
6837               gcc_assert (i != 0);
6838               classes[i] = X86_64_SSE_CLASS;
6839             }
6840
6841           /*  If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
6842                everything should be passed in memory.  */
6843           if (classes[i] == X86_64_X87UP_CLASS
6844               && (classes[i - 1] != X86_64_X87_CLASS))
6845             {
6846               static bool warned;
6847
6848               /* The first one should never be X86_64_X87UP_CLASS.  */
6849               gcc_assert (i != 0);
6850               if (!warned && warn_psabi)
6851                 {
6852                   warned = true;
6853                   inform (input_location,
6854                           "the ABI of passing union with long double"
6855                           " has changed in GCC 4.4");
6856                 }
6857               return 0;
6858             }
6859         }
6860       return words;
6861     }
6862
6863   /* Compute alignment needed.  We align all types to natural boundaries with
6864      exception of XFmode that is aligned to 64bits.  */
6865   if (mode != VOIDmode && mode != BLKmode)
6866     {
6867       int mode_alignment = GET_MODE_BITSIZE (mode);
6868
6869       if (mode == XFmode)
6870         mode_alignment = 128;
6871       else if (mode == XCmode)
6872         mode_alignment = 256;
6873       if (COMPLEX_MODE_P (mode))
6874         mode_alignment /= 2;
6875       /* Misaligned fields are always returned in memory.  */
6876       if (bit_offset % mode_alignment)
6877         return 0;
6878     }
6879
6880   /* for V1xx modes, just use the base mode */
6881   if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode
6882       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
6883     mode = GET_MODE_INNER (mode);
6884
6885   /* Classification of atomic types.  */
6886   switch (mode)
6887     {
6888     case SDmode:
6889     case DDmode:
6890       classes[0] = X86_64_SSE_CLASS;
6891       return 1;
6892     case TDmode:
6893       classes[0] = X86_64_SSE_CLASS;
6894       classes[1] = X86_64_SSEUP_CLASS;
6895       return 2;
6896     case DImode:
6897     case SImode:
6898     case HImode:
6899     case QImode:
6900     case CSImode:
6901     case CHImode:
6902     case CQImode:
6903       {
6904         int size = bit_offset + (int) GET_MODE_BITSIZE (mode);
6905
6906         /* Analyze last 128 bits only.  */
6907         size = (size - 1) & 0x7f;
6908
6909         if (size < 32)
6910           {
6911             classes[0] = X86_64_INTEGERSI_CLASS;
6912             return 1;
6913           }
6914         else if (size < 64)
6915           {
6916             classes[0] = X86_64_INTEGER_CLASS;
6917             return 1;
6918           }
6919         else if (size < 64+32)
6920           {
6921             classes[0] = X86_64_INTEGER_CLASS;
6922             classes[1] = X86_64_INTEGERSI_CLASS;
6923             return 2;
6924           }
6925         else if (size < 64+64)
6926           {
6927             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
6928             return 2;
6929           }
6930         else
6931           gcc_unreachable ();
6932       }
6933     case CDImode:
6934     case TImode:
6935       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
6936       return 2;
6937     case COImode:
6938     case OImode:
6939       /* OImode shouldn't be used directly.  */
6940       gcc_unreachable ();
6941     case CTImode:
6942       return 0;
6943     case SFmode:
6944       if (!(bit_offset % 64))
6945         classes[0] = X86_64_SSESF_CLASS;
6946       else
6947         classes[0] = X86_64_SSE_CLASS;
6948       return 1;
6949     case DFmode:
6950       classes[0] = X86_64_SSEDF_CLASS;
6951       return 1;
6952     case XFmode:
6953       classes[0] = X86_64_X87_CLASS;
6954       classes[1] = X86_64_X87UP_CLASS;
6955       return 2;
6956     case TFmode:
6957       classes[0] = X86_64_SSE_CLASS;
6958       classes[1] = X86_64_SSEUP_CLASS;
6959       return 2;
6960     case SCmode:
6961       classes[0] = X86_64_SSE_CLASS;
6962       if (!(bit_offset % 64))
6963         return 1;
6964       else
6965         {
6966           static bool warned;
6967
6968           if (!warned && warn_psabi)
6969             {
6970               warned = true;
6971               inform (input_location,
6972                       "the ABI of passing structure with complex float"
6973                       " member has changed in GCC 4.4");
6974             }
6975           classes[1] = X86_64_SSESF_CLASS;
6976           return 2;
6977         }
6978     case DCmode:
6979       classes[0] = X86_64_SSEDF_CLASS;
6980       classes[1] = X86_64_SSEDF_CLASS;
6981       return 2;
6982     case XCmode:
6983       classes[0] = X86_64_COMPLEX_X87_CLASS;
6984       return 1;
6985     case TCmode:
6986       /* This modes is larger than 16 bytes.  */
6987       return 0;
6988     case V8SFmode:
6989     case V8SImode:
6990     case V32QImode:
6991     case V16HImode:
6992     case V4DFmode:
6993     case V4DImode:
6994       classes[0] = X86_64_SSE_CLASS;
6995       classes[1] = X86_64_SSEUP_CLASS;
6996       classes[2] = X86_64_SSEUP_CLASS;
6997       classes[3] = X86_64_SSEUP_CLASS;
6998       return 4;
6999     case V8DFmode:
7000     case V16SFmode:
7001     case V8DImode:
7002     case V16SImode:
7003     case V32HImode:
7004     case V64QImode:
7005       classes[0] = X86_64_SSE_CLASS;
7006       classes[1] = X86_64_SSEUP_CLASS;
7007       classes[2] = X86_64_SSEUP_CLASS;
7008       classes[3] = X86_64_SSEUP_CLASS;
7009       classes[4] = X86_64_SSEUP_CLASS;
7010       classes[5] = X86_64_SSEUP_CLASS;
7011       classes[6] = X86_64_SSEUP_CLASS;
7012       classes[7] = X86_64_SSEUP_CLASS;
7013       return 8;
7014     case V4SFmode:
7015     case V4SImode:
7016     case V16QImode:
7017     case V8HImode:
7018     case V2DFmode:
7019     case V2DImode:
7020       classes[0] = X86_64_SSE_CLASS;
7021       classes[1] = X86_64_SSEUP_CLASS;
7022       return 2;
7023     case V1TImode:
7024     case V1DImode:
7025     case V2SFmode:
7026     case V2SImode:
7027     case V4HImode:
7028     case V8QImode:
7029       classes[0] = X86_64_SSE_CLASS;
7030       return 1;
7031     case BLKmode:
7032     case VOIDmode:
7033       return 0;
7034     default:
7035       gcc_assert (VECTOR_MODE_P (mode));
7036
7037       if (bytes > 16)
7038         return 0;
7039
7040       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
7041
7042       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
7043         classes[0] = X86_64_INTEGERSI_CLASS;
7044       else
7045         classes[0] = X86_64_INTEGER_CLASS;
7046       classes[1] = X86_64_INTEGER_CLASS;
7047       return 1 + (bytes > 8);
7048     }
7049 }
7050
7051 /* Examine the argument and return set number of register required in each
7052    class.  Return true iff parameter should be passed in memory.  */
7053
7054 static bool
7055 examine_argument (machine_mode mode, const_tree type, int in_return,
7056                   int *int_nregs, int *sse_nregs)
7057 {
7058   enum x86_64_reg_class regclass[MAX_CLASSES];
7059   int n = classify_argument (mode, type, regclass, 0);
7060
7061   *int_nregs = 0;
7062   *sse_nregs = 0;
7063
7064   if (!n)
7065     return true;
7066   for (n--; n >= 0; n--)
7067     switch (regclass[n])
7068       {
7069       case X86_64_INTEGER_CLASS:
7070       case X86_64_INTEGERSI_CLASS:
7071         (*int_nregs)++;
7072         break;
7073       case X86_64_SSE_CLASS:
7074       case X86_64_SSESF_CLASS:
7075       case X86_64_SSEDF_CLASS:
7076         (*sse_nregs)++;
7077         break;
7078       case X86_64_NO_CLASS:
7079       case X86_64_SSEUP_CLASS:
7080         break;
7081       case X86_64_X87_CLASS:
7082       case X86_64_X87UP_CLASS:
7083       case X86_64_COMPLEX_X87_CLASS:
7084         if (!in_return)
7085           return true;
7086         break;
7087       case X86_64_MEMORY_CLASS:
7088         gcc_unreachable ();
7089       }
7090
7091   return false;
7092 }
7093
7094 /* Construct container for the argument used by GCC interface.  See
7095    FUNCTION_ARG for the detailed description.  */
7096
7097 static rtx
7098 construct_container (machine_mode mode, machine_mode orig_mode,
7099                      const_tree type, int in_return, int nintregs, int nsseregs,
7100                      const int *intreg, int sse_regno)
7101 {
7102   /* The following variables hold the static issued_error state.  */
7103   static bool issued_sse_arg_error;
7104   static bool issued_sse_ret_error;
7105   static bool issued_x87_ret_error;
7106
7107   machine_mode tmpmode;
7108   int bytes =
7109     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
7110   enum x86_64_reg_class regclass[MAX_CLASSES];
7111   int n;
7112   int i;
7113   int nexps = 0;
7114   int needed_sseregs, needed_intregs;
7115   rtx exp[MAX_CLASSES];
7116   rtx ret;
7117
7118   n = classify_argument (mode, type, regclass, 0);
7119   if (!n)
7120     return NULL;
7121   if (examine_argument (mode, type, in_return, &needed_intregs,
7122                         &needed_sseregs))
7123     return NULL;
7124   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
7125     return NULL;
7126
7127   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
7128      some less clueful developer tries to use floating-point anyway.  */
7129   if (needed_sseregs && !TARGET_SSE)
7130     {
7131       if (in_return)
7132         {
7133           if (!issued_sse_ret_error)
7134             {
7135               error ("SSE register return with SSE disabled");
7136               issued_sse_ret_error = true;
7137             }
7138         }
7139       else if (!issued_sse_arg_error)
7140         {
7141           error ("SSE register argument with SSE disabled");
7142           issued_sse_arg_error = true;
7143         }
7144       return NULL;
7145     }
7146
7147   /* Likewise, error if the ABI requires us to return values in the
7148      x87 registers and the user specified -mno-80387.  */
7149   if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return)
7150     for (i = 0; i < n; i++)
7151       if (regclass[i] == X86_64_X87_CLASS
7152           || regclass[i] == X86_64_X87UP_CLASS
7153           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
7154         {
7155           if (!issued_x87_ret_error)
7156             {
7157               error ("x87 register return with x87 disabled");
7158               issued_x87_ret_error = true;
7159             }
7160           return NULL;
7161         }
7162
7163   /* First construct simple cases.  Avoid SCmode, since we want to use
7164      single register to pass this type.  */
7165   if (n == 1 && mode != SCmode)
7166     switch (regclass[0])
7167       {
7168       case X86_64_INTEGER_CLASS:
7169       case X86_64_INTEGERSI_CLASS:
7170         return gen_rtx_REG (mode, intreg[0]);
7171       case X86_64_SSE_CLASS:
7172       case X86_64_SSESF_CLASS:
7173       case X86_64_SSEDF_CLASS:
7174         if (mode != BLKmode)
7175           return gen_reg_or_parallel (mode, orig_mode,
7176                                       SSE_REGNO (sse_regno));
7177         break;
7178       case X86_64_X87_CLASS:
7179       case X86_64_COMPLEX_X87_CLASS:
7180         return gen_rtx_REG (mode, FIRST_STACK_REG);
7181       case X86_64_NO_CLASS:
7182         /* Zero sized array, struct or class.  */
7183         return NULL;
7184       default:
7185         gcc_unreachable ();
7186       }
7187   if (n == 2
7188       && regclass[0] == X86_64_SSE_CLASS
7189       && regclass[1] == X86_64_SSEUP_CLASS
7190       && mode != BLKmode)
7191     return gen_reg_or_parallel (mode, orig_mode,
7192                                 SSE_REGNO (sse_regno));
7193   if (n == 4
7194       && regclass[0] == X86_64_SSE_CLASS
7195       && regclass[1] == X86_64_SSEUP_CLASS
7196       && regclass[2] == X86_64_SSEUP_CLASS
7197       && regclass[3] == X86_64_SSEUP_CLASS
7198       && mode != BLKmode)
7199     return gen_reg_or_parallel (mode, orig_mode,
7200                                 SSE_REGNO (sse_regno));
7201   if (n == 8
7202       && regclass[0] == X86_64_SSE_CLASS
7203       && regclass[1] == X86_64_SSEUP_CLASS
7204       && regclass[2] == X86_64_SSEUP_CLASS
7205       && regclass[3] == X86_64_SSEUP_CLASS
7206       && regclass[4] == X86_64_SSEUP_CLASS
7207       && regclass[5] == X86_64_SSEUP_CLASS
7208       && regclass[6] == X86_64_SSEUP_CLASS
7209       && regclass[7] == X86_64_SSEUP_CLASS
7210       && mode != BLKmode)
7211     return gen_reg_or_parallel (mode, orig_mode,
7212                                 SSE_REGNO (sse_regno));
7213   if (n == 2
7214       && regclass[0] == X86_64_X87_CLASS
7215       && regclass[1] == X86_64_X87UP_CLASS)
7216     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
7217
7218   if (n == 2
7219       && regclass[0] == X86_64_INTEGER_CLASS
7220       && regclass[1] == X86_64_INTEGER_CLASS
7221       && (mode == CDImode || mode == TImode)
7222       && intreg[0] + 1 == intreg[1])
7223     return gen_rtx_REG (mode, intreg[0]);
7224
7225   /* Otherwise figure out the entries of the PARALLEL.  */
7226   for (i = 0; i < n; i++)
7227     {
7228       int pos;
7229
7230       switch (regclass[i])
7231         {
7232           case X86_64_NO_CLASS:
7233             break;
7234           case X86_64_INTEGER_CLASS:
7235           case X86_64_INTEGERSI_CLASS:
7236             /* Merge TImodes on aligned occasions here too.  */
7237             if (i * 8 + 8 > bytes)
7238               tmpmode
7239                 = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
7240             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
7241               tmpmode = SImode;
7242             else
7243               tmpmode = DImode;
7244             /* We've requested 24 bytes we
7245                don't have mode for.  Use DImode.  */
7246             if (tmpmode == BLKmode)
7247               tmpmode = DImode;
7248             exp [nexps++]
7249               = gen_rtx_EXPR_LIST (VOIDmode,
7250                                    gen_rtx_REG (tmpmode, *intreg),
7251                                    GEN_INT (i*8));
7252             intreg++;
7253             break;
7254           case X86_64_SSESF_CLASS:
7255             exp [nexps++]
7256               = gen_rtx_EXPR_LIST (VOIDmode,
7257                                    gen_rtx_REG (SFmode,
7258                                                 SSE_REGNO (sse_regno)),
7259                                    GEN_INT (i*8));
7260             sse_regno++;
7261             break;
7262           case X86_64_SSEDF_CLASS:
7263             exp [nexps++]
7264               = gen_rtx_EXPR_LIST (VOIDmode,
7265                                    gen_rtx_REG (DFmode,
7266                                                 SSE_REGNO (sse_regno)),
7267                                    GEN_INT (i*8));
7268             sse_regno++;
7269             break;
7270           case X86_64_SSE_CLASS:
7271             pos = i;
7272             switch (n)
7273               {
7274               case 1:
7275                 tmpmode = DImode;
7276                 break;
7277               case 2:
7278                 if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
7279                   {
7280                     tmpmode = TImode;
7281                     i++;
7282                   }
7283                 else
7284                   tmpmode = DImode;
7285                 break;
7286               case 4:
7287                 gcc_assert (i == 0
7288                             && regclass[1] == X86_64_SSEUP_CLASS
7289                             && regclass[2] == X86_64_SSEUP_CLASS
7290                             && regclass[3] == X86_64_SSEUP_CLASS);
7291                 tmpmode = OImode;
7292                 i += 3;
7293                 break;
7294               case 8:
7295                 gcc_assert (i == 0
7296                             && regclass[1] == X86_64_SSEUP_CLASS
7297                             && regclass[2] == X86_64_SSEUP_CLASS
7298                             && regclass[3] == X86_64_SSEUP_CLASS
7299                             && regclass[4] == X86_64_SSEUP_CLASS
7300                             && regclass[5] == X86_64_SSEUP_CLASS
7301                             && regclass[6] == X86_64_SSEUP_CLASS
7302                             && regclass[7] == X86_64_SSEUP_CLASS);
7303                 tmpmode = XImode;
7304                 i += 7;
7305                 break;
7306               default:
7307                 gcc_unreachable ();
7308               }
7309             exp [nexps++]
7310               = gen_rtx_EXPR_LIST (VOIDmode,
7311                                    gen_rtx_REG (tmpmode,
7312                                                 SSE_REGNO (sse_regno)),
7313                                    GEN_INT (pos*8));
7314             sse_regno++;
7315             break;
7316           default:
7317             gcc_unreachable ();
7318         }
7319     }
7320
7321   /* Empty aligned struct, union or class.  */
7322   if (nexps == 0)
7323     return NULL;
7324
7325   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
7326   for (i = 0; i < nexps; i++)
7327     XVECEXP (ret, 0, i) = exp [i];
7328   return ret;
7329 }
7330
7331 /* Update the data in CUM to advance over an argument of mode MODE
7332    and data type TYPE.  (TYPE is null for libcalls where that information
7333    may not be available.)
7334
7335    Return a number of integer regsiters advanced over.  */
7336
7337 static int
7338 function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
7339                          const_tree type, HOST_WIDE_INT bytes,
7340                          HOST_WIDE_INT words)
7341 {
7342   int res = 0;
7343
7344   switch (mode)
7345     {
7346     default:
7347       break;
7348
7349     case BLKmode:
7350       if (bytes < 0)
7351         break;
7352       /* FALLTHRU */
7353
7354     case DImode:
7355     case SImode:
7356     case HImode:
7357     case QImode:
7358       cum->words += words;
7359       cum->nregs -= words;
7360       cum->regno += words;
7361       if (cum->nregs >= 0)
7362         res = words;
7363       if (cum->nregs <= 0)
7364         {
7365           cum->nregs = 0;
7366           cum->regno = 0;
7367         }
7368       break;
7369
7370     case OImode:
7371       /* OImode shouldn't be used directly.  */
7372       gcc_unreachable ();
7373
7374     case DFmode:
7375       if (cum->float_in_sse < 2)
7376         break;
7377     case SFmode:
7378       if (cum->float_in_sse < 1)
7379         break;
7380       /* FALLTHRU */
7381
7382     case V8SFmode:
7383     case V8SImode:
7384     case V64QImode:
7385     case V32HImode:
7386     case V16SImode:
7387     case V8DImode:
7388     case V16SFmode:
7389     case V8DFmode:
7390     case V32QImode:
7391     case V16HImode:
7392     case V4DFmode:
7393     case V4DImode:
7394     case TImode:
7395     case V16QImode:
7396     case V8HImode:
7397     case V4SImode:
7398     case V2DImode:
7399     case V4SFmode:
7400     case V2DFmode:
7401       if (!type || !AGGREGATE_TYPE_P (type))
7402         {
7403           cum->sse_words += words;
7404           cum->sse_nregs -= 1;
7405           cum->sse_regno += 1;
7406           if (cum->sse_nregs <= 0)
7407             {
7408               cum->sse_nregs = 0;
7409               cum->sse_regno = 0;
7410             }
7411         }
7412       break;
7413
7414     case V8QImode:
7415     case V4HImode:
7416     case V2SImode:
7417     case V2SFmode:
7418     case V1TImode:
7419     case V1DImode:
7420       if (!type || !AGGREGATE_TYPE_P (type))
7421         {
7422           cum->mmx_words += words;
7423           cum->mmx_nregs -= 1;
7424           cum->mmx_regno += 1;
7425           if (cum->mmx_nregs <= 0)
7426             {
7427               cum->mmx_nregs = 0;
7428               cum->mmx_regno = 0;
7429             }
7430         }
7431       break;
7432     }
7433
7434   return res;
7435 }
7436
7437 static int
7438 function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode,
7439                          const_tree type, HOST_WIDE_INT words, bool named)
7440 {
7441   int int_nregs, sse_nregs;
7442
7443   /* Unnamed 512 and 256bit vector mode parameters are passed on stack.  */
7444   if (!named && (VALID_AVX512F_REG_MODE (mode)
7445                  || VALID_AVX256_REG_MODE (mode)))
7446     return 0;
7447
7448   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
7449       && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
7450     {
7451       cum->nregs -= int_nregs;
7452       cum->sse_nregs -= sse_nregs;
7453       cum->regno += int_nregs;
7454       cum->sse_regno += sse_nregs;
7455       return int_nregs;
7456     }
7457   else
7458     {
7459       int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
7460       cum->words = (cum->words + align - 1) & ~(align - 1);
7461       cum->words += words;
7462       return 0;
7463     }
7464 }
7465
7466 static int
7467 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
7468                             HOST_WIDE_INT words)
7469 {
7470   /* Otherwise, this should be passed indirect.  */
7471   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
7472
7473   cum->words += words;
7474   if (cum->nregs > 0)
7475     {
7476       cum->nregs -= 1;
7477       cum->regno += 1;
7478       return 1;
7479     }
7480   return 0;
7481 }
7482
7483 /* Update the data in CUM to advance over an argument of mode MODE and
7484    data type TYPE.  (TYPE is null for libcalls where that information
7485    may not be available.)  */
7486
7487 static void
7488 ix86_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
7489                            const_tree type, bool named)
7490 {
7491   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7492   HOST_WIDE_INT bytes, words;
7493   int nregs;
7494
7495   if (mode == BLKmode)
7496     bytes = int_size_in_bytes (type);
7497   else
7498     bytes = GET_MODE_SIZE (mode);
7499   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7500
7501   if (type)
7502     mode = type_natural_mode (type, NULL, false);
7503
7504   if ((type && POINTER_BOUNDS_TYPE_P (type))
7505       || POINTER_BOUNDS_MODE_P (mode))
7506     {
7507       /* If we pass bounds in BT then just update remained bounds count.  */
7508       if (cum->bnds_in_bt)
7509         {
7510           cum->bnds_in_bt--;
7511           return;
7512         }
7513
7514       /* Update remained number of bounds to force.  */
7515       if (cum->force_bnd_pass)
7516         cum->force_bnd_pass--;
7517
7518       cum->bnd_regno++;
7519
7520       return;
7521     }
7522
7523   /* The first arg not going to Bounds Tables resets this counter.  */
7524   cum->bnds_in_bt = 0;
7525   /* For unnamed args we always pass bounds to avoid bounds mess when
7526      passed and received types do not match.  If bounds do not follow
7527      unnamed arg, still pretend required number of bounds were passed.  */
7528   if (cum->force_bnd_pass)
7529     {
7530       cum->bnd_regno += cum->force_bnd_pass;
7531       cum->force_bnd_pass = 0;
7532     }
7533
7534   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7535     nregs = function_arg_advance_ms_64 (cum, bytes, words);
7536   else if (TARGET_64BIT)
7537     nregs = function_arg_advance_64 (cum, mode, type, words, named);
7538   else
7539     nregs = function_arg_advance_32 (cum, mode, type, bytes, words);
7540
7541   /* For stdarg we expect bounds to be passed for each value passed
7542      in register.  */
7543   if (cum->stdarg)
7544     cum->force_bnd_pass = nregs;
7545   /* For pointers passed in memory we expect bounds passed in Bounds
7546      Table.  */
7547   if (!nregs)
7548     cum->bnds_in_bt = chkp_type_bounds_count (type);
7549 }
7550
7551 /* Define where to put the arguments to a function.
7552    Value is zero to push the argument on the stack,
7553    or a hard register in which to store the argument.
7554
7555    MODE is the argument's machine mode.
7556    TYPE is the data type of the argument (as a tree).
7557     This is null for libcalls where that information may
7558     not be available.
7559    CUM is a variable of type CUMULATIVE_ARGS which gives info about
7560     the preceding args and about the function being called.
7561    NAMED is nonzero if this argument is a named parameter
7562     (otherwise it is an extra parameter matching an ellipsis).  */
7563
7564 static rtx
7565 function_arg_32 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7566                  machine_mode orig_mode, const_tree type,
7567                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
7568 {
7569   /* Avoid the AL settings for the Unix64 ABI.  */
7570   if (mode == VOIDmode)
7571     return constm1_rtx;
7572
7573   switch (mode)
7574     {
7575     default:
7576       break;
7577
7578     case BLKmode:
7579       if (bytes < 0)
7580         break;
7581       /* FALLTHRU */
7582     case DImode:
7583     case SImode:
7584     case HImode:
7585     case QImode:
7586       if (words <= cum->nregs)
7587         {
7588           int regno = cum->regno;
7589
7590           /* Fastcall allocates the first two DWORD (SImode) or
7591             smaller arguments to ECX and EDX if it isn't an
7592             aggregate type .  */
7593           if (cum->fastcall)
7594             {
7595               if (mode == BLKmode
7596                   || mode == DImode
7597                   || (type && AGGREGATE_TYPE_P (type)))
7598                 break;
7599
7600               /* ECX not EAX is the first allocated register.  */
7601               if (regno == AX_REG)
7602                 regno = CX_REG;
7603             }
7604           return gen_rtx_REG (mode, regno);
7605         }
7606       break;
7607
7608     case DFmode:
7609       if (cum->float_in_sse < 2)
7610         break;
7611     case SFmode:
7612       if (cum->float_in_sse < 1)
7613         break;
7614       /* FALLTHRU */
7615     case TImode:
7616       /* In 32bit, we pass TImode in xmm registers.  */
7617     case V16QImode:
7618     case V8HImode:
7619     case V4SImode:
7620     case V2DImode:
7621     case V4SFmode:
7622     case V2DFmode:
7623       if (!type || !AGGREGATE_TYPE_P (type))
7624         {
7625           if (cum->sse_nregs)
7626             return gen_reg_or_parallel (mode, orig_mode,
7627                                         cum->sse_regno + FIRST_SSE_REG);
7628         }
7629       break;
7630
7631     case OImode:
7632     case XImode:
7633       /* OImode and XImode shouldn't be used directly.  */
7634       gcc_unreachable ();
7635
7636     case V64QImode:
7637     case V32HImode:
7638     case V16SImode:
7639     case V8DImode:
7640     case V16SFmode:
7641     case V8DFmode:
7642     case V8SFmode:
7643     case V8SImode:
7644     case V32QImode:
7645     case V16HImode:
7646     case V4DFmode:
7647     case V4DImode:
7648       if (!type || !AGGREGATE_TYPE_P (type))
7649         {
7650           if (cum->sse_nregs)
7651             return gen_reg_or_parallel (mode, orig_mode,
7652                                         cum->sse_regno + FIRST_SSE_REG);
7653         }
7654       break;
7655
7656     case V8QImode:
7657     case V4HImode:
7658     case V2SImode:
7659     case V2SFmode:
7660     case V1TImode:
7661     case V1DImode:
7662       if (!type || !AGGREGATE_TYPE_P (type))
7663         {
7664           if (cum->mmx_nregs)
7665             return gen_reg_or_parallel (mode, orig_mode,
7666                                         cum->mmx_regno + FIRST_MMX_REG);
7667         }
7668       break;
7669     }
7670
7671   return NULL_RTX;
7672 }
7673
7674 static rtx
7675 function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7676                  machine_mode orig_mode, const_tree type, bool named)
7677 {
7678   /* Handle a hidden AL argument containing number of registers
7679      for varargs x86-64 functions.  */
7680   if (mode == VOIDmode)
7681     return GEN_INT (cum->maybe_vaarg
7682                     ? (cum->sse_nregs < 0
7683                        ? X86_64_SSE_REGPARM_MAX
7684                        : cum->sse_regno)
7685                     : -1);
7686
7687   switch (mode)
7688     {
7689     default:
7690       break;
7691
7692     case V8SFmode:
7693     case V8SImode:
7694     case V32QImode:
7695     case V16HImode:
7696     case V4DFmode:
7697     case V4DImode:
7698     case V16SFmode:
7699     case V16SImode:
7700     case V64QImode:
7701     case V32HImode:
7702     case V8DFmode:
7703     case V8DImode:
7704       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
7705       if (!named)
7706         return NULL;
7707       break;
7708     }
7709
7710   return construct_container (mode, orig_mode, type, 0, cum->nregs,
7711                               cum->sse_nregs,
7712                               &x86_64_int_parameter_registers [cum->regno],
7713                               cum->sse_regno);
7714 }
7715
7716 static rtx
7717 function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7718                     machine_mode orig_mode, bool named,
7719                     HOST_WIDE_INT bytes)
7720 {
7721   unsigned int regno;
7722
7723   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
7724      We use value of -2 to specify that current function call is MSABI.  */
7725   if (mode == VOIDmode)
7726     return GEN_INT (-2);
7727
7728   /* If we've run out of registers, it goes on the stack.  */
7729   if (cum->nregs == 0)
7730     return NULL_RTX;
7731
7732   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
7733
7734   /* Only floating point modes are passed in anything but integer regs.  */
7735   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
7736     {
7737       if (named)
7738         regno = cum->regno + FIRST_SSE_REG;
7739       else
7740         {
7741           rtx t1, t2;
7742
7743           /* Unnamed floating parameters are passed in both the
7744              SSE and integer registers.  */
7745           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
7746           t2 = gen_rtx_REG (mode, regno);
7747           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
7748           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
7749           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
7750         }
7751     }
7752   /* Handle aggregated types passed in register.  */
7753   if (orig_mode == BLKmode)
7754     {
7755       if (bytes > 0 && bytes <= 8)
7756         mode = (bytes > 4 ? DImode : SImode);
7757       if (mode == BLKmode)
7758         mode = DImode;
7759     }
7760
7761   return gen_reg_or_parallel (mode, orig_mode, regno);
7762 }
7763
7764 /* Return where to put the arguments to a function.
7765    Return zero to push the argument on the stack, or a hard register in which to store the argument.
7766
7767    MODE is the argument's machine mode.  TYPE is the data type of the
7768    argument.  It is null for libcalls where that information may not be
7769    available.  CUM gives information about the preceding args and about
7770    the function being called.  NAMED is nonzero if this argument is a
7771    named parameter (otherwise it is an extra parameter matching an
7772    ellipsis).  */
7773
7774 static rtx
7775 ix86_function_arg (cumulative_args_t cum_v, machine_mode omode,
7776                    const_tree type, bool named)
7777 {
7778   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7779   machine_mode mode = omode;
7780   HOST_WIDE_INT bytes, words;
7781   rtx arg;
7782
7783   /* All pointer bounds argumntas are handled separately here.  */
7784   if ((type && POINTER_BOUNDS_TYPE_P (type))
7785       || POINTER_BOUNDS_MODE_P (mode))
7786     {
7787       /* Return NULL if bounds are forced to go in Bounds Table.  */
7788       if (cum->bnds_in_bt)
7789         arg = NULL;
7790       /* Return the next available bound reg if any.  */
7791       else if (cum->bnd_regno <= LAST_BND_REG)
7792         arg = gen_rtx_REG (BNDmode, cum->bnd_regno);
7793       /* Return the next special slot number otherwise.  */
7794       else
7795         arg = GEN_INT (cum->bnd_regno - LAST_BND_REG - 1);
7796
7797       return arg;
7798     }
7799
7800   if (mode == BLKmode)
7801     bytes = int_size_in_bytes (type);
7802   else
7803     bytes = GET_MODE_SIZE (mode);
7804   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7805
7806   /* To simplify the code below, represent vector types with a vector mode
7807      even if MMX/SSE are not active.  */
7808   if (type && TREE_CODE (type) == VECTOR_TYPE)
7809     mode = type_natural_mode (type, cum, false);
7810
7811   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7812     arg = function_arg_ms_64 (cum, mode, omode, named, bytes);
7813   else if (TARGET_64BIT)
7814     arg = function_arg_64 (cum, mode, omode, type, named);
7815   else
7816     arg = function_arg_32 (cum, mode, omode, type, bytes, words);
7817
7818   return arg;
7819 }
7820
7821 /* A C expression that indicates when an argument must be passed by
7822    reference.  If nonzero for an argument, a copy of that argument is
7823    made in memory and a pointer to the argument is passed instead of
7824    the argument itself.  The pointer is passed in whatever way is
7825    appropriate for passing a pointer to that type.  */
7826
7827 static bool
7828 ix86_pass_by_reference (cumulative_args_t cum_v, machine_mode mode,
7829                         const_tree type, bool)
7830 {
7831   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7832
7833   /* See Windows x64 Software Convention.  */
7834   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7835     {
7836       int msize = (int) GET_MODE_SIZE (mode);
7837       if (type)
7838         {
7839           /* Arrays are passed by reference.  */
7840           if (TREE_CODE (type) == ARRAY_TYPE)
7841             return true;
7842
7843           if (AGGREGATE_TYPE_P (type))
7844             {
7845               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
7846                  are passed by reference.  */
7847               msize = int_size_in_bytes (type);
7848             }
7849         }
7850
7851       /* __m128 is passed by reference.  */
7852       switch (msize) {
7853       case 1: case 2: case 4: case 8:
7854         break;
7855       default:
7856         return true;
7857       }
7858     }
7859   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
7860     return 1;
7861
7862   return 0;
7863 }
7864
7865 /* Return true when TYPE should be 128bit aligned for 32bit argument
7866    passing ABI.  XXX: This function is obsolete and is only used for
7867    checking psABI compatibility with previous versions of GCC.  */
7868
7869 static bool
7870 ix86_compat_aligned_value_p (const_tree type)
7871 {
7872   machine_mode mode = TYPE_MODE (type);
7873   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
7874        || mode == TDmode
7875        || mode == TFmode
7876        || mode == TCmode)
7877       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
7878     return true;
7879   if (TYPE_ALIGN (type) < 128)
7880     return false;
7881
7882   if (AGGREGATE_TYPE_P (type))
7883     {
7884       /* Walk the aggregates recursively.  */
7885       switch (TREE_CODE (type))
7886         {
7887         case RECORD_TYPE:
7888         case UNION_TYPE:
7889         case QUAL_UNION_TYPE:
7890           {
7891             tree field;
7892
7893             /* Walk all the structure fields.  */
7894             for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
7895               {
7896                 if (TREE_CODE (field) == FIELD_DECL
7897                     && ix86_compat_aligned_value_p (TREE_TYPE (field)))
7898                   return true;
7899               }
7900             break;
7901           }
7902
7903         case ARRAY_TYPE:
7904           /* Just for use if some languages passes arrays by value.  */
7905           if (ix86_compat_aligned_value_p (TREE_TYPE (type)))
7906             return true;
7907           break;
7908
7909         default:
7910           gcc_unreachable ();
7911         }
7912     }
7913   return false;
7914 }
7915
7916 /* Return the alignment boundary for MODE and TYPE with alignment ALIGN.
7917    XXX: This function is obsolete and is only used for checking psABI
7918    compatibility with previous versions of GCC.  */
7919
7920 static unsigned int
7921 ix86_compat_function_arg_boundary (machine_mode mode,
7922                                    const_tree type, unsigned int align)
7923 {
7924   /* In 32bit, only _Decimal128 and __float128 are aligned to their
7925      natural boundaries.  */
7926   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
7927     {
7928       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
7929          make an exception for SSE modes since these require 128bit
7930          alignment.
7931
7932          The handling here differs from field_alignment.  ICC aligns MMX
7933          arguments to 4 byte boundaries, while structure fields are aligned
7934          to 8 byte boundaries.  */
7935       if (!type)
7936         {
7937           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
7938             align = PARM_BOUNDARY;
7939         }
7940       else
7941         {
7942           if (!ix86_compat_aligned_value_p (type))
7943             align = PARM_BOUNDARY;
7944         }
7945     }
7946   if (align > BIGGEST_ALIGNMENT)
7947     align = BIGGEST_ALIGNMENT;
7948   return align;
7949 }
7950
7951 /* Return true when TYPE should be 128bit aligned for 32bit argument
7952    passing ABI.  */
7953
7954 static bool
7955 ix86_contains_aligned_value_p (const_tree type)
7956 {
7957   machine_mode mode = TYPE_MODE (type);
7958
7959   if (mode == XFmode || mode == XCmode)
7960     return false;
7961
7962   if (TYPE_ALIGN (type) < 128)
7963     return false;
7964
7965   if (AGGREGATE_TYPE_P (type))
7966     {
7967       /* Walk the aggregates recursively.  */
7968       switch (TREE_CODE (type))
7969         {
7970         case RECORD_TYPE:
7971         case UNION_TYPE:
7972         case QUAL_UNION_TYPE:
7973           {
7974             tree field;
7975
7976             /* Walk all the structure fields.  */
7977             for (field = TYPE_FIELDS (type);
7978                  field;
7979                  field = DECL_CHAIN (field))
7980               {
7981                 if (TREE_CODE (field) == FIELD_DECL
7982                     && ix86_contains_aligned_value_p (TREE_TYPE (field)))
7983                   return true;
7984               }
7985             break;
7986           }
7987
7988         case ARRAY_TYPE:
7989           /* Just for use if some languages passes arrays by value.  */
7990           if (ix86_contains_aligned_value_p (TREE_TYPE (type)))
7991             return true;
7992           break;
7993
7994         default:
7995           gcc_unreachable ();
7996         }
7997     }
7998   else
7999     return TYPE_ALIGN (type) >= 128;
8000
8001   return false;
8002 }
8003
8004 /* Gives the alignment boundary, in bits, of an argument with the
8005    specified mode and type.  */
8006
8007 static unsigned int
8008 ix86_function_arg_boundary (machine_mode mode, const_tree type)
8009 {
8010   unsigned int align;
8011   if (type)
8012     {
8013       /* Since the main variant type is used for call, we convert it to
8014          the main variant type.  */
8015       type = TYPE_MAIN_VARIANT (type);
8016       align = TYPE_ALIGN (type);
8017     }
8018   else
8019     align = GET_MODE_ALIGNMENT (mode);
8020   if (align < PARM_BOUNDARY)
8021     align = PARM_BOUNDARY;
8022   else
8023     {
8024       static bool warned;
8025       unsigned int saved_align = align;
8026
8027       if (!TARGET_64BIT)
8028         {
8029           /* i386 ABI defines XFmode arguments to be 4 byte aligned.  */
8030           if (!type)
8031             {
8032               if (mode == XFmode || mode == XCmode)
8033                 align = PARM_BOUNDARY;
8034             }
8035           else if (!ix86_contains_aligned_value_p (type))
8036             align = PARM_BOUNDARY;
8037
8038           if (align < 128)
8039             align = PARM_BOUNDARY;
8040         }
8041
8042       if (warn_psabi
8043           && !warned
8044           && align != ix86_compat_function_arg_boundary (mode, type,
8045                                                          saved_align))
8046         {
8047           warned = true;
8048           inform (input_location,
8049                   "The ABI for passing parameters with %d-byte"
8050                   " alignment has changed in GCC 4.6",
8051                   align / BITS_PER_UNIT);
8052         }
8053     }
8054
8055   return align;
8056 }
8057
8058 /* Return true if N is a possible register number of function value.  */
8059
8060 static bool
8061 ix86_function_value_regno_p (const unsigned int regno)
8062 {
8063   switch (regno)
8064     {
8065     case AX_REG:
8066       return true;
8067     case DX_REG:
8068       return (!TARGET_64BIT || ix86_abi != MS_ABI);
8069     case DI_REG:
8070     case SI_REG:
8071       return TARGET_64BIT && ix86_abi != MS_ABI;
8072
8073     case FIRST_BND_REG:
8074       return chkp_function_instrumented_p (current_function_decl);
8075
8076       /* Complex values are returned in %st(0)/%st(1) pair.  */
8077     case ST0_REG:
8078     case ST1_REG:
8079       /* TODO: The function should depend on current function ABI but
8080        builtins.c would need updating then. Therefore we use the
8081        default ABI.  */
8082       if (TARGET_64BIT && ix86_abi == MS_ABI)
8083         return false;
8084       return TARGET_FLOAT_RETURNS_IN_80387;
8085
8086       /* Complex values are returned in %xmm0/%xmm1 pair.  */
8087     case XMM0_REG:
8088     case XMM1_REG:
8089       return TARGET_SSE;
8090
8091     case MM0_REG:
8092       if (TARGET_MACHO || TARGET_64BIT)
8093         return false;
8094       return TARGET_MMX;
8095     }
8096
8097   return false;
8098 }
8099
8100 /* Define how to find the value returned by a function.
8101    VALTYPE is the data type of the value (as a tree).
8102    If the precise function being called is known, FUNC is its FUNCTION_DECL;
8103    otherwise, FUNC is 0.  */
8104
8105 static rtx
8106 function_value_32 (machine_mode orig_mode, machine_mode mode,
8107                    const_tree fntype, const_tree fn)
8108 {
8109   unsigned int regno;
8110
8111   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
8112      we normally prevent this case when mmx is not available.  However
8113      some ABIs may require the result to be returned like DImode.  */
8114   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
8115     regno = FIRST_MMX_REG;
8116
8117   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
8118      we prevent this case when sse is not available.  However some ABIs
8119      may require the result to be returned like integer TImode.  */
8120   else if (mode == TImode
8121            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
8122     regno = FIRST_SSE_REG;
8123
8124   /* 32-byte vector modes in %ymm0.   */
8125   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
8126     regno = FIRST_SSE_REG;
8127
8128   /* 64-byte vector modes in %zmm0.   */
8129   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
8130     regno = FIRST_SSE_REG;
8131
8132   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
8133   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
8134     regno = FIRST_FLOAT_REG;
8135   else
8136     /* Most things go in %eax.  */
8137     regno = AX_REG;
8138
8139   /* Override FP return register with %xmm0 for local functions when
8140      SSE math is enabled or for functions with sseregparm attribute.  */
8141   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
8142     {
8143       int sse_level = ix86_function_sseregparm (fntype, fn, false);
8144       if ((sse_level >= 1 && mode == SFmode)
8145           || (sse_level == 2 && mode == DFmode))
8146         regno = FIRST_SSE_REG;
8147     }
8148
8149   /* OImode shouldn't be used directly.  */
8150   gcc_assert (mode != OImode);
8151
8152   return gen_rtx_REG (orig_mode, regno);
8153 }
8154
8155 static rtx
8156 function_value_64 (machine_mode orig_mode, machine_mode mode,
8157                    const_tree valtype)
8158 {
8159   rtx ret;
8160
8161   /* Handle libcalls, which don't provide a type node.  */
8162   if (valtype == NULL)
8163     {
8164       unsigned int regno;
8165
8166       switch (mode)
8167         {
8168         case SFmode:
8169         case SCmode:
8170         case DFmode:
8171         case DCmode:
8172         case TFmode:
8173         case SDmode:
8174         case DDmode:
8175         case TDmode:
8176           regno = FIRST_SSE_REG;
8177           break;
8178         case XFmode:
8179         case XCmode:
8180           regno = FIRST_FLOAT_REG;
8181           break;
8182         case TCmode:
8183           return NULL;
8184         default:
8185           regno = AX_REG;
8186         }
8187
8188       return gen_rtx_REG (mode, regno);
8189     }
8190   else if (POINTER_TYPE_P (valtype))
8191     {
8192       /* Pointers are always returned in word_mode.  */
8193       mode = word_mode;
8194     }
8195
8196   ret = construct_container (mode, orig_mode, valtype, 1,
8197                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
8198                              x86_64_int_return_registers, 0);
8199
8200   /* For zero sized structures, construct_container returns NULL, but we
8201      need to keep rest of compiler happy by returning meaningful value.  */
8202   if (!ret)
8203     ret = gen_rtx_REG (orig_mode, AX_REG);
8204
8205   return ret;
8206 }
8207
8208 static rtx
8209 function_value_ms_64 (machine_mode orig_mode, machine_mode mode,
8210                       const_tree valtype)
8211 {
8212   unsigned int regno = AX_REG;
8213
8214   if (TARGET_SSE)
8215     {
8216       switch (GET_MODE_SIZE (mode))
8217         {
8218         case 16:
8219           if (valtype != NULL_TREE
8220               && !VECTOR_INTEGER_TYPE_P (valtype)
8221               && !VECTOR_INTEGER_TYPE_P (valtype)
8222               && !INTEGRAL_TYPE_P (valtype)
8223               && !VECTOR_FLOAT_TYPE_P (valtype))
8224             break;
8225           if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
8226               && !COMPLEX_MODE_P (mode))
8227             regno = FIRST_SSE_REG;
8228           break;
8229         case 8:
8230         case 4:
8231           if (mode == SFmode || mode == DFmode)
8232             regno = FIRST_SSE_REG;
8233           break;
8234         default:
8235           break;
8236         }
8237     }
8238   return gen_rtx_REG (orig_mode, regno);
8239 }
8240
8241 static rtx
8242 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
8243                        machine_mode orig_mode, machine_mode mode)
8244 {
8245   const_tree fn, fntype;
8246
8247   fn = NULL_TREE;
8248   if (fntype_or_decl && DECL_P (fntype_or_decl))
8249     fn = fntype_or_decl;
8250   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
8251
8252   if ((valtype && POINTER_BOUNDS_TYPE_P (valtype))
8253       || POINTER_BOUNDS_MODE_P (mode))
8254     return gen_rtx_REG (BNDmode, FIRST_BND_REG);
8255   else if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
8256     return function_value_ms_64 (orig_mode, mode, valtype);
8257   else if (TARGET_64BIT)
8258     return function_value_64 (orig_mode, mode, valtype);
8259   else
8260     return function_value_32 (orig_mode, mode, fntype, fn);
8261 }
8262
8263 static rtx
8264 ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool)
8265 {
8266   machine_mode mode, orig_mode;
8267
8268   orig_mode = TYPE_MODE (valtype);
8269   mode = type_natural_mode (valtype, NULL, true);
8270   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
8271 }
8272
8273 /*  Return an RTX representing a place where a function returns
8274     or recieves pointer bounds or NULL if no bounds are returned.
8275
8276     VALTYPE is a data type of a value returned by the function.
8277
8278     FN_DECL_OR_TYPE is a tree node representing FUNCTION_DECL
8279     or FUNCTION_TYPE of the function.
8280
8281     If OUTGOING is false, return a place in which the caller will
8282     see the return value.  Otherwise, return a place where a
8283     function returns a value.  */
8284
8285 static rtx
8286 ix86_function_value_bounds (const_tree valtype,
8287                             const_tree fntype_or_decl ATTRIBUTE_UNUSED,
8288                             bool outgoing ATTRIBUTE_UNUSED)
8289 {
8290   rtx res = NULL_RTX;
8291
8292   if (BOUNDED_TYPE_P (valtype))
8293     res = gen_rtx_REG (BNDmode, FIRST_BND_REG);
8294   else if (chkp_type_has_pointer (valtype))
8295     {
8296       bitmap slots;
8297       rtx bounds[2];
8298       bitmap_iterator bi;
8299       unsigned i, bnd_no = 0;
8300
8301       bitmap_obstack_initialize (NULL);
8302       slots = BITMAP_ALLOC (NULL);
8303       chkp_find_bound_slots (valtype, slots);
8304
8305       EXECUTE_IF_SET_IN_BITMAP (slots, 0, i, bi)
8306         {
8307           rtx reg = gen_rtx_REG (BNDmode, FIRST_BND_REG + bnd_no);
8308           rtx offs = GEN_INT (i * POINTER_SIZE / BITS_PER_UNIT);
8309           gcc_assert (bnd_no < 2);
8310           bounds[bnd_no++] = gen_rtx_EXPR_LIST (VOIDmode, reg, offs);
8311         }
8312
8313       res = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (bnd_no, bounds));
8314
8315       BITMAP_FREE (slots);
8316       bitmap_obstack_release (NULL);
8317     }
8318   else
8319     res = NULL_RTX;
8320
8321   return res;
8322 }
8323
8324 /* Pointer function arguments and return values are promoted to
8325    word_mode.  */
8326
8327 static machine_mode
8328 ix86_promote_function_mode (const_tree type, machine_mode mode,
8329                             int *punsignedp, const_tree fntype,
8330                             int for_return)
8331 {
8332   if (type != NULL_TREE && POINTER_TYPE_P (type))
8333     {
8334       *punsignedp = POINTERS_EXTEND_UNSIGNED;
8335       return word_mode;
8336     }
8337   return default_promote_function_mode (type, mode, punsignedp, fntype,
8338                                         for_return);
8339 }
8340
8341 /* Return true if a structure, union or array with MODE containing FIELD
8342    should be accessed using BLKmode.  */
8343
8344 static bool
8345 ix86_member_type_forces_blk (const_tree field, machine_mode mode)
8346 {
8347   /* Union with XFmode must be in BLKmode.  */
8348   return (mode == XFmode
8349           && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE
8350               || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE));
8351 }
8352
8353 rtx
8354 ix86_libcall_value (machine_mode mode)
8355 {
8356   return ix86_function_value_1 (NULL, NULL, mode, mode);
8357 }
8358
8359 /* Return true iff type is returned in memory.  */
8360
8361 static bool
8362 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
8363 {
8364 #ifdef SUBTARGET_RETURN_IN_MEMORY
8365   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
8366 #else
8367   const machine_mode mode = type_natural_mode (type, NULL, true);
8368   HOST_WIDE_INT size;
8369
8370   if (POINTER_BOUNDS_TYPE_P (type))
8371     return false;
8372
8373   if (TARGET_64BIT)
8374     {
8375       if (ix86_function_type_abi (fntype) == MS_ABI)
8376         {
8377           size = int_size_in_bytes (type);
8378
8379           /* __m128 is returned in xmm0.  */
8380           if ((!type || VECTOR_INTEGER_TYPE_P (type)
8381                || INTEGRAL_TYPE_P (type)
8382                || VECTOR_FLOAT_TYPE_P (type))
8383               && (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
8384               && !COMPLEX_MODE_P (mode)
8385               && (GET_MODE_SIZE (mode) == 16 || size == 16))
8386             return false;
8387
8388           /* Otherwise, the size must be exactly in [1248]. */
8389           return size != 1 && size != 2 && size != 4 && size != 8;
8390         }
8391       else
8392         {
8393           int needed_intregs, needed_sseregs;
8394
8395           return examine_argument (mode, type, 1,
8396                                    &needed_intregs, &needed_sseregs);
8397         }
8398     }
8399   else
8400     {
8401       if (mode == BLKmode)
8402         return true;
8403
8404       size = int_size_in_bytes (type);
8405
8406       if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
8407         return false;
8408
8409       if (VECTOR_MODE_P (mode) || mode == TImode)
8410         {
8411           /* User-created vectors small enough to fit in EAX.  */
8412           if (size < 8)
8413             return false;
8414
8415           /* Unless ABI prescibes otherwise,
8416              MMX/3dNow values are returned in MM0 if available.  */
8417              
8418           if (size == 8)
8419             return TARGET_VECT8_RETURNS || !TARGET_MMX;
8420
8421           /* SSE values are returned in XMM0 if available.  */
8422           if (size == 16)
8423             return !TARGET_SSE;
8424
8425           /* AVX values are returned in YMM0 if available.  */
8426           if (size == 32)
8427             return !TARGET_AVX;
8428
8429           /* AVX512F values are returned in ZMM0 if available.  */
8430           if (size == 64)
8431             return !TARGET_AVX512F;
8432         }
8433
8434       if (mode == XFmode)
8435         return false;
8436
8437       if (size > 12)
8438         return true;
8439
8440       /* OImode shouldn't be used directly.  */
8441       gcc_assert (mode != OImode);
8442
8443       return false;
8444     }
8445 #endif
8446 }
8447
8448 \f
8449 /* Create the va_list data type.  */
8450
8451 /* Returns the calling convention specific va_list date type.
8452    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
8453
8454 static tree
8455 ix86_build_builtin_va_list_abi (enum calling_abi abi)
8456 {
8457   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
8458
8459   /* For i386 we use plain pointer to argument area.  */
8460   if (!TARGET_64BIT || abi == MS_ABI)
8461     return build_pointer_type (char_type_node);
8462
8463   record = lang_hooks.types.make_type (RECORD_TYPE);
8464   type_decl = build_decl (BUILTINS_LOCATION,
8465                           TYPE_DECL, get_identifier ("__va_list_tag"), record);
8466
8467   f_gpr = build_decl (BUILTINS_LOCATION,
8468                       FIELD_DECL, get_identifier ("gp_offset"),
8469                       unsigned_type_node);
8470   f_fpr = build_decl (BUILTINS_LOCATION,
8471                       FIELD_DECL, get_identifier ("fp_offset"),
8472                       unsigned_type_node);
8473   f_ovf = build_decl (BUILTINS_LOCATION,
8474                       FIELD_DECL, get_identifier ("overflow_arg_area"),
8475                       ptr_type_node);
8476   f_sav = build_decl (BUILTINS_LOCATION,
8477                       FIELD_DECL, get_identifier ("reg_save_area"),
8478                       ptr_type_node);
8479
8480   va_list_gpr_counter_field = f_gpr;
8481   va_list_fpr_counter_field = f_fpr;
8482
8483   DECL_FIELD_CONTEXT (f_gpr) = record;
8484   DECL_FIELD_CONTEXT (f_fpr) = record;
8485   DECL_FIELD_CONTEXT (f_ovf) = record;
8486   DECL_FIELD_CONTEXT (f_sav) = record;
8487
8488   TYPE_STUB_DECL (record) = type_decl;
8489   TYPE_NAME (record) = type_decl;
8490   TYPE_FIELDS (record) = f_gpr;
8491   DECL_CHAIN (f_gpr) = f_fpr;
8492   DECL_CHAIN (f_fpr) = f_ovf;
8493   DECL_CHAIN (f_ovf) = f_sav;
8494
8495   layout_type (record);
8496
8497   /* The correct type is an array type of one element.  */
8498   return build_array_type (record, build_index_type (size_zero_node));
8499 }
8500
8501 /* Setup the builtin va_list data type and for 64-bit the additional
8502    calling convention specific va_list data types.  */
8503
8504 static tree
8505 ix86_build_builtin_va_list (void)
8506 {
8507   tree ret = ix86_build_builtin_va_list_abi (ix86_abi);
8508
8509   /* Initialize abi specific va_list builtin types.  */
8510   if (TARGET_64BIT)
8511     {
8512       tree t;
8513       if (ix86_abi == MS_ABI)
8514         {
8515           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
8516           if (TREE_CODE (t) != RECORD_TYPE)
8517             t = build_variant_type_copy (t);
8518           sysv_va_list_type_node = t;
8519         }
8520       else
8521         {
8522           t = ret;
8523           if (TREE_CODE (t) != RECORD_TYPE)
8524             t = build_variant_type_copy (t);
8525           sysv_va_list_type_node = t;
8526         }
8527       if (ix86_abi != MS_ABI)
8528         {
8529           t = ix86_build_builtin_va_list_abi (MS_ABI);
8530           if (TREE_CODE (t) != RECORD_TYPE)
8531             t = build_variant_type_copy (t);
8532           ms_va_list_type_node = t;
8533         }
8534       else
8535         {
8536           t = ret;
8537           if (TREE_CODE (t) != RECORD_TYPE)
8538             t = build_variant_type_copy (t);
8539           ms_va_list_type_node = t;
8540         }
8541     }
8542
8543   return ret;
8544 }
8545
8546 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
8547
8548 static void
8549 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
8550 {
8551   rtx save_area, mem;
8552   alias_set_type set;
8553   int i, max;
8554
8555   /* GPR size of varargs save area.  */
8556   if (cfun->va_list_gpr_size)
8557     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
8558   else
8559     ix86_varargs_gpr_size = 0;
8560
8561   /* FPR size of varargs save area.  We don't need it if we don't pass
8562      anything in SSE registers.  */
8563   if (TARGET_SSE && cfun->va_list_fpr_size)
8564     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
8565   else
8566     ix86_varargs_fpr_size = 0;
8567
8568   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
8569     return;
8570
8571   save_area = frame_pointer_rtx;
8572   set = get_varargs_alias_set ();
8573
8574   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
8575   if (max > X86_64_REGPARM_MAX)
8576     max = X86_64_REGPARM_MAX;
8577
8578   for (i = cum->regno; i < max; i++)
8579     {
8580       mem = gen_rtx_MEM (word_mode,
8581                          plus_constant (Pmode, save_area, i * UNITS_PER_WORD));
8582       MEM_NOTRAP_P (mem) = 1;
8583       set_mem_alias_set (mem, set);
8584       emit_move_insn (mem,
8585                       gen_rtx_REG (word_mode,
8586                                    x86_64_int_parameter_registers[i]));
8587     }
8588
8589   if (ix86_varargs_fpr_size)
8590     {
8591       machine_mode smode;
8592       rtx_code_label *label;
8593       rtx test;
8594
8595       /* Now emit code to save SSE registers.  The AX parameter contains number
8596          of SSE parameter registers used to call this function, though all we
8597          actually check here is the zero/non-zero status.  */
8598
8599       label = gen_label_rtx ();
8600       test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx);
8601       emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1),
8602                                       label));
8603
8604       /* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if
8605          we used movdqa (i.e. TImode) instead?  Perhaps even better would
8606          be if we could determine the real mode of the data, via a hook
8607          into pass_stdarg.  Ignore all that for now.  */
8608       smode = V4SFmode;
8609       if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode))
8610         crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode);
8611
8612       max = cum->sse_regno + cfun->va_list_fpr_size / 16;
8613       if (max > X86_64_SSE_REGPARM_MAX)
8614         max = X86_64_SSE_REGPARM_MAX;
8615
8616       for (i = cum->sse_regno; i < max; ++i)
8617         {
8618           mem = plus_constant (Pmode, save_area,
8619                                i * 16 + ix86_varargs_gpr_size);
8620           mem = gen_rtx_MEM (smode, mem);
8621           MEM_NOTRAP_P (mem) = 1;
8622           set_mem_alias_set (mem, set);
8623           set_mem_align (mem, GET_MODE_ALIGNMENT (smode));
8624
8625           emit_move_insn (mem, gen_rtx_REG (smode, SSE_REGNO (i)));
8626         }
8627
8628       emit_label (label);
8629     }
8630 }
8631
8632 static void
8633 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
8634 {
8635   alias_set_type set = get_varargs_alias_set ();
8636   int i;
8637
8638   /* Reset to zero, as there might be a sysv vaarg used
8639      before.  */
8640   ix86_varargs_gpr_size = 0;
8641   ix86_varargs_fpr_size = 0;
8642
8643   for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
8644     {
8645       rtx reg, mem;
8646
8647       mem = gen_rtx_MEM (Pmode,
8648                          plus_constant (Pmode, virtual_incoming_args_rtx,
8649                                         i * UNITS_PER_WORD));
8650       MEM_NOTRAP_P (mem) = 1;
8651       set_mem_alias_set (mem, set);
8652
8653       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
8654       emit_move_insn (mem, reg);
8655     }
8656 }
8657
8658 static void
8659 ix86_setup_incoming_varargs (cumulative_args_t cum_v, machine_mode mode,
8660                              tree type, int *, int no_rtl)
8661 {
8662   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
8663   CUMULATIVE_ARGS next_cum;
8664   tree fntype;
8665
8666   /* This argument doesn't appear to be used anymore.  Which is good,
8667      because the old code here didn't suppress rtl generation.  */
8668   gcc_assert (!no_rtl);
8669
8670   if (!TARGET_64BIT)
8671     return;
8672
8673   fntype = TREE_TYPE (current_function_decl);
8674
8675   /* For varargs, we do not want to skip the dummy va_dcl argument.
8676      For stdargs, we do want to skip the last named argument.  */
8677   next_cum = *cum;
8678   if (stdarg_p (fntype))
8679     ix86_function_arg_advance (pack_cumulative_args (&next_cum), mode, type,
8680                                true);
8681
8682   if (cum->call_abi == MS_ABI)
8683     setup_incoming_varargs_ms_64 (&next_cum);
8684   else
8685     setup_incoming_varargs_64 (&next_cum);
8686 }
8687
8688 static void
8689 ix86_setup_incoming_vararg_bounds (cumulative_args_t cum_v,
8690                                    enum machine_mode mode,
8691                                    tree type,
8692                                    int *pretend_size ATTRIBUTE_UNUSED,
8693                                    int no_rtl)
8694 {
8695   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
8696   CUMULATIVE_ARGS next_cum;
8697   tree fntype;
8698   rtx save_area;
8699   int bnd_reg, i, max;
8700
8701   gcc_assert (!no_rtl);
8702
8703   /* Do nothing if we use plain pointer to argument area.  */
8704   if (!TARGET_64BIT || cum->call_abi == MS_ABI)
8705     return;
8706
8707   fntype = TREE_TYPE (current_function_decl);
8708
8709   /* For varargs, we do not want to skip the dummy va_dcl argument.
8710      For stdargs, we do want to skip the last named argument.  */
8711   next_cum = *cum;
8712   if (stdarg_p (fntype))
8713     ix86_function_arg_advance (pack_cumulative_args (&next_cum), mode, type,
8714                                true);
8715   save_area = frame_pointer_rtx;
8716
8717   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
8718   if (max > X86_64_REGPARM_MAX)
8719     max = X86_64_REGPARM_MAX;
8720
8721   bnd_reg = cum->bnd_regno + cum->force_bnd_pass;
8722   if (chkp_function_instrumented_p (current_function_decl))
8723     for (i = cum->regno; i < max; i++)
8724       {
8725         rtx addr = plus_constant (Pmode, save_area, i * UNITS_PER_WORD);
8726         rtx reg = gen_rtx_REG (DImode,
8727                                x86_64_int_parameter_registers[i]);
8728         rtx ptr = reg;
8729         rtx bounds;
8730
8731         if (bnd_reg <= LAST_BND_REG)
8732           bounds = gen_rtx_REG (BNDmode, bnd_reg);
8733         else
8734           {
8735             rtx ldx_addr =
8736               plus_constant (Pmode, arg_pointer_rtx,
8737                              (LAST_BND_REG - bnd_reg) * GET_MODE_SIZE (Pmode));
8738             bounds = gen_reg_rtx (BNDmode);
8739             emit_insn (BNDmode == BND64mode
8740                        ? gen_bnd64_ldx (bounds, ldx_addr, ptr)
8741                        : gen_bnd32_ldx (bounds, ldx_addr, ptr));
8742           }
8743
8744         emit_insn (BNDmode == BND64mode
8745                    ? gen_bnd64_stx (addr, ptr, bounds)
8746                    : gen_bnd32_stx (addr, ptr, bounds));
8747
8748         bnd_reg++;
8749       }
8750 }
8751
8752
8753 /* Checks if TYPE is of kind va_list char *.  */
8754
8755 static bool
8756 is_va_list_char_pointer (tree type)
8757 {
8758   tree canonic;
8759
8760   /* For 32-bit it is always true.  */
8761   if (!TARGET_64BIT)
8762     return true;
8763   canonic = ix86_canonical_va_list_type (type);
8764   return (canonic == ms_va_list_type_node
8765           || (ix86_abi == MS_ABI && canonic == va_list_type_node));
8766 }
8767
8768 /* Implement va_start.  */
8769
8770 static void
8771 ix86_va_start (tree valist, rtx nextarg)
8772 {
8773   HOST_WIDE_INT words, n_gpr, n_fpr;
8774   tree f_gpr, f_fpr, f_ovf, f_sav;
8775   tree gpr, fpr, ovf, sav, t;
8776   tree type;
8777   rtx ovf_rtx;
8778
8779   if (flag_split_stack
8780       && cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8781     {
8782       unsigned int scratch_regno;
8783
8784       /* When we are splitting the stack, we can't refer to the stack
8785          arguments using internal_arg_pointer, because they may be on
8786          the old stack.  The split stack prologue will arrange to
8787          leave a pointer to the old stack arguments in a scratch
8788          register, which we here copy to a pseudo-register.  The split
8789          stack prologue can't set the pseudo-register directly because
8790          it (the prologue) runs before any registers have been saved.  */
8791
8792       scratch_regno = split_stack_prologue_scratch_regno ();
8793       if (scratch_regno != INVALID_REGNUM)
8794         {
8795           rtx reg;
8796           rtx_insn *seq;
8797
8798           reg = gen_reg_rtx (Pmode);
8799           cfun->machine->split_stack_varargs_pointer = reg;
8800
8801           start_sequence ();
8802           emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno));
8803           seq = get_insns ();
8804           end_sequence ();
8805
8806           push_topmost_sequence ();
8807           emit_insn_after (seq, entry_of_function ());
8808           pop_topmost_sequence ();
8809         }
8810     }
8811
8812   /* Only 64bit target needs something special.  */
8813   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
8814     {
8815       if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8816         std_expand_builtin_va_start (valist, nextarg);
8817       else
8818         {
8819           rtx va_r, next;
8820
8821           va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
8822           next = expand_binop (ptr_mode, add_optab,
8823                                cfun->machine->split_stack_varargs_pointer,
8824                                crtl->args.arg_offset_rtx,
8825                                NULL_RTX, 0, OPTAB_LIB_WIDEN);
8826           convert_move (va_r, next, 0);
8827
8828           /* Store zero bounds for va_list.  */
8829           if (chkp_function_instrumented_p (current_function_decl))
8830             chkp_expand_bounds_reset_for_mem (valist,
8831                                               make_tree (TREE_TYPE (valist),
8832                                                          next));
8833
8834         }
8835       return;
8836     }
8837
8838   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
8839   f_fpr = DECL_CHAIN (f_gpr);
8840   f_ovf = DECL_CHAIN (f_fpr);
8841   f_sav = DECL_CHAIN (f_ovf);
8842
8843   valist = build_simple_mem_ref (valist);
8844   TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node);
8845   /* The following should be folded into the MEM_REF offset.  */
8846   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist),
8847                 f_gpr, NULL_TREE);
8848   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
8849                 f_fpr, NULL_TREE);
8850   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
8851                 f_ovf, NULL_TREE);
8852   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
8853                 f_sav, NULL_TREE);
8854
8855   /* Count number of gp and fp argument registers used.  */
8856   words = crtl->args.info.words;
8857   n_gpr = crtl->args.info.regno;
8858   n_fpr = crtl->args.info.sse_regno;
8859
8860   if (cfun->va_list_gpr_size)
8861     {
8862       type = TREE_TYPE (gpr);
8863       t = build2 (MODIFY_EXPR, type,
8864                   gpr, build_int_cst (type, n_gpr * 8));
8865       TREE_SIDE_EFFECTS (t) = 1;
8866       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8867     }
8868
8869   if (TARGET_SSE && cfun->va_list_fpr_size)
8870     {
8871       type = TREE_TYPE (fpr);
8872       t = build2 (MODIFY_EXPR, type, fpr,
8873                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
8874       TREE_SIDE_EFFECTS (t) = 1;
8875       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8876     }
8877
8878   /* Find the overflow area.  */
8879   type = TREE_TYPE (ovf);
8880   if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8881     ovf_rtx = crtl->args.internal_arg_pointer;
8882   else
8883     ovf_rtx = cfun->machine->split_stack_varargs_pointer;
8884   t = make_tree (type, ovf_rtx);
8885   if (words != 0)
8886     t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD);
8887
8888   /* Store zero bounds for overflow area pointer.  */
8889   if (chkp_function_instrumented_p (current_function_decl))
8890     chkp_expand_bounds_reset_for_mem (ovf, t);
8891
8892   t = build2 (MODIFY_EXPR, type, ovf, t);
8893   TREE_SIDE_EFFECTS (t) = 1;
8894   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8895
8896   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
8897     {
8898       /* Find the register save area.
8899          Prologue of the function save it right above stack frame.  */
8900       type = TREE_TYPE (sav);
8901       t = make_tree (type, frame_pointer_rtx);
8902       if (!ix86_varargs_gpr_size)
8903         t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX);
8904
8905       /* Store zero bounds for save area pointer.  */
8906       if (chkp_function_instrumented_p (current_function_decl))
8907         chkp_expand_bounds_reset_for_mem (sav, t);
8908
8909       t = build2 (MODIFY_EXPR, type, sav, t);
8910       TREE_SIDE_EFFECTS (t) = 1;
8911       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8912     }
8913 }
8914
8915 /* Implement va_arg.  */
8916
8917 static tree
8918 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
8919                       gimple_seq *post_p)
8920 {
8921   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
8922   tree f_gpr, f_fpr, f_ovf, f_sav;
8923   tree gpr, fpr, ovf, sav, t;
8924   int size, rsize;
8925   tree lab_false, lab_over = NULL_TREE;
8926   tree addr, t2;
8927   rtx container;
8928   int indirect_p = 0;
8929   tree ptrtype;
8930   machine_mode nat_mode;
8931   unsigned int arg_boundary;
8932
8933   /* Only 64bit target needs something special.  */
8934   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
8935     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
8936
8937   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
8938   f_fpr = DECL_CHAIN (f_gpr);
8939   f_ovf = DECL_CHAIN (f_fpr);
8940   f_sav = DECL_CHAIN (f_ovf);
8941
8942   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
8943                 build_va_arg_indirect_ref (valist), f_gpr, NULL_TREE);
8944   valist = build_va_arg_indirect_ref (valist);
8945   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
8946   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
8947   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
8948
8949   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
8950   if (indirect_p)
8951     type = build_pointer_type (type);
8952   size = int_size_in_bytes (type);
8953   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
8954
8955   nat_mode = type_natural_mode (type, NULL, false);
8956   switch (nat_mode)
8957     {
8958     case V8SFmode:
8959     case V8SImode:
8960     case V32QImode:
8961     case V16HImode:
8962     case V4DFmode:
8963     case V4DImode:
8964     case V16SFmode:
8965     case V16SImode:
8966     case V64QImode:
8967     case V32HImode:
8968     case V8DFmode:
8969     case V8DImode:
8970       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
8971       if (!TARGET_64BIT_MS_ABI)
8972         {
8973           container = NULL;
8974           break;
8975         }
8976
8977     default:
8978       container = construct_container (nat_mode, TYPE_MODE (type),
8979                                        type, 0, X86_64_REGPARM_MAX,
8980                                        X86_64_SSE_REGPARM_MAX, intreg,
8981                                        0);
8982       break;
8983     }
8984
8985   /* Pull the value out of the saved registers.  */
8986
8987   addr = create_tmp_var (ptr_type_node, "addr");
8988
8989   if (container)
8990     {
8991       int needed_intregs, needed_sseregs;
8992       bool need_temp;
8993       tree int_addr, sse_addr;
8994
8995       lab_false = create_artificial_label (UNKNOWN_LOCATION);
8996       lab_over = create_artificial_label (UNKNOWN_LOCATION);
8997
8998       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
8999
9000       need_temp = (!REG_P (container)
9001                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
9002                        || TYPE_ALIGN (type) > 128));
9003
9004       /* In case we are passing structure, verify that it is consecutive block
9005          on the register save area.  If not we need to do moves.  */
9006       if (!need_temp && !REG_P (container))
9007         {
9008           /* Verify that all registers are strictly consecutive  */
9009           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
9010             {
9011               int i;
9012
9013               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
9014                 {
9015                   rtx slot = XVECEXP (container, 0, i);
9016                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
9017                       || INTVAL (XEXP (slot, 1)) != i * 16)
9018                     need_temp = true;
9019                 }
9020             }
9021           else
9022             {
9023               int i;
9024
9025               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
9026                 {
9027                   rtx slot = XVECEXP (container, 0, i);
9028                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
9029                       || INTVAL (XEXP (slot, 1)) != i * 8)
9030                     need_temp = true;
9031                 }
9032             }
9033         }
9034       if (!need_temp)
9035         {
9036           int_addr = addr;
9037           sse_addr = addr;
9038         }
9039       else
9040         {
9041           int_addr = create_tmp_var (ptr_type_node, "int_addr");
9042           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
9043         }
9044
9045       /* First ensure that we fit completely in registers.  */
9046       if (needed_intregs)
9047         {
9048           t = build_int_cst (TREE_TYPE (gpr),
9049                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
9050           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
9051           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
9052           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
9053           gimplify_and_add (t, pre_p);
9054         }
9055       if (needed_sseregs)
9056         {
9057           t = build_int_cst (TREE_TYPE (fpr),
9058                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
9059                              + X86_64_REGPARM_MAX * 8);
9060           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
9061           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
9062           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
9063           gimplify_and_add (t, pre_p);
9064         }
9065
9066       /* Compute index to start of area used for integer regs.  */
9067       if (needed_intregs)
9068         {
9069           /* int_addr = gpr + sav; */
9070           t = fold_build_pointer_plus (sav, gpr);
9071           gimplify_assign (int_addr, t, pre_p);
9072         }
9073       if (needed_sseregs)
9074         {
9075           /* sse_addr = fpr + sav; */
9076           t = fold_build_pointer_plus (sav, fpr);
9077           gimplify_assign (sse_addr, t, pre_p);
9078         }
9079       if (need_temp)
9080         {
9081           int i, prev_size = 0;
9082           tree temp = create_tmp_var (type, "va_arg_tmp");
9083
9084           /* addr = &temp; */
9085           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
9086           gimplify_assign (addr, t, pre_p);
9087
9088           for (i = 0; i < XVECLEN (container, 0); i++)
9089             {
9090               rtx slot = XVECEXP (container, 0, i);
9091               rtx reg = XEXP (slot, 0);
9092               machine_mode mode = GET_MODE (reg);
9093               tree piece_type;
9094               tree addr_type;
9095               tree daddr_type;
9096               tree src_addr, src;
9097               int src_offset;
9098               tree dest_addr, dest;
9099               int cur_size = GET_MODE_SIZE (mode);
9100
9101               gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
9102               prev_size = INTVAL (XEXP (slot, 1));
9103               if (prev_size + cur_size > size)
9104                 {
9105                   cur_size = size - prev_size;
9106                   mode = mode_for_size (cur_size * BITS_PER_UNIT, MODE_INT, 1);
9107                   if (mode == BLKmode)
9108                     mode = QImode;
9109                 }
9110               piece_type = lang_hooks.types.type_for_mode (mode, 1);
9111               if (mode == GET_MODE (reg))
9112                 addr_type = build_pointer_type (piece_type);
9113               else
9114                 addr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
9115                                                          true);
9116               daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
9117                                                         true);
9118
9119               if (SSE_REGNO_P (REGNO (reg)))
9120                 {
9121                   src_addr = sse_addr;
9122                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
9123                 }
9124               else
9125                 {
9126                   src_addr = int_addr;
9127                   src_offset = REGNO (reg) * 8;
9128                 }
9129               src_addr = fold_convert (addr_type, src_addr);
9130               src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset);
9131
9132               dest_addr = fold_convert (daddr_type, addr);
9133               dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size);
9134               if (cur_size == GET_MODE_SIZE (mode))
9135                 {
9136                   src = build_va_arg_indirect_ref (src_addr);
9137                   dest = build_va_arg_indirect_ref (dest_addr);
9138
9139                   gimplify_assign (dest, src, pre_p);
9140                 }
9141               else
9142                 {
9143                   tree copy
9144                     = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
9145                                        3, dest_addr, src_addr,
9146                                        size_int (cur_size));
9147                   gimplify_and_add (copy, pre_p);
9148                 }
9149               prev_size += cur_size;
9150             }
9151         }
9152
9153       if (needed_intregs)
9154         {
9155           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
9156                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
9157           gimplify_assign (gpr, t, pre_p);
9158         }
9159
9160       if (needed_sseregs)
9161         {
9162           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
9163                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
9164           gimplify_assign (fpr, t, pre_p);
9165         }
9166
9167       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
9168
9169       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
9170     }
9171
9172   /* ... otherwise out of the overflow area.  */
9173
9174   /* When we align parameter on stack for caller, if the parameter
9175      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
9176      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
9177      here with caller.  */
9178   arg_boundary = ix86_function_arg_boundary (VOIDmode, type);
9179   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
9180     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
9181
9182   /* Care for on-stack alignment if needed.  */
9183   if (arg_boundary <= 64 || size == 0)
9184     t = ovf;
9185  else
9186     {
9187       HOST_WIDE_INT align = arg_boundary / 8;
9188       t = fold_build_pointer_plus_hwi (ovf, align - 1);
9189       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
9190                   build_int_cst (TREE_TYPE (t), -align));
9191     }
9192
9193   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
9194   gimplify_assign (addr, t, pre_p);
9195
9196   t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD);
9197   gimplify_assign (unshare_expr (ovf), t, pre_p);
9198
9199   if (container)
9200     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
9201
9202   ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
9203   addr = fold_convert (ptrtype, addr);
9204
9205   if (indirect_p)
9206     addr = build_va_arg_indirect_ref (addr);
9207   return build_va_arg_indirect_ref (addr);
9208 }
9209 \f
9210 /* Return true if OPNUM's MEM should be matched
9211    in movabs* patterns.  */
9212
9213 bool
9214 ix86_check_movabs (rtx insn, int opnum)
9215 {
9216   rtx set, mem;
9217
9218   set = PATTERN (insn);
9219   if (GET_CODE (set) == PARALLEL)
9220     set = XVECEXP (set, 0, 0);
9221   gcc_assert (GET_CODE (set) == SET);
9222   mem = XEXP (set, opnum);
9223   while (GET_CODE (mem) == SUBREG)
9224     mem = SUBREG_REG (mem);
9225   gcc_assert (MEM_P (mem));
9226   return volatile_ok || !MEM_VOLATILE_P (mem);
9227 }
9228 \f
9229 /* Initialize the table of extra 80387 mathematical constants.  */
9230
9231 static void
9232 init_ext_80387_constants (void)
9233 {
9234   static const char * cst[5] =
9235   {
9236     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
9237     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
9238     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
9239     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
9240     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
9241   };
9242   int i;
9243
9244   for (i = 0; i < 5; i++)
9245     {
9246       real_from_string (&ext_80387_constants_table[i], cst[i]);
9247       /* Ensure each constant is rounded to XFmode precision.  */
9248       real_convert (&ext_80387_constants_table[i],
9249                     XFmode, &ext_80387_constants_table[i]);
9250     }
9251
9252   ext_80387_constants_init = 1;
9253 }
9254
9255 /* Return non-zero if the constant is something that
9256    can be loaded with a special instruction.  */
9257
9258 int
9259 standard_80387_constant_p (rtx x)
9260 {
9261   machine_mode mode = GET_MODE (x);
9262
9263   REAL_VALUE_TYPE r;
9264
9265   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
9266     return -1;
9267
9268   if (x == CONST0_RTX (mode))
9269     return 1;
9270   if (x == CONST1_RTX (mode))
9271     return 2;
9272
9273   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
9274
9275   /* For XFmode constants, try to find a special 80387 instruction when
9276      optimizing for size or on those CPUs that benefit from them.  */
9277   if (mode == XFmode
9278       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
9279     {
9280       int i;
9281
9282       if (! ext_80387_constants_init)
9283         init_ext_80387_constants ();
9284
9285       for (i = 0; i < 5; i++)
9286         if (real_identical (&r, &ext_80387_constants_table[i]))
9287           return i + 3;
9288     }
9289
9290   /* Load of the constant -0.0 or -1.0 will be split as
9291      fldz;fchs or fld1;fchs sequence.  */
9292   if (real_isnegzero (&r))
9293     return 8;
9294   if (real_identical (&r, &dconstm1))
9295     return 9;
9296
9297   return 0;
9298 }
9299
9300 /* Return the opcode of the special instruction to be used to load
9301    the constant X.  */
9302
9303 const char *
9304 standard_80387_constant_opcode (rtx x)
9305 {
9306   switch (standard_80387_constant_p (x))
9307     {
9308     case 1:
9309       return "fldz";
9310     case 2:
9311       return "fld1";
9312     case 3:
9313       return "fldlg2";
9314     case 4:
9315       return "fldln2";
9316     case 5:
9317       return "fldl2e";
9318     case 6:
9319       return "fldl2t";
9320     case 7:
9321       return "fldpi";
9322     case 8:
9323     case 9:
9324       return "#";
9325     default:
9326       gcc_unreachable ();
9327     }
9328 }
9329
9330 /* Return the CONST_DOUBLE representing the 80387 constant that is
9331    loaded by the specified special instruction.  The argument IDX
9332    matches the return value from standard_80387_constant_p.  */
9333
9334 rtx
9335 standard_80387_constant_rtx (int idx)
9336 {
9337   int i;
9338
9339   if (! ext_80387_constants_init)
9340     init_ext_80387_constants ();
9341
9342   switch (idx)
9343     {
9344     case 3:
9345     case 4:
9346     case 5:
9347     case 6:
9348     case 7:
9349       i = idx - 3;
9350       break;
9351
9352     default:
9353       gcc_unreachable ();
9354     }
9355
9356   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
9357                                        XFmode);
9358 }
9359
9360 /* Return 1 if X is all 0s and 2 if x is all 1s
9361    in supported SSE/AVX vector mode.  */
9362
9363 int
9364 standard_sse_constant_p (rtx x)
9365 {
9366   machine_mode mode = GET_MODE (x);
9367
9368   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
9369     return 1;
9370   if (vector_all_ones_operand (x, mode))
9371     switch (mode)
9372       {
9373       case V16QImode:
9374       case V8HImode:
9375       case V4SImode:
9376       case V2DImode:
9377         if (TARGET_SSE2)
9378           return 2;
9379       case V32QImode:
9380       case V16HImode:
9381       case V8SImode:
9382       case V4DImode:
9383         if (TARGET_AVX2)
9384           return 2;
9385       case V64QImode:
9386       case V32HImode:
9387       case V16SImode:
9388       case V8DImode:
9389         if (TARGET_AVX512F)
9390           return 2;
9391       default:
9392         break;
9393       }
9394
9395   return 0;
9396 }
9397
9398 /* Return the opcode of the special instruction to be used to load
9399    the constant X.  */
9400
9401 const char *
9402 standard_sse_constant_opcode (rtx_insn *insn, rtx x)
9403 {
9404   switch (standard_sse_constant_p (x))
9405     {
9406     case 1:
9407       switch (get_attr_mode (insn))
9408         {
9409         case MODE_XI:
9410           return "vpxord\t%g0, %g0, %g0";
9411         case MODE_V16SF:
9412           return TARGET_AVX512DQ ? "vxorps\t%g0, %g0, %g0"
9413                                  : "vpxord\t%g0, %g0, %g0";
9414         case MODE_V8DF:
9415           return TARGET_AVX512DQ ? "vxorpd\t%g0, %g0, %g0"
9416                                  : "vpxorq\t%g0, %g0, %g0";
9417         case MODE_TI:
9418           return TARGET_AVX512VL ? "vpxord\t%t0, %t0, %t0"
9419                                  : "%vpxor\t%0, %d0";
9420         case MODE_V2DF:
9421           return "%vxorpd\t%0, %d0";
9422         case MODE_V4SF:
9423           return "%vxorps\t%0, %d0";
9424
9425         case MODE_OI:
9426           return TARGET_AVX512VL ? "vpxord\t%x0, %x0, %x0"
9427                                  : "vpxor\t%x0, %x0, %x0";
9428         case MODE_V4DF:
9429           return "vxorpd\t%x0, %x0, %x0";
9430         case MODE_V8SF:
9431           return "vxorps\t%x0, %x0, %x0";
9432
9433         default:
9434           break;
9435         }
9436
9437     case 2:
9438       if (TARGET_AVX512VL
9439           || get_attr_mode (insn) == MODE_XI
9440           || get_attr_mode (insn) == MODE_V8DF
9441           || get_attr_mode (insn) == MODE_V16SF)
9442         return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
9443       if (TARGET_AVX)
9444         return "vpcmpeqd\t%0, %0, %0";
9445       else
9446         return "pcmpeqd\t%0, %0";
9447
9448     default:
9449       break;
9450     }
9451   gcc_unreachable ();
9452 }
9453
9454 /* Returns true if OP contains a symbol reference */
9455
9456 bool
9457 symbolic_reference_mentioned_p (rtx op)
9458 {
9459   const char *fmt;
9460   int i;
9461
9462   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
9463     return true;
9464
9465   fmt = GET_RTX_FORMAT (GET_CODE (op));
9466   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
9467     {
9468       if (fmt[i] == 'E')
9469         {
9470           int j;
9471
9472           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
9473             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
9474               return true;
9475         }
9476
9477       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
9478         return true;
9479     }
9480
9481   return false;
9482 }
9483
9484 /* Return true if it is appropriate to emit `ret' instructions in the
9485    body of a function.  Do this only if the epilogue is simple, needing a
9486    couple of insns.  Prior to reloading, we can't tell how many registers
9487    must be saved, so return false then.  Return false if there is no frame
9488    marker to de-allocate.  */
9489
9490 bool
9491 ix86_can_use_return_insn_p (void)
9492 {
9493   struct ix86_frame frame;
9494
9495   if (! reload_completed || frame_pointer_needed)
9496     return 0;
9497
9498   /* Don't allow more than 32k pop, since that's all we can do
9499      with one instruction.  */
9500   if (crtl->args.pops_args && crtl->args.size >= 32768)
9501     return 0;
9502
9503   ix86_compute_frame_layout (&frame);
9504   return (frame.stack_pointer_offset == UNITS_PER_WORD
9505           && (frame.nregs + frame.nsseregs) == 0);
9506 }
9507 \f
9508 /* Value should be nonzero if functions must have frame pointers.
9509    Zero means the frame pointer need not be set up (and parms may
9510    be accessed via the stack pointer) in functions that seem suitable.  */
9511
9512 static bool
9513 ix86_frame_pointer_required (void)
9514 {
9515   /* If we accessed previous frames, then the generated code expects
9516      to be able to access the saved ebp value in our frame.  */
9517   if (cfun->machine->accesses_prev_frame)
9518     return true;
9519
9520   /* Several x86 os'es need a frame pointer for other reasons,
9521      usually pertaining to setjmp.  */
9522   if (SUBTARGET_FRAME_POINTER_REQUIRED)
9523     return true;
9524
9525   /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
9526   if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
9527     return true;
9528
9529   /* Win64 SEH, very large frames need a frame-pointer as maximum stack
9530      allocation is 4GB.  */
9531   if (TARGET_64BIT_MS_ABI && get_frame_size () > SEH_MAX_FRAME_SIZE)
9532     return true;
9533
9534   /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
9535      turns off the frame pointer by default.  Turn it back on now if
9536      we've not got a leaf function.  */
9537   if (TARGET_OMIT_LEAF_FRAME_POINTER
9538       && (!crtl->is_leaf
9539           || ix86_current_function_calls_tls_descriptor))
9540     return true;
9541
9542   if (crtl->profile && !flag_fentry)
9543     return true;
9544
9545   return false;
9546 }
9547
9548 /* Record that the current function accesses previous call frames.  */
9549
9550 void
9551 ix86_setup_frame_addresses (void)
9552 {
9553   cfun->machine->accesses_prev_frame = 1;
9554 }
9555 \f
9556 #ifndef USE_HIDDEN_LINKONCE
9557 # if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)
9558 #  define USE_HIDDEN_LINKONCE 1
9559 # else
9560 #  define USE_HIDDEN_LINKONCE 0
9561 # endif
9562 #endif
9563
9564 static int pic_labels_used;
9565
9566 /* Fills in the label name that should be used for a pc thunk for
9567    the given register.  */
9568
9569 static void
9570 get_pc_thunk_name (char name[32], unsigned int regno)
9571 {
9572   gcc_assert (!TARGET_64BIT);
9573
9574   if (USE_HIDDEN_LINKONCE)
9575     sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]);
9576   else
9577     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
9578 }
9579
9580
9581 /* This function generates code for -fpic that loads %ebx with
9582    the return address of the caller and then returns.  */
9583
9584 static void
9585 ix86_code_end (void)
9586 {
9587   rtx xops[2];
9588   int regno;
9589
9590   for (regno = AX_REG; regno <= SP_REG; regno++)
9591     {
9592       char name[32];
9593       tree decl;
9594
9595       if (!(pic_labels_used & (1 << regno)))
9596         continue;
9597
9598       get_pc_thunk_name (name, regno);
9599
9600       decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
9601                          get_identifier (name),
9602                          build_function_type_list (void_type_node, NULL_TREE));
9603       DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
9604                                        NULL_TREE, void_type_node);
9605       TREE_PUBLIC (decl) = 1;
9606       TREE_STATIC (decl) = 1;
9607       DECL_IGNORED_P (decl) = 1;
9608
9609 #if TARGET_MACHO
9610       if (TARGET_MACHO)
9611         {
9612           switch_to_section (darwin_sections[text_coal_section]);
9613           fputs ("\t.weak_definition\t", asm_out_file);
9614           assemble_name (asm_out_file, name);
9615           fputs ("\n\t.private_extern\t", asm_out_file);
9616           assemble_name (asm_out_file, name);
9617           putc ('\n', asm_out_file);
9618           ASM_OUTPUT_LABEL (asm_out_file, name);
9619           DECL_WEAK (decl) = 1;
9620         }
9621       else
9622 #endif
9623       if (USE_HIDDEN_LINKONCE)
9624         {
9625           cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
9626
9627           targetm.asm_out.unique_section (decl, 0);
9628           switch_to_section (get_named_section (decl, NULL, 0));
9629
9630           targetm.asm_out.globalize_label (asm_out_file, name);
9631           fputs ("\t.hidden\t", asm_out_file);
9632           assemble_name (asm_out_file, name);
9633           putc ('\n', asm_out_file);
9634           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
9635         }
9636       else
9637         {
9638           switch_to_section (text_section);
9639           ASM_OUTPUT_LABEL (asm_out_file, name);
9640         }
9641
9642       DECL_INITIAL (decl) = make_node (BLOCK);
9643       current_function_decl = decl;
9644       init_function_start (decl);
9645       first_function_block_is_cold = false;
9646       /* Make sure unwind info is emitted for the thunk if needed.  */
9647       final_start_function (emit_barrier (), asm_out_file, 1);
9648
9649       /* Pad stack IP move with 4 instructions (two NOPs count
9650          as one instruction).  */
9651       if (TARGET_PAD_SHORT_FUNCTION)
9652         {
9653           int i = 8;
9654
9655           while (i--)
9656             fputs ("\tnop\n", asm_out_file);
9657         }
9658
9659       xops[0] = gen_rtx_REG (Pmode, regno);
9660       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9661       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
9662       output_asm_insn ("%!ret", NULL);
9663       final_end_function ();
9664       init_insn_lengths ();
9665       free_after_compilation (cfun);
9666       set_cfun (NULL);
9667       current_function_decl = NULL;
9668     }
9669
9670   if (flag_split_stack)
9671     file_end_indicate_split_stack ();
9672 }
9673
9674 /* Emit code for the SET_GOT patterns.  */
9675
9676 const char *
9677 output_set_got (rtx dest, rtx label)
9678 {
9679   rtx xops[3];
9680
9681   xops[0] = dest;
9682
9683   if (TARGET_VXWORKS_RTP && flag_pic)
9684     {
9685       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
9686       xops[2] = gen_rtx_MEM (Pmode,
9687                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
9688       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
9689
9690       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
9691          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
9692          an unadorned address.  */
9693       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
9694       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
9695       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
9696       return "";
9697     }
9698
9699   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
9700
9701   if (!flag_pic)
9702     {
9703       if (TARGET_MACHO)
9704         /* We don't need a pic base, we're not producing pic.  */
9705         gcc_unreachable ();
9706
9707       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
9708       output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
9709       targetm.asm_out.internal_label (asm_out_file, "L",
9710                                       CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
9711     }
9712   else
9713     {
9714       char name[32];
9715       get_pc_thunk_name (name, REGNO (dest));
9716       pic_labels_used |= 1 << REGNO (dest);
9717
9718       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
9719       xops[2] = gen_rtx_MEM (QImode, xops[2]);
9720       output_asm_insn ("%!call\t%X2", xops);
9721
9722 #if TARGET_MACHO
9723       /* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here.
9724          This is what will be referenced by the Mach-O PIC subsystem.  */
9725       if (machopic_should_output_picbase_label () || !label)
9726         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
9727
9728       /* When we are restoring the pic base at the site of a nonlocal label,
9729          and we decided to emit the pic base above, we will still output a
9730          local label used for calculating the correction offset (even though
9731          the offset will be 0 in that case).  */
9732       if (label)
9733         targetm.asm_out.internal_label (asm_out_file, "L",
9734                                            CODE_LABEL_NUMBER (label));
9735 #endif
9736     }
9737
9738   if (!TARGET_MACHO)
9739     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
9740
9741   return "";
9742 }
9743
9744 /* Generate an "push" pattern for input ARG.  */
9745
9746 static rtx
9747 gen_push (rtx arg)
9748 {
9749   struct machine_function *m = cfun->machine;
9750
9751   if (m->fs.cfa_reg == stack_pointer_rtx)
9752     m->fs.cfa_offset += UNITS_PER_WORD;
9753   m->fs.sp_offset += UNITS_PER_WORD;
9754
9755   if (REG_P (arg) && GET_MODE (arg) != word_mode)
9756     arg = gen_rtx_REG (word_mode, REGNO (arg));
9757
9758   return gen_rtx_SET (VOIDmode,
9759                       gen_rtx_MEM (word_mode,
9760                                    gen_rtx_PRE_DEC (Pmode,
9761                                                     stack_pointer_rtx)),
9762                       arg);
9763 }
9764
9765 /* Generate an "pop" pattern for input ARG.  */
9766
9767 static rtx
9768 gen_pop (rtx arg)
9769 {
9770   if (REG_P (arg) && GET_MODE (arg) != word_mode)
9771     arg = gen_rtx_REG (word_mode, REGNO (arg));
9772
9773   return gen_rtx_SET (VOIDmode,
9774                       arg,
9775                       gen_rtx_MEM (word_mode,
9776                                    gen_rtx_POST_INC (Pmode,
9777                                                      stack_pointer_rtx)));
9778 }
9779
9780 /* Return >= 0 if there is an unused call-clobbered register available
9781    for the entire function.  */
9782
9783 static unsigned int
9784 ix86_select_alt_pic_regnum (void)
9785 {
9786   if (ix86_use_pseudo_pic_reg ())
9787     return INVALID_REGNUM;
9788
9789   if (crtl->is_leaf
9790       && !crtl->profile
9791       && !ix86_current_function_calls_tls_descriptor)
9792     {
9793       int i, drap;
9794       /* Can't use the same register for both PIC and DRAP.  */
9795       if (crtl->drap_reg)
9796         drap = REGNO (crtl->drap_reg);
9797       else
9798         drap = -1;
9799       for (i = 2; i >= 0; --i)
9800         if (i != drap && !df_regs_ever_live_p (i))
9801           return i;
9802     }
9803
9804   return INVALID_REGNUM;
9805 }
9806
9807 /* Return TRUE if we need to save REGNO.  */
9808
9809 static bool
9810 ix86_save_reg (unsigned int regno, bool maybe_eh_return)
9811 {
9812   if (regno == REAL_PIC_OFFSET_TABLE_REGNUM
9813       && pic_offset_table_rtx)
9814     {
9815       if (ix86_use_pseudo_pic_reg ())
9816         {
9817           /* REAL_PIC_OFFSET_TABLE_REGNUM used by call to
9818           _mcount in prologue.  */
9819           if (!TARGET_64BIT && flag_pic && crtl->profile)
9820             return true;
9821         }
9822       else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
9823                || crtl->profile
9824                || crtl->calls_eh_return
9825                || crtl->uses_const_pool
9826                || cfun->has_nonlocal_label)
9827         return ix86_select_alt_pic_regnum () == INVALID_REGNUM;
9828     }
9829
9830   if (crtl->calls_eh_return && maybe_eh_return)
9831     {
9832       unsigned i;
9833       for (i = 0; ; i++)
9834         {
9835           unsigned test = EH_RETURN_DATA_REGNO (i);
9836           if (test == INVALID_REGNUM)
9837             break;
9838           if (test == regno)
9839             return true;
9840         }
9841     }
9842
9843   if (crtl->drap_reg
9844       && regno == REGNO (crtl->drap_reg)
9845       && !cfun->machine->no_drap_save_restore)
9846     return true;
9847
9848   return (df_regs_ever_live_p (regno)
9849           && !call_used_regs[regno]
9850           && !fixed_regs[regno]
9851           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
9852 }
9853
9854 /* Return number of saved general prupose registers.  */
9855
9856 static int
9857 ix86_nsaved_regs (void)
9858 {
9859   int nregs = 0;
9860   int regno;
9861
9862   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9863     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
9864       nregs ++;
9865   return nregs;
9866 }
9867
9868 /* Return number of saved SSE registrers.  */
9869
9870 static int
9871 ix86_nsaved_sseregs (void)
9872 {
9873   int nregs = 0;
9874   int regno;
9875
9876   if (!TARGET_64BIT_MS_ABI)
9877     return 0;
9878   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9879     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
9880       nregs ++;
9881   return nregs;
9882 }
9883
9884 /* Given FROM and TO register numbers, say whether this elimination is
9885    allowed.  If stack alignment is needed, we can only replace argument
9886    pointer with hard frame pointer, or replace frame pointer with stack
9887    pointer.  Otherwise, frame pointer elimination is automatically
9888    handled and all other eliminations are valid.  */
9889
9890 static bool
9891 ix86_can_eliminate (const int from, const int to)
9892 {
9893   if (stack_realign_fp)
9894     return ((from == ARG_POINTER_REGNUM
9895              && to == HARD_FRAME_POINTER_REGNUM)
9896             || (from == FRAME_POINTER_REGNUM
9897                 && to == STACK_POINTER_REGNUM));
9898   else
9899     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true;
9900 }
9901
9902 /* Return the offset between two registers, one to be eliminated, and the other
9903    its replacement, at the start of a routine.  */
9904
9905 HOST_WIDE_INT
9906 ix86_initial_elimination_offset (int from, int to)
9907 {
9908   struct ix86_frame frame;
9909   ix86_compute_frame_layout (&frame);
9910
9911   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9912     return frame.hard_frame_pointer_offset;
9913   else if (from == FRAME_POINTER_REGNUM
9914            && to == HARD_FRAME_POINTER_REGNUM)
9915     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
9916   else
9917     {
9918       gcc_assert (to == STACK_POINTER_REGNUM);
9919
9920       if (from == ARG_POINTER_REGNUM)
9921         return frame.stack_pointer_offset;
9922
9923       gcc_assert (from == FRAME_POINTER_REGNUM);
9924       return frame.stack_pointer_offset - frame.frame_pointer_offset;
9925     }
9926 }
9927
9928 /* In a dynamically-aligned function, we can't know the offset from
9929    stack pointer to frame pointer, so we must ensure that setjmp
9930    eliminates fp against the hard fp (%ebp) rather than trying to
9931    index from %esp up to the top of the frame across a gap that is
9932    of unknown (at compile-time) size.  */
9933 static rtx
9934 ix86_builtin_setjmp_frame_value (void)
9935 {
9936   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
9937 }
9938
9939 /* When using -fsplit-stack, the allocation routines set a field in
9940    the TCB to the bottom of the stack plus this much space, measured
9941    in bytes.  */
9942
9943 #define SPLIT_STACK_AVAILABLE 256
9944
9945 /* Fill structure ix86_frame about frame of currently computed function.  */
9946
9947 static void
9948 ix86_compute_frame_layout (struct ix86_frame *frame)
9949 {
9950   unsigned HOST_WIDE_INT stack_alignment_needed;
9951   HOST_WIDE_INT offset;
9952   unsigned HOST_WIDE_INT preferred_alignment;
9953   HOST_WIDE_INT size = get_frame_size ();
9954   HOST_WIDE_INT to_allocate;
9955
9956   frame->nregs = ix86_nsaved_regs ();
9957   frame->nsseregs = ix86_nsaved_sseregs ();
9958
9959   /* 64-bit MS ABI seem to require stack alignment to be always 16 except for
9960      function prologues and leaf.  */
9961   if ((TARGET_64BIT_MS_ABI && crtl->preferred_stack_boundary < 128)
9962       && (!crtl->is_leaf || cfun->calls_alloca != 0
9963           || ix86_current_function_calls_tls_descriptor))
9964     {
9965       crtl->preferred_stack_boundary = 128;
9966       crtl->stack_alignment_needed = 128;
9967     }
9968   /* preferred_stack_boundary is never updated for call
9969      expanded from tls descriptor. Update it here. We don't update it in
9970      expand stage because according to the comments before
9971      ix86_current_function_calls_tls_descriptor, tls calls may be optimized
9972      away.  */
9973   else if (ix86_current_function_calls_tls_descriptor
9974            && crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
9975     {
9976       crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
9977       if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
9978         crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
9979     }
9980
9981   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
9982   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
9983
9984   gcc_assert (!size || stack_alignment_needed);
9985   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
9986   gcc_assert (preferred_alignment <= stack_alignment_needed);
9987
9988   /* For SEH we have to limit the amount of code movement into the prologue.
9989      At present we do this via a BLOCKAGE, at which point there's very little
9990      scheduling that can be done, which means that there's very little point
9991      in doing anything except PUSHs.  */
9992   if (TARGET_SEH)
9993     cfun->machine->use_fast_prologue_epilogue = false;
9994
9995   /* During reload iteration the amount of registers saved can change.
9996      Recompute the value as needed.  Do not recompute when amount of registers
9997      didn't change as reload does multiple calls to the function and does not
9998      expect the decision to change within single iteration.  */
9999   else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun))
10000            && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
10001     {
10002       int count = frame->nregs;
10003       struct cgraph_node *node = cgraph_node::get (current_function_decl);
10004
10005       cfun->machine->use_fast_prologue_epilogue_nregs = count;
10006
10007       /* The fast prologue uses move instead of push to save registers.  This
10008          is significantly longer, but also executes faster as modern hardware
10009          can execute the moves in parallel, but can't do that for push/pop.
10010
10011          Be careful about choosing what prologue to emit:  When function takes
10012          many instructions to execute we may use slow version as well as in
10013          case function is known to be outside hot spot (this is known with
10014          feedback only).  Weight the size of function by number of registers
10015          to save as it is cheap to use one or two push instructions but very
10016          slow to use many of them.  */
10017       if (count)
10018         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
10019       if (node->frequency < NODE_FREQUENCY_NORMAL
10020           || (flag_branch_probabilities
10021               && node->frequency < NODE_FREQUENCY_HOT))
10022         cfun->machine->use_fast_prologue_epilogue = false;
10023       else
10024         cfun->machine->use_fast_prologue_epilogue
10025            = !expensive_function_p (count);
10026     }
10027
10028   frame->save_regs_using_mov
10029     = (TARGET_PROLOGUE_USING_MOVE && cfun->machine->use_fast_prologue_epilogue
10030        /* If static stack checking is enabled and done with probes,
10031           the registers need to be saved before allocating the frame.  */
10032        && flag_stack_check != STATIC_BUILTIN_STACK_CHECK);
10033
10034   /* Skip return address.  */
10035   offset = UNITS_PER_WORD;
10036
10037   /* Skip pushed static chain.  */
10038   if (ix86_static_chain_on_stack)
10039     offset += UNITS_PER_WORD;
10040
10041   /* Skip saved base pointer.  */
10042   if (frame_pointer_needed)
10043     offset += UNITS_PER_WORD;
10044   frame->hfp_save_offset = offset;
10045
10046   /* The traditional frame pointer location is at the top of the frame.  */
10047   frame->hard_frame_pointer_offset = offset;
10048
10049   /* Register save area */
10050   offset += frame->nregs * UNITS_PER_WORD;
10051   frame->reg_save_offset = offset;
10052
10053   /* On SEH target, registers are pushed just before the frame pointer
10054      location.  */
10055   if (TARGET_SEH)
10056     frame->hard_frame_pointer_offset = offset;
10057
10058   /* Align and set SSE register save area.  */
10059   if (frame->nsseregs)
10060     {
10061       /* The only ABI that has saved SSE registers (Win64) also has a
10062          16-byte aligned default stack, and thus we don't need to be
10063          within the re-aligned local stack frame to save them.  */
10064       gcc_assert (INCOMING_STACK_BOUNDARY >= 128);
10065       offset = (offset + 16 - 1) & -16;
10066       offset += frame->nsseregs * 16;
10067     }
10068   frame->sse_reg_save_offset = offset;
10069
10070   /* The re-aligned stack starts here.  Values before this point are not
10071      directly comparable with values below this point.  In order to make
10072      sure that no value happens to be the same before and after, force
10073      the alignment computation below to add a non-zero value.  */
10074   if (stack_realign_fp)
10075     offset = (offset + stack_alignment_needed) & -stack_alignment_needed;
10076
10077   /* Va-arg area */
10078   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
10079   offset += frame->va_arg_size;
10080
10081   /* Align start of frame for local function.  */
10082   if (stack_realign_fp
10083       || offset != frame->sse_reg_save_offset
10084       || size != 0
10085       || !crtl->is_leaf
10086       || cfun->calls_alloca
10087       || ix86_current_function_calls_tls_descriptor)
10088     offset = (offset + stack_alignment_needed - 1) & -stack_alignment_needed;
10089
10090   /* Frame pointer points here.  */
10091   frame->frame_pointer_offset = offset;
10092
10093   offset += size;
10094
10095   /* Add outgoing arguments area.  Can be skipped if we eliminated
10096      all the function calls as dead code.
10097      Skipping is however impossible when function calls alloca.  Alloca
10098      expander assumes that last crtl->outgoing_args_size
10099      of stack frame are unused.  */
10100   if (ACCUMULATE_OUTGOING_ARGS
10101       && (!crtl->is_leaf || cfun->calls_alloca
10102           || ix86_current_function_calls_tls_descriptor))
10103     {
10104       offset += crtl->outgoing_args_size;
10105       frame->outgoing_arguments_size = crtl->outgoing_args_size;
10106     }
10107   else
10108     frame->outgoing_arguments_size = 0;
10109
10110   /* Align stack boundary.  Only needed if we're calling another function
10111      or using alloca.  */
10112   if (!crtl->is_leaf || cfun->calls_alloca
10113       || ix86_current_function_calls_tls_descriptor)
10114     offset = (offset + preferred_alignment - 1) & -preferred_alignment;
10115
10116   /* We've reached end of stack frame.  */
10117   frame->stack_pointer_offset = offset;
10118
10119   /* Size prologue needs to allocate.  */
10120   to_allocate = offset - frame->sse_reg_save_offset;
10121
10122   if ((!to_allocate && frame->nregs <= 1)
10123       || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000))
10124     frame->save_regs_using_mov = false;
10125
10126   if (ix86_using_red_zone ()
10127       && crtl->sp_is_unchanging
10128       && crtl->is_leaf
10129       && !ix86_current_function_calls_tls_descriptor)
10130     {
10131       frame->red_zone_size = to_allocate;
10132       if (frame->save_regs_using_mov)
10133         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
10134       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
10135         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
10136     }
10137   else
10138     frame->red_zone_size = 0;
10139   frame->stack_pointer_offset -= frame->red_zone_size;
10140
10141   /* The SEH frame pointer location is near the bottom of the frame.
10142      This is enforced by the fact that the difference between the
10143      stack pointer and the frame pointer is limited to 240 bytes in
10144      the unwind data structure.  */
10145   if (TARGET_SEH)
10146     {
10147       HOST_WIDE_INT diff;
10148
10149       /* If we can leave the frame pointer where it is, do so.  Also, returns
10150          the establisher frame for __builtin_frame_address (0).  */
10151       diff = frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
10152       if (diff <= SEH_MAX_FRAME_SIZE
10153           && (diff > 240 || (diff & 15) != 0)
10154           && !crtl->accesses_prior_frames)
10155         {
10156           /* Ideally we'd determine what portion of the local stack frame
10157              (within the constraint of the lowest 240) is most heavily used.
10158              But without that complication, simply bias the frame pointer
10159              by 128 bytes so as to maximize the amount of the local stack
10160              frame that is addressable with 8-bit offsets.  */
10161           frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128;
10162         }
10163     }
10164 }
10165
10166 /* This is semi-inlined memory_address_length, but simplified
10167    since we know that we're always dealing with reg+offset, and
10168    to avoid having to create and discard all that rtl.  */
10169
10170 static inline int
10171 choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
10172 {
10173   int len = 4;
10174
10175   if (offset == 0)
10176     {
10177       /* EBP and R13 cannot be encoded without an offset.  */
10178       len = (regno == BP_REG || regno == R13_REG);
10179     }
10180   else if (IN_RANGE (offset, -128, 127))
10181     len = 1;
10182
10183   /* ESP and R12 must be encoded with a SIB byte.  */
10184   if (regno == SP_REG || regno == R12_REG)
10185     len++;
10186
10187   return len;
10188 }
10189
10190 /* Return an RTX that points to CFA_OFFSET within the stack frame.
10191    The valid base registers are taken from CFUN->MACHINE->FS.  */
10192
10193 static rtx
10194 choose_baseaddr (HOST_WIDE_INT cfa_offset)
10195 {
10196   const struct machine_function *m = cfun->machine;
10197   rtx base_reg = NULL;
10198   HOST_WIDE_INT base_offset = 0;
10199
10200   if (m->use_fast_prologue_epilogue)
10201     {
10202       /* Choose the base register most likely to allow the most scheduling
10203          opportunities.  Generally FP is valid throughout the function,
10204          while DRAP must be reloaded within the epilogue.  But choose either
10205          over the SP due to increased encoding size.  */
10206
10207       if (m->fs.fp_valid)
10208         {
10209           base_reg = hard_frame_pointer_rtx;
10210           base_offset = m->fs.fp_offset - cfa_offset;
10211         }
10212       else if (m->fs.drap_valid)
10213         {
10214           base_reg = crtl->drap_reg;
10215           base_offset = 0 - cfa_offset;
10216         }
10217       else if (m->fs.sp_valid)
10218         {
10219           base_reg = stack_pointer_rtx;
10220           base_offset = m->fs.sp_offset - cfa_offset;
10221         }
10222     }
10223   else
10224     {
10225       HOST_WIDE_INT toffset;
10226       int len = 16, tlen;
10227
10228       /* Choose the base register with the smallest address encoding.
10229          With a tie, choose FP > DRAP > SP.  */
10230       if (m->fs.sp_valid)
10231         {
10232           base_reg = stack_pointer_rtx;
10233           base_offset = m->fs.sp_offset - cfa_offset;
10234           len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset);
10235         }
10236       if (m->fs.drap_valid)
10237         {
10238           toffset = 0 - cfa_offset;
10239           tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset);
10240           if (tlen <= len)
10241             {
10242               base_reg = crtl->drap_reg;
10243               base_offset = toffset;
10244               len = tlen;
10245             }
10246         }
10247       if (m->fs.fp_valid)
10248         {
10249           toffset = m->fs.fp_offset - cfa_offset;
10250           tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset);
10251           if (tlen <= len)
10252             {
10253               base_reg = hard_frame_pointer_rtx;
10254               base_offset = toffset;
10255               len = tlen;
10256             }
10257         }
10258     }
10259   gcc_assert (base_reg != NULL);
10260
10261   return plus_constant (Pmode, base_reg, base_offset);
10262 }
10263
10264 /* Emit code to save registers in the prologue.  */
10265
10266 static void
10267 ix86_emit_save_regs (void)
10268 {
10269   unsigned int regno;
10270   rtx insn;
10271
10272   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
10273     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10274       {
10275         insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno)));
10276         RTX_FRAME_RELATED_P (insn) = 1;
10277       }
10278 }
10279
10280 /* Emit a single register save at CFA - CFA_OFFSET.  */
10281
10282 static void
10283 ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
10284                               HOST_WIDE_INT cfa_offset)
10285 {
10286   struct machine_function *m = cfun->machine;
10287   rtx reg = gen_rtx_REG (mode, regno);
10288   rtx mem, addr, base, insn;
10289
10290   addr = choose_baseaddr (cfa_offset);
10291   mem = gen_frame_mem (mode, addr);
10292
10293   /* For SSE saves, we need to indicate the 128-bit alignment.  */
10294   set_mem_align (mem, GET_MODE_ALIGNMENT (mode));
10295
10296   insn = emit_move_insn (mem, reg);
10297   RTX_FRAME_RELATED_P (insn) = 1;
10298
10299   base = addr;
10300   if (GET_CODE (base) == PLUS)
10301     base = XEXP (base, 0);
10302   gcc_checking_assert (REG_P (base));
10303
10304   /* When saving registers into a re-aligned local stack frame, avoid
10305      any tricky guessing by dwarf2out.  */
10306   if (m->fs.realigned)
10307     {
10308       gcc_checking_assert (stack_realign_drap);
10309
10310       if (regno == REGNO (crtl->drap_reg))
10311         {
10312           /* A bit of a hack.  We force the DRAP register to be saved in
10313              the re-aligned stack frame, which provides us with a copy
10314              of the CFA that will last past the prologue.  Install it.  */
10315           gcc_checking_assert (cfun->machine->fs.fp_valid);
10316           addr = plus_constant (Pmode, hard_frame_pointer_rtx,
10317                                 cfun->machine->fs.fp_offset - cfa_offset);
10318           mem = gen_rtx_MEM (mode, addr);
10319           add_reg_note (insn, REG_CFA_DEF_CFA, mem);
10320         }
10321       else
10322         {
10323           /* The frame pointer is a stable reference within the
10324              aligned frame.  Use it.  */
10325           gcc_checking_assert (cfun->machine->fs.fp_valid);
10326           addr = plus_constant (Pmode, hard_frame_pointer_rtx,
10327                                 cfun->machine->fs.fp_offset - cfa_offset);
10328           mem = gen_rtx_MEM (mode, addr);
10329           add_reg_note (insn, REG_CFA_EXPRESSION,
10330                         gen_rtx_SET (VOIDmode, mem, reg));
10331         }
10332     }
10333
10334   /* The memory may not be relative to the current CFA register,
10335      which means that we may need to generate a new pattern for
10336      use by the unwind info.  */
10337   else if (base != m->fs.cfa_reg)
10338     {
10339       addr = plus_constant (Pmode, m->fs.cfa_reg,
10340                             m->fs.cfa_offset - cfa_offset);
10341       mem = gen_rtx_MEM (mode, addr);
10342       add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (VOIDmode, mem, reg));
10343     }
10344 }
10345
10346 /* Emit code to save registers using MOV insns.
10347    First register is stored at CFA - CFA_OFFSET.  */
10348 static void
10349 ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
10350 {
10351   unsigned int regno;
10352
10353   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10354     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10355       {
10356         ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
10357         cfa_offset -= UNITS_PER_WORD;
10358       }
10359 }
10360
10361 /* Emit code to save SSE registers using MOV insns.
10362    First register is stored at CFA - CFA_OFFSET.  */
10363 static void
10364 ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
10365 {
10366   unsigned int regno;
10367
10368   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10369     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10370       {
10371         ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
10372         cfa_offset -= 16;
10373       }
10374 }
10375
10376 static GTY(()) rtx queued_cfa_restores;
10377
10378 /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
10379    manipulation insn.  The value is on the stack at CFA - CFA_OFFSET.
10380    Don't add the note if the previously saved value will be left untouched
10381    within stack red-zone till return, as unwinders can find the same value
10382    in the register and on the stack.  */
10383
10384 static void
10385 ix86_add_cfa_restore_note (rtx insn, rtx reg, HOST_WIDE_INT cfa_offset)
10386 {
10387   if (!crtl->shrink_wrapped
10388       && cfa_offset <= cfun->machine->fs.red_zone_offset)
10389     return;
10390
10391   if (insn)
10392     {
10393       add_reg_note (insn, REG_CFA_RESTORE, reg);
10394       RTX_FRAME_RELATED_P (insn) = 1;
10395     }
10396   else
10397     queued_cfa_restores
10398       = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
10399 }
10400
10401 /* Add queued REG_CFA_RESTORE notes if any to INSN.  */
10402
10403 static void
10404 ix86_add_queued_cfa_restore_notes (rtx insn)
10405 {
10406   rtx last;
10407   if (!queued_cfa_restores)
10408     return;
10409   for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
10410     ;
10411   XEXP (last, 1) = REG_NOTES (insn);
10412   REG_NOTES (insn) = queued_cfa_restores;
10413   queued_cfa_restores = NULL_RTX;
10414   RTX_FRAME_RELATED_P (insn) = 1;
10415 }
10416
10417 /* Expand prologue or epilogue stack adjustment.
10418    The pattern exist to put a dependency on all ebp-based memory accesses.
10419    STYLE should be negative if instructions should be marked as frame related,
10420    zero if %r11 register is live and cannot be freely used and positive
10421    otherwise.  */
10422
10423 static void
10424 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
10425                            int style, bool set_cfa)
10426 {
10427   struct machine_function *m = cfun->machine;
10428   rtx insn;
10429   bool add_frame_related_expr = false;
10430
10431   if (Pmode == SImode)
10432     insn = gen_pro_epilogue_adjust_stack_si_add (dest, src, offset);
10433   else if (x86_64_immediate_operand (offset, DImode))
10434     insn = gen_pro_epilogue_adjust_stack_di_add (dest, src, offset);
10435   else
10436     {
10437       rtx tmp;
10438       /* r11 is used by indirect sibcall return as well, set before the
10439          epilogue and used after the epilogue.  */
10440       if (style)
10441         tmp = gen_rtx_REG (DImode, R11_REG);
10442       else
10443         {
10444           gcc_assert (src != hard_frame_pointer_rtx
10445                       && dest != hard_frame_pointer_rtx);
10446           tmp = hard_frame_pointer_rtx;
10447         }
10448       insn = emit_insn (gen_rtx_SET (DImode, tmp, offset));
10449       if (style < 0)
10450         add_frame_related_expr = true;
10451
10452       insn = gen_pro_epilogue_adjust_stack_di_add (dest, src, tmp);
10453     }
10454
10455   insn = emit_insn (insn);
10456   if (style >= 0)
10457     ix86_add_queued_cfa_restore_notes (insn);
10458
10459   if (set_cfa)
10460     {
10461       rtx r;
10462
10463       gcc_assert (m->fs.cfa_reg == src);
10464       m->fs.cfa_offset += INTVAL (offset);
10465       m->fs.cfa_reg = dest;
10466
10467       r = gen_rtx_PLUS (Pmode, src, offset);
10468       r = gen_rtx_SET (VOIDmode, dest, r);
10469       add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
10470       RTX_FRAME_RELATED_P (insn) = 1;
10471     }
10472   else if (style < 0)
10473     {
10474       RTX_FRAME_RELATED_P (insn) = 1;
10475       if (add_frame_related_expr)
10476         {
10477           rtx r = gen_rtx_PLUS (Pmode, src, offset);
10478           r = gen_rtx_SET (VOIDmode, dest, r);
10479           add_reg_note (insn, REG_FRAME_RELATED_EXPR, r);
10480         }
10481     }
10482
10483   if (dest == stack_pointer_rtx)
10484     {
10485       HOST_WIDE_INT ooffset = m->fs.sp_offset;
10486       bool valid = m->fs.sp_valid;
10487
10488       if (src == hard_frame_pointer_rtx)
10489         {
10490           valid = m->fs.fp_valid;
10491           ooffset = m->fs.fp_offset;
10492         }
10493       else if (src == crtl->drap_reg)
10494         {
10495           valid = m->fs.drap_valid;
10496           ooffset = 0;
10497         }
10498       else
10499         {
10500           /* Else there are two possibilities: SP itself, which we set
10501              up as the default above.  Or EH_RETURN_STACKADJ_RTX, which is
10502              taken care of this by hand along the eh_return path.  */
10503           gcc_checking_assert (src == stack_pointer_rtx
10504                                || offset == const0_rtx);
10505         }
10506
10507       m->fs.sp_offset = ooffset - INTVAL (offset);
10508       m->fs.sp_valid = valid;
10509     }
10510 }
10511
10512 /* Find an available register to be used as dynamic realign argument
10513    pointer regsiter.  Such a register will be written in prologue and
10514    used in begin of body, so it must not be
10515         1. parameter passing register.
10516         2. GOT pointer.
10517    We reuse static-chain register if it is available.  Otherwise, we
10518    use DI for i386 and R13 for x86-64.  We chose R13 since it has
10519    shorter encoding.
10520
10521    Return: the regno of chosen register.  */
10522
10523 static unsigned int
10524 find_drap_reg (void)
10525 {
10526   tree decl = cfun->decl;
10527
10528   if (TARGET_64BIT)
10529     {
10530       /* Use R13 for nested function or function need static chain.
10531          Since function with tail call may use any caller-saved
10532          registers in epilogue, DRAP must not use caller-saved
10533          register in such case.  */
10534       if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
10535         return R13_REG;
10536
10537       return R10_REG;
10538     }
10539   else
10540     {
10541       /* Use DI for nested function or function need static chain.
10542          Since function with tail call may use any caller-saved
10543          registers in epilogue, DRAP must not use caller-saved
10544          register in such case.  */
10545       if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
10546         return DI_REG;
10547
10548       /* Reuse static chain register if it isn't used for parameter
10549          passing.  */
10550       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2)
10551         {
10552           unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl));
10553           if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0)
10554             return CX_REG;
10555         }
10556       return DI_REG;
10557     }
10558 }
10559
10560 /* Return minimum incoming stack alignment.  */
10561
10562 static unsigned int
10563 ix86_minimum_incoming_stack_boundary (bool sibcall)
10564 {
10565   unsigned int incoming_stack_boundary;
10566
10567   /* Prefer the one specified at command line. */
10568   if (ix86_user_incoming_stack_boundary)
10569     incoming_stack_boundary = ix86_user_incoming_stack_boundary;
10570   /* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary
10571      if -mstackrealign is used, it isn't used for sibcall check and
10572      estimated stack alignment is 128bit.  */
10573   else if (!sibcall
10574            && !TARGET_64BIT
10575            && ix86_force_align_arg_pointer
10576            && crtl->stack_alignment_estimated == 128)
10577     incoming_stack_boundary = MIN_STACK_BOUNDARY;
10578   else
10579     incoming_stack_boundary = ix86_default_incoming_stack_boundary;
10580
10581   /* Incoming stack alignment can be changed on individual functions
10582      via force_align_arg_pointer attribute.  We use the smallest
10583      incoming stack boundary.  */
10584   if (incoming_stack_boundary > MIN_STACK_BOUNDARY
10585       && lookup_attribute (ix86_force_align_arg_pointer_string,
10586                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
10587     incoming_stack_boundary = MIN_STACK_BOUNDARY;
10588
10589   /* The incoming stack frame has to be aligned at least at
10590      parm_stack_boundary.  */
10591   if (incoming_stack_boundary < crtl->parm_stack_boundary)
10592     incoming_stack_boundary = crtl->parm_stack_boundary;
10593
10594   /* Stack at entrance of main is aligned by runtime.  We use the
10595      smallest incoming stack boundary. */
10596   if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
10597       && DECL_NAME (current_function_decl)
10598       && MAIN_NAME_P (DECL_NAME (current_function_decl))
10599       && DECL_FILE_SCOPE_P (current_function_decl))
10600     incoming_stack_boundary = MAIN_STACK_BOUNDARY;
10601
10602   return incoming_stack_boundary;
10603 }
10604
10605 /* Update incoming stack boundary and estimated stack alignment.  */
10606
10607 static void
10608 ix86_update_stack_boundary (void)
10609 {
10610   ix86_incoming_stack_boundary
10611     = ix86_minimum_incoming_stack_boundary (false);
10612
10613   /* x86_64 vararg needs 16byte stack alignment for register save
10614      area.  */
10615   if (TARGET_64BIT
10616       && cfun->stdarg
10617       && crtl->stack_alignment_estimated < 128)
10618     crtl->stack_alignment_estimated = 128;
10619 }
10620
10621 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
10622    needed or an rtx for DRAP otherwise.  */
10623
10624 static rtx
10625 ix86_get_drap_rtx (void)
10626 {
10627   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
10628     crtl->need_drap = true;
10629
10630   if (stack_realign_drap)
10631     {
10632       /* Assign DRAP to vDRAP and returns vDRAP */
10633       unsigned int regno = find_drap_reg ();
10634       rtx drap_vreg;
10635       rtx arg_ptr;
10636       rtx_insn *seq, *insn;
10637
10638       arg_ptr = gen_rtx_REG (Pmode, regno);
10639       crtl->drap_reg = arg_ptr;
10640
10641       start_sequence ();
10642       drap_vreg = copy_to_reg (arg_ptr);
10643       seq = get_insns ();
10644       end_sequence ();
10645
10646       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
10647       if (!optimize)
10648         {
10649           add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg);
10650           RTX_FRAME_RELATED_P (insn) = 1;
10651         }
10652       return drap_vreg;
10653     }
10654   else
10655     return NULL;
10656 }
10657
10658 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
10659
10660 static rtx
10661 ix86_internal_arg_pointer (void)
10662 {
10663   return virtual_incoming_args_rtx;
10664 }
10665
10666 struct scratch_reg {
10667   rtx reg;
10668   bool saved;
10669 };
10670
10671 /* Return a short-lived scratch register for use on function entry.
10672    In 32-bit mode, it is valid only after the registers are saved
10673    in the prologue.  This register must be released by means of
10674    release_scratch_register_on_entry once it is dead.  */
10675
10676 static void
10677 get_scratch_register_on_entry (struct scratch_reg *sr)
10678 {
10679   int regno;
10680
10681   sr->saved = false;
10682
10683   if (TARGET_64BIT)
10684     {
10685       /* We always use R11 in 64-bit mode.  */
10686       regno = R11_REG;
10687     }
10688   else
10689     {
10690       tree decl = current_function_decl, fntype = TREE_TYPE (decl);
10691       bool fastcall_p
10692         = lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
10693       bool thiscall_p
10694         = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
10695       bool static_chain_p = DECL_STATIC_CHAIN (decl);
10696       int regparm = ix86_function_regparm (fntype, decl);
10697       int drap_regno
10698         = crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM;
10699
10700       /* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax
10701           for the static chain register.  */
10702       if ((regparm < 1 || (fastcall_p && !static_chain_p))
10703           && drap_regno != AX_REG)
10704         regno = AX_REG;
10705       /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
10706           for the static chain register.  */
10707       else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
10708         regno = AX_REG;
10709       else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
10710         regno = DX_REG;
10711       /* ecx is the static chain register.  */
10712       else if (regparm < 3 && !fastcall_p && !thiscall_p
10713                && !static_chain_p
10714                && drap_regno != CX_REG)
10715         regno = CX_REG;
10716       else if (ix86_save_reg (BX_REG, true))
10717         regno = BX_REG;
10718       /* esi is the static chain register.  */
10719       else if (!(regparm == 3 && static_chain_p)
10720                && ix86_save_reg (SI_REG, true))
10721         regno = SI_REG;
10722       else if (ix86_save_reg (DI_REG, true))
10723         regno = DI_REG;
10724       else
10725         {
10726           regno = (drap_regno == AX_REG ? DX_REG : AX_REG);
10727           sr->saved = true;
10728         }
10729     }
10730
10731   sr->reg = gen_rtx_REG (Pmode, regno);
10732   if (sr->saved)
10733     {
10734       rtx insn = emit_insn (gen_push (sr->reg));
10735       RTX_FRAME_RELATED_P (insn) = 1;
10736     }
10737 }
10738
10739 /* Release a scratch register obtained from the preceding function.  */
10740
10741 static void
10742 release_scratch_register_on_entry (struct scratch_reg *sr)
10743 {
10744   if (sr->saved)
10745     {
10746       struct machine_function *m = cfun->machine;
10747       rtx x, insn = emit_insn (gen_pop (sr->reg));
10748
10749       /* The RTX_FRAME_RELATED_P mechanism doesn't know about pop.  */
10750       RTX_FRAME_RELATED_P (insn) = 1;
10751       x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
10752       x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
10753       add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
10754       m->fs.sp_offset -= UNITS_PER_WORD;
10755     }
10756 }
10757
10758 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
10759
10760 /* Emit code to adjust the stack pointer by SIZE bytes while probing it.  */
10761
10762 static void
10763 ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
10764 {
10765   /* We skip the probe for the first interval + a small dope of 4 words and
10766      probe that many bytes past the specified size to maintain a protection
10767      area at the botton of the stack.  */
10768   const int dope = 4 * UNITS_PER_WORD;
10769   rtx size_rtx = GEN_INT (size), last;
10770
10771   /* See if we have a constant small number of probes to generate.  If so,
10772      that's the easy case.  The run-time loop is made up of 11 insns in the
10773      generic case while the compile-time loop is made up of 3+2*(n-1) insns
10774      for n # of intervals.  */
10775   if (size <= 5 * PROBE_INTERVAL)
10776     {
10777       HOST_WIDE_INT i, adjust;
10778       bool first_probe = true;
10779
10780       /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for
10781          values of N from 1 until it exceeds SIZE.  If only one probe is
10782          needed, this will not generate any code.  Then adjust and probe
10783          to PROBE_INTERVAL + SIZE.  */
10784       for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
10785         {
10786           if (first_probe)
10787             {
10788               adjust = 2 * PROBE_INTERVAL + dope;
10789               first_probe = false;
10790             }
10791           else
10792             adjust = PROBE_INTERVAL;
10793
10794           emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10795                                   plus_constant (Pmode, stack_pointer_rtx,
10796                                                  -adjust)));
10797           emit_stack_probe (stack_pointer_rtx);
10798         }
10799
10800       if (first_probe)
10801         adjust = size + PROBE_INTERVAL + dope;
10802       else
10803         adjust = size + PROBE_INTERVAL - i;
10804
10805       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10806                               plus_constant (Pmode, stack_pointer_rtx,
10807                                              -adjust)));
10808       emit_stack_probe (stack_pointer_rtx);
10809
10810       /* Adjust back to account for the additional first interval.  */
10811       last = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10812                                      plus_constant (Pmode, stack_pointer_rtx,
10813                                                     PROBE_INTERVAL + dope)));
10814     }
10815
10816   /* Otherwise, do the same as above, but in a loop.  Note that we must be
10817      extra careful with variables wrapping around because we might be at
10818      the very top (or the very bottom) of the address space and we have
10819      to be able to handle this case properly; in particular, we use an
10820      equality test for the loop condition.  */
10821   else
10822     {
10823       HOST_WIDE_INT rounded_size;
10824       struct scratch_reg sr;
10825
10826       get_scratch_register_on_entry (&sr);
10827
10828
10829       /* Step 1: round SIZE to the previous multiple of the interval.  */
10830
10831       rounded_size = size & -PROBE_INTERVAL;
10832
10833
10834       /* Step 2: compute initial and final value of the loop counter.  */
10835
10836       /* SP = SP_0 + PROBE_INTERVAL.  */
10837       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10838                               plus_constant (Pmode, stack_pointer_rtx,
10839                                              - (PROBE_INTERVAL + dope))));
10840
10841       /* LAST_ADDR = SP_0 + PROBE_INTERVAL + ROUNDED_SIZE.  */
10842       emit_move_insn (sr.reg, GEN_INT (-rounded_size));
10843       emit_insn (gen_rtx_SET (VOIDmode, sr.reg,
10844                               gen_rtx_PLUS (Pmode, sr.reg,
10845                                             stack_pointer_rtx)));
10846
10847
10848       /* Step 3: the loop
10849
10850          while (SP != LAST_ADDR)
10851            {
10852              SP = SP + PROBE_INTERVAL
10853              probe at SP
10854            }
10855
10856          adjusts SP and probes to PROBE_INTERVAL + N * PROBE_INTERVAL for
10857          values of N from 1 until it is equal to ROUNDED_SIZE.  */
10858
10859       emit_insn (ix86_gen_adjust_stack_and_probe (sr.reg, sr.reg, size_rtx));
10860
10861
10862       /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot
10863          assert at compile-time that SIZE is equal to ROUNDED_SIZE.  */
10864
10865       if (size != rounded_size)
10866         {
10867           emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10868                                   plus_constant (Pmode, stack_pointer_rtx,
10869                                                  rounded_size - size)));
10870           emit_stack_probe (stack_pointer_rtx);
10871         }
10872
10873       /* Adjust back to account for the additional first interval.  */
10874       last = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10875                                      plus_constant (Pmode, stack_pointer_rtx,
10876                                                     PROBE_INTERVAL + dope)));
10877
10878       release_scratch_register_on_entry (&sr);
10879     }
10880
10881   gcc_assert (cfun->machine->fs.cfa_reg != stack_pointer_rtx);
10882
10883   /* Even if the stack pointer isn't the CFA register, we need to correctly
10884      describe the adjustments made to it, in particular differentiate the
10885      frame-related ones from the frame-unrelated ones.  */
10886   if (size > 0)
10887     {
10888       rtx expr = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
10889       XVECEXP (expr, 0, 0)
10890         = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10891                        plus_constant (Pmode, stack_pointer_rtx, -size));
10892       XVECEXP (expr, 0, 1)
10893         = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10894                        plus_constant (Pmode, stack_pointer_rtx,
10895                                       PROBE_INTERVAL + dope + size));
10896       add_reg_note (last, REG_FRAME_RELATED_EXPR, expr);
10897       RTX_FRAME_RELATED_P (last) = 1;
10898
10899       cfun->machine->fs.sp_offset += size;
10900     }
10901
10902   /* Make sure nothing is scheduled before we are done.  */
10903   emit_insn (gen_blockage ());
10904 }
10905
10906 /* Adjust the stack pointer up to REG while probing it.  */
10907
10908 const char *
10909 output_adjust_stack_and_probe (rtx reg)
10910 {
10911   static int labelno = 0;
10912   char loop_lab[32], end_lab[32];
10913   rtx xops[2];
10914
10915   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
10916   ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
10917
10918   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
10919
10920   /* Jump to END_LAB if SP == LAST_ADDR.  */
10921   xops[0] = stack_pointer_rtx;
10922   xops[1] = reg;
10923   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
10924   fputs ("\tje\t", asm_out_file);
10925   assemble_name_raw (asm_out_file, end_lab);
10926   fputc ('\n', asm_out_file);
10927
10928   /* SP = SP + PROBE_INTERVAL.  */
10929   xops[1] = GEN_INT (PROBE_INTERVAL);
10930   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
10931
10932   /* Probe at SP.  */
10933   xops[1] = const0_rtx;
10934   output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops);
10935
10936   fprintf (asm_out_file, "\tjmp\t");
10937   assemble_name_raw (asm_out_file, loop_lab);
10938   fputc ('\n', asm_out_file);
10939
10940   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
10941
10942   return "";
10943 }
10944
10945 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
10946    inclusive.  These are offsets from the current stack pointer.  */
10947
10948 static void
10949 ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
10950 {
10951   /* See if we have a constant small number of probes to generate.  If so,
10952      that's the easy case.  The run-time loop is made up of 7 insns in the
10953      generic case while the compile-time loop is made up of n insns for n #
10954      of intervals.  */
10955   if (size <= 7 * PROBE_INTERVAL)
10956     {
10957       HOST_WIDE_INT i;
10958
10959       /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
10960          it exceeds SIZE.  If only one probe is needed, this will not
10961          generate any code.  Then probe at FIRST + SIZE.  */
10962       for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
10963         emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
10964                                          -(first + i)));
10965
10966       emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
10967                                        -(first + size)));
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, last;
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       /* TEST_OFFSET = FIRST.  */
10991       emit_move_insn (sr.reg, GEN_INT (-first));
10992
10993       /* LAST_OFFSET = FIRST + ROUNDED_SIZE.  */
10994       last = first + rounded_size;
10995
10996
10997       /* Step 3: the loop
10998
10999          while (TEST_ADDR != LAST_ADDR)
11000            {
11001              TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
11002              probe at TEST_ADDR
11003            }
11004
11005          probes at FIRST + N * PROBE_INTERVAL for values of N from 1
11006          until it is equal to ROUNDED_SIZE.  */
11007
11008       emit_insn (ix86_gen_probe_stack_range (sr.reg, sr.reg, GEN_INT (-last)));
11009
11010
11011       /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
11012          that SIZE is equal to ROUNDED_SIZE.  */
11013
11014       if (size != rounded_size)
11015         emit_stack_probe (plus_constant (Pmode,
11016                                          gen_rtx_PLUS (Pmode,
11017                                                        stack_pointer_rtx,
11018                                                        sr.reg),
11019                                          rounded_size - size));
11020
11021       release_scratch_register_on_entry (&sr);
11022     }
11023
11024   /* Make sure nothing is scheduled before we are done.  */
11025   emit_insn (gen_blockage ());
11026 }
11027
11028 /* Probe a range of stack addresses from REG to END, inclusive.  These are
11029    offsets from the current stack pointer.  */
11030
11031 const char *
11032 output_probe_stack_range (rtx reg, rtx end)
11033 {
11034   static int labelno = 0;
11035   char loop_lab[32], end_lab[32];
11036   rtx xops[3];
11037
11038   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
11039   ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
11040
11041   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
11042
11043   /* Jump to END_LAB if TEST_ADDR == LAST_ADDR.  */
11044   xops[0] = reg;
11045   xops[1] = end;
11046   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
11047   fputs ("\tje\t", asm_out_file);
11048   assemble_name_raw (asm_out_file, end_lab);
11049   fputc ('\n', asm_out_file);
11050
11051   /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL.  */
11052   xops[1] = GEN_INT (PROBE_INTERVAL);
11053   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
11054
11055   /* Probe at TEST_ADDR.  */
11056   xops[0] = stack_pointer_rtx;
11057   xops[1] = reg;
11058   xops[2] = const0_rtx;
11059   output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops);
11060
11061   fprintf (asm_out_file, "\tjmp\t");
11062   assemble_name_raw (asm_out_file, loop_lab);
11063   fputc ('\n', asm_out_file);
11064
11065   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
11066
11067   return "";
11068 }
11069
11070 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
11071    to be generated in correct form.  */
11072 static void
11073 ix86_finalize_stack_realign_flags (void)
11074 {
11075   /* Check if stack realign is really needed after reload, and
11076      stores result in cfun */
11077   unsigned int incoming_stack_boundary
11078     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
11079        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
11080   unsigned int stack_realign = (incoming_stack_boundary
11081                                 < (crtl->is_leaf
11082                                    ? crtl->max_used_stack_slot_alignment
11083                                    : crtl->stack_alignment_needed));
11084
11085   if (crtl->stack_realign_finalized)
11086     {
11087       /* After stack_realign_needed is finalized, we can't no longer
11088          change it.  */
11089       gcc_assert (crtl->stack_realign_needed == stack_realign);
11090       return;
11091     }
11092
11093   /* If the only reason for frame_pointer_needed is that we conservatively
11094      assumed stack realignment might be needed, but in the end nothing that
11095      needed the stack alignment had been spilled, clear frame_pointer_needed
11096      and say we don't need stack realignment.  */
11097   if (stack_realign
11098       && frame_pointer_needed
11099       && crtl->is_leaf
11100       && flag_omit_frame_pointer
11101       && crtl->sp_is_unchanging
11102       && !ix86_current_function_calls_tls_descriptor
11103       && !crtl->accesses_prior_frames
11104       && !cfun->calls_alloca
11105       && !crtl->calls_eh_return
11106       && !(flag_stack_check && STACK_CHECK_MOVING_SP)
11107       && !ix86_frame_pointer_required ()
11108       && get_frame_size () == 0
11109       && ix86_nsaved_sseregs () == 0
11110       && ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0)
11111     {
11112       HARD_REG_SET set_up_by_prologue, prologue_used;
11113       basic_block bb;
11114
11115       CLEAR_HARD_REG_SET (prologue_used);
11116       CLEAR_HARD_REG_SET (set_up_by_prologue);
11117       add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM);
11118       add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM);
11119       add_to_hard_reg_set (&set_up_by_prologue, Pmode,
11120                            HARD_FRAME_POINTER_REGNUM);
11121       FOR_EACH_BB_FN (bb, cfun)
11122         {
11123           rtx_insn *insn;
11124           FOR_BB_INSNS (bb, insn)
11125             if (NONDEBUG_INSN_P (insn)
11126                 && requires_stack_frame_p (insn, prologue_used,
11127                                            set_up_by_prologue))
11128               {
11129                 crtl->stack_realign_needed = stack_realign;
11130                 crtl->stack_realign_finalized = true;
11131                 return;
11132               }
11133         }
11134
11135       /* If drap has been set, but it actually isn't live at the start
11136          of the function, there is no reason to set it up.  */
11137       if (crtl->drap_reg)
11138         {
11139           basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
11140           if (! REGNO_REG_SET_P (DF_LR_IN (bb), REGNO (crtl->drap_reg)))
11141             {
11142               crtl->drap_reg = NULL_RTX;
11143               crtl->need_drap = false;
11144             }
11145         }
11146       else
11147         cfun->machine->no_drap_save_restore = true;
11148
11149       frame_pointer_needed = false;
11150       stack_realign = false;
11151       crtl->max_used_stack_slot_alignment = incoming_stack_boundary;
11152       crtl->stack_alignment_needed = incoming_stack_boundary;
11153       crtl->stack_alignment_estimated = incoming_stack_boundary;
11154       if (crtl->preferred_stack_boundary > incoming_stack_boundary)
11155         crtl->preferred_stack_boundary = incoming_stack_boundary;
11156       df_finish_pass (true);
11157       df_scan_alloc (NULL);
11158       df_scan_blocks ();
11159       df_compute_regs_ever_live (true);
11160       df_analyze ();
11161     }
11162
11163   crtl->stack_realign_needed = stack_realign;
11164   crtl->stack_realign_finalized = true;
11165 }
11166
11167 /* Delete SET_GOT right after entry block if it is allocated to reg.  */
11168
11169 static void
11170 ix86_elim_entry_set_got (rtx reg)
11171 {
11172   basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
11173   rtx_insn *c_insn = BB_HEAD (bb);
11174   if (!NONDEBUG_INSN_P (c_insn))
11175     c_insn = next_nonnote_nondebug_insn (c_insn);
11176   if (c_insn && NONJUMP_INSN_P (c_insn))
11177     {
11178       rtx pat = PATTERN (c_insn);
11179       if (GET_CODE (pat) == PARALLEL)
11180         {
11181           rtx vec = XVECEXP (pat, 0, 0);
11182           if (GET_CODE (vec) == SET
11183               && XINT (XEXP (vec, 1), 1) == UNSPEC_SET_GOT
11184               && REGNO (XEXP (vec, 0)) == REGNO (reg))
11185             delete_insn (c_insn);
11186         }
11187     }
11188 }
11189
11190 /* Expand the prologue into a bunch of separate insns.  */
11191
11192 void
11193 ix86_expand_prologue (void)
11194 {
11195   struct machine_function *m = cfun->machine;
11196   rtx insn, t;
11197   struct ix86_frame frame;
11198   HOST_WIDE_INT allocate;
11199   bool int_registers_saved;
11200   bool sse_registers_saved;
11201
11202   ix86_finalize_stack_realign_flags ();
11203
11204   /* DRAP should not coexist with stack_realign_fp */
11205   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
11206
11207   memset (&m->fs, 0, sizeof (m->fs));
11208
11209   /* Initialize CFA state for before the prologue.  */
11210   m->fs.cfa_reg = stack_pointer_rtx;
11211   m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET;
11212
11213   /* Track SP offset to the CFA.  We continue tracking this after we've
11214      swapped the CFA register away from SP.  In the case of re-alignment
11215      this is fudged; we're interested to offsets within the local frame.  */
11216   m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
11217   m->fs.sp_valid = true;
11218
11219   ix86_compute_frame_layout (&frame);
11220
11221   if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
11222     {
11223       /* We should have already generated an error for any use of
11224          ms_hook on a nested function.  */
11225       gcc_checking_assert (!ix86_static_chain_on_stack);
11226
11227       /* Check if profiling is active and we shall use profiling before
11228          prologue variant. If so sorry.  */
11229       if (crtl->profile && flag_fentry != 0)
11230         sorry ("ms_hook_prologue attribute isn%'t compatible "
11231                "with -mfentry for 32-bit");
11232
11233       /* In ix86_asm_output_function_label we emitted:
11234          8b ff     movl.s %edi,%edi
11235          55        push   %ebp
11236          8b ec     movl.s %esp,%ebp
11237
11238          This matches the hookable function prologue in Win32 API
11239          functions in Microsoft Windows XP Service Pack 2 and newer.
11240          Wine uses this to enable Windows apps to hook the Win32 API
11241          functions provided by Wine.
11242
11243          What that means is that we've already set up the frame pointer.  */
11244
11245       if (frame_pointer_needed
11246           && !(crtl->drap_reg && crtl->stack_realign_needed))
11247         {
11248           rtx push, mov;
11249
11250           /* We've decided to use the frame pointer already set up.
11251              Describe this to the unwinder by pretending that both
11252              push and mov insns happen right here.
11253
11254              Putting the unwind info here at the end of the ms_hook
11255              is done so that we can make absolutely certain we get
11256              the required byte sequence at the start of the function,
11257              rather than relying on an assembler that can produce
11258              the exact encoding required.
11259
11260              However it does mean (in the unpatched case) that we have
11261              a 1 insn window where the asynchronous unwind info is
11262              incorrect.  However, if we placed the unwind info at
11263              its correct location we would have incorrect unwind info
11264              in the patched case.  Which is probably all moot since
11265              I don't expect Wine generates dwarf2 unwind info for the
11266              system libraries that use this feature.  */
11267
11268           insn = emit_insn (gen_blockage ());
11269
11270           push = gen_push (hard_frame_pointer_rtx);
11271           mov = gen_rtx_SET (VOIDmode, hard_frame_pointer_rtx,
11272                              stack_pointer_rtx);
11273           RTX_FRAME_RELATED_P (push) = 1;
11274           RTX_FRAME_RELATED_P (mov) = 1;
11275
11276           RTX_FRAME_RELATED_P (insn) = 1;
11277           add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11278                         gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov)));
11279
11280           /* Note that gen_push incremented m->fs.cfa_offset, even
11281              though we didn't emit the push insn here.  */
11282           m->fs.cfa_reg = hard_frame_pointer_rtx;
11283           m->fs.fp_offset = m->fs.cfa_offset;
11284           m->fs.fp_valid = true;
11285         }
11286       else
11287         {
11288           /* The frame pointer is not needed so pop %ebp again.
11289              This leaves us with a pristine state.  */
11290           emit_insn (gen_pop (hard_frame_pointer_rtx));
11291         }
11292     }
11293
11294   /* The first insn of a function that accepts its static chain on the
11295      stack is to push the register that would be filled in by a direct
11296      call.  This insn will be skipped by the trampoline.  */
11297   else if (ix86_static_chain_on_stack)
11298     {
11299       insn = emit_insn (gen_push (ix86_static_chain (cfun->decl, false)));
11300       emit_insn (gen_blockage ());
11301
11302       /* We don't want to interpret this push insn as a register save,
11303          only as a stack adjustment.  The real copy of the register as
11304          a save will be done later, if needed.  */
11305       t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
11306       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
11307       add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
11308       RTX_FRAME_RELATED_P (insn) = 1;
11309     }
11310
11311   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
11312      of DRAP is needed and stack realignment is really needed after reload */
11313   if (stack_realign_drap)
11314     {
11315       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
11316
11317       /* Only need to push parameter pointer reg if it is caller saved.  */
11318       if (!call_used_regs[REGNO (crtl->drap_reg)])
11319         {
11320           /* Push arg pointer reg */
11321           insn = emit_insn (gen_push (crtl->drap_reg));
11322           RTX_FRAME_RELATED_P (insn) = 1;
11323         }
11324
11325       /* Grab the argument pointer.  */
11326       t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
11327       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, t));
11328       RTX_FRAME_RELATED_P (insn) = 1;
11329       m->fs.cfa_reg = crtl->drap_reg;
11330       m->fs.cfa_offset = 0;
11331
11332       /* Align the stack.  */
11333       insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
11334                                         stack_pointer_rtx,
11335                                         GEN_INT (-align_bytes)));
11336       RTX_FRAME_RELATED_P (insn) = 1;
11337
11338       /* Replicate the return address on the stack so that return
11339          address can be reached via (argp - 1) slot.  This is needed
11340          to implement macro RETURN_ADDR_RTX and intrinsic function
11341          expand_builtin_return_addr etc.  */
11342       t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
11343       t = gen_frame_mem (word_mode, t);
11344       insn = emit_insn (gen_push (t));
11345       RTX_FRAME_RELATED_P (insn) = 1;
11346
11347       /* For the purposes of frame and register save area addressing,
11348          we've started over with a new frame.  */
11349       m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
11350       m->fs.realigned = true;
11351     }
11352
11353   int_registers_saved = (frame.nregs == 0);
11354   sse_registers_saved = (frame.nsseregs == 0);
11355
11356   if (frame_pointer_needed && !m->fs.fp_valid)
11357     {
11358       /* Note: AT&T enter does NOT have reversed args.  Enter is probably
11359          slower on all targets.  Also sdb doesn't like it.  */
11360       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
11361       RTX_FRAME_RELATED_P (insn) = 1;
11362
11363       /* Push registers now, before setting the frame pointer
11364          on SEH target.  */
11365       if (!int_registers_saved
11366           && TARGET_SEH
11367           && !frame.save_regs_using_mov)
11368         {
11369           ix86_emit_save_regs ();
11370           int_registers_saved = true;
11371           gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
11372         }
11373
11374       if (m->fs.sp_offset == frame.hard_frame_pointer_offset)
11375         {
11376           insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
11377           RTX_FRAME_RELATED_P (insn) = 1;
11378
11379           if (m->fs.cfa_reg == stack_pointer_rtx)
11380             m->fs.cfa_reg = hard_frame_pointer_rtx;
11381           m->fs.fp_offset = m->fs.sp_offset;
11382           m->fs.fp_valid = true;
11383         }
11384     }
11385
11386   if (!int_registers_saved)
11387     {
11388       /* If saving registers via PUSH, do so now.  */
11389       if (!frame.save_regs_using_mov)
11390         {
11391           ix86_emit_save_regs ();
11392           int_registers_saved = true;
11393           gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
11394         }
11395
11396       /* When using red zone we may start register saving before allocating
11397          the stack frame saving one cycle of the prologue.  However, avoid
11398          doing this if we have to probe the stack; at least on x86_64 the
11399          stack probe can turn into a call that clobbers a red zone location. */
11400       else if (ix86_using_red_zone ()
11401                && (! TARGET_STACK_PROBE
11402                    || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
11403         {
11404           ix86_emit_save_regs_using_mov (frame.reg_save_offset);
11405           int_registers_saved = true;
11406         }
11407     }
11408
11409   if (stack_realign_fp)
11410     {
11411       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
11412       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
11413
11414       /* The computation of the size of the re-aligned stack frame means
11415          that we must allocate the size of the register save area before
11416          performing the actual alignment.  Otherwise we cannot guarantee
11417          that there's enough storage above the realignment point.  */
11418       if (m->fs.sp_offset != frame.sse_reg_save_offset)
11419         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11420                                    GEN_INT (m->fs.sp_offset
11421                                             - frame.sse_reg_save_offset),
11422                                    -1, false);
11423
11424       /* Align the stack.  */
11425       insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
11426                                         stack_pointer_rtx,
11427                                         GEN_INT (-align_bytes)));
11428
11429       /* For the purposes of register save area addressing, the stack
11430          pointer is no longer valid.  As for the value of sp_offset,
11431          see ix86_compute_frame_layout, which we need to match in order
11432          to pass verification of stack_pointer_offset at the end.  */
11433       m->fs.sp_offset = (m->fs.sp_offset + align_bytes) & -align_bytes;
11434       m->fs.sp_valid = false;
11435     }
11436
11437   allocate = frame.stack_pointer_offset - m->fs.sp_offset;
11438
11439   if (flag_stack_usage_info)
11440     {
11441       /* We start to count from ARG_POINTER.  */
11442       HOST_WIDE_INT stack_size = frame.stack_pointer_offset;
11443
11444       /* If it was realigned, take into account the fake frame.  */
11445       if (stack_realign_drap)
11446         {
11447           if (ix86_static_chain_on_stack)
11448             stack_size += UNITS_PER_WORD;
11449
11450           if (!call_used_regs[REGNO (crtl->drap_reg)])
11451             stack_size += UNITS_PER_WORD;
11452
11453           /* This over-estimates by 1 minimal-stack-alignment-unit but
11454              mitigates that by counting in the new return address slot.  */
11455           current_function_dynamic_stack_size
11456             += crtl->stack_alignment_needed / BITS_PER_UNIT;
11457         }
11458
11459       current_function_static_stack_size = stack_size;
11460     }
11461
11462   /* On SEH target with very large frame size, allocate an area to save
11463      SSE registers (as the very large allocation won't be described).  */
11464   if (TARGET_SEH
11465       && frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE
11466       && !sse_registers_saved)
11467     {
11468       HOST_WIDE_INT sse_size =
11469         frame.sse_reg_save_offset - frame.reg_save_offset;
11470
11471       gcc_assert (int_registers_saved);
11472
11473       /* No need to do stack checking as the area will be immediately
11474          written.  */
11475       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11476                                  GEN_INT (-sse_size), -1,
11477                                  m->fs.cfa_reg == stack_pointer_rtx);
11478       allocate -= sse_size;
11479       ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
11480       sse_registers_saved = true;
11481     }
11482
11483   /* The stack has already been decremented by the instruction calling us
11484      so probe if the size is non-negative to preserve the protection area.  */
11485   if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
11486     {
11487       /* We expect the registers to be saved when probes are used.  */
11488       gcc_assert (int_registers_saved);
11489
11490       if (STACK_CHECK_MOVING_SP)
11491         {
11492           if (!(crtl->is_leaf && !cfun->calls_alloca
11493                 && allocate <= PROBE_INTERVAL))
11494             {
11495               ix86_adjust_stack_and_probe (allocate);
11496               allocate = 0;
11497             }
11498         }
11499       else
11500         {
11501           HOST_WIDE_INT size = allocate;
11502
11503           if (TARGET_64BIT && size >= (HOST_WIDE_INT) 0x80000000)
11504             size = 0x80000000 - STACK_CHECK_PROTECT - 1;
11505
11506           if (TARGET_STACK_PROBE)
11507             {
11508               if (crtl->is_leaf && !cfun->calls_alloca)
11509                 {
11510                   if (size > PROBE_INTERVAL)
11511                     ix86_emit_probe_stack_range (0, size);
11512                 }
11513               else
11514                 ix86_emit_probe_stack_range (0, size + STACK_CHECK_PROTECT);
11515             }
11516           else
11517             {
11518               if (crtl->is_leaf && !cfun->calls_alloca)
11519                 {
11520                   if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
11521                     ix86_emit_probe_stack_range (STACK_CHECK_PROTECT,
11522                                                  size - STACK_CHECK_PROTECT);
11523                 }
11524               else
11525                 ix86_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
11526             }
11527         }
11528     }
11529
11530   if (allocate == 0)
11531     ;
11532   else if (!ix86_target_stack_probe ()
11533            || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
11534     {
11535       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11536                                  GEN_INT (-allocate), -1,
11537                                  m->fs.cfa_reg == stack_pointer_rtx);
11538     }
11539   else
11540     {
11541       rtx eax = gen_rtx_REG (Pmode, AX_REG);
11542       rtx r10 = NULL;
11543       rtx (*adjust_stack_insn)(rtx, rtx, rtx);
11544       const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx);
11545       bool eax_live = ix86_eax_live_at_start_p ();
11546       bool r10_live = false;
11547
11548       if (TARGET_64BIT)
11549         r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0);
11550
11551       if (eax_live)
11552         {
11553           insn = emit_insn (gen_push (eax));
11554           allocate -= UNITS_PER_WORD;
11555           /* Note that SEH directives need to continue tracking the stack
11556              pointer even after the frame pointer has been set up.  */
11557           if (sp_is_cfa_reg || TARGET_SEH)
11558             {
11559               if (sp_is_cfa_reg)
11560                 m->fs.cfa_offset += UNITS_PER_WORD;
11561               RTX_FRAME_RELATED_P (insn) = 1;
11562               add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11563                             gen_rtx_SET (VOIDmode, stack_pointer_rtx,
11564                                          plus_constant (Pmode, stack_pointer_rtx,
11565                                                         -UNITS_PER_WORD)));
11566             }
11567         }
11568
11569       if (r10_live)
11570         {
11571           r10 = gen_rtx_REG (Pmode, R10_REG);
11572           insn = emit_insn (gen_push (r10));
11573           allocate -= UNITS_PER_WORD;
11574           if (sp_is_cfa_reg || TARGET_SEH)
11575             {
11576               if (sp_is_cfa_reg)
11577                 m->fs.cfa_offset += UNITS_PER_WORD;
11578               RTX_FRAME_RELATED_P (insn) = 1;
11579               add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11580                             gen_rtx_SET (VOIDmode, stack_pointer_rtx,
11581                                          plus_constant (Pmode, stack_pointer_rtx,
11582                                                         -UNITS_PER_WORD)));
11583             }
11584         }
11585
11586       emit_move_insn (eax, GEN_INT (allocate));
11587       emit_insn (ix86_gen_allocate_stack_worker (eax, eax));
11588
11589       /* Use the fact that AX still contains ALLOCATE.  */
11590       adjust_stack_insn = (Pmode == DImode
11591                            ? gen_pro_epilogue_adjust_stack_di_sub
11592                            : gen_pro_epilogue_adjust_stack_si_sub);
11593
11594       insn = emit_insn (adjust_stack_insn (stack_pointer_rtx,
11595                                            stack_pointer_rtx, eax));
11596
11597       if (sp_is_cfa_reg || TARGET_SEH)
11598         {
11599           if (sp_is_cfa_reg)
11600             m->fs.cfa_offset += allocate;
11601           RTX_FRAME_RELATED_P (insn) = 1;
11602           add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11603                         gen_rtx_SET (VOIDmode, stack_pointer_rtx,
11604                                      plus_constant (Pmode, stack_pointer_rtx,
11605                                                     -allocate)));
11606         }
11607       m->fs.sp_offset += allocate;
11608
11609       /* Use stack_pointer_rtx for relative addressing so that code
11610          works for realigned stack, too.  */
11611       if (r10_live && eax_live)
11612         {
11613           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
11614           emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
11615                           gen_frame_mem (word_mode, t));
11616           t = plus_constant (Pmode, t, UNITS_PER_WORD);
11617           emit_move_insn (gen_rtx_REG (word_mode, AX_REG),
11618                           gen_frame_mem (word_mode, t));
11619         }
11620       else if (eax_live || r10_live)
11621         {
11622           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
11623           emit_move_insn (gen_rtx_REG (word_mode,
11624                                        (eax_live ? AX_REG : R10_REG)),
11625                           gen_frame_mem (word_mode, t));
11626         }
11627     }
11628   gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset);
11629
11630   /* If we havn't already set up the frame pointer, do so now.  */
11631   if (frame_pointer_needed && !m->fs.fp_valid)
11632     {
11633       insn = ix86_gen_add3 (hard_frame_pointer_rtx, stack_pointer_rtx,
11634                             GEN_INT (frame.stack_pointer_offset
11635                                      - frame.hard_frame_pointer_offset));
11636       insn = emit_insn (insn);
11637       RTX_FRAME_RELATED_P (insn) = 1;
11638       add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL);
11639
11640       if (m->fs.cfa_reg == stack_pointer_rtx)
11641         m->fs.cfa_reg = hard_frame_pointer_rtx;
11642       m->fs.fp_offset = frame.hard_frame_pointer_offset;
11643       m->fs.fp_valid = true;
11644     }
11645
11646   if (!int_registers_saved)
11647     ix86_emit_save_regs_using_mov (frame.reg_save_offset);
11648   if (!sse_registers_saved)
11649     ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
11650
11651   /* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT
11652      in PROLOGUE.  */
11653   if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry)
11654     {
11655       rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM);
11656       insn = emit_insn (gen_set_got (pic));
11657       RTX_FRAME_RELATED_P (insn) = 1;
11658       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
11659       emit_insn (gen_prologue_use (pic));
11660       /* Deleting already emmitted SET_GOT if exist and allocated to
11661          REAL_PIC_OFFSET_TABLE_REGNUM.  */
11662       ix86_elim_entry_set_got (pic);
11663     }
11664
11665   if (crtl->drap_reg && !crtl->stack_realign_needed)
11666     {
11667       /* vDRAP is setup but after reload it turns out stack realign
11668          isn't necessary, here we will emit prologue to setup DRAP
11669          without stack realign adjustment */
11670       t = choose_baseaddr (0);
11671       emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, t));
11672     }
11673
11674   /* Prevent instructions from being scheduled into register save push
11675      sequence when access to the redzone area is done through frame pointer.
11676      The offset between the frame pointer and the stack pointer is calculated
11677      relative to the value of the stack pointer at the end of the function
11678      prologue, and moving instructions that access redzone area via frame
11679      pointer inside push sequence violates this assumption.  */
11680   if (frame_pointer_needed && frame.red_zone_size)
11681     emit_insn (gen_memory_blockage ());
11682
11683   /* Emit cld instruction if stringops are used in the function.  */
11684   if (TARGET_CLD && ix86_current_function_needs_cld)
11685     emit_insn (gen_cld ());
11686
11687   /* SEH requires that the prologue end within 256 bytes of the start of
11688      the function.  Prevent instruction schedules that would extend that.
11689      Further, prevent alloca modifications to the stack pointer from being
11690      combined with prologue modifications.  */
11691   if (TARGET_SEH)
11692     emit_insn (gen_prologue_use (stack_pointer_rtx));
11693 }
11694
11695 /* Emit code to restore REG using a POP insn.  */
11696
11697 static void
11698 ix86_emit_restore_reg_using_pop (rtx reg)
11699 {
11700   struct machine_function *m = cfun->machine;
11701   rtx insn = emit_insn (gen_pop (reg));
11702
11703   ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset);
11704   m->fs.sp_offset -= UNITS_PER_WORD;
11705
11706   if (m->fs.cfa_reg == crtl->drap_reg
11707       && REGNO (reg) == REGNO (crtl->drap_reg))
11708     {
11709       /* Previously we'd represented the CFA as an expression
11710          like *(%ebp - 8).  We've just popped that value from
11711          the stack, which means we need to reset the CFA to
11712          the drap register.  This will remain until we restore
11713          the stack pointer.  */
11714       add_reg_note (insn, REG_CFA_DEF_CFA, reg);
11715       RTX_FRAME_RELATED_P (insn) = 1;
11716
11717       /* This means that the DRAP register is valid for addressing too.  */
11718       m->fs.drap_valid = true;
11719       return;
11720     }
11721
11722   if (m->fs.cfa_reg == stack_pointer_rtx)
11723     {
11724       rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
11725       x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
11726       add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
11727       RTX_FRAME_RELATED_P (insn) = 1;
11728
11729       m->fs.cfa_offset -= UNITS_PER_WORD;
11730     }
11731
11732   /* When the frame pointer is the CFA, and we pop it, we are
11733      swapping back to the stack pointer as the CFA.  This happens
11734      for stack frames that don't allocate other data, so we assume
11735      the stack pointer is now pointing at the return address, i.e.
11736      the function entry state, which makes the offset be 1 word.  */
11737   if (reg == hard_frame_pointer_rtx)
11738     {
11739       m->fs.fp_valid = false;
11740       if (m->fs.cfa_reg == hard_frame_pointer_rtx)
11741         {
11742           m->fs.cfa_reg = stack_pointer_rtx;
11743           m->fs.cfa_offset -= UNITS_PER_WORD;
11744
11745           add_reg_note (insn, REG_CFA_DEF_CFA,
11746                         gen_rtx_PLUS (Pmode, stack_pointer_rtx,
11747                                       GEN_INT (m->fs.cfa_offset)));
11748           RTX_FRAME_RELATED_P (insn) = 1;
11749         }
11750     }
11751 }
11752
11753 /* Emit code to restore saved registers using POP insns.  */
11754
11755 static void
11756 ix86_emit_restore_regs_using_pop (void)
11757 {
11758   unsigned int regno;
11759
11760   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11761     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
11762       ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno));
11763 }
11764
11765 /* Emit code and notes for the LEAVE instruction.  */
11766
11767 static void
11768 ix86_emit_leave (void)
11769 {
11770   struct machine_function *m = cfun->machine;
11771   rtx insn = emit_insn (ix86_gen_leave ());
11772
11773   ix86_add_queued_cfa_restore_notes (insn);
11774
11775   gcc_assert (m->fs.fp_valid);
11776   m->fs.sp_valid = true;
11777   m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD;
11778   m->fs.fp_valid = false;
11779
11780   if (m->fs.cfa_reg == hard_frame_pointer_rtx)
11781     {
11782       m->fs.cfa_reg = stack_pointer_rtx;
11783       m->fs.cfa_offset = m->fs.sp_offset;
11784
11785       add_reg_note (insn, REG_CFA_DEF_CFA,
11786                     plus_constant (Pmode, stack_pointer_rtx,
11787                                    m->fs.sp_offset));
11788       RTX_FRAME_RELATED_P (insn) = 1;
11789     }
11790   ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx,
11791                              m->fs.fp_offset);
11792 }
11793
11794 /* Emit code to restore saved registers using MOV insns.
11795    First register is restored from CFA - CFA_OFFSET.  */
11796 static void
11797 ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
11798                                   bool maybe_eh_return)
11799 {
11800   struct machine_function *m = cfun->machine;
11801   unsigned int regno;
11802
11803   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11804     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
11805       {
11806         rtx reg = gen_rtx_REG (word_mode, regno);
11807         rtx insn, mem;
11808
11809         mem = choose_baseaddr (cfa_offset);
11810         mem = gen_frame_mem (word_mode, mem);
11811         insn = emit_move_insn (reg, mem);
11812
11813         if (m->fs.cfa_reg == crtl->drap_reg && regno == REGNO (crtl->drap_reg))
11814           {
11815             /* Previously we'd represented the CFA as an expression
11816                like *(%ebp - 8).  We've just popped that value from
11817                the stack, which means we need to reset the CFA to
11818                the drap register.  This will remain until we restore
11819                the stack pointer.  */
11820             add_reg_note (insn, REG_CFA_DEF_CFA, reg);
11821             RTX_FRAME_RELATED_P (insn) = 1;
11822
11823             /* This means that the DRAP register is valid for addressing.  */
11824             m->fs.drap_valid = true;
11825           }
11826         else
11827           ix86_add_cfa_restore_note (NULL_RTX, reg, cfa_offset);
11828
11829         cfa_offset -= UNITS_PER_WORD;
11830       }
11831 }
11832
11833 /* Emit code to restore saved registers using MOV insns.
11834    First register is restored from CFA - CFA_OFFSET.  */
11835 static void
11836 ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
11837                                       bool maybe_eh_return)
11838 {
11839   unsigned int regno;
11840
11841   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11842     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
11843       {
11844         rtx reg = gen_rtx_REG (V4SFmode, regno);
11845         rtx mem;
11846
11847         mem = choose_baseaddr (cfa_offset);
11848         mem = gen_rtx_MEM (V4SFmode, mem);
11849         set_mem_align (mem, 128);
11850         emit_move_insn (reg, mem);
11851
11852         ix86_add_cfa_restore_note (NULL_RTX, reg, cfa_offset);
11853
11854         cfa_offset -= 16;
11855       }
11856 }
11857
11858 /* Restore function stack, frame, and registers.  */
11859
11860 void
11861 ix86_expand_epilogue (int style)
11862 {
11863   struct machine_function *m = cfun->machine;
11864   struct machine_frame_state frame_state_save = m->fs;
11865   struct ix86_frame frame;
11866   bool restore_regs_via_mov;
11867   bool using_drap;
11868
11869   ix86_finalize_stack_realign_flags ();
11870   ix86_compute_frame_layout (&frame);
11871
11872   m->fs.sp_valid = (!frame_pointer_needed
11873                     || (crtl->sp_is_unchanging
11874                         && !stack_realign_fp));
11875   gcc_assert (!m->fs.sp_valid
11876               || m->fs.sp_offset == frame.stack_pointer_offset);
11877
11878   /* The FP must be valid if the frame pointer is present.  */
11879   gcc_assert (frame_pointer_needed == m->fs.fp_valid);
11880   gcc_assert (!m->fs.fp_valid
11881               || m->fs.fp_offset == frame.hard_frame_pointer_offset);
11882
11883   /* We must have *some* valid pointer to the stack frame.  */
11884   gcc_assert (m->fs.sp_valid || m->fs.fp_valid);
11885
11886   /* The DRAP is never valid at this point.  */
11887   gcc_assert (!m->fs.drap_valid);
11888
11889   /* See the comment about red zone and frame
11890      pointer usage in ix86_expand_prologue.  */
11891   if (frame_pointer_needed && frame.red_zone_size)
11892     emit_insn (gen_memory_blockage ());
11893
11894   using_drap = crtl->drap_reg && crtl->stack_realign_needed;
11895   gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg);
11896
11897   /* Determine the CFA offset of the end of the red-zone.  */
11898   m->fs.red_zone_offset = 0;
11899   if (ix86_using_red_zone () && crtl->args.pops_args < 65536)
11900     {
11901       /* The red-zone begins below the return address.  */
11902       m->fs.red_zone_offset = RED_ZONE_SIZE + UNITS_PER_WORD;
11903
11904       /* When the register save area is in the aligned portion of
11905          the stack, determine the maximum runtime displacement that
11906          matches up with the aligned frame.  */
11907       if (stack_realign_drap)
11908         m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT
11909                                   + UNITS_PER_WORD);
11910     }
11911
11912   /* Special care must be taken for the normal return case of a function
11913      using eh_return: the eax and edx registers are marked as saved, but
11914      not restored along this path.  Adjust the save location to match.  */
11915   if (crtl->calls_eh_return && style != 2)
11916     frame.reg_save_offset -= 2 * UNITS_PER_WORD;
11917
11918   /* EH_RETURN requires the use of moves to function properly.  */
11919   if (crtl->calls_eh_return)
11920     restore_regs_via_mov = true;
11921   /* SEH requires the use of pops to identify the epilogue.  */
11922   else if (TARGET_SEH)
11923     restore_regs_via_mov = false;
11924   /* If we're only restoring one register and sp is not valid then
11925      using a move instruction to restore the register since it's
11926      less work than reloading sp and popping the register.  */
11927   else if (!m->fs.sp_valid && frame.nregs <= 1)
11928     restore_regs_via_mov = true;
11929   else if (TARGET_EPILOGUE_USING_MOVE
11930            && cfun->machine->use_fast_prologue_epilogue
11931            && (frame.nregs > 1
11932                || m->fs.sp_offset != frame.reg_save_offset))
11933     restore_regs_via_mov = true;
11934   else if (frame_pointer_needed
11935            && !frame.nregs
11936            && m->fs.sp_offset != frame.reg_save_offset)
11937     restore_regs_via_mov = true;
11938   else if (frame_pointer_needed
11939            && TARGET_USE_LEAVE
11940            && cfun->machine->use_fast_prologue_epilogue
11941            && frame.nregs == 1)
11942     restore_regs_via_mov = true;
11943   else
11944     restore_regs_via_mov = false;
11945
11946   if (restore_regs_via_mov || frame.nsseregs)
11947     {
11948       /* Ensure that the entire register save area is addressable via
11949          the stack pointer, if we will restore via sp.  */
11950       if (TARGET_64BIT
11951           && m->fs.sp_offset > 0x7fffffff
11952           && !(m->fs.fp_valid || m->fs.drap_valid)
11953           && (frame.nsseregs + frame.nregs) != 0)
11954         {
11955           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11956                                      GEN_INT (m->fs.sp_offset
11957                                               - frame.sse_reg_save_offset),
11958                                      style,
11959                                      m->fs.cfa_reg == stack_pointer_rtx);
11960         }
11961     }
11962
11963   /* If there are any SSE registers to restore, then we have to do it
11964      via moves, since there's obviously no pop for SSE regs.  */
11965   if (frame.nsseregs)
11966     ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset,
11967                                           style == 2);
11968
11969   if (restore_regs_via_mov)
11970     {
11971       rtx t;
11972
11973       if (frame.nregs)
11974         ix86_emit_restore_regs_using_mov (frame.reg_save_offset, style == 2);
11975
11976       /* eh_return epilogues need %ecx added to the stack pointer.  */
11977       if (style == 2)
11978         {
11979           rtx insn, sa = EH_RETURN_STACKADJ_RTX;
11980
11981           /* Stack align doesn't work with eh_return.  */
11982           gcc_assert (!stack_realign_drap);
11983           /* Neither does regparm nested functions.  */
11984           gcc_assert (!ix86_static_chain_on_stack);
11985
11986           if (frame_pointer_needed)
11987             {
11988               t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
11989               t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
11990               emit_insn (gen_rtx_SET (VOIDmode, sa, t));
11991
11992               t = gen_frame_mem (Pmode, hard_frame_pointer_rtx);
11993               insn = emit_move_insn (hard_frame_pointer_rtx, t);
11994
11995               /* Note that we use SA as a temporary CFA, as the return
11996                  address is at the proper place relative to it.  We
11997                  pretend this happens at the FP restore insn because
11998                  prior to this insn the FP would be stored at the wrong
11999                  offset relative to SA, and after this insn we have no
12000                  other reasonable register to use for the CFA.  We don't
12001                  bother resetting the CFA to the SP for the duration of
12002                  the return insn.  */
12003               add_reg_note (insn, REG_CFA_DEF_CFA,
12004                             plus_constant (Pmode, sa, UNITS_PER_WORD));
12005               ix86_add_queued_cfa_restore_notes (insn);
12006               add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx);
12007               RTX_FRAME_RELATED_P (insn) = 1;
12008
12009               m->fs.cfa_reg = sa;
12010               m->fs.cfa_offset = UNITS_PER_WORD;
12011               m->fs.fp_valid = false;
12012
12013               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
12014                                          const0_rtx, style, false);
12015             }
12016           else
12017             {
12018               t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
12019               t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD);
12020               insn = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, t));
12021               ix86_add_queued_cfa_restore_notes (insn);
12022
12023               gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
12024               if (m->fs.cfa_offset != UNITS_PER_WORD)
12025                 {
12026                   m->fs.cfa_offset = UNITS_PER_WORD;
12027                   add_reg_note (insn, REG_CFA_DEF_CFA,
12028                                 plus_constant (Pmode, stack_pointer_rtx,
12029                                                UNITS_PER_WORD));
12030                   RTX_FRAME_RELATED_P (insn) = 1;
12031                 }
12032             }
12033           m->fs.sp_offset = UNITS_PER_WORD;
12034           m->fs.sp_valid = true;
12035         }
12036     }
12037   else
12038     {
12039       /* SEH requires that the function end with (1) a stack adjustment
12040          if necessary, (2) a sequence of pops, and (3) a return or
12041          jump instruction.  Prevent insns from the function body from
12042          being scheduled into this sequence.  */
12043       if (TARGET_SEH)
12044         {
12045           /* Prevent a catch region from being adjacent to the standard
12046              epilogue sequence.  Unfortuantely crtl->uses_eh_lsda nor
12047              several other flags that would be interesting to test are
12048              not yet set up.  */
12049           if (flag_non_call_exceptions)
12050             emit_insn (gen_nops (const1_rtx));
12051           else
12052             emit_insn (gen_blockage ());
12053         }
12054
12055       /* First step is to deallocate the stack frame so that we can
12056          pop the registers.  Also do it on SEH target for very large
12057          frame as the emitted instructions aren't allowed by the ABI in
12058          epilogues.  */
12059       if (!m->fs.sp_valid
12060           || (TARGET_SEH
12061               && (m->fs.sp_offset - frame.reg_save_offset
12062                   >= SEH_MAX_FRAME_SIZE)))
12063         {
12064           pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx,
12065                                      GEN_INT (m->fs.fp_offset
12066                                               - frame.reg_save_offset),
12067                                      style, false);
12068         }
12069       else if (m->fs.sp_offset != frame.reg_save_offset)
12070         {
12071           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12072                                      GEN_INT (m->fs.sp_offset
12073                                               - frame.reg_save_offset),
12074                                      style,
12075                                      m->fs.cfa_reg == stack_pointer_rtx);
12076         }
12077
12078       ix86_emit_restore_regs_using_pop ();
12079     }
12080
12081   /* If we used a stack pointer and haven't already got rid of it,
12082      then do so now.  */
12083   if (m->fs.fp_valid)
12084     {
12085       /* If the stack pointer is valid and pointing at the frame
12086          pointer store address, then we only need a pop.  */
12087       if (m->fs.sp_valid && m->fs.sp_offset == frame.hfp_save_offset)
12088         ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
12089       /* Leave results in shorter dependency chains on CPUs that are
12090          able to grok it fast.  */
12091       else if (TARGET_USE_LEAVE
12092                || optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun))
12093                || !cfun->machine->use_fast_prologue_epilogue)
12094         ix86_emit_leave ();
12095       else
12096         {
12097           pro_epilogue_adjust_stack (stack_pointer_rtx,
12098                                      hard_frame_pointer_rtx,
12099                                      const0_rtx, style, !using_drap);
12100           ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
12101         }
12102     }
12103
12104   if (using_drap)
12105     {
12106       int param_ptr_offset = UNITS_PER_WORD;
12107       rtx insn;
12108
12109       gcc_assert (stack_realign_drap);
12110
12111       if (ix86_static_chain_on_stack)
12112         param_ptr_offset += UNITS_PER_WORD;
12113       if (!call_used_regs[REGNO (crtl->drap_reg)])
12114         param_ptr_offset += UNITS_PER_WORD;
12115
12116       insn = emit_insn (gen_rtx_SET
12117                         (VOIDmode, stack_pointer_rtx,
12118                          gen_rtx_PLUS (Pmode,
12119                                        crtl->drap_reg,
12120                                        GEN_INT (-param_ptr_offset))));
12121       m->fs.cfa_reg = stack_pointer_rtx;
12122       m->fs.cfa_offset = param_ptr_offset;
12123       m->fs.sp_offset = param_ptr_offset;
12124       m->fs.realigned = false;
12125
12126       add_reg_note (insn, REG_CFA_DEF_CFA,
12127                     gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12128                                   GEN_INT (param_ptr_offset)));
12129       RTX_FRAME_RELATED_P (insn) = 1;
12130
12131       if (!call_used_regs[REGNO (crtl->drap_reg)])
12132         ix86_emit_restore_reg_using_pop (crtl->drap_reg);
12133     }
12134
12135   /* At this point the stack pointer must be valid, and we must have
12136      restored all of the registers.  We may not have deallocated the
12137      entire stack frame.  We've delayed this until now because it may
12138      be possible to merge the local stack deallocation with the
12139      deallocation forced by ix86_static_chain_on_stack.   */
12140   gcc_assert (m->fs.sp_valid);
12141   gcc_assert (!m->fs.fp_valid);
12142   gcc_assert (!m->fs.realigned);
12143   if (m->fs.sp_offset != UNITS_PER_WORD)
12144     {
12145       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12146                                  GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
12147                                  style, true);
12148     }
12149   else
12150     ix86_add_queued_cfa_restore_notes (get_last_insn ());
12151
12152   /* Sibcall epilogues don't want a return instruction.  */
12153   if (style == 0)
12154     {
12155       m->fs = frame_state_save;
12156       return;
12157     }
12158
12159   if (crtl->args.pops_args && crtl->args.size)
12160     {
12161       rtx popc = GEN_INT (crtl->args.pops_args);
12162
12163       /* i386 can only pop 64K bytes.  If asked to pop more, pop return
12164          address, do explicit add, and jump indirectly to the caller.  */
12165
12166       if (crtl->args.pops_args >= 65536)
12167         {
12168           rtx ecx = gen_rtx_REG (SImode, CX_REG);
12169           rtx insn;
12170
12171           /* There is no "pascal" calling convention in any 64bit ABI.  */
12172           gcc_assert (!TARGET_64BIT);
12173
12174           insn = emit_insn (gen_pop (ecx));
12175           m->fs.cfa_offset -= UNITS_PER_WORD;
12176           m->fs.sp_offset -= UNITS_PER_WORD;
12177
12178           rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
12179           x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
12180           add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
12181           add_reg_note (insn, REG_CFA_REGISTER,
12182                         gen_rtx_SET (VOIDmode, ecx, pc_rtx));
12183           RTX_FRAME_RELATED_P (insn) = 1;
12184
12185           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12186                                      popc, -1, true);
12187           emit_jump_insn (gen_simple_return_indirect_internal (ecx));
12188         }
12189       else
12190         emit_jump_insn (gen_simple_return_pop_internal (popc));
12191     }
12192   else
12193     emit_jump_insn (gen_simple_return_internal ());
12194
12195   /* Restore the state back to the state from the prologue,
12196      so that it's correct for the next epilogue.  */
12197   m->fs = frame_state_save;
12198 }
12199
12200 /* Reset from the function's potential modifications.  */
12201
12202 static void
12203 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED, HOST_WIDE_INT)
12204 {
12205   if (pic_offset_table_rtx
12206       && !ix86_use_pseudo_pic_reg ())
12207     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
12208 #if TARGET_MACHO
12209   /* Mach-O doesn't support labels at the end of objects, so if
12210      it looks like we might want one, insert a NOP.  */
12211   {
12212     rtx_insn *insn = get_last_insn ();
12213     rtx_insn *deleted_debug_label = NULL;
12214     while (insn
12215            && NOTE_P (insn)
12216            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
12217       {
12218         /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
12219            notes only, instead set their CODE_LABEL_NUMBER to -1,
12220            otherwise there would be code generation differences
12221            in between -g and -g0.  */
12222         if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
12223           deleted_debug_label = insn;
12224         insn = PREV_INSN (insn);
12225       }
12226     if (insn
12227         && (LABEL_P (insn)
12228             || (NOTE_P (insn)
12229                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
12230       fputs ("\tnop\n", file);
12231     else if (deleted_debug_label)
12232       for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
12233         if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
12234           CODE_LABEL_NUMBER (insn) = -1;
12235   }
12236 #endif
12237
12238 }
12239
12240 /* Return a scratch register to use in the split stack prologue.  The
12241    split stack prologue is used for -fsplit-stack.  It is the first
12242    instructions in the function, even before the regular prologue.
12243    The scratch register can be any caller-saved register which is not
12244    used for parameters or for the static chain.  */
12245
12246 static unsigned int
12247 split_stack_prologue_scratch_regno (void)
12248 {
12249   if (TARGET_64BIT)
12250     return R11_REG;
12251   else
12252     {
12253       bool is_fastcall, is_thiscall;
12254       int regparm;
12255
12256       is_fastcall = (lookup_attribute ("fastcall",
12257                                        TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
12258                      != NULL);
12259       is_thiscall = (lookup_attribute ("thiscall",
12260                                        TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
12261                      != NULL);
12262       regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
12263
12264       if (is_fastcall)
12265         {
12266           if (DECL_STATIC_CHAIN (cfun->decl))
12267             {
12268               sorry ("-fsplit-stack does not support fastcall with "
12269                      "nested function");
12270               return INVALID_REGNUM;
12271             }
12272           return AX_REG;
12273         }
12274       else if (is_thiscall)
12275         {
12276           if (!DECL_STATIC_CHAIN (cfun->decl))
12277             return DX_REG;
12278           return AX_REG;
12279         }
12280       else if (regparm < 3)
12281         {
12282           if (!DECL_STATIC_CHAIN (cfun->decl))
12283             return CX_REG;
12284           else
12285             {
12286               if (regparm >= 2)
12287                 {
12288                   sorry ("-fsplit-stack does not support 2 register "
12289                          "parameters for a nested function");
12290                   return INVALID_REGNUM;
12291                 }
12292               return DX_REG;
12293             }
12294         }
12295       else
12296         {
12297           /* FIXME: We could make this work by pushing a register
12298              around the addition and comparison.  */
12299           sorry ("-fsplit-stack does not support 3 register parameters");
12300           return INVALID_REGNUM;
12301         }
12302     }
12303 }
12304
12305 /* A SYMBOL_REF for the function which allocates new stackspace for
12306    -fsplit-stack.  */
12307
12308 static GTY(()) rtx split_stack_fn;
12309
12310 /* A SYMBOL_REF for the more stack function when using the large
12311    model.  */
12312
12313 static GTY(()) rtx split_stack_fn_large;
12314
12315 /* Handle -fsplit-stack.  These are the first instructions in the
12316    function, even before the regular prologue.  */
12317
12318 void
12319 ix86_expand_split_stack_prologue (void)
12320 {
12321   struct ix86_frame frame;
12322   HOST_WIDE_INT allocate;
12323   unsigned HOST_WIDE_INT args_size;
12324   rtx_code_label *label;
12325   rtx limit, current, jump_insn, allocate_rtx, call_insn, call_fusage;
12326   rtx scratch_reg = NULL_RTX;
12327   rtx_code_label *varargs_label = NULL;
12328   rtx fn;
12329
12330   gcc_assert (flag_split_stack && reload_completed);
12331
12332   ix86_finalize_stack_realign_flags ();
12333   ix86_compute_frame_layout (&frame);
12334   allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
12335
12336   /* This is the label we will branch to if we have enough stack
12337      space.  We expect the basic block reordering pass to reverse this
12338      branch if optimizing, so that we branch in the unlikely case.  */
12339   label = gen_label_rtx ();
12340
12341   /* We need to compare the stack pointer minus the frame size with
12342      the stack boundary in the TCB.  The stack boundary always gives
12343      us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we
12344      can compare directly.  Otherwise we need to do an addition.  */
12345
12346   limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12347                           UNSPEC_STACK_CHECK);
12348   limit = gen_rtx_CONST (Pmode, limit);
12349   limit = gen_rtx_MEM (Pmode, limit);
12350   if (allocate < SPLIT_STACK_AVAILABLE)
12351     current = stack_pointer_rtx;
12352   else
12353     {
12354       unsigned int scratch_regno;
12355       rtx offset;
12356
12357       /* We need a scratch register to hold the stack pointer minus
12358          the required frame size.  Since this is the very start of the
12359          function, the scratch register can be any caller-saved
12360          register which is not used for parameters.  */
12361       offset = GEN_INT (- allocate);
12362       scratch_regno = split_stack_prologue_scratch_regno ();
12363       if (scratch_regno == INVALID_REGNUM)
12364         return;
12365       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
12366       if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode))
12367         {
12368           /* We don't use ix86_gen_add3 in this case because it will
12369              want to split to lea, but when not optimizing the insn
12370              will not be split after this point.  */
12371           emit_insn (gen_rtx_SET (VOIDmode, scratch_reg,
12372                                   gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12373                                                 offset)));
12374         }
12375       else
12376         {
12377           emit_move_insn (scratch_reg, offset);
12378           emit_insn (ix86_gen_add3 (scratch_reg, scratch_reg,
12379                                     stack_pointer_rtx));
12380         }
12381       current = scratch_reg;
12382     }
12383
12384   ix86_expand_branch (GEU, current, limit, label);
12385   jump_insn = get_last_insn ();
12386   JUMP_LABEL (jump_insn) = label;
12387
12388   /* Mark the jump as very likely to be taken.  */
12389   add_int_reg_note (jump_insn, REG_BR_PROB,
12390                     REG_BR_PROB_BASE - REG_BR_PROB_BASE / 100);
12391
12392   if (split_stack_fn == NULL_RTX)
12393     {
12394       split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack");
12395       SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL;
12396     }
12397   fn = split_stack_fn;
12398
12399   /* Get more stack space.  We pass in the desired stack space and the
12400      size of the arguments to copy to the new stack.  In 32-bit mode
12401      we push the parameters; __morestack will return on a new stack
12402      anyhow.  In 64-bit mode we pass the parameters in r10 and
12403      r11.  */
12404   allocate_rtx = GEN_INT (allocate);
12405   args_size = crtl->args.size >= 0 ? crtl->args.size : 0;
12406   call_fusage = NULL_RTX;
12407   if (TARGET_64BIT)
12408     {
12409       rtx reg10, reg11;
12410
12411       reg10 = gen_rtx_REG (Pmode, R10_REG);
12412       reg11 = gen_rtx_REG (Pmode, R11_REG);
12413
12414       /* If this function uses a static chain, it will be in %r10.
12415          Preserve it across the call to __morestack.  */
12416       if (DECL_STATIC_CHAIN (cfun->decl))
12417         {
12418           rtx rax;
12419
12420           rax = gen_rtx_REG (word_mode, AX_REG);
12421           emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG));
12422           use_reg (&call_fusage, rax);
12423         }
12424
12425       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
12426           && !TARGET_PECOFF)
12427         {
12428           HOST_WIDE_INT argval;
12429
12430           gcc_assert (Pmode == DImode);
12431           /* When using the large model we need to load the address
12432              into a register, and we've run out of registers.  So we
12433              switch to a different calling convention, and we call a
12434              different function: __morestack_large.  We pass the
12435              argument size in the upper 32 bits of r10 and pass the
12436              frame size in the lower 32 bits.  */
12437           gcc_assert ((allocate & (HOST_WIDE_INT) 0xffffffff) == allocate);
12438           gcc_assert ((args_size & 0xffffffff) == args_size);
12439
12440           if (split_stack_fn_large == NULL_RTX)
12441             {
12442               split_stack_fn_large =
12443                 gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model");
12444               SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL;
12445             }
12446           if (ix86_cmodel == CM_LARGE_PIC)
12447             {
12448               rtx_code_label *label;
12449               rtx x;
12450
12451               label = gen_label_rtx ();
12452               emit_label (label);
12453               LABEL_PRESERVE_P (label) = 1;
12454               emit_insn (gen_set_rip_rex64 (reg10, label));
12455               emit_insn (gen_set_got_offset_rex64 (reg11, label));
12456               emit_insn (ix86_gen_add3 (reg10, reg10, reg11));
12457               x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn_large),
12458                                   UNSPEC_GOT);
12459               x = gen_rtx_CONST (Pmode, x);
12460               emit_move_insn (reg11, x);
12461               x = gen_rtx_PLUS (Pmode, reg10, reg11);
12462               x = gen_const_mem (Pmode, x);
12463               emit_move_insn (reg11, x);
12464             }
12465           else
12466             emit_move_insn (reg11, split_stack_fn_large);
12467
12468           fn = reg11;
12469
12470           argval = ((args_size << 16) << 16) + allocate;
12471           emit_move_insn (reg10, GEN_INT (argval));
12472         }
12473       else
12474         {
12475           emit_move_insn (reg10, allocate_rtx);
12476           emit_move_insn (reg11, GEN_INT (args_size));
12477           use_reg (&call_fusage, reg11);
12478         }
12479
12480       use_reg (&call_fusage, reg10);
12481     }
12482   else
12483     {
12484       emit_insn (gen_push (GEN_INT (args_size)));
12485       emit_insn (gen_push (allocate_rtx));
12486     }
12487   call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn),
12488                                 GEN_INT (UNITS_PER_WORD), constm1_rtx,
12489                                 NULL_RTX, false);
12490   add_function_usage_to (call_insn, call_fusage);
12491
12492   /* In order to make call/return prediction work right, we now need
12493      to execute a return instruction.  See
12494      libgcc/config/i386/morestack.S for the details on how this works.
12495
12496      For flow purposes gcc must not see this as a return
12497      instruction--we need control flow to continue at the subsequent
12498      label.  Therefore, we use an unspec.  */
12499   gcc_assert (crtl->args.pops_args < 65536);
12500   emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args)));
12501
12502   /* If we are in 64-bit mode and this function uses a static chain,
12503      we saved %r10 in %rax before calling _morestack.  */
12504   if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl))
12505     emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
12506                     gen_rtx_REG (word_mode, AX_REG));
12507
12508   /* If this function calls va_start, we need to store a pointer to
12509      the arguments on the old stack, because they may not have been
12510      all copied to the new stack.  At this point the old stack can be
12511      found at the frame pointer value used by __morestack, because
12512      __morestack has set that up before calling back to us.  Here we
12513      store that pointer in a scratch register, and in
12514      ix86_expand_prologue we store the scratch register in a stack
12515      slot.  */
12516   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12517     {
12518       unsigned int scratch_regno;
12519       rtx frame_reg;
12520       int words;
12521
12522       scratch_regno = split_stack_prologue_scratch_regno ();
12523       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
12524       frame_reg = gen_rtx_REG (Pmode, BP_REG);
12525
12526       /* 64-bit:
12527          fp -> old fp value
12528                return address within this function
12529                return address of caller of this function
12530                stack arguments
12531          So we add three words to get to the stack arguments.
12532
12533          32-bit:
12534          fp -> old fp value
12535                return address within this function
12536                first argument to __morestack
12537                second argument to __morestack
12538                return address of caller of this function
12539                stack arguments
12540          So we add five words to get to the stack arguments.
12541       */
12542       words = TARGET_64BIT ? 3 : 5;
12543       emit_insn (gen_rtx_SET (VOIDmode, scratch_reg,
12544                               gen_rtx_PLUS (Pmode, frame_reg,
12545                                             GEN_INT (words * UNITS_PER_WORD))));
12546
12547       varargs_label = gen_label_rtx ();
12548       emit_jump_insn (gen_jump (varargs_label));
12549       JUMP_LABEL (get_last_insn ()) = varargs_label;
12550
12551       emit_barrier ();
12552     }
12553
12554   emit_label (label);
12555   LABEL_NUSES (label) = 1;
12556
12557   /* If this function calls va_start, we now have to set the scratch
12558      register for the case where we do not call __morestack.  In this
12559      case we need to set it based on the stack pointer.  */
12560   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12561     {
12562       emit_insn (gen_rtx_SET (VOIDmode, scratch_reg,
12563                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12564                                             GEN_INT (UNITS_PER_WORD))));
12565
12566       emit_label (varargs_label);
12567       LABEL_NUSES (varargs_label) = 1;
12568     }
12569 }
12570
12571 /* We may have to tell the dataflow pass that the split stack prologue
12572    is initializing a scratch register.  */
12573
12574 static void
12575 ix86_live_on_entry (bitmap regs)
12576 {
12577   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12578     {
12579       gcc_assert (flag_split_stack);
12580       bitmap_set_bit (regs, split_stack_prologue_scratch_regno ());
12581     }
12582 }
12583 \f
12584 /* Extract the parts of an RTL expression that is a valid memory address
12585    for an instruction.  Return 0 if the structure of the address is
12586    grossly off.  Return -1 if the address contains ASHIFT, so it is not
12587    strictly valid, but still used for computing length of lea instruction.  */
12588
12589 int
12590 ix86_decompose_address (rtx addr, struct ix86_address *out)
12591 {
12592   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
12593   rtx base_reg, index_reg;
12594   HOST_WIDE_INT scale = 1;
12595   rtx scale_rtx = NULL_RTX;
12596   rtx tmp;
12597   int retval = 1;
12598   enum ix86_address_seg seg = SEG_DEFAULT;
12599
12600   /* Allow zero-extended SImode addresses,
12601      they will be emitted with addr32 prefix.  */
12602   if (TARGET_64BIT && GET_MODE (addr) == DImode)
12603     {
12604       if (GET_CODE (addr) == ZERO_EXTEND
12605           && GET_MODE (XEXP (addr, 0)) == SImode)
12606         {
12607           addr = XEXP (addr, 0);
12608           if (CONST_INT_P (addr))
12609             return 0;
12610         }             
12611       else if (GET_CODE (addr) == AND
12612                && const_32bit_mask (XEXP (addr, 1), DImode))
12613         {
12614           addr = simplify_gen_subreg (SImode, XEXP (addr, 0), DImode, 0);
12615           if (addr == NULL_RTX)
12616             return 0;
12617
12618           if (CONST_INT_P (addr))
12619             return 0;
12620         }
12621     }
12622
12623   /* Allow SImode subregs of DImode addresses,
12624      they will be emitted with addr32 prefix.  */
12625   if (TARGET_64BIT && GET_MODE (addr) == SImode)
12626     {
12627       if (GET_CODE (addr) == SUBREG
12628           && GET_MODE (SUBREG_REG (addr)) == DImode)
12629         {
12630           addr = SUBREG_REG (addr);
12631           if (CONST_INT_P (addr))
12632             return 0;
12633         }
12634     }
12635
12636   if (REG_P (addr))
12637     base = addr;
12638   else if (GET_CODE (addr) == SUBREG)
12639     {
12640       if (REG_P (SUBREG_REG (addr)))
12641         base = addr;
12642       else
12643         return 0;
12644     }
12645   else if (GET_CODE (addr) == PLUS)
12646     {
12647       rtx addends[4], op;
12648       int n = 0, i;
12649
12650       op = addr;
12651       do
12652         {
12653           if (n >= 4)
12654             return 0;
12655           addends[n++] = XEXP (op, 1);
12656           op = XEXP (op, 0);
12657         }
12658       while (GET_CODE (op) == PLUS);
12659       if (n >= 4)
12660         return 0;
12661       addends[n] = op;
12662
12663       for (i = n; i >= 0; --i)
12664         {
12665           op = addends[i];
12666           switch (GET_CODE (op))
12667             {
12668             case MULT:
12669               if (index)
12670                 return 0;
12671               index = XEXP (op, 0);
12672               scale_rtx = XEXP (op, 1);
12673               break;
12674
12675             case ASHIFT:
12676               if (index)
12677                 return 0;
12678               index = XEXP (op, 0);
12679               tmp = XEXP (op, 1);
12680               if (!CONST_INT_P (tmp))
12681                 return 0;
12682               scale = INTVAL (tmp);
12683               if ((unsigned HOST_WIDE_INT) scale > 3)
12684                 return 0;
12685               scale = 1 << scale;
12686               break;
12687
12688             case ZERO_EXTEND:
12689               op = XEXP (op, 0);
12690               if (GET_CODE (op) != UNSPEC)
12691                 return 0;
12692               /* FALLTHRU */
12693
12694             case UNSPEC:
12695               if (XINT (op, 1) == UNSPEC_TP
12696                   && TARGET_TLS_DIRECT_SEG_REFS
12697                   && seg == SEG_DEFAULT)
12698                 seg = DEFAULT_TLS_SEG_REG;
12699               else
12700                 return 0;
12701               break;
12702
12703             case SUBREG:
12704               if (!REG_P (SUBREG_REG (op)))
12705                 return 0;
12706               /* FALLTHRU */
12707
12708             case REG:
12709               if (!base)
12710                 base = op;
12711               else if (!index)
12712                 index = op;
12713               else
12714                 return 0;
12715               break;
12716
12717             case CONST:
12718             case CONST_INT:
12719             case SYMBOL_REF:
12720             case LABEL_REF:
12721               if (disp)
12722                 return 0;
12723               disp = op;
12724               break;
12725
12726             default:
12727               return 0;
12728             }
12729         }
12730     }
12731   else if (GET_CODE (addr) == MULT)
12732     {
12733       index = XEXP (addr, 0);           /* index*scale */
12734       scale_rtx = XEXP (addr, 1);
12735     }
12736   else if (GET_CODE (addr) == ASHIFT)
12737     {
12738       /* We're called for lea too, which implements ashift on occasion.  */
12739       index = XEXP (addr, 0);
12740       tmp = XEXP (addr, 1);
12741       if (!CONST_INT_P (tmp))
12742         return 0;
12743       scale = INTVAL (tmp);
12744       if ((unsigned HOST_WIDE_INT) scale > 3)
12745         return 0;
12746       scale = 1 << scale;
12747       retval = -1;
12748     }
12749   else
12750     disp = addr;                        /* displacement */
12751
12752   if (index)
12753     {
12754       if (REG_P (index))
12755         ;
12756       else if (GET_CODE (index) == SUBREG
12757                && REG_P (SUBREG_REG (index)))
12758         ;
12759       else
12760         return 0;
12761     }
12762
12763   /* Extract the integral value of scale.  */
12764   if (scale_rtx)
12765     {
12766       if (!CONST_INT_P (scale_rtx))
12767         return 0;
12768       scale = INTVAL (scale_rtx);
12769     }
12770
12771   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
12772   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
12773
12774   /* Avoid useless 0 displacement.  */
12775   if (disp == const0_rtx && (base || index))
12776     disp = NULL_RTX;
12777
12778   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
12779   if (base_reg && index_reg && scale == 1
12780       && (index_reg == arg_pointer_rtx
12781           || index_reg == frame_pointer_rtx
12782           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
12783     {
12784       std::swap (base, index);
12785       std::swap (base_reg, index_reg);
12786     }
12787
12788   /* Special case: %ebp cannot be encoded as a base without a displacement.
12789      Similarly %r13.  */
12790   if (!disp
12791       && base_reg
12792       && (base_reg == hard_frame_pointer_rtx
12793           || base_reg == frame_pointer_rtx
12794           || base_reg == arg_pointer_rtx
12795           || (REG_P (base_reg)
12796               && (REGNO (base_reg) == HARD_FRAME_POINTER_REGNUM
12797                   || REGNO (base_reg) == R13_REG))))
12798     disp = const0_rtx;
12799
12800   /* Special case: on K6, [%esi] makes the instruction vector decoded.
12801      Avoid this by transforming to [%esi+0].
12802      Reload calls address legitimization without cfun defined, so we need
12803      to test cfun for being non-NULL. */
12804   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
12805       && base_reg && !index_reg && !disp
12806       && REG_P (base_reg) && REGNO (base_reg) == SI_REG)
12807     disp = const0_rtx;
12808
12809   /* Special case: encode reg+reg instead of reg*2.  */
12810   if (!base && index && scale == 2)
12811     base = index, base_reg = index_reg, scale = 1;
12812
12813   /* Special case: scaling cannot be encoded without base or displacement.  */
12814   if (!base && !disp && index && scale != 1)
12815     disp = const0_rtx;
12816
12817   out->base = base;
12818   out->index = index;
12819   out->disp = disp;
12820   out->scale = scale;
12821   out->seg = seg;
12822
12823   return retval;
12824 }
12825 \f
12826 /* Return cost of the memory address x.
12827    For i386, it is better to use a complex address than let gcc copy
12828    the address into a reg and make a new pseudo.  But not if the address
12829    requires to two regs - that would mean more pseudos with longer
12830    lifetimes.  */
12831 static int
12832 ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
12833 {
12834   struct ix86_address parts;
12835   int cost = 1;
12836   int ok = ix86_decompose_address (x, &parts);
12837
12838   gcc_assert (ok);
12839
12840   if (parts.base && GET_CODE (parts.base) == SUBREG)
12841     parts.base = SUBREG_REG (parts.base);
12842   if (parts.index && GET_CODE (parts.index) == SUBREG)
12843     parts.index = SUBREG_REG (parts.index);
12844
12845   /* Attempt to minimize number of registers in the address.  */
12846   if ((parts.base
12847        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
12848       || (parts.index
12849           && (!REG_P (parts.index)
12850               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
12851     cost++;
12852
12853   /* When address base or index is "pic_offset_table_rtx" we don't increase
12854      address cost.  When a memopt with "pic_offset_table_rtx" is not invariant
12855      itself it most likely means that base or index is not invariant.
12856      Therefore only "pic_offset_table_rtx" could be hoisted out, which is not
12857      profitable for x86.  */
12858   if (parts.base
12859       && (current_pass->type == GIMPLE_PASS
12860           || (!pic_offset_table_rtx
12861               || REGNO (pic_offset_table_rtx) != REGNO(parts.base)))
12862       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
12863       && parts.index
12864       && (current_pass->type == GIMPLE_PASS
12865           || (!pic_offset_table_rtx
12866               || REGNO (pic_offset_table_rtx) != REGNO(parts.index)))
12867       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
12868       && parts.base != parts.index)
12869     cost++;
12870
12871   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
12872      since it's predecode logic can't detect the length of instructions
12873      and it degenerates to vector decoded.  Increase cost of such
12874      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
12875      to split such addresses or even refuse such addresses at all.
12876
12877      Following addressing modes are affected:
12878       [base+scale*index]
12879       [scale*index+disp]
12880       [base+index]
12881
12882      The first and last case  may be avoidable by explicitly coding the zero in
12883      memory address, but I don't have AMD-K6 machine handy to check this
12884      theory.  */
12885
12886   if (TARGET_K6
12887       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
12888           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
12889           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
12890     cost += 10;
12891
12892   return cost;
12893 }
12894 \f
12895 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
12896    this is used for to form addresses to local data when -fPIC is in
12897    use.  */
12898
12899 static bool
12900 darwin_local_data_pic (rtx disp)
12901 {
12902   return (GET_CODE (disp) == UNSPEC
12903           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
12904 }
12905
12906 /* Determine if a given RTX is a valid constant.  We already know this
12907    satisfies CONSTANT_P.  */
12908
12909 static bool
12910 ix86_legitimate_constant_p (machine_mode, rtx x)
12911 {
12912   /* Pointer bounds constants are not valid.  */
12913   if (POINTER_BOUNDS_MODE_P (GET_MODE (x)))
12914     return false;
12915
12916   switch (GET_CODE (x))
12917     {
12918     case CONST:
12919       x = XEXP (x, 0);
12920
12921       if (GET_CODE (x) == PLUS)
12922         {
12923           if (!CONST_INT_P (XEXP (x, 1)))
12924             return false;
12925           x = XEXP (x, 0);
12926         }
12927
12928       if (TARGET_MACHO && darwin_local_data_pic (x))
12929         return true;
12930
12931       /* Only some unspecs are valid as "constants".  */
12932       if (GET_CODE (x) == UNSPEC)
12933         switch (XINT (x, 1))
12934           {
12935           case UNSPEC_GOT:
12936           case UNSPEC_GOTOFF:
12937           case UNSPEC_PLTOFF:
12938             return TARGET_64BIT;
12939           case UNSPEC_TPOFF:
12940           case UNSPEC_NTPOFF:
12941             x = XVECEXP (x, 0, 0);
12942             return (GET_CODE (x) == SYMBOL_REF
12943                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
12944           case UNSPEC_DTPOFF:
12945             x = XVECEXP (x, 0, 0);
12946             return (GET_CODE (x) == SYMBOL_REF
12947                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
12948           default:
12949             return false;
12950           }
12951
12952       /* We must have drilled down to a symbol.  */
12953       if (GET_CODE (x) == LABEL_REF)
12954         return true;
12955       if (GET_CODE (x) != SYMBOL_REF)
12956         return false;
12957       /* FALLTHRU */
12958
12959     case SYMBOL_REF:
12960       /* TLS symbols are never valid.  */
12961       if (SYMBOL_REF_TLS_MODEL (x))
12962         return false;
12963
12964       /* DLLIMPORT symbols are never valid.  */
12965       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12966           && SYMBOL_REF_DLLIMPORT_P (x))
12967         return false;
12968
12969 #if TARGET_MACHO
12970       /* mdynamic-no-pic */
12971       if (MACHO_DYNAMIC_NO_PIC_P)
12972         return machopic_symbol_defined_p (x);
12973 #endif
12974       break;
12975
12976     case CONST_DOUBLE:
12977       if (GET_MODE (x) == TImode
12978           && x != CONST0_RTX (TImode)
12979           && !TARGET_64BIT)
12980         return false;
12981       break;
12982
12983     case CONST_VECTOR:
12984       if (!standard_sse_constant_p (x))
12985         return false;
12986
12987     default:
12988       break;
12989     }
12990
12991   /* Otherwise we handle everything else in the move patterns.  */
12992   return true;
12993 }
12994
12995 /* Determine if it's legal to put X into the constant pool.  This
12996    is not possible for the address of thread-local symbols, which
12997    is checked above.  */
12998
12999 static bool
13000 ix86_cannot_force_const_mem (machine_mode mode, rtx x)
13001 {
13002   /* We can always put integral constants and vectors in memory.  */
13003   switch (GET_CODE (x))
13004     {
13005     case CONST_INT:
13006     case CONST_DOUBLE:
13007     case CONST_VECTOR:
13008       return false;
13009
13010     default:
13011       break;
13012     }
13013   return !ix86_legitimate_constant_p (mode, x);
13014 }
13015
13016 /*  Nonzero if the symbol is marked as dllimport, or as stub-variable,
13017     otherwise zero.  */
13018
13019 static bool
13020 is_imported_p (rtx x)
13021 {
13022   if (!TARGET_DLLIMPORT_DECL_ATTRIBUTES
13023       || GET_CODE (x) != SYMBOL_REF)
13024     return false;
13025
13026   return SYMBOL_REF_DLLIMPORT_P (x) || SYMBOL_REF_STUBVAR_P (x);
13027 }
13028
13029
13030 /* Nonzero if the constant value X is a legitimate general operand
13031    when generating PIC code.  It is given that flag_pic is on and
13032    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
13033
13034 bool
13035 legitimate_pic_operand_p (rtx x)
13036 {
13037   rtx inner;
13038
13039   switch (GET_CODE (x))
13040     {
13041     case CONST:
13042       inner = XEXP (x, 0);
13043       if (GET_CODE (inner) == PLUS
13044           && CONST_INT_P (XEXP (inner, 1)))
13045         inner = XEXP (inner, 0);
13046
13047       /* Only some unspecs are valid as "constants".  */
13048       if (GET_CODE (inner) == UNSPEC)
13049         switch (XINT (inner, 1))
13050           {
13051           case UNSPEC_GOT:
13052           case UNSPEC_GOTOFF:
13053           case UNSPEC_PLTOFF:
13054             return TARGET_64BIT;
13055           case UNSPEC_TPOFF:
13056             x = XVECEXP (inner, 0, 0);
13057             return (GET_CODE (x) == SYMBOL_REF
13058                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
13059           case UNSPEC_MACHOPIC_OFFSET:
13060             return legitimate_pic_address_disp_p (x);
13061           default:
13062             return false;
13063           }
13064       /* FALLTHRU */
13065
13066     case SYMBOL_REF:
13067     case LABEL_REF:
13068       return legitimate_pic_address_disp_p (x);
13069
13070     default:
13071       return true;
13072     }
13073 }
13074
13075 /* Determine if a given CONST RTX is a valid memory displacement
13076    in PIC mode.  */
13077
13078 bool
13079 legitimate_pic_address_disp_p (rtx disp)
13080 {
13081   bool saw_plus;
13082
13083   /* In 64bit mode we can allow direct addresses of symbols and labels
13084      when they are not dynamic symbols.  */
13085   if (TARGET_64BIT)
13086     {
13087       rtx op0 = disp, op1;
13088
13089       switch (GET_CODE (disp))
13090         {
13091         case LABEL_REF:
13092           return true;
13093
13094         case CONST:
13095           if (GET_CODE (XEXP (disp, 0)) != PLUS)
13096             break;
13097           op0 = XEXP (XEXP (disp, 0), 0);
13098           op1 = XEXP (XEXP (disp, 0), 1);
13099           if (!CONST_INT_P (op1)
13100               || INTVAL (op1) >= 16*1024*1024
13101               || INTVAL (op1) < -16*1024*1024)
13102             break;
13103           if (GET_CODE (op0) == LABEL_REF)
13104             return true;
13105           if (GET_CODE (op0) == CONST
13106               && GET_CODE (XEXP (op0, 0)) == UNSPEC
13107               && XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL)
13108             return true;
13109           if (GET_CODE (op0) == UNSPEC
13110               && XINT (op0, 1) == UNSPEC_PCREL)
13111             return true;
13112           if (GET_CODE (op0) != SYMBOL_REF)
13113             break;
13114           /* FALLTHRU */
13115
13116         case SYMBOL_REF:
13117           /* TLS references should always be enclosed in UNSPEC.
13118              The dllimported symbol needs always to be resolved.  */
13119           if (SYMBOL_REF_TLS_MODEL (op0)
13120               || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0)))
13121             return false;
13122
13123           if (TARGET_PECOFF)
13124             {
13125               if (is_imported_p (op0))
13126                 return true;
13127
13128               if (SYMBOL_REF_FAR_ADDR_P (op0)
13129                   || !SYMBOL_REF_LOCAL_P (op0))
13130                 break;
13131
13132               /* Function-symbols need to be resolved only for
13133                  large-model.
13134                  For the small-model we don't need to resolve anything
13135                  here.  */
13136               if ((ix86_cmodel != CM_LARGE_PIC
13137                    && SYMBOL_REF_FUNCTION_P (op0))
13138                   || ix86_cmodel == CM_SMALL_PIC)
13139                 return true;
13140               /* Non-external symbols don't need to be resolved for
13141                  large, and medium-model.  */
13142               if ((ix86_cmodel == CM_LARGE_PIC
13143                    || ix86_cmodel == CM_MEDIUM_PIC)
13144                   && !SYMBOL_REF_EXTERNAL_P (op0))
13145                 return true;
13146             }
13147           else if (!SYMBOL_REF_FAR_ADDR_P (op0)
13148                    && (SYMBOL_REF_LOCAL_P (op0)
13149                        || (HAVE_LD_PIE_COPYRELOC
13150                            && flag_pie
13151                            && !SYMBOL_REF_WEAK (op0)
13152                            && !SYMBOL_REF_FUNCTION_P (op0)))
13153                    && ix86_cmodel != CM_LARGE_PIC)
13154             return true;
13155           break;
13156
13157         default:
13158           break;
13159         }
13160     }
13161   if (GET_CODE (disp) != CONST)
13162     return false;
13163   disp = XEXP (disp, 0);
13164
13165   if (TARGET_64BIT)
13166     {
13167       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
13168          of GOT tables.  We should not need these anyway.  */
13169       if (GET_CODE (disp) != UNSPEC
13170           || (XINT (disp, 1) != UNSPEC_GOTPCREL
13171               && XINT (disp, 1) != UNSPEC_GOTOFF
13172               && XINT (disp, 1) != UNSPEC_PCREL
13173               && XINT (disp, 1) != UNSPEC_PLTOFF))
13174         return false;
13175
13176       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
13177           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
13178         return false;
13179       return true;
13180     }
13181
13182   saw_plus = false;
13183   if (GET_CODE (disp) == PLUS)
13184     {
13185       if (!CONST_INT_P (XEXP (disp, 1)))
13186         return false;
13187       disp = XEXP (disp, 0);
13188       saw_plus = true;
13189     }
13190
13191   if (TARGET_MACHO && darwin_local_data_pic (disp))
13192     return true;
13193
13194   if (GET_CODE (disp) != UNSPEC)
13195     return false;
13196
13197   switch (XINT (disp, 1))
13198     {
13199     case UNSPEC_GOT:
13200       if (saw_plus)
13201         return false;
13202       /* We need to check for both symbols and labels because VxWorks loads
13203          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
13204          details.  */
13205       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
13206               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
13207     case UNSPEC_GOTOFF:
13208       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
13209          While ABI specify also 32bit relocation but we don't produce it in
13210          small PIC model at all.  */
13211       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
13212            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
13213           && !TARGET_64BIT)
13214         return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
13215       return false;
13216     case UNSPEC_GOTTPOFF:
13217     case UNSPEC_GOTNTPOFF:
13218     case UNSPEC_INDNTPOFF:
13219       if (saw_plus)
13220         return false;
13221       disp = XVECEXP (disp, 0, 0);
13222       return (GET_CODE (disp) == SYMBOL_REF
13223               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
13224     case UNSPEC_NTPOFF:
13225       disp = XVECEXP (disp, 0, 0);
13226       return (GET_CODE (disp) == SYMBOL_REF
13227               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
13228     case UNSPEC_DTPOFF:
13229       disp = XVECEXP (disp, 0, 0);
13230       return (GET_CODE (disp) == SYMBOL_REF
13231               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
13232     }
13233
13234   return false;
13235 }
13236
13237 /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS.  Returns a value to
13238    replace the input X, or the original X if no replacement is called for.
13239    The output parameter *WIN is 1 if the calling macro should goto WIN,
13240    0 if it should not.  */
13241
13242 bool
13243 ix86_legitimize_reload_address (rtx x, machine_mode, int opnum, int type,
13244                                 int)
13245 {
13246   /* Reload can generate:
13247
13248      (plus:DI (plus:DI (unspec:DI [(const_int 0 [0])] UNSPEC_TP)
13249                        (reg:DI 97))
13250               (reg:DI 2 cx))
13251
13252      This RTX is rejected from ix86_legitimate_address_p due to
13253      non-strictness of base register 97.  Following this rejection, 
13254      reload pushes all three components into separate registers,
13255      creating invalid memory address RTX.
13256
13257      Following code reloads only the invalid part of the
13258      memory address RTX.  */
13259
13260   if (GET_CODE (x) == PLUS
13261       && REG_P (XEXP (x, 1))
13262       && GET_CODE (XEXP (x, 0)) == PLUS
13263       && REG_P (XEXP (XEXP (x, 0), 1)))
13264     {
13265       rtx base, index;
13266       bool something_reloaded = false;
13267
13268       base = XEXP (XEXP (x, 0), 1);      
13269       if (!REG_OK_FOR_BASE_STRICT_P (base))
13270         {
13271           push_reload (base, NULL_RTX, &XEXP (XEXP (x, 0), 1), NULL,
13272                        BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
13273                        opnum, (enum reload_type) type);
13274           something_reloaded = true;
13275         }
13276
13277       index = XEXP (x, 1);
13278       if (!REG_OK_FOR_INDEX_STRICT_P (index))
13279         {
13280           push_reload (index, NULL_RTX, &XEXP (x, 1), NULL,
13281                        INDEX_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
13282                        opnum, (enum reload_type) type);
13283           something_reloaded = true;
13284         }
13285
13286       gcc_assert (something_reloaded);
13287       return true;
13288     }
13289
13290   return false;
13291 }
13292
13293 /* Determine if op is suitable RTX for an address register.
13294    Return naked register if a register or a register subreg is
13295    found, otherwise return NULL_RTX.  */
13296
13297 static rtx
13298 ix86_validate_address_register (rtx op)
13299 {
13300   machine_mode mode = GET_MODE (op);
13301
13302   /* Only SImode or DImode registers can form the address.  */
13303   if (mode != SImode && mode != DImode)
13304     return NULL_RTX;
13305
13306   if (REG_P (op))
13307     return op;
13308   else if (GET_CODE (op) == SUBREG)
13309     {
13310       rtx reg = SUBREG_REG (op);
13311
13312       if (!REG_P (reg))
13313         return NULL_RTX;
13314
13315       mode = GET_MODE (reg);
13316
13317       /* Don't allow SUBREGs that span more than a word.  It can
13318          lead to spill failures when the register is one word out
13319          of a two word structure.  */
13320       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
13321         return NULL_RTX;
13322
13323       /* Allow only SUBREGs of non-eliminable hard registers.  */
13324       if (register_no_elim_operand (reg, mode))
13325         return reg;
13326     }
13327
13328   /* Op is not a register.  */
13329   return NULL_RTX;
13330 }
13331
13332 /* Recognizes RTL expressions that are valid memory addresses for an
13333    instruction.  The MODE argument is the machine mode for the MEM
13334    expression that wants to use this address.
13335
13336    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
13337    convert common non-canonical forms to canonical form so that they will
13338    be recognized.  */
13339
13340 static bool
13341 ix86_legitimate_address_p (machine_mode, rtx addr, bool strict)
13342 {
13343   struct ix86_address parts;
13344   rtx base, index, disp;
13345   HOST_WIDE_INT scale;
13346   enum ix86_address_seg seg;
13347
13348   if (ix86_decompose_address (addr, &parts) <= 0)
13349     /* Decomposition failed.  */
13350     return false;
13351
13352   base = parts.base;
13353   index = parts.index;
13354   disp = parts.disp;
13355   scale = parts.scale;
13356   seg = parts.seg;
13357
13358   /* Validate base register.  */
13359   if (base)
13360     {
13361       rtx reg = ix86_validate_address_register (base);
13362
13363       if (reg == NULL_RTX)
13364         return false;
13365
13366       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
13367           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
13368         /* Base is not valid.  */
13369         return false;
13370     }
13371
13372   /* Validate index register.  */
13373   if (index)
13374     {
13375       rtx reg = ix86_validate_address_register (index);
13376
13377       if (reg == NULL_RTX)
13378         return false;
13379
13380       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
13381           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
13382         /* Index is not valid.  */
13383         return false;
13384     }
13385
13386   /* Index and base should have the same mode.  */
13387   if (base && index
13388       && GET_MODE (base) != GET_MODE (index))
13389     return false;
13390
13391   /* Address override works only on the (%reg) part of %fs:(%reg).  */
13392   if (seg != SEG_DEFAULT
13393       && ((base && GET_MODE (base) != word_mode)
13394           || (index && GET_MODE (index) != word_mode)))
13395     return false;
13396
13397   /* Validate scale factor.  */
13398   if (scale != 1)
13399     {
13400       if (!index)
13401         /* Scale without index.  */
13402         return false;
13403
13404       if (scale != 2 && scale != 4 && scale != 8)
13405         /* Scale is not a valid multiplier.  */
13406         return false;
13407     }
13408
13409   /* Validate displacement.  */
13410   if (disp)
13411     {
13412       if (GET_CODE (disp) == CONST
13413           && GET_CODE (XEXP (disp, 0)) == UNSPEC
13414           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
13415         switch (XINT (XEXP (disp, 0), 1))
13416           {
13417           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
13418              used.  While ABI specify also 32bit relocations, we don't produce
13419              them at all and use IP relative instead.  */
13420           case UNSPEC_GOT:
13421           case UNSPEC_GOTOFF:
13422             gcc_assert (flag_pic);
13423             if (!TARGET_64BIT)
13424               goto is_legitimate_pic;
13425
13426             /* 64bit address unspec.  */
13427             return false;
13428
13429           case UNSPEC_GOTPCREL:
13430           case UNSPEC_PCREL:
13431             gcc_assert (flag_pic);
13432             goto is_legitimate_pic;
13433
13434           case UNSPEC_GOTTPOFF:
13435           case UNSPEC_GOTNTPOFF:
13436           case UNSPEC_INDNTPOFF:
13437           case UNSPEC_NTPOFF:
13438           case UNSPEC_DTPOFF:
13439             break;
13440
13441           case UNSPEC_STACK_CHECK:
13442             gcc_assert (flag_split_stack);
13443             break;
13444
13445           default:
13446             /* Invalid address unspec.  */
13447             return false;
13448           }
13449
13450       else if (SYMBOLIC_CONST (disp)
13451                && (flag_pic
13452                    || (TARGET_MACHO
13453 #if TARGET_MACHO
13454                        && MACHOPIC_INDIRECT
13455                        && !machopic_operand_p (disp)
13456 #endif
13457                )))
13458         {
13459
13460         is_legitimate_pic:
13461           if (TARGET_64BIT && (index || base))
13462             {
13463               /* foo@dtpoff(%rX) is ok.  */
13464               if (GET_CODE (disp) != CONST
13465                   || GET_CODE (XEXP (disp, 0)) != PLUS
13466                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
13467                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
13468                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
13469                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
13470                 /* Non-constant pic memory reference.  */
13471                 return false;
13472             }
13473           else if ((!TARGET_MACHO || flag_pic)
13474                     && ! legitimate_pic_address_disp_p (disp))
13475             /* Displacement is an invalid pic construct.  */
13476             return false;
13477 #if TARGET_MACHO
13478           else if (MACHO_DYNAMIC_NO_PIC_P
13479                    && !ix86_legitimate_constant_p (Pmode, disp))
13480             /* displacment must be referenced via non_lazy_pointer */
13481             return false;
13482 #endif
13483
13484           /* This code used to verify that a symbolic pic displacement
13485              includes the pic_offset_table_rtx register.
13486
13487              While this is good idea, unfortunately these constructs may
13488              be created by "adds using lea" optimization for incorrect
13489              code like:
13490
13491              int a;
13492              int foo(int i)
13493                {
13494                  return *(&a+i);
13495                }
13496
13497              This code is nonsensical, but results in addressing
13498              GOT table with pic_offset_table_rtx base.  We can't
13499              just refuse it easily, since it gets matched by
13500              "addsi3" pattern, that later gets split to lea in the
13501              case output register differs from input.  While this
13502              can be handled by separate addsi pattern for this case
13503              that never results in lea, this seems to be easier and
13504              correct fix for crash to disable this test.  */
13505         }
13506       else if (GET_CODE (disp) != LABEL_REF
13507                && !CONST_INT_P (disp)
13508                && (GET_CODE (disp) != CONST
13509                    || !ix86_legitimate_constant_p (Pmode, disp))
13510                && (GET_CODE (disp) != SYMBOL_REF
13511                    || !ix86_legitimate_constant_p (Pmode, disp)))
13512         /* Displacement is not constant.  */
13513         return false;
13514       else if (TARGET_64BIT
13515                && !x86_64_immediate_operand (disp, VOIDmode))
13516         /* Displacement is out of range.  */
13517         return false;
13518       /* In x32 mode, constant addresses are sign extended to 64bit, so
13519          we have to prevent addresses from 0x80000000 to 0xffffffff.  */
13520       else if (TARGET_X32 && !(index || base)
13521                && CONST_INT_P (disp)
13522                && val_signbit_known_set_p (SImode, INTVAL (disp)))
13523         return false;
13524     }
13525
13526   /* Everything looks valid.  */
13527   return true;
13528 }
13529
13530 /* Determine if a given RTX is a valid constant address.  */
13531
13532 bool
13533 constant_address_p (rtx x)
13534 {
13535   return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
13536 }
13537 \f
13538 /* Return a unique alias set for the GOT.  */
13539
13540 static alias_set_type
13541 ix86_GOT_alias_set (void)
13542 {
13543   static alias_set_type set = -1;
13544   if (set == -1)
13545     set = new_alias_set ();
13546   return set;
13547 }
13548
13549 /* Set regs_ever_live for PIC base address register
13550    to true if required.  */
13551 static void
13552 set_pic_reg_ever_live ()
13553 {
13554   if (reload_in_progress)
13555     df_set_regs_ever_live (REGNO (pic_offset_table_rtx), true);
13556 }
13557
13558 /* Return a legitimate reference for ORIG (an address) using the
13559    register REG.  If REG is 0, a new pseudo is generated.
13560
13561    There are two types of references that must be handled:
13562
13563    1. Global data references must load the address from the GOT, via
13564       the PIC reg.  An insn is emitted to do this load, and the reg is
13565       returned.
13566
13567    2. Static data references, constant pool addresses, and code labels
13568       compute the address as an offset from the GOT, whose base is in
13569       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
13570       differentiate them from global data objects.  The returned
13571       address is the PIC reg + an unspec constant.
13572
13573    TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
13574    reg also appears in the address.  */
13575
13576 static rtx
13577 legitimize_pic_address (rtx orig, rtx reg)
13578 {
13579   rtx addr = orig;
13580   rtx new_rtx = orig;
13581
13582 #if TARGET_MACHO
13583   if (TARGET_MACHO && !TARGET_64BIT)
13584     {
13585       if (reg == 0)
13586         reg = gen_reg_rtx (Pmode);
13587       /* Use the generic Mach-O PIC machinery.  */
13588       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
13589     }
13590 #endif
13591
13592   if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES)
13593     {
13594       rtx tmp = legitimize_pe_coff_symbol (addr, true);
13595       if (tmp)
13596         return tmp;
13597     }
13598
13599   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
13600     new_rtx = addr;
13601   else if (TARGET_64BIT && !TARGET_PECOFF
13602            && ix86_cmodel != CM_SMALL_PIC && gotoff_operand (addr, Pmode))
13603     {
13604       rtx tmpreg;
13605       /* This symbol may be referenced via a displacement from the PIC
13606          base address (@GOTOFF).  */
13607
13608       set_pic_reg_ever_live ();
13609       if (GET_CODE (addr) == CONST)
13610         addr = XEXP (addr, 0);
13611       if (GET_CODE (addr) == PLUS)
13612           {
13613             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
13614                                       UNSPEC_GOTOFF);
13615             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
13616           }
13617         else
13618           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
13619       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13620       if (!reg)
13621         tmpreg = gen_reg_rtx (Pmode);
13622       else
13623         tmpreg = reg;
13624       emit_move_insn (tmpreg, new_rtx);
13625
13626       if (reg != 0)
13627         {
13628           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
13629                                          tmpreg, 1, OPTAB_DIRECT);
13630           new_rtx = reg;
13631         }
13632       else
13633         new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
13634     }
13635   else if (!TARGET_64BIT && !TARGET_PECOFF && gotoff_operand (addr, Pmode))
13636     {
13637       /* This symbol may be referenced via a displacement from the PIC
13638          base address (@GOTOFF).  */
13639
13640       set_pic_reg_ever_live ();
13641       if (GET_CODE (addr) == CONST)
13642         addr = XEXP (addr, 0);
13643       if (GET_CODE (addr) == PLUS)
13644           {
13645             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
13646                                       UNSPEC_GOTOFF);
13647             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
13648           }
13649         else
13650           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
13651       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13652       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13653
13654       if (reg != 0)
13655         {
13656           emit_move_insn (reg, new_rtx);
13657           new_rtx = reg;
13658         }
13659     }
13660   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
13661            /* We can't use @GOTOFF for text labels on VxWorks;
13662               see gotoff_operand.  */
13663            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
13664     {
13665       rtx tmp = legitimize_pe_coff_symbol (addr, true);
13666       if (tmp)
13667         return tmp;
13668
13669       /* For x64 PE-COFF there is no GOT table.  So we use address
13670          directly.  */
13671       if (TARGET_64BIT && TARGET_PECOFF)
13672         {
13673           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
13674           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13675
13676           if (reg == 0)
13677             reg = gen_reg_rtx (Pmode);
13678           emit_move_insn (reg, new_rtx);
13679           new_rtx = reg;
13680         }
13681       else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
13682         {
13683           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
13684           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13685           new_rtx = gen_const_mem (Pmode, new_rtx);
13686           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
13687
13688           if (reg == 0)
13689             reg = gen_reg_rtx (Pmode);
13690           /* Use directly gen_movsi, otherwise the address is loaded
13691              into register for CSE.  We don't want to CSE this addresses,
13692              instead we CSE addresses from the GOT table, so skip this.  */
13693           emit_insn (gen_movsi (reg, new_rtx));
13694           new_rtx = reg;
13695         }
13696       else
13697         {
13698           /* This symbol must be referenced via a load from the
13699              Global Offset Table (@GOT).  */
13700
13701           set_pic_reg_ever_live ();
13702           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
13703           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13704           if (TARGET_64BIT)
13705             new_rtx = force_reg (Pmode, new_rtx);
13706           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13707           new_rtx = gen_const_mem (Pmode, new_rtx);
13708           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
13709
13710           if (reg == 0)
13711             reg = gen_reg_rtx (Pmode);
13712           emit_move_insn (reg, new_rtx);
13713           new_rtx = reg;
13714         }
13715     }
13716   else
13717     {
13718       if (CONST_INT_P (addr)
13719           && !x86_64_immediate_operand (addr, VOIDmode))
13720         {
13721           if (reg)
13722             {
13723               emit_move_insn (reg, addr);
13724               new_rtx = reg;
13725             }
13726           else
13727             new_rtx = force_reg (Pmode, addr);
13728         }
13729       else if (GET_CODE (addr) == CONST)
13730         {
13731           addr = XEXP (addr, 0);
13732
13733           /* We must match stuff we generate before.  Assume the only
13734              unspecs that can get here are ours.  Not that we could do
13735              anything with them anyway....  */
13736           if (GET_CODE (addr) == UNSPEC
13737               || (GET_CODE (addr) == PLUS
13738                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
13739             return orig;
13740           gcc_assert (GET_CODE (addr) == PLUS);
13741         }
13742       if (GET_CODE (addr) == PLUS)
13743         {
13744           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
13745
13746           /* Check first to see if this is a constant offset from a @GOTOFF
13747              symbol reference.  */
13748           if (!TARGET_PECOFF && gotoff_operand (op0, Pmode)
13749               && CONST_INT_P (op1))
13750             {
13751               if (!TARGET_64BIT)
13752                 {
13753                   set_pic_reg_ever_live ();
13754                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
13755                                             UNSPEC_GOTOFF);
13756                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
13757                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13758                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13759
13760                   if (reg != 0)
13761                     {
13762                       emit_move_insn (reg, new_rtx);
13763                       new_rtx = reg;
13764                     }
13765                 }
13766               else
13767                 {
13768                   if (INTVAL (op1) < -16*1024*1024
13769                       || INTVAL (op1) >= 16*1024*1024)
13770                     {
13771                       if (!x86_64_immediate_operand (op1, Pmode))
13772                         op1 = force_reg (Pmode, op1);
13773                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
13774                     }
13775                 }
13776             }
13777           else
13778             {
13779               rtx base = legitimize_pic_address (op0, reg);
13780               machine_mode mode = GET_MODE (base);
13781               new_rtx
13782                 = legitimize_pic_address (op1, base == reg ? NULL_RTX : reg);
13783
13784               if (CONST_INT_P (new_rtx))
13785                 {
13786                   if (INTVAL (new_rtx) < -16*1024*1024
13787                       || INTVAL (new_rtx) >= 16*1024*1024)
13788                     {
13789                       if (!x86_64_immediate_operand (new_rtx, mode))
13790                         new_rtx = force_reg (mode, new_rtx);
13791                       new_rtx
13792                         = gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx);
13793                     }
13794                   else
13795                     new_rtx = plus_constant (mode, base, INTVAL (new_rtx));
13796                 }
13797               else
13798                 {
13799                   if (GET_CODE (new_rtx) == PLUS
13800                       && CONSTANT_P (XEXP (new_rtx, 1)))
13801                     {
13802                       base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0));
13803                       new_rtx = XEXP (new_rtx, 1);
13804                     }
13805                   new_rtx = gen_rtx_PLUS (mode, base, new_rtx);
13806                 }
13807             }
13808         }
13809     }
13810   return new_rtx;
13811 }
13812 \f
13813 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
13814
13815 static rtx
13816 get_thread_pointer (machine_mode tp_mode, bool to_reg)
13817 {
13818   rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
13819
13820   if (GET_MODE (tp) != tp_mode)
13821     {
13822       gcc_assert (GET_MODE (tp) == SImode);
13823       gcc_assert (tp_mode == DImode);
13824
13825       tp = gen_rtx_ZERO_EXTEND (tp_mode, tp);
13826     }
13827
13828   if (to_reg)
13829     tp = copy_to_mode_reg (tp_mode, tp);
13830
13831   return tp;
13832 }
13833
13834 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
13835
13836 static GTY(()) rtx ix86_tls_symbol;
13837
13838 static rtx
13839 ix86_tls_get_addr (void)
13840 {
13841   if (!ix86_tls_symbol)
13842     {
13843       const char *sym
13844         = ((TARGET_ANY_GNU_TLS && !TARGET_64BIT)
13845            ? "___tls_get_addr" : "__tls_get_addr");
13846
13847       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym);
13848     }
13849
13850   if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF)
13851     {
13852       rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol),
13853                                    UNSPEC_PLTOFF);
13854       return gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
13855                            gen_rtx_CONST (Pmode, unspec));
13856     }
13857
13858   return ix86_tls_symbol;
13859 }
13860
13861 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
13862
13863 static GTY(()) rtx ix86_tls_module_base_symbol;
13864
13865 rtx
13866 ix86_tls_module_base (void)
13867 {
13868   if (!ix86_tls_module_base_symbol)
13869     {
13870       ix86_tls_module_base_symbol
13871         = gen_rtx_SYMBOL_REF (Pmode, "_TLS_MODULE_BASE_");
13872
13873       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
13874         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
13875     }
13876
13877   return ix86_tls_module_base_symbol;
13878 }
13879
13880 /* A subroutine of ix86_legitimize_address and ix86_expand_move.  FOR_MOV is
13881    false if we expect this to be used for a memory address and true if
13882    we expect to load the address into a register.  */
13883
13884 static rtx
13885 legitimize_tls_address (rtx x, enum tls_model model, bool for_mov)
13886 {
13887   rtx dest, base, off;
13888   rtx pic = NULL_RTX, tp = NULL_RTX;
13889   machine_mode tp_mode = Pmode;
13890   int type;
13891
13892   /* Fall back to global dynamic model if tool chain cannot support local
13893      dynamic.  */
13894   if (TARGET_SUN_TLS && !TARGET_64BIT
13895       && !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM
13896       && model == TLS_MODEL_LOCAL_DYNAMIC)
13897     model = TLS_MODEL_GLOBAL_DYNAMIC;
13898
13899   switch (model)
13900     {
13901     case TLS_MODEL_GLOBAL_DYNAMIC:
13902       dest = gen_reg_rtx (Pmode);
13903
13904       if (!TARGET_64BIT)
13905         {
13906           if (flag_pic && !TARGET_PECOFF)
13907             pic = pic_offset_table_rtx;
13908           else
13909             {
13910               pic = gen_reg_rtx (Pmode);
13911               emit_insn (gen_set_got (pic));
13912             }
13913         }
13914
13915       if (TARGET_GNU2_TLS)
13916         {
13917           if (TARGET_64BIT)
13918             emit_insn (gen_tls_dynamic_gnu2_64 (dest, x));
13919           else
13920             emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic));
13921
13922           tp = get_thread_pointer (Pmode, true);
13923           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
13924
13925           if (GET_MODE (x) != Pmode)
13926             x = gen_rtx_ZERO_EXTEND (Pmode, x);
13927
13928           set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
13929         }
13930       else
13931         {
13932           rtx caddr = ix86_tls_get_addr ();
13933
13934           if (TARGET_64BIT)
13935             {
13936               rtx rax = gen_rtx_REG (Pmode, AX_REG);
13937               rtx_insn *insns;
13938
13939               start_sequence ();
13940               emit_call_insn
13941                 (ix86_gen_tls_global_dynamic_64 (rax, x, caddr));
13942               insns = get_insns ();
13943               end_sequence ();
13944
13945               if (GET_MODE (x) != Pmode)
13946                 x = gen_rtx_ZERO_EXTEND (Pmode, x);
13947
13948               RTL_CONST_CALL_P (insns) = 1;
13949               emit_libcall_block (insns, dest, rax, x);
13950             }
13951           else
13952             emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr));
13953         }
13954       break;
13955
13956     case TLS_MODEL_LOCAL_DYNAMIC:
13957       base = gen_reg_rtx (Pmode);
13958
13959       if (!TARGET_64BIT)
13960         {
13961           if (flag_pic)
13962             pic = pic_offset_table_rtx;
13963           else
13964             {
13965               pic = gen_reg_rtx (Pmode);
13966               emit_insn (gen_set_got (pic));
13967             }
13968         }
13969
13970       if (TARGET_GNU2_TLS)
13971         {
13972           rtx tmp = ix86_tls_module_base ();
13973
13974           if (TARGET_64BIT)
13975             emit_insn (gen_tls_dynamic_gnu2_64 (base, tmp));
13976           else
13977             emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic));
13978
13979           tp = get_thread_pointer (Pmode, true);
13980           set_unique_reg_note (get_last_insn (), REG_EQUAL,
13981                                gen_rtx_MINUS (Pmode, tmp, tp));
13982         }
13983       else
13984         {
13985           rtx caddr = ix86_tls_get_addr ();
13986
13987           if (TARGET_64BIT)
13988             {
13989               rtx rax = gen_rtx_REG (Pmode, AX_REG);
13990               rtx_insn *insns;
13991               rtx eqv;
13992
13993               start_sequence ();
13994               emit_call_insn
13995                 (ix86_gen_tls_local_dynamic_base_64 (rax, caddr));
13996               insns = get_insns ();
13997               end_sequence ();
13998
13999               /* Attach a unique REG_EQUAL, to allow the RTL optimizers to
14000                  share the LD_BASE result with other LD model accesses.  */
14001               eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
14002                                     UNSPEC_TLS_LD_BASE);
14003
14004               RTL_CONST_CALL_P (insns) = 1;
14005               emit_libcall_block (insns, base, rax, eqv);
14006             }
14007           else
14008             emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr));
14009         }
14010
14011       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
14012       off = gen_rtx_CONST (Pmode, off);
14013
14014       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
14015
14016       if (TARGET_GNU2_TLS)
14017         {
14018           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
14019
14020           if (GET_MODE (x) != Pmode)
14021             x = gen_rtx_ZERO_EXTEND (Pmode, x);
14022
14023           set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
14024         }
14025       break;
14026
14027     case TLS_MODEL_INITIAL_EXEC:
14028       if (TARGET_64BIT)
14029         {
14030           if (TARGET_SUN_TLS && !TARGET_X32)
14031             {
14032               /* The Sun linker took the AMD64 TLS spec literally
14033                  and can only handle %rax as destination of the
14034                  initial executable code sequence.  */
14035
14036               dest = gen_reg_rtx (DImode);
14037               emit_insn (gen_tls_initial_exec_64_sun (dest, x));
14038               return dest;
14039             }
14040
14041           /* Generate DImode references to avoid %fs:(%reg32)
14042              problems and linker IE->LE relaxation bug.  */
14043           tp_mode = DImode;
14044           pic = NULL;
14045           type = UNSPEC_GOTNTPOFF;
14046         }
14047       else if (flag_pic)
14048         {
14049           set_pic_reg_ever_live ();
14050           pic = pic_offset_table_rtx;
14051           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
14052         }
14053       else if (!TARGET_ANY_GNU_TLS)
14054         {
14055           pic = gen_reg_rtx (Pmode);
14056           emit_insn (gen_set_got (pic));
14057           type = UNSPEC_GOTTPOFF;
14058         }
14059       else
14060         {
14061           pic = NULL;
14062           type = UNSPEC_INDNTPOFF;
14063         }
14064
14065       off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type);
14066       off = gen_rtx_CONST (tp_mode, off);
14067       if (pic)
14068         off = gen_rtx_PLUS (tp_mode, pic, off);
14069       off = gen_const_mem (tp_mode, off);
14070       set_mem_alias_set (off, ix86_GOT_alias_set ());
14071
14072       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14073         {
14074           base = get_thread_pointer (tp_mode,
14075                                      for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
14076           off = force_reg (tp_mode, off);
14077           return gen_rtx_PLUS (tp_mode, base, off);
14078         }
14079       else
14080         {
14081           base = get_thread_pointer (Pmode, true);
14082           dest = gen_reg_rtx (Pmode);
14083           emit_insn (ix86_gen_sub3 (dest, base, off));
14084         }
14085       break;
14086
14087     case TLS_MODEL_LOCAL_EXEC:
14088       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
14089                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14090                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
14091       off = gen_rtx_CONST (Pmode, off);
14092
14093       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14094         {
14095           base = get_thread_pointer (Pmode,
14096                                      for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
14097           return gen_rtx_PLUS (Pmode, base, off);
14098         }
14099       else
14100         {
14101           base = get_thread_pointer (Pmode, true);
14102           dest = gen_reg_rtx (Pmode);
14103           emit_insn (ix86_gen_sub3 (dest, base, off));
14104         }
14105       break;
14106
14107     default:
14108       gcc_unreachable ();
14109     }
14110
14111   return dest;
14112 }
14113
14114 /* Create or return the unique __imp_DECL dllimport symbol corresponding
14115    to symbol DECL if BEIMPORT is true.  Otherwise create or return the
14116    unique refptr-DECL symbol corresponding to symbol DECL.  */
14117
14118 struct dllimport_hasher : ggc_cache_hasher<tree_map *>
14119 {
14120   static inline hashval_t hash (tree_map *m) { return m->hash; }
14121   static inline bool
14122   equal (tree_map *a, tree_map *b)
14123   {
14124     return a->base.from == b->base.from;
14125   }
14126
14127   static void
14128   handle_cache_entry (tree_map *&m)
14129   {
14130     extern void gt_ggc_mx (tree_map *&);
14131     if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY)
14132       return;
14133     else if (ggc_marked_p (m->base.from))
14134       gt_ggc_mx (m);
14135     else
14136       m = static_cast<tree_map *> (HTAB_DELETED_ENTRY);
14137   }
14138 };
14139
14140 static GTY((cache)) hash_table<dllimport_hasher> *dllimport_map;
14141
14142 static tree
14143 get_dllimport_decl (tree decl, bool beimport)
14144 {
14145   struct tree_map *h, in;
14146   const char *name;
14147   const char *prefix;
14148   size_t namelen, prefixlen;
14149   char *imp_name;
14150   tree to;
14151   rtx rtl;
14152
14153   if (!dllimport_map)
14154     dllimport_map = hash_table<dllimport_hasher>::create_ggc (512);
14155
14156   in.hash = htab_hash_pointer (decl);
14157   in.base.from = decl;
14158   tree_map **loc = dllimport_map->find_slot_with_hash (&in, in.hash, INSERT);
14159   h = *loc;
14160   if (h)
14161     return h->to;
14162
14163   *loc = h = ggc_alloc<tree_map> ();
14164   h->hash = in.hash;
14165   h->base.from = decl;
14166   h->to = to = build_decl (DECL_SOURCE_LOCATION (decl),
14167                            VAR_DECL, NULL, ptr_type_node);
14168   DECL_ARTIFICIAL (to) = 1;
14169   DECL_IGNORED_P (to) = 1;
14170   DECL_EXTERNAL (to) = 1;
14171   TREE_READONLY (to) = 1;
14172
14173   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
14174   name = targetm.strip_name_encoding (name);
14175   if (beimport)
14176     prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
14177       ? "*__imp_" : "*__imp__";
14178   else
14179     prefix = user_label_prefix[0] == 0 ? "*.refptr." : "*refptr.";
14180   namelen = strlen (name);
14181   prefixlen = strlen (prefix);
14182   imp_name = (char *) alloca (namelen + prefixlen + 1);
14183   memcpy (imp_name, prefix, prefixlen);
14184   memcpy (imp_name + prefixlen, name, namelen + 1);
14185
14186   name = ggc_alloc_string (imp_name, namelen + prefixlen);
14187   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
14188   SET_SYMBOL_REF_DECL (rtl, to);
14189   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_STUBVAR;
14190   if (!beimport)
14191     {
14192       SYMBOL_REF_FLAGS (rtl) |= SYMBOL_FLAG_EXTERNAL;
14193 #ifdef SUB_TARGET_RECORD_STUB
14194       SUB_TARGET_RECORD_STUB (name);
14195 #endif
14196     }      
14197
14198   rtl = gen_const_mem (Pmode, rtl);
14199   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
14200
14201   SET_DECL_RTL (to, rtl);
14202   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
14203
14204   return to;
14205 }
14206
14207 /* Expand SYMBOL into its corresponding far-addresse symbol.
14208    WANT_REG is true if we require the result be a register.  */
14209
14210 static rtx
14211 legitimize_pe_coff_extern_decl (rtx symbol, bool want_reg)
14212 {
14213   tree imp_decl;
14214   rtx x;
14215
14216   gcc_assert (SYMBOL_REF_DECL (symbol));
14217   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), false);
14218
14219   x = DECL_RTL (imp_decl);
14220   if (want_reg)
14221     x = force_reg (Pmode, x);
14222   return x;
14223 }
14224
14225 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
14226    true if we require the result be a register.  */
14227
14228 static rtx
14229 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
14230 {
14231   tree imp_decl;
14232   rtx x;
14233
14234   gcc_assert (SYMBOL_REF_DECL (symbol));
14235   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), true);
14236
14237   x = DECL_RTL (imp_decl);
14238   if (want_reg)
14239     x = force_reg (Pmode, x);
14240   return x;
14241 }
14242
14243 /* Expand SYMBOL into its corresponding dllimport or refptr symbol.  WANT_REG 
14244    is true if we require the result be a register.  */
14245
14246 static rtx
14247 legitimize_pe_coff_symbol (rtx addr, bool inreg)
14248 {
14249   if (!TARGET_PECOFF)
14250     return NULL_RTX;
14251
14252   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
14253     {
14254       if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
14255         return legitimize_dllimport_symbol (addr, inreg);
14256       if (GET_CODE (addr) == CONST
14257           && GET_CODE (XEXP (addr, 0)) == PLUS
14258           && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
14259           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
14260         {
14261           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), inreg);
14262           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
14263         }
14264     }
14265
14266   if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC)
14267     return NULL_RTX;
14268   if (GET_CODE (addr) == SYMBOL_REF
14269       && !is_imported_p (addr)
14270       && SYMBOL_REF_EXTERNAL_P (addr)
14271       && SYMBOL_REF_DECL (addr))
14272     return legitimize_pe_coff_extern_decl (addr, inreg);
14273
14274   if (GET_CODE (addr) == CONST
14275       && GET_CODE (XEXP (addr, 0)) == PLUS
14276       && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
14277       && !is_imported_p (XEXP (XEXP (addr, 0), 0))
14278       && SYMBOL_REF_EXTERNAL_P (XEXP (XEXP (addr, 0), 0))
14279       && SYMBOL_REF_DECL (XEXP (XEXP (addr, 0), 0)))
14280     {
14281       rtx t = legitimize_pe_coff_extern_decl (XEXP (XEXP (addr, 0), 0), inreg);
14282       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
14283     }
14284   return NULL_RTX;
14285 }
14286
14287 /* Try machine-dependent ways of modifying an illegitimate address
14288    to be legitimate.  If we find one, return the new, valid address.
14289    This macro is used in only one place: `memory_address' in explow.c.
14290
14291    OLDX is the address as it was before break_out_memory_refs was called.
14292    In some cases it is useful to look at this to decide what needs to be done.
14293
14294    It is always safe for this macro to do nothing.  It exists to recognize
14295    opportunities to optimize the output.
14296
14297    For the 80386, we handle X+REG by loading X into a register R and
14298    using R+REG.  R will go in a general reg and indexing will be used.
14299    However, if REG is a broken-out memory address or multiplication,
14300    nothing needs to be done because REG can certainly go in a general reg.
14301
14302    When -fpic is used, special handling is needed for symbolic references.
14303    See comments by legitimize_pic_address in i386.c for details.  */
14304
14305 static rtx
14306 ix86_legitimize_address (rtx x, rtx, machine_mode mode)
14307 {
14308   bool changed = false;
14309   unsigned log;
14310
14311   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
14312   if (log)
14313     return legitimize_tls_address (x, (enum tls_model) log, false);
14314   if (GET_CODE (x) == CONST
14315       && GET_CODE (XEXP (x, 0)) == PLUS
14316       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
14317       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
14318     {
14319       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
14320                                       (enum tls_model) log, false);
14321       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
14322     }
14323
14324   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
14325     {
14326       rtx tmp = legitimize_pe_coff_symbol (x, true);
14327       if (tmp)
14328         return tmp;
14329     }
14330
14331   if (flag_pic && SYMBOLIC_CONST (x))
14332     return legitimize_pic_address (x, 0);
14333
14334 #if TARGET_MACHO
14335   if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x))
14336     return machopic_indirect_data_reference (x, 0);
14337 #endif
14338
14339   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
14340   if (GET_CODE (x) == ASHIFT
14341       && CONST_INT_P (XEXP (x, 1))
14342       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
14343     {
14344       changed = true;
14345       log = INTVAL (XEXP (x, 1));
14346       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
14347                         GEN_INT (1 << log));
14348     }
14349
14350   if (GET_CODE (x) == PLUS)
14351     {
14352       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
14353
14354       if (GET_CODE (XEXP (x, 0)) == ASHIFT
14355           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
14356           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
14357         {
14358           changed = true;
14359           log = INTVAL (XEXP (XEXP (x, 0), 1));
14360           XEXP (x, 0) = gen_rtx_MULT (Pmode,
14361                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
14362                                       GEN_INT (1 << log));
14363         }
14364
14365       if (GET_CODE (XEXP (x, 1)) == ASHIFT
14366           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
14367           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
14368         {
14369           changed = true;
14370           log = INTVAL (XEXP (XEXP (x, 1), 1));
14371           XEXP (x, 1) = gen_rtx_MULT (Pmode,
14372                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
14373                                       GEN_INT (1 << log));
14374         }
14375
14376       /* Put multiply first if it isn't already.  */
14377       if (GET_CODE (XEXP (x, 1)) == MULT)
14378         {
14379           std::swap (XEXP (x, 0), XEXP (x, 1));
14380           changed = true;
14381         }
14382
14383       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
14384          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
14385          created by virtual register instantiation, register elimination, and
14386          similar optimizations.  */
14387       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
14388         {
14389           changed = true;
14390           x = gen_rtx_PLUS (Pmode,
14391                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
14392                                           XEXP (XEXP (x, 1), 0)),
14393                             XEXP (XEXP (x, 1), 1));
14394         }
14395
14396       /* Canonicalize
14397          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
14398          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
14399       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
14400                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
14401                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
14402                && CONSTANT_P (XEXP (x, 1)))
14403         {
14404           rtx constant;
14405           rtx other = NULL_RTX;
14406
14407           if (CONST_INT_P (XEXP (x, 1)))
14408             {
14409               constant = XEXP (x, 1);
14410               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
14411             }
14412           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
14413             {
14414               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
14415               other = XEXP (x, 1);
14416             }
14417           else
14418             constant = 0;
14419
14420           if (constant)
14421             {
14422               changed = true;
14423               x = gen_rtx_PLUS (Pmode,
14424                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
14425                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
14426                                 plus_constant (Pmode, other,
14427                                                INTVAL (constant)));
14428             }
14429         }
14430
14431       if (changed && ix86_legitimate_address_p (mode, x, false))
14432         return x;
14433
14434       if (GET_CODE (XEXP (x, 0)) == MULT)
14435         {
14436           changed = true;
14437           XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0));
14438         }
14439
14440       if (GET_CODE (XEXP (x, 1)) == MULT)
14441         {
14442           changed = true;
14443           XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1));
14444         }
14445
14446       if (changed
14447           && REG_P (XEXP (x, 1))
14448           && REG_P (XEXP (x, 0)))
14449         return x;
14450
14451       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
14452         {
14453           changed = true;
14454           x = legitimize_pic_address (x, 0);
14455         }
14456
14457       if (changed && ix86_legitimate_address_p (mode, x, false))
14458         return x;
14459
14460       if (REG_P (XEXP (x, 0)))
14461         {
14462           rtx temp = gen_reg_rtx (Pmode);
14463           rtx val  = force_operand (XEXP (x, 1), temp);
14464           if (val != temp)
14465             {
14466               val = convert_to_mode (Pmode, val, 1);
14467               emit_move_insn (temp, val);
14468             }
14469
14470           XEXP (x, 1) = temp;
14471           return x;
14472         }
14473
14474       else if (REG_P (XEXP (x, 1)))
14475         {
14476           rtx temp = gen_reg_rtx (Pmode);
14477           rtx val  = force_operand (XEXP (x, 0), temp);
14478           if (val != temp)
14479             {
14480               val = convert_to_mode (Pmode, val, 1);
14481               emit_move_insn (temp, val);
14482             }
14483
14484           XEXP (x, 0) = temp;
14485           return x;
14486         }
14487     }
14488
14489   return x;
14490 }
14491 \f
14492 /* Print an integer constant expression in assembler syntax.  Addition
14493    and subtraction are the only arithmetic that may appear in these
14494    expressions.  FILE is the stdio stream to write to, X is the rtx, and
14495    CODE is the operand print code from the output string.  */
14496
14497 static void
14498 output_pic_addr_const (FILE *file, rtx x, int code)
14499 {
14500   char buf[256];
14501
14502   switch (GET_CODE (x))
14503     {
14504     case PC:
14505       gcc_assert (flag_pic);
14506       putc ('.', file);
14507       break;
14508
14509     case SYMBOL_REF:
14510       if (TARGET_64BIT || ! TARGET_MACHO_BRANCH_ISLANDS)
14511         output_addr_const (file, x);
14512       else
14513         {
14514           const char *name = XSTR (x, 0);
14515
14516           /* Mark the decl as referenced so that cgraph will
14517              output the function.  */
14518           if (SYMBOL_REF_DECL (x))
14519             mark_decl_referenced (SYMBOL_REF_DECL (x));
14520
14521 #if TARGET_MACHO
14522           if (MACHOPIC_INDIRECT
14523               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
14524             name = machopic_indirection_name (x, /*stub_p=*/true);
14525 #endif
14526           assemble_name (file, name);
14527         }
14528       if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
14529           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
14530         fputs ("@PLT", file);
14531       break;
14532
14533     case LABEL_REF:
14534       x = XEXP (x, 0);
14535       /* FALLTHRU */
14536     case CODE_LABEL:
14537       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
14538       assemble_name (asm_out_file, buf);
14539       break;
14540
14541     case CONST_INT:
14542       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
14543       break;
14544
14545     case CONST:
14546       /* This used to output parentheses around the expression,
14547          but that does not work on the 386 (either ATT or BSD assembler).  */
14548       output_pic_addr_const (file, XEXP (x, 0), code);
14549       break;
14550
14551     case CONST_DOUBLE:
14552       if (GET_MODE (x) == VOIDmode)
14553         {
14554           /* We can use %d if the number is <32 bits and positive.  */
14555           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
14556             fprintf (file, "0x%lx%08lx",
14557                      (unsigned long) CONST_DOUBLE_HIGH (x),
14558                      (unsigned long) CONST_DOUBLE_LOW (x));
14559           else
14560             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
14561         }
14562       else
14563         /* We can't handle floating point constants;
14564            TARGET_PRINT_OPERAND must handle them.  */
14565         output_operand_lossage ("floating constant misused");
14566       break;
14567
14568     case PLUS:
14569       /* Some assemblers need integer constants to appear first.  */
14570       if (CONST_INT_P (XEXP (x, 0)))
14571         {
14572           output_pic_addr_const (file, XEXP (x, 0), code);
14573           putc ('+', file);
14574           output_pic_addr_const (file, XEXP (x, 1), code);
14575         }
14576       else
14577         {
14578           gcc_assert (CONST_INT_P (XEXP (x, 1)));
14579           output_pic_addr_const (file, XEXP (x, 1), code);
14580           putc ('+', file);
14581           output_pic_addr_const (file, XEXP (x, 0), code);
14582         }
14583       break;
14584
14585     case MINUS:
14586       if (!TARGET_MACHO)
14587         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
14588       output_pic_addr_const (file, XEXP (x, 0), code);
14589       putc ('-', file);
14590       output_pic_addr_const (file, XEXP (x, 1), code);
14591       if (!TARGET_MACHO)
14592         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
14593       break;
14594
14595      case UNSPEC:
14596        if (XINT (x, 1) == UNSPEC_STACK_CHECK)
14597          {
14598            bool f = i386_asm_output_addr_const_extra (file, x);
14599            gcc_assert (f);
14600            break;
14601          }
14602
14603        gcc_assert (XVECLEN (x, 0) == 1);
14604        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
14605        switch (XINT (x, 1))
14606         {
14607         case UNSPEC_GOT:
14608           fputs ("@GOT", file);
14609           break;
14610         case UNSPEC_GOTOFF:
14611           fputs ("@GOTOFF", file);
14612           break;
14613         case UNSPEC_PLTOFF:
14614           fputs ("@PLTOFF", file);
14615           break;
14616         case UNSPEC_PCREL:
14617           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14618                  "(%rip)" : "[rip]", file);
14619           break;
14620         case UNSPEC_GOTPCREL:
14621           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14622                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
14623           break;
14624         case UNSPEC_GOTTPOFF:
14625           /* FIXME: This might be @TPOFF in Sun ld too.  */
14626           fputs ("@gottpoff", file);
14627           break;
14628         case UNSPEC_TPOFF:
14629           fputs ("@tpoff", file);
14630           break;
14631         case UNSPEC_NTPOFF:
14632           if (TARGET_64BIT)
14633             fputs ("@tpoff", file);
14634           else
14635             fputs ("@ntpoff", file);
14636           break;
14637         case UNSPEC_DTPOFF:
14638           fputs ("@dtpoff", file);
14639           break;
14640         case UNSPEC_GOTNTPOFF:
14641           if (TARGET_64BIT)
14642             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14643                    "@gottpoff(%rip)": "@gottpoff[rip]", file);
14644           else
14645             fputs ("@gotntpoff", file);
14646           break;
14647         case UNSPEC_INDNTPOFF:
14648           fputs ("@indntpoff", file);
14649           break;
14650 #if TARGET_MACHO
14651         case UNSPEC_MACHOPIC_OFFSET:
14652           putc ('-', file);
14653           machopic_output_function_base_name (file);
14654           break;
14655 #endif
14656         default:
14657           output_operand_lossage ("invalid UNSPEC as operand");
14658           break;
14659         }
14660        break;
14661
14662     default:
14663       output_operand_lossage ("invalid expression as operand");
14664     }
14665 }
14666
14667 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
14668    We need to emit DTP-relative relocations.  */
14669
14670 static void ATTRIBUTE_UNUSED
14671 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
14672 {
14673   fputs (ASM_LONG, file);
14674   output_addr_const (file, x);
14675   fputs ("@dtpoff", file);
14676   switch (size)
14677     {
14678     case 4:
14679       break;
14680     case 8:
14681       fputs (", 0", file);
14682       break;
14683     default:
14684       gcc_unreachable ();
14685    }
14686 }
14687
14688 /* Return true if X is a representation of the PIC register.  This copes
14689    with calls from ix86_find_base_term, where the register might have
14690    been replaced by a cselib value.  */
14691
14692 static bool
14693 ix86_pic_register_p (rtx x)
14694 {
14695   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
14696     return (pic_offset_table_rtx
14697             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
14698   else if (!REG_P (x))
14699     return false;
14700   else if (pic_offset_table_rtx)
14701     {
14702       if (REGNO (x) == REGNO (pic_offset_table_rtx))
14703         return true;
14704       if (HARD_REGISTER_P (x)
14705           && !HARD_REGISTER_P (pic_offset_table_rtx)
14706           && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
14707         return true;
14708       return false;
14709     }
14710   else
14711     return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
14712 }
14713
14714 /* Helper function for ix86_delegitimize_address.
14715    Attempt to delegitimize TLS local-exec accesses.  */
14716
14717 static rtx
14718 ix86_delegitimize_tls_address (rtx orig_x)
14719 {
14720   rtx x = orig_x, unspec;
14721   struct ix86_address addr;
14722
14723   if (!TARGET_TLS_DIRECT_SEG_REFS)
14724     return orig_x;
14725   if (MEM_P (x))
14726     x = XEXP (x, 0);
14727   if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
14728     return orig_x;
14729   if (ix86_decompose_address (x, &addr) == 0
14730       || addr.seg != DEFAULT_TLS_SEG_REG
14731       || addr.disp == NULL_RTX
14732       || GET_CODE (addr.disp) != CONST)
14733     return orig_x;
14734   unspec = XEXP (addr.disp, 0);
14735   if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
14736     unspec = XEXP (unspec, 0);
14737   if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF)
14738     return orig_x;
14739   x = XVECEXP (unspec, 0, 0);
14740   gcc_assert (GET_CODE (x) == SYMBOL_REF);
14741   if (unspec != XEXP (addr.disp, 0))
14742     x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1));
14743   if (addr.index)
14744     {
14745       rtx idx = addr.index;
14746       if (addr.scale != 1)
14747         idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
14748       x = gen_rtx_PLUS (Pmode, idx, x);
14749     }
14750   if (addr.base)
14751     x = gen_rtx_PLUS (Pmode, addr.base, x);
14752   if (MEM_P (orig_x))
14753     x = replace_equiv_address_nv (orig_x, x);
14754   return x;
14755 }
14756
14757 /* In the name of slightly smaller debug output, and to cater to
14758    general assembler lossage, recognize PIC+GOTOFF and turn it back
14759    into a direct symbol reference.
14760
14761    On Darwin, this is necessary to avoid a crash, because Darwin
14762    has a different PIC label for each routine but the DWARF debugging
14763    information is not associated with any particular routine, so it's
14764    necessary to remove references to the PIC label from RTL stored by
14765    the DWARF output code.  */
14766
14767 static rtx
14768 ix86_delegitimize_address (rtx x)
14769 {
14770   rtx orig_x = delegitimize_mem_from_attrs (x);
14771   /* addend is NULL or some rtx if x is something+GOTOFF where
14772      something doesn't include the PIC register.  */
14773   rtx addend = NULL_RTX;
14774   /* reg_addend is NULL or a multiple of some register.  */
14775   rtx reg_addend = NULL_RTX;
14776   /* const_addend is NULL or a const_int.  */
14777   rtx const_addend = NULL_RTX;
14778   /* This is the result, or NULL.  */
14779   rtx result = NULL_RTX;
14780
14781   x = orig_x;
14782
14783   if (MEM_P (x))
14784     x = XEXP (x, 0);
14785
14786   if (TARGET_64BIT)
14787     {
14788       if (GET_CODE (x) == CONST
14789           && GET_CODE (XEXP (x, 0)) == PLUS
14790           && GET_MODE (XEXP (x, 0)) == Pmode
14791           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
14792           && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC
14793           && XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL)
14794         {
14795           rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0);
14796           x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2);
14797           if (MEM_P (orig_x))
14798             x = replace_equiv_address_nv (orig_x, x);
14799           return x;
14800         }
14801
14802       if (GET_CODE (x) == CONST
14803           && GET_CODE (XEXP (x, 0)) == UNSPEC
14804           && (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL
14805               || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)
14806           && (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL))
14807         {
14808           x = XVECEXP (XEXP (x, 0), 0, 0);
14809           if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x))
14810             {
14811               x = simplify_gen_subreg (GET_MODE (orig_x), x,
14812                                        GET_MODE (x), 0);
14813               if (x == NULL_RTX)
14814                 return orig_x;
14815             }
14816           return x;
14817         }
14818
14819       if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC)
14820         return ix86_delegitimize_tls_address (orig_x);
14821
14822       /* Fall thru into the code shared with -m32 for -mcmodel=large -fpic
14823          and -mcmodel=medium -fpic.  */
14824     }
14825
14826   if (GET_CODE (x) != PLUS
14827       || GET_CODE (XEXP (x, 1)) != CONST)
14828     return ix86_delegitimize_tls_address (orig_x);
14829
14830   if (ix86_pic_register_p (XEXP (x, 0)))
14831     /* %ebx + GOT/GOTOFF */
14832     ;
14833   else if (GET_CODE (XEXP (x, 0)) == PLUS)
14834     {
14835       /* %ebx + %reg * scale + GOT/GOTOFF */
14836       reg_addend = XEXP (x, 0);
14837       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
14838         reg_addend = XEXP (reg_addend, 1);
14839       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
14840         reg_addend = XEXP (reg_addend, 0);
14841       else
14842         {
14843           reg_addend = NULL_RTX;
14844           addend = XEXP (x, 0);
14845         }
14846     }
14847   else
14848     addend = XEXP (x, 0);
14849
14850   x = XEXP (XEXP (x, 1), 0);
14851   if (GET_CODE (x) == PLUS
14852       && CONST_INT_P (XEXP (x, 1)))
14853     {
14854       const_addend = XEXP (x, 1);
14855       x = XEXP (x, 0);
14856     }
14857
14858   if (GET_CODE (x) == UNSPEC
14859       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend)
14860           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))
14861           || (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC
14862               && !MEM_P (orig_x) && !addend)))
14863     result = XVECEXP (x, 0, 0);
14864
14865   if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x)
14866       && !MEM_P (orig_x))
14867     result = XVECEXP (x, 0, 0);
14868
14869   if (! result)
14870     return ix86_delegitimize_tls_address (orig_x);
14871
14872   if (const_addend)
14873     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
14874   if (reg_addend)
14875     result = gen_rtx_PLUS (Pmode, reg_addend, result);
14876   if (addend)
14877     {
14878       /* If the rest of original X doesn't involve the PIC register, add
14879          addend and subtract pic_offset_table_rtx.  This can happen e.g.
14880          for code like:
14881          leal (%ebx, %ecx, 4), %ecx
14882          ...
14883          movl foo@GOTOFF(%ecx), %edx
14884          in which case we return (%ecx - %ebx) + foo
14885          or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
14886          and reload has completed.  */
14887       if (pic_offset_table_rtx
14888           && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
14889         result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
14890                                                      pic_offset_table_rtx),
14891                                result);
14892       else if (pic_offset_table_rtx && !TARGET_MACHO && !TARGET_VXWORKS_RTP)
14893         {
14894           rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
14895           tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
14896           result = gen_rtx_PLUS (Pmode, tmp, result);
14897         }
14898       else
14899         return orig_x;
14900     }
14901   if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x))
14902     {
14903       result = simplify_gen_subreg (GET_MODE (orig_x), result, Pmode, 0);
14904       if (result == NULL_RTX)
14905         return orig_x;
14906     }
14907   return result;
14908 }
14909
14910 /* If X is a machine specific address (i.e. a symbol or label being
14911    referenced as a displacement from the GOT implemented using an
14912    UNSPEC), then return the base term.  Otherwise return X.  */
14913
14914 rtx
14915 ix86_find_base_term (rtx x)
14916 {
14917   rtx term;
14918
14919   if (TARGET_64BIT)
14920     {
14921       if (GET_CODE (x) != CONST)
14922         return x;
14923       term = XEXP (x, 0);
14924       if (GET_CODE (term) == PLUS
14925           && (CONST_INT_P (XEXP (term, 1))
14926               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
14927         term = XEXP (term, 0);
14928       if (GET_CODE (term) != UNSPEC
14929           || (XINT (term, 1) != UNSPEC_GOTPCREL
14930               && XINT (term, 1) != UNSPEC_PCREL))
14931         return x;
14932
14933       return XVECEXP (term, 0, 0);
14934     }
14935
14936   return ix86_delegitimize_address (x);
14937 }
14938 \f
14939 static void
14940 put_condition_code (enum rtx_code code, machine_mode mode, bool reverse,
14941                     bool fp, FILE *file)
14942 {
14943   const char *suffix;
14944
14945   if (mode == CCFPmode || mode == CCFPUmode)
14946     {
14947       code = ix86_fp_compare_code_to_integer (code);
14948       mode = CCmode;
14949     }
14950   if (reverse)
14951     code = reverse_condition (code);
14952
14953   switch (code)
14954     {
14955     case EQ:
14956       switch (mode)
14957         {
14958         case CCAmode:
14959           suffix = "a";
14960           break;
14961
14962         case CCCmode:
14963           suffix = "c";
14964           break;
14965
14966         case CCOmode:
14967           suffix = "o";
14968           break;
14969
14970         case CCSmode:
14971           suffix = "s";
14972           break;
14973
14974         default:
14975           suffix = "e";
14976         }
14977       break;
14978     case NE:
14979       switch (mode)
14980         {
14981         case CCAmode:
14982           suffix = "na";
14983           break;
14984
14985         case CCCmode:
14986           suffix = "nc";
14987           break;
14988
14989         case CCOmode:
14990           suffix = "no";
14991           break;
14992
14993         case CCSmode:
14994           suffix = "ns";
14995           break;
14996
14997         default:
14998           suffix = "ne";
14999         }
15000       break;
15001     case GT:
15002       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
15003       suffix = "g";
15004       break;
15005     case GTU:
15006       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
15007          Those same assemblers have the same but opposite lossage on cmov.  */
15008       if (mode == CCmode)
15009         suffix = fp ? "nbe" : "a";
15010       else
15011         gcc_unreachable ();
15012       break;
15013     case LT:
15014       switch (mode)
15015         {
15016         case CCNOmode:
15017         case CCGOCmode:
15018           suffix = "s";
15019           break;
15020
15021         case CCmode:
15022         case CCGCmode:
15023           suffix = "l";
15024           break;
15025
15026         default:
15027           gcc_unreachable ();
15028         }
15029       break;
15030     case LTU:
15031       if (mode == CCmode)
15032         suffix = "b";
15033       else if (mode == CCCmode)
15034         suffix = fp ? "b" : "c";
15035       else
15036         gcc_unreachable ();
15037       break;
15038     case GE:
15039       switch (mode)
15040         {
15041         case CCNOmode:
15042         case CCGOCmode:
15043           suffix = "ns";
15044           break;
15045
15046         case CCmode:
15047         case CCGCmode:
15048           suffix = "ge";
15049           break;
15050
15051         default:
15052           gcc_unreachable ();
15053         }
15054       break;
15055     case GEU:
15056       if (mode == CCmode)
15057         suffix = "nb";
15058       else if (mode == CCCmode)
15059         suffix = fp ? "nb" : "nc";
15060       else
15061         gcc_unreachable ();
15062       break;
15063     case LE:
15064       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
15065       suffix = "le";
15066       break;
15067     case LEU:
15068       if (mode == CCmode)
15069         suffix = "be";
15070       else
15071         gcc_unreachable ();
15072       break;
15073     case UNORDERED:
15074       suffix = fp ? "u" : "p";
15075       break;
15076     case ORDERED:
15077       suffix = fp ? "nu" : "np";
15078       break;
15079     default:
15080       gcc_unreachable ();
15081     }
15082   fputs (suffix, file);
15083 }
15084
15085 /* Print the name of register X to FILE based on its machine mode and number.
15086    If CODE is 'w', pretend the mode is HImode.
15087    If CODE is 'b', pretend the mode is QImode.
15088    If CODE is 'k', pretend the mode is SImode.
15089    If CODE is 'q', pretend the mode is DImode.
15090    If CODE is 'x', pretend the mode is V4SFmode.
15091    If CODE is 't', pretend the mode is V8SFmode.
15092    If CODE is 'g', pretend the mode is V16SFmode.
15093    If CODE is 'h', pretend the reg is the 'high' byte register.
15094    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
15095    If CODE is 'd', duplicate the operand for AVX instruction.
15096  */
15097
15098 void
15099 print_reg (rtx x, int code, FILE *file)
15100 {
15101   const char *reg;
15102   unsigned int regno;
15103   bool duplicated = code == 'd' && TARGET_AVX;
15104
15105   if (ASSEMBLER_DIALECT == ASM_ATT)
15106     putc ('%', file);
15107
15108   if (x == pc_rtx)
15109     {
15110       gcc_assert (TARGET_64BIT);
15111       fputs ("rip", file);
15112       return;
15113     }
15114
15115   regno = true_regnum (x);
15116   gcc_assert (regno != ARG_POINTER_REGNUM
15117               && regno != FRAME_POINTER_REGNUM
15118               && regno != FLAGS_REG
15119               && regno != FPSR_REG
15120               && regno != FPCR_REG);
15121
15122   if (code == 'w' || MMX_REG_P (x))
15123     code = 2;
15124   else if (code == 'b')
15125     code = 1;
15126   else if (code == 'k')
15127     code = 4;
15128   else if (code == 'q')
15129     code = 8;
15130   else if (code == 'y')
15131     code = 3;
15132   else if (code == 'h')
15133     code = 0;
15134   else if (code == 'x')
15135     code = 16;
15136   else if (code == 't')
15137     code = 32;
15138   else if (code == 'g')
15139     code = 64;
15140   else
15141     code = GET_MODE_SIZE (GET_MODE (x));
15142
15143   /* Irritatingly, AMD extended registers use different naming convention
15144      from the normal registers: "r%d[bwd]"  */
15145   if (REX_INT_REGNO_P (regno))
15146     {
15147       gcc_assert (TARGET_64BIT);
15148       putc ('r', file);
15149       fprint_ul (file, regno - FIRST_REX_INT_REG + 8);
15150       switch (code)
15151         {
15152           case 0:
15153             error ("extended registers have no high halves");
15154             break;
15155           case 1:
15156             putc ('b', file);
15157             break;
15158           case 2:
15159             putc ('w', file);
15160             break;
15161           case 4:
15162             putc ('d', file);
15163             break;
15164           case 8:
15165             /* no suffix */
15166             break;
15167           default:
15168             error ("unsupported operand size for extended register");
15169             break;
15170         }
15171       return;
15172     }
15173
15174   reg = NULL;
15175   switch (code)
15176     {
15177     case 3:
15178       if (STACK_TOP_P (x))
15179         {
15180           reg = "st(0)";
15181           break;
15182         }
15183       /* FALLTHRU */
15184     case 8:
15185     case 4:
15186     case 12:
15187       if (! ANY_FP_REG_P (x) && ! ANY_MASK_REG_P (x) && ! ANY_BND_REG_P (x))
15188         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
15189       /* FALLTHRU */
15190     case 16:
15191     case 2:
15192     normal:
15193       reg = hi_reg_name[regno];
15194       break;
15195     case 1:
15196       if (regno >= ARRAY_SIZE (qi_reg_name))
15197         goto normal;
15198       reg = qi_reg_name[regno];
15199       break;
15200     case 0:
15201       if (regno >= ARRAY_SIZE (qi_high_reg_name))
15202         goto normal;
15203       reg = qi_high_reg_name[regno];
15204       break;
15205     case 32:
15206       if (SSE_REG_P (x))
15207         {
15208           gcc_assert (!duplicated);
15209           putc ('y', file);
15210           fputs (hi_reg_name[regno] + 1, file);
15211           return;
15212         }
15213     case 64:
15214       if (SSE_REG_P (x))
15215         {
15216           gcc_assert (!duplicated);
15217           putc ('z', file);
15218           fputs (hi_reg_name[REGNO (x)] + 1, file);
15219           return;
15220         }
15221       break;
15222     default:
15223       gcc_unreachable ();
15224     }
15225
15226   fputs (reg, file);
15227   if (duplicated)
15228     {
15229       if (ASSEMBLER_DIALECT == ASM_ATT)
15230         fprintf (file, ", %%%s", reg);
15231       else
15232         fprintf (file, ", %s", reg);
15233     }
15234 }
15235
15236 /* Meaning of CODE:
15237    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
15238    C -- print opcode suffix for set/cmov insn.
15239    c -- like C, but print reversed condition
15240    F,f -- likewise, but for floating-point.
15241    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
15242         otherwise nothing
15243    R -- print embeded rounding and sae.
15244    r -- print only sae.
15245    z -- print the opcode suffix for the size of the current operand.
15246    Z -- likewise, with special suffixes for x87 instructions.
15247    * -- print a star (in certain assembler syntax)
15248    A -- print an absolute memory reference.
15249    E -- print address with DImode register names if TARGET_64BIT.
15250    w -- print the operand as if it's a "word" (HImode) even if it isn't.
15251    s -- print a shift double count, followed by the assemblers argument
15252         delimiter.
15253    b -- print the QImode name of the register for the indicated operand.
15254         %b0 would print %al if operands[0] is reg 0.
15255    w --  likewise, print the HImode name of the register.
15256    k --  likewise, print the SImode name of the register.
15257    q --  likewise, print the DImode name of the register.
15258    x --  likewise, print the V4SFmode name of the register.
15259    t --  likewise, print the V8SFmode name of the register.
15260    g --  likewise, print the V16SFmode name of the register.
15261    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
15262    y -- print "st(0)" instead of "st" as a register.
15263    d -- print duplicated register operand for AVX instruction.
15264    D -- print condition for SSE cmp instruction.
15265    P -- if PIC, print an @PLT suffix.
15266    p -- print raw symbol name.
15267    X -- don't print any sort of PIC '@' suffix for a symbol.
15268    & -- print some in-use local-dynamic symbol name.
15269    H -- print a memory address offset by 8; used for sse high-parts
15270    Y -- print condition for XOP pcom* instruction.
15271    + -- print a branch hint as 'cs' or 'ds' prefix
15272    ; -- print a semicolon (after prefixes due to bug in older gas).
15273    ~ -- print "i" if TARGET_AVX2, "f" otherwise.
15274    @ -- print a segment register of thread base pointer load
15275    ^ -- print addr32 prefix if TARGET_64BIT and Pmode != word_mode
15276    ! -- print MPX prefix for jxx/call/ret instructions if required.
15277  */
15278
15279 void
15280 ix86_print_operand (FILE *file, rtx x, int code)
15281 {
15282   if (code)
15283     {
15284       switch (code)
15285         {
15286         case 'A':
15287           switch (ASSEMBLER_DIALECT)
15288             {
15289             case ASM_ATT:
15290               putc ('*', file);
15291               break;
15292
15293             case ASM_INTEL:
15294               /* Intel syntax. For absolute addresses, registers should not
15295                  be surrounded by braces.  */
15296               if (!REG_P (x))
15297                 {
15298                   putc ('[', file);
15299                   ix86_print_operand (file, x, 0);
15300                   putc (']', file);
15301                   return;
15302                 }
15303               break;
15304
15305             default:
15306               gcc_unreachable ();
15307             }
15308
15309           ix86_print_operand (file, x, 0);
15310           return;
15311
15312         case 'E':
15313           /* Wrap address in an UNSPEC to declare special handling.  */
15314           if (TARGET_64BIT)
15315             x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR);
15316
15317           output_address (x);
15318           return;
15319
15320         case 'L':
15321           if (ASSEMBLER_DIALECT == ASM_ATT)
15322             putc ('l', file);
15323           return;
15324
15325         case 'W':
15326           if (ASSEMBLER_DIALECT == ASM_ATT)
15327             putc ('w', file);
15328           return;
15329
15330         case 'B':
15331           if (ASSEMBLER_DIALECT == ASM_ATT)
15332             putc ('b', file);
15333           return;
15334
15335         case 'Q':
15336           if (ASSEMBLER_DIALECT == ASM_ATT)
15337             putc ('l', file);
15338           return;
15339
15340         case 'S':
15341           if (ASSEMBLER_DIALECT == ASM_ATT)
15342             putc ('s', file);
15343           return;
15344
15345         case 'T':
15346           if (ASSEMBLER_DIALECT == ASM_ATT)
15347             putc ('t', file);
15348           return;
15349
15350         case 'O':
15351 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
15352           if (ASSEMBLER_DIALECT != ASM_ATT)
15353             return;
15354
15355           switch (GET_MODE_SIZE (GET_MODE (x)))
15356             {
15357             case 2:
15358               putc ('w', file);
15359               break;
15360   
15361             case 4:
15362               putc ('l', file);
15363               break;
15364
15365             case 8:
15366               putc ('q', file);
15367               break;
15368
15369             default:
15370               output_operand_lossage
15371                 ("invalid operand size for operand code 'O'");
15372               return;
15373             }
15374
15375           putc ('.', file);
15376 #endif
15377           return;
15378
15379         case 'z':
15380           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
15381             {
15382               /* Opcodes don't get size suffixes if using Intel opcodes.  */
15383               if (ASSEMBLER_DIALECT == ASM_INTEL)
15384                 return;
15385
15386               switch (GET_MODE_SIZE (GET_MODE (x)))
15387                 {
15388                 case 1:
15389                   putc ('b', file);
15390                   return;
15391
15392                 case 2:
15393                   putc ('w', file);
15394                   return;
15395
15396                 case 4:
15397                   putc ('l', file);
15398                   return;
15399
15400                 case 8:
15401                   putc ('q', file);
15402                   return;
15403
15404                 default:
15405                   output_operand_lossage
15406                     ("invalid operand size for operand code 'z'");
15407                   return;
15408                 }
15409             }
15410
15411           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
15412             warning
15413               (0, "non-integer operand used with operand code 'z'");
15414           /* FALLTHRU */
15415
15416         case 'Z':
15417           /* 387 opcodes don't get size suffixes if using Intel opcodes.  */
15418           if (ASSEMBLER_DIALECT == ASM_INTEL)
15419             return;
15420
15421           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
15422             {
15423               switch (GET_MODE_SIZE (GET_MODE (x)))
15424                 {
15425                 case 2:
15426 #ifdef HAVE_AS_IX86_FILDS
15427                   putc ('s', file);
15428 #endif
15429                   return;
15430
15431                 case 4:
15432                   putc ('l', file);
15433                   return;
15434
15435                 case 8:
15436 #ifdef HAVE_AS_IX86_FILDQ
15437                   putc ('q', file);
15438 #else
15439                   fputs ("ll", file);
15440 #endif
15441                   return;
15442
15443                 default:
15444                   break;
15445                 }
15446             }
15447           else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
15448             {
15449               /* 387 opcodes don't get size suffixes
15450                  if the operands are registers.  */
15451               if (STACK_REG_P (x))
15452                 return;
15453
15454               switch (GET_MODE_SIZE (GET_MODE (x)))
15455                 {
15456                 case 4:
15457                   putc ('s', file);
15458                   return;
15459
15460                 case 8:
15461                   putc ('l', file);
15462                   return;
15463
15464                 case 12:
15465                 case 16:
15466                   putc ('t', file);
15467                   return;
15468
15469                 default:
15470                   break;
15471                 }
15472             }
15473           else
15474             {
15475               output_operand_lossage
15476                 ("invalid operand type used with operand code 'Z'");
15477               return;
15478             }
15479
15480           output_operand_lossage
15481             ("invalid operand size for operand code 'Z'");
15482           return;
15483
15484         case 'd':
15485         case 'b':
15486         case 'w':
15487         case 'k':
15488         case 'q':
15489         case 'h':
15490         case 't':
15491         case 'g':
15492         case 'y':
15493         case 'x':
15494         case 'X':
15495         case 'P':
15496         case 'p':
15497           break;
15498
15499         case 's':
15500           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
15501             {
15502               ix86_print_operand (file, x, 0);
15503               fputs (", ", file);
15504             }
15505           return;
15506
15507         case 'Y':
15508           switch (GET_CODE (x))
15509             {
15510             case NE:
15511               fputs ("neq", file);
15512               break;
15513             case EQ:
15514               fputs ("eq", file);
15515               break;
15516             case GE:
15517             case GEU:
15518               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
15519               break;
15520             case GT:
15521             case GTU:
15522               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
15523               break;
15524             case LE:
15525             case LEU:
15526               fputs ("le", file);
15527               break;
15528             case LT:
15529             case LTU:
15530               fputs ("lt", file);
15531               break;
15532             case UNORDERED:
15533               fputs ("unord", file);
15534               break;
15535             case ORDERED:
15536               fputs ("ord", file);
15537               break;
15538             case UNEQ:
15539               fputs ("ueq", file);
15540               break;
15541             case UNGE:
15542               fputs ("nlt", file);
15543               break;
15544             case UNGT:
15545               fputs ("nle", file);
15546               break;
15547             case UNLE:
15548               fputs ("ule", file);
15549               break;
15550             case UNLT:
15551               fputs ("ult", file);
15552               break;
15553             case LTGT:
15554               fputs ("une", file);
15555               break;
15556             default:
15557               output_operand_lossage ("operand is not a condition code, "
15558                                       "invalid operand code 'Y'");
15559               return;
15560             }
15561           return;
15562
15563         case 'D':
15564           /* Little bit of braindamage here.  The SSE compare instructions
15565              does use completely different names for the comparisons that the
15566              fp conditional moves.  */
15567           switch (GET_CODE (x))
15568             {
15569             case UNEQ:
15570               if (TARGET_AVX)
15571                 {
15572                   fputs ("eq_us", file);
15573                   break;
15574                 }
15575             case EQ:
15576               fputs ("eq", file);
15577               break;
15578             case UNLT:
15579               if (TARGET_AVX)
15580                 {
15581                   fputs ("nge", file);
15582                   break;
15583                 }
15584             case LT:
15585               fputs ("lt", file);
15586               break;
15587             case UNLE:
15588               if (TARGET_AVX)
15589                 {
15590                   fputs ("ngt", file);
15591                   break;
15592                 }
15593             case LE:
15594               fputs ("le", file);
15595               break;
15596             case UNORDERED:
15597               fputs ("unord", file);
15598               break;
15599             case LTGT:
15600               if (TARGET_AVX)
15601                 {
15602                   fputs ("neq_oq", file);
15603                   break;
15604                 }
15605             case NE:
15606               fputs ("neq", file);
15607               break;
15608             case GE:
15609               if (TARGET_AVX)
15610                 {
15611                   fputs ("ge", file);
15612                   break;
15613                 }
15614             case UNGE:
15615               fputs ("nlt", file);
15616               break;
15617             case GT:
15618               if (TARGET_AVX)
15619                 {
15620                   fputs ("gt", file);
15621                   break;
15622                 }
15623             case UNGT:
15624               fputs ("nle", file);
15625               break;
15626             case ORDERED:
15627               fputs ("ord", file);
15628               break;
15629             default:
15630               output_operand_lossage ("operand is not a condition code, "
15631                                       "invalid operand code 'D'");
15632               return;
15633             }
15634           return;
15635
15636         case 'F':
15637         case 'f':
15638 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
15639           if (ASSEMBLER_DIALECT == ASM_ATT)
15640             putc ('.', file);
15641 #endif
15642
15643         case 'C':
15644         case 'c':
15645           if (!COMPARISON_P (x))
15646             {
15647               output_operand_lossage ("operand is not a condition code, "
15648                                       "invalid operand code '%c'", code);
15649               return;
15650             }
15651           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
15652                               code == 'c' || code == 'f',
15653                               code == 'F' || code == 'f',
15654                               file);
15655           return;
15656
15657         case 'H':
15658           if (!offsettable_memref_p (x))
15659             {
15660               output_operand_lossage ("operand is not an offsettable memory "
15661                                       "reference, invalid operand code 'H'");
15662               return;
15663             }
15664           /* It doesn't actually matter what mode we use here, as we're
15665              only going to use this for printing.  */
15666           x = adjust_address_nv (x, DImode, 8);
15667           /* Output 'qword ptr' for intel assembler dialect.  */
15668           if (ASSEMBLER_DIALECT == ASM_INTEL)
15669             code = 'q';
15670           break;
15671
15672         case 'K':
15673           gcc_assert (CONST_INT_P (x));
15674
15675           if (INTVAL (x) & IX86_HLE_ACQUIRE)
15676 #ifdef HAVE_AS_IX86_HLE
15677             fputs ("xacquire ", file);
15678 #else
15679             fputs ("\n" ASM_BYTE "0xf2\n\t", file);
15680 #endif
15681           else if (INTVAL (x) & IX86_HLE_RELEASE)
15682 #ifdef HAVE_AS_IX86_HLE
15683             fputs ("xrelease ", file);
15684 #else
15685             fputs ("\n" ASM_BYTE "0xf3\n\t", file);
15686 #endif
15687           /* We do not want to print value of the operand.  */
15688           return;
15689
15690         case 'N':
15691           if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
15692             fputs ("{z}", file);
15693           return;
15694
15695         case 'r':
15696           gcc_assert (CONST_INT_P (x));
15697           gcc_assert (INTVAL (x) == ROUND_SAE);
15698
15699           if (ASSEMBLER_DIALECT == ASM_INTEL)
15700             fputs (", ", file);
15701
15702           fputs ("{sae}", file);
15703
15704           if (ASSEMBLER_DIALECT == ASM_ATT)
15705             fputs (", ", file);
15706
15707           return;
15708
15709         case 'R':
15710           gcc_assert (CONST_INT_P (x));
15711
15712           if (ASSEMBLER_DIALECT == ASM_INTEL)
15713             fputs (", ", file);
15714
15715           switch (INTVAL (x))
15716             {
15717             case ROUND_NEAREST_INT | ROUND_SAE:
15718               fputs ("{rn-sae}", file);
15719               break;
15720             case ROUND_NEG_INF | ROUND_SAE:
15721               fputs ("{rd-sae}", file);
15722               break;
15723             case ROUND_POS_INF | ROUND_SAE:
15724               fputs ("{ru-sae}", file);
15725               break;
15726             case ROUND_ZERO | ROUND_SAE:
15727               fputs ("{rz-sae}", file);
15728               break;
15729             default:
15730               gcc_unreachable ();
15731             }
15732
15733           if (ASSEMBLER_DIALECT == ASM_ATT)
15734             fputs (", ", file);
15735
15736           return;
15737
15738         case '*':
15739           if (ASSEMBLER_DIALECT == ASM_ATT)
15740             putc ('*', file);
15741           return;
15742
15743         case '&':
15744           {
15745             const char *name = get_some_local_dynamic_name ();
15746             if (name == NULL)
15747               output_operand_lossage ("'%%&' used without any "
15748                                       "local dynamic TLS references");
15749             else
15750               assemble_name (file, name);
15751             return;
15752           }
15753
15754         case '+':
15755           {
15756             rtx x;
15757
15758             if (!optimize
15759                 || optimize_function_for_size_p (cfun)
15760                 || !TARGET_BRANCH_PREDICTION_HINTS)
15761               return;
15762
15763             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
15764             if (x)
15765               {
15766                 int pred_val = XINT (x, 0);
15767
15768                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
15769                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
15770                   {
15771                     bool taken = pred_val > REG_BR_PROB_BASE / 2;
15772                     bool cputaken
15773                       = final_forward_branch_p (current_output_insn) == 0;
15774
15775                     /* Emit hints only in the case default branch prediction
15776                        heuristics would fail.  */
15777                     if (taken != cputaken)
15778                       {
15779                         /* We use 3e (DS) prefix for taken branches and
15780                            2e (CS) prefix for not taken branches.  */
15781                         if (taken)
15782                           fputs ("ds ; ", file);
15783                         else
15784                           fputs ("cs ; ", file);
15785                       }
15786                   }
15787               }
15788             return;
15789           }
15790
15791         case ';':
15792 #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
15793           putc (';', file);
15794 #endif
15795           return;
15796
15797         case '@':
15798           if (ASSEMBLER_DIALECT == ASM_ATT)
15799             putc ('%', file);
15800
15801           /* The kernel uses a different segment register for performance
15802              reasons; a system call would not have to trash the userspace
15803              segment register, which would be expensive.  */
15804           if (TARGET_64BIT && ix86_cmodel != CM_KERNEL)
15805             fputs ("fs", file);
15806           else
15807             fputs ("gs", file);
15808           return;
15809
15810         case '~':
15811           putc (TARGET_AVX2 ? 'i' : 'f', file);
15812           return;
15813
15814         case '^':
15815           if (TARGET_64BIT && Pmode != word_mode)
15816             fputs ("addr32 ", file);
15817           return;
15818
15819         case '!':
15820           if (ix86_bnd_prefixed_insn_p (current_output_insn))
15821             fputs ("bnd ", file);
15822           return;
15823
15824         default:
15825             output_operand_lossage ("invalid operand code '%c'", code);
15826         }
15827     }
15828
15829   if (REG_P (x))
15830     print_reg (x, code, file);
15831
15832   else if (MEM_P (x))
15833     {
15834       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
15835       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
15836           && GET_MODE (x) != BLKmode)
15837         {
15838           const char * size;
15839           switch (GET_MODE_SIZE (GET_MODE (x)))
15840             {
15841             case 1: size = "BYTE"; break;
15842             case 2: size = "WORD"; break;
15843             case 4: size = "DWORD"; break;
15844             case 8: size = "QWORD"; break;
15845             case 12: size = "TBYTE"; break;
15846             case 16:
15847               if (GET_MODE (x) == XFmode)
15848                 size = "TBYTE";
15849               else
15850                 size = "XMMWORD";
15851               break;
15852             case 32: size = "YMMWORD"; break;
15853             case 64: size = "ZMMWORD"; break;
15854             default:
15855               gcc_unreachable ();
15856             }
15857
15858           /* Check for explicit size override (codes 'b', 'w', 'k',
15859              'q' and 'x')  */
15860           if (code == 'b')
15861             size = "BYTE";
15862           else if (code == 'w')
15863             size = "WORD";
15864           else if (code == 'k')
15865             size = "DWORD";
15866           else if (code == 'q')
15867             size = "QWORD";
15868           else if (code == 'x')
15869             size = "XMMWORD";
15870
15871           fputs (size, file);
15872           fputs (" PTR ", file);
15873         }
15874
15875       x = XEXP (x, 0);
15876       /* Avoid (%rip) for call operands.  */
15877       if (CONSTANT_ADDRESS_P (x) && code == 'P'
15878           && !CONST_INT_P (x))
15879         output_addr_const (file, x);
15880       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
15881         output_operand_lossage ("invalid constraints for operand");
15882       else
15883         output_address (x);
15884     }
15885
15886   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
15887     {
15888       REAL_VALUE_TYPE r;
15889       long l;
15890
15891       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
15892       REAL_VALUE_TO_TARGET_SINGLE (r, l);
15893
15894       if (ASSEMBLER_DIALECT == ASM_ATT)
15895         putc ('$', file);
15896       /* Sign extend 32bit SFmode immediate to 8 bytes.  */
15897       if (code == 'q')
15898         fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x",
15899                  (unsigned long long) (int) l);
15900       else
15901         fprintf (file, "0x%08x", (unsigned int) l);
15902     }
15903
15904   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
15905     {
15906       REAL_VALUE_TYPE r;
15907       long l[2];
15908
15909       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
15910       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15911
15912       if (ASSEMBLER_DIALECT == ASM_ATT)
15913         putc ('$', file);
15914       fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff);
15915     }
15916
15917   /* These float cases don't actually occur as immediate operands.  */
15918   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode)
15919     {
15920       char dstr[30];
15921
15922       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
15923       fputs (dstr, file);
15924     }
15925
15926   else
15927     {
15928       /* We have patterns that allow zero sets of memory, for instance.
15929          In 64-bit mode, we should probably support all 8-byte vectors,
15930          since we can in fact encode that into an immediate.  */
15931       if (GET_CODE (x) == CONST_VECTOR)
15932         {
15933           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
15934           x = const0_rtx;
15935         }
15936
15937       if (code != 'P' && code != 'p')
15938         {
15939           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
15940             {
15941               if (ASSEMBLER_DIALECT == ASM_ATT)
15942                 putc ('$', file);
15943             }
15944           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
15945                    || GET_CODE (x) == LABEL_REF)
15946             {
15947               if (ASSEMBLER_DIALECT == ASM_ATT)
15948                 putc ('$', file);
15949               else
15950                 fputs ("OFFSET FLAT:", file);
15951             }
15952         }
15953       if (CONST_INT_P (x))
15954         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
15955       else if (flag_pic || MACHOPIC_INDIRECT)
15956         output_pic_addr_const (file, x, code);
15957       else
15958         output_addr_const (file, x);
15959     }
15960 }
15961
15962 static bool
15963 ix86_print_operand_punct_valid_p (unsigned char code)
15964 {
15965   return (code == '@' || code == '*' || code == '+' || code == '&'
15966           || code == ';' || code == '~' || code == '^' || code == '!');
15967 }
15968 \f
15969 /* Print a memory operand whose address is ADDR.  */
15970
15971 static void
15972 ix86_print_operand_address (FILE *file, rtx addr)
15973 {
15974   struct ix86_address parts;
15975   rtx base, index, disp;
15976   int scale;
15977   int ok;
15978   bool vsib = false;
15979   int code = 0;
15980
15981   if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR)
15982     {
15983       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
15984       gcc_assert (parts.index == NULL_RTX);
15985       parts.index = XVECEXP (addr, 0, 1);
15986       parts.scale = INTVAL (XVECEXP (addr, 0, 2));
15987       addr = XVECEXP (addr, 0, 0);
15988       vsib = true;
15989     }
15990   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR)
15991     {
15992       gcc_assert (TARGET_64BIT);
15993       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
15994       code = 'q';
15995     }
15996   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_BNDMK_ADDR)
15997     {
15998       ok = ix86_decompose_address (XVECEXP (addr, 0, 1), &parts);
15999       gcc_assert (parts.base == NULL_RTX || parts.index == NULL_RTX);
16000       if (parts.base != NULL_RTX)
16001         {
16002           parts.index = parts.base;
16003           parts.scale = 1;
16004         }
16005       parts.base = XVECEXP (addr, 0, 0);
16006       addr = XVECEXP (addr, 0, 0);
16007     }
16008   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_BNDLDX_ADDR)
16009     {
16010       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
16011       gcc_assert (parts.index == NULL_RTX);
16012       parts.index = XVECEXP (addr, 0, 1);
16013       addr = XVECEXP (addr, 0, 0);
16014     }
16015   else
16016     ok = ix86_decompose_address (addr, &parts);
16017
16018   gcc_assert (ok);
16019
16020   base = parts.base;
16021   index = parts.index;
16022   disp = parts.disp;
16023   scale = parts.scale;
16024
16025   switch (parts.seg)
16026     {
16027     case SEG_DEFAULT:
16028       break;
16029     case SEG_FS:
16030     case SEG_GS:
16031       if (ASSEMBLER_DIALECT == ASM_ATT)
16032         putc ('%', file);
16033       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
16034       break;
16035     default:
16036       gcc_unreachable ();
16037     }
16038
16039   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
16040   if (TARGET_64BIT && !base && !index)
16041     {
16042       rtx symbol = disp;
16043
16044       if (GET_CODE (disp) == CONST
16045           && GET_CODE (XEXP (disp, 0)) == PLUS
16046           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
16047         symbol = XEXP (XEXP (disp, 0), 0);
16048
16049       if (GET_CODE (symbol) == LABEL_REF
16050           || (GET_CODE (symbol) == SYMBOL_REF
16051               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
16052         base = pc_rtx;
16053     }
16054   if (!base && !index)
16055     {
16056       /* Displacement only requires special attention.  */
16057
16058       if (CONST_INT_P (disp))
16059         {
16060           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
16061             fputs ("ds:", file);
16062           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
16063         }
16064       else if (flag_pic)
16065         output_pic_addr_const (file, disp, 0);
16066       else
16067         output_addr_const (file, disp);
16068     }
16069   else
16070     {
16071       /* Print SImode register names to force addr32 prefix.  */
16072       if (SImode_address_operand (addr, VOIDmode))
16073         {
16074 #ifdef ENABLE_CHECKING
16075           gcc_assert (TARGET_64BIT);
16076           switch (GET_CODE (addr))
16077             {
16078             case SUBREG:
16079               gcc_assert (GET_MODE (addr) == SImode);
16080               gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode);
16081               break;
16082             case ZERO_EXTEND:
16083             case AND:
16084               gcc_assert (GET_MODE (addr) == DImode);
16085               break;
16086             default:
16087               gcc_unreachable ();
16088             }
16089 #endif
16090           gcc_assert (!code);
16091           code = 'k';
16092         }
16093       else if (code == 0
16094                && TARGET_X32
16095                && disp
16096                && CONST_INT_P (disp)
16097                && INTVAL (disp) < -16*1024*1024)
16098         {
16099           /* X32 runs in 64-bit mode, where displacement, DISP, in
16100              address DISP(%r64), is encoded as 32-bit immediate sign-
16101              extended from 32-bit to 64-bit.  For -0x40000300(%r64),
16102              address is %r64 + 0xffffffffbffffd00.  When %r64 <
16103              0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64,
16104              which is invalid for x32.  The correct address is %r64
16105              - 0x40000300 == 0xf7ffdd64.  To properly encode
16106              -0x40000300(%r64) for x32, we zero-extend negative
16107              displacement by forcing addr32 prefix which truncates
16108              0xfffffffff7ffdd64 to 0xf7ffdd64.  In theory, we should
16109              zero-extend all negative displacements, including -1(%rsp).
16110              However, for small negative displacements, sign-extension
16111              won't cause overflow.  We only zero-extend negative
16112              displacements if they < -16*1024*1024, which is also used
16113              to check legitimate address displacements for PIC.  */
16114           code = 'k';
16115         }
16116
16117       if (ASSEMBLER_DIALECT == ASM_ATT)
16118         {
16119           if (disp)
16120             {
16121               if (flag_pic)
16122                 output_pic_addr_const (file, disp, 0);
16123               else if (GET_CODE (disp) == LABEL_REF)
16124                 output_asm_label (disp);
16125               else
16126                 output_addr_const (file, disp);
16127             }
16128
16129           putc ('(', file);
16130           if (base)
16131             print_reg (base, code, file);
16132           if (index)
16133             {
16134               putc (',', file);
16135               print_reg (index, vsib ? 0 : code, file);
16136               if (scale != 1 || vsib)
16137                 fprintf (file, ",%d", scale);
16138             }
16139           putc (')', file);
16140         }
16141       else
16142         {
16143           rtx offset = NULL_RTX;
16144
16145           if (disp)
16146             {
16147               /* Pull out the offset of a symbol; print any symbol itself.  */
16148               if (GET_CODE (disp) == CONST
16149                   && GET_CODE (XEXP (disp, 0)) == PLUS
16150                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
16151                 {
16152                   offset = XEXP (XEXP (disp, 0), 1);
16153                   disp = gen_rtx_CONST (VOIDmode,
16154                                         XEXP (XEXP (disp, 0), 0));
16155                 }
16156
16157               if (flag_pic)
16158                 output_pic_addr_const (file, disp, 0);
16159               else if (GET_CODE (disp) == LABEL_REF)
16160                 output_asm_label (disp);
16161               else if (CONST_INT_P (disp))
16162                 offset = disp;
16163               else
16164                 output_addr_const (file, disp);
16165             }
16166
16167           putc ('[', file);
16168           if (base)
16169             {
16170               print_reg (base, code, file);
16171               if (offset)
16172                 {
16173                   if (INTVAL (offset) >= 0)
16174                     putc ('+', file);
16175                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
16176                 }
16177             }
16178           else if (offset)
16179             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
16180           else
16181             putc ('0', file);
16182
16183           if (index)
16184             {
16185               putc ('+', file);
16186               print_reg (index, vsib ? 0 : code, file);
16187               if (scale != 1 || vsib)
16188                 fprintf (file, "*%d", scale);
16189             }
16190           putc (']', file);
16191         }
16192     }
16193 }
16194
16195 /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
16196
16197 static bool
16198 i386_asm_output_addr_const_extra (FILE *file, rtx x)
16199 {
16200   rtx op;
16201
16202   if (GET_CODE (x) != UNSPEC)
16203     return false;
16204
16205   op = XVECEXP (x, 0, 0);
16206   switch (XINT (x, 1))
16207     {
16208     case UNSPEC_GOTTPOFF:
16209       output_addr_const (file, op);
16210       /* FIXME: This might be @TPOFF in Sun ld.  */
16211       fputs ("@gottpoff", file);
16212       break;
16213     case UNSPEC_TPOFF:
16214       output_addr_const (file, op);
16215       fputs ("@tpoff", file);
16216       break;
16217     case UNSPEC_NTPOFF:
16218       output_addr_const (file, op);
16219       if (TARGET_64BIT)
16220         fputs ("@tpoff", file);
16221       else
16222         fputs ("@ntpoff", file);
16223       break;
16224     case UNSPEC_DTPOFF:
16225       output_addr_const (file, op);
16226       fputs ("@dtpoff", file);
16227       break;
16228     case UNSPEC_GOTNTPOFF:
16229       output_addr_const (file, op);
16230       if (TARGET_64BIT)
16231         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
16232                "@gottpoff(%rip)" : "@gottpoff[rip]", file);
16233       else
16234         fputs ("@gotntpoff", file);
16235       break;
16236     case UNSPEC_INDNTPOFF:
16237       output_addr_const (file, op);
16238       fputs ("@indntpoff", file);
16239       break;
16240 #if TARGET_MACHO
16241     case UNSPEC_MACHOPIC_OFFSET:
16242       output_addr_const (file, op);
16243       putc ('-', file);
16244       machopic_output_function_base_name (file);
16245       break;
16246 #endif
16247
16248     case UNSPEC_STACK_CHECK:
16249       {
16250         int offset;
16251
16252         gcc_assert (flag_split_stack);
16253
16254 #ifdef TARGET_THREAD_SPLIT_STACK_OFFSET
16255         offset = TARGET_THREAD_SPLIT_STACK_OFFSET;
16256 #else
16257         gcc_unreachable ();
16258 #endif
16259
16260         fprintf (file, "%s:%d", TARGET_64BIT ? "%fs" : "%gs", offset);
16261       }
16262       break;
16263
16264     default:
16265       return false;
16266     }
16267
16268   return true;
16269 }
16270 \f
16271 /* Split one or more double-mode RTL references into pairs of half-mode
16272    references.  The RTL can be REG, offsettable MEM, integer constant, or
16273    CONST_DOUBLE.  "operands" is a pointer to an array of double-mode RTLs to
16274    split and "num" is its length.  lo_half and hi_half are output arrays
16275    that parallel "operands".  */
16276
16277 void
16278 split_double_mode (machine_mode mode, rtx operands[],
16279                    int num, rtx lo_half[], rtx hi_half[])
16280 {
16281   machine_mode half_mode;
16282   unsigned int byte;
16283
16284   switch (mode)
16285     {
16286     case TImode:
16287       half_mode = DImode;
16288       break;
16289     case DImode:
16290       half_mode = SImode;
16291       break;
16292     default:
16293       gcc_unreachable ();
16294     }
16295
16296   byte = GET_MODE_SIZE (half_mode);
16297
16298   while (num--)
16299     {
16300       rtx op = operands[num];
16301
16302       /* simplify_subreg refuse to split volatile memory addresses,
16303          but we still have to handle it.  */
16304       if (MEM_P (op))
16305         {
16306           lo_half[num] = adjust_address (op, half_mode, 0);
16307           hi_half[num] = adjust_address (op, half_mode, byte);
16308         }
16309       else
16310         {
16311           lo_half[num] = simplify_gen_subreg (half_mode, op,
16312                                               GET_MODE (op) == VOIDmode
16313                                               ? mode : GET_MODE (op), 0);
16314           hi_half[num] = simplify_gen_subreg (half_mode, op,
16315                                               GET_MODE (op) == VOIDmode
16316                                               ? mode : GET_MODE (op), byte);
16317         }
16318     }
16319 }
16320 \f
16321 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
16322    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
16323    is the expression of the binary operation.  The output may either be
16324    emitted here, or returned to the caller, like all output_* functions.
16325
16326    There is no guarantee that the operands are the same mode, as they
16327    might be within FLOAT or FLOAT_EXTEND expressions.  */
16328
16329 #ifndef SYSV386_COMPAT
16330 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
16331    wants to fix the assemblers because that causes incompatibility
16332    with gcc.  No-one wants to fix gcc because that causes
16333    incompatibility with assemblers...  You can use the option of
16334    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
16335 #define SYSV386_COMPAT 1
16336 #endif
16337
16338 const char *
16339 output_387_binary_op (rtx insn, rtx *operands)
16340 {
16341   static char buf[40];
16342   const char *p;
16343   const char *ssep;
16344   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
16345
16346 #ifdef ENABLE_CHECKING
16347   /* Even if we do not want to check the inputs, this documents input
16348      constraints.  Which helps in understanding the following code.  */
16349   if (STACK_REG_P (operands[0])
16350       && ((REG_P (operands[1])
16351            && REGNO (operands[0]) == REGNO (operands[1])
16352            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
16353           || (REG_P (operands[2])
16354               && REGNO (operands[0]) == REGNO (operands[2])
16355               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
16356       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
16357     ; /* ok */
16358   else
16359     gcc_assert (is_sse);
16360 #endif
16361
16362   switch (GET_CODE (operands[3]))
16363     {
16364     case PLUS:
16365       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16366           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16367         p = "fiadd";
16368       else
16369         p = "fadd";
16370       ssep = "vadd";
16371       break;
16372
16373     case MINUS:
16374       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16375           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16376         p = "fisub";
16377       else
16378         p = "fsub";
16379       ssep = "vsub";
16380       break;
16381
16382     case MULT:
16383       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16384           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16385         p = "fimul";
16386       else
16387         p = "fmul";
16388       ssep = "vmul";
16389       break;
16390
16391     case DIV:
16392       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16393           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16394         p = "fidiv";
16395       else
16396         p = "fdiv";
16397       ssep = "vdiv";
16398       break;
16399
16400     default:
16401       gcc_unreachable ();
16402     }
16403
16404   if (is_sse)
16405    {
16406      if (TARGET_AVX)
16407        {
16408          strcpy (buf, ssep);
16409          if (GET_MODE (operands[0]) == SFmode)
16410            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
16411          else
16412            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
16413        }
16414      else
16415        {
16416          strcpy (buf, ssep + 1);
16417          if (GET_MODE (operands[0]) == SFmode)
16418            strcat (buf, "ss\t{%2, %0|%0, %2}");
16419          else
16420            strcat (buf, "sd\t{%2, %0|%0, %2}");
16421        }
16422       return buf;
16423    }
16424   strcpy (buf, p);
16425
16426   switch (GET_CODE (operands[3]))
16427     {
16428     case MULT:
16429     case PLUS:
16430       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
16431         std::swap (operands[1], operands[2]);
16432
16433       /* know operands[0] == operands[1].  */
16434
16435       if (MEM_P (operands[2]))
16436         {
16437           p = "%Z2\t%2";
16438           break;
16439         }
16440
16441       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
16442         {
16443           if (STACK_TOP_P (operands[0]))
16444             /* How is it that we are storing to a dead operand[2]?
16445                Well, presumably operands[1] is dead too.  We can't
16446                store the result to st(0) as st(0) gets popped on this
16447                instruction.  Instead store to operands[2] (which I
16448                think has to be st(1)).  st(1) will be popped later.
16449                gcc <= 2.8.1 didn't have this check and generated
16450                assembly code that the Unixware assembler rejected.  */
16451             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
16452           else
16453             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
16454           break;
16455         }
16456
16457       if (STACK_TOP_P (operands[0]))
16458         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
16459       else
16460         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
16461       break;
16462
16463     case MINUS:
16464     case DIV:
16465       if (MEM_P (operands[1]))
16466         {
16467           p = "r%Z1\t%1";
16468           break;
16469         }
16470
16471       if (MEM_P (operands[2]))
16472         {
16473           p = "%Z2\t%2";
16474           break;
16475         }
16476
16477       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
16478         {
16479 #if SYSV386_COMPAT
16480           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
16481              derived assemblers, confusingly reverse the direction of
16482              the operation for fsub{r} and fdiv{r} when the
16483              destination register is not st(0).  The Intel assembler
16484              doesn't have this brain damage.  Read !SYSV386_COMPAT to
16485              figure out what the hardware really does.  */
16486           if (STACK_TOP_P (operands[0]))
16487             p = "{p\t%0, %2|rp\t%2, %0}";
16488           else
16489             p = "{rp\t%2, %0|p\t%0, %2}";
16490 #else
16491           if (STACK_TOP_P (operands[0]))
16492             /* As above for fmul/fadd, we can't store to st(0).  */
16493             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
16494           else
16495             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
16496 #endif
16497           break;
16498         }
16499
16500       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
16501         {
16502 #if SYSV386_COMPAT
16503           if (STACK_TOP_P (operands[0]))
16504             p = "{rp\t%0, %1|p\t%1, %0}";
16505           else
16506             p = "{p\t%1, %0|rp\t%0, %1}";
16507 #else
16508           if (STACK_TOP_P (operands[0]))
16509             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
16510           else
16511             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
16512 #endif
16513           break;
16514         }
16515
16516       if (STACK_TOP_P (operands[0]))
16517         {
16518           if (STACK_TOP_P (operands[1]))
16519             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
16520           else
16521             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
16522           break;
16523         }
16524       else if (STACK_TOP_P (operands[1]))
16525         {
16526 #if SYSV386_COMPAT
16527           p = "{\t%1, %0|r\t%0, %1}";
16528 #else
16529           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
16530 #endif
16531         }
16532       else
16533         {
16534 #if SYSV386_COMPAT
16535           p = "{r\t%2, %0|\t%0, %2}";
16536 #else
16537           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
16538 #endif
16539         }
16540       break;
16541
16542     default:
16543       gcc_unreachable ();
16544     }
16545
16546   strcat (buf, p);
16547   return buf;
16548 }
16549
16550 /* Check if a 256bit AVX register is referenced inside of EXP.   */
16551
16552 static bool
16553 ix86_check_avx256_register (const_rtx exp)
16554 {
16555   if (GET_CODE (exp) == SUBREG)
16556     exp = SUBREG_REG (exp);
16557
16558   return (REG_P (exp)
16559           && VALID_AVX256_REG_OR_OI_MODE (GET_MODE (exp)));
16560 }
16561
16562 /* Return needed mode for entity in optimize_mode_switching pass.  */
16563
16564 static int
16565 ix86_avx_u128_mode_needed (rtx_insn *insn)
16566 {
16567   if (CALL_P (insn))
16568     {
16569       rtx link;
16570
16571       /* Needed mode is set to AVX_U128_CLEAN if there are
16572          no 256bit modes used in function arguments.  */
16573       for (link = CALL_INSN_FUNCTION_USAGE (insn);
16574            link;
16575            link = XEXP (link, 1))
16576         {
16577           if (GET_CODE (XEXP (link, 0)) == USE)
16578             {
16579               rtx arg = XEXP (XEXP (link, 0), 0);
16580
16581               if (ix86_check_avx256_register (arg))
16582                 return AVX_U128_DIRTY;
16583             }
16584         }
16585
16586       return AVX_U128_CLEAN;
16587     }
16588
16589   /* Require DIRTY mode if a 256bit AVX register is referenced.  Hardware
16590      changes state only when a 256bit register is written to, but we need
16591      to prevent the compiler from moving optimal insertion point above
16592      eventual read from 256bit register.  */
16593   subrtx_iterator::array_type array;
16594   FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
16595     if (ix86_check_avx256_register (*iter))
16596       return AVX_U128_DIRTY;
16597
16598   return AVX_U128_ANY;
16599 }
16600
16601 /* Return mode that i387 must be switched into
16602    prior to the execution of insn.  */
16603
16604 static int
16605 ix86_i387_mode_needed (int entity, rtx_insn *insn)
16606 {
16607   enum attr_i387_cw mode;
16608
16609   /* The mode UNINITIALIZED is used to store control word after a
16610      function call or ASM pattern.  The mode ANY specify that function
16611      has no requirements on the control word and make no changes in the
16612      bits we are interested in.  */
16613
16614   if (CALL_P (insn)
16615       || (NONJUMP_INSN_P (insn)
16616           && (asm_noperands (PATTERN (insn)) >= 0
16617               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
16618     return I387_CW_UNINITIALIZED;
16619
16620   if (recog_memoized (insn) < 0)
16621     return I387_CW_ANY;
16622
16623   mode = get_attr_i387_cw (insn);
16624
16625   switch (entity)
16626     {
16627     case I387_TRUNC:
16628       if (mode == I387_CW_TRUNC)
16629         return mode;
16630       break;
16631
16632     case I387_FLOOR:
16633       if (mode == I387_CW_FLOOR)
16634         return mode;
16635       break;
16636
16637     case I387_CEIL:
16638       if (mode == I387_CW_CEIL)
16639         return mode;
16640       break;
16641
16642     case I387_MASK_PM:
16643       if (mode == I387_CW_MASK_PM)
16644         return mode;
16645       break;
16646
16647     default:
16648       gcc_unreachable ();
16649     }
16650
16651   return I387_CW_ANY;
16652 }
16653
16654 /* Return mode that entity must be switched into
16655    prior to the execution of insn.  */
16656
16657 static int
16658 ix86_mode_needed (int entity, rtx_insn *insn)
16659 {
16660   switch (entity)
16661     {
16662     case AVX_U128:
16663       return ix86_avx_u128_mode_needed (insn);
16664     case I387_TRUNC:
16665     case I387_FLOOR:
16666     case I387_CEIL:
16667     case I387_MASK_PM:
16668       return ix86_i387_mode_needed (entity, insn);
16669     default:
16670       gcc_unreachable ();
16671     }
16672   return 0;
16673 }
16674
16675 /* Check if a 256bit AVX register is referenced in stores.   */
16676  
16677 static void
16678 ix86_check_avx256_stores (rtx dest, const_rtx, void *data)
16679  {
16680    if (ix86_check_avx256_register (dest))
16681     {
16682       bool *used = (bool *) data;
16683       *used = true;
16684     }
16685  } 
16686
16687 /* Calculate mode of upper 128bit AVX registers after the insn.  */
16688
16689 static int
16690 ix86_avx_u128_mode_after (int mode, rtx_insn *insn)
16691 {
16692   rtx pat = PATTERN (insn);
16693
16694   if (vzeroupper_operation (pat, VOIDmode)
16695       || vzeroall_operation (pat, VOIDmode))
16696     return AVX_U128_CLEAN;
16697
16698   /* We know that state is clean after CALL insn if there are no
16699      256bit registers used in the function return register.  */
16700   if (CALL_P (insn))
16701     {
16702       bool avx_reg256_found = false;
16703       note_stores (pat, ix86_check_avx256_stores, &avx_reg256_found);
16704
16705       return avx_reg256_found ? AVX_U128_DIRTY : AVX_U128_CLEAN;
16706     }
16707
16708   /* Otherwise, return current mode.  Remember that if insn
16709      references AVX 256bit registers, the mode was already changed
16710      to DIRTY from MODE_NEEDED.  */
16711   return mode;
16712 }
16713
16714 /* Return the mode that an insn results in.  */
16715
16716 int
16717 ix86_mode_after (int entity, int mode, rtx_insn *insn)
16718 {
16719   switch (entity)
16720     {
16721     case AVX_U128:
16722       return ix86_avx_u128_mode_after (mode, insn);
16723     case I387_TRUNC:
16724     case I387_FLOOR:
16725     case I387_CEIL:
16726     case I387_MASK_PM:
16727       return mode;
16728     default:
16729       gcc_unreachable ();
16730     }
16731 }
16732
16733 static int
16734 ix86_avx_u128_mode_entry (void)
16735 {
16736   tree arg;
16737
16738   /* Entry mode is set to AVX_U128_DIRTY if there are
16739      256bit modes used in function arguments.  */
16740   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
16741        arg = TREE_CHAIN (arg))
16742     {
16743       rtx incoming = DECL_INCOMING_RTL (arg);
16744
16745       if (incoming && ix86_check_avx256_register (incoming))
16746         return AVX_U128_DIRTY;
16747     }
16748
16749   return AVX_U128_CLEAN;
16750 }
16751
16752 /* Return a mode that ENTITY is assumed to be
16753    switched to at function entry.  */
16754
16755 static int
16756 ix86_mode_entry (int entity)
16757 {
16758   switch (entity)
16759     {
16760     case AVX_U128:
16761       return ix86_avx_u128_mode_entry ();
16762     case I387_TRUNC:
16763     case I387_FLOOR:
16764     case I387_CEIL:
16765     case I387_MASK_PM:
16766       return I387_CW_ANY;
16767     default:
16768       gcc_unreachable ();
16769     }
16770 }
16771
16772 static int
16773 ix86_avx_u128_mode_exit (void)
16774 {
16775   rtx reg = crtl->return_rtx;
16776
16777   /* Exit mode is set to AVX_U128_DIRTY if there are
16778      256bit modes used in the function return register.  */
16779   if (reg && ix86_check_avx256_register (reg))
16780     return AVX_U128_DIRTY;
16781
16782   return AVX_U128_CLEAN;
16783 }
16784
16785 /* Return a mode that ENTITY is assumed to be
16786    switched to at function exit.  */
16787
16788 static int
16789 ix86_mode_exit (int entity)
16790 {
16791   switch (entity)
16792     {
16793     case AVX_U128:
16794       return ix86_avx_u128_mode_exit ();
16795     case I387_TRUNC:
16796     case I387_FLOOR:
16797     case I387_CEIL:
16798     case I387_MASK_PM:
16799       return I387_CW_ANY;
16800     default:
16801       gcc_unreachable ();
16802     }
16803 }
16804
16805 static int
16806 ix86_mode_priority (int, int n)
16807 {
16808   return n;
16809 }
16810
16811 /* Output code to initialize control word copies used by trunc?f?i and
16812    rounding patterns.  CURRENT_MODE is set to current control word,
16813    while NEW_MODE is set to new control word.  */
16814
16815 static void
16816 emit_i387_cw_initialization (int mode)
16817 {
16818   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
16819   rtx new_mode;
16820
16821   enum ix86_stack_slot slot;
16822
16823   rtx reg = gen_reg_rtx (HImode);
16824
16825   emit_insn (gen_x86_fnstcw_1 (stored_mode));
16826   emit_move_insn (reg, copy_rtx (stored_mode));
16827
16828   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
16829       || optimize_insn_for_size_p ())
16830     {
16831       switch (mode)
16832         {
16833         case I387_CW_TRUNC:
16834           /* round toward zero (truncate) */
16835           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
16836           slot = SLOT_CW_TRUNC;
16837           break;
16838
16839         case I387_CW_FLOOR:
16840           /* round down toward -oo */
16841           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
16842           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
16843           slot = SLOT_CW_FLOOR;
16844           break;
16845
16846         case I387_CW_CEIL:
16847           /* round up toward +oo */
16848           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
16849           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
16850           slot = SLOT_CW_CEIL;
16851           break;
16852
16853         case I387_CW_MASK_PM:
16854           /* mask precision exception for nearbyint() */
16855           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
16856           slot = SLOT_CW_MASK_PM;
16857           break;
16858
16859         default:
16860           gcc_unreachable ();
16861         }
16862     }
16863   else
16864     {
16865       switch (mode)
16866         {
16867         case I387_CW_TRUNC:
16868           /* round toward zero (truncate) */
16869           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
16870           slot = SLOT_CW_TRUNC;
16871           break;
16872
16873         case I387_CW_FLOOR:
16874           /* round down toward -oo */
16875           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
16876           slot = SLOT_CW_FLOOR;
16877           break;
16878
16879         case I387_CW_CEIL:
16880           /* round up toward +oo */
16881           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
16882           slot = SLOT_CW_CEIL;
16883           break;
16884
16885         case I387_CW_MASK_PM:
16886           /* mask precision exception for nearbyint() */
16887           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
16888           slot = SLOT_CW_MASK_PM;
16889           break;
16890
16891         default:
16892           gcc_unreachable ();
16893         }
16894     }
16895
16896   gcc_assert (slot < MAX_386_STACK_LOCALS);
16897
16898   new_mode = assign_386_stack_local (HImode, slot);
16899   emit_move_insn (new_mode, reg);
16900 }
16901
16902 /* Emit vzeroupper.  */
16903
16904 void
16905 ix86_avx_emit_vzeroupper (HARD_REG_SET regs_live)
16906 {
16907   int i;
16908
16909   /* Cancel automatic vzeroupper insertion if there are
16910      live call-saved SSE registers at the insertion point.  */
16911
16912   for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
16913     if (TEST_HARD_REG_BIT (regs_live, i) && !call_used_regs[i])
16914       return;
16915
16916   if (TARGET_64BIT)
16917     for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
16918       if (TEST_HARD_REG_BIT (regs_live, i) && !call_used_regs[i])
16919         return;
16920
16921   emit_insn (gen_avx_vzeroupper ());
16922 }
16923
16924 /* Generate one or more insns to set ENTITY to MODE.  */
16925
16926 /* Generate one or more insns to set ENTITY to MODE.  HARD_REG_LIVE
16927    is the set of hard registers live at the point where the insn(s)
16928    are to be inserted.  */
16929
16930 static void
16931 ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
16932                     HARD_REG_SET regs_live)
16933 {
16934   switch (entity)
16935     {
16936     case AVX_U128:
16937       if (mode == AVX_U128_CLEAN)
16938         ix86_avx_emit_vzeroupper (regs_live);
16939       break;
16940     case I387_TRUNC:
16941     case I387_FLOOR:
16942     case I387_CEIL:
16943     case I387_MASK_PM:
16944       if (mode != I387_CW_ANY
16945           && mode != I387_CW_UNINITIALIZED)
16946         emit_i387_cw_initialization (mode);
16947       break;
16948     default:
16949       gcc_unreachable ();
16950     }
16951 }
16952
16953 /* Output code for INSN to convert a float to a signed int.  OPERANDS
16954    are the insn operands.  The output may be [HSD]Imode and the input
16955    operand may be [SDX]Fmode.  */
16956
16957 const char *
16958 output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp)
16959 {
16960   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
16961   int dimode_p = GET_MODE (operands[0]) == DImode;
16962   int round_mode = get_attr_i387_cw (insn);
16963
16964   /* Jump through a hoop or two for DImode, since the hardware has no
16965      non-popping instruction.  We used to do this a different way, but
16966      that was somewhat fragile and broke with post-reload splitters.  */
16967   if ((dimode_p || fisttp) && !stack_top_dies)
16968     output_asm_insn ("fld\t%y1", operands);
16969
16970   gcc_assert (STACK_TOP_P (operands[1]));
16971   gcc_assert (MEM_P (operands[0]));
16972   gcc_assert (GET_MODE (operands[1]) != TFmode);
16973
16974   if (fisttp)
16975       output_asm_insn ("fisttp%Z0\t%0", operands);
16976   else
16977     {
16978       if (round_mode != I387_CW_ANY)
16979         output_asm_insn ("fldcw\t%3", operands);
16980       if (stack_top_dies || dimode_p)
16981         output_asm_insn ("fistp%Z0\t%0", operands);
16982       else
16983         output_asm_insn ("fist%Z0\t%0", operands);
16984       if (round_mode != I387_CW_ANY)
16985         output_asm_insn ("fldcw\t%2", operands);
16986     }
16987
16988   return "";
16989 }
16990
16991 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
16992    have the values zero or one, indicates the ffreep insn's operand
16993    from the OPERANDS array.  */
16994
16995 static const char *
16996 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
16997 {
16998   if (TARGET_USE_FFREEP)
16999 #ifdef HAVE_AS_IX86_FFREEP
17000     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
17001 #else
17002     {
17003       static char retval[32];
17004       int regno = REGNO (operands[opno]);
17005
17006       gcc_assert (STACK_REGNO_P (regno));
17007
17008       regno -= FIRST_STACK_REG;
17009
17010       snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
17011       return retval;
17012     }
17013 #endif
17014
17015   return opno ? "fstp\t%y1" : "fstp\t%y0";
17016 }
17017
17018
17019 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
17020    should be used.  UNORDERED_P is true when fucom should be used.  */
17021
17022 const char *
17023 output_fp_compare (rtx insn, rtx *operands, bool eflags_p, bool unordered_p)
17024 {
17025   int stack_top_dies;
17026   rtx cmp_op0, cmp_op1;
17027   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
17028
17029   if (eflags_p)
17030     {
17031       cmp_op0 = operands[0];
17032       cmp_op1 = operands[1];
17033     }
17034   else
17035     {
17036       cmp_op0 = operands[1];
17037       cmp_op1 = operands[2];
17038     }
17039
17040   if (is_sse)
17041     {
17042       if (GET_MODE (operands[0]) == SFmode)
17043         if (unordered_p)
17044           return "%vucomiss\t{%1, %0|%0, %1}";
17045         else
17046           return "%vcomiss\t{%1, %0|%0, %1}";
17047       else
17048         if (unordered_p)
17049           return "%vucomisd\t{%1, %0|%0, %1}";
17050         else
17051           return "%vcomisd\t{%1, %0|%0, %1}";
17052     }
17053
17054   gcc_assert (STACK_TOP_P (cmp_op0));
17055
17056   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
17057
17058   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
17059     {
17060       if (stack_top_dies)
17061         {
17062           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
17063           return output_387_ffreep (operands, 1);
17064         }
17065       else
17066         return "ftst\n\tfnstsw\t%0";
17067     }
17068
17069   if (STACK_REG_P (cmp_op1)
17070       && stack_top_dies
17071       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
17072       && REGNO (cmp_op1) != FIRST_STACK_REG)
17073     {
17074       /* If both the top of the 387 stack dies, and the other operand
17075          is also a stack register that dies, then this must be a
17076          `fcompp' float compare */
17077
17078       if (eflags_p)
17079         {
17080           /* There is no double popping fcomi variant.  Fortunately,
17081              eflags is immune from the fstp's cc clobbering.  */
17082           if (unordered_p)
17083             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
17084           else
17085             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
17086           return output_387_ffreep (operands, 0);
17087         }
17088       else
17089         {
17090           if (unordered_p)
17091             return "fucompp\n\tfnstsw\t%0";
17092           else
17093             return "fcompp\n\tfnstsw\t%0";
17094         }
17095     }
17096   else
17097     {
17098       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
17099
17100       static const char * const alt[16] =
17101       {
17102         "fcom%Z2\t%y2\n\tfnstsw\t%0",
17103         "fcomp%Z2\t%y2\n\tfnstsw\t%0",
17104         "fucom%Z2\t%y2\n\tfnstsw\t%0",
17105         "fucomp%Z2\t%y2\n\tfnstsw\t%0",
17106
17107         "ficom%Z2\t%y2\n\tfnstsw\t%0",
17108         "ficomp%Z2\t%y2\n\tfnstsw\t%0",
17109         NULL,
17110         NULL,
17111
17112         "fcomi\t{%y1, %0|%0, %y1}",
17113         "fcomip\t{%y1, %0|%0, %y1}",
17114         "fucomi\t{%y1, %0|%0, %y1}",
17115         "fucomip\t{%y1, %0|%0, %y1}",
17116
17117         NULL,
17118         NULL,
17119         NULL,
17120         NULL
17121       };
17122
17123       int mask;
17124       const char *ret;
17125
17126       mask  = eflags_p << 3;
17127       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
17128       mask |= unordered_p << 1;
17129       mask |= stack_top_dies;
17130
17131       gcc_assert (mask < 16);
17132       ret = alt[mask];
17133       gcc_assert (ret);
17134
17135       return ret;
17136     }
17137 }
17138
17139 void
17140 ix86_output_addr_vec_elt (FILE *file, int value)
17141 {
17142   const char *directive = ASM_LONG;
17143
17144 #ifdef ASM_QUAD
17145   if (TARGET_LP64)
17146     directive = ASM_QUAD;
17147 #else
17148   gcc_assert (!TARGET_64BIT);
17149 #endif
17150
17151   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
17152 }
17153
17154 void
17155 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
17156 {
17157   const char *directive = ASM_LONG;
17158
17159 #ifdef ASM_QUAD
17160   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
17161     directive = ASM_QUAD;
17162 #else
17163   gcc_assert (!TARGET_64BIT);
17164 #endif
17165   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
17166   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
17167     fprintf (file, "%s%s%d-%s%d\n",
17168              directive, LPREFIX, value, LPREFIX, rel);
17169   else if (HAVE_AS_GOTOFF_IN_DATA)
17170     fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
17171 #if TARGET_MACHO
17172   else if (TARGET_MACHO)
17173     {
17174       fprintf (file, ASM_LONG "%s%d-", LPREFIX, value);
17175       machopic_output_function_base_name (file);
17176       putc ('\n', file);
17177     }
17178 #endif
17179   else
17180     asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
17181                  GOT_SYMBOL_NAME, LPREFIX, value);
17182 }
17183 \f
17184 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
17185    for the target.  */
17186
17187 void
17188 ix86_expand_clear (rtx dest)
17189 {
17190   rtx tmp;
17191
17192   /* We play register width games, which are only valid after reload.  */
17193   gcc_assert (reload_completed);
17194
17195   /* Avoid HImode and its attendant prefix byte.  */
17196   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
17197     dest = gen_rtx_REG (SImode, REGNO (dest));
17198   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
17199
17200   if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17201     {
17202       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
17203       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
17204     }
17205
17206   emit_insn (tmp);
17207 }
17208
17209 /* X is an unchanging MEM.  If it is a constant pool reference, return
17210    the constant pool rtx, else NULL.  */
17211
17212 rtx
17213 maybe_get_pool_constant (rtx x)
17214 {
17215   x = ix86_delegitimize_address (XEXP (x, 0));
17216
17217   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
17218     return get_pool_constant (x);
17219
17220   return NULL_RTX;
17221 }
17222
17223 void
17224 ix86_expand_move (machine_mode mode, rtx operands[])
17225 {
17226   rtx op0, op1;
17227   enum tls_model model;
17228
17229   op0 = operands[0];
17230   op1 = operands[1];
17231
17232   if (GET_CODE (op1) == SYMBOL_REF)
17233     {
17234       rtx tmp;
17235
17236       model = SYMBOL_REF_TLS_MODEL (op1);
17237       if (model)
17238         {
17239           op1 = legitimize_tls_address (op1, model, true);
17240           op1 = force_operand (op1, op0);
17241           if (op1 == op0)
17242             return;
17243           op1 = convert_to_mode (mode, op1, 1);
17244         }
17245       else if ((tmp = legitimize_pe_coff_symbol (op1, false)) != NULL_RTX)
17246         op1 = tmp;
17247     }
17248   else if (GET_CODE (op1) == CONST
17249            && GET_CODE (XEXP (op1, 0)) == PLUS
17250            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
17251     {
17252       rtx addend = XEXP (XEXP (op1, 0), 1);
17253       rtx symbol = XEXP (XEXP (op1, 0), 0);
17254       rtx tmp;
17255
17256       model = SYMBOL_REF_TLS_MODEL (symbol);
17257       if (model)
17258         tmp = legitimize_tls_address (symbol, model, true);
17259       else
17260         tmp = legitimize_pe_coff_symbol (symbol, true);
17261
17262       if (tmp)
17263         {
17264           tmp = force_operand (tmp, NULL);
17265           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
17266                                      op0, 1, OPTAB_DIRECT);
17267           if (tmp == op0)
17268             return;
17269           op1 = convert_to_mode (mode, tmp, 1);
17270         }
17271     }
17272
17273   if ((flag_pic || MACHOPIC_INDIRECT)
17274       && symbolic_operand (op1, mode))
17275     {
17276       if (TARGET_MACHO && !TARGET_64BIT)
17277         {
17278 #if TARGET_MACHO
17279           /* dynamic-no-pic */
17280           if (MACHOPIC_INDIRECT)
17281             {
17282               rtx temp = ((reload_in_progress
17283                            || ((op0 && REG_P (op0))
17284                                && mode == Pmode))
17285                           ? op0 : gen_reg_rtx (Pmode));
17286               op1 = machopic_indirect_data_reference (op1, temp);
17287               if (MACHOPIC_PURE)
17288                 op1 = machopic_legitimize_pic_address (op1, mode,
17289                                                        temp == op1 ? 0 : temp);
17290             }
17291           if (op0 != op1 && GET_CODE (op0) != MEM)
17292             {
17293               rtx insn = gen_rtx_SET (VOIDmode, op0, op1);
17294               emit_insn (insn);
17295               return;
17296             }
17297           if (GET_CODE (op0) == MEM)
17298             op1 = force_reg (Pmode, op1);
17299           else
17300             {
17301               rtx temp = op0;
17302               if (GET_CODE (temp) != REG)
17303                 temp = gen_reg_rtx (Pmode);
17304               temp = legitimize_pic_address (op1, temp);
17305               if (temp == op0)
17306             return;
17307               op1 = temp;
17308             }
17309       /* dynamic-no-pic */
17310 #endif
17311         }
17312       else
17313         {
17314           if (MEM_P (op0))
17315             op1 = force_reg (mode, op1);
17316           else if (!(TARGET_64BIT && x86_64_movabs_operand (op1, DImode)))
17317             {
17318               rtx reg = can_create_pseudo_p () ? NULL_RTX : op0;
17319               op1 = legitimize_pic_address (op1, reg);
17320               if (op0 == op1)
17321                 return;
17322               op1 = convert_to_mode (mode, op1, 1);
17323             }
17324         }
17325     }
17326   else
17327     {
17328       if (MEM_P (op0)
17329           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
17330               || !push_operand (op0, mode))
17331           && MEM_P (op1))
17332         op1 = force_reg (mode, op1);
17333
17334       if (push_operand (op0, mode)
17335           && ! general_no_elim_operand (op1, mode))
17336         op1 = copy_to_mode_reg (mode, op1);
17337
17338       /* Force large constants in 64bit compilation into register
17339          to get them CSEed.  */
17340       if (can_create_pseudo_p ()
17341           && (mode == DImode) && TARGET_64BIT
17342           && immediate_operand (op1, mode)
17343           && !x86_64_zext_immediate_operand (op1, VOIDmode)
17344           && !register_operand (op0, mode)
17345           && optimize)
17346         op1 = copy_to_mode_reg (mode, op1);
17347
17348       if (can_create_pseudo_p ()
17349           && FLOAT_MODE_P (mode)
17350           && GET_CODE (op1) == CONST_DOUBLE)
17351         {
17352           /* If we are loading a floating point constant to a register,
17353              force the value to memory now, since we'll get better code
17354              out the back end.  */
17355
17356           op1 = validize_mem (force_const_mem (mode, op1));
17357           if (!register_operand (op0, mode))
17358             {
17359               rtx temp = gen_reg_rtx (mode);
17360               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
17361               emit_move_insn (op0, temp);
17362               return;
17363             }
17364         }
17365     }
17366
17367   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17368 }
17369
17370 void
17371 ix86_expand_vector_move (machine_mode mode, rtx operands[])
17372 {
17373   rtx op0 = operands[0], op1 = operands[1];
17374   unsigned int align = GET_MODE_ALIGNMENT (mode);
17375
17376   if (push_operand (op0, VOIDmode))
17377     op0 = emit_move_resolve_push (mode, op0);
17378
17379   /* Force constants other than zero into memory.  We do not know how
17380      the instructions used to build constants modify the upper 64 bits
17381      of the register, once we have that information we may be able
17382      to handle some of them more efficiently.  */
17383   if (can_create_pseudo_p ()
17384       && register_operand (op0, mode)
17385       && (CONSTANT_P (op1)
17386           || (GET_CODE (op1) == SUBREG
17387               && CONSTANT_P (SUBREG_REG (op1))))
17388       && !standard_sse_constant_p (op1))
17389     op1 = validize_mem (force_const_mem (mode, op1));
17390
17391   /* We need to check memory alignment for SSE mode since attribute
17392      can make operands unaligned.  */
17393   if (can_create_pseudo_p ()
17394       && SSE_REG_MODE_P (mode)
17395       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
17396           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
17397     {
17398       rtx tmp[2];
17399
17400       /* ix86_expand_vector_move_misalign() does not like constants ... */
17401       if (CONSTANT_P (op1)
17402           || (GET_CODE (op1) == SUBREG
17403               && CONSTANT_P (SUBREG_REG (op1))))
17404         op1 = validize_mem (force_const_mem (mode, op1));
17405
17406       /* ... nor both arguments in memory.  */
17407       if (!register_operand (op0, mode)
17408           && !register_operand (op1, mode))
17409         op1 = force_reg (mode, op1);
17410
17411       tmp[0] = op0; tmp[1] = op1;
17412       ix86_expand_vector_move_misalign (mode, tmp);
17413       return;
17414     }
17415
17416   /* Make operand1 a register if it isn't already.  */
17417   if (can_create_pseudo_p ()
17418       && !register_operand (op0, mode)
17419       && !register_operand (op1, mode))
17420     {
17421       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
17422       return;
17423     }
17424
17425   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17426 }
17427
17428 /* Split 32-byte AVX unaligned load and store if needed.  */
17429
17430 static void
17431 ix86_avx256_split_vector_move_misalign (rtx op0, rtx op1)
17432 {
17433   rtx m;
17434   rtx (*extract) (rtx, rtx, rtx);
17435   rtx (*load_unaligned) (rtx, rtx);
17436   rtx (*store_unaligned) (rtx, rtx);
17437   machine_mode mode;
17438
17439   switch (GET_MODE (op0))
17440     {
17441     default:
17442       gcc_unreachable ();
17443     case V32QImode:
17444       extract = gen_avx_vextractf128v32qi;
17445       load_unaligned = gen_avx_loaddquv32qi;
17446       store_unaligned = gen_avx_storedquv32qi;
17447       mode = V16QImode;
17448       break;
17449     case V8SFmode:
17450       extract = gen_avx_vextractf128v8sf;
17451       load_unaligned = gen_avx_loadups256;
17452       store_unaligned = gen_avx_storeups256;
17453       mode = V4SFmode;
17454       break;
17455     case V4DFmode:
17456       extract = gen_avx_vextractf128v4df;
17457       load_unaligned = gen_avx_loadupd256;
17458       store_unaligned = gen_avx_storeupd256;
17459       mode = V2DFmode;
17460       break;
17461     }
17462
17463   if (MEM_P (op1))
17464     {
17465       if (TARGET_AVX256_SPLIT_UNALIGNED_LOAD)
17466         {
17467           rtx r = gen_reg_rtx (mode);
17468           m = adjust_address (op1, mode, 0);
17469           emit_move_insn (r, m);
17470           m = adjust_address (op1, mode, 16);
17471           r = gen_rtx_VEC_CONCAT (GET_MODE (op0), r, m);
17472           emit_move_insn (op0, r);
17473         }
17474       /* Normal *mov<mode>_internal pattern will handle
17475          unaligned loads just fine if misaligned_operand
17476          is true, and without the UNSPEC it can be combined
17477          with arithmetic instructions.  */
17478       else if (misaligned_operand (op1, GET_MODE (op1)))
17479         emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17480       else
17481         emit_insn (load_unaligned (op0, op1));
17482     }
17483   else if (MEM_P (op0))
17484     {
17485       if (TARGET_AVX256_SPLIT_UNALIGNED_STORE)
17486         {
17487           m = adjust_address (op0, mode, 0);
17488           emit_insn (extract (m, op1, const0_rtx));
17489           m = adjust_address (op0, mode, 16);
17490           emit_insn (extract (m, op1, const1_rtx));
17491         }
17492       else
17493         emit_insn (store_unaligned (op0, op1));
17494     }
17495   else
17496     gcc_unreachable ();
17497 }
17498
17499 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
17500    straight to ix86_expand_vector_move.  */
17501 /* Code generation for scalar reg-reg moves of single and double precision data:
17502      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
17503        movaps reg, reg
17504      else
17505        movss reg, reg
17506      if (x86_sse_partial_reg_dependency == true)
17507        movapd reg, reg
17508      else
17509        movsd reg, reg
17510
17511    Code generation for scalar loads of double precision data:
17512      if (x86_sse_split_regs == true)
17513        movlpd mem, reg      (gas syntax)
17514      else
17515        movsd mem, reg
17516
17517    Code generation for unaligned packed loads of single precision data
17518    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
17519      if (x86_sse_unaligned_move_optimal)
17520        movups mem, reg
17521
17522      if (x86_sse_partial_reg_dependency == true)
17523        {
17524          xorps  reg, reg
17525          movlps mem, reg
17526          movhps mem+8, reg
17527        }
17528      else
17529        {
17530          movlps mem, reg
17531          movhps mem+8, reg
17532        }
17533
17534    Code generation for unaligned packed loads of double precision data
17535    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
17536      if (x86_sse_unaligned_move_optimal)
17537        movupd mem, reg
17538
17539      if (x86_sse_split_regs == true)
17540        {
17541          movlpd mem, reg
17542          movhpd mem+8, reg
17543        }
17544      else
17545        {
17546          movsd  mem, reg
17547          movhpd mem+8, reg
17548        }
17549  */
17550
17551 void
17552 ix86_expand_vector_move_misalign (machine_mode mode, rtx operands[])
17553 {
17554   rtx op0, op1, orig_op0 = NULL_RTX, m;
17555   rtx (*load_unaligned) (rtx, rtx);
17556   rtx (*store_unaligned) (rtx, rtx);
17557
17558   op0 = operands[0];
17559   op1 = operands[1];
17560
17561   if (GET_MODE_SIZE (mode) == 64)
17562     {
17563       switch (GET_MODE_CLASS (mode))
17564         {
17565         case MODE_VECTOR_INT:
17566         case MODE_INT:
17567           if (GET_MODE (op0) != V16SImode)
17568             {
17569               if (!MEM_P (op0))
17570                 {
17571                   orig_op0 = op0;
17572                   op0 = gen_reg_rtx (V16SImode);
17573                 }
17574               else
17575                 op0 = gen_lowpart (V16SImode, op0);
17576             }
17577           op1 = gen_lowpart (V16SImode, op1);
17578           /* FALLTHRU */
17579
17580         case MODE_VECTOR_FLOAT:
17581           switch (GET_MODE (op0))
17582             {
17583             default:
17584               gcc_unreachable ();
17585             case V16SImode:
17586               load_unaligned = gen_avx512f_loaddquv16si;
17587               store_unaligned = gen_avx512f_storedquv16si;
17588               break;
17589             case V16SFmode:
17590               load_unaligned = gen_avx512f_loadups512;
17591               store_unaligned = gen_avx512f_storeups512;
17592               break;
17593             case V8DFmode:
17594               load_unaligned = gen_avx512f_loadupd512;
17595               store_unaligned = gen_avx512f_storeupd512;
17596               break;
17597             }
17598
17599           if (MEM_P (op1))
17600             emit_insn (load_unaligned (op0, op1));
17601           else if (MEM_P (op0))
17602             emit_insn (store_unaligned (op0, op1));
17603           else
17604             gcc_unreachable ();
17605           if (orig_op0)
17606             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17607           break;
17608
17609         default:
17610           gcc_unreachable ();
17611         }
17612
17613       return;
17614     }
17615
17616   if (TARGET_AVX
17617       && GET_MODE_SIZE (mode) == 32)
17618     {
17619       switch (GET_MODE_CLASS (mode))
17620         {
17621         case MODE_VECTOR_INT:
17622         case MODE_INT:
17623           if (GET_MODE (op0) != V32QImode)
17624             {
17625               if (!MEM_P (op0))
17626                 {
17627                   orig_op0 = op0;
17628                   op0 = gen_reg_rtx (V32QImode);
17629                 }
17630               else
17631                 op0 = gen_lowpart (V32QImode, op0);
17632             }
17633           op1 = gen_lowpart (V32QImode, op1);
17634           /* FALLTHRU */
17635
17636         case MODE_VECTOR_FLOAT:
17637           ix86_avx256_split_vector_move_misalign (op0, op1);
17638           if (orig_op0)
17639             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17640           break;
17641
17642         default:
17643           gcc_unreachable ();
17644         }
17645
17646       return;
17647     }
17648
17649   if (MEM_P (op1))
17650     {
17651       /* Normal *mov<mode>_internal pattern will handle
17652          unaligned loads just fine if misaligned_operand
17653          is true, and without the UNSPEC it can be combined
17654          with arithmetic instructions.  */
17655       if (TARGET_AVX
17656           && (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
17657               || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
17658           && misaligned_operand (op1, GET_MODE (op1)))
17659         emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17660       /* ??? If we have typed data, then it would appear that using
17661          movdqu is the only way to get unaligned data loaded with
17662          integer type.  */
17663       else if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
17664         {
17665           if (GET_MODE (op0) != V16QImode)
17666             {
17667               orig_op0 = op0;
17668               op0 = gen_reg_rtx (V16QImode);
17669             }
17670           op1 = gen_lowpart (V16QImode, op1);
17671           /* We will eventually emit movups based on insn attributes.  */
17672           emit_insn (gen_sse2_loaddquv16qi (op0, op1));
17673           if (orig_op0)
17674             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17675         }
17676       else if (TARGET_SSE2 && mode == V2DFmode)
17677         {
17678           rtx zero;
17679
17680           if (TARGET_AVX
17681               || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
17682               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17683               || optimize_insn_for_size_p ())
17684             {
17685               /* We will eventually emit movups based on insn attributes.  */
17686               emit_insn (gen_sse2_loadupd (op0, op1));
17687               return;
17688             }
17689
17690           /* When SSE registers are split into halves, we can avoid
17691              writing to the top half twice.  */
17692           if (TARGET_SSE_SPLIT_REGS)
17693             {
17694               emit_clobber (op0);
17695               zero = op0;
17696             }
17697           else
17698             {
17699               /* ??? Not sure about the best option for the Intel chips.
17700                  The following would seem to satisfy; the register is
17701                  entirely cleared, breaking the dependency chain.  We
17702                  then store to the upper half, with a dependency depth
17703                  of one.  A rumor has it that Intel recommends two movsd
17704                  followed by an unpacklpd, but this is unconfirmed.  And
17705                  given that the dependency depth of the unpacklpd would
17706                  still be one, I'm not sure why this would be better.  */
17707               zero = CONST0_RTX (V2DFmode);
17708             }
17709
17710           m = adjust_address (op1, DFmode, 0);
17711           emit_insn (gen_sse2_loadlpd (op0, zero, m));
17712           m = adjust_address (op1, DFmode, 8);
17713           emit_insn (gen_sse2_loadhpd (op0, op0, m));
17714         }
17715       else
17716         {
17717           rtx t;
17718
17719           if (TARGET_AVX
17720               || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
17721               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17722               || optimize_insn_for_size_p ())
17723             {
17724               if (GET_MODE (op0) != V4SFmode)
17725                 {
17726                   orig_op0 = op0;
17727                   op0 = gen_reg_rtx (V4SFmode);
17728                 }
17729               op1 = gen_lowpart (V4SFmode, op1);
17730               emit_insn (gen_sse_loadups (op0, op1));
17731               if (orig_op0)
17732                 emit_move_insn (orig_op0,
17733                                 gen_lowpart (GET_MODE (orig_op0), op0));
17734               return;
17735             }
17736
17737           if (mode != V4SFmode)
17738             t = gen_reg_rtx (V4SFmode);
17739           else
17740             t = op0;
17741             
17742           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
17743             emit_move_insn (t, CONST0_RTX (V4SFmode));
17744           else
17745             emit_clobber (t);
17746
17747           m = adjust_address (op1, V2SFmode, 0);
17748           emit_insn (gen_sse_loadlps (t, t, m));
17749           m = adjust_address (op1, V2SFmode, 8);
17750           emit_insn (gen_sse_loadhps (t, t, m));
17751           if (mode != V4SFmode)
17752             emit_move_insn (op0, gen_lowpart (mode, t));
17753         }
17754     }
17755   else if (MEM_P (op0))
17756     {
17757       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
17758         {
17759           op0 = gen_lowpart (V16QImode, op0);
17760           op1 = gen_lowpart (V16QImode, op1);
17761           /* We will eventually emit movups based on insn attributes.  */
17762           emit_insn (gen_sse2_storedquv16qi (op0, op1));
17763         }
17764       else if (TARGET_SSE2 && mode == V2DFmode)
17765         {
17766           if (TARGET_AVX
17767               || TARGET_SSE_UNALIGNED_STORE_OPTIMAL
17768               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17769               || optimize_insn_for_size_p ())
17770             /* We will eventually emit movups based on insn attributes.  */
17771             emit_insn (gen_sse2_storeupd (op0, op1));
17772           else
17773             {
17774               m = adjust_address (op0, DFmode, 0);
17775               emit_insn (gen_sse2_storelpd (m, op1));
17776               m = adjust_address (op0, DFmode, 8);
17777               emit_insn (gen_sse2_storehpd (m, op1));
17778             }
17779         }
17780       else
17781         {
17782           if (mode != V4SFmode)
17783             op1 = gen_lowpart (V4SFmode, op1);
17784
17785           if (TARGET_AVX
17786               || TARGET_SSE_UNALIGNED_STORE_OPTIMAL
17787               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17788               || optimize_insn_for_size_p ())
17789             {
17790               op0 = gen_lowpart (V4SFmode, op0);
17791               emit_insn (gen_sse_storeups (op0, op1));
17792             }
17793           else
17794             {
17795               m = adjust_address (op0, V2SFmode, 0);
17796               emit_insn (gen_sse_storelps (m, op1));
17797               m = adjust_address (op0, V2SFmode, 8);
17798               emit_insn (gen_sse_storehps (m, op1));
17799             }
17800         }
17801     }
17802   else
17803     gcc_unreachable ();
17804 }
17805
17806 /* Helper function of ix86_fixup_binary_operands to canonicalize
17807    operand order.  Returns true if the operands should be swapped.  */
17808
17809 static bool
17810 ix86_swap_binary_operands_p (enum rtx_code code, machine_mode mode,
17811                              rtx operands[])
17812 {
17813   rtx dst = operands[0];
17814   rtx src1 = operands[1];
17815   rtx src2 = operands[2];
17816
17817   /* If the operation is not commutative, we can't do anything.  */
17818   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
17819     return false;
17820
17821   /* Highest priority is that src1 should match dst.  */
17822   if (rtx_equal_p (dst, src1))
17823     return false;
17824   if (rtx_equal_p (dst, src2))
17825     return true;
17826
17827   /* Next highest priority is that immediate constants come second.  */
17828   if (immediate_operand (src2, mode))
17829     return false;
17830   if (immediate_operand (src1, mode))
17831     return true;
17832
17833   /* Lowest priority is that memory references should come second.  */
17834   if (MEM_P (src2))
17835     return false;
17836   if (MEM_P (src1))
17837     return true;
17838
17839   return false;
17840 }
17841
17842
17843 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
17844    destination to use for the operation.  If different from the true
17845    destination in operands[0], a copy operation will be required.  */
17846
17847 rtx
17848 ix86_fixup_binary_operands (enum rtx_code code, machine_mode mode,
17849                             rtx operands[])
17850 {
17851   rtx dst = operands[0];
17852   rtx src1 = operands[1];
17853   rtx src2 = operands[2];
17854
17855   /* Canonicalize operand order.  */
17856   if (ix86_swap_binary_operands_p (code, mode, operands))
17857     {
17858       /* It is invalid to swap operands of different modes.  */
17859       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
17860
17861       std::swap (src1, src2);
17862     }
17863
17864   /* Both source operands cannot be in memory.  */
17865   if (MEM_P (src1) && MEM_P (src2))
17866     {
17867       /* Optimization: Only read from memory once.  */
17868       if (rtx_equal_p (src1, src2))
17869         {
17870           src2 = force_reg (mode, src2);
17871           src1 = src2;
17872         }
17873       else if (rtx_equal_p (dst, src1))
17874         src2 = force_reg (mode, src2);
17875       else
17876         src1 = force_reg (mode, src1);
17877     }
17878
17879   /* If the destination is memory, and we do not have matching source
17880      operands, do things in registers.  */
17881   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
17882     dst = gen_reg_rtx (mode);
17883
17884   /* Source 1 cannot be a constant.  */
17885   if (CONSTANT_P (src1))
17886     src1 = force_reg (mode, src1);
17887
17888   /* Source 1 cannot be a non-matching memory.  */
17889   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
17890     src1 = force_reg (mode, src1);
17891
17892   /* Improve address combine.  */
17893   if (code == PLUS
17894       && GET_MODE_CLASS (mode) == MODE_INT
17895       && MEM_P (src2))
17896     src2 = force_reg (mode, src2);
17897
17898   operands[1] = src1;
17899   operands[2] = src2;
17900   return dst;
17901 }
17902
17903 /* Similarly, but assume that the destination has already been
17904    set up properly.  */
17905
17906 void
17907 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
17908                                     machine_mode mode, rtx operands[])
17909 {
17910   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
17911   gcc_assert (dst == operands[0]);
17912 }
17913
17914 /* Attempt to expand a binary operator.  Make the expansion closer to the
17915    actual machine, then just general_operand, which will allow 3 separate
17916    memory references (one output, two input) in a single insn.  */
17917
17918 void
17919 ix86_expand_binary_operator (enum rtx_code code, machine_mode mode,
17920                              rtx operands[])
17921 {
17922   rtx src1, src2, dst, op, clob;
17923
17924   dst = ix86_fixup_binary_operands (code, mode, operands);
17925   src1 = operands[1];
17926   src2 = operands[2];
17927
17928  /* Emit the instruction.  */
17929
17930   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
17931   if (reload_in_progress)
17932     {
17933       /* Reload doesn't know about the flags register, and doesn't know that
17934          it doesn't want to clobber it.  We can only do this with PLUS.  */
17935       gcc_assert (code == PLUS);
17936       emit_insn (op);
17937     }
17938   else if (reload_completed
17939            && code == PLUS
17940            && !rtx_equal_p (dst, src1))
17941     {
17942       /* This is going to be an LEA; avoid splitting it later.  */
17943       emit_insn (op);
17944     }
17945   else
17946     {
17947       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
17948       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
17949     }
17950
17951   /* Fix up the destination if needed.  */
17952   if (dst != operands[0])
17953     emit_move_insn (operands[0], dst);
17954 }
17955
17956 /* Expand vector logical operation CODE (AND, IOR, XOR) in MODE with
17957    the given OPERANDS.  */
17958
17959 void
17960 ix86_expand_vector_logical_operator (enum rtx_code code, machine_mode mode,
17961                                      rtx operands[])
17962 {
17963   rtx op1 = NULL_RTX, op2 = NULL_RTX;
17964   if (GET_CODE (operands[1]) == SUBREG)
17965     {
17966       op1 = operands[1];
17967       op2 = operands[2];
17968     }
17969   else if (GET_CODE (operands[2]) == SUBREG)
17970     {
17971       op1 = operands[2];
17972       op2 = operands[1];
17973     }
17974   /* Optimize (__m128i) d | (__m128i) e and similar code
17975      when d and e are float vectors into float vector logical
17976      insn.  In C/C++ without using intrinsics there is no other way
17977      to express vector logical operation on float vectors than
17978      to cast them temporarily to integer vectors.  */
17979   if (op1
17980       && !TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17981       && ((GET_CODE (op2) == SUBREG || GET_CODE (op2) == CONST_VECTOR))
17982       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op1))) == MODE_VECTOR_FLOAT
17983       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1))) == GET_MODE_SIZE (mode)
17984       && SUBREG_BYTE (op1) == 0
17985       && (GET_CODE (op2) == CONST_VECTOR
17986           || (GET_MODE (SUBREG_REG (op1)) == GET_MODE (SUBREG_REG (op2))
17987               && SUBREG_BYTE (op2) == 0))
17988       && can_create_pseudo_p ())
17989     {
17990       rtx dst;
17991       switch (GET_MODE (SUBREG_REG (op1)))
17992         {
17993         case V4SFmode:
17994         case V8SFmode:
17995         case V16SFmode:
17996         case V2DFmode:
17997         case V4DFmode:
17998         case V8DFmode:
17999           dst = gen_reg_rtx (GET_MODE (SUBREG_REG (op1)));
18000           if (GET_CODE (op2) == CONST_VECTOR)
18001             {
18002               op2 = gen_lowpart (GET_MODE (dst), op2);
18003               op2 = force_reg (GET_MODE (dst), op2);
18004             }
18005           else
18006             {
18007               op1 = operands[1];
18008               op2 = SUBREG_REG (operands[2]);
18009               if (!nonimmediate_operand (op2, GET_MODE (dst)))
18010                 op2 = force_reg (GET_MODE (dst), op2);
18011             }
18012           op1 = SUBREG_REG (op1);
18013           if (!nonimmediate_operand (op1, GET_MODE (dst)))
18014             op1 = force_reg (GET_MODE (dst), op1);
18015           emit_insn (gen_rtx_SET (VOIDmode, dst,
18016                                   gen_rtx_fmt_ee (code, GET_MODE (dst),
18017                                                   op1, op2)));
18018           emit_move_insn (operands[0], gen_lowpart (mode, dst));
18019           return;
18020         default:
18021           break;
18022         }
18023     }
18024   if (!nonimmediate_operand (operands[1], mode))
18025     operands[1] = force_reg (mode, operands[1]);
18026   if (!nonimmediate_operand (operands[2], mode))
18027     operands[2] = force_reg (mode, operands[2]);
18028   ix86_fixup_binary_operands_no_copy (code, mode, operands);
18029   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
18030                           gen_rtx_fmt_ee (code, mode, operands[1],
18031                                           operands[2])));
18032 }
18033
18034 /* Return TRUE or FALSE depending on whether the binary operator meets the
18035    appropriate constraints.  */
18036
18037 bool
18038 ix86_binary_operator_ok (enum rtx_code code, machine_mode mode,
18039                          rtx operands[3])
18040 {
18041   rtx dst = operands[0];
18042   rtx src1 = operands[1];
18043   rtx src2 = operands[2];
18044
18045   /* Both source operands cannot be in memory.  */
18046   if (MEM_P (src1) && MEM_P (src2))
18047     return false;
18048
18049   /* Canonicalize operand order for commutative operators.  */
18050   if (ix86_swap_binary_operands_p (code, mode, operands))
18051     std::swap (src1, src2);
18052
18053   /* If the destination is memory, we must have a matching source operand.  */
18054   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
18055       return false;
18056
18057   /* Source 1 cannot be a constant.  */
18058   if (CONSTANT_P (src1))
18059     return false;
18060
18061   /* Source 1 cannot be a non-matching memory.  */
18062   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
18063     /* Support "andhi/andsi/anddi" as a zero-extending move.  */
18064     return (code == AND
18065             && (mode == HImode
18066                 || mode == SImode
18067                 || (TARGET_64BIT && mode == DImode))
18068             && satisfies_constraint_L (src2));
18069
18070   return true;
18071 }
18072
18073 /* Attempt to expand a unary operator.  Make the expansion closer to the
18074    actual machine, then just general_operand, which will allow 2 separate
18075    memory references (one output, one input) in a single insn.  */
18076
18077 void
18078 ix86_expand_unary_operator (enum rtx_code code, machine_mode mode,
18079                             rtx operands[])
18080 {
18081   bool matching_memory = false;
18082   rtx src, dst, op, clob;
18083
18084   dst = operands[0];
18085   src = operands[1];
18086
18087   /* If the destination is memory, and we do not have matching source
18088      operands, do things in registers.  */
18089   if (MEM_P (dst))
18090     {
18091       if (rtx_equal_p (dst, src))
18092         matching_memory = true;
18093       else
18094         dst = gen_reg_rtx (mode);
18095     }
18096
18097   /* When source operand is memory, destination must match.  */
18098   if (MEM_P (src) && !matching_memory)
18099     src = force_reg (mode, src);
18100
18101   /* Emit the instruction.  */
18102
18103   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
18104   if (reload_in_progress || code == NOT)
18105     {
18106       /* Reload doesn't know about the flags register, and doesn't know that
18107          it doesn't want to clobber it.  */
18108       gcc_assert (code == NOT);
18109       emit_insn (op);
18110     }
18111   else
18112     {
18113       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18114       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18115     }
18116
18117   /* Fix up the destination if needed.  */
18118   if (dst != operands[0])
18119     emit_move_insn (operands[0], dst);
18120 }
18121
18122 /* Split 32bit/64bit divmod with 8bit unsigned divmod if dividend and
18123    divisor are within the range [0-255].  */
18124
18125 void
18126 ix86_split_idivmod (machine_mode mode, rtx operands[],
18127                     bool signed_p)
18128 {
18129   rtx_code_label *end_label, *qimode_label;
18130   rtx insn, div, mod;
18131   rtx scratch, tmp0, tmp1, tmp2;
18132   rtx (*gen_divmod4_1) (rtx, rtx, rtx, rtx);
18133   rtx (*gen_zero_extend) (rtx, rtx);
18134   rtx (*gen_test_ccno_1) (rtx, rtx);
18135
18136   switch (mode)
18137     {
18138     case SImode:
18139       gen_divmod4_1 = signed_p ? gen_divmodsi4_1 : gen_udivmodsi4_1;
18140       gen_test_ccno_1 = gen_testsi_ccno_1;
18141       gen_zero_extend = gen_zero_extendqisi2;
18142       break;
18143     case DImode:
18144       gen_divmod4_1 = signed_p ? gen_divmoddi4_1 : gen_udivmoddi4_1;
18145       gen_test_ccno_1 = gen_testdi_ccno_1;
18146       gen_zero_extend = gen_zero_extendqidi2;
18147       break;
18148     default:
18149       gcc_unreachable ();
18150     }
18151
18152   end_label = gen_label_rtx ();
18153   qimode_label = gen_label_rtx ();
18154
18155   scratch = gen_reg_rtx (mode);
18156
18157   /* Use 8bit unsigned divimod if dividend and divisor are within
18158      the range [0-255].  */
18159   emit_move_insn (scratch, operands[2]);
18160   scratch = expand_simple_binop (mode, IOR, scratch, operands[3],
18161                                  scratch, 1, OPTAB_DIRECT);
18162   emit_insn (gen_test_ccno_1 (scratch, GEN_INT (-0x100)));
18163   tmp0 = gen_rtx_REG (CCNOmode, FLAGS_REG);
18164   tmp0 = gen_rtx_EQ (VOIDmode, tmp0, const0_rtx);
18165   tmp0 = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp0,
18166                                gen_rtx_LABEL_REF (VOIDmode, qimode_label),
18167                                pc_rtx);
18168   insn = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp0));
18169   predict_jump (REG_BR_PROB_BASE * 50 / 100);
18170   JUMP_LABEL (insn) = qimode_label;
18171
18172   /* Generate original signed/unsigned divimod.  */
18173   div = gen_divmod4_1 (operands[0], operands[1],
18174                        operands[2], operands[3]);
18175   emit_insn (div);
18176
18177   /* Branch to the end.  */
18178   emit_jump_insn (gen_jump (end_label));
18179   emit_barrier ();
18180
18181   /* Generate 8bit unsigned divide.  */
18182   emit_label (qimode_label);
18183   /* Don't use operands[0] for result of 8bit divide since not all
18184      registers support QImode ZERO_EXTRACT.  */
18185   tmp0 = simplify_gen_subreg (HImode, scratch, mode, 0);
18186   tmp1 = simplify_gen_subreg (HImode, operands[2], mode, 0);
18187   tmp2 = simplify_gen_subreg (QImode, operands[3], mode, 0);
18188   emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, tmp2));
18189
18190   if (signed_p)
18191     {
18192       div = gen_rtx_DIV (SImode, operands[2], operands[3]);
18193       mod = gen_rtx_MOD (SImode, operands[2], operands[3]);
18194     }
18195   else
18196     {
18197       div = gen_rtx_UDIV (SImode, operands[2], operands[3]);
18198       mod = gen_rtx_UMOD (SImode, operands[2], operands[3]);
18199     }
18200
18201   /* Extract remainder from AH.  */
18202   tmp1 = gen_rtx_ZERO_EXTRACT (mode, tmp0, GEN_INT (8), GEN_INT (8));
18203   if (REG_P (operands[1]))
18204     insn = emit_move_insn (operands[1], tmp1);
18205   else
18206     {
18207       /* Need a new scratch register since the old one has result
18208          of 8bit divide.  */
18209       scratch = gen_reg_rtx (mode);
18210       emit_move_insn (scratch, tmp1);
18211       insn = emit_move_insn (operands[1], scratch);
18212     }
18213   set_unique_reg_note (insn, REG_EQUAL, mod);
18214
18215   /* Zero extend quotient from AL.  */
18216   tmp1 = gen_lowpart (QImode, tmp0);
18217   insn = emit_insn (gen_zero_extend (operands[0], tmp1));
18218   set_unique_reg_note (insn, REG_EQUAL, div);
18219
18220   emit_label (end_label);
18221 }
18222
18223 #define LEA_MAX_STALL (3)
18224 #define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1)
18225
18226 /* Increase given DISTANCE in half-cycles according to
18227    dependencies between PREV and NEXT instructions.
18228    Add 1 half-cycle if there is no dependency and
18229    go to next cycle if there is some dependecy.  */
18230
18231 static unsigned int
18232 increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance)
18233 {
18234   df_ref def, use;
18235
18236   if (!prev || !next)
18237     return distance + (distance & 1) + 2;
18238
18239   if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev))
18240     return distance + 1;
18241
18242   FOR_EACH_INSN_USE (use, next)
18243     FOR_EACH_INSN_DEF (def, prev)
18244       if (!DF_REF_IS_ARTIFICIAL (def)
18245           && DF_REF_REGNO (use) == DF_REF_REGNO (def))
18246         return distance + (distance & 1) + 2;
18247
18248   return distance + 1;
18249 }
18250
18251 /* Function checks if instruction INSN defines register number
18252    REGNO1 or REGNO2.  */
18253
18254 static bool
18255 insn_defines_reg (unsigned int regno1, unsigned int regno2,
18256                   rtx insn)
18257 {
18258   df_ref def;
18259
18260   FOR_EACH_INSN_DEF (def, insn)
18261     if (DF_REF_REG_DEF_P (def)
18262         && !DF_REF_IS_ARTIFICIAL (def)
18263         && (regno1 == DF_REF_REGNO (def)
18264             || regno2 == DF_REF_REGNO (def)))
18265       return true;
18266
18267   return false;
18268 }
18269
18270 /* Function checks if instruction INSN uses register number
18271    REGNO as a part of address expression.  */
18272
18273 static bool
18274 insn_uses_reg_mem (unsigned int regno, rtx insn)
18275 {
18276   df_ref use;
18277
18278   FOR_EACH_INSN_USE (use, insn)
18279     if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use))
18280       return true;
18281
18282   return false;
18283 }
18284
18285 /* Search backward for non-agu definition of register number REGNO1
18286    or register number REGNO2 in basic block starting from instruction
18287    START up to head of basic block or instruction INSN.
18288
18289    Function puts true value into *FOUND var if definition was found
18290    and false otherwise.
18291
18292    Distance in half-cycles between START and found instruction or head
18293    of BB is added to DISTANCE and returned.  */
18294
18295 static int
18296 distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2,
18297                                rtx_insn *insn, int distance,
18298                                rtx_insn *start, bool *found)
18299 {
18300   basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL;
18301   rtx_insn *prev = start;
18302   rtx_insn *next = NULL;
18303
18304   *found = false;
18305
18306   while (prev
18307          && prev != insn
18308          && distance < LEA_SEARCH_THRESHOLD)
18309     {
18310       if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev))
18311         {
18312           distance = increase_distance (prev, next, distance);
18313           if (insn_defines_reg (regno1, regno2, prev))
18314             {
18315               if (recog_memoized (prev) < 0
18316                   || get_attr_type (prev) != TYPE_LEA)
18317                 {
18318                   *found = true;
18319                   return distance;
18320                 }
18321             }
18322
18323           next = prev;
18324         }
18325       if (prev == BB_HEAD (bb))
18326         break;
18327
18328       prev = PREV_INSN (prev);
18329     }
18330
18331   return distance;
18332 }
18333
18334 /* Search backward for non-agu definition of register number REGNO1
18335    or register number REGNO2 in INSN's basic block until
18336    1. Pass LEA_SEARCH_THRESHOLD instructions, or
18337    2. Reach neighbour BBs boundary, or
18338    3. Reach agu definition.
18339    Returns the distance between the non-agu definition point and INSN.
18340    If no definition point, returns -1.  */
18341
18342 static int
18343 distance_non_agu_define (unsigned int regno1, unsigned int regno2,
18344                          rtx_insn *insn)
18345 {
18346   basic_block bb = BLOCK_FOR_INSN (insn);
18347   int distance = 0;
18348   bool found = false;
18349
18350   if (insn != BB_HEAD (bb))
18351     distance = distance_non_agu_define_in_bb (regno1, regno2, insn,
18352                                               distance, PREV_INSN (insn),
18353                                               &found);
18354
18355   if (!found && distance < LEA_SEARCH_THRESHOLD)
18356     {
18357       edge e;
18358       edge_iterator ei;
18359       bool simple_loop = false;
18360
18361       FOR_EACH_EDGE (e, ei, bb->preds)
18362         if (e->src == bb)
18363           {
18364             simple_loop = true;
18365             break;
18366           }
18367
18368       if (simple_loop)
18369         distance = distance_non_agu_define_in_bb (regno1, regno2,
18370                                                   insn, distance,
18371                                                   BB_END (bb), &found);
18372       else
18373         {
18374           int shortest_dist = -1;
18375           bool found_in_bb = false;
18376
18377           FOR_EACH_EDGE (e, ei, bb->preds)
18378             {
18379               int bb_dist
18380                 = distance_non_agu_define_in_bb (regno1, regno2,
18381                                                  insn, distance,
18382                                                  BB_END (e->src),
18383                                                  &found_in_bb);
18384               if (found_in_bb)
18385                 {
18386                   if (shortest_dist < 0)
18387                     shortest_dist = bb_dist;
18388                   else if (bb_dist > 0)
18389                     shortest_dist = MIN (bb_dist, shortest_dist);
18390
18391                   found = true;
18392                 }
18393             }
18394
18395           distance = shortest_dist;
18396         }
18397     }
18398
18399   /* get_attr_type may modify recog data.  We want to make sure
18400      that recog data is valid for instruction INSN, on which
18401      distance_non_agu_define is called.  INSN is unchanged here.  */
18402   extract_insn_cached (insn);
18403
18404   if (!found)
18405     return -1;
18406
18407   return distance >> 1;
18408 }
18409
18410 /* Return the distance in half-cycles between INSN and the next
18411    insn that uses register number REGNO in memory address added
18412    to DISTANCE.  Return -1 if REGNO0 is set.
18413
18414    Put true value into *FOUND if register usage was found and
18415    false otherwise.
18416    Put true value into *REDEFINED if register redefinition was
18417    found and false otherwise.  */
18418
18419 static int
18420 distance_agu_use_in_bb (unsigned int regno,
18421                         rtx_insn *insn, int distance, rtx_insn *start,
18422                         bool *found, bool *redefined)
18423 {
18424   basic_block bb = NULL;
18425   rtx_insn *next = start;
18426   rtx_insn *prev = NULL;
18427
18428   *found = false;
18429   *redefined = false;
18430
18431   if (start != NULL_RTX)
18432     {
18433       bb = BLOCK_FOR_INSN (start);
18434       if (start != BB_HEAD (bb))
18435         /* If insn and start belong to the same bb, set prev to insn,
18436            so the call to increase_distance will increase the distance
18437            between insns by 1.  */
18438         prev = insn;
18439     }
18440
18441   while (next
18442          && next != insn
18443          && distance < LEA_SEARCH_THRESHOLD)
18444     {
18445       if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next))
18446         {
18447           distance = increase_distance(prev, next, distance);
18448           if (insn_uses_reg_mem (regno, next))
18449             {
18450               /* Return DISTANCE if OP0 is used in memory
18451                  address in NEXT.  */
18452               *found = true;
18453               return distance;
18454             }
18455
18456           if (insn_defines_reg (regno, INVALID_REGNUM, next))
18457             {
18458               /* Return -1 if OP0 is set in NEXT.  */
18459               *redefined = true;
18460               return -1;
18461             }
18462
18463           prev = next;
18464         }
18465
18466       if (next == BB_END (bb))
18467         break;
18468
18469       next = NEXT_INSN (next);
18470     }
18471
18472   return distance;
18473 }
18474
18475 /* Return the distance between INSN and the next insn that uses
18476    register number REGNO0 in memory address.  Return -1 if no such
18477    a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set.  */
18478
18479 static int
18480 distance_agu_use (unsigned int regno0, rtx_insn *insn)
18481 {
18482   basic_block bb = BLOCK_FOR_INSN (insn);
18483   int distance = 0;
18484   bool found = false;
18485   bool redefined = false;
18486
18487   if (insn != BB_END (bb))
18488     distance = distance_agu_use_in_bb (regno0, insn, distance,
18489                                        NEXT_INSN (insn),
18490                                        &found, &redefined);
18491
18492   if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD)
18493     {
18494       edge e;
18495       edge_iterator ei;
18496       bool simple_loop = false;
18497
18498       FOR_EACH_EDGE (e, ei, bb->succs)
18499         if (e->dest == bb)
18500           {
18501             simple_loop = true;
18502             break;
18503           }
18504
18505       if (simple_loop)
18506         distance = distance_agu_use_in_bb (regno0, insn,
18507                                            distance, BB_HEAD (bb),
18508                                            &found, &redefined);
18509       else
18510         {
18511           int shortest_dist = -1;
18512           bool found_in_bb = false;
18513           bool redefined_in_bb = false;
18514
18515           FOR_EACH_EDGE (e, ei, bb->succs)
18516             {
18517               int bb_dist
18518                 = distance_agu_use_in_bb (regno0, insn,
18519                                           distance, BB_HEAD (e->dest),
18520                                           &found_in_bb, &redefined_in_bb);
18521               if (found_in_bb)
18522                 {
18523                   if (shortest_dist < 0)
18524                     shortest_dist = bb_dist;
18525                   else if (bb_dist > 0)
18526                     shortest_dist = MIN (bb_dist, shortest_dist);
18527
18528                   found = true;
18529                 }
18530             }
18531
18532           distance = shortest_dist;
18533         }
18534     }
18535
18536   if (!found || redefined)
18537     return -1;
18538
18539   return distance >> 1;
18540 }
18541
18542 /* Define this macro to tune LEA priority vs ADD, it take effect when
18543    there is a dilemma of choicing LEA or ADD
18544    Negative value: ADD is more preferred than LEA
18545    Zero: Netrual
18546    Positive value: LEA is more preferred than ADD*/
18547 #define IX86_LEA_PRIORITY 0
18548
18549 /* Return true if usage of lea INSN has performance advantage
18550    over a sequence of instructions.  Instructions sequence has
18551    SPLIT_COST cycles higher latency than lea latency.  */
18552
18553 static bool
18554 ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
18555                       unsigned int regno2, int split_cost, bool has_scale)
18556 {
18557   int dist_define, dist_use;
18558
18559   /* For Silvermont if using a 2-source or 3-source LEA for
18560      non-destructive destination purposes, or due to wanting
18561      ability to use SCALE, the use of LEA is justified.  */
18562   if (TARGET_SILVERMONT || TARGET_INTEL)
18563     {
18564       if (has_scale)
18565         return true;
18566       if (split_cost < 1)
18567         return false;
18568       if (regno0 == regno1 || regno0 == regno2)
18569         return false;
18570       return true;
18571     }
18572
18573   dist_define = distance_non_agu_define (regno1, regno2, insn);
18574   dist_use = distance_agu_use (regno0, insn);
18575
18576   if (dist_define < 0 || dist_define >= LEA_MAX_STALL)
18577     {
18578       /* If there is no non AGU operand definition, no AGU
18579          operand usage and split cost is 0 then both lea
18580          and non lea variants have same priority.  Currently
18581          we prefer lea for 64 bit code and non lea on 32 bit
18582          code.  */
18583       if (dist_use < 0 && split_cost == 0)
18584         return TARGET_64BIT || IX86_LEA_PRIORITY;
18585       else
18586         return true;
18587     }
18588
18589   /* With longer definitions distance lea is more preferable.
18590      Here we change it to take into account splitting cost and
18591      lea priority.  */
18592   dist_define += split_cost + IX86_LEA_PRIORITY;
18593
18594   /* If there is no use in memory addess then we just check
18595      that split cost exceeds AGU stall.  */
18596   if (dist_use < 0)
18597     return dist_define > LEA_MAX_STALL;
18598
18599   /* If this insn has both backward non-agu dependence and forward
18600      agu dependence, the one with short distance takes effect.  */
18601   return dist_define >= dist_use;
18602 }
18603
18604 /* Return true if it is legal to clobber flags by INSN and
18605    false otherwise.  */
18606
18607 static bool
18608 ix86_ok_to_clobber_flags (rtx_insn *insn)
18609 {
18610   basic_block bb = BLOCK_FOR_INSN (insn);
18611   df_ref use;
18612   bitmap live;
18613
18614   while (insn)
18615     {
18616       if (NONDEBUG_INSN_P (insn))
18617         {
18618           FOR_EACH_INSN_USE (use, insn)
18619             if (DF_REF_REG_USE_P (use) && DF_REF_REGNO (use) == FLAGS_REG)
18620               return false;
18621
18622           if (insn_defines_reg (FLAGS_REG, INVALID_REGNUM, insn))
18623             return true;
18624         }
18625
18626       if (insn == BB_END (bb))
18627         break;
18628
18629       insn = NEXT_INSN (insn);
18630     }
18631
18632   live = df_get_live_out(bb);
18633   return !REGNO_REG_SET_P (live, FLAGS_REG);
18634 }
18635
18636 /* Return true if we need to split op0 = op1 + op2 into a sequence of
18637    move and add to avoid AGU stalls.  */
18638
18639 bool
18640 ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[])
18641 {
18642   unsigned int regno0, regno1, regno2;
18643
18644   /* Check if we need to optimize.  */
18645   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18646     return false;
18647
18648   /* Check it is correct to split here.  */
18649   if (!ix86_ok_to_clobber_flags(insn))
18650     return false;
18651
18652   regno0 = true_regnum (operands[0]);
18653   regno1 = true_regnum (operands[1]);
18654   regno2 = true_regnum (operands[2]);
18655
18656   /* We need to split only adds with non destructive
18657      destination operand.  */
18658   if (regno0 == regno1 || regno0 == regno2)
18659     return false;
18660   else
18661     return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false);
18662 }
18663
18664 /* Return true if we should emit lea instruction instead of mov
18665    instruction.  */
18666
18667 bool
18668 ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[])
18669 {
18670   unsigned int regno0, regno1;
18671
18672   /* Check if we need to optimize.  */
18673   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18674     return false;
18675
18676   /* Use lea for reg to reg moves only.  */
18677   if (!REG_P (operands[0]) || !REG_P (operands[1]))
18678     return false;
18679
18680   regno0 = true_regnum (operands[0]);
18681   regno1 = true_regnum (operands[1]);
18682
18683   return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false);
18684 }
18685
18686 /* Return true if we need to split lea into a sequence of
18687    instructions to avoid AGU stalls. */
18688
18689 bool
18690 ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
18691 {
18692   unsigned int regno0, regno1, regno2;
18693   int split_cost;
18694   struct ix86_address parts;
18695   int ok;
18696
18697   /* Check we need to optimize.  */
18698   if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
18699     return false;
18700
18701   /* The "at least two components" test below might not catch simple
18702      move or zero extension insns if parts.base is non-NULL and parts.disp
18703      is const0_rtx as the only components in the address, e.g. if the
18704      register is %rbp or %r13.  As this test is much cheaper and moves or
18705      zero extensions are the common case, do this check first.  */
18706   if (REG_P (operands[1])
18707       || (SImode_address_operand (operands[1], VOIDmode)
18708           && REG_P (XEXP (operands[1], 0))))
18709     return false;
18710
18711   /* Check if it is OK to split here.  */
18712   if (!ix86_ok_to_clobber_flags (insn))
18713     return false;
18714
18715   ok = ix86_decompose_address (operands[1], &parts);
18716   gcc_assert (ok);
18717
18718   /* There should be at least two components in the address.  */
18719   if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX)
18720       + (parts.disp != NULL_RTX) + (parts.scale > 1) < 2)
18721     return false;
18722
18723   /* We should not split into add if non legitimate pic
18724      operand is used as displacement. */
18725   if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp))
18726     return false;
18727
18728   regno0 = true_regnum (operands[0]) ;
18729   regno1 = INVALID_REGNUM;
18730   regno2 = INVALID_REGNUM;
18731
18732   if (parts.base)
18733     regno1 = true_regnum (parts.base);
18734   if (parts.index)
18735     regno2 = true_regnum (parts.index);
18736
18737   split_cost = 0;
18738
18739   /* Compute how many cycles we will add to execution time
18740      if split lea into a sequence of instructions.  */
18741   if (parts.base || parts.index)
18742     {
18743       /* Have to use mov instruction if non desctructive
18744          destination form is used.  */
18745       if (regno1 != regno0 && regno2 != regno0)
18746         split_cost += 1;
18747
18748       /* Have to add index to base if both exist.  */
18749       if (parts.base && parts.index)
18750         split_cost += 1;
18751
18752       /* Have to use shift and adds if scale is 2 or greater.  */
18753       if (parts.scale > 1)
18754         {
18755           if (regno0 != regno1)
18756             split_cost += 1;
18757           else if (regno2 == regno0)
18758             split_cost += 4;
18759           else
18760             split_cost += parts.scale;
18761         }
18762
18763       /* Have to use add instruction with immediate if
18764          disp is non zero.  */
18765       if (parts.disp && parts.disp != const0_rtx)
18766         split_cost += 1;
18767
18768       /* Subtract the price of lea.  */
18769       split_cost -= 1;
18770     }
18771
18772   return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost,
18773                                 parts.scale > 1);
18774 }
18775
18776 /* Emit x86 binary operand CODE in mode MODE, where the first operand
18777    matches destination.  RTX includes clobber of FLAGS_REG.  */
18778
18779 static void
18780 ix86_emit_binop (enum rtx_code code, machine_mode mode,
18781                  rtx dst, rtx src)
18782 {
18783   rtx op, clob;
18784
18785   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, dst, src));
18786   clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18787   
18788   emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18789 }
18790
18791 /* Return true if regno1 def is nearest to the insn.  */
18792
18793 static bool
18794 find_nearest_reg_def (rtx_insn *insn, int regno1, int regno2)
18795 {
18796   rtx_insn *prev = insn;
18797   rtx_insn *start = BB_HEAD (BLOCK_FOR_INSN (insn));
18798
18799   if (insn == start)
18800     return false;
18801   while (prev && prev != start)
18802     {
18803       if (!INSN_P (prev) || !NONDEBUG_INSN_P (prev))
18804         {
18805           prev = PREV_INSN (prev);
18806           continue;
18807         }
18808       if (insn_defines_reg (regno1, INVALID_REGNUM, prev))
18809         return true;
18810       else if (insn_defines_reg (regno2, INVALID_REGNUM, prev))
18811         return false;
18812       prev = PREV_INSN (prev);
18813     }
18814
18815   /* None of the regs is defined in the bb.  */
18816   return false;
18817 }
18818
18819 /* Split lea instructions into a sequence of instructions
18820    which are executed on ALU to avoid AGU stalls.
18821    It is assumed that it is allowed to clobber flags register
18822    at lea position.  */
18823
18824 void
18825 ix86_split_lea_for_addr (rtx_insn *insn, rtx operands[], machine_mode mode)
18826 {
18827   unsigned int regno0, regno1, regno2;
18828   struct ix86_address parts;
18829   rtx target, tmp;
18830   int ok, adds;
18831
18832   ok = ix86_decompose_address (operands[1], &parts);
18833   gcc_assert (ok);
18834
18835   target = gen_lowpart (mode, operands[0]);
18836
18837   regno0 = true_regnum (target);
18838   regno1 = INVALID_REGNUM;
18839   regno2 = INVALID_REGNUM;
18840
18841   if (parts.base)
18842     {
18843       parts.base = gen_lowpart (mode, parts.base);
18844       regno1 = true_regnum (parts.base);
18845     }
18846
18847   if (parts.index)
18848     {
18849       parts.index = gen_lowpart (mode, parts.index);
18850       regno2 = true_regnum (parts.index);
18851     }
18852
18853   if (parts.disp)
18854     parts.disp = gen_lowpart (mode, parts.disp);
18855
18856   if (parts.scale > 1)
18857     {
18858       /* Case r1 = r1 + ...  */
18859       if (regno1 == regno0)
18860         {
18861           /* If we have a case r1 = r1 + C * r2 then we
18862              should use multiplication which is very
18863              expensive.  Assume cost model is wrong if we
18864              have such case here.  */
18865           gcc_assert (regno2 != regno0);
18866
18867           for (adds = parts.scale; adds > 0; adds--)
18868             ix86_emit_binop (PLUS, mode, target, parts.index);
18869         }
18870       else
18871         {
18872           /* r1 = r2 + r3 * C case.  Need to move r3 into r1.  */
18873           if (regno0 != regno2)
18874             emit_insn (gen_rtx_SET (VOIDmode, target, parts.index));
18875
18876           /* Use shift for scaling.  */
18877           ix86_emit_binop (ASHIFT, mode, target,
18878                            GEN_INT (exact_log2 (parts.scale)));
18879
18880           if (parts.base)
18881             ix86_emit_binop (PLUS, mode, target, parts.base);
18882
18883           if (parts.disp && parts.disp != const0_rtx)
18884             ix86_emit_binop (PLUS, mode, target, parts.disp);
18885         }
18886     }
18887   else if (!parts.base && !parts.index)
18888     {
18889       gcc_assert(parts.disp);
18890       emit_insn (gen_rtx_SET (VOIDmode, target, parts.disp));
18891     }
18892   else
18893     {
18894       if (!parts.base)
18895         {
18896           if (regno0 != regno2)
18897             emit_insn (gen_rtx_SET (VOIDmode, target, parts.index));
18898         }
18899       else if (!parts.index)
18900         {
18901           if (regno0 != regno1)
18902             emit_insn (gen_rtx_SET (VOIDmode, target, parts.base));
18903         }
18904       else
18905         {
18906           if (regno0 == regno1)
18907             tmp = parts.index;
18908           else if (regno0 == regno2)
18909             tmp = parts.base;
18910           else
18911             {
18912               rtx tmp1;
18913
18914               /* Find better operand for SET instruction, depending
18915                  on which definition is farther from the insn.  */
18916               if (find_nearest_reg_def (insn, regno1, regno2))
18917                 tmp = parts.index, tmp1 = parts.base;
18918               else
18919                 tmp = parts.base, tmp1 = parts.index;
18920
18921               emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
18922
18923               if (parts.disp && parts.disp != const0_rtx)
18924                 ix86_emit_binop (PLUS, mode, target, parts.disp);
18925
18926               ix86_emit_binop (PLUS, mode, target, tmp1);
18927               return;
18928             }
18929
18930           ix86_emit_binop (PLUS, mode, target, tmp);
18931         }
18932
18933       if (parts.disp && parts.disp != const0_rtx)
18934         ix86_emit_binop (PLUS, mode, target, parts.disp);
18935     }
18936 }
18937
18938 /* Return true if it is ok to optimize an ADD operation to LEA
18939    operation to avoid flag register consumation.  For most processors,
18940    ADD is faster than LEA.  For the processors like BONNELL, if the
18941    destination register of LEA holds an actual address which will be
18942    used soon, LEA is better and otherwise ADD is better.  */
18943
18944 bool
18945 ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[])
18946 {
18947   unsigned int regno0 = true_regnum (operands[0]);
18948   unsigned int regno1 = true_regnum (operands[1]);
18949   unsigned int regno2 = true_regnum (operands[2]);
18950
18951   /* If a = b + c, (a!=b && a!=c), must use lea form. */
18952   if (regno0 != regno1 && regno0 != regno2)
18953     return true;
18954
18955   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18956     return false;
18957
18958   return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false);
18959 }
18960
18961 /* Return true if destination reg of SET_BODY is shift count of
18962    USE_BODY.  */
18963
18964 static bool
18965 ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
18966 {
18967   rtx set_dest;
18968   rtx shift_rtx;
18969   int i;
18970
18971   /* Retrieve destination of SET_BODY.  */
18972   switch (GET_CODE (set_body))
18973     {
18974     case SET:
18975       set_dest = SET_DEST (set_body);
18976       if (!set_dest || !REG_P (set_dest))
18977         return false;
18978       break;
18979     case PARALLEL:
18980       for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
18981         if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
18982                                           use_body))
18983           return true;
18984     default:
18985       return false;
18986       break;
18987     }
18988
18989   /* Retrieve shift count of USE_BODY.  */
18990   switch (GET_CODE (use_body))
18991     {
18992     case SET:
18993       shift_rtx = XEXP (use_body, 1);
18994       break;
18995     case PARALLEL:
18996       for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
18997         if (ix86_dep_by_shift_count_body (set_body,
18998                                           XVECEXP (use_body, 0, i)))
18999           return true;
19000     default:
19001       return false;
19002       break;
19003     }
19004
19005   if (shift_rtx
19006       && (GET_CODE (shift_rtx) == ASHIFT
19007           || GET_CODE (shift_rtx) == LSHIFTRT
19008           || GET_CODE (shift_rtx) == ASHIFTRT
19009           || GET_CODE (shift_rtx) == ROTATE
19010           || GET_CODE (shift_rtx) == ROTATERT))
19011     {
19012       rtx shift_count = XEXP (shift_rtx, 1);
19013
19014       /* Return true if shift count is dest of SET_BODY.  */
19015       if (REG_P (shift_count))
19016         {
19017           /* Add check since it can be invoked before register
19018              allocation in pre-reload schedule.  */
19019           if (reload_completed
19020               && true_regnum (set_dest) == true_regnum (shift_count))
19021             return true;
19022           else if (REGNO(set_dest) == REGNO(shift_count))
19023             return true;
19024         }
19025     }
19026
19027   return false;
19028 }
19029
19030 /* Return true if destination reg of SET_INSN is shift count of
19031    USE_INSN.  */
19032
19033 bool
19034 ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
19035 {
19036   return ix86_dep_by_shift_count_body (PATTERN (set_insn),
19037                                        PATTERN (use_insn));
19038 }
19039
19040 /* Return TRUE or FALSE depending on whether the unary operator meets the
19041    appropriate constraints.  */
19042
19043 bool
19044 ix86_unary_operator_ok (enum rtx_code,
19045                         machine_mode,
19046                         rtx operands[2])
19047 {
19048   /* If one of operands is memory, source and destination must match.  */
19049   if ((MEM_P (operands[0])
19050        || MEM_P (operands[1]))
19051       && ! rtx_equal_p (operands[0], operands[1]))
19052     return false;
19053   return true;
19054 }
19055
19056 /* Return TRUE if the operands to a vec_interleave_{high,low}v2df
19057    are ok, keeping in mind the possible movddup alternative.  */
19058
19059 bool
19060 ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high)
19061 {
19062   if (MEM_P (operands[0]))
19063     return rtx_equal_p (operands[0], operands[1 + high]);
19064   if (MEM_P (operands[1]) && MEM_P (operands[2]))
19065     return TARGET_SSE3 && rtx_equal_p (operands[1], operands[2]);
19066   return true;
19067 }
19068
19069 /* Post-reload splitter for converting an SF or DFmode value in an
19070    SSE register into an unsigned SImode.  */
19071
19072 void
19073 ix86_split_convert_uns_si_sse (rtx operands[])
19074 {
19075   machine_mode vecmode;
19076   rtx value, large, zero_or_two31, input, two31, x;
19077
19078   large = operands[1];
19079   zero_or_two31 = operands[2];
19080   input = operands[3];
19081   two31 = operands[4];
19082   vecmode = GET_MODE (large);
19083   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
19084
19085   /* Load up the value into the low element.  We must ensure that the other
19086      elements are valid floats -- zero is the easiest such value.  */
19087   if (MEM_P (input))
19088     {
19089       if (vecmode == V4SFmode)
19090         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
19091       else
19092         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
19093     }
19094   else
19095     {
19096       input = gen_rtx_REG (vecmode, REGNO (input));
19097       emit_move_insn (value, CONST0_RTX (vecmode));
19098       if (vecmode == V4SFmode)
19099         emit_insn (gen_sse_movss (value, value, input));
19100       else
19101         emit_insn (gen_sse2_movsd (value, value, input));
19102     }
19103
19104   emit_move_insn (large, two31);
19105   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
19106
19107   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
19108   emit_insn (gen_rtx_SET (VOIDmode, large, x));
19109
19110   x = gen_rtx_AND (vecmode, zero_or_two31, large);
19111   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
19112
19113   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
19114   emit_insn (gen_rtx_SET (VOIDmode, value, x));
19115
19116   large = gen_rtx_REG (V4SImode, REGNO (large));
19117   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
19118
19119   x = gen_rtx_REG (V4SImode, REGNO (value));
19120   if (vecmode == V4SFmode)
19121     emit_insn (gen_fix_truncv4sfv4si2 (x, value));
19122   else
19123     emit_insn (gen_sse2_cvttpd2dq (x, value));
19124   value = x;
19125
19126   emit_insn (gen_xorv4si3 (value, value, large));
19127 }
19128
19129 /* Convert an unsigned DImode value into a DFmode, using only SSE.
19130    Expects the 64-bit DImode to be supplied in a pair of integral
19131    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
19132    -mfpmath=sse, !optimize_size only.  */
19133
19134 void
19135 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
19136 {
19137   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
19138   rtx int_xmm, fp_xmm;
19139   rtx biases, exponents;
19140   rtx x;
19141
19142   int_xmm = gen_reg_rtx (V4SImode);
19143   if (TARGET_INTER_UNIT_MOVES_TO_VEC)
19144     emit_insn (gen_movdi_to_sse (int_xmm, input));
19145   else if (TARGET_SSE_SPLIT_REGS)
19146     {
19147       emit_clobber (int_xmm);
19148       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
19149     }
19150   else
19151     {
19152       x = gen_reg_rtx (V2DImode);
19153       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
19154       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
19155     }
19156
19157   x = gen_rtx_CONST_VECTOR (V4SImode,
19158                             gen_rtvec (4, GEN_INT (0x43300000UL),
19159                                        GEN_INT (0x45300000UL),
19160                                        const0_rtx, const0_rtx));
19161   exponents = validize_mem (force_const_mem (V4SImode, x));
19162
19163   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
19164   emit_insn (gen_vec_interleave_lowv4si (int_xmm, int_xmm, exponents));
19165
19166   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
19167      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
19168      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
19169      (0x1.0p84 + double(fp_value_hi_xmm)).
19170      Note these exponents differ by 32.  */
19171
19172   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
19173
19174   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
19175      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
19176   real_ldexp (&bias_lo_rvt, &dconst1, 52);
19177   real_ldexp (&bias_hi_rvt, &dconst1, 84);
19178   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
19179   x = const_double_from_real_value (bias_hi_rvt, DFmode);
19180   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
19181   biases = validize_mem (force_const_mem (V2DFmode, biases));
19182   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
19183
19184   /* Add the upper and lower DFmode values together.  */
19185   if (TARGET_SSE3)
19186     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
19187   else
19188     {
19189       x = copy_to_mode_reg (V2DFmode, fp_xmm);
19190       emit_insn (gen_vec_interleave_highv2df (fp_xmm, fp_xmm, fp_xmm));
19191       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
19192     }
19193
19194   ix86_expand_vector_extract (false, target, fp_xmm, 0);
19195 }
19196
19197 /* Not used, but eases macroization of patterns.  */
19198 void
19199 ix86_expand_convert_uns_sixf_sse (rtx, rtx)
19200 {
19201   gcc_unreachable ();
19202 }
19203
19204 /* Convert an unsigned SImode value into a DFmode.  Only currently used
19205    for SSE, but applicable anywhere.  */
19206
19207 void
19208 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
19209 {
19210   REAL_VALUE_TYPE TWO31r;
19211   rtx x, fp;
19212
19213   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
19214                            NULL, 1, OPTAB_DIRECT);
19215
19216   fp = gen_reg_rtx (DFmode);
19217   emit_insn (gen_floatsidf2 (fp, x));
19218
19219   real_ldexp (&TWO31r, &dconst1, 31);
19220   x = const_double_from_real_value (TWO31r, DFmode);
19221
19222   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
19223   if (x != target)
19224     emit_move_insn (target, x);
19225 }
19226
19227 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
19228    32-bit mode; otherwise we have a direct convert instruction.  */
19229
19230 void
19231 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
19232 {
19233   REAL_VALUE_TYPE TWO32r;
19234   rtx fp_lo, fp_hi, x;
19235
19236   fp_lo = gen_reg_rtx (DFmode);
19237   fp_hi = gen_reg_rtx (DFmode);
19238
19239   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
19240
19241   real_ldexp (&TWO32r, &dconst1, 32);
19242   x = const_double_from_real_value (TWO32r, DFmode);
19243   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
19244
19245   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
19246
19247   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
19248                            0, OPTAB_DIRECT);
19249   if (x != target)
19250     emit_move_insn (target, x);
19251 }
19252
19253 /* Convert an unsigned SImode value into a SFmode, using only SSE.
19254    For x86_32, -mfpmath=sse, !optimize_size only.  */
19255 void
19256 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
19257 {
19258   REAL_VALUE_TYPE ONE16r;
19259   rtx fp_hi, fp_lo, int_hi, int_lo, x;
19260
19261   real_ldexp (&ONE16r, &dconst1, 16);
19262   x = const_double_from_real_value (ONE16r, SFmode);
19263   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
19264                                       NULL, 0, OPTAB_DIRECT);
19265   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
19266                                       NULL, 0, OPTAB_DIRECT);
19267   fp_hi = gen_reg_rtx (SFmode);
19268   fp_lo = gen_reg_rtx (SFmode);
19269   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
19270   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
19271   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
19272                                0, OPTAB_DIRECT);
19273   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
19274                                0, OPTAB_DIRECT);
19275   if (!rtx_equal_p (target, fp_hi))
19276     emit_move_insn (target, fp_hi);
19277 }
19278
19279 /* floatunsv{4,8}siv{4,8}sf2 expander.  Expand code to convert
19280    a vector of unsigned ints VAL to vector of floats TARGET.  */
19281
19282 void
19283 ix86_expand_vector_convert_uns_vsivsf (rtx target, rtx val)
19284 {
19285   rtx tmp[8];
19286   REAL_VALUE_TYPE TWO16r;
19287   machine_mode intmode = GET_MODE (val);
19288   machine_mode fltmode = GET_MODE (target);
19289   rtx (*cvt) (rtx, rtx);
19290
19291   if (intmode == V4SImode)
19292     cvt = gen_floatv4siv4sf2;
19293   else
19294     cvt = gen_floatv8siv8sf2;
19295   tmp[0] = ix86_build_const_vector (intmode, 1, GEN_INT (0xffff));
19296   tmp[0] = force_reg (intmode, tmp[0]);
19297   tmp[1] = expand_simple_binop (intmode, AND, val, tmp[0], NULL_RTX, 1,
19298                                 OPTAB_DIRECT);
19299   tmp[2] = expand_simple_binop (intmode, LSHIFTRT, val, GEN_INT (16),
19300                                 NULL_RTX, 1, OPTAB_DIRECT);
19301   tmp[3] = gen_reg_rtx (fltmode);
19302   emit_insn (cvt (tmp[3], tmp[1]));
19303   tmp[4] = gen_reg_rtx (fltmode);
19304   emit_insn (cvt (tmp[4], tmp[2]));
19305   real_ldexp (&TWO16r, &dconst1, 16);
19306   tmp[5] = const_double_from_real_value (TWO16r, SFmode);
19307   tmp[5] = force_reg (fltmode, ix86_build_const_vector (fltmode, 1, tmp[5]));
19308   tmp[6] = expand_simple_binop (fltmode, MULT, tmp[4], tmp[5], NULL_RTX, 1,
19309                                 OPTAB_DIRECT);
19310   tmp[7] = expand_simple_binop (fltmode, PLUS, tmp[3], tmp[6], target, 1,
19311                                 OPTAB_DIRECT);
19312   if (tmp[7] != target)
19313     emit_move_insn (target, tmp[7]);
19314 }
19315
19316 /* Adjust a V*SFmode/V*DFmode value VAL so that *sfix_trunc* resp. fix_trunc*
19317    pattern can be used on it instead of *ufix_trunc* resp. fixuns_trunc*.
19318    This is done by doing just signed conversion if < 0x1p31, and otherwise by
19319    subtracting 0x1p31 first and xoring in 0x80000000 from *XORP afterwards.  */
19320
19321 rtx
19322 ix86_expand_adjust_ufix_to_sfix_si (rtx val, rtx *xorp)
19323 {
19324   REAL_VALUE_TYPE TWO31r;
19325   rtx two31r, tmp[4];
19326   machine_mode mode = GET_MODE (val);
19327   machine_mode scalarmode = GET_MODE_INNER (mode);
19328   machine_mode intmode = GET_MODE_SIZE (mode) == 32 ? V8SImode : V4SImode;
19329   rtx (*cmp) (rtx, rtx, rtx, rtx);
19330   int i;
19331
19332   for (i = 0; i < 3; i++)
19333     tmp[i] = gen_reg_rtx (mode);
19334   real_ldexp (&TWO31r, &dconst1, 31);
19335   two31r = const_double_from_real_value (TWO31r, scalarmode);
19336   two31r = ix86_build_const_vector (mode, 1, two31r);
19337   two31r = force_reg (mode, two31r);
19338   switch (mode)
19339     {
19340     case V8SFmode: cmp = gen_avx_maskcmpv8sf3; break;
19341     case V4SFmode: cmp = gen_sse_maskcmpv4sf3; break;
19342     case V4DFmode: cmp = gen_avx_maskcmpv4df3; break;
19343     case V2DFmode: cmp = gen_sse2_maskcmpv2df3; break;
19344     default: gcc_unreachable ();
19345     }
19346   tmp[3] = gen_rtx_LE (mode, two31r, val);
19347   emit_insn (cmp (tmp[0], two31r, val, tmp[3]));
19348   tmp[1] = expand_simple_binop (mode, AND, tmp[0], two31r, tmp[1],
19349                                 0, OPTAB_DIRECT);
19350   if (intmode == V4SImode || TARGET_AVX2)
19351     *xorp = expand_simple_binop (intmode, ASHIFT,
19352                                  gen_lowpart (intmode, tmp[0]),
19353                                  GEN_INT (31), NULL_RTX, 0,
19354                                  OPTAB_DIRECT);
19355   else
19356     {
19357       rtx two31 = GEN_INT ((unsigned HOST_WIDE_INT) 1 << 31);
19358       two31 = ix86_build_const_vector (intmode, 1, two31);
19359       *xorp = expand_simple_binop (intmode, AND,
19360                                    gen_lowpart (intmode, tmp[0]),
19361                                    two31, NULL_RTX, 0,
19362                                    OPTAB_DIRECT);
19363     }
19364   return expand_simple_binop (mode, MINUS, val, tmp[1], tmp[2],
19365                               0, OPTAB_DIRECT);
19366 }
19367
19368 /* A subroutine of ix86_build_signbit_mask.  If VECT is true,
19369    then replicate the value for all elements of the vector
19370    register.  */
19371
19372 rtx
19373 ix86_build_const_vector (machine_mode mode, bool vect, rtx value)
19374 {
19375   int i, n_elt;
19376   rtvec v;
19377   machine_mode scalar_mode;
19378
19379   switch (mode)
19380     {
19381     case V64QImode:
19382     case V32QImode:
19383     case V16QImode:
19384     case V32HImode:
19385     case V16HImode:
19386     case V8HImode:
19387     case V16SImode:
19388     case V8SImode:
19389     case V4SImode:
19390     case V8DImode:
19391     case V4DImode:
19392     case V2DImode:
19393       gcc_assert (vect);
19394     case V16SFmode:
19395     case V8SFmode:
19396     case V4SFmode:
19397     case V8DFmode:
19398     case V4DFmode:
19399     case V2DFmode:
19400       n_elt = GET_MODE_NUNITS (mode);
19401       v = rtvec_alloc (n_elt);
19402       scalar_mode = GET_MODE_INNER (mode);
19403
19404       RTVEC_ELT (v, 0) = value;
19405
19406       for (i = 1; i < n_elt; ++i)
19407         RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode);
19408
19409       return gen_rtx_CONST_VECTOR (mode, v);
19410
19411     default:
19412       gcc_unreachable ();
19413     }
19414 }
19415
19416 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
19417    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
19418    for an SSE register.  If VECT is true, then replicate the mask for
19419    all elements of the vector register.  If INVERT is true, then create
19420    a mask excluding the sign bit.  */
19421
19422 rtx
19423 ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert)
19424 {
19425   machine_mode vec_mode, imode;
19426   HOST_WIDE_INT hi, lo;
19427   int shift = 63;
19428   rtx v;
19429   rtx mask;
19430
19431   /* Find the sign bit, sign extended to 2*HWI.  */
19432   switch (mode)
19433     {
19434     case V16SImode:
19435     case V16SFmode:
19436     case V8SImode:
19437     case V4SImode:
19438     case V8SFmode:
19439     case V4SFmode:
19440       vec_mode = mode;
19441       mode = GET_MODE_INNER (mode);
19442       imode = SImode;
19443       lo = 0x80000000, hi = lo < 0;
19444       break;
19445
19446     case V8DImode:
19447     case V4DImode:
19448     case V2DImode:
19449     case V8DFmode:
19450     case V4DFmode:
19451     case V2DFmode:
19452       vec_mode = mode;
19453       mode = GET_MODE_INNER (mode);
19454       imode = DImode;
19455       if (HOST_BITS_PER_WIDE_INT >= 64)
19456         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
19457       else
19458         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
19459       break;
19460
19461     case TImode:
19462     case TFmode:
19463       vec_mode = VOIDmode;
19464       if (HOST_BITS_PER_WIDE_INT >= 64)
19465         {
19466           imode = TImode;
19467           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
19468         }
19469       else
19470         {
19471           rtvec vec;
19472
19473           imode = DImode;
19474           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
19475
19476           if (invert)
19477             {
19478               lo = ~lo, hi = ~hi;
19479               v = constm1_rtx;
19480             }
19481           else
19482             v = const0_rtx;
19483
19484           mask = immed_double_const (lo, hi, imode);
19485
19486           vec = gen_rtvec (2, v, mask);
19487           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
19488           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
19489
19490           return v;
19491         }
19492      break;
19493
19494     default:
19495       gcc_unreachable ();
19496     }
19497
19498   if (invert)
19499     lo = ~lo, hi = ~hi;
19500
19501   /* Force this value into the low part of a fp vector constant.  */
19502   mask = immed_double_const (lo, hi, imode);
19503   mask = gen_lowpart (mode, mask);
19504
19505   if (vec_mode == VOIDmode)
19506     return force_reg (mode, mask);
19507
19508   v = ix86_build_const_vector (vec_mode, vect, mask);
19509   return force_reg (vec_mode, v);
19510 }
19511
19512 /* Generate code for floating point ABS or NEG.  */
19513
19514 void
19515 ix86_expand_fp_absneg_operator (enum rtx_code code, machine_mode mode,
19516                                 rtx operands[])
19517 {
19518   rtx mask, set, dst, src;
19519   bool use_sse = false;
19520   bool vector_mode = VECTOR_MODE_P (mode);
19521   machine_mode vmode = mode;
19522
19523   if (vector_mode)
19524     use_sse = true;
19525   else if (mode == TFmode)
19526     use_sse = true;
19527   else if (TARGET_SSE_MATH)
19528     {
19529       use_sse = SSE_FLOAT_MODE_P (mode);
19530       if (mode == SFmode)
19531         vmode = V4SFmode;
19532       else if (mode == DFmode)
19533         vmode = V2DFmode;
19534     }
19535
19536   /* NEG and ABS performed with SSE use bitwise mask operations.
19537      Create the appropriate mask now.  */
19538   if (use_sse)
19539     mask = ix86_build_signbit_mask (vmode, vector_mode, code == ABS);
19540   else
19541     mask = NULL_RTX;
19542
19543   dst = operands[0];
19544   src = operands[1];
19545
19546   set = gen_rtx_fmt_e (code, mode, src);
19547   set = gen_rtx_SET (VOIDmode, dst, set);
19548
19549   if (mask)
19550     {
19551       rtx use, clob;
19552       rtvec par;
19553
19554       use = gen_rtx_USE (VOIDmode, mask);
19555       if (vector_mode)
19556         par = gen_rtvec (2, set, use);
19557       else
19558         {
19559           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
19560           par = gen_rtvec (3, set, use, clob);
19561         }
19562       emit_insn (gen_rtx_PARALLEL (VOIDmode, par));
19563     }
19564   else
19565     emit_insn (set);
19566 }
19567
19568 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
19569
19570 void
19571 ix86_expand_copysign (rtx operands[])
19572 {
19573   machine_mode mode, vmode;
19574   rtx dest, op0, op1, mask, nmask;
19575
19576   dest = operands[0];
19577   op0 = operands[1];
19578   op1 = operands[2];
19579
19580   mode = GET_MODE (dest);
19581
19582   if (mode == SFmode)
19583     vmode = V4SFmode;
19584   else if (mode == DFmode)
19585     vmode = V2DFmode;
19586   else
19587     vmode = mode;
19588
19589   if (GET_CODE (op0) == CONST_DOUBLE)
19590     {
19591       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
19592
19593       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
19594         op0 = simplify_unary_operation (ABS, mode, op0, mode);
19595
19596       if (mode == SFmode || mode == DFmode)
19597         {
19598           if (op0 == CONST0_RTX (mode))
19599             op0 = CONST0_RTX (vmode);
19600           else
19601             {
19602               rtx v = ix86_build_const_vector (vmode, false, op0);
19603
19604               op0 = force_reg (vmode, v);
19605             }
19606         }
19607       else if (op0 != CONST0_RTX (mode))
19608         op0 = force_reg (mode, op0);
19609
19610       mask = ix86_build_signbit_mask (vmode, 0, 0);
19611
19612       if (mode == SFmode)
19613         copysign_insn = gen_copysignsf3_const;
19614       else if (mode == DFmode)
19615         copysign_insn = gen_copysigndf3_const;
19616       else
19617         copysign_insn = gen_copysigntf3_const;
19618
19619         emit_insn (copysign_insn (dest, op0, op1, mask));
19620     }
19621   else
19622     {
19623       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
19624
19625       nmask = ix86_build_signbit_mask (vmode, 0, 1);
19626       mask = ix86_build_signbit_mask (vmode, 0, 0);
19627
19628       if (mode == SFmode)
19629         copysign_insn = gen_copysignsf3_var;
19630       else if (mode == DFmode)
19631         copysign_insn = gen_copysigndf3_var;
19632       else
19633         copysign_insn = gen_copysigntf3_var;
19634
19635       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
19636     }
19637 }
19638
19639 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
19640    be a constant, and so has already been expanded into a vector constant.  */
19641
19642 void
19643 ix86_split_copysign_const (rtx operands[])
19644 {
19645   machine_mode mode, vmode;
19646   rtx dest, op0, mask, x;
19647
19648   dest = operands[0];
19649   op0 = operands[1];
19650   mask = operands[3];
19651
19652   mode = GET_MODE (dest);
19653   vmode = GET_MODE (mask);
19654
19655   dest = simplify_gen_subreg (vmode, dest, mode, 0);
19656   x = gen_rtx_AND (vmode, dest, mask);
19657   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19658
19659   if (op0 != CONST0_RTX (vmode))
19660     {
19661       x = gen_rtx_IOR (vmode, dest, op0);
19662       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19663     }
19664 }
19665
19666 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
19667    so we have to do two masks.  */
19668
19669 void
19670 ix86_split_copysign_var (rtx operands[])
19671 {
19672   machine_mode mode, vmode;
19673   rtx dest, scratch, op0, op1, mask, nmask, x;
19674
19675   dest = operands[0];
19676   scratch = operands[1];
19677   op0 = operands[2];
19678   op1 = operands[3];
19679   nmask = operands[4];
19680   mask = operands[5];
19681
19682   mode = GET_MODE (dest);
19683   vmode = GET_MODE (mask);
19684
19685   if (rtx_equal_p (op0, op1))
19686     {
19687       /* Shouldn't happen often (it's useless, obviously), but when it does
19688          we'd generate incorrect code if we continue below.  */
19689       emit_move_insn (dest, op0);
19690       return;
19691     }
19692
19693   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
19694     {
19695       gcc_assert (REGNO (op1) == REGNO (scratch));
19696
19697       x = gen_rtx_AND (vmode, scratch, mask);
19698       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
19699
19700       dest = mask;
19701       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
19702       x = gen_rtx_NOT (vmode, dest);
19703       x = gen_rtx_AND (vmode, x, op0);
19704       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19705     }
19706   else
19707     {
19708       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
19709         {
19710           x = gen_rtx_AND (vmode, scratch, mask);
19711         }
19712       else                                              /* alternative 2,4 */
19713         {
19714           gcc_assert (REGNO (mask) == REGNO (scratch));
19715           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
19716           x = gen_rtx_AND (vmode, scratch, op1);
19717         }
19718       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
19719
19720       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
19721         {
19722           dest = simplify_gen_subreg (vmode, op0, mode, 0);
19723           x = gen_rtx_AND (vmode, dest, nmask);
19724         }
19725       else                                              /* alternative 3,4 */
19726         {
19727           gcc_assert (REGNO (nmask) == REGNO (dest));
19728           dest = nmask;
19729           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
19730           x = gen_rtx_AND (vmode, dest, op0);
19731         }
19732       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19733     }
19734
19735   x = gen_rtx_IOR (vmode, dest, scratch);
19736   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19737 }
19738
19739 /* Return TRUE or FALSE depending on whether the first SET in INSN
19740    has source and destination with matching CC modes, and that the
19741    CC mode is at least as constrained as REQ_MODE.  */
19742
19743 bool
19744 ix86_match_ccmode (rtx insn, machine_mode req_mode)
19745 {
19746   rtx set;
19747   machine_mode set_mode;
19748
19749   set = PATTERN (insn);
19750   if (GET_CODE (set) == PARALLEL)
19751     set = XVECEXP (set, 0, 0);
19752   gcc_assert (GET_CODE (set) == SET);
19753   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
19754
19755   set_mode = GET_MODE (SET_DEST (set));
19756   switch (set_mode)
19757     {
19758     case CCNOmode:
19759       if (req_mode != CCNOmode
19760           && (req_mode != CCmode
19761               || XEXP (SET_SRC (set), 1) != const0_rtx))
19762         return false;
19763       break;
19764     case CCmode:
19765       if (req_mode == CCGCmode)
19766         return false;
19767       /* FALLTHRU */
19768     case CCGCmode:
19769       if (req_mode == CCGOCmode || req_mode == CCNOmode)
19770         return false;
19771       /* FALLTHRU */
19772     case CCGOCmode:
19773       if (req_mode == CCZmode)
19774         return false;
19775       /* FALLTHRU */
19776     case CCZmode:
19777       break;
19778
19779     case CCAmode:
19780     case CCCmode:
19781     case CCOmode:
19782     case CCSmode:
19783       if (set_mode != req_mode)
19784         return false;
19785       break;
19786
19787     default:
19788       gcc_unreachable ();
19789     }
19790
19791   return GET_MODE (SET_SRC (set)) == set_mode;
19792 }
19793
19794 /* Generate insn patterns to do an integer compare of OPERANDS.  */
19795
19796 static rtx
19797 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
19798 {
19799   machine_mode cmpmode;
19800   rtx tmp, flags;
19801
19802   cmpmode = SELECT_CC_MODE (code, op0, op1);
19803   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
19804
19805   /* This is very simple, but making the interface the same as in the
19806      FP case makes the rest of the code easier.  */
19807   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
19808   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
19809
19810   /* Return the test that should be put into the flags user, i.e.
19811      the bcc, scc, or cmov instruction.  */
19812   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
19813 }
19814
19815 /* Figure out whether to use ordered or unordered fp comparisons.
19816    Return the appropriate mode to use.  */
19817
19818 machine_mode
19819 ix86_fp_compare_mode (enum rtx_code)
19820 {
19821   /* ??? In order to make all comparisons reversible, we do all comparisons
19822      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
19823      all forms trapping and nontrapping comparisons, we can make inequality
19824      comparisons trapping again, since it results in better code when using
19825      FCOM based compares.  */
19826   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
19827 }
19828
19829 machine_mode
19830 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
19831 {
19832   machine_mode mode = GET_MODE (op0);
19833
19834   if (SCALAR_FLOAT_MODE_P (mode))
19835     {
19836       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
19837       return ix86_fp_compare_mode (code);
19838     }
19839
19840   switch (code)
19841     {
19842       /* Only zero flag is needed.  */
19843     case EQ:                    /* ZF=0 */
19844     case NE:                    /* ZF!=0 */
19845       return CCZmode;
19846       /* Codes needing carry flag.  */
19847     case GEU:                   /* CF=0 */
19848     case LTU:                   /* CF=1 */
19849       /* Detect overflow checks.  They need just the carry flag.  */
19850       if (GET_CODE (op0) == PLUS
19851           && rtx_equal_p (op1, XEXP (op0, 0)))
19852         return CCCmode;
19853       else
19854         return CCmode;
19855     case GTU:                   /* CF=0 & ZF=0 */
19856     case LEU:                   /* CF=1 | ZF=1 */
19857       return CCmode;
19858       /* Codes possibly doable only with sign flag when
19859          comparing against zero.  */
19860     case GE:                    /* SF=OF   or   SF=0 */
19861     case LT:                    /* SF<>OF  or   SF=1 */
19862       if (op1 == const0_rtx)
19863         return CCGOCmode;
19864       else
19865         /* For other cases Carry flag is not required.  */
19866         return CCGCmode;
19867       /* Codes doable only with sign flag when comparing
19868          against zero, but we miss jump instruction for it
19869          so we need to use relational tests against overflow
19870          that thus needs to be zero.  */
19871     case GT:                    /* ZF=0 & SF=OF */
19872     case LE:                    /* ZF=1 | SF<>OF */
19873       if (op1 == const0_rtx)
19874         return CCNOmode;
19875       else
19876         return CCGCmode;
19877       /* strcmp pattern do (use flags) and combine may ask us for proper
19878          mode.  */
19879     case USE:
19880       return CCmode;
19881     default:
19882       gcc_unreachable ();
19883     }
19884 }
19885
19886 /* Return the fixed registers used for condition codes.  */
19887
19888 static bool
19889 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
19890 {
19891   *p1 = FLAGS_REG;
19892   *p2 = FPSR_REG;
19893   return true;
19894 }
19895
19896 /* If two condition code modes are compatible, return a condition code
19897    mode which is compatible with both.  Otherwise, return
19898    VOIDmode.  */
19899
19900 static machine_mode
19901 ix86_cc_modes_compatible (machine_mode m1, machine_mode m2)
19902 {
19903   if (m1 == m2)
19904     return m1;
19905
19906   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
19907     return VOIDmode;
19908
19909   if ((m1 == CCGCmode && m2 == CCGOCmode)
19910       || (m1 == CCGOCmode && m2 == CCGCmode))
19911     return CCGCmode;
19912
19913   if (m1 == CCZmode && (m2 == CCGCmode || m2 == CCGOCmode))
19914     return m2;
19915   else if (m2 == CCZmode && (m1 == CCGCmode || m1 == CCGOCmode))
19916     return m1;
19917
19918   switch (m1)
19919     {
19920     default:
19921       gcc_unreachable ();
19922
19923     case CCmode:
19924     case CCGCmode:
19925     case CCGOCmode:
19926     case CCNOmode:
19927     case CCAmode:
19928     case CCCmode:
19929     case CCOmode:
19930     case CCSmode:
19931     case CCZmode:
19932       switch (m2)
19933         {
19934         default:
19935           return VOIDmode;
19936
19937         case CCmode:
19938         case CCGCmode:
19939         case CCGOCmode:
19940         case CCNOmode:
19941         case CCAmode:
19942         case CCCmode:
19943         case CCOmode:
19944         case CCSmode:
19945         case CCZmode:
19946           return CCmode;
19947         }
19948
19949     case CCFPmode:
19950     case CCFPUmode:
19951       /* These are only compatible with themselves, which we already
19952          checked above.  */
19953       return VOIDmode;
19954     }
19955 }
19956
19957
19958 /* Return a comparison we can do and that it is equivalent to
19959    swap_condition (code) apart possibly from orderedness.
19960    But, never change orderedness if TARGET_IEEE_FP, returning
19961    UNKNOWN in that case if necessary.  */
19962
19963 static enum rtx_code
19964 ix86_fp_swap_condition (enum rtx_code code)
19965 {
19966   switch (code)
19967     {
19968     case GT:                   /* GTU - CF=0 & ZF=0 */
19969       return TARGET_IEEE_FP ? UNKNOWN : UNLT;
19970     case GE:                   /* GEU - CF=0 */
19971       return TARGET_IEEE_FP ? UNKNOWN : UNLE;
19972     case UNLT:                 /* LTU - CF=1 */
19973       return TARGET_IEEE_FP ? UNKNOWN : GT;
19974     case UNLE:                 /* LEU - CF=1 | ZF=1 */
19975       return TARGET_IEEE_FP ? UNKNOWN : GE;
19976     default:
19977       return swap_condition (code);
19978     }
19979 }
19980
19981 /* Return cost of comparison CODE using the best strategy for performance.
19982    All following functions do use number of instructions as a cost metrics.
19983    In future this should be tweaked to compute bytes for optimize_size and
19984    take into account performance of various instructions on various CPUs.  */
19985
19986 static int
19987 ix86_fp_comparison_cost (enum rtx_code code)
19988 {
19989   int arith_cost;
19990
19991   /* The cost of code using bit-twiddling on %ah.  */
19992   switch (code)
19993     {
19994     case UNLE:
19995     case UNLT:
19996     case LTGT:
19997     case GT:
19998     case GE:
19999     case UNORDERED:
20000     case ORDERED:
20001     case UNEQ:
20002       arith_cost = 4;
20003       break;
20004     case LT:
20005     case NE:
20006     case EQ:
20007     case UNGE:
20008       arith_cost = TARGET_IEEE_FP ? 5 : 4;
20009       break;
20010     case LE:
20011     case UNGT:
20012       arith_cost = TARGET_IEEE_FP ? 6 : 4;
20013       break;
20014     default:
20015       gcc_unreachable ();
20016     }
20017
20018   switch (ix86_fp_comparison_strategy (code))
20019     {
20020     case IX86_FPCMP_COMI:
20021       return arith_cost > 4 ? 3 : 2;
20022     case IX86_FPCMP_SAHF:
20023       return arith_cost > 4 ? 4 : 3;
20024     default:
20025       return arith_cost;
20026     }
20027 }
20028
20029 /* Return strategy to use for floating-point.  We assume that fcomi is always
20030    preferrable where available, since that is also true when looking at size
20031    (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test).  */
20032
20033 enum ix86_fpcmp_strategy
20034 ix86_fp_comparison_strategy (enum rtx_code)
20035 {
20036   /* Do fcomi/sahf based test when profitable.  */
20037
20038   if (TARGET_CMOVE)
20039     return IX86_FPCMP_COMI;
20040
20041   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
20042     return IX86_FPCMP_SAHF;
20043
20044   return IX86_FPCMP_ARITH;
20045 }
20046
20047 /* Swap, force into registers, or otherwise massage the two operands
20048    to a fp comparison.  The operands are updated in place; the new
20049    comparison code is returned.  */
20050
20051 static enum rtx_code
20052 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
20053 {
20054   machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
20055   rtx op0 = *pop0, op1 = *pop1;
20056   machine_mode op_mode = GET_MODE (op0);
20057   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
20058
20059   /* All of the unordered compare instructions only work on registers.
20060      The same is true of the fcomi compare instructions.  The XFmode
20061      compare instructions require registers except when comparing
20062      against zero or when converting operand 1 from fixed point to
20063      floating point.  */
20064
20065   if (!is_sse
20066       && (fpcmp_mode == CCFPUmode
20067           || (op_mode == XFmode
20068               && ! (standard_80387_constant_p (op0) == 1
20069                     || standard_80387_constant_p (op1) == 1)
20070               && GET_CODE (op1) != FLOAT)
20071           || ix86_fp_comparison_strategy (code) == IX86_FPCMP_COMI))
20072     {
20073       op0 = force_reg (op_mode, op0);
20074       op1 = force_reg (op_mode, op1);
20075     }
20076   else
20077     {
20078       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
20079          things around if they appear profitable, otherwise force op0
20080          into a register.  */
20081
20082       if (standard_80387_constant_p (op0) == 0
20083           || (MEM_P (op0)
20084               && ! (standard_80387_constant_p (op1) == 0
20085                     || MEM_P (op1))))
20086         {
20087           enum rtx_code new_code = ix86_fp_swap_condition (code);
20088           if (new_code != UNKNOWN)
20089             {
20090               std::swap (op0, op1);
20091               code = new_code;
20092             }
20093         }
20094
20095       if (!REG_P (op0))
20096         op0 = force_reg (op_mode, op0);
20097
20098       if (CONSTANT_P (op1))
20099         {
20100           int tmp = standard_80387_constant_p (op1);
20101           if (tmp == 0)
20102             op1 = validize_mem (force_const_mem (op_mode, op1));
20103           else if (tmp == 1)
20104             {
20105               if (TARGET_CMOVE)
20106                 op1 = force_reg (op_mode, op1);
20107             }
20108           else
20109             op1 = force_reg (op_mode, op1);
20110         }
20111     }
20112
20113   /* Try to rearrange the comparison to make it cheaper.  */
20114   if (ix86_fp_comparison_cost (code)
20115       > ix86_fp_comparison_cost (swap_condition (code))
20116       && (REG_P (op1) || can_create_pseudo_p ()))
20117     {
20118       std::swap (op0, op1);
20119       code = swap_condition (code);
20120       if (!REG_P (op0))
20121         op0 = force_reg (op_mode, op0);
20122     }
20123
20124   *pop0 = op0;
20125   *pop1 = op1;
20126   return code;
20127 }
20128
20129 /* Convert comparison codes we use to represent FP comparison to integer
20130    code that will result in proper branch.  Return UNKNOWN if no such code
20131    is available.  */
20132
20133 enum rtx_code
20134 ix86_fp_compare_code_to_integer (enum rtx_code code)
20135 {
20136   switch (code)
20137     {
20138     case GT:
20139       return GTU;
20140     case GE:
20141       return GEU;
20142     case ORDERED:
20143     case UNORDERED:
20144       return code;
20145       break;
20146     case UNEQ:
20147       return EQ;
20148       break;
20149     case UNLT:
20150       return LTU;
20151       break;
20152     case UNLE:
20153       return LEU;
20154       break;
20155     case LTGT:
20156       return NE;
20157       break;
20158     default:
20159       return UNKNOWN;
20160     }
20161 }
20162
20163 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
20164
20165 static rtx
20166 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch)
20167 {
20168   machine_mode fpcmp_mode, intcmp_mode;
20169   rtx tmp, tmp2;
20170
20171   fpcmp_mode = ix86_fp_compare_mode (code);
20172   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
20173
20174   /* Do fcomi/sahf based test when profitable.  */
20175   switch (ix86_fp_comparison_strategy (code))
20176     {
20177     case IX86_FPCMP_COMI:
20178       intcmp_mode = fpcmp_mode;
20179       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20180       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
20181                          tmp);
20182       emit_insn (tmp);
20183       break;
20184
20185     case IX86_FPCMP_SAHF:
20186       intcmp_mode = fpcmp_mode;
20187       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20188       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
20189                          tmp);
20190
20191       if (!scratch)
20192         scratch = gen_reg_rtx (HImode);
20193       tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
20194       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
20195       break;
20196
20197     case IX86_FPCMP_ARITH:
20198       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
20199       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20200       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
20201       if (!scratch)
20202         scratch = gen_reg_rtx (HImode);
20203       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
20204
20205       /* In the unordered case, we have to check C2 for NaN's, which
20206          doesn't happen to work out to anything nice combination-wise.
20207          So do some bit twiddling on the value we've got in AH to come
20208          up with an appropriate set of condition codes.  */
20209
20210       intcmp_mode = CCNOmode;
20211       switch (code)
20212         {
20213         case GT:
20214         case UNGT:
20215           if (code == GT || !TARGET_IEEE_FP)
20216             {
20217               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
20218               code = EQ;
20219             }
20220           else
20221             {
20222               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20223               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
20224               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
20225               intcmp_mode = CCmode;
20226               code = GEU;
20227             }
20228           break;
20229         case LT:
20230         case UNLT:
20231           if (code == LT && TARGET_IEEE_FP)
20232             {
20233               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20234               emit_insn (gen_cmpqi_ext_3 (scratch, const1_rtx));
20235               intcmp_mode = CCmode;
20236               code = EQ;
20237             }
20238           else
20239             {
20240               emit_insn (gen_testqi_ext_ccno_0 (scratch, const1_rtx));
20241               code = NE;
20242             }
20243           break;
20244         case GE:
20245         case UNGE:
20246           if (code == GE || !TARGET_IEEE_FP)
20247             {
20248               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
20249               code = EQ;
20250             }
20251           else
20252             {
20253               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20254               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch, const1_rtx));
20255               code = NE;
20256             }
20257           break;
20258         case LE:
20259         case UNLE:
20260           if (code == LE && TARGET_IEEE_FP)
20261             {
20262               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20263               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
20264               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
20265               intcmp_mode = CCmode;
20266               code = LTU;
20267             }
20268           else
20269             {
20270               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
20271               code = NE;
20272             }
20273           break;
20274         case EQ:
20275         case UNEQ:
20276           if (code == EQ && TARGET_IEEE_FP)
20277             {
20278               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20279               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
20280               intcmp_mode = CCmode;
20281               code = EQ;
20282             }
20283           else
20284             {
20285               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
20286               code = NE;
20287             }
20288           break;
20289         case NE:
20290         case LTGT:
20291           if (code == NE && TARGET_IEEE_FP)
20292             {
20293               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20294               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
20295                                              GEN_INT (0x40)));
20296               code = NE;
20297             }
20298           else
20299             {
20300               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
20301               code = EQ;
20302             }
20303           break;
20304
20305         case UNORDERED:
20306           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
20307           code = NE;
20308           break;
20309         case ORDERED:
20310           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
20311           code = EQ;
20312           break;
20313
20314         default:
20315           gcc_unreachable ();
20316         }
20317         break;
20318
20319     default:
20320       gcc_unreachable();
20321     }
20322
20323   /* Return the test that should be put into the flags user, i.e.
20324      the bcc, scc, or cmov instruction.  */
20325   return gen_rtx_fmt_ee (code, VOIDmode,
20326                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
20327                          const0_rtx);
20328 }
20329
20330 static rtx
20331 ix86_expand_compare (enum rtx_code code, rtx op0, rtx op1)
20332 {
20333   rtx ret;
20334
20335   if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
20336     ret = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
20337
20338   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
20339     {
20340       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
20341       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
20342     }
20343   else
20344     ret = ix86_expand_int_compare (code, op0, op1);
20345
20346   return ret;
20347 }
20348
20349 void
20350 ix86_expand_branch (enum rtx_code code, rtx op0, rtx op1, rtx label)
20351 {
20352   machine_mode mode = GET_MODE (op0);
20353   rtx tmp;
20354
20355   switch (mode)
20356     {
20357     case SFmode:
20358     case DFmode:
20359     case XFmode:
20360     case QImode:
20361     case HImode:
20362     case SImode:
20363       simple:
20364       tmp = ix86_expand_compare (code, op0, op1);
20365       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
20366                                   gen_rtx_LABEL_REF (VOIDmode, label),
20367                                   pc_rtx);
20368       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
20369       return;
20370
20371     case DImode:
20372       if (TARGET_64BIT)
20373         goto simple;
20374     case TImode:
20375       /* Expand DImode branch into multiple compare+branch.  */
20376       {
20377         rtx lo[2], hi[2];
20378         rtx_code_label *label2;
20379         enum rtx_code code1, code2, code3;
20380         machine_mode submode;
20381
20382         if (CONSTANT_P (op0) && !CONSTANT_P (op1))
20383           {
20384             std::swap (op0, op1);
20385             code = swap_condition (code);
20386           }
20387
20388         split_double_mode (mode, &op0, 1, lo+0, hi+0);
20389         split_double_mode (mode, &op1, 1, lo+1, hi+1);
20390
20391         submode = mode == DImode ? SImode : DImode;
20392
20393         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
20394            avoid two branches.  This costs one extra insn, so disable when
20395            optimizing for size.  */
20396
20397         if ((code == EQ || code == NE)
20398             && (!optimize_insn_for_size_p ()
20399                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
20400           {
20401             rtx xor0, xor1;
20402
20403             xor1 = hi[0];
20404             if (hi[1] != const0_rtx)
20405               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
20406                                    NULL_RTX, 0, OPTAB_WIDEN);
20407
20408             xor0 = lo[0];
20409             if (lo[1] != const0_rtx)
20410               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
20411                                    NULL_RTX, 0, OPTAB_WIDEN);
20412
20413             tmp = expand_binop (submode, ior_optab, xor1, xor0,
20414                                 NULL_RTX, 0, OPTAB_WIDEN);
20415
20416             ix86_expand_branch (code, tmp, const0_rtx, label);
20417             return;
20418           }
20419
20420         /* Otherwise, if we are doing less-than or greater-or-equal-than,
20421            op1 is a constant and the low word is zero, then we can just
20422            examine the high word.  Similarly for low word -1 and
20423            less-or-equal-than or greater-than.  */
20424
20425         if (CONST_INT_P (hi[1]))
20426           switch (code)
20427             {
20428             case LT: case LTU: case GE: case GEU:
20429               if (lo[1] == const0_rtx)
20430                 {
20431                   ix86_expand_branch (code, hi[0], hi[1], label);
20432                   return;
20433                 }
20434               break;
20435             case LE: case LEU: case GT: case GTU:
20436               if (lo[1] == constm1_rtx)
20437                 {
20438                   ix86_expand_branch (code, hi[0], hi[1], label);
20439                   return;
20440                 }
20441               break;
20442             default:
20443               break;
20444             }
20445
20446         /* Otherwise, we need two or three jumps.  */
20447
20448         label2 = gen_label_rtx ();
20449
20450         code1 = code;
20451         code2 = swap_condition (code);
20452         code3 = unsigned_condition (code);
20453
20454         switch (code)
20455           {
20456           case LT: case GT: case LTU: case GTU:
20457             break;
20458
20459           case LE:   code1 = LT;  code2 = GT;  break;
20460           case GE:   code1 = GT;  code2 = LT;  break;
20461           case LEU:  code1 = LTU; code2 = GTU; break;
20462           case GEU:  code1 = GTU; code2 = LTU; break;
20463
20464           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
20465           case NE:   code2 = UNKNOWN; break;
20466
20467           default:
20468             gcc_unreachable ();
20469           }
20470
20471         /*
20472          * a < b =>
20473          *    if (hi(a) < hi(b)) goto true;
20474          *    if (hi(a) > hi(b)) goto false;
20475          *    if (lo(a) < lo(b)) goto true;
20476          *  false:
20477          */
20478
20479         if (code1 != UNKNOWN)
20480           ix86_expand_branch (code1, hi[0], hi[1], label);
20481         if (code2 != UNKNOWN)
20482           ix86_expand_branch (code2, hi[0], hi[1], label2);
20483
20484         ix86_expand_branch (code3, lo[0], lo[1], label);
20485
20486         if (code2 != UNKNOWN)
20487           emit_label (label2);
20488         return;
20489       }
20490
20491     default:
20492       gcc_assert (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC);
20493       goto simple;
20494     }
20495 }
20496
20497 /* Split branch based on floating point condition.  */
20498 void
20499 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
20500                       rtx target1, rtx target2, rtx tmp)
20501 {
20502   rtx condition;
20503   rtx i;
20504
20505   if (target2 != pc_rtx)
20506     {
20507       std::swap (target1, target2);
20508       code = reverse_condition_maybe_unordered (code);
20509     }
20510
20511   condition = ix86_expand_fp_compare (code, op1, op2,
20512                                       tmp);
20513
20514   i = emit_jump_insn (gen_rtx_SET
20515                       (VOIDmode, pc_rtx,
20516                        gen_rtx_IF_THEN_ELSE (VOIDmode,
20517                                              condition, target1, target2)));
20518   if (split_branch_probability >= 0)
20519     add_int_reg_note (i, REG_BR_PROB, split_branch_probability);
20520 }
20521
20522 void
20523 ix86_expand_setcc (rtx dest, enum rtx_code code, rtx op0, rtx op1)
20524 {
20525   rtx ret;
20526
20527   gcc_assert (GET_MODE (dest) == QImode);
20528
20529   ret = ix86_expand_compare (code, op0, op1);
20530   PUT_MODE (ret, QImode);
20531   emit_insn (gen_rtx_SET (VOIDmode, dest, ret));
20532 }
20533
20534 /* Expand comparison setting or clearing carry flag.  Return true when
20535    successful and set pop for the operation.  */
20536 static bool
20537 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
20538 {
20539   machine_mode mode =
20540     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
20541
20542   /* Do not handle double-mode compares that go through special path.  */
20543   if (mode == (TARGET_64BIT ? TImode : DImode))
20544     return false;
20545
20546   if (SCALAR_FLOAT_MODE_P (mode))
20547     {
20548       rtx compare_op;
20549       rtx_insn *compare_seq;
20550
20551       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
20552
20553       /* Shortcut:  following common codes never translate
20554          into carry flag compares.  */
20555       if (code == EQ || code == NE || code == UNEQ || code == LTGT
20556           || code == ORDERED || code == UNORDERED)
20557         return false;
20558
20559       /* These comparisons require zero flag; swap operands so they won't.  */
20560       if ((code == GT || code == UNLE || code == LE || code == UNGT)
20561           && !TARGET_IEEE_FP)
20562         {
20563           std::swap (op0, op1);
20564           code = swap_condition (code);
20565         }
20566
20567       /* Try to expand the comparison and verify that we end up with
20568          carry flag based comparison.  This fails to be true only when
20569          we decide to expand comparison using arithmetic that is not
20570          too common scenario.  */
20571       start_sequence ();
20572       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
20573       compare_seq = get_insns ();
20574       end_sequence ();
20575
20576       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
20577           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
20578         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
20579       else
20580         code = GET_CODE (compare_op);
20581
20582       if (code != LTU && code != GEU)
20583         return false;
20584
20585       emit_insn (compare_seq);
20586       *pop = compare_op;
20587       return true;
20588     }
20589
20590   if (!INTEGRAL_MODE_P (mode))
20591     return false;
20592
20593   switch (code)
20594     {
20595     case LTU:
20596     case GEU:
20597       break;
20598
20599     /* Convert a==0 into (unsigned)a<1.  */
20600     case EQ:
20601     case NE:
20602       if (op1 != const0_rtx)
20603         return false;
20604       op1 = const1_rtx;
20605       code = (code == EQ ? LTU : GEU);
20606       break;
20607
20608     /* Convert a>b into b<a or a>=b-1.  */
20609     case GTU:
20610     case LEU:
20611       if (CONST_INT_P (op1))
20612         {
20613           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
20614           /* Bail out on overflow.  We still can swap operands but that
20615              would force loading of the constant into register.  */
20616           if (op1 == const0_rtx
20617               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
20618             return false;
20619           code = (code == GTU ? GEU : LTU);
20620         }
20621       else
20622         {
20623           std::swap (op0, op1);
20624           code = (code == GTU ? LTU : GEU);
20625         }
20626       break;
20627
20628     /* Convert a>=0 into (unsigned)a<0x80000000.  */
20629     case LT:
20630     case GE:
20631       if (mode == DImode || op1 != const0_rtx)
20632         return false;
20633       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
20634       code = (code == LT ? GEU : LTU);
20635       break;
20636     case LE:
20637     case GT:
20638       if (mode == DImode || op1 != constm1_rtx)
20639         return false;
20640       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
20641       code = (code == LE ? GEU : LTU);
20642       break;
20643
20644     default:
20645       return false;
20646     }
20647   /* Swapping operands may cause constant to appear as first operand.  */
20648   if (!nonimmediate_operand (op0, VOIDmode))
20649     {
20650       if (!can_create_pseudo_p ())
20651         return false;
20652       op0 = force_reg (mode, op0);
20653     }
20654   *pop = ix86_expand_compare (code, op0, op1);
20655   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
20656   return true;
20657 }
20658
20659 bool
20660 ix86_expand_int_movcc (rtx operands[])
20661 {
20662   enum rtx_code code = GET_CODE (operands[1]), compare_code;
20663   rtx_insn *compare_seq;
20664   rtx compare_op;
20665   machine_mode mode = GET_MODE (operands[0]);
20666   bool sign_bit_compare_p = false;
20667   rtx op0 = XEXP (operands[1], 0);
20668   rtx op1 = XEXP (operands[1], 1);
20669
20670   if (GET_MODE (op0) == TImode
20671       || (GET_MODE (op0) == DImode
20672           && !TARGET_64BIT))
20673     return false;
20674
20675   start_sequence ();
20676   compare_op = ix86_expand_compare (code, op0, op1);
20677   compare_seq = get_insns ();
20678   end_sequence ();
20679
20680   compare_code = GET_CODE (compare_op);
20681
20682   if ((op1 == const0_rtx && (code == GE || code == LT))
20683       || (op1 == constm1_rtx && (code == GT || code == LE)))
20684     sign_bit_compare_p = true;
20685
20686   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
20687      HImode insns, we'd be swallowed in word prefix ops.  */
20688
20689   if ((mode != HImode || TARGET_FAST_PREFIX)
20690       && (mode != (TARGET_64BIT ? TImode : DImode))
20691       && CONST_INT_P (operands[2])
20692       && CONST_INT_P (operands[3]))
20693     {
20694       rtx out = operands[0];
20695       HOST_WIDE_INT ct = INTVAL (operands[2]);
20696       HOST_WIDE_INT cf = INTVAL (operands[3]);
20697       HOST_WIDE_INT diff;
20698
20699       diff = ct - cf;
20700       /*  Sign bit compares are better done using shifts than we do by using
20701           sbb.  */
20702       if (sign_bit_compare_p
20703           || ix86_expand_carry_flag_compare (code, op0, op1, &compare_op))
20704         {
20705           /* Detect overlap between destination and compare sources.  */
20706           rtx tmp = out;
20707
20708           if (!sign_bit_compare_p)
20709             {
20710               rtx flags;
20711               bool fpcmp = false;
20712
20713               compare_code = GET_CODE (compare_op);
20714
20715               flags = XEXP (compare_op, 0);
20716
20717               if (GET_MODE (flags) == CCFPmode
20718                   || GET_MODE (flags) == CCFPUmode)
20719                 {
20720                   fpcmp = true;
20721                   compare_code
20722                     = ix86_fp_compare_code_to_integer (compare_code);
20723                 }
20724
20725               /* To simplify rest of code, restrict to the GEU case.  */
20726               if (compare_code == LTU)
20727                 {
20728                   std::swap (ct, cf);
20729                   compare_code = reverse_condition (compare_code);
20730                   code = reverse_condition (code);
20731                 }
20732               else
20733                 {
20734                   if (fpcmp)
20735                     PUT_CODE (compare_op,
20736                               reverse_condition_maybe_unordered
20737                                 (GET_CODE (compare_op)));
20738                   else
20739                     PUT_CODE (compare_op,
20740                               reverse_condition (GET_CODE (compare_op)));
20741                 }
20742               diff = ct - cf;
20743
20744               if (reg_overlap_mentioned_p (out, op0)
20745                   || reg_overlap_mentioned_p (out, op1))
20746                 tmp = gen_reg_rtx (mode);
20747
20748               if (mode == DImode)
20749                 emit_insn (gen_x86_movdicc_0_m1 (tmp, flags, compare_op));
20750               else
20751                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp),
20752                                                  flags, compare_op));
20753             }
20754           else
20755             {
20756               if (code == GT || code == GE)
20757                 code = reverse_condition (code);
20758               else
20759                 {
20760                   std::swap (ct, cf);
20761                   diff = ct - cf;
20762                 }
20763               tmp = emit_store_flag (tmp, code, op0, op1, VOIDmode, 0, -1);
20764             }
20765
20766           if (diff == 1)
20767             {
20768               /*
20769                * cmpl op0,op1
20770                * sbbl dest,dest
20771                * [addl dest, ct]
20772                *
20773                * Size 5 - 8.
20774                */
20775               if (ct)
20776                 tmp = expand_simple_binop (mode, PLUS,
20777                                            tmp, GEN_INT (ct),
20778                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20779             }
20780           else if (cf == -1)
20781             {
20782               /*
20783                * cmpl op0,op1
20784                * sbbl dest,dest
20785                * orl $ct, dest
20786                *
20787                * Size 8.
20788                */
20789               tmp = expand_simple_binop (mode, IOR,
20790                                          tmp, GEN_INT (ct),
20791                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
20792             }
20793           else if (diff == -1 && ct)
20794             {
20795               /*
20796                * cmpl op0,op1
20797                * sbbl dest,dest
20798                * notl dest
20799                * [addl dest, cf]
20800                *
20801                * Size 8 - 11.
20802                */
20803               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
20804               if (cf)
20805                 tmp = expand_simple_binop (mode, PLUS,
20806                                            copy_rtx (tmp), GEN_INT (cf),
20807                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20808             }
20809           else
20810             {
20811               /*
20812                * cmpl op0,op1
20813                * sbbl dest,dest
20814                * [notl dest]
20815                * andl cf - ct, dest
20816                * [addl dest, ct]
20817                *
20818                * Size 8 - 11.
20819                */
20820
20821               if (cf == 0)
20822                 {
20823                   cf = ct;
20824                   ct = 0;
20825                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
20826                 }
20827
20828               tmp = expand_simple_binop (mode, AND,
20829                                          copy_rtx (tmp),
20830                                          gen_int_mode (cf - ct, mode),
20831                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
20832               if (ct)
20833                 tmp = expand_simple_binop (mode, PLUS,
20834                                            copy_rtx (tmp), GEN_INT (ct),
20835                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20836             }
20837
20838           if (!rtx_equal_p (tmp, out))
20839             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
20840
20841           return true;
20842         }
20843
20844       if (diff < 0)
20845         {
20846           machine_mode cmp_mode = GET_MODE (op0);
20847           enum rtx_code new_code;
20848
20849           if (SCALAR_FLOAT_MODE_P (cmp_mode))
20850             {
20851               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
20852
20853               /* We may be reversing unordered compare to normal compare, that
20854                  is not valid in general (we may convert non-trapping condition
20855                  to trapping one), however on i386 we currently emit all
20856                  comparisons unordered.  */
20857               new_code = reverse_condition_maybe_unordered (code);
20858             }
20859           else
20860             new_code = ix86_reverse_condition (code, cmp_mode);
20861           if (new_code != UNKNOWN)
20862             {
20863               std::swap (ct, cf);
20864               diff = -diff;
20865               code = new_code;
20866             }
20867         }
20868
20869       compare_code = UNKNOWN;
20870       if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
20871           && CONST_INT_P (op1))
20872         {
20873           if (op1 == const0_rtx
20874               && (code == LT || code == GE))
20875             compare_code = code;
20876           else if (op1 == constm1_rtx)
20877             {
20878               if (code == LE)
20879                 compare_code = LT;
20880               else if (code == GT)
20881                 compare_code = GE;
20882             }
20883         }
20884
20885       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
20886       if (compare_code != UNKNOWN
20887           && GET_MODE (op0) == GET_MODE (out)
20888           && (cf == -1 || ct == -1))
20889         {
20890           /* If lea code below could be used, only optimize
20891              if it results in a 2 insn sequence.  */
20892
20893           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
20894                  || diff == 3 || diff == 5 || diff == 9)
20895               || (compare_code == LT && ct == -1)
20896               || (compare_code == GE && cf == -1))
20897             {
20898               /*
20899                * notl op1       (if necessary)
20900                * sarl $31, op1
20901                * orl cf, op1
20902                */
20903               if (ct != -1)
20904                 {
20905                   cf = ct;
20906                   ct = -1;
20907                   code = reverse_condition (code);
20908                 }
20909
20910               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, -1);
20911
20912               out = expand_simple_binop (mode, IOR,
20913                                          out, GEN_INT (cf),
20914                                          out, 1, OPTAB_DIRECT);
20915               if (out != operands[0])
20916                 emit_move_insn (operands[0], out);
20917
20918               return true;
20919             }
20920         }
20921
20922
20923       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
20924            || diff == 3 || diff == 5 || diff == 9)
20925           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
20926           && (mode != DImode
20927               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
20928         {
20929           /*
20930            * xorl dest,dest
20931            * cmpl op1,op2
20932            * setcc dest
20933            * lea cf(dest*(ct-cf)),dest
20934            *
20935            * Size 14.
20936            *
20937            * This also catches the degenerate setcc-only case.
20938            */
20939
20940           rtx tmp;
20941           int nops;
20942
20943           out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, 1);
20944
20945           nops = 0;
20946           /* On x86_64 the lea instruction operates on Pmode, so we need
20947              to get arithmetics done in proper mode to match.  */
20948           if (diff == 1)
20949             tmp = copy_rtx (out);
20950           else
20951             {
20952               rtx out1;
20953               out1 = copy_rtx (out);
20954               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
20955               nops++;
20956               if (diff & 1)
20957                 {
20958                   tmp = gen_rtx_PLUS (mode, tmp, out1);
20959                   nops++;
20960                 }
20961             }
20962           if (cf != 0)
20963             {
20964               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
20965               nops++;
20966             }
20967           if (!rtx_equal_p (tmp, out))
20968             {
20969               if (nops == 1)
20970                 out = force_operand (tmp, copy_rtx (out));
20971               else
20972                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
20973             }
20974           if (!rtx_equal_p (out, operands[0]))
20975             emit_move_insn (operands[0], copy_rtx (out));
20976
20977           return true;
20978         }
20979
20980       /*
20981        * General case:                  Jumpful:
20982        *   xorl dest,dest               cmpl op1, op2
20983        *   cmpl op1, op2                movl ct, dest
20984        *   setcc dest                   jcc 1f
20985        *   decl dest                    movl cf, dest
20986        *   andl (cf-ct),dest            1:
20987        *   addl ct,dest
20988        *
20989        * Size 20.                       Size 14.
20990        *
20991        * This is reasonably steep, but branch mispredict costs are
20992        * high on modern cpus, so consider failing only if optimizing
20993        * for space.
20994        */
20995
20996       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
20997           && BRANCH_COST (optimize_insn_for_speed_p (),
20998                           false) >= 2)
20999         {
21000           if (cf == 0)
21001             {
21002               machine_mode cmp_mode = GET_MODE (op0);
21003               enum rtx_code new_code;
21004
21005               if (SCALAR_FLOAT_MODE_P (cmp_mode))
21006                 {
21007                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
21008
21009                   /* We may be reversing unordered compare to normal compare,
21010                      that is not valid in general (we may convert non-trapping
21011                      condition to trapping one), however on i386 we currently
21012                      emit all comparisons unordered.  */
21013                   new_code = reverse_condition_maybe_unordered (code);
21014                 }
21015               else
21016                 {
21017                   new_code = ix86_reverse_condition (code, cmp_mode);
21018                   if (compare_code != UNKNOWN && new_code != UNKNOWN)
21019                     compare_code = reverse_condition (compare_code);
21020                 }
21021
21022               if (new_code != UNKNOWN)
21023                 {
21024                   cf = ct;
21025                   ct = 0;
21026                   code = new_code;
21027                 }
21028             }
21029
21030           if (compare_code != UNKNOWN)
21031             {
21032               /* notl op1       (if needed)
21033                  sarl $31, op1
21034                  andl (cf-ct), op1
21035                  addl ct, op1
21036
21037                  For x < 0 (resp. x <= -1) there will be no notl,
21038                  so if possible swap the constants to get rid of the
21039                  complement.
21040                  True/false will be -1/0 while code below (store flag
21041                  followed by decrement) is 0/-1, so the constants need
21042                  to be exchanged once more.  */
21043
21044               if (compare_code == GE || !cf)
21045                 {
21046                   code = reverse_condition (code);
21047                   compare_code = LT;
21048                 }
21049               else
21050                 std::swap (ct, cf);
21051
21052               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, -1);
21053             }
21054           else
21055             {
21056               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, 1);
21057
21058               out = expand_simple_binop (mode, PLUS, copy_rtx (out),
21059                                          constm1_rtx,
21060                                          copy_rtx (out), 1, OPTAB_DIRECT);
21061             }
21062
21063           out = expand_simple_binop (mode, AND, copy_rtx (out),
21064                                      gen_int_mode (cf - ct, mode),
21065                                      copy_rtx (out), 1, OPTAB_DIRECT);
21066           if (ct)
21067             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
21068                                        copy_rtx (out), 1, OPTAB_DIRECT);
21069           if (!rtx_equal_p (out, operands[0]))
21070             emit_move_insn (operands[0], copy_rtx (out));
21071
21072           return true;
21073         }
21074     }
21075
21076   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
21077     {
21078       /* Try a few things more with specific constants and a variable.  */
21079
21080       optab op;
21081       rtx var, orig_out, out, tmp;
21082
21083       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
21084         return false;
21085
21086       /* If one of the two operands is an interesting constant, load a
21087          constant with the above and mask it in with a logical operation.  */
21088
21089       if (CONST_INT_P (operands[2]))
21090         {
21091           var = operands[3];
21092           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
21093             operands[3] = constm1_rtx, op = and_optab;
21094           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
21095             operands[3] = const0_rtx, op = ior_optab;
21096           else
21097             return false;
21098         }
21099       else if (CONST_INT_P (operands[3]))
21100         {
21101           var = operands[2];
21102           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
21103             operands[2] = constm1_rtx, op = and_optab;
21104           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
21105             operands[2] = const0_rtx, op = ior_optab;
21106           else
21107             return false;
21108         }
21109       else
21110         return false;
21111
21112       orig_out = operands[0];
21113       tmp = gen_reg_rtx (mode);
21114       operands[0] = tmp;
21115
21116       /* Recurse to get the constant loaded.  */
21117       if (ix86_expand_int_movcc (operands) == 0)
21118         return false;
21119
21120       /* Mask in the interesting variable.  */
21121       out = expand_binop (mode, op, var, tmp, orig_out, 0,
21122                           OPTAB_WIDEN);
21123       if (!rtx_equal_p (out, orig_out))
21124         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
21125
21126       return true;
21127     }
21128
21129   /*
21130    * For comparison with above,
21131    *
21132    * movl cf,dest
21133    * movl ct,tmp
21134    * cmpl op1,op2
21135    * cmovcc tmp,dest
21136    *
21137    * Size 15.
21138    */
21139
21140   if (! nonimmediate_operand (operands[2], mode))
21141     operands[2] = force_reg (mode, operands[2]);
21142   if (! nonimmediate_operand (operands[3], mode))
21143     operands[3] = force_reg (mode, operands[3]);
21144
21145   if (! register_operand (operands[2], VOIDmode)
21146       && (mode == QImode
21147           || ! register_operand (operands[3], VOIDmode)))
21148     operands[2] = force_reg (mode, operands[2]);
21149
21150   if (mode == QImode
21151       && ! register_operand (operands[3], VOIDmode))
21152     operands[3] = force_reg (mode, operands[3]);
21153
21154   emit_insn (compare_seq);
21155   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
21156                           gen_rtx_IF_THEN_ELSE (mode,
21157                                                 compare_op, operands[2],
21158                                                 operands[3])));
21159   return true;
21160 }
21161
21162 /* Swap, force into registers, or otherwise massage the two operands
21163    to an sse comparison with a mask result.  Thus we differ a bit from
21164    ix86_prepare_fp_compare_args which expects to produce a flags result.
21165
21166    The DEST operand exists to help determine whether to commute commutative
21167    operators.  The POP0/POP1 operands are updated in place.  The new
21168    comparison code is returned, or UNKNOWN if not implementable.  */
21169
21170 static enum rtx_code
21171 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
21172                                   rtx *pop0, rtx *pop1)
21173 {
21174   switch (code)
21175     {
21176     case LTGT:
21177     case UNEQ:
21178       /* AVX supports all the needed comparisons.  */
21179       if (TARGET_AVX)
21180         break;
21181       /* We have no LTGT as an operator.  We could implement it with
21182          NE & ORDERED, but this requires an extra temporary.  It's
21183          not clear that it's worth it.  */
21184       return UNKNOWN;
21185
21186     case LT:
21187     case LE:
21188     case UNGT:
21189     case UNGE:
21190       /* These are supported directly.  */
21191       break;
21192
21193     case EQ:
21194     case NE:
21195     case UNORDERED:
21196     case ORDERED:
21197       /* AVX has 3 operand comparisons, no need to swap anything.  */
21198       if (TARGET_AVX)
21199         break;
21200       /* For commutative operators, try to canonicalize the destination
21201          operand to be first in the comparison - this helps reload to
21202          avoid extra moves.  */
21203       if (!dest || !rtx_equal_p (dest, *pop1))
21204         break;
21205       /* FALLTHRU */
21206
21207     case GE:
21208     case GT:
21209     case UNLE:
21210     case UNLT:
21211       /* These are not supported directly before AVX, and furthermore
21212          ix86_expand_sse_fp_minmax only optimizes LT/UNGE.  Swap the
21213          comparison operands to transform into something that is
21214          supported.  */
21215       std::swap (*pop0, *pop1);
21216       code = swap_condition (code);
21217       break;
21218
21219     default:
21220       gcc_unreachable ();
21221     }
21222
21223   return code;
21224 }
21225
21226 /* Detect conditional moves that exactly match min/max operational
21227    semantics.  Note that this is IEEE safe, as long as we don't
21228    interchange the operands.
21229
21230    Returns FALSE if this conditional move doesn't match a MIN/MAX,
21231    and TRUE if the operation is successful and instructions are emitted.  */
21232
21233 static bool
21234 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
21235                            rtx cmp_op1, rtx if_true, rtx if_false)
21236 {
21237   machine_mode mode;
21238   bool is_min;
21239   rtx tmp;
21240
21241   if (code == LT)
21242     ;
21243   else if (code == UNGE)
21244     std::swap (if_true, if_false);
21245   else
21246     return false;
21247
21248   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
21249     is_min = true;
21250   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
21251     is_min = false;
21252   else
21253     return false;
21254
21255   mode = GET_MODE (dest);
21256
21257   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
21258      but MODE may be a vector mode and thus not appropriate.  */
21259   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
21260     {
21261       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
21262       rtvec v;
21263
21264       if_true = force_reg (mode, if_true);
21265       v = gen_rtvec (2, if_true, if_false);
21266       tmp = gen_rtx_UNSPEC (mode, v, u);
21267     }
21268   else
21269     {
21270       code = is_min ? SMIN : SMAX;
21271       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
21272     }
21273
21274   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
21275   return true;
21276 }
21277
21278 /* Expand an sse vector comparison.  Return the register with the result.  */
21279
21280 static rtx
21281 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
21282                      rtx op_true, rtx op_false)
21283 {
21284   machine_mode mode = GET_MODE (dest);
21285   machine_mode cmp_ops_mode = GET_MODE (cmp_op0);
21286
21287   /* In general case result of comparison can differ from operands' type.  */
21288   machine_mode cmp_mode;
21289
21290   /* In AVX512F the result of comparison is an integer mask.  */
21291   bool maskcmp = false;
21292   rtx x;
21293
21294   if (GET_MODE_SIZE (cmp_ops_mode) == 64)
21295     {
21296       cmp_mode = mode_for_size (GET_MODE_NUNITS (cmp_ops_mode), MODE_INT, 0);
21297       gcc_assert (cmp_mode != BLKmode);
21298
21299       maskcmp = true;
21300     }
21301   else
21302     cmp_mode = cmp_ops_mode;
21303
21304
21305   cmp_op0 = force_reg (cmp_ops_mode, cmp_op0);
21306   if (!nonimmediate_operand (cmp_op1, cmp_ops_mode))
21307     cmp_op1 = force_reg (cmp_ops_mode, cmp_op1);
21308
21309   if (optimize
21310       || reg_overlap_mentioned_p (dest, op_true)
21311       || reg_overlap_mentioned_p (dest, op_false))
21312     dest = gen_reg_rtx (maskcmp ? cmp_mode : mode);
21313
21314   /* Compare patterns for int modes are unspec in AVX512F only.  */
21315   if (maskcmp && (code == GT || code == EQ))
21316     {
21317       rtx (*gen)(rtx, rtx, rtx);
21318
21319       switch (cmp_ops_mode)
21320         {
21321         case V64QImode:
21322           gcc_assert (TARGET_AVX512BW);
21323           gen = code == GT ? gen_avx512bw_gtv64qi3 : gen_avx512bw_eqv64qi3_1;
21324           break;
21325         case V32HImode:
21326           gcc_assert (TARGET_AVX512BW);
21327           gen = code == GT ? gen_avx512bw_gtv32hi3 : gen_avx512bw_eqv32hi3_1;
21328           break;
21329         case V16SImode:
21330           gen = code == GT ? gen_avx512f_gtv16si3 : gen_avx512f_eqv16si3_1;
21331           break;
21332         case V8DImode:
21333           gen = code == GT ? gen_avx512f_gtv8di3 : gen_avx512f_eqv8di3_1;
21334           break;
21335         default:
21336           gen = NULL;
21337         }
21338
21339       if (gen)
21340         {
21341           emit_insn (gen (dest, cmp_op0, cmp_op1));
21342           return dest;
21343         }
21344     }
21345   x = gen_rtx_fmt_ee (code, cmp_mode, cmp_op0, cmp_op1);
21346
21347   if (cmp_mode != mode && !maskcmp)
21348     {
21349       x = force_reg (cmp_ops_mode, x);
21350       convert_move (dest, x, false);
21351     }
21352   else
21353     emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21354
21355   return dest;
21356 }
21357
21358 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
21359    operations.  This is used for both scalar and vector conditional moves.  */
21360
21361 static void
21362 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
21363 {
21364   machine_mode mode = GET_MODE (dest);
21365   machine_mode cmpmode = GET_MODE (cmp);
21366
21367   /* In AVX512F the result of comparison is an integer mask.  */
21368   bool maskcmp = (mode != cmpmode && TARGET_AVX512F);
21369
21370   rtx t2, t3, x;
21371
21372   if (vector_all_ones_operand (op_true, mode)
21373       && rtx_equal_p (op_false, CONST0_RTX (mode))
21374       && !maskcmp)
21375     {
21376       emit_insn (gen_rtx_SET (VOIDmode, dest, cmp));
21377     }
21378   else if (op_false == CONST0_RTX (mode)
21379       && !maskcmp)
21380     {
21381       op_true = force_reg (mode, op_true);
21382       x = gen_rtx_AND (mode, cmp, op_true);
21383       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21384     }
21385   else if (op_true == CONST0_RTX (mode)
21386       && !maskcmp)
21387     {
21388       op_false = force_reg (mode, op_false);
21389       x = gen_rtx_NOT (mode, cmp);
21390       x = gen_rtx_AND (mode, x, op_false);
21391       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21392     }
21393   else if (INTEGRAL_MODE_P (mode) && op_true == CONSTM1_RTX (mode)
21394       && !maskcmp)
21395     {
21396       op_false = force_reg (mode, op_false);
21397       x = gen_rtx_IOR (mode, cmp, op_false);
21398       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21399     }
21400   else if (TARGET_XOP
21401       && !maskcmp)
21402     {
21403       op_true = force_reg (mode, op_true);
21404
21405       if (!nonimmediate_operand (op_false, mode))
21406         op_false = force_reg (mode, op_false);
21407
21408       emit_insn (gen_rtx_SET (mode, dest,
21409                               gen_rtx_IF_THEN_ELSE (mode, cmp,
21410                                                     op_true,
21411                                                     op_false)));
21412     }
21413   else
21414     {
21415       rtx (*gen) (rtx, rtx, rtx, rtx) = NULL;
21416       rtx d = dest;
21417
21418       if (!nonimmediate_operand (op_true, mode))
21419         op_true = force_reg (mode, op_true);
21420
21421       op_false = force_reg (mode, op_false);
21422
21423       switch (mode)
21424         {
21425         case V4SFmode:
21426           if (TARGET_SSE4_1)
21427             gen = gen_sse4_1_blendvps;
21428           break;
21429         case V2DFmode:
21430           if (TARGET_SSE4_1)
21431             gen = gen_sse4_1_blendvpd;
21432           break;
21433         case V16QImode:
21434         case V8HImode:
21435         case V4SImode:
21436         case V2DImode:
21437           if (TARGET_SSE4_1)
21438             {
21439               gen = gen_sse4_1_pblendvb;
21440               if (mode != V16QImode)
21441                 d = gen_reg_rtx (V16QImode);
21442               op_false = gen_lowpart (V16QImode, op_false);
21443               op_true = gen_lowpart (V16QImode, op_true);
21444               cmp = gen_lowpart (V16QImode, cmp);
21445             }
21446           break;
21447         case V8SFmode:
21448           if (TARGET_AVX)
21449             gen = gen_avx_blendvps256;
21450           break;
21451         case V4DFmode:
21452           if (TARGET_AVX)
21453             gen = gen_avx_blendvpd256;
21454           break;
21455         case V32QImode:
21456         case V16HImode:
21457         case V8SImode:
21458         case V4DImode:
21459           if (TARGET_AVX2)
21460             {
21461               gen = gen_avx2_pblendvb;
21462               if (mode != V32QImode)
21463                 d = gen_reg_rtx (V32QImode);
21464               op_false = gen_lowpart (V32QImode, op_false);
21465               op_true = gen_lowpart (V32QImode, op_true);
21466               cmp = gen_lowpart (V32QImode, cmp);
21467             }
21468           break;
21469
21470         case V64QImode:
21471           gen = gen_avx512bw_blendmv64qi;
21472           break;
21473         case V32HImode:
21474           gen = gen_avx512bw_blendmv32hi;
21475           break;
21476         case V16SImode:
21477           gen = gen_avx512f_blendmv16si;
21478           break;
21479         case V8DImode:
21480           gen = gen_avx512f_blendmv8di;
21481           break;
21482         case V8DFmode:
21483           gen = gen_avx512f_blendmv8df;
21484           break;
21485         case V16SFmode:
21486           gen = gen_avx512f_blendmv16sf;
21487           break;
21488
21489         default:
21490           break;
21491         }
21492
21493       if (gen != NULL)
21494         {
21495           emit_insn (gen (d, op_false, op_true, cmp));
21496           if (d != dest)
21497             emit_move_insn (dest, gen_lowpart (GET_MODE (dest), d));
21498         }
21499       else
21500         {
21501           op_true = force_reg (mode, op_true);
21502
21503           t2 = gen_reg_rtx (mode);
21504           if (optimize)
21505             t3 = gen_reg_rtx (mode);
21506           else
21507             t3 = dest;
21508
21509           x = gen_rtx_AND (mode, op_true, cmp);
21510           emit_insn (gen_rtx_SET (VOIDmode, t2, x));
21511
21512           x = gen_rtx_NOT (mode, cmp);
21513           x = gen_rtx_AND (mode, x, op_false);
21514           emit_insn (gen_rtx_SET (VOIDmode, t3, x));
21515
21516           x = gen_rtx_IOR (mode, t3, t2);
21517           emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21518         }
21519     }
21520 }
21521
21522 /* Expand a floating-point conditional move.  Return true if successful.  */
21523
21524 bool
21525 ix86_expand_fp_movcc (rtx operands[])
21526 {
21527   machine_mode mode = GET_MODE (operands[0]);
21528   enum rtx_code code = GET_CODE (operands[1]);
21529   rtx tmp, compare_op;
21530   rtx op0 = XEXP (operands[1], 0);
21531   rtx op1 = XEXP (operands[1], 1);
21532
21533   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
21534     {
21535       machine_mode cmode;
21536
21537       /* Since we've no cmove for sse registers, don't force bad register
21538          allocation just to gain access to it.  Deny movcc when the
21539          comparison mode doesn't match the move mode.  */
21540       cmode = GET_MODE (op0);
21541       if (cmode == VOIDmode)
21542         cmode = GET_MODE (op1);
21543       if (cmode != mode)
21544         return false;
21545
21546       code = ix86_prepare_sse_fp_compare_args (operands[0], code, &op0, &op1);
21547       if (code == UNKNOWN)
21548         return false;
21549
21550       if (ix86_expand_sse_fp_minmax (operands[0], code, op0, op1,
21551                                      operands[2], operands[3]))
21552         return true;
21553
21554       tmp = ix86_expand_sse_cmp (operands[0], code, op0, op1,
21555                                  operands[2], operands[3]);
21556       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
21557       return true;
21558     }
21559
21560   if (GET_MODE (op0) == TImode
21561       || (GET_MODE (op0) == DImode
21562           && !TARGET_64BIT))
21563     return false;
21564
21565   /* The floating point conditional move instructions don't directly
21566      support conditions resulting from a signed integer comparison.  */
21567
21568   compare_op = ix86_expand_compare (code, op0, op1);
21569   if (!fcmov_comparison_operator (compare_op, VOIDmode))
21570     {
21571       tmp = gen_reg_rtx (QImode);
21572       ix86_expand_setcc (tmp, code, op0, op1);
21573
21574       compare_op = ix86_expand_compare (NE, tmp, const0_rtx);
21575     }
21576
21577   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
21578                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
21579                                                 operands[2], operands[3])));
21580
21581   return true;
21582 }
21583
21584 /* Expand a floating-point vector conditional move; a vcond operation
21585    rather than a movcc operation.  */
21586
21587 bool
21588 ix86_expand_fp_vcond (rtx operands[])
21589 {
21590   enum rtx_code code = GET_CODE (operands[3]);
21591   rtx cmp;
21592
21593   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
21594                                            &operands[4], &operands[5]);
21595   if (code == UNKNOWN)
21596     {
21597       rtx temp;
21598       switch (GET_CODE (operands[3]))
21599         {
21600         case LTGT:
21601           temp = ix86_expand_sse_cmp (operands[0], ORDERED, operands[4],
21602                                       operands[5], operands[0], operands[0]);
21603           cmp = ix86_expand_sse_cmp (operands[0], NE, operands[4],
21604                                      operands[5], operands[1], operands[2]);
21605           code = AND;
21606           break;
21607         case UNEQ:
21608           temp = ix86_expand_sse_cmp (operands[0], UNORDERED, operands[4],
21609                                       operands[5], operands[0], operands[0]);
21610           cmp = ix86_expand_sse_cmp (operands[0], EQ, operands[4],
21611                                      operands[5], operands[1], operands[2]);
21612           code = IOR;
21613           break;
21614         default:
21615           gcc_unreachable ();
21616         }
21617       cmp = expand_simple_binop (GET_MODE (cmp), code, temp, cmp, cmp, 1,
21618                                  OPTAB_DIRECT);
21619       ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
21620       return true;
21621     }
21622
21623   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
21624                                  operands[5], operands[1], operands[2]))
21625     return true;
21626
21627   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
21628                              operands[1], operands[2]);
21629   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
21630   return true;
21631 }
21632
21633 /* Expand a signed/unsigned integral vector conditional move.  */
21634
21635 bool
21636 ix86_expand_int_vcond (rtx operands[])
21637 {
21638   machine_mode data_mode = GET_MODE (operands[0]);
21639   machine_mode mode = GET_MODE (operands[4]);
21640   enum rtx_code code = GET_CODE (operands[3]);
21641   bool negate = false;
21642   rtx x, cop0, cop1;
21643
21644   cop0 = operands[4];
21645   cop1 = operands[5];
21646
21647   /* Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
21648      and x < 0 ? 1 : 0 into (unsigned) x >> 31.  */
21649   if ((code == LT || code == GE)
21650       && data_mode == mode
21651       && cop1 == CONST0_RTX (mode)
21652       && operands[1 + (code == LT)] == CONST0_RTX (data_mode)
21653       && GET_MODE_SIZE (GET_MODE_INNER (data_mode)) > 1
21654       && GET_MODE_SIZE (GET_MODE_INNER (data_mode)) <= 8
21655       && (GET_MODE_SIZE (data_mode) == 16
21656           || (TARGET_AVX2 && GET_MODE_SIZE (data_mode) == 32)))
21657     {
21658       rtx negop = operands[2 - (code == LT)];
21659       int shift = GET_MODE_BITSIZE (GET_MODE_INNER (data_mode)) - 1;
21660       if (negop == CONST1_RTX (data_mode))
21661         {
21662           rtx res = expand_simple_binop (mode, LSHIFTRT, cop0, GEN_INT (shift),
21663                                          operands[0], 1, OPTAB_DIRECT);
21664           if (res != operands[0])
21665             emit_move_insn (operands[0], res);
21666           return true;
21667         }
21668       else if (GET_MODE_INNER (data_mode) != DImode
21669                && vector_all_ones_operand (negop, data_mode))
21670         {
21671           rtx res = expand_simple_binop (mode, ASHIFTRT, cop0, GEN_INT (shift),
21672                                          operands[0], 0, OPTAB_DIRECT);
21673           if (res != operands[0])
21674             emit_move_insn (operands[0], res);
21675           return true;
21676         }
21677     }
21678
21679   if (!nonimmediate_operand (cop1, mode))
21680     cop1 = force_reg (mode, cop1);
21681   if (!general_operand (operands[1], data_mode))
21682     operands[1] = force_reg (data_mode, operands[1]);
21683   if (!general_operand (operands[2], data_mode))
21684     operands[2] = force_reg (data_mode, operands[2]);
21685
21686   /* XOP supports all of the comparisons on all 128-bit vector int types.  */
21687   if (TARGET_XOP
21688       && (mode == V16QImode || mode == V8HImode
21689           || mode == V4SImode || mode == V2DImode))
21690     ;
21691   else
21692     {
21693       /* Canonicalize the comparison to EQ, GT, GTU.  */
21694       switch (code)
21695         {
21696         case EQ:
21697         case GT:
21698         case GTU:
21699           break;
21700
21701         case NE:
21702         case LE:
21703         case LEU:
21704           code = reverse_condition (code);
21705           negate = true;
21706           break;
21707
21708         case GE:
21709         case GEU:
21710           code = reverse_condition (code);
21711           negate = true;
21712           /* FALLTHRU */
21713
21714         case LT:
21715         case LTU:
21716           std::swap (cop0, cop1);
21717           code = swap_condition (code);
21718           break;
21719
21720         default:
21721           gcc_unreachable ();
21722         }
21723
21724       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
21725       if (mode == V2DImode)
21726         {
21727           switch (code)
21728             {
21729             case EQ:
21730               /* SSE4.1 supports EQ.  */
21731               if (!TARGET_SSE4_1)
21732                 return false;
21733               break;
21734
21735             case GT:
21736             case GTU:
21737               /* SSE4.2 supports GT/GTU.  */
21738               if (!TARGET_SSE4_2)
21739                 return false;
21740               break;
21741
21742             default:
21743               gcc_unreachable ();
21744             }
21745         }
21746
21747       /* Unsigned parallel compare is not supported by the hardware.
21748          Play some tricks to turn this into a signed comparison
21749          against 0.  */
21750       if (code == GTU)
21751         {
21752           cop0 = force_reg (mode, cop0);
21753
21754           switch (mode)
21755             {
21756             case V16SImode:
21757             case V8DImode:
21758             case V8SImode:
21759             case V4DImode:
21760             case V4SImode:
21761             case V2DImode:
21762                 {
21763                   rtx t1, t2, mask;
21764                   rtx (*gen_sub3) (rtx, rtx, rtx);
21765
21766                   switch (mode)
21767                     {
21768                     case V16SImode: gen_sub3 = gen_subv16si3; break;
21769                     case V8DImode: gen_sub3 = gen_subv8di3; break;
21770                     case V8SImode: gen_sub3 = gen_subv8si3; break;
21771                     case V4DImode: gen_sub3 = gen_subv4di3; break;
21772                     case V4SImode: gen_sub3 = gen_subv4si3; break;
21773                     case V2DImode: gen_sub3 = gen_subv2di3; break;
21774                     default:
21775                       gcc_unreachable ();
21776                     }
21777                   /* Subtract (-(INT MAX) - 1) from both operands to make
21778                      them signed.  */
21779                   mask = ix86_build_signbit_mask (mode, true, false);
21780                   t1 = gen_reg_rtx (mode);
21781                   emit_insn (gen_sub3 (t1, cop0, mask));
21782
21783                   t2 = gen_reg_rtx (mode);
21784                   emit_insn (gen_sub3 (t2, cop1, mask));
21785
21786                   cop0 = t1;
21787                   cop1 = t2;
21788                   code = GT;
21789                 }
21790               break;
21791
21792             case V64QImode:
21793             case V32HImode:
21794             case V32QImode:
21795             case V16HImode:
21796             case V16QImode:
21797             case V8HImode:
21798               /* Perform a parallel unsigned saturating subtraction.  */
21799               x = gen_reg_rtx (mode);
21800               emit_insn (gen_rtx_SET (VOIDmode, x,
21801                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
21802
21803               cop0 = x;
21804               cop1 = CONST0_RTX (mode);
21805               code = EQ;
21806               negate = !negate;
21807               break;
21808
21809             default:
21810               gcc_unreachable ();
21811             }
21812         }
21813     }
21814
21815   /* Allow the comparison to be done in one mode, but the movcc to
21816      happen in another mode.  */
21817   if (data_mode == mode)
21818     {
21819       x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
21820                                operands[1+negate], operands[2-negate]);
21821     }
21822   else
21823     {
21824       gcc_assert (GET_MODE_SIZE (data_mode) == GET_MODE_SIZE (mode));
21825       x = ix86_expand_sse_cmp (gen_reg_rtx (mode), code, cop0, cop1,
21826                                operands[1+negate], operands[2-negate]);
21827       if (GET_MODE (x) == mode)
21828         x = gen_lowpart (data_mode, x);
21829     }
21830
21831   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
21832                          operands[2-negate]);
21833   return true;
21834 }
21835
21836 /* AVX512F does support 64-byte integer vector operations,
21837    thus the longest vector we are faced with is V64QImode.  */
21838 #define MAX_VECT_LEN    64
21839
21840 struct expand_vec_perm_d
21841 {
21842   rtx target, op0, op1;
21843   unsigned char perm[MAX_VECT_LEN];
21844   machine_mode vmode;
21845   unsigned char nelt;
21846   bool one_operand_p;
21847   bool testing_p;
21848 };
21849
21850 static bool
21851 ix86_expand_vec_perm_vpermi2 (rtx target, rtx op0, rtx mask, rtx op1,
21852                               struct expand_vec_perm_d *d)
21853 {
21854   /* ix86_expand_vec_perm_vpermi2 is called from both const and non-const
21855      expander, so args are either in d, or in op0, op1 etc.  */
21856   machine_mode mode = GET_MODE (d ? d->op0 : op0);
21857   machine_mode maskmode = mode;
21858   rtx (*gen) (rtx, rtx, rtx, rtx) = NULL;
21859
21860   switch (mode)
21861     {
21862     case V8HImode:
21863       if (TARGET_AVX512VL && TARGET_AVX512BW)
21864         gen = gen_avx512vl_vpermi2varv8hi3;
21865       break;
21866     case V16HImode:
21867       if (TARGET_AVX512VL && TARGET_AVX512BW)
21868         gen = gen_avx512vl_vpermi2varv16hi3;
21869       break;
21870     case V64QImode:
21871       if (TARGET_AVX512VBMI)
21872         gen = gen_avx512bw_vpermi2varv64qi3;
21873       break;
21874     case V32HImode:
21875       if (TARGET_AVX512BW)
21876         gen = gen_avx512bw_vpermi2varv32hi3;
21877       break;
21878     case V4SImode:
21879       if (TARGET_AVX512VL)
21880         gen = gen_avx512vl_vpermi2varv4si3;
21881       break;
21882     case V8SImode:
21883       if (TARGET_AVX512VL)
21884         gen = gen_avx512vl_vpermi2varv8si3;
21885       break;
21886     case V16SImode:
21887       if (TARGET_AVX512F)
21888         gen = gen_avx512f_vpermi2varv16si3;
21889       break;
21890     case V4SFmode:
21891       if (TARGET_AVX512VL)
21892         {
21893           gen = gen_avx512vl_vpermi2varv4sf3;
21894           maskmode = V4SImode;
21895         }
21896       break;
21897     case V8SFmode:
21898       if (TARGET_AVX512VL)
21899         {
21900           gen = gen_avx512vl_vpermi2varv8sf3;
21901           maskmode = V8SImode;
21902         }
21903       break;
21904     case V16SFmode:
21905       if (TARGET_AVX512F)
21906         {
21907           gen = gen_avx512f_vpermi2varv16sf3;
21908           maskmode = V16SImode;
21909         }
21910       break;
21911     case V2DImode:
21912       if (TARGET_AVX512VL)
21913         gen = gen_avx512vl_vpermi2varv2di3;
21914       break;
21915     case V4DImode:
21916       if (TARGET_AVX512VL)
21917         gen = gen_avx512vl_vpermi2varv4di3;
21918       break;
21919     case V8DImode:
21920       if (TARGET_AVX512F)
21921         gen = gen_avx512f_vpermi2varv8di3;
21922       break;
21923     case V2DFmode:
21924       if (TARGET_AVX512VL)
21925         {
21926           gen = gen_avx512vl_vpermi2varv2df3;
21927           maskmode = V2DImode;
21928         }
21929       break;
21930     case V4DFmode:
21931       if (TARGET_AVX512VL)
21932         {
21933           gen = gen_avx512vl_vpermi2varv4df3;
21934           maskmode = V4DImode;
21935         }
21936       break;
21937     case V8DFmode:
21938       if (TARGET_AVX512F)
21939         {
21940           gen = gen_avx512f_vpermi2varv8df3;
21941           maskmode = V8DImode;
21942         }
21943       break;
21944     default:
21945       break;
21946     }
21947
21948   if (gen == NULL)
21949     return false;
21950
21951   /* ix86_expand_vec_perm_vpermi2 is called from both const and non-const
21952      expander, so args are either in d, or in op0, op1 etc.  */
21953   if (d)
21954     {
21955       rtx vec[64];
21956       target = d->target;
21957       op0 = d->op0;
21958       op1 = d->op1;
21959       for (int i = 0; i < d->nelt; ++i)
21960         vec[i] = GEN_INT (d->perm[i]);
21961       mask = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (d->nelt, vec));
21962     }
21963
21964   emit_insn (gen (target, op0, force_reg (maskmode, mask), op1));
21965   return true;
21966 }
21967
21968 /* Expand a variable vector permutation.  */
21969
21970 void
21971 ix86_expand_vec_perm (rtx operands[])
21972 {
21973   rtx target = operands[0];
21974   rtx op0 = operands[1];
21975   rtx op1 = operands[2];
21976   rtx mask = operands[3];
21977   rtx t1, t2, t3, t4, t5, t6, t7, t8, vt, vt2, vec[32];
21978   machine_mode mode = GET_MODE (op0);
21979   machine_mode maskmode = GET_MODE (mask);
21980   int w, e, i;
21981   bool one_operand_shuffle = rtx_equal_p (op0, op1);
21982
21983   /* Number of elements in the vector.  */
21984   w = GET_MODE_NUNITS (mode);
21985   e = GET_MODE_UNIT_SIZE (mode);
21986   gcc_assert (w <= 64);
21987
21988   if (ix86_expand_vec_perm_vpermi2 (target, op0, mask, op1, NULL))
21989     return;
21990
21991   if (TARGET_AVX2)
21992     {
21993       if (mode == V4DImode || mode == V4DFmode || mode == V16HImode)
21994         {
21995           /* Unfortunately, the VPERMQ and VPERMPD instructions only support
21996              an constant shuffle operand.  With a tiny bit of effort we can
21997              use VPERMD instead.  A re-interpretation stall for V4DFmode is
21998              unfortunate but there's no avoiding it.
21999              Similarly for V16HImode we don't have instructions for variable
22000              shuffling, while for V32QImode we can use after preparing suitable
22001              masks vpshufb; vpshufb; vpermq; vpor.  */
22002
22003           if (mode == V16HImode)
22004             {
22005               maskmode = mode = V32QImode;
22006               w = 32;
22007               e = 1;
22008             }
22009           else
22010             {
22011               maskmode = mode = V8SImode;
22012               w = 8;
22013               e = 4;
22014             }
22015           t1 = gen_reg_rtx (maskmode);
22016
22017           /* Replicate the low bits of the V4DImode mask into V8SImode:
22018                mask = { A B C D }
22019                t1 = { A A B B C C D D }.  */
22020           for (i = 0; i < w / 2; ++i)
22021             vec[i*2 + 1] = vec[i*2] = GEN_INT (i * 2);
22022           vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22023           vt = force_reg (maskmode, vt);
22024           mask = gen_lowpart (maskmode, mask);
22025           if (maskmode == V8SImode)
22026             emit_insn (gen_avx2_permvarv8si (t1, mask, vt));
22027           else
22028             emit_insn (gen_avx2_pshufbv32qi3 (t1, mask, vt));
22029
22030           /* Multiply the shuffle indicies by two.  */
22031           t1 = expand_simple_binop (maskmode, PLUS, t1, t1, t1, 1,
22032                                     OPTAB_DIRECT);
22033
22034           /* Add one to the odd shuffle indicies:
22035                 t1 = { A*2, A*2+1, B*2, B*2+1, ... }.  */
22036           for (i = 0; i < w / 2; ++i)
22037             {
22038               vec[i * 2] = const0_rtx;
22039               vec[i * 2 + 1] = const1_rtx;
22040             }
22041           vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22042           vt = validize_mem (force_const_mem (maskmode, vt));
22043           t1 = expand_simple_binop (maskmode, PLUS, t1, vt, t1, 1,
22044                                     OPTAB_DIRECT);
22045
22046           /* Continue as if V8SImode (resp. V32QImode) was used initially.  */
22047           operands[3] = mask = t1;
22048           target = gen_reg_rtx (mode);
22049           op0 = gen_lowpart (mode, op0);
22050           op1 = gen_lowpart (mode, op1);
22051         }
22052
22053       switch (mode)
22054         {
22055         case V8SImode:
22056           /* The VPERMD and VPERMPS instructions already properly ignore
22057              the high bits of the shuffle elements.  No need for us to
22058              perform an AND ourselves.  */
22059           if (one_operand_shuffle)
22060             {
22061               emit_insn (gen_avx2_permvarv8si (target, op0, mask));
22062               if (target != operands[0])
22063                 emit_move_insn (operands[0],
22064                                 gen_lowpart (GET_MODE (operands[0]), target));
22065             }
22066           else
22067             {
22068               t1 = gen_reg_rtx (V8SImode);
22069               t2 = gen_reg_rtx (V8SImode);
22070               emit_insn (gen_avx2_permvarv8si (t1, op0, mask));
22071               emit_insn (gen_avx2_permvarv8si (t2, op1, mask));
22072               goto merge_two;
22073             }
22074           return;
22075
22076         case V8SFmode:
22077           mask = gen_lowpart (V8SImode, mask);
22078           if (one_operand_shuffle)
22079             emit_insn (gen_avx2_permvarv8sf (target, op0, mask));
22080           else
22081             {
22082               t1 = gen_reg_rtx (V8SFmode);
22083               t2 = gen_reg_rtx (V8SFmode);
22084               emit_insn (gen_avx2_permvarv8sf (t1, op0, mask));
22085               emit_insn (gen_avx2_permvarv8sf (t2, op1, mask));
22086               goto merge_two;
22087             }
22088           return;
22089
22090         case V4SImode:
22091           /* By combining the two 128-bit input vectors into one 256-bit
22092              input vector, we can use VPERMD and VPERMPS for the full
22093              two-operand shuffle.  */
22094           t1 = gen_reg_rtx (V8SImode);
22095           t2 = gen_reg_rtx (V8SImode);
22096           emit_insn (gen_avx_vec_concatv8si (t1, op0, op1));
22097           emit_insn (gen_avx_vec_concatv8si (t2, mask, mask));
22098           emit_insn (gen_avx2_permvarv8si (t1, t1, t2));
22099           emit_insn (gen_avx_vextractf128v8si (target, t1, const0_rtx));
22100           return;
22101
22102         case V4SFmode:
22103           t1 = gen_reg_rtx (V8SFmode);
22104           t2 = gen_reg_rtx (V8SImode);
22105           mask = gen_lowpart (V4SImode, mask);
22106           emit_insn (gen_avx_vec_concatv8sf (t1, op0, op1));
22107           emit_insn (gen_avx_vec_concatv8si (t2, mask, mask));
22108           emit_insn (gen_avx2_permvarv8sf (t1, t1, t2));
22109           emit_insn (gen_avx_vextractf128v8sf (target, t1, const0_rtx));
22110           return;
22111
22112         case V32QImode:
22113           t1 = gen_reg_rtx (V32QImode);
22114           t2 = gen_reg_rtx (V32QImode);
22115           t3 = gen_reg_rtx (V32QImode);
22116           vt2 = GEN_INT (-128);
22117           for (i = 0; i < 32; i++)
22118             vec[i] = vt2;
22119           vt = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));
22120           vt = force_reg (V32QImode, vt);
22121           for (i = 0; i < 32; i++)
22122             vec[i] = i < 16 ? vt2 : const0_rtx;
22123           vt2 = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));
22124           vt2 = force_reg (V32QImode, vt2);
22125           /* From mask create two adjusted masks, which contain the same
22126              bits as mask in the low 7 bits of each vector element.
22127              The first mask will have the most significant bit clear
22128              if it requests element from the same 128-bit lane
22129              and MSB set if it requests element from the other 128-bit lane.
22130              The second mask will have the opposite values of the MSB,
22131              and additionally will have its 128-bit lanes swapped.
22132              E.g. { 07 12 1e 09 ... | 17 19 05 1f ... } mask vector will have
22133              t1   { 07 92 9e 09 ... | 17 19 85 1f ... } and
22134              t3   { 97 99 05 9f ... | 87 12 1e 89 ... } where each ...
22135              stands for other 12 bytes.  */
22136           /* The bit whether element is from the same lane or the other
22137              lane is bit 4, so shift it up by 3 to the MSB position.  */
22138           t5 = gen_reg_rtx (V4DImode);
22139           emit_insn (gen_ashlv4di3 (t5, gen_lowpart (V4DImode, mask),
22140                                     GEN_INT (3)));
22141           /* Clear MSB bits from the mask just in case it had them set.  */
22142           emit_insn (gen_avx2_andnotv32qi3 (t2, vt, mask));
22143           /* After this t1 will have MSB set for elements from other lane.  */
22144           emit_insn (gen_xorv32qi3 (t1, gen_lowpart (V32QImode, t5), vt2));
22145           /* Clear bits other than MSB.  */
22146           emit_insn (gen_andv32qi3 (t1, t1, vt));
22147           /* Or in the lower bits from mask into t3.  */
22148           emit_insn (gen_iorv32qi3 (t3, t1, t2));
22149           /* And invert MSB bits in t1, so MSB is set for elements from the same
22150              lane.  */
22151           emit_insn (gen_xorv32qi3 (t1, t1, vt));
22152           /* Swap 128-bit lanes in t3.  */
22153           t6 = gen_reg_rtx (V4DImode);
22154           emit_insn (gen_avx2_permv4di_1 (t6, gen_lowpart (V4DImode, t3),
22155                                           const2_rtx, GEN_INT (3),
22156                                           const0_rtx, const1_rtx));
22157           /* And or in the lower bits from mask into t1.  */
22158           emit_insn (gen_iorv32qi3 (t1, t1, t2));
22159           if (one_operand_shuffle)
22160             {
22161               /* Each of these shuffles will put 0s in places where
22162                  element from the other 128-bit lane is needed, otherwise
22163                  will shuffle in the requested value.  */
22164               emit_insn (gen_avx2_pshufbv32qi3 (t3, op0,
22165                                                 gen_lowpart (V32QImode, t6)));
22166               emit_insn (gen_avx2_pshufbv32qi3 (t1, op0, t1));
22167               /* For t3 the 128-bit lanes are swapped again.  */
22168               t7 = gen_reg_rtx (V4DImode);
22169               emit_insn (gen_avx2_permv4di_1 (t7, gen_lowpart (V4DImode, t3),
22170                                               const2_rtx, GEN_INT (3),
22171                                               const0_rtx, const1_rtx));
22172               /* And oring both together leads to the result.  */
22173               emit_insn (gen_iorv32qi3 (target, t1,
22174                                         gen_lowpart (V32QImode, t7)));
22175               if (target != operands[0])
22176                 emit_move_insn (operands[0],
22177                                 gen_lowpart (GET_MODE (operands[0]), target));
22178               return;
22179             }
22180
22181           t4 = gen_reg_rtx (V32QImode);
22182           /* Similarly to the above one_operand_shuffle code,
22183              just for repeated twice for each operand.  merge_two:
22184              code will merge the two results together.  */
22185           emit_insn (gen_avx2_pshufbv32qi3 (t4, op0,
22186                                             gen_lowpart (V32QImode, t6)));
22187           emit_insn (gen_avx2_pshufbv32qi3 (t3, op1,
22188                                             gen_lowpart (V32QImode, t6)));
22189           emit_insn (gen_avx2_pshufbv32qi3 (t2, op0, t1));
22190           emit_insn (gen_avx2_pshufbv32qi3 (t1, op1, t1));
22191           t7 = gen_reg_rtx (V4DImode);
22192           emit_insn (gen_avx2_permv4di_1 (t7, gen_lowpart (V4DImode, t4),
22193                                           const2_rtx, GEN_INT (3),
22194                                           const0_rtx, const1_rtx));
22195           t8 = gen_reg_rtx (V4DImode);
22196           emit_insn (gen_avx2_permv4di_1 (t8, gen_lowpart (V4DImode, t3),
22197                                           const2_rtx, GEN_INT (3),
22198                                           const0_rtx, const1_rtx));
22199           emit_insn (gen_iorv32qi3 (t4, t2, gen_lowpart (V32QImode, t7)));
22200           emit_insn (gen_iorv32qi3 (t3, t1, gen_lowpart (V32QImode, t8)));
22201           t1 = t4;
22202           t2 = t3;
22203           goto merge_two;
22204
22205         default:
22206           gcc_assert (GET_MODE_SIZE (mode) <= 16);
22207           break;
22208         }
22209     }
22210
22211   if (TARGET_XOP)
22212     {
22213       /* The XOP VPPERM insn supports three inputs.  By ignoring the 
22214          one_operand_shuffle special case, we avoid creating another
22215          set of constant vectors in memory.  */
22216       one_operand_shuffle = false;
22217
22218       /* mask = mask & {2*w-1, ...} */
22219       vt = GEN_INT (2*w - 1);
22220     }
22221   else
22222     {
22223       /* mask = mask & {w-1, ...} */
22224       vt = GEN_INT (w - 1);
22225     }
22226
22227   for (i = 0; i < w; i++)
22228     vec[i] = vt;
22229   vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22230   mask = expand_simple_binop (maskmode, AND, mask, vt,
22231                               NULL_RTX, 0, OPTAB_DIRECT);
22232
22233   /* For non-QImode operations, convert the word permutation control
22234      into a byte permutation control.  */
22235   if (mode != V16QImode)
22236     {
22237       mask = expand_simple_binop (maskmode, ASHIFT, mask,
22238                                   GEN_INT (exact_log2 (e)),
22239                                   NULL_RTX, 0, OPTAB_DIRECT);
22240
22241       /* Convert mask to vector of chars.  */
22242       mask = force_reg (V16QImode, gen_lowpart (V16QImode, mask));
22243
22244       /* Replicate each of the input bytes into byte positions:
22245          (v2di) --> {0,0,0,0,0,0,0,0, 8,8,8,8,8,8,8,8}
22246          (v4si) --> {0,0,0,0, 4,4,4,4, 8,8,8,8, 12,12,12,12}
22247          (v8hi) --> {0,0, 2,2, 4,4, 6,6, ...}.  */
22248       for (i = 0; i < 16; ++i)
22249         vec[i] = GEN_INT (i/e * e);
22250       vt = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, vec));
22251       vt = validize_mem (force_const_mem (V16QImode, vt));
22252       if (TARGET_XOP)
22253         emit_insn (gen_xop_pperm (mask, mask, mask, vt));
22254       else
22255         emit_insn (gen_ssse3_pshufbv16qi3 (mask, mask, vt));
22256
22257       /* Convert it into the byte positions by doing
22258          mask = mask + {0,1,..,16/w, 0,1,..,16/w, ...}  */
22259       for (i = 0; i < 16; ++i)
22260         vec[i] = GEN_INT (i % e);
22261       vt = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, vec));
22262       vt = validize_mem (force_const_mem (V16QImode, vt));
22263       emit_insn (gen_addv16qi3 (mask, mask, vt));
22264     }
22265
22266   /* The actual shuffle operations all operate on V16QImode.  */
22267   op0 = gen_lowpart (V16QImode, op0);
22268   op1 = gen_lowpart (V16QImode, op1);
22269
22270   if (TARGET_XOP)
22271     {
22272       if (GET_MODE (target) != V16QImode)
22273         target = gen_reg_rtx (V16QImode);
22274       emit_insn (gen_xop_pperm (target, op0, op1, mask));
22275       if (target != operands[0])
22276         emit_move_insn (operands[0],
22277                         gen_lowpart (GET_MODE (operands[0]), target));
22278     }
22279   else if (one_operand_shuffle)
22280     {
22281       if (GET_MODE (target) != V16QImode)
22282         target = gen_reg_rtx (V16QImode);
22283       emit_insn (gen_ssse3_pshufbv16qi3 (target, op0, mask));
22284       if (target != operands[0])
22285         emit_move_insn (operands[0],
22286                         gen_lowpart (GET_MODE (operands[0]), target));
22287     }
22288   else
22289     {
22290       rtx xops[6];
22291       bool ok;
22292
22293       /* Shuffle the two input vectors independently.  */
22294       t1 = gen_reg_rtx (V16QImode);
22295       t2 = gen_reg_rtx (V16QImode);
22296       emit_insn (gen_ssse3_pshufbv16qi3 (t1, op0, mask));
22297       emit_insn (gen_ssse3_pshufbv16qi3 (t2, op1, mask));
22298
22299  merge_two:
22300       /* Then merge them together.  The key is whether any given control
22301          element contained a bit set that indicates the second word.  */
22302       mask = operands[3];
22303       vt = GEN_INT (w);
22304       if (maskmode == V2DImode && !TARGET_SSE4_1)
22305         {
22306           /* Without SSE4.1, we don't have V2DImode EQ.  Perform one
22307              more shuffle to convert the V2DI input mask into a V4SI
22308              input mask.  At which point the masking that expand_int_vcond
22309              will work as desired.  */
22310           rtx t3 = gen_reg_rtx (V4SImode);
22311           emit_insn (gen_sse2_pshufd_1 (t3, gen_lowpart (V4SImode, mask),
22312                                         const0_rtx, const0_rtx,
22313                                         const2_rtx, const2_rtx));
22314           mask = t3;
22315           maskmode = V4SImode;
22316           e = w = 4;
22317         }
22318
22319       for (i = 0; i < w; i++)
22320         vec[i] = vt;
22321       vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22322       vt = force_reg (maskmode, vt);
22323       mask = expand_simple_binop (maskmode, AND, mask, vt,
22324                                   NULL_RTX, 0, OPTAB_DIRECT);
22325
22326       if (GET_MODE (target) != mode)
22327         target = gen_reg_rtx (mode);
22328       xops[0] = target;
22329       xops[1] = gen_lowpart (mode, t2);
22330       xops[2] = gen_lowpart (mode, t1);
22331       xops[3] = gen_rtx_EQ (maskmode, mask, vt);
22332       xops[4] = mask;
22333       xops[5] = vt;
22334       ok = ix86_expand_int_vcond (xops);
22335       gcc_assert (ok);
22336       if (target != operands[0])
22337         emit_move_insn (operands[0],
22338                         gen_lowpart (GET_MODE (operands[0]), target));
22339     }
22340 }
22341
22342 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
22343    true if we should do zero extension, else sign extension.  HIGH_P is
22344    true if we want the N/2 high elements, else the low elements.  */
22345
22346 void
22347 ix86_expand_sse_unpack (rtx dest, rtx src, bool unsigned_p, bool high_p)
22348 {
22349   machine_mode imode = GET_MODE (src);
22350   rtx tmp;
22351
22352   if (TARGET_SSE4_1)
22353     {
22354       rtx (*unpack)(rtx, rtx);
22355       rtx (*extract)(rtx, rtx) = NULL;
22356       machine_mode halfmode = BLKmode;
22357
22358       switch (imode)
22359         {
22360         case V64QImode:
22361           if (unsigned_p)
22362             unpack = gen_avx512bw_zero_extendv32qiv32hi2;
22363           else
22364             unpack = gen_avx512bw_sign_extendv32qiv32hi2;
22365           halfmode = V32QImode;
22366           extract
22367             = high_p ? gen_vec_extract_hi_v64qi : gen_vec_extract_lo_v64qi;
22368           break;
22369         case V32QImode:
22370           if (unsigned_p)
22371             unpack = gen_avx2_zero_extendv16qiv16hi2;
22372           else
22373             unpack = gen_avx2_sign_extendv16qiv16hi2;
22374           halfmode = V16QImode;
22375           extract
22376             = high_p ? gen_vec_extract_hi_v32qi : gen_vec_extract_lo_v32qi;
22377           break;
22378         case V32HImode:
22379           if (unsigned_p)
22380             unpack = gen_avx512f_zero_extendv16hiv16si2;
22381           else
22382             unpack = gen_avx512f_sign_extendv16hiv16si2;
22383           halfmode = V16HImode;
22384           extract
22385             = high_p ? gen_vec_extract_hi_v32hi : gen_vec_extract_lo_v32hi;
22386           break;
22387         case V16HImode:
22388           if (unsigned_p)
22389             unpack = gen_avx2_zero_extendv8hiv8si2;
22390           else
22391             unpack = gen_avx2_sign_extendv8hiv8si2;
22392           halfmode = V8HImode;
22393           extract
22394             = high_p ? gen_vec_extract_hi_v16hi : gen_vec_extract_lo_v16hi;
22395           break;
22396         case V16SImode:
22397           if (unsigned_p)
22398             unpack = gen_avx512f_zero_extendv8siv8di2;
22399           else
22400             unpack = gen_avx512f_sign_extendv8siv8di2;
22401           halfmode = V8SImode;
22402           extract
22403             = high_p ? gen_vec_extract_hi_v16si : gen_vec_extract_lo_v16si;
22404           break;
22405         case V8SImode:
22406           if (unsigned_p)
22407             unpack = gen_avx2_zero_extendv4siv4di2;
22408           else
22409             unpack = gen_avx2_sign_extendv4siv4di2;
22410           halfmode = V4SImode;
22411           extract
22412             = high_p ? gen_vec_extract_hi_v8si : gen_vec_extract_lo_v8si;
22413           break;
22414         case V16QImode:
22415           if (unsigned_p)
22416             unpack = gen_sse4_1_zero_extendv8qiv8hi2;
22417           else
22418             unpack = gen_sse4_1_sign_extendv8qiv8hi2;
22419           break;
22420         case V8HImode:
22421           if (unsigned_p)
22422             unpack = gen_sse4_1_zero_extendv4hiv4si2;
22423           else
22424             unpack = gen_sse4_1_sign_extendv4hiv4si2;
22425           break;
22426         case V4SImode:
22427           if (unsigned_p)
22428             unpack = gen_sse4_1_zero_extendv2siv2di2;
22429           else
22430             unpack = gen_sse4_1_sign_extendv2siv2di2;
22431           break;
22432         default:
22433           gcc_unreachable ();
22434         }
22435
22436       if (GET_MODE_SIZE (imode) >= 32)
22437         {
22438           tmp = gen_reg_rtx (halfmode);
22439           emit_insn (extract (tmp, src));
22440         }
22441       else if (high_p)
22442         {
22443           /* Shift higher 8 bytes to lower 8 bytes.  */
22444           tmp = gen_reg_rtx (V1TImode);
22445           emit_insn (gen_sse2_lshrv1ti3 (tmp, gen_lowpart (V1TImode, src),
22446                                          GEN_INT (64)));
22447           tmp = gen_lowpart (imode, tmp);
22448         }
22449       else
22450         tmp = src;
22451
22452       emit_insn (unpack (dest, tmp));
22453     }
22454   else
22455     {
22456       rtx (*unpack)(rtx, rtx, rtx);
22457
22458       switch (imode)
22459         {
22460         case V16QImode:
22461           if (high_p)
22462             unpack = gen_vec_interleave_highv16qi;
22463           else
22464             unpack = gen_vec_interleave_lowv16qi;
22465           break;
22466         case V8HImode:
22467           if (high_p)
22468             unpack = gen_vec_interleave_highv8hi;
22469           else
22470             unpack = gen_vec_interleave_lowv8hi;
22471           break;
22472         case V4SImode:
22473           if (high_p)
22474             unpack = gen_vec_interleave_highv4si;
22475           else
22476             unpack = gen_vec_interleave_lowv4si;
22477           break;
22478         default:
22479           gcc_unreachable ();
22480         }
22481
22482       if (unsigned_p)
22483         tmp = force_reg (imode, CONST0_RTX (imode));
22484       else
22485         tmp = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
22486                                    src, pc_rtx, pc_rtx);
22487
22488       rtx tmp2 = gen_reg_rtx (imode);
22489       emit_insn (unpack (tmp2, src, tmp));
22490       emit_move_insn (dest, gen_lowpart (GET_MODE (dest), tmp2));
22491     }
22492 }
22493
22494 /* Expand conditional increment or decrement using adb/sbb instructions.
22495    The default case using setcc followed by the conditional move can be
22496    done by generic code.  */
22497 bool
22498 ix86_expand_int_addcc (rtx operands[])
22499 {
22500   enum rtx_code code = GET_CODE (operands[1]);
22501   rtx flags;
22502   rtx (*insn)(rtx, rtx, rtx, rtx, rtx);
22503   rtx compare_op;
22504   rtx val = const0_rtx;
22505   bool fpcmp = false;
22506   machine_mode mode;
22507   rtx op0 = XEXP (operands[1], 0);
22508   rtx op1 = XEXP (operands[1], 1);
22509
22510   if (operands[3] != const1_rtx
22511       && operands[3] != constm1_rtx)
22512     return false;
22513   if (!ix86_expand_carry_flag_compare (code, op0, op1, &compare_op))
22514      return false;
22515   code = GET_CODE (compare_op);
22516
22517   flags = XEXP (compare_op, 0);
22518
22519   if (GET_MODE (flags) == CCFPmode
22520       || GET_MODE (flags) == CCFPUmode)
22521     {
22522       fpcmp = true;
22523       code = ix86_fp_compare_code_to_integer (code);
22524     }
22525
22526   if (code != LTU)
22527     {
22528       val = constm1_rtx;
22529       if (fpcmp)
22530         PUT_CODE (compare_op,
22531                   reverse_condition_maybe_unordered
22532                     (GET_CODE (compare_op)));
22533       else
22534         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
22535     }
22536
22537   mode = GET_MODE (operands[0]);
22538
22539   /* Construct either adc or sbb insn.  */
22540   if ((code == LTU) == (operands[3] == constm1_rtx))
22541     {
22542       switch (mode)
22543         {
22544           case QImode:
22545             insn = gen_subqi3_carry;
22546             break;
22547           case HImode:
22548             insn = gen_subhi3_carry;
22549             break;
22550           case SImode:
22551             insn = gen_subsi3_carry;
22552             break;
22553           case DImode:
22554             insn = gen_subdi3_carry;
22555             break;
22556           default:
22557             gcc_unreachable ();
22558         }
22559     }
22560   else
22561     {
22562       switch (mode)
22563         {
22564           case QImode:
22565             insn = gen_addqi3_carry;
22566             break;
22567           case HImode:
22568             insn = gen_addhi3_carry;
22569             break;
22570           case SImode:
22571             insn = gen_addsi3_carry;
22572             break;
22573           case DImode:
22574             insn = gen_adddi3_carry;
22575             break;
22576           default:
22577             gcc_unreachable ();
22578         }
22579     }
22580   emit_insn (insn (operands[0], operands[2], val, flags, compare_op));
22581
22582   return true;
22583 }
22584
22585
22586 /* Split operands 0 and 1 into half-mode parts.  Similar to split_double_mode,
22587    but works for floating pointer parameters and nonoffsetable memories.
22588    For pushes, it returns just stack offsets; the values will be saved
22589    in the right order.  Maximally three parts are generated.  */
22590
22591 static int
22592 ix86_split_to_parts (rtx operand, rtx *parts, machine_mode mode)
22593 {
22594   int size;
22595
22596   if (!TARGET_64BIT)
22597     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
22598   else
22599     size = (GET_MODE_SIZE (mode) + 4) / 8;
22600
22601   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
22602   gcc_assert (size >= 2 && size <= 4);
22603
22604   /* Optimize constant pool reference to immediates.  This is used by fp
22605      moves, that force all constants to memory to allow combining.  */
22606   if (MEM_P (operand) && MEM_READONLY_P (operand))
22607     {
22608       rtx tmp = maybe_get_pool_constant (operand);
22609       if (tmp)
22610         operand = tmp;
22611     }
22612
22613   if (MEM_P (operand) && !offsettable_memref_p (operand))
22614     {
22615       /* The only non-offsetable memories we handle are pushes.  */
22616       int ok = push_operand (operand, VOIDmode);
22617
22618       gcc_assert (ok);
22619
22620       operand = copy_rtx (operand);
22621       PUT_MODE (operand, word_mode);
22622       parts[0] = parts[1] = parts[2] = parts[3] = operand;
22623       return size;
22624     }
22625
22626   if (GET_CODE (operand) == CONST_VECTOR)
22627     {
22628       machine_mode imode = int_mode_for_mode (mode);
22629       /* Caution: if we looked through a constant pool memory above,
22630          the operand may actually have a different mode now.  That's
22631          ok, since we want to pun this all the way back to an integer.  */
22632       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
22633       gcc_assert (operand != NULL);
22634       mode = imode;
22635     }
22636
22637   if (!TARGET_64BIT)
22638     {
22639       if (mode == DImode)
22640         split_double_mode (mode, &operand, 1, &parts[0], &parts[1]);
22641       else
22642         {
22643           int i;
22644
22645           if (REG_P (operand))
22646             {
22647               gcc_assert (reload_completed);
22648               for (i = 0; i < size; i++)
22649                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
22650             }
22651           else if (offsettable_memref_p (operand))
22652             {
22653               operand = adjust_address (operand, SImode, 0);
22654               parts[0] = operand;
22655               for (i = 1; i < size; i++)
22656                 parts[i] = adjust_address (operand, SImode, 4 * i);
22657             }
22658           else if (GET_CODE (operand) == CONST_DOUBLE)
22659             {
22660               REAL_VALUE_TYPE r;
22661               long l[4];
22662
22663               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
22664               switch (mode)
22665                 {
22666                 case TFmode:
22667                   real_to_target (l, &r, mode);
22668                   parts[3] = gen_int_mode (l[3], SImode);
22669                   parts[2] = gen_int_mode (l[2], SImode);
22670                   break;
22671                 case XFmode:
22672                   /* We can't use REAL_VALUE_TO_TARGET_LONG_DOUBLE since
22673                      long double may not be 80-bit.  */
22674                   real_to_target (l, &r, mode);
22675                   parts[2] = gen_int_mode (l[2], SImode);
22676                   break;
22677                 case DFmode:
22678                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
22679                   break;
22680                 default:
22681                   gcc_unreachable ();
22682                 }
22683               parts[1] = gen_int_mode (l[1], SImode);
22684               parts[0] = gen_int_mode (l[0], SImode);
22685             }
22686           else
22687             gcc_unreachable ();
22688         }
22689     }
22690   else
22691     {
22692       if (mode == TImode)
22693         split_double_mode (mode, &operand, 1, &parts[0], &parts[1]);
22694       if (mode == XFmode || mode == TFmode)
22695         {
22696           machine_mode upper_mode = mode==XFmode ? SImode : DImode;
22697           if (REG_P (operand))
22698             {
22699               gcc_assert (reload_completed);
22700               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
22701               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
22702             }
22703           else if (offsettable_memref_p (operand))
22704             {
22705               operand = adjust_address (operand, DImode, 0);
22706               parts[0] = operand;
22707               parts[1] = adjust_address (operand, upper_mode, 8);
22708             }
22709           else if (GET_CODE (operand) == CONST_DOUBLE)
22710             {
22711               REAL_VALUE_TYPE r;
22712               long l[4];
22713
22714               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
22715               real_to_target (l, &r, mode);
22716
22717               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
22718               if (HOST_BITS_PER_WIDE_INT >= 64)
22719                 parts[0]
22720                   = gen_int_mode
22721                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
22722                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
22723                        DImode);
22724               else
22725                 parts[0] = immed_double_const (l[0], l[1], DImode);
22726
22727               if (upper_mode == SImode)
22728                 parts[1] = gen_int_mode (l[2], SImode);
22729               else if (HOST_BITS_PER_WIDE_INT >= 64)
22730                 parts[1]
22731                   = gen_int_mode
22732                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
22733                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
22734                        DImode);
22735               else
22736                 parts[1] = immed_double_const (l[2], l[3], DImode);
22737             }
22738           else
22739             gcc_unreachable ();
22740         }
22741     }
22742
22743   return size;
22744 }
22745
22746 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
22747    Return false when normal moves are needed; true when all required
22748    insns have been emitted.  Operands 2-4 contain the input values
22749    int the correct order; operands 5-7 contain the output values.  */
22750
22751 void
22752 ix86_split_long_move (rtx operands[])
22753 {
22754   rtx part[2][4];
22755   int nparts, i, j;
22756   int push = 0;
22757   int collisions = 0;
22758   machine_mode mode = GET_MODE (operands[0]);
22759   bool collisionparts[4];
22760
22761   /* The DFmode expanders may ask us to move double.
22762      For 64bit target this is single move.  By hiding the fact
22763      here we simplify i386.md splitters.  */
22764   if (TARGET_64BIT && GET_MODE_SIZE (GET_MODE (operands[0])) == 8)
22765     {
22766       /* Optimize constant pool reference to immediates.  This is used by
22767          fp moves, that force all constants to memory to allow combining.  */
22768
22769       if (MEM_P (operands[1])
22770           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
22771           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
22772         operands[1] = get_pool_constant (XEXP (operands[1], 0));
22773       if (push_operand (operands[0], VOIDmode))
22774         {
22775           operands[0] = copy_rtx (operands[0]);
22776           PUT_MODE (operands[0], word_mode);
22777         }
22778       else
22779         operands[0] = gen_lowpart (DImode, operands[0]);
22780       operands[1] = gen_lowpart (DImode, operands[1]);
22781       emit_move_insn (operands[0], operands[1]);
22782       return;
22783     }
22784
22785   /* The only non-offsettable memory we handle is push.  */
22786   if (push_operand (operands[0], VOIDmode))
22787     push = 1;
22788   else
22789     gcc_assert (!MEM_P (operands[0])
22790                 || offsettable_memref_p (operands[0]));
22791
22792   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
22793   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
22794
22795   /* When emitting push, take care for source operands on the stack.  */
22796   if (push && MEM_P (operands[1])
22797       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
22798     {
22799       rtx src_base = XEXP (part[1][nparts - 1], 0);
22800
22801       /* Compensate for the stack decrement by 4.  */
22802       if (!TARGET_64BIT && nparts == 3
22803           && mode == XFmode && TARGET_128BIT_LONG_DOUBLE)
22804         src_base = plus_constant (Pmode, src_base, 4);
22805
22806       /* src_base refers to the stack pointer and is
22807          automatically decreased by emitted push.  */
22808       for (i = 0; i < nparts; i++)
22809         part[1][i] = change_address (part[1][i],
22810                                      GET_MODE (part[1][i]), src_base);
22811     }
22812
22813   /* We need to do copy in the right order in case an address register
22814      of the source overlaps the destination.  */
22815   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
22816     {
22817       rtx tmp;
22818
22819       for (i = 0; i < nparts; i++)
22820         {
22821           collisionparts[i]
22822             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
22823           if (collisionparts[i])
22824             collisions++;
22825         }
22826
22827       /* Collision in the middle part can be handled by reordering.  */
22828       if (collisions == 1 && nparts == 3 && collisionparts [1])
22829         {
22830           std::swap (part[0][1], part[0][2]);
22831           std::swap (part[1][1], part[1][2]);
22832         }
22833       else if (collisions == 1
22834                && nparts == 4
22835                && (collisionparts [1] || collisionparts [2]))
22836         {
22837           if (collisionparts [1])
22838             {
22839               std::swap (part[0][1], part[0][2]);
22840               std::swap (part[1][1], part[1][2]);
22841             }
22842           else
22843             {
22844               std::swap (part[0][2], part[0][3]);
22845               std::swap (part[1][2], part[1][3]);
22846             }
22847         }
22848
22849       /* If there are more collisions, we can't handle it by reordering.
22850          Do an lea to the last part and use only one colliding move.  */
22851       else if (collisions > 1)
22852         {
22853           rtx base;
22854
22855           collisions = 1;
22856
22857           base = part[0][nparts - 1];
22858
22859           /* Handle the case when the last part isn't valid for lea.
22860              Happens in 64-bit mode storing the 12-byte XFmode.  */
22861           if (GET_MODE (base) != Pmode)
22862             base = gen_rtx_REG (Pmode, REGNO (base));
22863
22864           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
22865           part[1][0] = replace_equiv_address (part[1][0], base);
22866           for (i = 1; i < nparts; i++)
22867             {
22868               tmp = plus_constant (Pmode, base, UNITS_PER_WORD * i);
22869               part[1][i] = replace_equiv_address (part[1][i], tmp);
22870             }
22871         }
22872     }
22873
22874   if (push)
22875     {
22876       if (!TARGET_64BIT)
22877         {
22878           if (nparts == 3)
22879             {
22880               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
22881                 emit_insn (ix86_gen_add3 (stack_pointer_rtx,
22882                                           stack_pointer_rtx, GEN_INT (-4)));
22883               emit_move_insn (part[0][2], part[1][2]);
22884             }
22885           else if (nparts == 4)
22886             {
22887               emit_move_insn (part[0][3], part[1][3]);
22888               emit_move_insn (part[0][2], part[1][2]);
22889             }
22890         }
22891       else
22892         {
22893           /* In 64bit mode we don't have 32bit push available.  In case this is
22894              register, it is OK - we will just use larger counterpart.  We also
22895              retype memory - these comes from attempt to avoid REX prefix on
22896              moving of second half of TFmode value.  */
22897           if (GET_MODE (part[1][1]) == SImode)
22898             {
22899               switch (GET_CODE (part[1][1]))
22900                 {
22901                 case MEM:
22902                   part[1][1] = adjust_address (part[1][1], DImode, 0);
22903                   break;
22904
22905                 case REG:
22906                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
22907                   break;
22908
22909                 default:
22910                   gcc_unreachable ();
22911                 }
22912
22913               if (GET_MODE (part[1][0]) == SImode)
22914                 part[1][0] = part[1][1];
22915             }
22916         }
22917       emit_move_insn (part[0][1], part[1][1]);
22918       emit_move_insn (part[0][0], part[1][0]);
22919       return;
22920     }
22921
22922   /* Choose correct order to not overwrite the source before it is copied.  */
22923   if ((REG_P (part[0][0])
22924        && REG_P (part[1][1])
22925        && (REGNO (part[0][0]) == REGNO (part[1][1])
22926            || (nparts == 3
22927                && REGNO (part[0][0]) == REGNO (part[1][2]))
22928            || (nparts == 4
22929                && REGNO (part[0][0]) == REGNO (part[1][3]))))
22930       || (collisions > 0
22931           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
22932     {
22933       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
22934         {
22935           operands[2 + i] = part[0][j];
22936           operands[6 + i] = part[1][j];
22937         }
22938     }
22939   else
22940     {
22941       for (i = 0; i < nparts; i++)
22942         {
22943           operands[2 + i] = part[0][i];
22944           operands[6 + i] = part[1][i];
22945         }
22946     }
22947
22948   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
22949   if (optimize_insn_for_size_p ())
22950     {
22951       for (j = 0; j < nparts - 1; j++)
22952         if (CONST_INT_P (operands[6 + j])
22953             && operands[6 + j] != const0_rtx
22954             && REG_P (operands[2 + j]))
22955           for (i = j; i < nparts - 1; i++)
22956             if (CONST_INT_P (operands[7 + i])
22957                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
22958               operands[7 + i] = operands[2 + j];
22959     }
22960
22961   for (i = 0; i < nparts; i++)
22962     emit_move_insn (operands[2 + i], operands[6 + i]);
22963
22964   return;
22965 }
22966
22967 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
22968    left shift by a constant, either using a single shift or
22969    a sequence of add instructions.  */
22970
22971 static void
22972 ix86_expand_ashl_const (rtx operand, int count, machine_mode mode)
22973 {
22974   rtx (*insn)(rtx, rtx, rtx);
22975
22976   if (count == 1
22977       || (count * ix86_cost->add <= ix86_cost->shift_const
22978           && !optimize_insn_for_size_p ()))
22979     {
22980       insn = mode == DImode ? gen_addsi3 : gen_adddi3;
22981       while (count-- > 0)
22982         emit_insn (insn (operand, operand, operand));
22983     }
22984   else
22985     {
22986       insn = mode == DImode ? gen_ashlsi3 : gen_ashldi3;
22987       emit_insn (insn (operand, operand, GEN_INT (count)));
22988     }
22989 }
22990
22991 void
22992 ix86_split_ashl (rtx *operands, rtx scratch, machine_mode mode)
22993 {
22994   rtx (*gen_ashl3)(rtx, rtx, rtx);
22995   rtx (*gen_shld)(rtx, rtx, rtx);
22996   int half_width = GET_MODE_BITSIZE (mode) >> 1;
22997
22998   rtx low[2], high[2];
22999   int count;
23000
23001   if (CONST_INT_P (operands[2]))
23002     {
23003       split_double_mode (mode, operands, 2, low, high);
23004       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23005
23006       if (count >= half_width)
23007         {
23008           emit_move_insn (high[0], low[1]);
23009           emit_move_insn (low[0], const0_rtx);
23010
23011           if (count > half_width)
23012             ix86_expand_ashl_const (high[0], count - half_width, mode);
23013         }
23014       else
23015         {
23016           gen_shld = mode == DImode ? gen_x86_shld : gen_x86_64_shld;
23017
23018           if (!rtx_equal_p (operands[0], operands[1]))
23019             emit_move_insn (operands[0], operands[1]);
23020
23021           emit_insn (gen_shld (high[0], low[0], GEN_INT (count)));
23022           ix86_expand_ashl_const (low[0], count, mode);
23023         }
23024       return;
23025     }
23026
23027   split_double_mode (mode, operands, 1, low, high);
23028
23029   gen_ashl3 = mode == DImode ? gen_ashlsi3 : gen_ashldi3;
23030
23031   if (operands[1] == const1_rtx)
23032     {
23033       /* Assuming we've chosen a QImode capable registers, then 1 << N
23034          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
23035       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
23036         {
23037           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
23038
23039           ix86_expand_clear (low[0]);
23040           ix86_expand_clear (high[0]);
23041           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (half_width)));
23042
23043           d = gen_lowpart (QImode, low[0]);
23044           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
23045           s = gen_rtx_EQ (QImode, flags, const0_rtx);
23046           emit_insn (gen_rtx_SET (VOIDmode, d, s));
23047
23048           d = gen_lowpart (QImode, high[0]);
23049           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
23050           s = gen_rtx_NE (QImode, flags, const0_rtx);
23051           emit_insn (gen_rtx_SET (VOIDmode, d, s));
23052         }
23053
23054       /* Otherwise, we can get the same results by manually performing
23055          a bit extract operation on bit 5/6, and then performing the two
23056          shifts.  The two methods of getting 0/1 into low/high are exactly
23057          the same size.  Avoiding the shift in the bit extract case helps
23058          pentium4 a bit; no one else seems to care much either way.  */
23059       else
23060         {
23061           machine_mode half_mode;
23062           rtx (*gen_lshr3)(rtx, rtx, rtx);
23063           rtx (*gen_and3)(rtx, rtx, rtx);
23064           rtx (*gen_xor3)(rtx, rtx, rtx);
23065           HOST_WIDE_INT bits;
23066           rtx x;
23067
23068           if (mode == DImode)
23069             {
23070               half_mode = SImode;
23071               gen_lshr3 = gen_lshrsi3;
23072               gen_and3 = gen_andsi3;
23073               gen_xor3 = gen_xorsi3;
23074               bits = 5;
23075             }
23076           else
23077             {
23078               half_mode = DImode;
23079               gen_lshr3 = gen_lshrdi3;
23080               gen_and3 = gen_anddi3;
23081               gen_xor3 = gen_xordi3;
23082               bits = 6;
23083             }
23084
23085           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
23086             x = gen_rtx_ZERO_EXTEND (half_mode, operands[2]);
23087           else
23088             x = gen_lowpart (half_mode, operands[2]);
23089           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
23090
23091           emit_insn (gen_lshr3 (high[0], high[0], GEN_INT (bits)));
23092           emit_insn (gen_and3 (high[0], high[0], const1_rtx));
23093           emit_move_insn (low[0], high[0]);
23094           emit_insn (gen_xor3 (low[0], low[0], const1_rtx));
23095         }
23096
23097       emit_insn (gen_ashl3 (low[0], low[0], operands[2]));
23098       emit_insn (gen_ashl3 (high[0], high[0], operands[2]));
23099       return;
23100     }
23101
23102   if (operands[1] == constm1_rtx)
23103     {
23104       /* For -1 << N, we can avoid the shld instruction, because we
23105          know that we're shifting 0...31/63 ones into a -1.  */
23106       emit_move_insn (low[0], constm1_rtx);
23107       if (optimize_insn_for_size_p ())
23108         emit_move_insn (high[0], low[0]);
23109       else
23110         emit_move_insn (high[0], constm1_rtx);
23111     }
23112   else
23113     {
23114       gen_shld = mode == DImode ? gen_x86_shld : gen_x86_64_shld;
23115
23116       if (!rtx_equal_p (operands[0], operands[1]))
23117         emit_move_insn (operands[0], operands[1]);
23118
23119       split_double_mode (mode, operands, 1, low, high);
23120       emit_insn (gen_shld (high[0], low[0], operands[2]));
23121     }
23122
23123   emit_insn (gen_ashl3 (low[0], low[0], operands[2]));
23124
23125   if (TARGET_CMOVE && scratch)
23126     {
23127       rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23128         = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23129
23130       ix86_expand_clear (scratch);
23131       emit_insn (gen_x86_shift_adj_1 (high[0], low[0], operands[2], scratch));
23132     }
23133   else
23134     {
23135       rtx (*gen_x86_shift_adj_2)(rtx, rtx, rtx)
23136         = mode == DImode ? gen_x86_shiftsi_adj_2 : gen_x86_shiftdi_adj_2;
23137
23138       emit_insn (gen_x86_shift_adj_2 (high[0], low[0], operands[2]));
23139     }
23140 }
23141
23142 void
23143 ix86_split_ashr (rtx *operands, rtx scratch, machine_mode mode)
23144 {
23145   rtx (*gen_ashr3)(rtx, rtx, rtx)
23146     = mode == DImode ? gen_ashrsi3 : gen_ashrdi3;
23147   rtx (*gen_shrd)(rtx, rtx, rtx);
23148   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23149
23150   rtx low[2], high[2];
23151   int count;
23152
23153   if (CONST_INT_P (operands[2]))
23154     {
23155       split_double_mode (mode, operands, 2, low, high);
23156       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23157
23158       if (count == GET_MODE_BITSIZE (mode) - 1)
23159         {
23160           emit_move_insn (high[0], high[1]);
23161           emit_insn (gen_ashr3 (high[0], high[0],
23162                                 GEN_INT (half_width - 1)));
23163           emit_move_insn (low[0], high[0]);
23164
23165         }
23166       else if (count >= half_width)
23167         {
23168           emit_move_insn (low[0], high[1]);
23169           emit_move_insn (high[0], low[0]);
23170           emit_insn (gen_ashr3 (high[0], high[0],
23171                                 GEN_INT (half_width - 1)));
23172
23173           if (count > half_width)
23174             emit_insn (gen_ashr3 (low[0], low[0],
23175                                   GEN_INT (count - half_width)));
23176         }
23177       else
23178         {
23179           gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23180
23181           if (!rtx_equal_p (operands[0], operands[1]))
23182             emit_move_insn (operands[0], operands[1]);
23183
23184           emit_insn (gen_shrd (low[0], high[0], GEN_INT (count)));
23185           emit_insn (gen_ashr3 (high[0], high[0], GEN_INT (count)));
23186         }
23187     }
23188   else
23189     {
23190       gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23191
23192      if (!rtx_equal_p (operands[0], operands[1]))
23193         emit_move_insn (operands[0], operands[1]);
23194
23195       split_double_mode (mode, operands, 1, low, high);
23196
23197       emit_insn (gen_shrd (low[0], high[0], operands[2]));
23198       emit_insn (gen_ashr3 (high[0], high[0], operands[2]));
23199
23200       if (TARGET_CMOVE && scratch)
23201         {
23202           rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23203             = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23204
23205           emit_move_insn (scratch, high[0]);
23206           emit_insn (gen_ashr3 (scratch, scratch,
23207                                 GEN_INT (half_width - 1)));
23208           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
23209                                           scratch));
23210         }
23211       else
23212         {
23213           rtx (*gen_x86_shift_adj_3)(rtx, rtx, rtx)
23214             = mode == DImode ? gen_x86_shiftsi_adj_3 : gen_x86_shiftdi_adj_3;
23215
23216           emit_insn (gen_x86_shift_adj_3 (low[0], high[0], operands[2]));
23217         }
23218     }
23219 }
23220
23221 void
23222 ix86_split_lshr (rtx *operands, rtx scratch, machine_mode mode)
23223 {
23224   rtx (*gen_lshr3)(rtx, rtx, rtx)
23225     = mode == DImode ? gen_lshrsi3 : gen_lshrdi3;
23226   rtx (*gen_shrd)(rtx, rtx, rtx);
23227   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23228
23229   rtx low[2], high[2];
23230   int count;
23231
23232   if (CONST_INT_P (operands[2]))
23233     {
23234       split_double_mode (mode, operands, 2, low, high);
23235       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23236
23237       if (count >= half_width)
23238         {
23239           emit_move_insn (low[0], high[1]);
23240           ix86_expand_clear (high[0]);
23241
23242           if (count > half_width)
23243             emit_insn (gen_lshr3 (low[0], low[0],
23244                                   GEN_INT (count - half_width)));
23245         }
23246       else
23247         {
23248           gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23249
23250           if (!rtx_equal_p (operands[0], operands[1]))
23251             emit_move_insn (operands[0], operands[1]);
23252
23253           emit_insn (gen_shrd (low[0], high[0], GEN_INT (count)));
23254           emit_insn (gen_lshr3 (high[0], high[0], GEN_INT (count)));
23255         }
23256     }
23257   else
23258     {
23259       gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23260
23261       if (!rtx_equal_p (operands[0], operands[1]))
23262         emit_move_insn (operands[0], operands[1]);
23263
23264       split_double_mode (mode, operands, 1, low, high);
23265
23266       emit_insn (gen_shrd (low[0], high[0], operands[2]));
23267       emit_insn (gen_lshr3 (high[0], high[0], operands[2]));
23268
23269       if (TARGET_CMOVE && scratch)
23270         {
23271           rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23272             = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23273
23274           ix86_expand_clear (scratch);
23275           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
23276                                           scratch));
23277         }
23278       else
23279         {
23280           rtx (*gen_x86_shift_adj_2)(rtx, rtx, rtx)
23281             = mode == DImode ? gen_x86_shiftsi_adj_2 : gen_x86_shiftdi_adj_2;
23282
23283           emit_insn (gen_x86_shift_adj_2 (low[0], high[0], operands[2]));
23284         }
23285     }
23286 }
23287
23288 /* Predict just emitted jump instruction to be taken with probability PROB.  */
23289 static void
23290 predict_jump (int prob)
23291 {
23292   rtx insn = get_last_insn ();
23293   gcc_assert (JUMP_P (insn));
23294   add_int_reg_note (insn, REG_BR_PROB, prob);
23295 }
23296
23297 /* Helper function for the string operations below.  Dest VARIABLE whether
23298    it is aligned to VALUE bytes.  If true, jump to the label.  */
23299 static rtx_code_label *
23300 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
23301 {
23302   rtx_code_label *label = gen_label_rtx ();
23303   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
23304   if (GET_MODE (variable) == DImode)
23305     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
23306   else
23307     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
23308   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
23309                            1, label);
23310   if (epilogue)
23311     predict_jump (REG_BR_PROB_BASE * 50 / 100);
23312   else
23313     predict_jump (REG_BR_PROB_BASE * 90 / 100);
23314   return label;
23315 }
23316
23317 /* Adjust COUNTER by the VALUE.  */
23318 static void
23319 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
23320 {
23321   rtx (*gen_add)(rtx, rtx, rtx)
23322     = GET_MODE (countreg) == DImode ? gen_adddi3 : gen_addsi3;
23323
23324   emit_insn (gen_add (countreg, countreg, GEN_INT (-value)));
23325 }
23326
23327 /* Zero extend possibly SImode EXP to Pmode register.  */
23328 rtx
23329 ix86_zero_extend_to_Pmode (rtx exp)
23330 {
23331   return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
23332 }
23333
23334 /* Divide COUNTREG by SCALE.  */
23335 static rtx
23336 scale_counter (rtx countreg, int scale)
23337 {
23338   rtx sc;
23339
23340   if (scale == 1)
23341     return countreg;
23342   if (CONST_INT_P (countreg))
23343     return GEN_INT (INTVAL (countreg) / scale);
23344   gcc_assert (REG_P (countreg));
23345
23346   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
23347                             GEN_INT (exact_log2 (scale)),
23348                             NULL, 1, OPTAB_DIRECT);
23349   return sc;
23350 }
23351
23352 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
23353    DImode for constant loop counts.  */
23354
23355 static machine_mode
23356 counter_mode (rtx count_exp)
23357 {
23358   if (GET_MODE (count_exp) != VOIDmode)
23359     return GET_MODE (count_exp);
23360   if (!CONST_INT_P (count_exp))
23361     return Pmode;
23362   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
23363     return DImode;
23364   return SImode;
23365 }
23366
23367 /* Copy the address to a Pmode register.  This is used for x32 to
23368    truncate DImode TLS address to a SImode register. */
23369
23370 static rtx
23371 ix86_copy_addr_to_reg (rtx addr)
23372 {
23373   if (GET_MODE (addr) == Pmode || GET_MODE (addr) == VOIDmode)
23374     return copy_addr_to_reg (addr);
23375   else
23376     {
23377       gcc_assert (GET_MODE (addr) == DImode && Pmode == SImode);
23378       return gen_rtx_SUBREG (SImode, copy_to_mode_reg (DImode, addr), 0);
23379     }
23380 }
23381
23382 /* When ISSETMEM is FALSE, output simple loop to move memory pointer to SRCPTR
23383    to DESTPTR via chunks of MODE unrolled UNROLL times, overall size is COUNT
23384    specified in bytes.  When ISSETMEM is TRUE, output the equivalent loop to set
23385    memory by VALUE (supposed to be in MODE).
23386
23387    The size is rounded down to whole number of chunk size moved at once.
23388    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
23389
23390
23391 static void
23392 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
23393                                rtx destptr, rtx srcptr, rtx value,
23394                                rtx count, machine_mode mode, int unroll,
23395                                int expected_size, bool issetmem)
23396 {
23397   rtx_code_label *out_label, *top_label;
23398   rtx iter, tmp;
23399   machine_mode iter_mode = counter_mode (count);
23400   int piece_size_n = GET_MODE_SIZE (mode) * unroll;
23401   rtx piece_size = GEN_INT (piece_size_n);
23402   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
23403   rtx size;
23404   int i;
23405
23406   top_label = gen_label_rtx ();
23407   out_label = gen_label_rtx ();
23408   iter = gen_reg_rtx (iter_mode);
23409
23410   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
23411                               NULL, 1, OPTAB_DIRECT);
23412   /* Those two should combine.  */
23413   if (piece_size == const1_rtx)
23414     {
23415       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
23416                                true, out_label);
23417       predict_jump (REG_BR_PROB_BASE * 10 / 100);
23418     }
23419   emit_move_insn (iter, const0_rtx);
23420
23421   emit_label (top_label);
23422
23423   tmp = convert_modes (Pmode, iter_mode, iter, true);
23424
23425   /* This assert could be relaxed - in this case we'll need to compute
23426      smallest power of two, containing in PIECE_SIZE_N and pass it to
23427      offset_address.  */
23428   gcc_assert ((piece_size_n & (piece_size_n - 1)) == 0);
23429   destmem = offset_address (destmem, tmp, piece_size_n);
23430   destmem = adjust_address (destmem, mode, 0);
23431
23432   if (!issetmem)
23433     {
23434       srcmem = offset_address (srcmem, copy_rtx (tmp), piece_size_n);
23435       srcmem = adjust_address (srcmem, mode, 0);
23436
23437       /* When unrolling for chips that reorder memory reads and writes,
23438          we can save registers by using single temporary.
23439          Also using 4 temporaries is overkill in 32bit mode.  */
23440       if (!TARGET_64BIT && 0)
23441         {
23442           for (i = 0; i < unroll; i++)
23443             {
23444               if (i)
23445                 {
23446                   destmem =
23447                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23448                   srcmem =
23449                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
23450                 }
23451               emit_move_insn (destmem, srcmem);
23452             }
23453         }
23454       else
23455         {
23456           rtx tmpreg[4];
23457           gcc_assert (unroll <= 4);
23458           for (i = 0; i < unroll; i++)
23459             {
23460               tmpreg[i] = gen_reg_rtx (mode);
23461               if (i)
23462                 {
23463                   srcmem =
23464                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
23465                 }
23466               emit_move_insn (tmpreg[i], srcmem);
23467             }
23468           for (i = 0; i < unroll; i++)
23469             {
23470               if (i)
23471                 {
23472                   destmem =
23473                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23474                 }
23475               emit_move_insn (destmem, tmpreg[i]);
23476             }
23477         }
23478     }
23479   else
23480     for (i = 0; i < unroll; i++)
23481       {
23482         if (i)
23483           destmem =
23484             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23485         emit_move_insn (destmem, value);
23486       }
23487
23488   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
23489                              true, OPTAB_LIB_WIDEN);
23490   if (tmp != iter)
23491     emit_move_insn (iter, tmp);
23492
23493   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
23494                            true, top_label);
23495   if (expected_size != -1)
23496     {
23497       expected_size /= GET_MODE_SIZE (mode) * unroll;
23498       if (expected_size == 0)
23499         predict_jump (0);
23500       else if (expected_size > REG_BR_PROB_BASE)
23501         predict_jump (REG_BR_PROB_BASE - 1);
23502       else
23503         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
23504     }
23505   else
23506     predict_jump (REG_BR_PROB_BASE * 80 / 100);
23507   iter = ix86_zero_extend_to_Pmode (iter);
23508   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
23509                              true, OPTAB_LIB_WIDEN);
23510   if (tmp != destptr)
23511     emit_move_insn (destptr, tmp);
23512   if (!issetmem)
23513     {
23514       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
23515                                  true, OPTAB_LIB_WIDEN);
23516       if (tmp != srcptr)
23517         emit_move_insn (srcptr, tmp);
23518     }
23519   emit_label (out_label);
23520 }
23521
23522 /* Output "rep; mov" or "rep; stos" instruction depending on ISSETMEM argument.
23523    When ISSETMEM is true, arguments SRCMEM and SRCPTR are ignored.
23524    When ISSETMEM is false, arguments VALUE and ORIG_VALUE are ignored.
23525    For setmem case, VALUE is a promoted to a wider size ORIG_VALUE.
23526    ORIG_VALUE is the original value passed to memset to fill the memory with.
23527    Other arguments have same meaning as for previous function.  */
23528
23529 static void
23530 expand_set_or_movmem_via_rep (rtx destmem, rtx srcmem,
23531                            rtx destptr, rtx srcptr, rtx value, rtx orig_value,
23532                            rtx count,
23533                            machine_mode mode, bool issetmem)
23534 {
23535   rtx destexp;
23536   rtx srcexp;
23537   rtx countreg;
23538   HOST_WIDE_INT rounded_count;
23539
23540   /* If possible, it is shorter to use rep movs.
23541      TODO: Maybe it is better to move this logic to decide_alg.  */
23542   if (mode == QImode && CONST_INT_P (count) && !(INTVAL (count) & 3)
23543       && (!issetmem || orig_value == const0_rtx))
23544     mode = SImode;
23545
23546   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
23547     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
23548
23549   countreg = ix86_zero_extend_to_Pmode (scale_counter (count,
23550                                                        GET_MODE_SIZE (mode)));
23551   if (mode != QImode)
23552     {
23553       destexp = gen_rtx_ASHIFT (Pmode, countreg,
23554                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
23555       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
23556     }
23557   else
23558     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
23559   if ((!issetmem || orig_value == const0_rtx) && CONST_INT_P (count))
23560     {
23561       rounded_count = (INTVAL (count)
23562                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
23563       destmem = shallow_copy_rtx (destmem);
23564       set_mem_size (destmem, rounded_count);
23565     }
23566   else if (MEM_SIZE_KNOWN_P (destmem))
23567     clear_mem_size (destmem);
23568
23569   if (issetmem)
23570     {
23571       value = force_reg (mode, gen_lowpart (mode, value));
23572       emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
23573     }
23574   else
23575     {
23576       if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
23577         srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
23578       if (mode != QImode)
23579         {
23580           srcexp = gen_rtx_ASHIFT (Pmode, countreg,
23581                                    GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
23582           srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
23583         }
23584       else
23585         srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
23586       if (CONST_INT_P (count))
23587         {
23588           rounded_count = (INTVAL (count)
23589                            & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
23590           srcmem = shallow_copy_rtx (srcmem);
23591           set_mem_size (srcmem, rounded_count);
23592         }
23593       else
23594         {
23595           if (MEM_SIZE_KNOWN_P (srcmem))
23596             clear_mem_size (srcmem);
23597         }
23598       emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
23599                               destexp, srcexp));
23600     }
23601 }
23602
23603 /* This function emits moves to copy SIZE_TO_MOVE bytes from SRCMEM to
23604    DESTMEM.
23605    SRC is passed by pointer to be updated on return.
23606    Return value is updated DST.  */
23607 static rtx
23608 emit_memmov (rtx destmem, rtx *srcmem, rtx destptr, rtx srcptr,
23609              HOST_WIDE_INT size_to_move)
23610 {
23611   rtx dst = destmem, src = *srcmem, adjust, tempreg;
23612   enum insn_code code;
23613   machine_mode move_mode;
23614   int piece_size, i;
23615
23616   /* Find the widest mode in which we could perform moves.
23617      Start with the biggest power of 2 less than SIZE_TO_MOVE and half
23618      it until move of such size is supported.  */
23619   piece_size = 1 << floor_log2 (size_to_move);
23620   move_mode = mode_for_size (piece_size * BITS_PER_UNIT, MODE_INT, 0);
23621   code = optab_handler (mov_optab, move_mode);
23622   while (code == CODE_FOR_nothing && piece_size > 1)
23623     {
23624       piece_size >>= 1;
23625       move_mode = mode_for_size (piece_size * BITS_PER_UNIT, MODE_INT, 0);
23626       code = optab_handler (mov_optab, move_mode);
23627     }
23628
23629   /* Find the corresponding vector mode with the same size as MOVE_MODE.
23630      MOVE_MODE is an integer mode at the moment (SI, DI, TI, etc.).  */
23631   if (GET_MODE_SIZE (move_mode) > GET_MODE_SIZE (word_mode))
23632     {
23633       int nunits = GET_MODE_SIZE (move_mode) / GET_MODE_SIZE (word_mode);
23634       move_mode = mode_for_vector (word_mode, nunits);
23635       code = optab_handler (mov_optab, move_mode);
23636       if (code == CODE_FOR_nothing)
23637         {
23638           move_mode = word_mode;
23639           piece_size = GET_MODE_SIZE (move_mode);
23640           code = optab_handler (mov_optab, move_mode);
23641         }
23642     }
23643   gcc_assert (code != CODE_FOR_nothing);
23644
23645   dst = adjust_automodify_address_nv (dst, move_mode, destptr, 0);
23646   src = adjust_automodify_address_nv (src, move_mode, srcptr, 0);
23647
23648   /* Emit moves.  We'll need SIZE_TO_MOVE/PIECE_SIZES moves.  */
23649   gcc_assert (size_to_move % piece_size == 0);
23650   adjust = GEN_INT (piece_size);
23651   for (i = 0; i < size_to_move; i += piece_size)
23652     {
23653       /* We move from memory to memory, so we'll need to do it via
23654          a temporary register.  */
23655       tempreg = gen_reg_rtx (move_mode);
23656       emit_insn (GEN_FCN (code) (tempreg, src));
23657       emit_insn (GEN_FCN (code) (dst, tempreg));
23658
23659       emit_move_insn (destptr,
23660                       gen_rtx_PLUS (Pmode, copy_rtx (destptr), adjust));
23661       emit_move_insn (srcptr,
23662                       gen_rtx_PLUS (Pmode, copy_rtx (srcptr), adjust));
23663
23664       dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23665                                           piece_size);
23666       src = adjust_automodify_address_nv (src, move_mode, srcptr,
23667                                           piece_size);
23668     }
23669
23670   /* Update DST and SRC rtx.  */
23671   *srcmem = src;
23672   return dst;
23673 }
23674
23675 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
23676 static void
23677 expand_movmem_epilogue (rtx destmem, rtx srcmem,
23678                         rtx destptr, rtx srcptr, rtx count, int max_size)
23679 {
23680   rtx src, dest;
23681   if (CONST_INT_P (count))
23682     {
23683       HOST_WIDE_INT countval = INTVAL (count);
23684       HOST_WIDE_INT epilogue_size = countval % max_size;
23685       int i;
23686
23687       /* For now MAX_SIZE should be a power of 2.  This assert could be
23688          relaxed, but it'll require a bit more complicated epilogue
23689          expanding.  */
23690       gcc_assert ((max_size & (max_size - 1)) == 0);
23691       for (i = max_size; i >= 1; i >>= 1)
23692         {
23693           if (epilogue_size & i)
23694             destmem = emit_memmov (destmem, &srcmem, destptr, srcptr, i);
23695         }
23696       return;
23697     }
23698   if (max_size > 8)
23699     {
23700       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
23701                                     count, 1, OPTAB_DIRECT);
23702       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
23703                                      count, QImode, 1, 4, false);
23704       return;
23705     }
23706
23707   /* When there are stringops, we can cheaply increase dest and src pointers.
23708      Otherwise we save code size by maintaining offset (zero is readily
23709      available from preceding rep operation) and using x86 addressing modes.
23710    */
23711   if (TARGET_SINGLE_STRINGOP)
23712     {
23713       if (max_size > 4)
23714         {
23715           rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23716           src = change_address (srcmem, SImode, srcptr);
23717           dest = change_address (destmem, SImode, destptr);
23718           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23719           emit_label (label);
23720           LABEL_NUSES (label) = 1;
23721         }
23722       if (max_size > 2)
23723         {
23724           rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23725           src = change_address (srcmem, HImode, srcptr);
23726           dest = change_address (destmem, HImode, destptr);
23727           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23728           emit_label (label);
23729           LABEL_NUSES (label) = 1;
23730         }
23731       if (max_size > 1)
23732         {
23733           rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23734           src = change_address (srcmem, QImode, srcptr);
23735           dest = change_address (destmem, QImode, destptr);
23736           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23737           emit_label (label);
23738           LABEL_NUSES (label) = 1;
23739         }
23740     }
23741   else
23742     {
23743       rtx offset = force_reg (Pmode, const0_rtx);
23744       rtx tmp;
23745
23746       if (max_size > 4)
23747         {
23748           rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23749           src = change_address (srcmem, SImode, srcptr);
23750           dest = change_address (destmem, SImode, destptr);
23751           emit_move_insn (dest, src);
23752           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
23753                                      true, OPTAB_LIB_WIDEN);
23754           if (tmp != offset)
23755             emit_move_insn (offset, tmp);
23756           emit_label (label);
23757           LABEL_NUSES (label) = 1;
23758         }
23759       if (max_size > 2)
23760         {
23761           rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23762           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
23763           src = change_address (srcmem, HImode, tmp);
23764           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
23765           dest = change_address (destmem, HImode, tmp);
23766           emit_move_insn (dest, src);
23767           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
23768                                      true, OPTAB_LIB_WIDEN);
23769           if (tmp != offset)
23770             emit_move_insn (offset, tmp);
23771           emit_label (label);
23772           LABEL_NUSES (label) = 1;
23773         }
23774       if (max_size > 1)
23775         {
23776           rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23777           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
23778           src = change_address (srcmem, QImode, tmp);
23779           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
23780           dest = change_address (destmem, QImode, tmp);
23781           emit_move_insn (dest, src);
23782           emit_label (label);
23783           LABEL_NUSES (label) = 1;
23784         }
23785     }
23786 }
23787
23788 /* This function emits moves to fill SIZE_TO_MOVE bytes starting from DESTMEM
23789    with value PROMOTED_VAL.
23790    SRC is passed by pointer to be updated on return.
23791    Return value is updated DST.  */
23792 static rtx
23793 emit_memset (rtx destmem, rtx destptr, rtx promoted_val,
23794              HOST_WIDE_INT size_to_move)
23795 {
23796   rtx dst = destmem, adjust;
23797   enum insn_code code;
23798   machine_mode move_mode;
23799   int piece_size, i;
23800
23801   /* Find the widest mode in which we could perform moves.
23802      Start with the biggest power of 2 less than SIZE_TO_MOVE and half
23803      it until move of such size is supported.  */
23804   move_mode = GET_MODE (promoted_val);
23805   if (move_mode == VOIDmode)
23806     move_mode = QImode;
23807   if (size_to_move < GET_MODE_SIZE (move_mode))
23808     {
23809       move_mode = mode_for_size (size_to_move * BITS_PER_UNIT, MODE_INT, 0);
23810       promoted_val = gen_lowpart (move_mode, promoted_val);
23811     }
23812   piece_size = GET_MODE_SIZE (move_mode);
23813   code = optab_handler (mov_optab, move_mode);
23814   gcc_assert (code != CODE_FOR_nothing && promoted_val != NULL_RTX);
23815
23816   dst = adjust_automodify_address_nv (dst, move_mode, destptr, 0);
23817
23818   /* Emit moves.  We'll need SIZE_TO_MOVE/PIECE_SIZES moves.  */
23819   gcc_assert (size_to_move % piece_size == 0);
23820   adjust = GEN_INT (piece_size);
23821   for (i = 0; i < size_to_move; i += piece_size)
23822     {
23823       if (piece_size <= GET_MODE_SIZE (word_mode))
23824         {
23825           emit_insn (gen_strset (destptr, dst, promoted_val));
23826           dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23827                                               piece_size);
23828           continue;
23829         }
23830
23831       emit_insn (GEN_FCN (code) (dst, promoted_val));
23832
23833       emit_move_insn (destptr,
23834                       gen_rtx_PLUS (Pmode, copy_rtx (destptr), adjust));
23835
23836       dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23837                                           piece_size);
23838     }
23839
23840   /* Update DST rtx.  */
23841   return dst;
23842 }
23843 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
23844 static void
23845 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
23846                                  rtx count, int max_size)
23847 {
23848   count =
23849     expand_simple_binop (counter_mode (count), AND, count,
23850                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
23851   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
23852                                  gen_lowpart (QImode, value), count, QImode,
23853                                  1, max_size / 2, true);
23854 }
23855
23856 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
23857 static void
23858 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx vec_value,
23859                         rtx count, int max_size)
23860 {
23861   rtx dest;
23862
23863   if (CONST_INT_P (count))
23864     {
23865       HOST_WIDE_INT countval = INTVAL (count);
23866       HOST_WIDE_INT epilogue_size = countval % max_size;
23867       int i;
23868
23869       /* For now MAX_SIZE should be a power of 2.  This assert could be
23870          relaxed, but it'll require a bit more complicated epilogue
23871          expanding.  */
23872       gcc_assert ((max_size & (max_size - 1)) == 0);
23873       for (i = max_size; i >= 1; i >>= 1)
23874         {
23875           if (epilogue_size & i)
23876             {
23877               if (vec_value && i > GET_MODE_SIZE (GET_MODE (value)))
23878                 destmem = emit_memset (destmem, destptr, vec_value, i);
23879               else
23880                 destmem = emit_memset (destmem, destptr, value, i);
23881             }
23882         }
23883       return;
23884     }
23885   if (max_size > 32)
23886     {
23887       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
23888       return;
23889     }
23890   if (max_size > 16)
23891     {
23892       rtx_code_label *label = ix86_expand_aligntest (count, 16, true);
23893       if (TARGET_64BIT)
23894         {
23895           dest = change_address (destmem, DImode, destptr);
23896           emit_insn (gen_strset (destptr, dest, value));
23897           dest = adjust_automodify_address_nv (dest, DImode, destptr, 8);
23898           emit_insn (gen_strset (destptr, dest, value));
23899         }
23900       else
23901         {
23902           dest = change_address (destmem, SImode, destptr);
23903           emit_insn (gen_strset (destptr, dest, value));
23904           dest = adjust_automodify_address_nv (dest, SImode, destptr, 4);
23905           emit_insn (gen_strset (destptr, dest, value));
23906           dest = adjust_automodify_address_nv (dest, SImode, destptr, 8);
23907           emit_insn (gen_strset (destptr, dest, value));
23908           dest = adjust_automodify_address_nv (dest, SImode, destptr, 12);
23909           emit_insn (gen_strset (destptr, dest, value));
23910         }
23911       emit_label (label);
23912       LABEL_NUSES (label) = 1;
23913     }
23914   if (max_size > 8)
23915     {
23916       rtx_code_label *label = ix86_expand_aligntest (count, 8, true);
23917       if (TARGET_64BIT)
23918         {
23919           dest = change_address (destmem, DImode, destptr);
23920           emit_insn (gen_strset (destptr, dest, value));
23921         }
23922       else
23923         {
23924           dest = change_address (destmem, SImode, destptr);
23925           emit_insn (gen_strset (destptr, dest, value));
23926           dest = adjust_automodify_address_nv (dest, SImode, destptr, 4);
23927           emit_insn (gen_strset (destptr, dest, value));
23928         }
23929       emit_label (label);
23930       LABEL_NUSES (label) = 1;
23931     }
23932   if (max_size > 4)
23933     {
23934       rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23935       dest = change_address (destmem, SImode, destptr);
23936       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
23937       emit_label (label);
23938       LABEL_NUSES (label) = 1;
23939     }
23940   if (max_size > 2)
23941     {
23942       rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23943       dest = change_address (destmem, HImode, destptr);
23944       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
23945       emit_label (label);
23946       LABEL_NUSES (label) = 1;
23947     }
23948   if (max_size > 1)
23949     {
23950       rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23951       dest = change_address (destmem, QImode, destptr);
23952       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
23953       emit_label (label);
23954       LABEL_NUSES (label) = 1;
23955     }
23956 }
23957
23958 /* Depending on ISSETMEM, copy enough from SRCMEM to DESTMEM or set enough to
23959    DESTMEM to align it to DESIRED_ALIGNMENT.  Original alignment is ALIGN.
23960    Depending on ISSETMEM, either arguments SRCMEM/SRCPTR or VALUE/VEC_VALUE are
23961    ignored.
23962    Return value is updated DESTMEM.  */
23963 static rtx
23964 expand_set_or_movmem_prologue (rtx destmem, rtx srcmem,
23965                                   rtx destptr, rtx srcptr, rtx value,
23966                                   rtx vec_value, rtx count, int align,
23967                                   int desired_alignment, bool issetmem)
23968 {
23969   int i;
23970   for (i = 1; i < desired_alignment; i <<= 1)
23971     {
23972       if (align <= i)
23973         {
23974           rtx_code_label *label = ix86_expand_aligntest (destptr, i, false);
23975           if (issetmem)
23976             {
23977               if (vec_value && i > GET_MODE_SIZE (GET_MODE (value)))
23978                 destmem = emit_memset (destmem, destptr, vec_value, i);
23979               else
23980                 destmem = emit_memset (destmem, destptr, value, i);
23981             }
23982           else
23983             destmem = emit_memmov (destmem, &srcmem, destptr, srcptr, i);
23984           ix86_adjust_counter (count, i);
23985           emit_label (label);
23986           LABEL_NUSES (label) = 1;
23987           set_mem_align (destmem, i * 2 * BITS_PER_UNIT);
23988         }
23989     }
23990   return destmem;
23991 }
23992
23993 /* Test if COUNT&SIZE is nonzero and if so, expand movme
23994    or setmem sequence that is valid for SIZE..2*SIZE-1 bytes
23995    and jump to DONE_LABEL.  */
23996 static void
23997 expand_small_movmem_or_setmem (rtx destmem, rtx srcmem,
23998                                rtx destptr, rtx srcptr,
23999                                rtx value, rtx vec_value,
24000                                rtx count, int size,
24001                                rtx done_label, bool issetmem)
24002 {
24003   rtx_code_label *label = ix86_expand_aligntest (count, size, false);
24004   machine_mode mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 1);
24005   rtx modesize;
24006   int n;
24007
24008   /* If we do not have vector value to copy, we must reduce size.  */
24009   if (issetmem)
24010     {
24011       if (!vec_value)
24012         {
24013           if (GET_MODE (value) == VOIDmode && size > 8)
24014             mode = Pmode;
24015           else if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (value)))
24016             mode = GET_MODE (value);
24017         }
24018       else
24019         mode = GET_MODE (vec_value), value = vec_value;
24020     }
24021   else
24022     {
24023       /* Choose appropriate vector mode.  */
24024       if (size >= 32)
24025         mode = TARGET_AVX ? V32QImode : TARGET_SSE ? V16QImode : DImode;
24026       else if (size >= 16)
24027         mode = TARGET_SSE ? V16QImode : DImode;
24028       srcmem = change_address (srcmem, mode, srcptr);
24029     }
24030   destmem = change_address (destmem, mode, destptr);
24031   modesize = GEN_INT (GET_MODE_SIZE (mode));
24032   gcc_assert (GET_MODE_SIZE (mode) <= size);
24033   for (n = 0; n * GET_MODE_SIZE (mode) < size; n++)
24034     {
24035       if (issetmem)
24036         emit_move_insn (destmem, gen_lowpart (mode, value));
24037       else
24038         {
24039           emit_move_insn (destmem, srcmem);
24040           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24041         }
24042       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24043     }
24044
24045   destmem = offset_address (destmem, count, 1);
24046   destmem = offset_address (destmem, GEN_INT (-2 * size),
24047                             GET_MODE_SIZE (mode));
24048   if (!issetmem)
24049     {
24050       srcmem = offset_address (srcmem, count, 1);
24051       srcmem = offset_address (srcmem, GEN_INT (-2 * size),
24052                                GET_MODE_SIZE (mode));
24053     }
24054   for (n = 0; n * GET_MODE_SIZE (mode) < size; n++)
24055     {
24056       if (issetmem)
24057         emit_move_insn (destmem, gen_lowpart (mode, value));
24058       else
24059         {
24060           emit_move_insn (destmem, srcmem);
24061           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24062         }
24063       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24064     }
24065   emit_jump_insn (gen_jump (done_label));
24066   emit_barrier ();
24067
24068   emit_label (label);
24069   LABEL_NUSES (label) = 1;
24070 }
24071
24072 /* Handle small memcpy (up to SIZE that is supposed to be small power of 2.
24073    and get ready for the main memcpy loop by copying iniital DESIRED_ALIGN-ALIGN
24074    bytes and last SIZE bytes adjusitng DESTPTR/SRCPTR/COUNT in a way we can
24075    proceed with an loop copying SIZE bytes at once. Do moves in MODE.
24076    DONE_LABEL is a label after the whole copying sequence. The label is created
24077    on demand if *DONE_LABEL is NULL.
24078    MIN_SIZE is minimal size of block copied.  This value gets adjusted for new
24079    bounds after the initial copies. 
24080
24081    DESTMEM/SRCMEM are memory expressions pointing to the copies block,
24082    DESTPTR/SRCPTR are pointers to the block. DYNAMIC_CHECK indicate whether
24083    we will dispatch to a library call for large blocks.
24084
24085    In pseudocode we do:
24086
24087    if (COUNT < SIZE)
24088      {
24089        Assume that SIZE is 4. Bigger sizes are handled analogously
24090        if (COUNT & 4)
24091          {
24092             copy 4 bytes from SRCPTR to DESTPTR
24093             copy 4 bytes from SRCPTR + COUNT - 4 to DESTPTR + COUNT - 4
24094             goto done_label
24095          }
24096        if (!COUNT)
24097          goto done_label;
24098        copy 1 byte from SRCPTR to DESTPTR
24099        if (COUNT & 2)
24100          {
24101             copy 2 bytes from SRCPTR to DESTPTR
24102             copy 2 bytes from SRCPTR + COUNT - 2 to DESTPTR + COUNT - 2
24103          }
24104      }
24105    else
24106      {
24107        copy at least DESIRED_ALIGN-ALIGN bytes from SRCPTR to DESTPTR
24108        copy SIZE bytes from SRCPTR + COUNT - SIZE to DESTPTR + COUNT -SIZE
24109
24110        OLD_DESPTR = DESTPTR;
24111        Align DESTPTR up to DESIRED_ALIGN
24112        SRCPTR += DESTPTR - OLD_DESTPTR
24113        COUNT -= DEST_PTR - OLD_DESTPTR
24114        if (DYNAMIC_CHECK)
24115          Round COUNT down to multiple of SIZE
24116        << optional caller supplied zero size guard is here >>
24117        << optional caller suppplied dynamic check is here >>
24118        << caller supplied main copy loop is here >>
24119      }
24120    done_label:
24121   */
24122 static void
24123 expand_set_or_movmem_prologue_epilogue_by_misaligned_moves (rtx destmem, rtx srcmem,
24124                                                             rtx *destptr, rtx *srcptr,
24125                                                             machine_mode mode,
24126                                                             rtx value, rtx vec_value,
24127                                                             rtx *count,
24128                                                             rtx_code_label **done_label,
24129                                                             int size,
24130                                                             int desired_align,
24131                                                             int align,
24132                                                             unsigned HOST_WIDE_INT *min_size,
24133                                                             bool dynamic_check,
24134                                                             bool issetmem)
24135 {
24136   rtx_code_label *loop_label = NULL, *label;
24137   int n;
24138   rtx modesize;
24139   int prolog_size = 0;
24140   rtx mode_value;
24141
24142   /* Chose proper value to copy.  */
24143   if (issetmem && VECTOR_MODE_P (mode))
24144     mode_value = vec_value;
24145   else
24146     mode_value = value;
24147   gcc_assert (GET_MODE_SIZE (mode) <= size);
24148
24149   /* See if block is big or small, handle small blocks.  */
24150   if (!CONST_INT_P (*count) && *min_size < (unsigned HOST_WIDE_INT)size)
24151     {
24152       int size2 = size;
24153       loop_label = gen_label_rtx ();
24154
24155       if (!*done_label)
24156         *done_label = gen_label_rtx ();
24157
24158       emit_cmp_and_jump_insns (*count, GEN_INT (size2), GE, 0, GET_MODE (*count),
24159                                1, loop_label);
24160       size2 >>= 1;
24161
24162       /* Handle sizes > 3.  */
24163       for (;size2 > 2; size2 >>= 1)
24164         expand_small_movmem_or_setmem (destmem, srcmem,
24165                                        *destptr, *srcptr,
24166                                        value, vec_value,
24167                                        *count,
24168                                        size2, *done_label, issetmem);
24169       /* Nothing to copy?  Jump to DONE_LABEL if so */
24170       emit_cmp_and_jump_insns (*count, const0_rtx, EQ, 0, GET_MODE (*count),
24171                                1, *done_label);
24172
24173       /* Do a byte copy.  */
24174       destmem = change_address (destmem, QImode, *destptr);
24175       if (issetmem)
24176         emit_move_insn (destmem, gen_lowpart (QImode, value));
24177       else
24178         {
24179           srcmem = change_address (srcmem, QImode, *srcptr);
24180           emit_move_insn (destmem, srcmem);
24181         }
24182
24183       /* Handle sizes 2 and 3.  */
24184       label = ix86_expand_aligntest (*count, 2, false);
24185       destmem = change_address (destmem, HImode, *destptr);
24186       destmem = offset_address (destmem, *count, 1);
24187       destmem = offset_address (destmem, GEN_INT (-2), 2);
24188       if (issetmem)
24189         emit_move_insn (destmem, gen_lowpart (HImode, value));
24190       else
24191         {
24192           srcmem = change_address (srcmem, HImode, *srcptr);
24193           srcmem = offset_address (srcmem, *count, 1);
24194           srcmem = offset_address (srcmem, GEN_INT (-2), 2);
24195           emit_move_insn (destmem, srcmem);
24196         }
24197
24198       emit_label (label);
24199       LABEL_NUSES (label) = 1;
24200       emit_jump_insn (gen_jump (*done_label));
24201       emit_barrier ();
24202     }
24203   else
24204     gcc_assert (*min_size >= (unsigned HOST_WIDE_INT)size
24205                 || UINTVAL (*count) >= (unsigned HOST_WIDE_INT)size);
24206
24207   /* Start memcpy for COUNT >= SIZE.  */
24208   if (loop_label)
24209     {
24210        emit_label (loop_label);
24211        LABEL_NUSES (loop_label) = 1;
24212     }
24213
24214   /* Copy first desired_align bytes.  */
24215   if (!issetmem)
24216     srcmem = change_address (srcmem, mode, *srcptr);
24217   destmem = change_address (destmem, mode, *destptr);
24218   modesize = GEN_INT (GET_MODE_SIZE (mode));
24219   for (n = 0; prolog_size < desired_align - align; n++)
24220     {
24221       if (issetmem)
24222         emit_move_insn (destmem, mode_value);
24223       else
24224         {
24225           emit_move_insn (destmem, srcmem);
24226           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24227         }
24228       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24229       prolog_size += GET_MODE_SIZE (mode);
24230     }
24231
24232
24233   /* Copy last SIZE bytes.  */
24234   destmem = offset_address (destmem, *count, 1);
24235   destmem = offset_address (destmem,
24236                             GEN_INT (-size - prolog_size),
24237                             1);
24238   if (issetmem)
24239     emit_move_insn (destmem, mode_value);
24240   else
24241     {
24242       srcmem = offset_address (srcmem, *count, 1);
24243       srcmem = offset_address (srcmem,
24244                                GEN_INT (-size - prolog_size),
24245                                1);
24246       emit_move_insn (destmem, srcmem);
24247     }
24248   for (n = 1; n * GET_MODE_SIZE (mode) < size; n++)
24249     {
24250       destmem = offset_address (destmem, modesize, 1);
24251       if (issetmem)
24252         emit_move_insn (destmem, mode_value);
24253       else
24254         {
24255           srcmem = offset_address (srcmem, modesize, 1);
24256           emit_move_insn (destmem, srcmem);
24257         }
24258     }
24259
24260   /* Align destination.  */
24261   if (desired_align > 1 && desired_align > align)
24262     {
24263       rtx saveddest = *destptr;
24264
24265       gcc_assert (desired_align <= size);
24266       /* Align destptr up, place it to new register.  */
24267       *destptr = expand_simple_binop (GET_MODE (*destptr), PLUS, *destptr,
24268                                       GEN_INT (prolog_size),
24269                                       NULL_RTX, 1, OPTAB_DIRECT);
24270       *destptr = expand_simple_binop (GET_MODE (*destptr), AND, *destptr,
24271                                       GEN_INT (-desired_align),
24272                                       *destptr, 1, OPTAB_DIRECT);
24273       /* See how many bytes we skipped.  */
24274       saveddest = expand_simple_binop (GET_MODE (*destptr), MINUS, saveddest,
24275                                        *destptr,
24276                                        saveddest, 1, OPTAB_DIRECT);
24277       /* Adjust srcptr and count.  */
24278       if (!issetmem)
24279         *srcptr = expand_simple_binop (GET_MODE (*srcptr), MINUS, *srcptr, saveddest,
24280                                         *srcptr, 1, OPTAB_DIRECT);
24281       *count = expand_simple_binop (GET_MODE (*count), PLUS, *count,
24282                                     saveddest, *count, 1, OPTAB_DIRECT);
24283       /* We copied at most size + prolog_size.  */
24284       if (*min_size > (unsigned HOST_WIDE_INT)(size + prolog_size))
24285         *min_size = (*min_size - size) & ~(unsigned HOST_WIDE_INT)(size - 1);
24286       else
24287         *min_size = 0;
24288
24289       /* Our loops always round down the bock size, but for dispatch to library
24290          we need precise value.  */
24291       if (dynamic_check)
24292         *count = expand_simple_binop (GET_MODE (*count), AND, *count,
24293                                       GEN_INT (-size), *count, 1, OPTAB_DIRECT);
24294     }
24295   else
24296     {
24297       gcc_assert (prolog_size == 0);
24298       /* Decrease count, so we won't end up copying last word twice.  */
24299       if (!CONST_INT_P (*count))
24300         *count = expand_simple_binop (GET_MODE (*count), PLUS, *count,
24301                                       constm1_rtx, *count, 1, OPTAB_DIRECT);
24302       else
24303         *count = GEN_INT ((UINTVAL (*count) - 1) & ~(unsigned HOST_WIDE_INT)(size - 1));
24304       if (*min_size)
24305         *min_size = (*min_size - 1) & ~(unsigned HOST_WIDE_INT)(size - 1);
24306     }
24307 }
24308
24309
24310 /* This function is like the previous one, except here we know how many bytes
24311    need to be copied.  That allows us to update alignment not only of DST, which
24312    is returned, but also of SRC, which is passed as a pointer for that
24313    reason.  */
24314 static rtx
24315 expand_set_or_movmem_constant_prologue (rtx dst, rtx *srcp, rtx destreg,
24316                                            rtx srcreg, rtx value, rtx vec_value,
24317                                            int desired_align, int align_bytes,
24318                                            bool issetmem)
24319 {
24320   rtx src = NULL;
24321   rtx orig_dst = dst;
24322   rtx orig_src = NULL;
24323   int piece_size = 1;
24324   int copied_bytes = 0;
24325
24326   if (!issetmem)
24327     {
24328       gcc_assert (srcp != NULL);
24329       src = *srcp;
24330       orig_src = src;
24331     }
24332
24333   for (piece_size = 1;
24334        piece_size <= desired_align && copied_bytes < align_bytes;
24335        piece_size <<= 1)
24336     {
24337       if (align_bytes & piece_size)
24338         {
24339           if (issetmem)
24340             {
24341               if (vec_value && piece_size > GET_MODE_SIZE (GET_MODE (value)))
24342                 dst = emit_memset (dst, destreg, vec_value, piece_size);
24343               else
24344                 dst = emit_memset (dst, destreg, value, piece_size);
24345             }
24346           else
24347             dst = emit_memmov (dst, &src, destreg, srcreg, piece_size);
24348           copied_bytes += piece_size;
24349         }
24350     }
24351   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
24352     set_mem_align (dst, desired_align * BITS_PER_UNIT);
24353   if (MEM_SIZE_KNOWN_P (orig_dst))
24354     set_mem_size (dst, MEM_SIZE (orig_dst) - align_bytes);
24355
24356   if (!issetmem)
24357     {
24358       int src_align_bytes = get_mem_align_offset (src, desired_align
24359                                                        * BITS_PER_UNIT);
24360       if (src_align_bytes >= 0)
24361         src_align_bytes = desired_align - src_align_bytes;
24362       if (src_align_bytes >= 0)
24363         {
24364           unsigned int src_align;
24365           for (src_align = desired_align; src_align >= 2; src_align >>= 1)
24366             {
24367               if ((src_align_bytes & (src_align - 1))
24368                    == (align_bytes & (src_align - 1)))
24369                 break;
24370             }
24371           if (src_align > (unsigned int) desired_align)
24372             src_align = desired_align;
24373           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
24374             set_mem_align (src, src_align * BITS_PER_UNIT);
24375         }
24376       if (MEM_SIZE_KNOWN_P (orig_src))
24377         set_mem_size (src, MEM_SIZE (orig_src) - align_bytes);
24378       *srcp = src;
24379     }
24380
24381   return dst;
24382 }
24383
24384 /* Return true if ALG can be used in current context.  
24385    Assume we expand memset if MEMSET is true.  */
24386 static bool
24387 alg_usable_p (enum stringop_alg alg, bool memset)
24388 {
24389   if (alg == no_stringop)
24390     return false;
24391   if (alg == vector_loop)
24392     return TARGET_SSE || TARGET_AVX;
24393   /* Algorithms using the rep prefix want at least edi and ecx;
24394      additionally, memset wants eax and memcpy wants esi.  Don't
24395      consider such algorithms if the user has appropriated those
24396      registers for their own purposes.  */
24397   if (alg == rep_prefix_1_byte
24398       || alg == rep_prefix_4_byte
24399       || alg == rep_prefix_8_byte)
24400     return !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
24401              || (memset ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
24402   return true;
24403 }
24404
24405 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
24406 static enum stringop_alg
24407 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size,
24408             unsigned HOST_WIDE_INT min_size, unsigned HOST_WIDE_INT max_size,
24409             bool memset, bool zero_memset, int *dynamic_check, bool *noalign)
24410 {
24411   const struct stringop_algs * algs;
24412   bool optimize_for_speed;
24413   int max = 0;
24414   const struct processor_costs *cost;
24415   int i;
24416   bool any_alg_usable_p = false;
24417
24418   *noalign = false;
24419   *dynamic_check = -1;
24420
24421   /* Even if the string operation call is cold, we still might spend a lot
24422      of time processing large blocks.  */
24423   if (optimize_function_for_size_p (cfun)
24424       || (optimize_insn_for_size_p ()
24425           && (max_size < 256
24426               || (expected_size != -1 && expected_size < 256))))
24427     optimize_for_speed = false;
24428   else
24429     optimize_for_speed = true;
24430
24431   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
24432   if (memset)
24433     algs = &cost->memset[TARGET_64BIT != 0];
24434   else
24435     algs = &cost->memcpy[TARGET_64BIT != 0];
24436
24437   /* See maximal size for user defined algorithm.  */
24438   for (i = 0; i < MAX_STRINGOP_ALGS; i++)
24439     {
24440       enum stringop_alg candidate = algs->size[i].alg;
24441       bool usable = alg_usable_p (candidate, memset);
24442       any_alg_usable_p |= usable;
24443
24444       if (candidate != libcall && candidate && usable)
24445           max = algs->size[i].max;
24446     }
24447
24448   /* If expected size is not known but max size is small enough
24449      so inline version is a win, set expected size into
24450      the range.  */
24451   if (((max > 1 && (unsigned HOST_WIDE_INT) max >= max_size) || max == -1)
24452       && expected_size == -1)
24453     expected_size = min_size / 2 + max_size / 2;
24454
24455   /* If user specified the algorithm, honnor it if possible.  */
24456   if (ix86_stringop_alg != no_stringop
24457       && alg_usable_p (ix86_stringop_alg, memset))
24458     return ix86_stringop_alg;
24459   /* rep; movq or rep; movl is the smallest variant.  */
24460   else if (!optimize_for_speed)
24461     {
24462       *noalign = true;
24463       if (!count || (count & 3) || (memset && !zero_memset))
24464         return alg_usable_p (rep_prefix_1_byte, memset)
24465                ? rep_prefix_1_byte : loop_1_byte;
24466       else
24467         return alg_usable_p (rep_prefix_4_byte, memset)
24468                ? rep_prefix_4_byte : loop;
24469     }
24470   /* Very tiny blocks are best handled via the loop, REP is expensive to
24471      setup.  */
24472   else if (expected_size != -1 && expected_size < 4)
24473     return loop_1_byte;
24474   else if (expected_size != -1)
24475     {
24476       enum stringop_alg alg = libcall;
24477       bool alg_noalign = false;
24478       for (i = 0; i < MAX_STRINGOP_ALGS; i++)
24479         {
24480           /* We get here if the algorithms that were not libcall-based
24481              were rep-prefix based and we are unable to use rep prefixes
24482              based on global register usage.  Break out of the loop and
24483              use the heuristic below.  */
24484           if (algs->size[i].max == 0)
24485             break;
24486           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
24487             {
24488               enum stringop_alg candidate = algs->size[i].alg;
24489
24490               if (candidate != libcall && alg_usable_p (candidate, memset))
24491                 {
24492                   alg = candidate;
24493                   alg_noalign = algs->size[i].noalign;
24494                 }
24495               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
24496                  last non-libcall inline algorithm.  */
24497               if (TARGET_INLINE_ALL_STRINGOPS)
24498                 {
24499                   /* When the current size is best to be copied by a libcall,
24500                      but we are still forced to inline, run the heuristic below
24501                      that will pick code for medium sized blocks.  */
24502                   if (alg != libcall)
24503                     {
24504                       *noalign = alg_noalign;
24505                       return alg;
24506                     }
24507                   else if (!any_alg_usable_p)
24508                     break;
24509                 }
24510               else if (alg_usable_p (candidate, memset))
24511                 {
24512                   *noalign = algs->size[i].noalign;
24513                   return candidate;
24514                 }
24515             }
24516         }
24517     }
24518   /* When asked to inline the call anyway, try to pick meaningful choice.
24519      We look for maximal size of block that is faster to copy by hand and
24520      take blocks of at most of that size guessing that average size will
24521      be roughly half of the block.
24522
24523      If this turns out to be bad, we might simply specify the preferred
24524      choice in ix86_costs.  */
24525   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24526       && (algs->unknown_size == libcall
24527           || !alg_usable_p (algs->unknown_size, memset)))
24528     {
24529       enum stringop_alg alg;
24530
24531       /* If there aren't any usable algorithms, then recursing on
24532          smaller sizes isn't going to find anything.  Just return the
24533          simple byte-at-a-time copy loop.  */
24534       if (!any_alg_usable_p)
24535         {
24536           /* Pick something reasonable.  */
24537           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24538             *dynamic_check = 128;
24539           return loop_1_byte;
24540         }
24541       if (max <= 0)
24542         max = 4096;
24543       alg = decide_alg (count, max / 2, min_size, max_size, memset,
24544                         zero_memset, dynamic_check, noalign);
24545       gcc_assert (*dynamic_check == -1);
24546       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24547         *dynamic_check = max;
24548       else
24549         gcc_assert (alg != libcall);
24550       return alg;
24551     }
24552   return (alg_usable_p (algs->unknown_size, memset)
24553           ? algs->unknown_size : libcall);
24554 }
24555
24556 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
24557    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
24558 static int
24559 decide_alignment (int align,
24560                   enum stringop_alg alg,
24561                   int expected_size,
24562                   machine_mode move_mode)
24563 {
24564   int desired_align = 0;
24565
24566   gcc_assert (alg != no_stringop);
24567
24568   if (alg == libcall)
24569     return 0;
24570   if (move_mode == VOIDmode)
24571     return 0;
24572
24573   desired_align = GET_MODE_SIZE (move_mode);
24574   /* PentiumPro has special logic triggering for 8 byte aligned blocks.
24575      copying whole cacheline at once.  */
24576   if (TARGET_PENTIUMPRO
24577       && (alg == rep_prefix_4_byte || alg == rep_prefix_1_byte))
24578     desired_align = 8;
24579
24580   if (optimize_size)
24581     desired_align = 1;
24582   if (desired_align < align)
24583     desired_align = align;
24584   if (expected_size != -1 && expected_size < 4)
24585     desired_align = align;
24586
24587   return desired_align;
24588 }
24589
24590
24591 /* Helper function for memcpy.  For QImode value 0xXY produce
24592    0xXYXYXYXY of wide specified by MODE.  This is essentially
24593    a * 0x10101010, but we can do slightly better than
24594    synth_mult by unwinding the sequence by hand on CPUs with
24595    slow multiply.  */
24596 static rtx
24597 promote_duplicated_reg (machine_mode mode, rtx val)
24598 {
24599   machine_mode valmode = GET_MODE (val);
24600   rtx tmp;
24601   int nops = mode == DImode ? 3 : 2;
24602
24603   gcc_assert (mode == SImode || mode == DImode || val == const0_rtx);
24604   if (val == const0_rtx)
24605     return copy_to_mode_reg (mode, CONST0_RTX (mode));
24606   if (CONST_INT_P (val))
24607     {
24608       HOST_WIDE_INT v = INTVAL (val) & 255;
24609
24610       v |= v << 8;
24611       v |= v << 16;
24612       if (mode == DImode)
24613         v |= (v << 16) << 16;
24614       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
24615     }
24616
24617   if (valmode == VOIDmode)
24618     valmode = QImode;
24619   if (valmode != QImode)
24620     val = gen_lowpart (QImode, val);
24621   if (mode == QImode)
24622     return val;
24623   if (!TARGET_PARTIAL_REG_STALL)
24624     nops--;
24625   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
24626       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
24627       <= (ix86_cost->shift_const + ix86_cost->add) * nops
24628           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
24629     {
24630       rtx reg = convert_modes (mode, QImode, val, true);
24631       tmp = promote_duplicated_reg (mode, const1_rtx);
24632       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
24633                                   OPTAB_DIRECT);
24634     }
24635   else
24636     {
24637       rtx reg = convert_modes (mode, QImode, val, true);
24638
24639       if (!TARGET_PARTIAL_REG_STALL)
24640         if (mode == SImode)
24641           emit_insn (gen_movsi_insv_1 (reg, reg));
24642         else
24643           emit_insn (gen_movdi_insv_1 (reg, reg));
24644       else
24645         {
24646           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
24647                                      NULL, 1, OPTAB_DIRECT);
24648           reg =
24649             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24650         }
24651       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
24652                                  NULL, 1, OPTAB_DIRECT);
24653       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24654       if (mode == SImode)
24655         return reg;
24656       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
24657                                  NULL, 1, OPTAB_DIRECT);
24658       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24659       return reg;
24660     }
24661 }
24662
24663 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
24664    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
24665    alignment from ALIGN to DESIRED_ALIGN.  */
24666 static rtx
24667 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align,
24668                                 int align)
24669 {
24670   rtx promoted_val;
24671
24672   if (TARGET_64BIT
24673       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
24674     promoted_val = promote_duplicated_reg (DImode, val);
24675   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
24676     promoted_val = promote_duplicated_reg (SImode, val);
24677   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
24678     promoted_val = promote_duplicated_reg (HImode, val);
24679   else
24680     promoted_val = val;
24681
24682   return promoted_val;
24683 }
24684
24685 /* Expand string move (memcpy) ot store (memset) operation.  Use i386 string
24686    operations when profitable.  The code depends upon architecture, block size
24687    and alignment, but always has one of the following overall structures:
24688
24689    Aligned move sequence:
24690
24691      1) Prologue guard: Conditional that jumps up to epilogues for small
24692         blocks that can be handled by epilogue alone.  This is faster
24693         but also needed for correctness, since prologue assume the block
24694         is larger than the desired alignment.
24695
24696         Optional dynamic check for size and libcall for large
24697         blocks is emitted here too, with -minline-stringops-dynamically.
24698
24699      2) Prologue: copy first few bytes in order to get destination
24700         aligned to DESIRED_ALIGN.  It is emitted only when ALIGN is less
24701         than DESIRED_ALIGN and up to DESIRED_ALIGN - ALIGN bytes can be
24702         copied.  We emit either a jump tree on power of two sized
24703         blocks, or a byte loop.
24704
24705      3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
24706         with specified algorithm.
24707
24708      4) Epilogue: code copying tail of the block that is too small to be
24709         handled by main body (or up to size guarded by prologue guard). 
24710
24711   Misaligned move sequence
24712
24713      1) missaligned move prologue/epilogue containing:
24714         a) Prologue handling small memory blocks and jumping to done_label
24715            (skipped if blocks are known to be large enough)
24716         b) Signle move copying first DESIRED_ALIGN-ALIGN bytes if alignment is
24717            needed by single possibly misaligned move
24718            (skipped if alignment is not needed)
24719         c) Copy of last SIZE_NEEDED bytes by possibly misaligned moves
24720
24721      2) Zero size guard dispatching to done_label, if needed
24722
24723      3) dispatch to library call, if needed,
24724
24725      3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
24726         with specified algorithm.  */
24727 bool
24728 ix86_expand_set_or_movmem (rtx dst, rtx src, rtx count_exp, rtx val_exp,
24729                            rtx align_exp, rtx expected_align_exp,
24730                            rtx expected_size_exp, rtx min_size_exp,
24731                            rtx max_size_exp, rtx probable_max_size_exp,
24732                            bool issetmem)
24733 {
24734   rtx destreg;
24735   rtx srcreg = NULL;
24736   rtx_code_label *label = NULL;
24737   rtx tmp;
24738   rtx_code_label *jump_around_label = NULL;
24739   HOST_WIDE_INT align = 1;
24740   unsigned HOST_WIDE_INT count = 0;
24741   HOST_WIDE_INT expected_size = -1;
24742   int size_needed = 0, epilogue_size_needed;
24743   int desired_align = 0, align_bytes = 0;
24744   enum stringop_alg alg;
24745   rtx promoted_val = NULL;
24746   rtx vec_promoted_val = NULL;
24747   bool force_loopy_epilogue = false;
24748   int dynamic_check;
24749   bool need_zero_guard = false;
24750   bool noalign;
24751   machine_mode move_mode = VOIDmode;
24752   int unroll_factor = 1;
24753   /* TODO: Once value ranges are available, fill in proper data.  */
24754   unsigned HOST_WIDE_INT min_size = 0;
24755   unsigned HOST_WIDE_INT max_size = -1;
24756   unsigned HOST_WIDE_INT probable_max_size = -1;
24757   bool misaligned_prologue_used = false;
24758
24759   if (CONST_INT_P (align_exp))
24760     align = INTVAL (align_exp);
24761   /* i386 can do misaligned access on reasonably increased cost.  */
24762   if (CONST_INT_P (expected_align_exp)
24763       && INTVAL (expected_align_exp) > align)
24764     align = INTVAL (expected_align_exp);
24765   /* ALIGN is the minimum of destination and source alignment, but we care here
24766      just about destination alignment.  */
24767   else if (!issetmem
24768            && MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
24769     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
24770
24771   if (CONST_INT_P (count_exp))
24772     {
24773       min_size = max_size = probable_max_size = count = expected_size
24774         = INTVAL (count_exp);
24775       /* When COUNT is 0, there is nothing to do.  */
24776       if (!count)
24777         return true;
24778     }
24779   else
24780     {
24781       if (min_size_exp)
24782         min_size = INTVAL (min_size_exp);
24783       if (max_size_exp)
24784         max_size = INTVAL (max_size_exp);
24785       if (probable_max_size_exp)
24786         probable_max_size = INTVAL (probable_max_size_exp);
24787       if (CONST_INT_P (expected_size_exp))
24788         expected_size = INTVAL (expected_size_exp);
24789      }
24790
24791   /* Make sure we don't need to care about overflow later on.  */
24792   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
24793     return false;
24794
24795   /* Step 0: Decide on preferred algorithm, desired alignment and
24796      size of chunks to be copied by main loop.  */
24797   alg = decide_alg (count, expected_size, min_size, probable_max_size,
24798                     issetmem,
24799                     issetmem && val_exp == const0_rtx,
24800                     &dynamic_check, &noalign);
24801   if (alg == libcall)
24802     return false;
24803   gcc_assert (alg != no_stringop);
24804
24805   /* For now vector-version of memset is generated only for memory zeroing, as
24806      creating of promoted vector value is very cheap in this case.  */
24807   if (issetmem && alg == vector_loop && val_exp != const0_rtx)
24808     alg = unrolled_loop;
24809
24810   if (!count)
24811     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
24812   destreg = ix86_copy_addr_to_reg (XEXP (dst, 0));
24813   if (!issetmem)
24814     srcreg = ix86_copy_addr_to_reg (XEXP (src, 0));
24815
24816   unroll_factor = 1;
24817   move_mode = word_mode;
24818   switch (alg)
24819     {
24820     case libcall:
24821     case no_stringop:
24822     case last_alg:
24823       gcc_unreachable ();
24824     case loop_1_byte:
24825       need_zero_guard = true;
24826       move_mode = QImode;
24827       break;
24828     case loop:
24829       need_zero_guard = true;
24830       break;
24831     case unrolled_loop:
24832       need_zero_guard = true;
24833       unroll_factor = (TARGET_64BIT ? 4 : 2);
24834       break;
24835     case vector_loop:
24836       need_zero_guard = true;
24837       unroll_factor = 4;
24838       /* Find the widest supported mode.  */
24839       move_mode = word_mode;
24840       while (optab_handler (mov_optab, GET_MODE_WIDER_MODE (move_mode))
24841              != CODE_FOR_nothing)
24842           move_mode = GET_MODE_WIDER_MODE (move_mode);
24843
24844       /* Find the corresponding vector mode with the same size as MOVE_MODE.
24845          MOVE_MODE is an integer mode at the moment (SI, DI, TI, etc.).  */
24846       if (GET_MODE_SIZE (move_mode) > GET_MODE_SIZE (word_mode))
24847         {
24848           int nunits = GET_MODE_SIZE (move_mode) / GET_MODE_SIZE (word_mode);
24849           move_mode = mode_for_vector (word_mode, nunits);
24850           if (optab_handler (mov_optab, move_mode) == CODE_FOR_nothing)
24851             move_mode = word_mode;
24852         }
24853       gcc_assert (optab_handler (mov_optab, move_mode) != CODE_FOR_nothing);
24854       break;
24855     case rep_prefix_8_byte:
24856       move_mode = DImode;
24857       break;
24858     case rep_prefix_4_byte:
24859       move_mode = SImode;
24860       break;
24861     case rep_prefix_1_byte:
24862       move_mode = QImode;
24863       break;
24864     }
24865   size_needed = GET_MODE_SIZE (move_mode) * unroll_factor;
24866   epilogue_size_needed = size_needed;
24867
24868   desired_align = decide_alignment (align, alg, expected_size, move_mode);
24869   if (!TARGET_ALIGN_STRINGOPS || noalign)
24870     align = desired_align;
24871
24872   /* Step 1: Prologue guard.  */
24873
24874   /* Alignment code needs count to be in register.  */
24875   if (CONST_INT_P (count_exp) && desired_align > align)
24876     {
24877       if (INTVAL (count_exp) > desired_align
24878           && INTVAL (count_exp) > size_needed)
24879         {
24880           align_bytes
24881             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
24882           if (align_bytes <= 0)
24883             align_bytes = 0;
24884           else
24885             align_bytes = desired_align - align_bytes;
24886         }
24887       if (align_bytes == 0)
24888         count_exp = force_reg (counter_mode (count_exp), count_exp);
24889     }
24890   gcc_assert (desired_align >= 1 && align >= 1);
24891
24892   /* Misaligned move sequences handle both prologue and epilogue at once.
24893      Default code generation results in a smaller code for large alignments
24894      and also avoids redundant job when sizes are known precisely.  */
24895   misaligned_prologue_used
24896     = (TARGET_MISALIGNED_MOVE_STRING_PRO_EPILOGUES
24897        && MAX (desired_align, epilogue_size_needed) <= 32
24898        && desired_align <= epilogue_size_needed
24899        && ((desired_align > align && !align_bytes)
24900            || (!count && epilogue_size_needed > 1)));
24901
24902   /* Do the cheap promotion to allow better CSE across the
24903      main loop and epilogue (ie one load of the big constant in the
24904      front of all code.  
24905      For now the misaligned move sequences do not have fast path
24906      without broadcasting.  */
24907   if (issetmem && ((CONST_INT_P (val_exp) || misaligned_prologue_used)))
24908     {
24909       if (alg == vector_loop)
24910         {
24911           gcc_assert (val_exp == const0_rtx);
24912           vec_promoted_val = promote_duplicated_reg (move_mode, val_exp);
24913           promoted_val = promote_duplicated_reg_to_size (val_exp,
24914                                                          GET_MODE_SIZE (word_mode),
24915                                                          desired_align, align);
24916         }
24917       else
24918         {
24919           promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
24920                                                          desired_align, align);
24921         }
24922     }
24923   /* Misaligned move sequences handles both prologues and epilogues at once.
24924      Default code generation results in smaller code for large alignments and
24925      also avoids redundant job when sizes are known precisely.  */
24926   if (misaligned_prologue_used)
24927     {
24928       /* Misaligned move prologue handled small blocks by itself.  */
24929       expand_set_or_movmem_prologue_epilogue_by_misaligned_moves
24930            (dst, src, &destreg, &srcreg,
24931             move_mode, promoted_val, vec_promoted_val,
24932             &count_exp,
24933             &jump_around_label,
24934             desired_align < align
24935             ? MAX (desired_align, epilogue_size_needed) : epilogue_size_needed,
24936             desired_align, align, &min_size, dynamic_check, issetmem);
24937       if (!issetmem)
24938         src = change_address (src, BLKmode, srcreg);
24939       dst = change_address (dst, BLKmode, destreg);
24940       set_mem_align (dst, desired_align * BITS_PER_UNIT);
24941       epilogue_size_needed = 0;
24942       if (need_zero_guard && !min_size)
24943         {
24944           /* It is possible that we copied enough so the main loop will not
24945              execute.  */
24946           gcc_assert (size_needed > 1);
24947           if (jump_around_label == NULL_RTX)
24948             jump_around_label = gen_label_rtx ();
24949           emit_cmp_and_jump_insns (count_exp,
24950                                    GEN_INT (size_needed),
24951                                    LTU, 0, counter_mode (count_exp), 1, jump_around_label);
24952           if (expected_size == -1
24953               || expected_size < (desired_align - align) / 2 + size_needed)
24954             predict_jump (REG_BR_PROB_BASE * 20 / 100);
24955           else
24956             predict_jump (REG_BR_PROB_BASE * 60 / 100);
24957         }
24958     }
24959   /* Ensure that alignment prologue won't copy past end of block.  */
24960   else if (size_needed > 1 || (desired_align > 1 && desired_align > align))
24961     {
24962       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
24963       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
24964          Make sure it is power of 2.  */
24965       epilogue_size_needed = 1 << (floor_log2 (epilogue_size_needed) + 1);
24966
24967       /* To improve performance of small blocks, we jump around the VAL
24968          promoting mode.  This mean that if the promoted VAL is not constant,
24969          we might not use it in the epilogue and have to use byte
24970          loop variant.  */
24971       if (issetmem && epilogue_size_needed > 2 && !promoted_val)
24972         force_loopy_epilogue = true;
24973       if ((count && count < (unsigned HOST_WIDE_INT) epilogue_size_needed)
24974           || max_size < (unsigned HOST_WIDE_INT) epilogue_size_needed)
24975         {
24976           /* If main algorithm works on QImode, no epilogue is needed.
24977              For small sizes just don't align anything.  */
24978           if (size_needed == 1)
24979             desired_align = align;
24980           else
24981             goto epilogue;
24982         }
24983       else if (!count
24984                && min_size < (unsigned HOST_WIDE_INT) epilogue_size_needed)
24985         {
24986           label = gen_label_rtx ();
24987           emit_cmp_and_jump_insns (count_exp,
24988                                    GEN_INT (epilogue_size_needed),
24989                                    LTU, 0, counter_mode (count_exp), 1, label);
24990           if (expected_size == -1 || expected_size < epilogue_size_needed)
24991             predict_jump (REG_BR_PROB_BASE * 60 / 100);
24992           else
24993             predict_jump (REG_BR_PROB_BASE * 20 / 100);
24994         }
24995     }
24996
24997   /* Emit code to decide on runtime whether library call or inline should be
24998      used.  */
24999   if (dynamic_check != -1)
25000     {
25001       if (!issetmem && CONST_INT_P (count_exp))
25002         {
25003           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
25004             {
25005               emit_block_move_via_libcall (dst, src, count_exp, false);
25006               count_exp = const0_rtx;
25007               goto epilogue;
25008             }
25009         }
25010       else
25011         {
25012           rtx_code_label *hot_label = gen_label_rtx ();
25013           if (jump_around_label == NULL_RTX)
25014             jump_around_label = gen_label_rtx ();
25015           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
25016                                    LEU, 0, counter_mode (count_exp),
25017                                    1, hot_label);
25018           predict_jump (REG_BR_PROB_BASE * 90 / 100);
25019           if (issetmem)
25020             set_storage_via_libcall (dst, count_exp, val_exp, false);
25021           else
25022             emit_block_move_via_libcall (dst, src, count_exp, false);
25023           emit_jump (jump_around_label);
25024           emit_label (hot_label);
25025         }
25026     }
25027
25028   /* Step 2: Alignment prologue.  */
25029   /* Do the expensive promotion once we branched off the small blocks.  */
25030   if (issetmem && !promoted_val)
25031     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
25032                                                    desired_align, align);
25033
25034   if (desired_align > align && !misaligned_prologue_used)
25035     {
25036       if (align_bytes == 0)
25037         {
25038           /* Except for the first move in prologue, we no longer know
25039              constant offset in aliasing info.  It don't seems to worth
25040              the pain to maintain it for the first move, so throw away
25041              the info early.  */
25042           dst = change_address (dst, BLKmode, destreg);
25043           if (!issetmem)
25044             src = change_address (src, BLKmode, srcreg);
25045           dst = expand_set_or_movmem_prologue (dst, src, destreg, srcreg,
25046                                             promoted_val, vec_promoted_val,
25047                                             count_exp, align, desired_align,
25048                                             issetmem);
25049           /* At most desired_align - align bytes are copied.  */
25050           if (min_size < (unsigned)(desired_align - align))
25051             min_size = 0;
25052           else
25053             min_size -= desired_align - align;
25054         }
25055       else
25056         {
25057           /* If we know how many bytes need to be stored before dst is
25058              sufficiently aligned, maintain aliasing info accurately.  */
25059           dst = expand_set_or_movmem_constant_prologue (dst, &src, destreg,
25060                                                            srcreg,
25061                                                            promoted_val,
25062                                                            vec_promoted_val,
25063                                                            desired_align,
25064                                                            align_bytes,
25065                                                            issetmem);
25066
25067           count_exp = plus_constant (counter_mode (count_exp),
25068                                      count_exp, -align_bytes);
25069           count -= align_bytes;
25070           min_size -= align_bytes;
25071           max_size -= align_bytes;
25072         }
25073       if (need_zero_guard
25074           && !min_size
25075           && (count < (unsigned HOST_WIDE_INT) size_needed
25076               || (align_bytes == 0
25077                   && count < ((unsigned HOST_WIDE_INT) size_needed
25078                               + desired_align - align))))
25079         {
25080           /* It is possible that we copied enough so the main loop will not
25081              execute.  */
25082           gcc_assert (size_needed > 1);
25083           if (label == NULL_RTX)
25084             label = gen_label_rtx ();
25085           emit_cmp_and_jump_insns (count_exp,
25086                                    GEN_INT (size_needed),
25087                                    LTU, 0, counter_mode (count_exp), 1, label);
25088           if (expected_size == -1
25089               || expected_size < (desired_align - align) / 2 + size_needed)
25090             predict_jump (REG_BR_PROB_BASE * 20 / 100);
25091           else
25092             predict_jump (REG_BR_PROB_BASE * 60 / 100);
25093         }
25094     }
25095   if (label && size_needed == 1)
25096     {
25097       emit_label (label);
25098       LABEL_NUSES (label) = 1;
25099       label = NULL;
25100       epilogue_size_needed = 1;
25101       if (issetmem)
25102         promoted_val = val_exp;
25103     }
25104   else if (label == NULL_RTX && !misaligned_prologue_used)
25105     epilogue_size_needed = size_needed;
25106
25107   /* Step 3: Main loop.  */
25108
25109   switch (alg)
25110     {
25111     case libcall:
25112     case no_stringop:
25113     case last_alg:
25114       gcc_unreachable ();
25115     case loop_1_byte:
25116     case loop:
25117     case unrolled_loop:
25118       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, promoted_val,
25119                                      count_exp, move_mode, unroll_factor,
25120                                      expected_size, issetmem);
25121       break;
25122     case vector_loop:
25123       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg,
25124                                      vec_promoted_val, count_exp, move_mode,
25125                                      unroll_factor, expected_size, issetmem);
25126       break;
25127     case rep_prefix_8_byte:
25128     case rep_prefix_4_byte:
25129     case rep_prefix_1_byte:
25130       expand_set_or_movmem_via_rep (dst, src, destreg, srcreg, promoted_val,
25131                                        val_exp, count_exp, move_mode, issetmem);
25132       break;
25133     }
25134   /* Adjust properly the offset of src and dest memory for aliasing.  */
25135   if (CONST_INT_P (count_exp))
25136     {
25137       if (!issetmem)
25138         src = adjust_automodify_address_nv (src, BLKmode, srcreg,
25139                                             (count / size_needed) * size_needed);
25140       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
25141                                           (count / size_needed) * size_needed);
25142     }
25143   else
25144     {
25145       if (!issetmem)
25146         src = change_address (src, BLKmode, srcreg);
25147       dst = change_address (dst, BLKmode, destreg);
25148     }
25149
25150   /* Step 4: Epilogue to copy the remaining bytes.  */
25151  epilogue:
25152   if (label)
25153     {
25154       /* When the main loop is done, COUNT_EXP might hold original count,
25155          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
25156          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
25157          bytes. Compensate if needed.  */
25158
25159       if (size_needed < epilogue_size_needed)
25160         {
25161           tmp =
25162             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
25163                                  GEN_INT (size_needed - 1), count_exp, 1,
25164                                  OPTAB_DIRECT);
25165           if (tmp != count_exp)
25166             emit_move_insn (count_exp, tmp);
25167         }
25168       emit_label (label);
25169       LABEL_NUSES (label) = 1;
25170     }
25171
25172   if (count_exp != const0_rtx && epilogue_size_needed > 1)
25173     {
25174       if (force_loopy_epilogue)
25175         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
25176                                          epilogue_size_needed);
25177       else
25178         {
25179           if (issetmem)
25180             expand_setmem_epilogue (dst, destreg, promoted_val,
25181                                     vec_promoted_val, count_exp,
25182                                     epilogue_size_needed);
25183           else
25184             expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
25185                                     epilogue_size_needed);
25186         }
25187     }
25188   if (jump_around_label)
25189     emit_label (jump_around_label);
25190   return true;
25191 }
25192
25193
25194 /* Expand the appropriate insns for doing strlen if not just doing
25195    repnz; scasb
25196
25197    out = result, initialized with the start address
25198    align_rtx = alignment of the address.
25199    scratch = scratch register, initialized with the startaddress when
25200         not aligned, otherwise undefined
25201
25202    This is just the body. It needs the initializations mentioned above and
25203    some address computing at the end.  These things are done in i386.md.  */
25204
25205 static void
25206 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
25207 {
25208   int align;
25209   rtx tmp;
25210   rtx_code_label *align_2_label = NULL;
25211   rtx_code_label *align_3_label = NULL;
25212   rtx_code_label *align_4_label = gen_label_rtx ();
25213   rtx_code_label *end_0_label = gen_label_rtx ();
25214   rtx mem;
25215   rtx tmpreg = gen_reg_rtx (SImode);
25216   rtx scratch = gen_reg_rtx (SImode);
25217   rtx cmp;
25218
25219   align = 0;
25220   if (CONST_INT_P (align_rtx))
25221     align = INTVAL (align_rtx);
25222
25223   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
25224
25225   /* Is there a known alignment and is it less than 4?  */
25226   if (align < 4)
25227     {
25228       rtx scratch1 = gen_reg_rtx (Pmode);
25229       emit_move_insn (scratch1, out);
25230       /* Is there a known alignment and is it not 2? */
25231       if (align != 2)
25232         {
25233           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
25234           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
25235
25236           /* Leave just the 3 lower bits.  */
25237           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
25238                                     NULL_RTX, 0, OPTAB_WIDEN);
25239
25240           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
25241                                    Pmode, 1, align_4_label);
25242           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
25243                                    Pmode, 1, align_2_label);
25244           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
25245                                    Pmode, 1, align_3_label);
25246         }
25247       else
25248         {
25249           /* Since the alignment is 2, we have to check 2 or 0 bytes;
25250              check if is aligned to 4 - byte.  */
25251
25252           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
25253                                     NULL_RTX, 0, OPTAB_WIDEN);
25254
25255           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
25256                                    Pmode, 1, align_4_label);
25257         }
25258
25259       mem = change_address (src, QImode, out);
25260
25261       /* Now compare the bytes.  */
25262
25263       /* Compare the first n unaligned byte on a byte per byte basis.  */
25264       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
25265                                QImode, 1, end_0_label);
25266
25267       /* Increment the address.  */
25268       emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25269
25270       /* Not needed with an alignment of 2 */
25271       if (align != 2)
25272         {
25273           emit_label (align_2_label);
25274
25275           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
25276                                    end_0_label);
25277
25278           emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25279
25280           emit_label (align_3_label);
25281         }
25282
25283       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
25284                                end_0_label);
25285
25286       emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25287     }
25288
25289   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
25290      align this loop.  It gives only huge programs, but does not help to
25291      speed up.  */
25292   emit_label (align_4_label);
25293
25294   mem = change_address (src, SImode, out);
25295   emit_move_insn (scratch, mem);
25296   emit_insn (ix86_gen_add3 (out, out, GEN_INT (4)));
25297
25298   /* This formula yields a nonzero result iff one of the bytes is zero.
25299      This saves three branches inside loop and many cycles.  */
25300
25301   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
25302   emit_insn (gen_one_cmplsi2 (scratch, scratch));
25303   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
25304   emit_insn (gen_andsi3 (tmpreg, tmpreg,
25305                          gen_int_mode (0x80808080, SImode)));
25306   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
25307                            align_4_label);
25308
25309   if (TARGET_CMOVE)
25310     {
25311        rtx reg = gen_reg_rtx (SImode);
25312        rtx reg2 = gen_reg_rtx (Pmode);
25313        emit_move_insn (reg, tmpreg);
25314        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
25315
25316        /* If zero is not in the first two bytes, move two bytes forward.  */
25317        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
25318        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25319        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
25320        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
25321                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
25322                                                      reg,
25323                                                      tmpreg)));
25324        /* Emit lea manually to avoid clobbering of flags.  */
25325        emit_insn (gen_rtx_SET (SImode, reg2,
25326                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
25327
25328        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25329        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
25330        emit_insn (gen_rtx_SET (VOIDmode, out,
25331                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
25332                                                      reg2,
25333                                                      out)));
25334     }
25335   else
25336     {
25337        rtx_code_label *end_2_label = gen_label_rtx ();
25338        /* Is zero in the first two bytes? */
25339
25340        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
25341        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25342        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
25343        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
25344                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
25345                             pc_rtx);
25346        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
25347        JUMP_LABEL (tmp) = end_2_label;
25348
25349        /* Not in the first two.  Move two bytes forward.  */
25350        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
25351        emit_insn (ix86_gen_add3 (out, out, const2_rtx));
25352
25353        emit_label (end_2_label);
25354
25355     }
25356
25357   /* Avoid branch in fixing the byte.  */
25358   tmpreg = gen_lowpart (QImode, tmpreg);
25359   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
25360   tmp = gen_rtx_REG (CCmode, FLAGS_REG);
25361   cmp = gen_rtx_LTU (VOIDmode, tmp, const0_rtx);
25362   emit_insn (ix86_gen_sub3_carry (out, out, GEN_INT (3), tmp, cmp));
25363
25364   emit_label (end_0_label);
25365 }
25366
25367 /* Expand strlen.  */
25368
25369 bool
25370 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
25371 {
25372   rtx addr, scratch1, scratch2, scratch3, scratch4;
25373
25374   /* The generic case of strlen expander is long.  Avoid it's
25375      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
25376
25377   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
25378       && !TARGET_INLINE_ALL_STRINGOPS
25379       && !optimize_insn_for_size_p ()
25380       && (!CONST_INT_P (align) || INTVAL (align) < 4))
25381     return false;
25382
25383   addr = force_reg (Pmode, XEXP (src, 0));
25384   scratch1 = gen_reg_rtx (Pmode);
25385
25386   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
25387       && !optimize_insn_for_size_p ())
25388     {
25389       /* Well it seems that some optimizer does not combine a call like
25390          foo(strlen(bar), strlen(bar));
25391          when the move and the subtraction is done here.  It does calculate
25392          the length just once when these instructions are done inside of
25393          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
25394          often used and I use one fewer register for the lifetime of
25395          output_strlen_unroll() this is better.  */
25396
25397       emit_move_insn (out, addr);
25398
25399       ix86_expand_strlensi_unroll_1 (out, src, align);
25400
25401       /* strlensi_unroll_1 returns the address of the zero at the end of
25402          the string, like memchr(), so compute the length by subtracting
25403          the start address.  */
25404       emit_insn (ix86_gen_sub3 (out, out, addr));
25405     }
25406   else
25407     {
25408       rtx unspec;
25409
25410       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
25411       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
25412         return false;
25413
25414       scratch2 = gen_reg_rtx (Pmode);
25415       scratch3 = gen_reg_rtx (Pmode);
25416       scratch4 = force_reg (Pmode, constm1_rtx);
25417
25418       emit_move_insn (scratch3, addr);
25419       eoschar = force_reg (QImode, eoschar);
25420
25421       src = replace_equiv_address_nv (src, scratch3);
25422
25423       /* If .md starts supporting :P, this can be done in .md.  */
25424       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
25425                                                  scratch4), UNSPEC_SCAS);
25426       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
25427       emit_insn (ix86_gen_one_cmpl2 (scratch2, scratch1));
25428       emit_insn (ix86_gen_add3 (out, scratch2, constm1_rtx));
25429     }
25430   return true;
25431 }
25432
25433 /* For given symbol (function) construct code to compute address of it's PLT
25434    entry in large x86-64 PIC model.  */
25435 static rtx
25436 construct_plt_address (rtx symbol)
25437 {
25438   rtx tmp, unspec;
25439
25440   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
25441   gcc_assert (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF);
25442   gcc_assert (Pmode == DImode);
25443
25444   tmp = gen_reg_rtx (Pmode);
25445   unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
25446
25447   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
25448   emit_insn (ix86_gen_add3 (tmp, tmp, pic_offset_table_rtx));
25449   return tmp;
25450 }
25451
25452 rtx
25453 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
25454                   rtx callarg2,
25455                   rtx pop, bool sibcall)
25456 {
25457   rtx vec[3];
25458   rtx use = NULL, call;
25459   unsigned int vec_len = 0;
25460
25461   if (pop == const0_rtx)
25462     pop = NULL;
25463   gcc_assert (!TARGET_64BIT || !pop);
25464
25465   if (TARGET_MACHO && !TARGET_64BIT)
25466     {
25467 #if TARGET_MACHO
25468       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
25469         fnaddr = machopic_indirect_call_target (fnaddr);
25470 #endif
25471     }
25472   else
25473     {
25474       /* Static functions and indirect calls don't need the pic register.  */
25475       if (flag_pic
25476           && (!TARGET_64BIT
25477               || (ix86_cmodel == CM_LARGE_PIC
25478                   && DEFAULT_ABI != MS_ABI))
25479           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
25480           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
25481         {
25482           use_reg (&use, gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM));
25483           if (ix86_use_pseudo_pic_reg ())
25484             emit_move_insn (gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM),
25485                             pic_offset_table_rtx);
25486         }
25487     }
25488
25489   /* Skip setting up RAX register for -mskip-rax-setup when there are no
25490      parameters passed in vector registers.  */
25491   if (TARGET_64BIT
25492       && (INTVAL (callarg2) > 0
25493           || (INTVAL (callarg2) == 0
25494               && (TARGET_SSE || !flag_skip_rax_setup))))
25495     {
25496       rtx al = gen_rtx_REG (QImode, AX_REG);
25497       emit_move_insn (al, callarg2);
25498       use_reg (&use, al);
25499     }
25500
25501   if (ix86_cmodel == CM_LARGE_PIC
25502       && !TARGET_PECOFF
25503       && MEM_P (fnaddr)
25504       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
25505       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
25506     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
25507   else if (sibcall
25508            ? !sibcall_insn_operand (XEXP (fnaddr, 0), word_mode)
25509            : !call_insn_operand (XEXP (fnaddr, 0), word_mode))
25510     {
25511       fnaddr = convert_to_mode (word_mode, XEXP (fnaddr, 0), 1);
25512       fnaddr = gen_rtx_MEM (QImode, copy_to_mode_reg (word_mode, fnaddr));
25513     }
25514
25515   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
25516
25517   if (retval)
25518     {
25519       /* We should add bounds as destination register in case
25520          pointer with bounds may be returned.  */
25521       if (TARGET_MPX && SCALAR_INT_MODE_P (GET_MODE (retval)))
25522         {
25523           rtx b0 = gen_rtx_REG (BND64mode, FIRST_BND_REG);
25524           rtx b1 = gen_rtx_REG (BND64mode, FIRST_BND_REG + 1);
25525           retval = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (3, retval, b0, b1));
25526           chkp_put_regs_to_expr_list (retval);
25527         }
25528
25529       call = gen_rtx_SET (VOIDmode, retval, call);
25530     }
25531   vec[vec_len++] = call;
25532
25533   if (pop)
25534     {
25535       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
25536       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
25537       vec[vec_len++] = pop;
25538     }
25539
25540   if (TARGET_64BIT_MS_ABI
25541       && (!callarg2 || INTVAL (callarg2) != -2))
25542     {
25543       int const cregs_size
25544         = ARRAY_SIZE (x86_64_ms_sysv_extra_clobbered_registers);
25545       int i;
25546
25547       for (i = 0; i < cregs_size; i++)
25548         {
25549           int regno = x86_64_ms_sysv_extra_clobbered_registers[i];
25550           machine_mode mode = SSE_REGNO_P (regno) ? TImode : DImode;
25551
25552           clobber_reg (&use, gen_rtx_REG (mode, regno));
25553         }
25554     }
25555
25556   if (vec_len > 1)
25557     call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (vec_len, vec));
25558   call = emit_call_insn (call);
25559   if (use)
25560     CALL_INSN_FUNCTION_USAGE (call) = use;
25561
25562   return call;
25563 }
25564
25565 /* Output the assembly for a call instruction.  */
25566
25567 const char *
25568 ix86_output_call_insn (rtx_insn *insn, rtx call_op)
25569 {
25570   bool direct_p = constant_call_address_operand (call_op, VOIDmode);
25571   bool seh_nop_p = false;
25572   const char *xasm;
25573
25574   if (SIBLING_CALL_P (insn))
25575     {
25576       if (direct_p)
25577         xasm = "%!jmp\t%P0";
25578       /* SEH epilogue detection requires the indirect branch case
25579          to include REX.W.  */
25580       else if (TARGET_SEH)
25581         xasm = "%!rex.W jmp %A0";
25582       else
25583         xasm = "%!jmp\t%A0";
25584
25585       output_asm_insn (xasm, &call_op);
25586       return "";
25587     }
25588
25589   /* SEH unwinding can require an extra nop to be emitted in several
25590      circumstances.  Determine if we have one of those.  */
25591   if (TARGET_SEH)
25592     {
25593       rtx_insn *i;
25594
25595       for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
25596         {
25597           /* If we get to another real insn, we don't need the nop.  */
25598           if (INSN_P (i))
25599             break;
25600
25601           /* If we get to the epilogue note, prevent a catch region from
25602              being adjacent to the standard epilogue sequence.  If non-
25603              call-exceptions, we'll have done this during epilogue emission. */
25604           if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG
25605               && !flag_non_call_exceptions
25606               && !can_throw_internal (insn))
25607             {
25608               seh_nop_p = true;
25609               break;
25610             }
25611         }
25612
25613       /* If we didn't find a real insn following the call, prevent the
25614          unwinder from looking into the next function.  */
25615       if (i == NULL)
25616         seh_nop_p = true;
25617     }
25618
25619   if (direct_p)
25620     xasm = "%!call\t%P0";
25621   else
25622     xasm = "%!call\t%A0";
25623
25624   output_asm_insn (xasm, &call_op);
25625
25626   if (seh_nop_p)
25627     return "nop";
25628
25629   return "";
25630 }
25631 \f
25632 /* Clear stack slot assignments remembered from previous functions.
25633    This is called from INIT_EXPANDERS once before RTL is emitted for each
25634    function.  */
25635
25636 static struct machine_function *
25637 ix86_init_machine_status (void)
25638 {
25639   struct machine_function *f;
25640
25641   f = ggc_cleared_alloc<machine_function> ();
25642   f->use_fast_prologue_epilogue_nregs = -1;
25643   f->call_abi = ix86_abi;
25644
25645   return f;
25646 }
25647
25648 /* Return a MEM corresponding to a stack slot with mode MODE.
25649    Allocate a new slot if necessary.
25650
25651    The RTL for a function can have several slots available: N is
25652    which slot to use.  */
25653
25654 rtx
25655 assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n)
25656 {
25657   struct stack_local_entry *s;
25658
25659   gcc_assert (n < MAX_386_STACK_LOCALS);
25660
25661   for (s = ix86_stack_locals; s; s = s->next)
25662     if (s->mode == mode && s->n == n)
25663       return validize_mem (copy_rtx (s->rtl));
25664
25665   s = ggc_alloc<stack_local_entry> ();
25666   s->n = n;
25667   s->mode = mode;
25668   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
25669
25670   s->next = ix86_stack_locals;
25671   ix86_stack_locals = s;
25672   return validize_mem (copy_rtx (s->rtl));
25673 }
25674
25675 static void
25676 ix86_instantiate_decls (void)
25677 {
25678   struct stack_local_entry *s;
25679
25680   for (s = ix86_stack_locals; s; s = s->next)
25681     if (s->rtl != NULL_RTX)
25682       instantiate_decl_rtl (s->rtl);
25683 }
25684 \f
25685 /* Check whether x86 address PARTS is a pc-relative address.  */
25686
25687 static bool
25688 rip_relative_addr_p (struct ix86_address *parts)
25689 {
25690   rtx base, index, disp;
25691
25692   base = parts->base;
25693   index = parts->index;
25694   disp = parts->disp;
25695
25696   if (disp && !base && !index)
25697     {
25698       if (TARGET_64BIT)
25699         {
25700           rtx symbol = disp;
25701
25702           if (GET_CODE (disp) == CONST)
25703             symbol = XEXP (disp, 0);
25704           if (GET_CODE (symbol) == PLUS
25705               && CONST_INT_P (XEXP (symbol, 1)))
25706             symbol = XEXP (symbol, 0);
25707
25708           if (GET_CODE (symbol) == LABEL_REF
25709               || (GET_CODE (symbol) == SYMBOL_REF
25710                   && SYMBOL_REF_TLS_MODEL (symbol) == 0)
25711               || (GET_CODE (symbol) == UNSPEC
25712                   && (XINT (symbol, 1) == UNSPEC_GOTPCREL
25713                       || XINT (symbol, 1) == UNSPEC_PCREL
25714                       || XINT (symbol, 1) == UNSPEC_GOTNTPOFF)))
25715             return true;
25716         }
25717     }
25718   return false;
25719 }
25720
25721 /* Calculate the length of the memory address in the instruction encoding.
25722    Includes addr32 prefix, does not include the one-byte modrm, opcode,
25723    or other prefixes.  We never generate addr32 prefix for LEA insn.  */
25724
25725 int
25726 memory_address_length (rtx addr, bool lea)
25727 {
25728   struct ix86_address parts;
25729   rtx base, index, disp;
25730   int len;
25731   int ok;
25732
25733   if (GET_CODE (addr) == PRE_DEC
25734       || GET_CODE (addr) == POST_INC
25735       || GET_CODE (addr) == PRE_MODIFY
25736       || GET_CODE (addr) == POST_MODIFY)
25737     return 0;
25738
25739   ok = ix86_decompose_address (addr, &parts);
25740   gcc_assert (ok);
25741
25742   len = (parts.seg == SEG_DEFAULT) ? 0 : 1;
25743
25744   /*  If this is not LEA instruction, add the length of addr32 prefix.  */
25745   if (TARGET_64BIT && !lea
25746       && (SImode_address_operand (addr, VOIDmode)
25747           || (parts.base && GET_MODE (parts.base) == SImode)
25748           || (parts.index && GET_MODE (parts.index) == SImode)))
25749     len++;
25750
25751   base = parts.base;
25752   index = parts.index;
25753   disp = parts.disp;
25754
25755   if (base && GET_CODE (base) == SUBREG)
25756     base = SUBREG_REG (base);
25757   if (index && GET_CODE (index) == SUBREG)
25758     index = SUBREG_REG (index);
25759
25760   gcc_assert (base == NULL_RTX || REG_P (base));
25761   gcc_assert (index == NULL_RTX || REG_P (index));
25762
25763   /* Rule of thumb:
25764        - esp as the base always wants an index,
25765        - ebp as the base always wants a displacement,
25766        - r12 as the base always wants an index,
25767        - r13 as the base always wants a displacement.  */
25768
25769   /* Register Indirect.  */
25770   if (base && !index && !disp)
25771     {
25772       /* esp (for its index) and ebp (for its displacement) need
25773          the two-byte modrm form.  Similarly for r12 and r13 in 64-bit
25774          code.  */
25775       if (base == arg_pointer_rtx
25776           || base == frame_pointer_rtx
25777           || REGNO (base) == SP_REG
25778           || REGNO (base) == BP_REG
25779           || REGNO (base) == R12_REG
25780           || REGNO (base) == R13_REG)
25781         len++;
25782     }
25783
25784   /* Direct Addressing.  In 64-bit mode mod 00 r/m 5
25785      is not disp32, but disp32(%rip), so for disp32
25786      SIB byte is needed, unless print_operand_address
25787      optimizes it into disp32(%rip) or (%rip) is implied
25788      by UNSPEC.  */
25789   else if (disp && !base && !index)
25790     {
25791       len += 4;
25792       if (rip_relative_addr_p (&parts))
25793         len++;
25794     }
25795   else
25796     {
25797       /* Find the length of the displacement constant.  */
25798       if (disp)
25799         {
25800           if (base && satisfies_constraint_K (disp))
25801             len += 1;
25802           else
25803             len += 4;
25804         }
25805       /* ebp always wants a displacement.  Similarly r13.  */
25806       else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
25807         len++;
25808
25809       /* An index requires the two-byte modrm form....  */
25810       if (index
25811           /* ...like esp (or r12), which always wants an index.  */
25812           || base == arg_pointer_rtx
25813           || base == frame_pointer_rtx
25814           || (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
25815         len++;
25816     }
25817
25818   return len;
25819 }
25820
25821 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
25822    is set, expect that insn have 8bit immediate alternative.  */
25823 int
25824 ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform)
25825 {
25826   int len = 0;
25827   int i;
25828   extract_insn_cached (insn);
25829   for (i = recog_data.n_operands - 1; i >= 0; --i)
25830     if (CONSTANT_P (recog_data.operand[i]))
25831       {
25832         enum attr_mode mode = get_attr_mode (insn);
25833
25834         gcc_assert (!len);
25835         if (shortform && CONST_INT_P (recog_data.operand[i]))
25836           {
25837             HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
25838             switch (mode)
25839               {
25840               case MODE_QI:
25841                 len = 1;
25842                 continue;
25843               case MODE_HI:
25844                 ival = trunc_int_for_mode (ival, HImode);
25845                 break;
25846               case MODE_SI:
25847                 ival = trunc_int_for_mode (ival, SImode);
25848                 break;
25849               default:
25850                 break;
25851               }
25852             if (IN_RANGE (ival, -128, 127))
25853               {
25854                 len = 1;
25855                 continue;
25856               }
25857           }
25858         switch (mode)
25859           {
25860           case MODE_QI:
25861             len = 1;
25862             break;
25863           case MODE_HI:
25864             len = 2;
25865             break;
25866           case MODE_SI:
25867             len = 4;
25868             break;
25869           /* Immediates for DImode instructions are encoded
25870              as 32bit sign extended values.  */
25871           case MODE_DI:
25872             len = 4;
25873             break;
25874           default:
25875             fatal_insn ("unknown insn mode", insn);
25876         }
25877       }
25878   return len;
25879 }
25880
25881 /* Compute default value for "length_address" attribute.  */
25882 int
25883 ix86_attr_length_address_default (rtx_insn *insn)
25884 {
25885   int i;
25886
25887   if (get_attr_type (insn) == TYPE_LEA)
25888     {
25889       rtx set = PATTERN (insn), addr;
25890
25891       if (GET_CODE (set) == PARALLEL)
25892         set = XVECEXP (set, 0, 0);
25893
25894       gcc_assert (GET_CODE (set) == SET);
25895
25896       addr = SET_SRC (set);
25897
25898       return memory_address_length (addr, true);
25899     }
25900
25901   extract_insn_cached (insn);
25902   for (i = recog_data.n_operands - 1; i >= 0; --i)
25903     if (MEM_P (recog_data.operand[i]))
25904       {
25905         constrain_operands_cached (insn, reload_completed);
25906         if (which_alternative != -1)
25907           {
25908             const char *constraints = recog_data.constraints[i];
25909             int alt = which_alternative;
25910
25911             while (*constraints == '=' || *constraints == '+')
25912               constraints++;
25913             while (alt-- > 0)
25914               while (*constraints++ != ',')
25915                 ;
25916             /* Skip ignored operands.  */
25917             if (*constraints == 'X')
25918               continue;
25919           }
25920         return memory_address_length (XEXP (recog_data.operand[i], 0), false);
25921       }
25922   return 0;
25923 }
25924
25925 /* Compute default value for "length_vex" attribute. It includes
25926    2 or 3 byte VEX prefix and 1 opcode byte.  */
25927
25928 int
25929 ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode,
25930                               bool has_vex_w)
25931 {
25932   int i;
25933
25934   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
25935      byte VEX prefix.  */
25936   if (!has_0f_opcode || has_vex_w)
25937     return 3 + 1;
25938
25939  /* We can always use 2 byte VEX prefix in 32bit.  */
25940   if (!TARGET_64BIT)
25941     return 2 + 1;
25942
25943   extract_insn_cached (insn);
25944
25945   for (i = recog_data.n_operands - 1; i >= 0; --i)
25946     if (REG_P (recog_data.operand[i]))
25947       {
25948         /* REX.W bit uses 3 byte VEX prefix.  */
25949         if (GET_MODE (recog_data.operand[i]) == DImode
25950             && GENERAL_REG_P (recog_data.operand[i]))
25951           return 3 + 1;
25952       }
25953     else
25954       {
25955         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
25956         if (MEM_P (recog_data.operand[i])
25957             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
25958           return 3 + 1;
25959       }
25960
25961   return 2 + 1;
25962 }
25963 \f
25964 /* Return the maximum number of instructions a cpu can issue.  */
25965
25966 static int
25967 ix86_issue_rate (void)
25968 {
25969   switch (ix86_tune)
25970     {
25971     case PROCESSOR_PENTIUM:
25972     case PROCESSOR_BONNELL:
25973     case PROCESSOR_SILVERMONT:
25974     case PROCESSOR_KNL:
25975     case PROCESSOR_INTEL:
25976     case PROCESSOR_K6:
25977     case PROCESSOR_BTVER2:
25978     case PROCESSOR_PENTIUM4:
25979     case PROCESSOR_NOCONA:
25980       return 2;
25981
25982     case PROCESSOR_PENTIUMPRO:
25983     case PROCESSOR_ATHLON:
25984     case PROCESSOR_K8:
25985     case PROCESSOR_AMDFAM10:
25986     case PROCESSOR_GENERIC:
25987     case PROCESSOR_BTVER1:
25988       return 3;
25989
25990     case PROCESSOR_BDVER1:
25991     case PROCESSOR_BDVER2:
25992     case PROCESSOR_BDVER3:
25993     case PROCESSOR_BDVER4:
25994     case PROCESSOR_CORE2:
25995     case PROCESSOR_NEHALEM:
25996     case PROCESSOR_SANDYBRIDGE:
25997     case PROCESSOR_HASWELL:
25998       return 4;
25999
26000     default:
26001       return 1;
26002     }
26003 }
26004
26005 /* A subroutine of ix86_adjust_cost -- return TRUE iff INSN reads flags set
26006    by DEP_INSN and nothing set by DEP_INSN.  */
26007
26008 static bool
26009 ix86_flags_dependent (rtx_insn *insn, rtx_insn *dep_insn, enum attr_type insn_type)
26010 {
26011   rtx set, set2;
26012
26013   /* Simplify the test for uninteresting insns.  */
26014   if (insn_type != TYPE_SETCC
26015       && insn_type != TYPE_ICMOV
26016       && insn_type != TYPE_FCMOV
26017       && insn_type != TYPE_IBR)
26018     return false;
26019
26020   if ((set = single_set (dep_insn)) != 0)
26021     {
26022       set = SET_DEST (set);
26023       set2 = NULL_RTX;
26024     }
26025   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
26026            && XVECLEN (PATTERN (dep_insn), 0) == 2
26027            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
26028            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
26029     {
26030       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
26031       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
26032     }
26033   else
26034     return false;
26035
26036   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
26037     return false;
26038
26039   /* This test is true if the dependent insn reads the flags but
26040      not any other potentially set register.  */
26041   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
26042     return false;
26043
26044   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
26045     return false;
26046
26047   return true;
26048 }
26049
26050 /* Return true iff USE_INSN has a memory address with operands set by
26051    SET_INSN.  */
26052
26053 bool
26054 ix86_agi_dependent (rtx_insn *set_insn, rtx_insn *use_insn)
26055 {
26056   int i;
26057   extract_insn_cached (use_insn);
26058   for (i = recog_data.n_operands - 1; i >= 0; --i)
26059     if (MEM_P (recog_data.operand[i]))
26060       {
26061         rtx addr = XEXP (recog_data.operand[i], 0);
26062         return modified_in_p (addr, set_insn) != 0;
26063       }
26064   return false;
26065 }
26066
26067 /* Helper function for exact_store_load_dependency.
26068    Return true if addr is found in insn.  */
26069 static bool
26070 exact_dependency_1 (rtx addr, rtx insn)
26071 {
26072   enum rtx_code code;
26073   const char *format_ptr;
26074   int i, j;
26075
26076   code = GET_CODE (insn);
26077   switch (code)
26078     {
26079     case MEM:
26080       if (rtx_equal_p (addr, insn))
26081         return true;
26082       break;
26083     case REG:
26084     CASE_CONST_ANY:
26085     case SYMBOL_REF:
26086     case CODE_LABEL:
26087     case PC:
26088     case CC0:
26089     case EXPR_LIST:
26090       return false;
26091     default:
26092       break;
26093     }
26094
26095   format_ptr = GET_RTX_FORMAT (code);
26096   for (i = 0; i < GET_RTX_LENGTH (code); i++)
26097     {
26098       switch (*format_ptr++)
26099         {
26100         case 'e':
26101           if (exact_dependency_1 (addr, XEXP (insn, i)))
26102             return true;
26103           break;
26104         case 'E':
26105           for (j = 0; j < XVECLEN (insn, i); j++)
26106             if (exact_dependency_1 (addr, XVECEXP (insn, i, j)))
26107               return true;
26108             break;
26109         }
26110     }
26111   return false;
26112 }
26113
26114 /* Return true if there exists exact dependency for store & load, i.e.
26115    the same memory address is used in them.  */
26116 static bool
26117 exact_store_load_dependency (rtx_insn *store, rtx_insn *load)
26118 {
26119   rtx set1, set2;
26120
26121   set1 = single_set (store);
26122   if (!set1)
26123     return false;
26124   if (!MEM_P (SET_DEST (set1)))
26125     return false;
26126   set2 = single_set (load);
26127   if (!set2)
26128     return false;
26129   if (exact_dependency_1 (SET_DEST (set1), SET_SRC (set2)))
26130     return true;
26131   return false;
26132 }
26133
26134 static int
26135 ix86_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
26136 {
26137   enum attr_type insn_type, dep_insn_type;
26138   enum attr_memory memory;
26139   rtx set, set2;
26140   int dep_insn_code_number;
26141
26142   /* Anti and output dependencies have zero cost on all CPUs.  */
26143   if (REG_NOTE_KIND (link) != 0)
26144     return 0;
26145
26146   dep_insn_code_number = recog_memoized (dep_insn);
26147
26148   /* If we can't recognize the insns, we can't really do anything.  */
26149   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
26150     return cost;
26151
26152   insn_type = get_attr_type (insn);
26153   dep_insn_type = get_attr_type (dep_insn);
26154
26155   switch (ix86_tune)
26156     {
26157     case PROCESSOR_PENTIUM:
26158       /* Address Generation Interlock adds a cycle of latency.  */
26159       if (insn_type == TYPE_LEA)
26160         {
26161           rtx addr = PATTERN (insn);
26162
26163           if (GET_CODE (addr) == PARALLEL)
26164             addr = XVECEXP (addr, 0, 0);
26165
26166           gcc_assert (GET_CODE (addr) == SET);
26167
26168           addr = SET_SRC (addr);
26169           if (modified_in_p (addr, dep_insn))
26170             cost += 1;
26171         }
26172       else if (ix86_agi_dependent (dep_insn, insn))
26173         cost += 1;
26174
26175       /* ??? Compares pair with jump/setcc.  */
26176       if (ix86_flags_dependent (insn, dep_insn, insn_type))
26177         cost = 0;
26178
26179       /* Floating point stores require value to be ready one cycle earlier.  */
26180       if (insn_type == TYPE_FMOV
26181           && get_attr_memory (insn) == MEMORY_STORE
26182           && !ix86_agi_dependent (dep_insn, insn))
26183         cost += 1;
26184       break;
26185
26186     case PROCESSOR_PENTIUMPRO:
26187       /* INT->FP conversion is expensive.  */
26188       if (get_attr_fp_int_src (dep_insn))
26189         cost += 5;
26190
26191       /* There is one cycle extra latency between an FP op and a store.  */
26192       if (insn_type == TYPE_FMOV
26193           && (set = single_set (dep_insn)) != NULL_RTX
26194           && (set2 = single_set (insn)) != NULL_RTX
26195           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
26196           && MEM_P (SET_DEST (set2)))
26197         cost += 1;
26198
26199       memory = get_attr_memory (insn);
26200
26201       /* Show ability of reorder buffer to hide latency of load by executing
26202          in parallel with previous instruction in case
26203          previous instruction is not needed to compute the address.  */
26204       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26205           && !ix86_agi_dependent (dep_insn, insn))
26206         {
26207           /* Claim moves to take one cycle, as core can issue one load
26208              at time and the next load can start cycle later.  */
26209           if (dep_insn_type == TYPE_IMOV
26210               || dep_insn_type == TYPE_FMOV)
26211             cost = 1;
26212           else if (cost > 1)
26213             cost--;
26214         }
26215       break;
26216
26217     case PROCESSOR_K6:
26218      /* The esp dependency is resolved before
26219         the instruction is really finished.  */
26220       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26221           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26222         return 1;
26223
26224       /* INT->FP conversion is expensive.  */
26225       if (get_attr_fp_int_src (dep_insn))
26226         cost += 5;
26227
26228       memory = get_attr_memory (insn);
26229
26230       /* Show ability of reorder buffer to hide latency of load by executing
26231          in parallel with previous instruction in case
26232          previous instruction is not needed to compute the address.  */
26233       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26234           && !ix86_agi_dependent (dep_insn, insn))
26235         {
26236           /* Claim moves to take one cycle, as core can issue one load
26237              at time and the next load can start cycle later.  */
26238           if (dep_insn_type == TYPE_IMOV
26239               || dep_insn_type == TYPE_FMOV)
26240             cost = 1;
26241           else if (cost > 2)
26242             cost -= 2;
26243           else
26244             cost = 1;
26245         }
26246       break;
26247
26248     case PROCESSOR_AMDFAM10:
26249     case PROCESSOR_BDVER1:
26250     case PROCESSOR_BDVER2:
26251     case PROCESSOR_BDVER3:
26252     case PROCESSOR_BDVER4:
26253     case PROCESSOR_BTVER1:
26254     case PROCESSOR_BTVER2:
26255     case PROCESSOR_GENERIC:
26256       /* Stack engine allows to execute push&pop instructions in parall.  */
26257       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26258           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26259         return 0;
26260       /* FALLTHRU */
26261
26262     case PROCESSOR_ATHLON:
26263     case PROCESSOR_K8:
26264       memory = get_attr_memory (insn);
26265
26266       /* Show ability of reorder buffer to hide latency of load by executing
26267          in parallel with previous instruction in case
26268          previous instruction is not needed to compute the address.  */
26269       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26270           && !ix86_agi_dependent (dep_insn, insn))
26271         {
26272           enum attr_unit unit = get_attr_unit (insn);
26273           int loadcost = 3;
26274
26275           /* Because of the difference between the length of integer and
26276              floating unit pipeline preparation stages, the memory operands
26277              for floating point are cheaper.
26278
26279              ??? For Athlon it the difference is most probably 2.  */
26280           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
26281             loadcost = 3;
26282           else
26283             loadcost = TARGET_ATHLON ? 2 : 0;
26284
26285           if (cost >= loadcost)
26286             cost -= loadcost;
26287           else
26288             cost = 0;
26289         }
26290       break;
26291
26292     case PROCESSOR_CORE2:
26293     case PROCESSOR_NEHALEM:
26294     case PROCESSOR_SANDYBRIDGE:
26295     case PROCESSOR_HASWELL:
26296       /* Stack engine allows to execute push&pop instructions in parall.  */
26297       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26298           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26299         return 0;
26300
26301       memory = get_attr_memory (insn);
26302
26303       /* Show ability of reorder buffer to hide latency of load by executing
26304          in parallel with previous instruction in case
26305          previous instruction is not needed to compute the address.  */
26306       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26307           && !ix86_agi_dependent (dep_insn, insn))
26308         {
26309           if (cost >= 4)
26310             cost -= 4;
26311           else
26312             cost = 0;
26313         }
26314       break;
26315
26316     case PROCESSOR_SILVERMONT:
26317     case PROCESSOR_KNL:
26318     case PROCESSOR_INTEL:
26319       if (!reload_completed)
26320         return cost;
26321
26322       /* Increase cost of integer loads.  */
26323       memory = get_attr_memory (dep_insn);
26324       if (memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26325         {
26326           enum attr_unit unit = get_attr_unit (dep_insn);
26327           if (unit == UNIT_INTEGER && cost == 1)
26328             {
26329               if (memory == MEMORY_LOAD)
26330                 cost = 3;
26331               else
26332                 {
26333                   /* Increase cost of ld/st for short int types only
26334                      because of store forwarding issue.  */
26335                   rtx set = single_set (dep_insn);
26336                   if (set && (GET_MODE (SET_DEST (set)) == QImode
26337                               || GET_MODE (SET_DEST (set)) == HImode))
26338                     {
26339                       /* Increase cost of store/load insn if exact
26340                          dependence exists and it is load insn.  */
26341                       enum attr_memory insn_memory = get_attr_memory (insn);
26342                       if (insn_memory == MEMORY_LOAD
26343                           && exact_store_load_dependency (dep_insn, insn))
26344                         cost = 3;
26345                     }
26346                 }
26347             }
26348         }
26349
26350     default:
26351       break;
26352     }
26353
26354   return cost;
26355 }
26356
26357 /* How many alternative schedules to try.  This should be as wide as the
26358    scheduling freedom in the DFA, but no wider.  Making this value too
26359    large results extra work for the scheduler.  */
26360
26361 static int
26362 ia32_multipass_dfa_lookahead (void)
26363 {
26364   switch (ix86_tune)
26365     {
26366     case PROCESSOR_PENTIUM:
26367       return 2;
26368
26369     case PROCESSOR_PENTIUMPRO:
26370     case PROCESSOR_K6:
26371       return 1;
26372
26373     case PROCESSOR_BDVER1:
26374     case PROCESSOR_BDVER2:
26375     case PROCESSOR_BDVER3:
26376     case PROCESSOR_BDVER4:
26377       /* We use lookahead value 4 for BD both before and after reload
26378          schedules. Plan is to have value 8 included for O3. */
26379         return 4;
26380
26381     case PROCESSOR_CORE2:
26382     case PROCESSOR_NEHALEM:
26383     case PROCESSOR_SANDYBRIDGE:
26384     case PROCESSOR_HASWELL:
26385     case PROCESSOR_BONNELL:
26386     case PROCESSOR_SILVERMONT:
26387     case PROCESSOR_KNL:
26388     case PROCESSOR_INTEL:
26389       /* Generally, we want haifa-sched:max_issue() to look ahead as far
26390          as many instructions can be executed on a cycle, i.e.,
26391          issue_rate.  I wonder why tuning for many CPUs does not do this.  */
26392       if (reload_completed)
26393         return ix86_issue_rate ();
26394       /* Don't use lookahead for pre-reload schedule to save compile time.  */
26395       return 0;
26396
26397     default:
26398       return 0;
26399     }
26400 }
26401
26402 /* Return true if target platform supports macro-fusion.  */
26403
26404 static bool
26405 ix86_macro_fusion_p ()
26406 {
26407   return TARGET_FUSE_CMP_AND_BRANCH;
26408 }
26409
26410 /* Check whether current microarchitecture support macro fusion
26411    for insn pair "CONDGEN + CONDJMP". Refer to
26412    "Intel Architectures Optimization Reference Manual". */
26413
26414 static bool
26415 ix86_macro_fusion_pair_p (rtx_insn *condgen, rtx_insn *condjmp)
26416 {
26417   rtx src, dest;
26418   enum rtx_code ccode;
26419   rtx compare_set = NULL_RTX, test_if, cond;
26420   rtx alu_set = NULL_RTX, addr = NULL_RTX;
26421
26422   if (!any_condjump_p (condjmp))
26423     return false;
26424
26425   if (get_attr_type (condgen) != TYPE_TEST
26426       && get_attr_type (condgen) != TYPE_ICMP
26427       && get_attr_type (condgen) != TYPE_INCDEC
26428       && get_attr_type (condgen) != TYPE_ALU)
26429     return false;
26430
26431   compare_set = single_set (condgen);
26432   if (compare_set == NULL_RTX
26433       && !TARGET_FUSE_ALU_AND_BRANCH)
26434     return false;
26435
26436   if (compare_set == NULL_RTX)
26437     {
26438       int i;
26439       rtx pat = PATTERN (condgen);
26440       for (i = 0; i < XVECLEN (pat, 0); i++)
26441         if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
26442           {
26443             rtx set_src = SET_SRC (XVECEXP (pat, 0, i));
26444             if (GET_CODE (set_src) == COMPARE)
26445               compare_set = XVECEXP (pat, 0, i);
26446             else
26447               alu_set = XVECEXP (pat, 0, i);
26448           }
26449     }
26450   if (compare_set == NULL_RTX)
26451     return false;
26452   src = SET_SRC (compare_set);
26453   if (GET_CODE (src) != COMPARE)
26454     return false;
26455
26456   /* Macro-fusion for cmp/test MEM-IMM + conditional jmp is not
26457      supported.  */
26458   if ((MEM_P (XEXP (src, 0))
26459        && CONST_INT_P (XEXP (src, 1)))
26460       || (MEM_P (XEXP (src, 1))
26461           && CONST_INT_P (XEXP (src, 0))))
26462     return false;
26463
26464   /* No fusion for RIP-relative address.  */
26465   if (MEM_P (XEXP (src, 0)))
26466     addr = XEXP (XEXP (src, 0), 0);
26467   else if (MEM_P (XEXP (src, 1)))
26468     addr = XEXP (XEXP (src, 1), 0);
26469
26470   if (addr) {
26471     ix86_address parts;
26472     int ok = ix86_decompose_address (addr, &parts);
26473     gcc_assert (ok);
26474
26475     if (rip_relative_addr_p (&parts))
26476       return false;
26477   }
26478
26479   test_if = SET_SRC (pc_set (condjmp));
26480   cond = XEXP (test_if, 0);
26481   ccode = GET_CODE (cond);
26482   /* Check whether conditional jump use Sign or Overflow Flags.  */
26483   if (!TARGET_FUSE_CMP_AND_BRANCH_SOFLAGS
26484       && (ccode == GE
26485           || ccode == GT
26486           || ccode == LE
26487           || ccode == LT))
26488     return false;
26489
26490   /* Return true for TYPE_TEST and TYPE_ICMP.  */
26491   if (get_attr_type (condgen) == TYPE_TEST
26492       || get_attr_type (condgen) == TYPE_ICMP)
26493     return true;
26494
26495   /* The following is the case that macro-fusion for alu + jmp.  */
26496   if (!TARGET_FUSE_ALU_AND_BRANCH || !alu_set)
26497     return false;
26498
26499   /* No fusion for alu op with memory destination operand.  */
26500   dest = SET_DEST (alu_set);
26501   if (MEM_P (dest))
26502     return false;
26503
26504   /* Macro-fusion for inc/dec + unsigned conditional jump is not
26505      supported.  */
26506   if (get_attr_type (condgen) == TYPE_INCDEC
26507       && (ccode == GEU
26508           || ccode == GTU
26509           || ccode == LEU
26510           || ccode == LTU))
26511     return false;
26512
26513   return true;
26514 }
26515
26516 /* Try to reorder ready list to take advantage of Atom pipelined IMUL
26517    execution. It is applied if
26518    (1) IMUL instruction is on the top of list;
26519    (2) There exists the only producer of independent IMUL instruction in
26520        ready list.
26521    Return index of IMUL producer if it was found and -1 otherwise.  */
26522 static int
26523 do_reorder_for_imul (rtx_insn **ready, int n_ready)
26524 {
26525   rtx_insn *insn;
26526   rtx set, insn1, insn2;
26527   sd_iterator_def sd_it;
26528   dep_t dep;
26529   int index = -1;
26530   int i;
26531
26532   if (!TARGET_BONNELL)
26533     return index;
26534
26535   /* Check that IMUL instruction is on the top of ready list.  */
26536   insn = ready[n_ready - 1];
26537   set = single_set (insn);
26538   if (!set)
26539     return index;
26540   if (!(GET_CODE (SET_SRC (set)) == MULT
26541       && GET_MODE (SET_SRC (set)) == SImode))
26542     return index;
26543
26544   /* Search for producer of independent IMUL instruction.  */
26545   for (i = n_ready - 2; i >= 0; i--)
26546     {
26547       insn = ready[i];
26548       if (!NONDEBUG_INSN_P (insn))
26549         continue;
26550       /* Skip IMUL instruction.  */
26551       insn2 = PATTERN (insn);
26552       if (GET_CODE (insn2) == PARALLEL)
26553         insn2 = XVECEXP (insn2, 0, 0);
26554       if (GET_CODE (insn2) == SET
26555           && GET_CODE (SET_SRC (insn2)) == MULT
26556           && GET_MODE (SET_SRC (insn2)) == SImode)
26557         continue;
26558
26559       FOR_EACH_DEP (insn, SD_LIST_FORW, sd_it, dep)
26560         {
26561           rtx con;
26562           con = DEP_CON (dep);
26563           if (!NONDEBUG_INSN_P (con))
26564             continue;
26565           insn1 = PATTERN (con);
26566           if (GET_CODE (insn1) == PARALLEL)
26567             insn1 = XVECEXP (insn1, 0, 0);
26568
26569           if (GET_CODE (insn1) == SET
26570               && GET_CODE (SET_SRC (insn1)) == MULT
26571               && GET_MODE (SET_SRC (insn1)) == SImode)
26572             {
26573               sd_iterator_def sd_it1;
26574               dep_t dep1;
26575               /* Check if there is no other dependee for IMUL.  */
26576               index = i;
26577               FOR_EACH_DEP (con, SD_LIST_BACK, sd_it1, dep1)
26578                 {
26579                   rtx pro;
26580                   pro = DEP_PRO (dep1);
26581                   if (!NONDEBUG_INSN_P (pro))
26582                     continue;
26583                   if (pro != insn)
26584                     index = -1;
26585                 }
26586               if (index >= 0)
26587                 break;
26588             }
26589         }
26590       if (index >= 0)
26591         break;
26592     }
26593   return index;
26594 }
26595
26596 /* Try to find the best candidate on the top of ready list if two insns
26597    have the same priority - candidate is best if its dependees were
26598    scheduled earlier. Applied for Silvermont only.
26599    Return true if top 2 insns must be interchanged.  */
26600 static bool
26601 swap_top_of_ready_list (rtx_insn **ready, int n_ready)
26602 {
26603   rtx_insn *top = ready[n_ready - 1];
26604   rtx_insn *next = ready[n_ready - 2];
26605   rtx set;
26606   sd_iterator_def sd_it;
26607   dep_t dep;
26608   int clock1 = -1;
26609   int clock2 = -1;
26610   #define INSN_TICK(INSN) (HID (INSN)->tick)
26611
26612   if (!TARGET_SILVERMONT && !TARGET_INTEL)
26613     return false;
26614
26615   if (!NONDEBUG_INSN_P (top))
26616     return false;
26617   if (!NONJUMP_INSN_P (top))
26618     return false;
26619   if (!NONDEBUG_INSN_P (next))
26620     return false;
26621   if (!NONJUMP_INSN_P (next))
26622     return false;
26623   set = single_set (top);
26624   if (!set)
26625     return false;
26626   set = single_set (next);
26627   if (!set)
26628     return false;
26629
26630   if (INSN_PRIORITY_KNOWN (top) && INSN_PRIORITY_KNOWN (next))
26631     {
26632       if (INSN_PRIORITY (top) != INSN_PRIORITY (next))
26633         return false;
26634       /* Determine winner more precise.  */
26635       FOR_EACH_DEP (top, SD_LIST_RES_BACK, sd_it, dep)
26636         {
26637           rtx pro;
26638           pro = DEP_PRO (dep);
26639           if (!NONDEBUG_INSN_P (pro))
26640             continue;
26641           if (INSN_TICK (pro) > clock1)
26642             clock1 = INSN_TICK (pro);
26643         }
26644       FOR_EACH_DEP (next, SD_LIST_RES_BACK, sd_it, dep)
26645         {
26646           rtx pro;
26647           pro = DEP_PRO (dep);
26648           if (!NONDEBUG_INSN_P (pro))
26649             continue;
26650           if (INSN_TICK (pro) > clock2)
26651             clock2 = INSN_TICK (pro);
26652         }
26653
26654       if (clock1 == clock2)
26655         {
26656           /* Determine winner - load must win. */
26657           enum attr_memory memory1, memory2;
26658           memory1 = get_attr_memory (top);
26659           memory2 = get_attr_memory (next);
26660           if (memory2 == MEMORY_LOAD && memory1 != MEMORY_LOAD)
26661             return true;
26662         }
26663         return (bool) (clock2 < clock1);
26664     }
26665   return false;
26666   #undef INSN_TICK
26667 }
26668
26669 /* Perform possible reodering of ready list for Atom/Silvermont only.
26670    Return issue rate.  */
26671 static int
26672 ix86_sched_reorder (FILE *dump, int sched_verbose, rtx_insn **ready,
26673                     int *pn_ready, int clock_var)
26674 {
26675   int issue_rate = -1;
26676   int n_ready = *pn_ready;
26677   int i;
26678   rtx_insn *insn;
26679   int index = -1;
26680
26681   /* Set up issue rate.  */
26682   issue_rate = ix86_issue_rate ();
26683
26684   /* Do reodering for BONNELL/SILVERMONT only.  */
26685   if (!TARGET_BONNELL && !TARGET_SILVERMONT && !TARGET_INTEL)
26686     return issue_rate;
26687
26688   /* Nothing to do if ready list contains only 1 instruction.  */
26689   if (n_ready <= 1)
26690     return issue_rate;
26691
26692   /* Do reodering for post-reload scheduler only.  */
26693   if (!reload_completed)
26694     return issue_rate;
26695
26696   if ((index = do_reorder_for_imul (ready, n_ready)) >= 0)
26697     {
26698       if (sched_verbose > 1)
26699         fprintf (dump, ";;\tatom sched_reorder: put %d insn on top\n",
26700                  INSN_UID (ready[index]));
26701
26702       /* Put IMUL producer (ready[index]) at the top of ready list.  */
26703       insn = ready[index];
26704       for (i = index; i < n_ready - 1; i++)
26705         ready[i] = ready[i + 1];
26706       ready[n_ready - 1] = insn;
26707       return issue_rate;
26708     }
26709   if (clock_var != 0 && swap_top_of_ready_list (ready, n_ready))
26710     {
26711       if (sched_verbose > 1)
26712         fprintf (dump, ";;\tslm sched_reorder: swap %d and %d insns\n",
26713                  INSN_UID (ready[n_ready - 1]), INSN_UID (ready[n_ready - 2]));
26714       /* Swap 2 top elements of ready list.  */
26715       insn = ready[n_ready - 1];
26716       ready[n_ready - 1] = ready[n_ready - 2];
26717       ready[n_ready - 2] = insn;
26718     }
26719   return issue_rate;
26720 }
26721
26722 static bool
26723 ix86_class_likely_spilled_p (reg_class_t);
26724
26725 /* Returns true if lhs of insn is HW function argument register and set up
26726    is_spilled to true if it is likely spilled HW register.  */
26727 static bool
26728 insn_is_function_arg (rtx insn, bool* is_spilled)
26729 {
26730   rtx dst;
26731
26732   if (!NONDEBUG_INSN_P (insn))
26733     return false;
26734   /* Call instructions are not movable, ignore it.  */
26735   if (CALL_P (insn))
26736     return false;
26737   insn = PATTERN (insn);
26738   if (GET_CODE (insn) == PARALLEL)
26739     insn = XVECEXP (insn, 0, 0);
26740   if (GET_CODE (insn) != SET)
26741     return false;
26742   dst = SET_DEST (insn);
26743   if (REG_P (dst) && HARD_REGISTER_P (dst)
26744       && ix86_function_arg_regno_p (REGNO (dst)))
26745     {
26746       /* Is it likely spilled HW register?  */
26747       if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst))
26748           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))))
26749         *is_spilled = true;
26750       return true;
26751     }
26752   return false;
26753 }
26754
26755 /* Add output dependencies for chain of function adjacent arguments if only
26756    there is a move to likely spilled HW register.  Return first argument
26757    if at least one dependence was added or NULL otherwise.  */
26758 static rtx_insn *
26759 add_parameter_dependencies (rtx_insn *call, rtx_insn *head)
26760 {
26761   rtx_insn *insn;
26762   rtx_insn *last = call;
26763   rtx_insn *first_arg = NULL;
26764   bool is_spilled = false;
26765
26766   head = PREV_INSN (head);
26767
26768   /* Find nearest to call argument passing instruction.  */
26769   while (true)
26770     {
26771       last = PREV_INSN (last);
26772       if (last == head)
26773         return NULL;
26774       if (!NONDEBUG_INSN_P (last))
26775         continue;
26776       if (insn_is_function_arg (last, &is_spilled))
26777         break;
26778       return NULL;
26779     }
26780
26781   first_arg = last;
26782   while (true)
26783     {
26784       insn = PREV_INSN (last);
26785       if (!INSN_P (insn))
26786         break;
26787       if (insn == head)
26788         break;
26789       if (!NONDEBUG_INSN_P (insn))
26790         {
26791           last = insn;
26792           continue;
26793         }
26794       if (insn_is_function_arg (insn, &is_spilled))
26795         {
26796           /* Add output depdendence between two function arguments if chain
26797              of output arguments contains likely spilled HW registers.  */
26798           if (is_spilled)
26799             add_dependence (first_arg, insn, REG_DEP_OUTPUT);
26800           first_arg = last = insn;
26801         }
26802       else
26803         break;
26804     }
26805   if (!is_spilled)
26806     return NULL;
26807   return first_arg;
26808 }
26809
26810 /* Add output or anti dependency from insn to first_arg to restrict its code
26811    motion.  */
26812 static void
26813 avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn)
26814 {
26815   rtx set;
26816   rtx tmp;
26817
26818   set = single_set (insn);
26819   if (!set)
26820     return;
26821   tmp = SET_DEST (set);
26822   if (REG_P (tmp))
26823     {
26824       /* Add output dependency to the first function argument.  */
26825       add_dependence (first_arg, insn, REG_DEP_OUTPUT);
26826       return;
26827     }
26828   /* Add anti dependency.  */
26829   add_dependence (first_arg, insn, REG_DEP_ANTI);
26830 }
26831
26832 /* Avoid cross block motion of function argument through adding dependency
26833    from the first non-jump instruction in bb.  */
26834 static void
26835 add_dependee_for_func_arg (rtx_insn *arg, basic_block bb)
26836 {
26837   rtx_insn *insn = BB_END (bb);
26838
26839   while (insn)
26840     {
26841       if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn))
26842         {
26843           rtx set = single_set (insn);
26844           if (set)
26845             {
26846               avoid_func_arg_motion (arg, insn);
26847               return;
26848             }
26849         }
26850       if (insn == BB_HEAD (bb))
26851         return;
26852       insn = PREV_INSN (insn);
26853     }
26854 }
26855
26856 /* Hook for pre-reload schedule - avoid motion of function arguments
26857    passed in likely spilled HW registers.  */
26858 static void
26859 ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail)
26860 {
26861   rtx_insn *insn;
26862   rtx_insn *first_arg = NULL;
26863   if (reload_completed)
26864     return;
26865   while (head != tail && DEBUG_INSN_P (head))
26866     head = NEXT_INSN (head);
26867   for (insn = tail; insn != head; insn = PREV_INSN (insn))
26868     if (INSN_P (insn) && CALL_P (insn))
26869       {
26870         first_arg = add_parameter_dependencies (insn, head);
26871         if (first_arg)
26872           {
26873             /* Add dependee for first argument to predecessors if only
26874                region contains more than one block.  */
26875             basic_block bb =  BLOCK_FOR_INSN (insn);
26876             int rgn = CONTAINING_RGN (bb->index);
26877             int nr_blks = RGN_NR_BLOCKS (rgn);
26878             /* Skip trivial regions and region head blocks that can have
26879                predecessors outside of region.  */
26880             if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0)
26881               {
26882                 edge e;
26883                 edge_iterator ei;
26884
26885                 /* Regions are SCCs with the exception of selective
26886                    scheduling with pipelining of outer blocks enabled.
26887                    So also check that immediate predecessors of a non-head
26888                    block are in the same region.  */
26889                 FOR_EACH_EDGE (e, ei, bb->preds)
26890                   {
26891                     /* Avoid creating of loop-carried dependencies through
26892                        using topological ordering in the region.  */
26893                     if (rgn == CONTAINING_RGN (e->src->index)
26894                         && BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index))
26895                       add_dependee_for_func_arg (first_arg, e->src); 
26896                   }
26897               }
26898             insn = first_arg;
26899             if (insn == head)
26900               break;
26901           }
26902       }
26903     else if (first_arg)
26904       avoid_func_arg_motion (first_arg, insn);
26905 }
26906
26907 /* Hook for pre-reload schedule - set priority of moves from likely spilled
26908    HW registers to maximum, to schedule them at soon as possible. These are
26909    moves from function argument registers at the top of the function entry
26910    and moves from function return value registers after call.  */
26911 static int
26912 ix86_adjust_priority (rtx_insn *insn, int priority)
26913 {
26914   rtx set;
26915
26916   if (reload_completed)
26917     return priority;
26918
26919   if (!NONDEBUG_INSN_P (insn))
26920     return priority;
26921
26922   set = single_set (insn);
26923   if (set)
26924     {
26925       rtx tmp = SET_SRC (set);
26926       if (REG_P (tmp)
26927           && HARD_REGISTER_P (tmp)
26928           && !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp))
26929           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp))))
26930         return current_sched_info->sched_max_insns_priority;
26931     }
26932
26933   return priority;
26934 }
26935
26936 /* Model decoder of Core 2/i7.
26937    Below hooks for multipass scheduling (see haifa-sched.c:max_issue)
26938    track the instruction fetch block boundaries and make sure that long
26939    (9+ bytes) instructions are assigned to D0.  */
26940
26941 /* Maximum length of an insn that can be handled by
26942    a secondary decoder unit.  '8' for Core 2/i7.  */
26943 static int core2i7_secondary_decoder_max_insn_size;
26944
26945 /* Ifetch block size, i.e., number of bytes decoder reads per cycle.
26946    '16' for Core 2/i7.  */
26947 static int core2i7_ifetch_block_size;
26948
26949 /* Maximum number of instructions decoder can handle per cycle.
26950    '6' for Core 2/i7.  */
26951 static int core2i7_ifetch_block_max_insns;
26952
26953 typedef struct ix86_first_cycle_multipass_data_ *
26954   ix86_first_cycle_multipass_data_t;
26955 typedef const struct ix86_first_cycle_multipass_data_ *
26956   const_ix86_first_cycle_multipass_data_t;
26957
26958 /* A variable to store target state across calls to max_issue within
26959    one cycle.  */
26960 static struct ix86_first_cycle_multipass_data_ _ix86_first_cycle_multipass_data,
26961   *ix86_first_cycle_multipass_data = &_ix86_first_cycle_multipass_data;
26962
26963 /* Initialize DATA.  */
26964 static void
26965 core2i7_first_cycle_multipass_init (void *_data)
26966 {
26967   ix86_first_cycle_multipass_data_t data
26968     = (ix86_first_cycle_multipass_data_t) _data;
26969
26970   data->ifetch_block_len = 0;
26971   data->ifetch_block_n_insns = 0;
26972   data->ready_try_change = NULL;
26973   data->ready_try_change_size = 0;
26974 }
26975
26976 /* Advancing the cycle; reset ifetch block counts.  */
26977 static void
26978 core2i7_dfa_post_advance_cycle (void)
26979 {
26980   ix86_first_cycle_multipass_data_t data = ix86_first_cycle_multipass_data;
26981
26982   gcc_assert (data->ifetch_block_n_insns <= core2i7_ifetch_block_max_insns);
26983
26984   data->ifetch_block_len = 0;
26985   data->ifetch_block_n_insns = 0;
26986 }
26987
26988 static int min_insn_size (rtx_insn *);
26989
26990 /* Filter out insns from ready_try that the core will not be able to issue
26991    on current cycle due to decoder.  */
26992 static void
26993 core2i7_first_cycle_multipass_filter_ready_try
26994 (const_ix86_first_cycle_multipass_data_t data,
26995  signed char *ready_try, int n_ready, bool first_cycle_insn_p)
26996 {
26997   while (n_ready--)
26998     {
26999       rtx_insn *insn;
27000       int insn_size;
27001
27002       if (ready_try[n_ready])
27003         continue;
27004
27005       insn = get_ready_element (n_ready);
27006       insn_size = min_insn_size (insn);
27007
27008       if (/* If this is a too long an insn for a secondary decoder ...  */
27009           (!first_cycle_insn_p
27010            && insn_size > core2i7_secondary_decoder_max_insn_size)
27011           /* ... or it would not fit into the ifetch block ...  */
27012           || data->ifetch_block_len + insn_size > core2i7_ifetch_block_size
27013           /* ... or the decoder is full already ...  */
27014           || data->ifetch_block_n_insns + 1 > core2i7_ifetch_block_max_insns)
27015         /* ... mask the insn out.  */
27016         {
27017           ready_try[n_ready] = 1;
27018
27019           if (data->ready_try_change)
27020             bitmap_set_bit (data->ready_try_change, n_ready);
27021         }
27022     }
27023 }
27024
27025 /* Prepare for a new round of multipass lookahead scheduling.  */
27026 static void
27027 core2i7_first_cycle_multipass_begin (void *_data,
27028                                      signed char *ready_try, int n_ready,
27029                                      bool first_cycle_insn_p)
27030 {
27031   ix86_first_cycle_multipass_data_t data
27032     = (ix86_first_cycle_multipass_data_t) _data;
27033   const_ix86_first_cycle_multipass_data_t prev_data
27034     = ix86_first_cycle_multipass_data;
27035
27036   /* Restore the state from the end of the previous round.  */
27037   data->ifetch_block_len = prev_data->ifetch_block_len;
27038   data->ifetch_block_n_insns = prev_data->ifetch_block_n_insns;
27039
27040   /* Filter instructions that cannot be issued on current cycle due to
27041      decoder restrictions.  */
27042   core2i7_first_cycle_multipass_filter_ready_try (data, ready_try, n_ready,
27043                                                   first_cycle_insn_p);
27044 }
27045
27046 /* INSN is being issued in current solution.  Account for its impact on
27047    the decoder model.  */
27048 static void
27049 core2i7_first_cycle_multipass_issue (void *_data,
27050                                      signed char *ready_try, int n_ready,
27051                                      rtx_insn *insn, const void *_prev_data)
27052 {
27053   ix86_first_cycle_multipass_data_t data
27054     = (ix86_first_cycle_multipass_data_t) _data;
27055   const_ix86_first_cycle_multipass_data_t prev_data
27056     = (const_ix86_first_cycle_multipass_data_t) _prev_data;
27057
27058   int insn_size = min_insn_size (insn);
27059
27060   data->ifetch_block_len = prev_data->ifetch_block_len + insn_size;
27061   data->ifetch_block_n_insns = prev_data->ifetch_block_n_insns + 1;
27062   gcc_assert (data->ifetch_block_len <= core2i7_ifetch_block_size
27063               && data->ifetch_block_n_insns <= core2i7_ifetch_block_max_insns);
27064
27065   /* Allocate or resize the bitmap for storing INSN's effect on ready_try.  */
27066   if (!data->ready_try_change)
27067     {
27068       data->ready_try_change = sbitmap_alloc (n_ready);
27069       data->ready_try_change_size = n_ready;
27070     }
27071   else if (data->ready_try_change_size < n_ready)
27072     {
27073       data->ready_try_change = sbitmap_resize (data->ready_try_change,
27074                                                n_ready, 0);
27075       data->ready_try_change_size = n_ready;
27076     }
27077   bitmap_clear (data->ready_try_change);
27078
27079   /* Filter out insns from ready_try that the core will not be able to issue
27080      on current cycle due to decoder.  */
27081   core2i7_first_cycle_multipass_filter_ready_try (data, ready_try, n_ready,
27082                                                   false);
27083 }
27084
27085 /* Revert the effect on ready_try.  */
27086 static void
27087 core2i7_first_cycle_multipass_backtrack (const void *_data,
27088                                          signed char *ready_try,
27089                                          int n_ready ATTRIBUTE_UNUSED)
27090 {
27091   const_ix86_first_cycle_multipass_data_t data
27092     = (const_ix86_first_cycle_multipass_data_t) _data;
27093   unsigned int i = 0;
27094   sbitmap_iterator sbi;
27095
27096   gcc_assert (bitmap_last_set_bit (data->ready_try_change) < n_ready);
27097   EXECUTE_IF_SET_IN_BITMAP (data->ready_try_change, 0, i, sbi)
27098     {
27099       ready_try[i] = 0;
27100     }
27101 }
27102
27103 /* Save the result of multipass lookahead scheduling for the next round.  */
27104 static void
27105 core2i7_first_cycle_multipass_end (const void *_data)
27106 {
27107   const_ix86_first_cycle_multipass_data_t data
27108     = (const_ix86_first_cycle_multipass_data_t) _data;
27109   ix86_first_cycle_multipass_data_t next_data
27110     = ix86_first_cycle_multipass_data;
27111
27112   if (data != NULL)
27113     {
27114       next_data->ifetch_block_len = data->ifetch_block_len;
27115       next_data->ifetch_block_n_insns = data->ifetch_block_n_insns;
27116     }
27117 }
27118
27119 /* Deallocate target data.  */
27120 static void
27121 core2i7_first_cycle_multipass_fini (void *_data)
27122 {
27123   ix86_first_cycle_multipass_data_t data
27124     = (ix86_first_cycle_multipass_data_t) _data;
27125
27126   if (data->ready_try_change)
27127     {
27128       sbitmap_free (data->ready_try_change);
27129       data->ready_try_change = NULL;
27130       data->ready_try_change_size = 0;
27131     }
27132 }
27133
27134 /* Prepare for scheduling pass.  */
27135 static void
27136 ix86_sched_init_global (FILE *, int, int)
27137 {
27138   /* Install scheduling hooks for current CPU.  Some of these hooks are used
27139      in time-critical parts of the scheduler, so we only set them up when
27140      they are actually used.  */
27141   switch (ix86_tune)
27142     {
27143     case PROCESSOR_CORE2:
27144     case PROCESSOR_NEHALEM:
27145     case PROCESSOR_SANDYBRIDGE:
27146     case PROCESSOR_HASWELL:
27147       /* Do not perform multipass scheduling for pre-reload schedule
27148          to save compile time.  */
27149       if (reload_completed)
27150         {
27151           targetm.sched.dfa_post_advance_cycle
27152             = core2i7_dfa_post_advance_cycle;
27153           targetm.sched.first_cycle_multipass_init
27154             = core2i7_first_cycle_multipass_init;
27155           targetm.sched.first_cycle_multipass_begin
27156             = core2i7_first_cycle_multipass_begin;
27157           targetm.sched.first_cycle_multipass_issue
27158             = core2i7_first_cycle_multipass_issue;
27159           targetm.sched.first_cycle_multipass_backtrack
27160             = core2i7_first_cycle_multipass_backtrack;
27161           targetm.sched.first_cycle_multipass_end
27162             = core2i7_first_cycle_multipass_end;
27163           targetm.sched.first_cycle_multipass_fini
27164             = core2i7_first_cycle_multipass_fini;
27165
27166           /* Set decoder parameters.  */
27167           core2i7_secondary_decoder_max_insn_size = 8;
27168           core2i7_ifetch_block_size = 16;
27169           core2i7_ifetch_block_max_insns = 6;
27170           break;
27171         }
27172       /* ... Fall through ...  */
27173     default:
27174       targetm.sched.dfa_post_advance_cycle = NULL;
27175       targetm.sched.first_cycle_multipass_init = NULL;
27176       targetm.sched.first_cycle_multipass_begin = NULL;
27177       targetm.sched.first_cycle_multipass_issue = NULL;
27178       targetm.sched.first_cycle_multipass_backtrack = NULL;
27179       targetm.sched.first_cycle_multipass_end = NULL;
27180       targetm.sched.first_cycle_multipass_fini = NULL;
27181       break;
27182     }
27183 }
27184
27185 \f
27186 /* Compute the alignment given to a constant that is being placed in memory.
27187    EXP is the constant and ALIGN is the alignment that the object would
27188    ordinarily have.
27189    The value of this function is used instead of that alignment to align
27190    the object.  */
27191
27192 int
27193 ix86_constant_alignment (tree exp, int align)
27194 {
27195   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
27196       || TREE_CODE (exp) == INTEGER_CST)
27197     {
27198       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
27199         return 64;
27200       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
27201         return 128;
27202     }
27203   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
27204            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
27205     return BITS_PER_WORD;
27206
27207   return align;
27208 }
27209
27210 /* Compute the alignment for a static variable.
27211    TYPE is the data type, and ALIGN is the alignment that
27212    the object would ordinarily have.  The value of this function is used
27213    instead of that alignment to align the object.  */
27214
27215 int
27216 ix86_data_alignment (tree type, int align, bool opt)
27217 {
27218   /* GCC 4.8 and earlier used to incorrectly assume this alignment even
27219      for symbols from other compilation units or symbols that don't need
27220      to bind locally.  In order to preserve some ABI compatibility with
27221      those compilers, ensure we don't decrease alignment from what we
27222      used to assume.  */
27223
27224   int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT);
27225
27226   /* A data structure, equal or greater than the size of a cache line
27227      (64 bytes in the Pentium 4 and other recent Intel processors, including
27228      processors based on Intel Core microarchitecture) should be aligned
27229      so that its base address is a multiple of a cache line size.  */
27230
27231   int max_align
27232     = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
27233
27234   if (max_align < BITS_PER_WORD)
27235     max_align = BITS_PER_WORD;
27236
27237   switch (ix86_align_data_type)
27238     {
27239     case ix86_align_data_type_abi: opt = false; break;
27240     case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break;
27241     case ix86_align_data_type_cacheline: break;
27242     }
27243
27244   if (opt
27245       && AGGREGATE_TYPE_P (type)
27246       && TYPE_SIZE (type)
27247       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
27248     {
27249       if (wi::geu_p (TYPE_SIZE (type), max_align_compat)
27250           && align < max_align_compat)
27251         align = max_align_compat;
27252        if (wi::geu_p (TYPE_SIZE (type), max_align)
27253            && align < max_align)
27254          align = max_align;
27255     }
27256
27257   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
27258      to 16byte boundary.  */
27259   if (TARGET_64BIT)
27260     {
27261       if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
27262           && TYPE_SIZE (type)
27263           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
27264           && wi::geu_p (TYPE_SIZE (type), 128)
27265           && align < 128)
27266         return 128;
27267     }
27268
27269   if (!opt)
27270     return align;
27271
27272   if (TREE_CODE (type) == ARRAY_TYPE)
27273     {
27274       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
27275         return 64;
27276       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
27277         return 128;
27278     }
27279   else if (TREE_CODE (type) == COMPLEX_TYPE)
27280     {
27281
27282       if (TYPE_MODE (type) == DCmode && align < 64)
27283         return 64;
27284       if ((TYPE_MODE (type) == XCmode
27285            || TYPE_MODE (type) == TCmode) && align < 128)
27286         return 128;
27287     }
27288   else if ((TREE_CODE (type) == RECORD_TYPE
27289             || TREE_CODE (type) == UNION_TYPE
27290             || TREE_CODE (type) == QUAL_UNION_TYPE)
27291            && TYPE_FIELDS (type))
27292     {
27293       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
27294         return 64;
27295       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
27296         return 128;
27297     }
27298   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
27299            || TREE_CODE (type) == INTEGER_TYPE)
27300     {
27301       if (TYPE_MODE (type) == DFmode && align < 64)
27302         return 64;
27303       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
27304         return 128;
27305     }
27306
27307   return align;
27308 }
27309
27310 /* Compute the alignment for a local variable or a stack slot.  EXP is
27311    the data type or decl itself, MODE is the widest mode available and
27312    ALIGN is the alignment that the object would ordinarily have.  The
27313    value of this macro is used instead of that alignment to align the
27314    object.  */
27315
27316 unsigned int
27317 ix86_local_alignment (tree exp, machine_mode mode,
27318                       unsigned int align)
27319 {
27320   tree type, decl;
27321
27322   if (exp && DECL_P (exp))
27323     {
27324       type = TREE_TYPE (exp);
27325       decl = exp;
27326     }
27327   else
27328     {
27329       type = exp;
27330       decl = NULL;
27331     }
27332
27333   /* Don't do dynamic stack realignment for long long objects with
27334      -mpreferred-stack-boundary=2.  */
27335   if (!TARGET_64BIT
27336       && align == 64
27337       && ix86_preferred_stack_boundary < 64
27338       && (mode == DImode || (type && TYPE_MODE (type) == DImode))
27339       && (!type || !TYPE_USER_ALIGN (type))
27340       && (!decl || !DECL_USER_ALIGN (decl)))
27341     align = 32;
27342
27343   /* If TYPE is NULL, we are allocating a stack slot for caller-save
27344      register in MODE.  We will return the largest alignment of XF
27345      and DF.  */
27346   if (!type)
27347     {
27348       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
27349         align = GET_MODE_ALIGNMENT (DFmode);
27350       return align;
27351     }
27352
27353   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
27354      to 16byte boundary.  Exact wording is:
27355
27356      An array uses the same alignment as its elements, except that a local or
27357      global array variable of length at least 16 bytes or
27358      a C99 variable-length array variable always has alignment of at least 16 bytes.
27359
27360      This was added to allow use of aligned SSE instructions at arrays.  This
27361      rule is meant for static storage (where compiler can not do the analysis
27362      by itself).  We follow it for automatic variables only when convenient.
27363      We fully control everything in the function compiled and functions from
27364      other unit can not rely on the alignment.
27365
27366      Exclude va_list type.  It is the common case of local array where
27367      we can not benefit from the alignment.  
27368
27369      TODO: Probably one should optimize for size only when var is not escaping.  */
27370   if (TARGET_64BIT && optimize_function_for_speed_p (cfun)
27371       && TARGET_SSE)
27372     {
27373       if (AGGREGATE_TYPE_P (type)
27374           && (va_list_type_node == NULL_TREE
27375               || (TYPE_MAIN_VARIANT (type)
27376                   != TYPE_MAIN_VARIANT (va_list_type_node)))
27377           && TYPE_SIZE (type)
27378           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
27379           && wi::geu_p (TYPE_SIZE (type), 16)
27380           && align < 128)
27381         return 128;
27382     }
27383   if (TREE_CODE (type) == ARRAY_TYPE)
27384     {
27385       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
27386         return 64;
27387       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
27388         return 128;
27389     }
27390   else if (TREE_CODE (type) == COMPLEX_TYPE)
27391     {
27392       if (TYPE_MODE (type) == DCmode && align < 64)
27393         return 64;
27394       if ((TYPE_MODE (type) == XCmode
27395            || TYPE_MODE (type) == TCmode) && align < 128)
27396         return 128;
27397     }
27398   else if ((TREE_CODE (type) == RECORD_TYPE
27399             || TREE_CODE (type) == UNION_TYPE
27400             || TREE_CODE (type) == QUAL_UNION_TYPE)
27401            && TYPE_FIELDS (type))
27402     {
27403       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
27404         return 64;
27405       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
27406         return 128;
27407     }
27408   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
27409            || TREE_CODE (type) == INTEGER_TYPE)
27410     {
27411
27412       if (TYPE_MODE (type) == DFmode && align < 64)
27413         return 64;
27414       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
27415         return 128;
27416     }
27417   return align;
27418 }
27419
27420 /* Compute the minimum required alignment for dynamic stack realignment
27421    purposes for a local variable, parameter or a stack slot.  EXP is
27422    the data type or decl itself, MODE is its mode and ALIGN is the
27423    alignment that the object would ordinarily have.  */
27424
27425 unsigned int
27426 ix86_minimum_alignment (tree exp, machine_mode mode,
27427                         unsigned int align)
27428 {
27429   tree type, decl;
27430
27431   if (exp && DECL_P (exp))
27432     {
27433       type = TREE_TYPE (exp);
27434       decl = exp;
27435     }
27436   else
27437     {
27438       type = exp;
27439       decl = NULL;
27440     }
27441
27442   if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
27443     return align;
27444
27445   /* Don't do dynamic stack realignment for long long objects with
27446      -mpreferred-stack-boundary=2.  */
27447   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
27448       && (!type || !TYPE_USER_ALIGN (type))
27449       && (!decl || !DECL_USER_ALIGN (decl)))
27450     return 32;
27451
27452   return align;
27453 }
27454 \f
27455 /* Find a location for the static chain incoming to a nested function.
27456    This is a register, unless all free registers are used by arguments.  */
27457
27458 static rtx
27459 ix86_static_chain (const_tree fndecl_or_type, bool incoming_p)
27460 {
27461   unsigned regno;
27462
27463   /* While this function won't be called by the middle-end when a static
27464      chain isn't needed, it's also used throughout the backend so it's
27465      easiest to keep this check centralized.  */
27466   if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type))
27467     return NULL;
27468
27469   if (TARGET_64BIT)
27470     {
27471       /* We always use R10 in 64-bit mode.  */
27472       regno = R10_REG;
27473     }
27474   else
27475     {
27476       const_tree fntype, fndecl;
27477       unsigned int ccvt;
27478
27479       /* By default in 32-bit mode we use ECX to pass the static chain.  */
27480       regno = CX_REG;
27481
27482       if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL)
27483         {
27484           fntype = TREE_TYPE (fndecl_or_type);
27485           fndecl = fndecl_or_type;
27486         }
27487       else
27488         {
27489           fntype = fndecl_or_type;
27490           fndecl = NULL;
27491         }
27492
27493       ccvt = ix86_get_callcvt (fntype);
27494       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
27495         {
27496           /* Fastcall functions use ecx/edx for arguments, which leaves
27497              us with EAX for the static chain.
27498              Thiscall functions use ecx for arguments, which also
27499              leaves us with EAX for the static chain.  */
27500           regno = AX_REG;
27501         }
27502       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
27503         {
27504           /* Thiscall functions use ecx for arguments, which leaves
27505              us with EAX and EDX for the static chain.
27506              We are using for abi-compatibility EAX.  */
27507           regno = AX_REG;
27508         }
27509       else if (ix86_function_regparm (fntype, fndecl) == 3)
27510         {
27511           /* For regparm 3, we have no free call-clobbered registers in
27512              which to store the static chain.  In order to implement this,
27513              we have the trampoline push the static chain to the stack.
27514              However, we can't push a value below the return address when
27515              we call the nested function directly, so we have to use an
27516              alternate entry point.  For this we use ESI, and have the
27517              alternate entry point push ESI, so that things appear the
27518              same once we're executing the nested function.  */
27519           if (incoming_p)
27520             {
27521               if (fndecl == current_function_decl)
27522                 ix86_static_chain_on_stack = true;
27523               return gen_frame_mem (SImode,
27524                                     plus_constant (Pmode,
27525                                                    arg_pointer_rtx, -8));
27526             }
27527           regno = SI_REG;
27528         }
27529     }
27530
27531   return gen_rtx_REG (Pmode, regno);
27532 }
27533
27534 /* Emit RTL insns to initialize the variable parts of a trampoline.
27535    FNDECL is the decl of the target address; M_TRAMP is a MEM for
27536    the trampoline, and CHAIN_VALUE is an RTX for the static chain
27537    to be passed to the target function.  */
27538
27539 static void
27540 ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
27541 {
27542   rtx mem, fnaddr;
27543   int opcode;
27544   int offset = 0;
27545
27546   fnaddr = XEXP (DECL_RTL (fndecl), 0);
27547
27548   if (TARGET_64BIT)
27549     {
27550       int size;
27551
27552       /* Load the function address to r11.  Try to load address using
27553          the shorter movl instead of movabs.  We may want to support
27554          movq for kernel mode, but kernel does not use trampolines at
27555          the moment.  FNADDR is a 32bit address and may not be in
27556          DImode when ptr_mode == SImode.  Always use movl in this
27557          case.  */
27558       if (ptr_mode == SImode
27559           || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
27560         {
27561           fnaddr = copy_addr_to_reg (fnaddr);
27562
27563           mem = adjust_address (m_tramp, HImode, offset);
27564           emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
27565
27566           mem = adjust_address (m_tramp, SImode, offset + 2);
27567           emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
27568           offset += 6;
27569         }
27570       else
27571         {
27572           mem = adjust_address (m_tramp, HImode, offset);
27573           emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
27574
27575           mem = adjust_address (m_tramp, DImode, offset + 2);
27576           emit_move_insn (mem, fnaddr);
27577           offset += 10;
27578         }
27579
27580       /* Load static chain using movabs to r10.  Use the shorter movl
27581          instead of movabs when ptr_mode == SImode.  */
27582       if (ptr_mode == SImode)
27583         {
27584           opcode = 0xba41;
27585           size = 6;
27586         }
27587       else
27588         {
27589           opcode = 0xba49;
27590           size = 10;
27591         }
27592
27593       mem = adjust_address (m_tramp, HImode, offset);
27594       emit_move_insn (mem, gen_int_mode (opcode, HImode));
27595
27596       mem = adjust_address (m_tramp, ptr_mode, offset + 2);
27597       emit_move_insn (mem, chain_value);
27598       offset += size;
27599
27600       /* Jump to r11; the last (unused) byte is a nop, only there to
27601          pad the write out to a single 32-bit store.  */
27602       mem = adjust_address (m_tramp, SImode, offset);
27603       emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
27604       offset += 4;
27605     }
27606   else
27607     {
27608       rtx disp, chain;
27609
27610       /* Depending on the static chain location, either load a register
27611          with a constant, or push the constant to the stack.  All of the
27612          instructions are the same size.  */
27613       chain = ix86_static_chain (fndecl, true);
27614       if (REG_P (chain))
27615         {
27616           switch (REGNO (chain))
27617             {
27618             case AX_REG:
27619               opcode = 0xb8; break;
27620             case CX_REG:
27621               opcode = 0xb9; break;
27622             default:
27623               gcc_unreachable ();
27624             }
27625         }
27626       else
27627         opcode = 0x68;
27628
27629       mem = adjust_address (m_tramp, QImode, offset);
27630       emit_move_insn (mem, gen_int_mode (opcode, QImode));
27631
27632       mem = adjust_address (m_tramp, SImode, offset + 1);
27633       emit_move_insn (mem, chain_value);
27634       offset += 5;
27635
27636       mem = adjust_address (m_tramp, QImode, offset);
27637       emit_move_insn (mem, gen_int_mode (0xe9, QImode));
27638
27639       mem = adjust_address (m_tramp, SImode, offset + 1);
27640
27641       /* Compute offset from the end of the jmp to the target function.
27642          In the case in which the trampoline stores the static chain on
27643          the stack, we need to skip the first insn which pushes the
27644          (call-saved) register static chain; this push is 1 byte.  */
27645       offset += 5;
27646       disp = expand_binop (SImode, sub_optab, fnaddr,
27647                            plus_constant (Pmode, XEXP (m_tramp, 0),
27648                                           offset - (MEM_P (chain) ? 1 : 0)),
27649                            NULL_RTX, 1, OPTAB_DIRECT);
27650       emit_move_insn (mem, disp);
27651     }
27652
27653   gcc_assert (offset <= TRAMPOLINE_SIZE);
27654
27655 #ifdef HAVE_ENABLE_EXECUTE_STACK
27656 #ifdef CHECK_EXECUTE_STACK_ENABLED
27657   if (CHECK_EXECUTE_STACK_ENABLED)
27658 #endif
27659   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
27660                      LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
27661 #endif
27662 }
27663 \f
27664 /* The following file contains several enumerations and data structures
27665    built from the definitions in i386-builtin-types.def.  */
27666
27667 #include "i386-builtin-types.inc"
27668
27669 /* Table for the ix86 builtin non-function types.  */
27670 static GTY(()) tree ix86_builtin_type_tab[(int) IX86_BT_LAST_CPTR + 1];
27671
27672 /* Retrieve an element from the above table, building some of
27673    the types lazily.  */
27674
27675 static tree
27676 ix86_get_builtin_type (enum ix86_builtin_type tcode)
27677 {
27678   unsigned int index;
27679   tree type, itype;
27680
27681   gcc_assert ((unsigned)tcode < ARRAY_SIZE(ix86_builtin_type_tab));
27682
27683   type = ix86_builtin_type_tab[(int) tcode];
27684   if (type != NULL)
27685     return type;
27686
27687   gcc_assert (tcode > IX86_BT_LAST_PRIM);
27688   if (tcode <= IX86_BT_LAST_VECT)
27689     {
27690       machine_mode mode;
27691
27692       index = tcode - IX86_BT_LAST_PRIM - 1;
27693       itype = ix86_get_builtin_type (ix86_builtin_type_vect_base[index]);
27694       mode = ix86_builtin_type_vect_mode[index];
27695
27696       type = build_vector_type_for_mode (itype, mode);
27697     }
27698   else
27699     {
27700       int quals;
27701
27702       index = tcode - IX86_BT_LAST_VECT - 1;
27703       if (tcode <= IX86_BT_LAST_PTR)
27704         quals = TYPE_UNQUALIFIED;
27705       else
27706         quals = TYPE_QUAL_CONST;
27707
27708       itype = ix86_get_builtin_type (ix86_builtin_type_ptr_base[index]);
27709       if (quals != TYPE_UNQUALIFIED)
27710         itype = build_qualified_type (itype, quals);
27711
27712       type = build_pointer_type (itype);
27713     }
27714
27715   ix86_builtin_type_tab[(int) tcode] = type;
27716   return type;
27717 }
27718
27719 /* Table for the ix86 builtin function types.  */
27720 static GTY(()) tree ix86_builtin_func_type_tab[(int) IX86_BT_LAST_ALIAS + 1];
27721
27722 /* Retrieve an element from the above table, building some of
27723    the types lazily.  */
27724
27725 static tree
27726 ix86_get_builtin_func_type (enum ix86_builtin_func_type tcode)
27727 {
27728   tree type;
27729
27730   gcc_assert ((unsigned)tcode < ARRAY_SIZE (ix86_builtin_func_type_tab));
27731
27732   type = ix86_builtin_func_type_tab[(int) tcode];
27733   if (type != NULL)
27734     return type;
27735
27736   if (tcode <= IX86_BT_LAST_FUNC)
27737     {
27738       unsigned start = ix86_builtin_func_start[(int) tcode];
27739       unsigned after = ix86_builtin_func_start[(int) tcode + 1];
27740       tree rtype, atype, args = void_list_node;
27741       unsigned i;
27742
27743       rtype = ix86_get_builtin_type (ix86_builtin_func_args[start]);
27744       for (i = after - 1; i > start; --i)
27745         {
27746           atype = ix86_get_builtin_type (ix86_builtin_func_args[i]);
27747           args = tree_cons (NULL, atype, args);
27748         }
27749
27750       type = build_function_type (rtype, args);
27751     }
27752   else
27753     {
27754       unsigned index = tcode - IX86_BT_LAST_FUNC - 1;
27755       enum ix86_builtin_func_type icode;
27756
27757       icode = ix86_builtin_func_alias_base[index];
27758       type = ix86_get_builtin_func_type (icode);
27759     }
27760
27761   ix86_builtin_func_type_tab[(int) tcode] = type;
27762   return type;
27763 }
27764
27765
27766 /* Codes for all the SSE/MMX builtins.  */
27767 enum ix86_builtins
27768 {
27769   IX86_BUILTIN_ADDPS,
27770   IX86_BUILTIN_ADDSS,
27771   IX86_BUILTIN_DIVPS,
27772   IX86_BUILTIN_DIVSS,
27773   IX86_BUILTIN_MULPS,
27774   IX86_BUILTIN_MULSS,
27775   IX86_BUILTIN_SUBPS,
27776   IX86_BUILTIN_SUBSS,
27777
27778   IX86_BUILTIN_CMPEQPS,
27779   IX86_BUILTIN_CMPLTPS,
27780   IX86_BUILTIN_CMPLEPS,
27781   IX86_BUILTIN_CMPGTPS,
27782   IX86_BUILTIN_CMPGEPS,
27783   IX86_BUILTIN_CMPNEQPS,
27784   IX86_BUILTIN_CMPNLTPS,
27785   IX86_BUILTIN_CMPNLEPS,
27786   IX86_BUILTIN_CMPNGTPS,
27787   IX86_BUILTIN_CMPNGEPS,
27788   IX86_BUILTIN_CMPORDPS,
27789   IX86_BUILTIN_CMPUNORDPS,
27790   IX86_BUILTIN_CMPEQSS,
27791   IX86_BUILTIN_CMPLTSS,
27792   IX86_BUILTIN_CMPLESS,
27793   IX86_BUILTIN_CMPNEQSS,
27794   IX86_BUILTIN_CMPNLTSS,
27795   IX86_BUILTIN_CMPNLESS,
27796   IX86_BUILTIN_CMPORDSS,
27797   IX86_BUILTIN_CMPUNORDSS,
27798
27799   IX86_BUILTIN_COMIEQSS,
27800   IX86_BUILTIN_COMILTSS,
27801   IX86_BUILTIN_COMILESS,
27802   IX86_BUILTIN_COMIGTSS,
27803   IX86_BUILTIN_COMIGESS,
27804   IX86_BUILTIN_COMINEQSS,
27805   IX86_BUILTIN_UCOMIEQSS,
27806   IX86_BUILTIN_UCOMILTSS,
27807   IX86_BUILTIN_UCOMILESS,
27808   IX86_BUILTIN_UCOMIGTSS,
27809   IX86_BUILTIN_UCOMIGESS,
27810   IX86_BUILTIN_UCOMINEQSS,
27811
27812   IX86_BUILTIN_CVTPI2PS,
27813   IX86_BUILTIN_CVTPS2PI,
27814   IX86_BUILTIN_CVTSI2SS,
27815   IX86_BUILTIN_CVTSI642SS,
27816   IX86_BUILTIN_CVTSS2SI,
27817   IX86_BUILTIN_CVTSS2SI64,
27818   IX86_BUILTIN_CVTTPS2PI,
27819   IX86_BUILTIN_CVTTSS2SI,
27820   IX86_BUILTIN_CVTTSS2SI64,
27821
27822   IX86_BUILTIN_MAXPS,
27823   IX86_BUILTIN_MAXSS,
27824   IX86_BUILTIN_MINPS,
27825   IX86_BUILTIN_MINSS,
27826
27827   IX86_BUILTIN_LOADUPS,
27828   IX86_BUILTIN_STOREUPS,
27829   IX86_BUILTIN_MOVSS,
27830
27831   IX86_BUILTIN_MOVHLPS,
27832   IX86_BUILTIN_MOVLHPS,
27833   IX86_BUILTIN_LOADHPS,
27834   IX86_BUILTIN_LOADLPS,
27835   IX86_BUILTIN_STOREHPS,
27836   IX86_BUILTIN_STORELPS,
27837
27838   IX86_BUILTIN_MASKMOVQ,
27839   IX86_BUILTIN_MOVMSKPS,
27840   IX86_BUILTIN_PMOVMSKB,
27841
27842   IX86_BUILTIN_MOVNTPS,
27843   IX86_BUILTIN_MOVNTQ,
27844
27845   IX86_BUILTIN_LOADDQU,
27846   IX86_BUILTIN_STOREDQU,
27847
27848   IX86_BUILTIN_PACKSSWB,
27849   IX86_BUILTIN_PACKSSDW,
27850   IX86_BUILTIN_PACKUSWB,
27851
27852   IX86_BUILTIN_PADDB,
27853   IX86_BUILTIN_PADDW,
27854   IX86_BUILTIN_PADDD,
27855   IX86_BUILTIN_PADDQ,
27856   IX86_BUILTIN_PADDSB,
27857   IX86_BUILTIN_PADDSW,
27858   IX86_BUILTIN_PADDUSB,
27859   IX86_BUILTIN_PADDUSW,
27860   IX86_BUILTIN_PSUBB,
27861   IX86_BUILTIN_PSUBW,
27862   IX86_BUILTIN_PSUBD,
27863   IX86_BUILTIN_PSUBQ,
27864   IX86_BUILTIN_PSUBSB,
27865   IX86_BUILTIN_PSUBSW,
27866   IX86_BUILTIN_PSUBUSB,
27867   IX86_BUILTIN_PSUBUSW,
27868
27869   IX86_BUILTIN_PAND,
27870   IX86_BUILTIN_PANDN,
27871   IX86_BUILTIN_POR,
27872   IX86_BUILTIN_PXOR,
27873
27874   IX86_BUILTIN_PAVGB,
27875   IX86_BUILTIN_PAVGW,
27876
27877   IX86_BUILTIN_PCMPEQB,
27878   IX86_BUILTIN_PCMPEQW,
27879   IX86_BUILTIN_PCMPEQD,
27880   IX86_BUILTIN_PCMPGTB,
27881   IX86_BUILTIN_PCMPGTW,
27882   IX86_BUILTIN_PCMPGTD,
27883
27884   IX86_BUILTIN_PMADDWD,
27885
27886   IX86_BUILTIN_PMAXSW,
27887   IX86_BUILTIN_PMAXUB,
27888   IX86_BUILTIN_PMINSW,
27889   IX86_BUILTIN_PMINUB,
27890
27891   IX86_BUILTIN_PMULHUW,
27892   IX86_BUILTIN_PMULHW,
27893   IX86_BUILTIN_PMULLW,
27894
27895   IX86_BUILTIN_PSADBW,
27896   IX86_BUILTIN_PSHUFW,
27897
27898   IX86_BUILTIN_PSLLW,
27899   IX86_BUILTIN_PSLLD,
27900   IX86_BUILTIN_PSLLQ,
27901   IX86_BUILTIN_PSRAW,
27902   IX86_BUILTIN_PSRAD,
27903   IX86_BUILTIN_PSRLW,
27904   IX86_BUILTIN_PSRLD,
27905   IX86_BUILTIN_PSRLQ,
27906   IX86_BUILTIN_PSLLWI,
27907   IX86_BUILTIN_PSLLDI,
27908   IX86_BUILTIN_PSLLQI,
27909   IX86_BUILTIN_PSRAWI,
27910   IX86_BUILTIN_PSRADI,
27911   IX86_BUILTIN_PSRLWI,
27912   IX86_BUILTIN_PSRLDI,
27913   IX86_BUILTIN_PSRLQI,
27914
27915   IX86_BUILTIN_PUNPCKHBW,
27916   IX86_BUILTIN_PUNPCKHWD,
27917   IX86_BUILTIN_PUNPCKHDQ,
27918   IX86_BUILTIN_PUNPCKLBW,
27919   IX86_BUILTIN_PUNPCKLWD,
27920   IX86_BUILTIN_PUNPCKLDQ,
27921
27922   IX86_BUILTIN_SHUFPS,
27923
27924   IX86_BUILTIN_RCPPS,
27925   IX86_BUILTIN_RCPSS,
27926   IX86_BUILTIN_RSQRTPS,
27927   IX86_BUILTIN_RSQRTPS_NR,
27928   IX86_BUILTIN_RSQRTSS,
27929   IX86_BUILTIN_RSQRTF,
27930   IX86_BUILTIN_SQRTPS,
27931   IX86_BUILTIN_SQRTPS_NR,
27932   IX86_BUILTIN_SQRTSS,
27933
27934   IX86_BUILTIN_UNPCKHPS,
27935   IX86_BUILTIN_UNPCKLPS,
27936
27937   IX86_BUILTIN_ANDPS,
27938   IX86_BUILTIN_ANDNPS,
27939   IX86_BUILTIN_ORPS,
27940   IX86_BUILTIN_XORPS,
27941
27942   IX86_BUILTIN_EMMS,
27943   IX86_BUILTIN_LDMXCSR,
27944   IX86_BUILTIN_STMXCSR,
27945   IX86_BUILTIN_SFENCE,
27946
27947   IX86_BUILTIN_FXSAVE,
27948   IX86_BUILTIN_FXRSTOR,
27949   IX86_BUILTIN_FXSAVE64,
27950   IX86_BUILTIN_FXRSTOR64,
27951
27952   IX86_BUILTIN_XSAVE,
27953   IX86_BUILTIN_XRSTOR,
27954   IX86_BUILTIN_XSAVE64,
27955   IX86_BUILTIN_XRSTOR64,
27956
27957   IX86_BUILTIN_XSAVEOPT,
27958   IX86_BUILTIN_XSAVEOPT64,
27959
27960   IX86_BUILTIN_XSAVEC,
27961   IX86_BUILTIN_XSAVEC64,
27962
27963   IX86_BUILTIN_XSAVES,
27964   IX86_BUILTIN_XRSTORS,
27965   IX86_BUILTIN_XSAVES64,
27966   IX86_BUILTIN_XRSTORS64,
27967
27968   /* 3DNow! Original */
27969   IX86_BUILTIN_FEMMS,
27970   IX86_BUILTIN_PAVGUSB,
27971   IX86_BUILTIN_PF2ID,
27972   IX86_BUILTIN_PFACC,
27973   IX86_BUILTIN_PFADD,
27974   IX86_BUILTIN_PFCMPEQ,
27975   IX86_BUILTIN_PFCMPGE,
27976   IX86_BUILTIN_PFCMPGT,
27977   IX86_BUILTIN_PFMAX,
27978   IX86_BUILTIN_PFMIN,
27979   IX86_BUILTIN_PFMUL,
27980   IX86_BUILTIN_PFRCP,
27981   IX86_BUILTIN_PFRCPIT1,
27982   IX86_BUILTIN_PFRCPIT2,
27983   IX86_BUILTIN_PFRSQIT1,
27984   IX86_BUILTIN_PFRSQRT,
27985   IX86_BUILTIN_PFSUB,
27986   IX86_BUILTIN_PFSUBR,
27987   IX86_BUILTIN_PI2FD,
27988   IX86_BUILTIN_PMULHRW,
27989
27990   /* 3DNow! Athlon Extensions */
27991   IX86_BUILTIN_PF2IW,
27992   IX86_BUILTIN_PFNACC,
27993   IX86_BUILTIN_PFPNACC,
27994   IX86_BUILTIN_PI2FW,
27995   IX86_BUILTIN_PSWAPDSI,
27996   IX86_BUILTIN_PSWAPDSF,
27997
27998   /* SSE2 */
27999   IX86_BUILTIN_ADDPD,
28000   IX86_BUILTIN_ADDSD,
28001   IX86_BUILTIN_DIVPD,
28002   IX86_BUILTIN_DIVSD,
28003   IX86_BUILTIN_MULPD,
28004   IX86_BUILTIN_MULSD,
28005   IX86_BUILTIN_SUBPD,
28006   IX86_BUILTIN_SUBSD,
28007
28008   IX86_BUILTIN_CMPEQPD,
28009   IX86_BUILTIN_CMPLTPD,
28010   IX86_BUILTIN_CMPLEPD,
28011   IX86_BUILTIN_CMPGTPD,
28012   IX86_BUILTIN_CMPGEPD,
28013   IX86_BUILTIN_CMPNEQPD,
28014   IX86_BUILTIN_CMPNLTPD,
28015   IX86_BUILTIN_CMPNLEPD,
28016   IX86_BUILTIN_CMPNGTPD,
28017   IX86_BUILTIN_CMPNGEPD,
28018   IX86_BUILTIN_CMPORDPD,
28019   IX86_BUILTIN_CMPUNORDPD,
28020   IX86_BUILTIN_CMPEQSD,
28021   IX86_BUILTIN_CMPLTSD,
28022   IX86_BUILTIN_CMPLESD,
28023   IX86_BUILTIN_CMPNEQSD,
28024   IX86_BUILTIN_CMPNLTSD,
28025   IX86_BUILTIN_CMPNLESD,
28026   IX86_BUILTIN_CMPORDSD,
28027   IX86_BUILTIN_CMPUNORDSD,
28028
28029   IX86_BUILTIN_COMIEQSD,
28030   IX86_BUILTIN_COMILTSD,
28031   IX86_BUILTIN_COMILESD,
28032   IX86_BUILTIN_COMIGTSD,
28033   IX86_BUILTIN_COMIGESD,
28034   IX86_BUILTIN_COMINEQSD,
28035   IX86_BUILTIN_UCOMIEQSD,
28036   IX86_BUILTIN_UCOMILTSD,
28037   IX86_BUILTIN_UCOMILESD,
28038   IX86_BUILTIN_UCOMIGTSD,
28039   IX86_BUILTIN_UCOMIGESD,
28040   IX86_BUILTIN_UCOMINEQSD,
28041
28042   IX86_BUILTIN_MAXPD,
28043   IX86_BUILTIN_MAXSD,
28044   IX86_BUILTIN_MINPD,
28045   IX86_BUILTIN_MINSD,
28046
28047   IX86_BUILTIN_ANDPD,
28048   IX86_BUILTIN_ANDNPD,
28049   IX86_BUILTIN_ORPD,
28050   IX86_BUILTIN_XORPD,
28051
28052   IX86_BUILTIN_SQRTPD,
28053   IX86_BUILTIN_SQRTSD,
28054
28055   IX86_BUILTIN_UNPCKHPD,
28056   IX86_BUILTIN_UNPCKLPD,
28057
28058   IX86_BUILTIN_SHUFPD,
28059
28060   IX86_BUILTIN_LOADUPD,
28061   IX86_BUILTIN_STOREUPD,
28062   IX86_BUILTIN_MOVSD,
28063
28064   IX86_BUILTIN_LOADHPD,
28065   IX86_BUILTIN_LOADLPD,
28066
28067   IX86_BUILTIN_CVTDQ2PD,
28068   IX86_BUILTIN_CVTDQ2PS,
28069
28070   IX86_BUILTIN_CVTPD2DQ,
28071   IX86_BUILTIN_CVTPD2PI,
28072   IX86_BUILTIN_CVTPD2PS,
28073   IX86_BUILTIN_CVTTPD2DQ,
28074   IX86_BUILTIN_CVTTPD2PI,
28075
28076   IX86_BUILTIN_CVTPI2PD,
28077   IX86_BUILTIN_CVTSI2SD,
28078   IX86_BUILTIN_CVTSI642SD,
28079
28080   IX86_BUILTIN_CVTSD2SI,
28081   IX86_BUILTIN_CVTSD2SI64,
28082   IX86_BUILTIN_CVTSD2SS,
28083   IX86_BUILTIN_CVTSS2SD,
28084   IX86_BUILTIN_CVTTSD2SI,
28085   IX86_BUILTIN_CVTTSD2SI64,
28086
28087   IX86_BUILTIN_CVTPS2DQ,
28088   IX86_BUILTIN_CVTPS2PD,
28089   IX86_BUILTIN_CVTTPS2DQ,
28090
28091   IX86_BUILTIN_MOVNTI,
28092   IX86_BUILTIN_MOVNTI64,
28093   IX86_BUILTIN_MOVNTPD,
28094   IX86_BUILTIN_MOVNTDQ,
28095
28096   IX86_BUILTIN_MOVQ128,
28097
28098   /* SSE2 MMX */
28099   IX86_BUILTIN_MASKMOVDQU,
28100   IX86_BUILTIN_MOVMSKPD,
28101   IX86_BUILTIN_PMOVMSKB128,
28102
28103   IX86_BUILTIN_PACKSSWB128,
28104   IX86_BUILTIN_PACKSSDW128,
28105   IX86_BUILTIN_PACKUSWB128,
28106
28107   IX86_BUILTIN_PADDB128,
28108   IX86_BUILTIN_PADDW128,
28109   IX86_BUILTIN_PADDD128,
28110   IX86_BUILTIN_PADDQ128,
28111   IX86_BUILTIN_PADDSB128,
28112   IX86_BUILTIN_PADDSW128,
28113   IX86_BUILTIN_PADDUSB128,
28114   IX86_BUILTIN_PADDUSW128,
28115   IX86_BUILTIN_PSUBB128,
28116   IX86_BUILTIN_PSUBW128,
28117   IX86_BUILTIN_PSUBD128,
28118   IX86_BUILTIN_PSUBQ128,
28119   IX86_BUILTIN_PSUBSB128,
28120   IX86_BUILTIN_PSUBSW128,
28121   IX86_BUILTIN_PSUBUSB128,
28122   IX86_BUILTIN_PSUBUSW128,
28123
28124   IX86_BUILTIN_PAND128,
28125   IX86_BUILTIN_PANDN128,
28126   IX86_BUILTIN_POR128,
28127   IX86_BUILTIN_PXOR128,
28128
28129   IX86_BUILTIN_PAVGB128,
28130   IX86_BUILTIN_PAVGW128,
28131
28132   IX86_BUILTIN_PCMPEQB128,
28133   IX86_BUILTIN_PCMPEQW128,
28134   IX86_BUILTIN_PCMPEQD128,
28135   IX86_BUILTIN_PCMPGTB128,
28136   IX86_BUILTIN_PCMPGTW128,
28137   IX86_BUILTIN_PCMPGTD128,
28138
28139   IX86_BUILTIN_PMADDWD128,
28140
28141   IX86_BUILTIN_PMAXSW128,
28142   IX86_BUILTIN_PMAXUB128,
28143   IX86_BUILTIN_PMINSW128,
28144   IX86_BUILTIN_PMINUB128,
28145
28146   IX86_BUILTIN_PMULUDQ,
28147   IX86_BUILTIN_PMULUDQ128,
28148   IX86_BUILTIN_PMULHUW128,
28149   IX86_BUILTIN_PMULHW128,
28150   IX86_BUILTIN_PMULLW128,
28151
28152   IX86_BUILTIN_PSADBW128,
28153   IX86_BUILTIN_PSHUFHW,
28154   IX86_BUILTIN_PSHUFLW,
28155   IX86_BUILTIN_PSHUFD,
28156
28157   IX86_BUILTIN_PSLLDQI128,
28158   IX86_BUILTIN_PSLLWI128,
28159   IX86_BUILTIN_PSLLDI128,
28160   IX86_BUILTIN_PSLLQI128,
28161   IX86_BUILTIN_PSRAWI128,
28162   IX86_BUILTIN_PSRADI128,
28163   IX86_BUILTIN_PSRLDQI128,
28164   IX86_BUILTIN_PSRLWI128,
28165   IX86_BUILTIN_PSRLDI128,
28166   IX86_BUILTIN_PSRLQI128,
28167
28168   IX86_BUILTIN_PSLLDQ128,
28169   IX86_BUILTIN_PSLLW128,
28170   IX86_BUILTIN_PSLLD128,
28171   IX86_BUILTIN_PSLLQ128,
28172   IX86_BUILTIN_PSRAW128,
28173   IX86_BUILTIN_PSRAD128,
28174   IX86_BUILTIN_PSRLW128,
28175   IX86_BUILTIN_PSRLD128,
28176   IX86_BUILTIN_PSRLQ128,
28177
28178   IX86_BUILTIN_PUNPCKHBW128,
28179   IX86_BUILTIN_PUNPCKHWD128,
28180   IX86_BUILTIN_PUNPCKHDQ128,
28181   IX86_BUILTIN_PUNPCKHQDQ128,
28182   IX86_BUILTIN_PUNPCKLBW128,
28183   IX86_BUILTIN_PUNPCKLWD128,
28184   IX86_BUILTIN_PUNPCKLDQ128,
28185   IX86_BUILTIN_PUNPCKLQDQ128,
28186
28187   IX86_BUILTIN_CLFLUSH,
28188   IX86_BUILTIN_MFENCE,
28189   IX86_BUILTIN_LFENCE,
28190   IX86_BUILTIN_PAUSE,
28191
28192   IX86_BUILTIN_FNSTENV,
28193   IX86_BUILTIN_FLDENV,
28194   IX86_BUILTIN_FNSTSW,
28195   IX86_BUILTIN_FNCLEX,
28196
28197   IX86_BUILTIN_BSRSI,
28198   IX86_BUILTIN_BSRDI,
28199   IX86_BUILTIN_RDPMC,
28200   IX86_BUILTIN_RDTSC,
28201   IX86_BUILTIN_RDTSCP,
28202   IX86_BUILTIN_ROLQI,
28203   IX86_BUILTIN_ROLHI,
28204   IX86_BUILTIN_RORQI,
28205   IX86_BUILTIN_RORHI,
28206
28207   /* SSE3.  */
28208   IX86_BUILTIN_ADDSUBPS,
28209   IX86_BUILTIN_HADDPS,
28210   IX86_BUILTIN_HSUBPS,
28211   IX86_BUILTIN_MOVSHDUP,
28212   IX86_BUILTIN_MOVSLDUP,
28213   IX86_BUILTIN_ADDSUBPD,
28214   IX86_BUILTIN_HADDPD,
28215   IX86_BUILTIN_HSUBPD,
28216   IX86_BUILTIN_LDDQU,
28217
28218   IX86_BUILTIN_MONITOR,
28219   IX86_BUILTIN_MWAIT,
28220
28221   /* SSSE3.  */
28222   IX86_BUILTIN_PHADDW,
28223   IX86_BUILTIN_PHADDD,
28224   IX86_BUILTIN_PHADDSW,
28225   IX86_BUILTIN_PHSUBW,
28226   IX86_BUILTIN_PHSUBD,
28227   IX86_BUILTIN_PHSUBSW,
28228   IX86_BUILTIN_PMADDUBSW,
28229   IX86_BUILTIN_PMULHRSW,
28230   IX86_BUILTIN_PSHUFB,
28231   IX86_BUILTIN_PSIGNB,
28232   IX86_BUILTIN_PSIGNW,
28233   IX86_BUILTIN_PSIGND,
28234   IX86_BUILTIN_PALIGNR,
28235   IX86_BUILTIN_PABSB,
28236   IX86_BUILTIN_PABSW,
28237   IX86_BUILTIN_PABSD,
28238
28239   IX86_BUILTIN_PHADDW128,
28240   IX86_BUILTIN_PHADDD128,
28241   IX86_BUILTIN_PHADDSW128,
28242   IX86_BUILTIN_PHSUBW128,
28243   IX86_BUILTIN_PHSUBD128,
28244   IX86_BUILTIN_PHSUBSW128,
28245   IX86_BUILTIN_PMADDUBSW128,
28246   IX86_BUILTIN_PMULHRSW128,
28247   IX86_BUILTIN_PSHUFB128,
28248   IX86_BUILTIN_PSIGNB128,
28249   IX86_BUILTIN_PSIGNW128,
28250   IX86_BUILTIN_PSIGND128,
28251   IX86_BUILTIN_PALIGNR128,
28252   IX86_BUILTIN_PABSB128,
28253   IX86_BUILTIN_PABSW128,
28254   IX86_BUILTIN_PABSD128,
28255
28256   /* AMDFAM10 - SSE4A New Instructions.  */
28257   IX86_BUILTIN_MOVNTSD,
28258   IX86_BUILTIN_MOVNTSS,
28259   IX86_BUILTIN_EXTRQI,
28260   IX86_BUILTIN_EXTRQ,
28261   IX86_BUILTIN_INSERTQI,
28262   IX86_BUILTIN_INSERTQ,
28263
28264   /* SSE4.1.  */
28265   IX86_BUILTIN_BLENDPD,
28266   IX86_BUILTIN_BLENDPS,
28267   IX86_BUILTIN_BLENDVPD,
28268   IX86_BUILTIN_BLENDVPS,
28269   IX86_BUILTIN_PBLENDVB128,
28270   IX86_BUILTIN_PBLENDW128,
28271
28272   IX86_BUILTIN_DPPD,
28273   IX86_BUILTIN_DPPS,
28274
28275   IX86_BUILTIN_INSERTPS128,
28276
28277   IX86_BUILTIN_MOVNTDQA,
28278   IX86_BUILTIN_MPSADBW128,
28279   IX86_BUILTIN_PACKUSDW128,
28280   IX86_BUILTIN_PCMPEQQ,
28281   IX86_BUILTIN_PHMINPOSUW128,
28282
28283   IX86_BUILTIN_PMAXSB128,
28284   IX86_BUILTIN_PMAXSD128,
28285   IX86_BUILTIN_PMAXUD128,
28286   IX86_BUILTIN_PMAXUW128,
28287
28288   IX86_BUILTIN_PMINSB128,
28289   IX86_BUILTIN_PMINSD128,
28290   IX86_BUILTIN_PMINUD128,
28291   IX86_BUILTIN_PMINUW128,
28292
28293   IX86_BUILTIN_PMOVSXBW128,
28294   IX86_BUILTIN_PMOVSXBD128,
28295   IX86_BUILTIN_PMOVSXBQ128,
28296   IX86_BUILTIN_PMOVSXWD128,
28297   IX86_BUILTIN_PMOVSXWQ128,
28298   IX86_BUILTIN_PMOVSXDQ128,
28299
28300   IX86_BUILTIN_PMOVZXBW128,
28301   IX86_BUILTIN_PMOVZXBD128,
28302   IX86_BUILTIN_PMOVZXBQ128,
28303   IX86_BUILTIN_PMOVZXWD128,
28304   IX86_BUILTIN_PMOVZXWQ128,
28305   IX86_BUILTIN_PMOVZXDQ128,
28306
28307   IX86_BUILTIN_PMULDQ128,
28308   IX86_BUILTIN_PMULLD128,
28309
28310   IX86_BUILTIN_ROUNDSD,
28311   IX86_BUILTIN_ROUNDSS,
28312
28313   IX86_BUILTIN_ROUNDPD,
28314   IX86_BUILTIN_ROUNDPS,
28315
28316   IX86_BUILTIN_FLOORPD,
28317   IX86_BUILTIN_CEILPD,
28318   IX86_BUILTIN_TRUNCPD,
28319   IX86_BUILTIN_RINTPD,
28320   IX86_BUILTIN_ROUNDPD_AZ,
28321
28322   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX,
28323   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX,
28324   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX,
28325
28326   IX86_BUILTIN_FLOORPS,
28327   IX86_BUILTIN_CEILPS,
28328   IX86_BUILTIN_TRUNCPS,
28329   IX86_BUILTIN_RINTPS,
28330   IX86_BUILTIN_ROUNDPS_AZ,
28331
28332   IX86_BUILTIN_FLOORPS_SFIX,
28333   IX86_BUILTIN_CEILPS_SFIX,
28334   IX86_BUILTIN_ROUNDPS_AZ_SFIX,
28335
28336   IX86_BUILTIN_PTESTZ,
28337   IX86_BUILTIN_PTESTC,
28338   IX86_BUILTIN_PTESTNZC,
28339
28340   IX86_BUILTIN_VEC_INIT_V2SI,
28341   IX86_BUILTIN_VEC_INIT_V4HI,
28342   IX86_BUILTIN_VEC_INIT_V8QI,
28343   IX86_BUILTIN_VEC_EXT_V2DF,
28344   IX86_BUILTIN_VEC_EXT_V2DI,
28345   IX86_BUILTIN_VEC_EXT_V4SF,
28346   IX86_BUILTIN_VEC_EXT_V4SI,
28347   IX86_BUILTIN_VEC_EXT_V8HI,
28348   IX86_BUILTIN_VEC_EXT_V2SI,
28349   IX86_BUILTIN_VEC_EXT_V4HI,
28350   IX86_BUILTIN_VEC_EXT_V16QI,
28351   IX86_BUILTIN_VEC_SET_V2DI,
28352   IX86_BUILTIN_VEC_SET_V4SF,
28353   IX86_BUILTIN_VEC_SET_V4SI,
28354   IX86_BUILTIN_VEC_SET_V8HI,
28355   IX86_BUILTIN_VEC_SET_V4HI,
28356   IX86_BUILTIN_VEC_SET_V16QI,
28357
28358   IX86_BUILTIN_VEC_PACK_SFIX,
28359   IX86_BUILTIN_VEC_PACK_SFIX256,
28360
28361   /* SSE4.2.  */
28362   IX86_BUILTIN_CRC32QI,
28363   IX86_BUILTIN_CRC32HI,
28364   IX86_BUILTIN_CRC32SI,
28365   IX86_BUILTIN_CRC32DI,
28366
28367   IX86_BUILTIN_PCMPESTRI128,
28368   IX86_BUILTIN_PCMPESTRM128,
28369   IX86_BUILTIN_PCMPESTRA128,
28370   IX86_BUILTIN_PCMPESTRC128,
28371   IX86_BUILTIN_PCMPESTRO128,
28372   IX86_BUILTIN_PCMPESTRS128,
28373   IX86_BUILTIN_PCMPESTRZ128,
28374   IX86_BUILTIN_PCMPISTRI128,
28375   IX86_BUILTIN_PCMPISTRM128,
28376   IX86_BUILTIN_PCMPISTRA128,
28377   IX86_BUILTIN_PCMPISTRC128,
28378   IX86_BUILTIN_PCMPISTRO128,
28379   IX86_BUILTIN_PCMPISTRS128,
28380   IX86_BUILTIN_PCMPISTRZ128,
28381
28382   IX86_BUILTIN_PCMPGTQ,
28383
28384   /* AES instructions */
28385   IX86_BUILTIN_AESENC128,
28386   IX86_BUILTIN_AESENCLAST128,
28387   IX86_BUILTIN_AESDEC128,
28388   IX86_BUILTIN_AESDECLAST128,
28389   IX86_BUILTIN_AESIMC128,
28390   IX86_BUILTIN_AESKEYGENASSIST128,
28391
28392   /* PCLMUL instruction */
28393   IX86_BUILTIN_PCLMULQDQ128,
28394
28395   /* AVX */
28396   IX86_BUILTIN_ADDPD256,
28397   IX86_BUILTIN_ADDPS256,
28398   IX86_BUILTIN_ADDSUBPD256,
28399   IX86_BUILTIN_ADDSUBPS256,
28400   IX86_BUILTIN_ANDPD256,
28401   IX86_BUILTIN_ANDPS256,
28402   IX86_BUILTIN_ANDNPD256,
28403   IX86_BUILTIN_ANDNPS256,
28404   IX86_BUILTIN_BLENDPD256,
28405   IX86_BUILTIN_BLENDPS256,
28406   IX86_BUILTIN_BLENDVPD256,
28407   IX86_BUILTIN_BLENDVPS256,
28408   IX86_BUILTIN_DIVPD256,
28409   IX86_BUILTIN_DIVPS256,
28410   IX86_BUILTIN_DPPS256,
28411   IX86_BUILTIN_HADDPD256,
28412   IX86_BUILTIN_HADDPS256,
28413   IX86_BUILTIN_HSUBPD256,
28414   IX86_BUILTIN_HSUBPS256,
28415   IX86_BUILTIN_MAXPD256,
28416   IX86_BUILTIN_MAXPS256,
28417   IX86_BUILTIN_MINPD256,
28418   IX86_BUILTIN_MINPS256,
28419   IX86_BUILTIN_MULPD256,
28420   IX86_BUILTIN_MULPS256,
28421   IX86_BUILTIN_ORPD256,
28422   IX86_BUILTIN_ORPS256,
28423   IX86_BUILTIN_SHUFPD256,
28424   IX86_BUILTIN_SHUFPS256,
28425   IX86_BUILTIN_SUBPD256,
28426   IX86_BUILTIN_SUBPS256,
28427   IX86_BUILTIN_XORPD256,
28428   IX86_BUILTIN_XORPS256,
28429   IX86_BUILTIN_CMPSD,
28430   IX86_BUILTIN_CMPSS,
28431   IX86_BUILTIN_CMPPD,
28432   IX86_BUILTIN_CMPPS,
28433   IX86_BUILTIN_CMPPD256,
28434   IX86_BUILTIN_CMPPS256,
28435   IX86_BUILTIN_CVTDQ2PD256,
28436   IX86_BUILTIN_CVTDQ2PS256,
28437   IX86_BUILTIN_CVTPD2PS256,
28438   IX86_BUILTIN_CVTPS2DQ256,
28439   IX86_BUILTIN_CVTPS2PD256,
28440   IX86_BUILTIN_CVTTPD2DQ256,
28441   IX86_BUILTIN_CVTPD2DQ256,
28442   IX86_BUILTIN_CVTTPS2DQ256,
28443   IX86_BUILTIN_EXTRACTF128PD256,
28444   IX86_BUILTIN_EXTRACTF128PS256,
28445   IX86_BUILTIN_EXTRACTF128SI256,
28446   IX86_BUILTIN_VZEROALL,
28447   IX86_BUILTIN_VZEROUPPER,
28448   IX86_BUILTIN_VPERMILVARPD,
28449   IX86_BUILTIN_VPERMILVARPS,
28450   IX86_BUILTIN_VPERMILVARPD256,
28451   IX86_BUILTIN_VPERMILVARPS256,
28452   IX86_BUILTIN_VPERMILPD,
28453   IX86_BUILTIN_VPERMILPS,
28454   IX86_BUILTIN_VPERMILPD256,
28455   IX86_BUILTIN_VPERMILPS256,
28456   IX86_BUILTIN_VPERMIL2PD,
28457   IX86_BUILTIN_VPERMIL2PS,
28458   IX86_BUILTIN_VPERMIL2PD256,
28459   IX86_BUILTIN_VPERMIL2PS256,
28460   IX86_BUILTIN_VPERM2F128PD256,
28461   IX86_BUILTIN_VPERM2F128PS256,
28462   IX86_BUILTIN_VPERM2F128SI256,
28463   IX86_BUILTIN_VBROADCASTSS,
28464   IX86_BUILTIN_VBROADCASTSD256,
28465   IX86_BUILTIN_VBROADCASTSS256,
28466   IX86_BUILTIN_VBROADCASTPD256,
28467   IX86_BUILTIN_VBROADCASTPS256,
28468   IX86_BUILTIN_VINSERTF128PD256,
28469   IX86_BUILTIN_VINSERTF128PS256,
28470   IX86_BUILTIN_VINSERTF128SI256,
28471   IX86_BUILTIN_LOADUPD256,
28472   IX86_BUILTIN_LOADUPS256,
28473   IX86_BUILTIN_STOREUPD256,
28474   IX86_BUILTIN_STOREUPS256,
28475   IX86_BUILTIN_LDDQU256,
28476   IX86_BUILTIN_MOVNTDQ256,
28477   IX86_BUILTIN_MOVNTPD256,
28478   IX86_BUILTIN_MOVNTPS256,
28479   IX86_BUILTIN_LOADDQU256,
28480   IX86_BUILTIN_STOREDQU256,
28481   IX86_BUILTIN_MASKLOADPD,
28482   IX86_BUILTIN_MASKLOADPS,
28483   IX86_BUILTIN_MASKSTOREPD,
28484   IX86_BUILTIN_MASKSTOREPS,
28485   IX86_BUILTIN_MASKLOADPD256,
28486   IX86_BUILTIN_MASKLOADPS256,
28487   IX86_BUILTIN_MASKSTOREPD256,
28488   IX86_BUILTIN_MASKSTOREPS256,
28489   IX86_BUILTIN_MOVSHDUP256,
28490   IX86_BUILTIN_MOVSLDUP256,
28491   IX86_BUILTIN_MOVDDUP256,
28492
28493   IX86_BUILTIN_SQRTPD256,
28494   IX86_BUILTIN_SQRTPS256,
28495   IX86_BUILTIN_SQRTPS_NR256,
28496   IX86_BUILTIN_RSQRTPS256,
28497   IX86_BUILTIN_RSQRTPS_NR256,
28498
28499   IX86_BUILTIN_RCPPS256,
28500
28501   IX86_BUILTIN_ROUNDPD256,
28502   IX86_BUILTIN_ROUNDPS256,
28503
28504   IX86_BUILTIN_FLOORPD256,
28505   IX86_BUILTIN_CEILPD256,
28506   IX86_BUILTIN_TRUNCPD256,
28507   IX86_BUILTIN_RINTPD256,
28508   IX86_BUILTIN_ROUNDPD_AZ256,
28509
28510   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256,
28511   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256,
28512   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256,
28513
28514   IX86_BUILTIN_FLOORPS256,
28515   IX86_BUILTIN_CEILPS256,
28516   IX86_BUILTIN_TRUNCPS256,
28517   IX86_BUILTIN_RINTPS256,
28518   IX86_BUILTIN_ROUNDPS_AZ256,
28519
28520   IX86_BUILTIN_FLOORPS_SFIX256,
28521   IX86_BUILTIN_CEILPS_SFIX256,
28522   IX86_BUILTIN_ROUNDPS_AZ_SFIX256,
28523
28524   IX86_BUILTIN_UNPCKHPD256,
28525   IX86_BUILTIN_UNPCKLPD256,
28526   IX86_BUILTIN_UNPCKHPS256,
28527   IX86_BUILTIN_UNPCKLPS256,
28528
28529   IX86_BUILTIN_SI256_SI,
28530   IX86_BUILTIN_PS256_PS,
28531   IX86_BUILTIN_PD256_PD,
28532   IX86_BUILTIN_SI_SI256,
28533   IX86_BUILTIN_PS_PS256,
28534   IX86_BUILTIN_PD_PD256,
28535
28536   IX86_BUILTIN_VTESTZPD,
28537   IX86_BUILTIN_VTESTCPD,
28538   IX86_BUILTIN_VTESTNZCPD,
28539   IX86_BUILTIN_VTESTZPS,
28540   IX86_BUILTIN_VTESTCPS,
28541   IX86_BUILTIN_VTESTNZCPS,
28542   IX86_BUILTIN_VTESTZPD256,
28543   IX86_BUILTIN_VTESTCPD256,
28544   IX86_BUILTIN_VTESTNZCPD256,
28545   IX86_BUILTIN_VTESTZPS256,
28546   IX86_BUILTIN_VTESTCPS256,
28547   IX86_BUILTIN_VTESTNZCPS256,
28548   IX86_BUILTIN_PTESTZ256,
28549   IX86_BUILTIN_PTESTC256,
28550   IX86_BUILTIN_PTESTNZC256,
28551
28552   IX86_BUILTIN_MOVMSKPD256,
28553   IX86_BUILTIN_MOVMSKPS256,
28554
28555   /* AVX2 */
28556   IX86_BUILTIN_MPSADBW256,
28557   IX86_BUILTIN_PABSB256,
28558   IX86_BUILTIN_PABSW256,
28559   IX86_BUILTIN_PABSD256,
28560   IX86_BUILTIN_PACKSSDW256,
28561   IX86_BUILTIN_PACKSSWB256,
28562   IX86_BUILTIN_PACKUSDW256,
28563   IX86_BUILTIN_PACKUSWB256,
28564   IX86_BUILTIN_PADDB256,
28565   IX86_BUILTIN_PADDW256,
28566   IX86_BUILTIN_PADDD256,
28567   IX86_BUILTIN_PADDQ256,
28568   IX86_BUILTIN_PADDSB256,
28569   IX86_BUILTIN_PADDSW256,
28570   IX86_BUILTIN_PADDUSB256,
28571   IX86_BUILTIN_PADDUSW256,
28572   IX86_BUILTIN_PALIGNR256,
28573   IX86_BUILTIN_AND256I,
28574   IX86_BUILTIN_ANDNOT256I,
28575   IX86_BUILTIN_PAVGB256,
28576   IX86_BUILTIN_PAVGW256,
28577   IX86_BUILTIN_PBLENDVB256,
28578   IX86_BUILTIN_PBLENDVW256,
28579   IX86_BUILTIN_PCMPEQB256,
28580   IX86_BUILTIN_PCMPEQW256,
28581   IX86_BUILTIN_PCMPEQD256,
28582   IX86_BUILTIN_PCMPEQQ256,
28583   IX86_BUILTIN_PCMPGTB256,
28584   IX86_BUILTIN_PCMPGTW256,
28585   IX86_BUILTIN_PCMPGTD256,
28586   IX86_BUILTIN_PCMPGTQ256,
28587   IX86_BUILTIN_PHADDW256,
28588   IX86_BUILTIN_PHADDD256,
28589   IX86_BUILTIN_PHADDSW256,
28590   IX86_BUILTIN_PHSUBW256,
28591   IX86_BUILTIN_PHSUBD256,
28592   IX86_BUILTIN_PHSUBSW256,
28593   IX86_BUILTIN_PMADDUBSW256,
28594   IX86_BUILTIN_PMADDWD256,
28595   IX86_BUILTIN_PMAXSB256,
28596   IX86_BUILTIN_PMAXSW256,
28597   IX86_BUILTIN_PMAXSD256,
28598   IX86_BUILTIN_PMAXUB256,
28599   IX86_BUILTIN_PMAXUW256,
28600   IX86_BUILTIN_PMAXUD256,
28601   IX86_BUILTIN_PMINSB256,
28602   IX86_BUILTIN_PMINSW256,
28603   IX86_BUILTIN_PMINSD256,
28604   IX86_BUILTIN_PMINUB256,
28605   IX86_BUILTIN_PMINUW256,
28606   IX86_BUILTIN_PMINUD256,
28607   IX86_BUILTIN_PMOVMSKB256,
28608   IX86_BUILTIN_PMOVSXBW256,
28609   IX86_BUILTIN_PMOVSXBD256,
28610   IX86_BUILTIN_PMOVSXBQ256,
28611   IX86_BUILTIN_PMOVSXWD256,
28612   IX86_BUILTIN_PMOVSXWQ256,
28613   IX86_BUILTIN_PMOVSXDQ256,
28614   IX86_BUILTIN_PMOVZXBW256,
28615   IX86_BUILTIN_PMOVZXBD256,
28616   IX86_BUILTIN_PMOVZXBQ256,
28617   IX86_BUILTIN_PMOVZXWD256,
28618   IX86_BUILTIN_PMOVZXWQ256,
28619   IX86_BUILTIN_PMOVZXDQ256,
28620   IX86_BUILTIN_PMULDQ256,
28621   IX86_BUILTIN_PMULHRSW256,
28622   IX86_BUILTIN_PMULHUW256,
28623   IX86_BUILTIN_PMULHW256,
28624   IX86_BUILTIN_PMULLW256,
28625   IX86_BUILTIN_PMULLD256,
28626   IX86_BUILTIN_PMULUDQ256,
28627   IX86_BUILTIN_POR256,
28628   IX86_BUILTIN_PSADBW256,
28629   IX86_BUILTIN_PSHUFB256,
28630   IX86_BUILTIN_PSHUFD256,
28631   IX86_BUILTIN_PSHUFHW256,
28632   IX86_BUILTIN_PSHUFLW256,
28633   IX86_BUILTIN_PSIGNB256,
28634   IX86_BUILTIN_PSIGNW256,
28635   IX86_BUILTIN_PSIGND256,
28636   IX86_BUILTIN_PSLLDQI256,
28637   IX86_BUILTIN_PSLLWI256,
28638   IX86_BUILTIN_PSLLW256,
28639   IX86_BUILTIN_PSLLDI256,
28640   IX86_BUILTIN_PSLLD256,
28641   IX86_BUILTIN_PSLLQI256,
28642   IX86_BUILTIN_PSLLQ256,
28643   IX86_BUILTIN_PSRAWI256,
28644   IX86_BUILTIN_PSRAW256,
28645   IX86_BUILTIN_PSRADI256,
28646   IX86_BUILTIN_PSRAD256,
28647   IX86_BUILTIN_PSRLDQI256,
28648   IX86_BUILTIN_PSRLWI256,
28649   IX86_BUILTIN_PSRLW256,
28650   IX86_BUILTIN_PSRLDI256,
28651   IX86_BUILTIN_PSRLD256,
28652   IX86_BUILTIN_PSRLQI256,
28653   IX86_BUILTIN_PSRLQ256,
28654   IX86_BUILTIN_PSUBB256,
28655   IX86_BUILTIN_PSUBW256,
28656   IX86_BUILTIN_PSUBD256,
28657   IX86_BUILTIN_PSUBQ256,
28658   IX86_BUILTIN_PSUBSB256,
28659   IX86_BUILTIN_PSUBSW256,
28660   IX86_BUILTIN_PSUBUSB256,
28661   IX86_BUILTIN_PSUBUSW256,
28662   IX86_BUILTIN_PUNPCKHBW256,
28663   IX86_BUILTIN_PUNPCKHWD256,
28664   IX86_BUILTIN_PUNPCKHDQ256,
28665   IX86_BUILTIN_PUNPCKHQDQ256,
28666   IX86_BUILTIN_PUNPCKLBW256,
28667   IX86_BUILTIN_PUNPCKLWD256,
28668   IX86_BUILTIN_PUNPCKLDQ256,
28669   IX86_BUILTIN_PUNPCKLQDQ256,
28670   IX86_BUILTIN_PXOR256,
28671   IX86_BUILTIN_MOVNTDQA256,
28672   IX86_BUILTIN_VBROADCASTSS_PS,
28673   IX86_BUILTIN_VBROADCASTSS_PS256,
28674   IX86_BUILTIN_VBROADCASTSD_PD256,
28675   IX86_BUILTIN_VBROADCASTSI256,
28676   IX86_BUILTIN_PBLENDD256,
28677   IX86_BUILTIN_PBLENDD128,
28678   IX86_BUILTIN_PBROADCASTB256,
28679   IX86_BUILTIN_PBROADCASTW256,
28680   IX86_BUILTIN_PBROADCASTD256,
28681   IX86_BUILTIN_PBROADCASTQ256,
28682   IX86_BUILTIN_PBROADCASTB128,
28683   IX86_BUILTIN_PBROADCASTW128,
28684   IX86_BUILTIN_PBROADCASTD128,
28685   IX86_BUILTIN_PBROADCASTQ128,
28686   IX86_BUILTIN_VPERMVARSI256,
28687   IX86_BUILTIN_VPERMDF256,
28688   IX86_BUILTIN_VPERMVARSF256,
28689   IX86_BUILTIN_VPERMDI256,
28690   IX86_BUILTIN_VPERMTI256,
28691   IX86_BUILTIN_VEXTRACT128I256,
28692   IX86_BUILTIN_VINSERT128I256,
28693   IX86_BUILTIN_MASKLOADD,
28694   IX86_BUILTIN_MASKLOADQ,
28695   IX86_BUILTIN_MASKLOADD256,
28696   IX86_BUILTIN_MASKLOADQ256,
28697   IX86_BUILTIN_MASKSTORED,
28698   IX86_BUILTIN_MASKSTOREQ,
28699   IX86_BUILTIN_MASKSTORED256,
28700   IX86_BUILTIN_MASKSTOREQ256,
28701   IX86_BUILTIN_PSLLVV4DI,
28702   IX86_BUILTIN_PSLLVV2DI,
28703   IX86_BUILTIN_PSLLVV8SI,
28704   IX86_BUILTIN_PSLLVV4SI,
28705   IX86_BUILTIN_PSRAVV8SI,
28706   IX86_BUILTIN_PSRAVV4SI,
28707   IX86_BUILTIN_PSRLVV4DI,
28708   IX86_BUILTIN_PSRLVV2DI,
28709   IX86_BUILTIN_PSRLVV8SI,
28710   IX86_BUILTIN_PSRLVV4SI,
28711
28712   IX86_BUILTIN_GATHERSIV2DF,
28713   IX86_BUILTIN_GATHERSIV4DF,
28714   IX86_BUILTIN_GATHERDIV2DF,
28715   IX86_BUILTIN_GATHERDIV4DF,
28716   IX86_BUILTIN_GATHERSIV4SF,
28717   IX86_BUILTIN_GATHERSIV8SF,
28718   IX86_BUILTIN_GATHERDIV4SF,
28719   IX86_BUILTIN_GATHERDIV8SF,
28720   IX86_BUILTIN_GATHERSIV2DI,
28721   IX86_BUILTIN_GATHERSIV4DI,
28722   IX86_BUILTIN_GATHERDIV2DI,
28723   IX86_BUILTIN_GATHERDIV4DI,
28724   IX86_BUILTIN_GATHERSIV4SI,
28725   IX86_BUILTIN_GATHERSIV8SI,
28726   IX86_BUILTIN_GATHERDIV4SI,
28727   IX86_BUILTIN_GATHERDIV8SI,
28728
28729   /* AVX512F */
28730   IX86_BUILTIN_SI512_SI256,
28731   IX86_BUILTIN_PD512_PD256,
28732   IX86_BUILTIN_PS512_PS256,
28733   IX86_BUILTIN_SI512_SI,
28734   IX86_BUILTIN_PD512_PD,
28735   IX86_BUILTIN_PS512_PS,
28736   IX86_BUILTIN_ADDPD512,
28737   IX86_BUILTIN_ADDPS512,
28738   IX86_BUILTIN_ADDSD_ROUND,
28739   IX86_BUILTIN_ADDSS_ROUND,
28740   IX86_BUILTIN_ALIGND512,
28741   IX86_BUILTIN_ALIGNQ512,
28742   IX86_BUILTIN_BLENDMD512,
28743   IX86_BUILTIN_BLENDMPD512,
28744   IX86_BUILTIN_BLENDMPS512,
28745   IX86_BUILTIN_BLENDMQ512,
28746   IX86_BUILTIN_BROADCASTF32X4_512,
28747   IX86_BUILTIN_BROADCASTF64X4_512,
28748   IX86_BUILTIN_BROADCASTI32X4_512,
28749   IX86_BUILTIN_BROADCASTI64X4_512,
28750   IX86_BUILTIN_BROADCASTSD512,
28751   IX86_BUILTIN_BROADCASTSS512,
28752   IX86_BUILTIN_CMPD512,
28753   IX86_BUILTIN_CMPPD512,
28754   IX86_BUILTIN_CMPPS512,
28755   IX86_BUILTIN_CMPQ512,
28756   IX86_BUILTIN_CMPSD_MASK,
28757   IX86_BUILTIN_CMPSS_MASK,
28758   IX86_BUILTIN_COMIDF,
28759   IX86_BUILTIN_COMISF,
28760   IX86_BUILTIN_COMPRESSPD512,
28761   IX86_BUILTIN_COMPRESSPDSTORE512,
28762   IX86_BUILTIN_COMPRESSPS512,
28763   IX86_BUILTIN_COMPRESSPSSTORE512,
28764   IX86_BUILTIN_CVTDQ2PD512,
28765   IX86_BUILTIN_CVTDQ2PS512,
28766   IX86_BUILTIN_CVTPD2DQ512,
28767   IX86_BUILTIN_CVTPD2PS512,
28768   IX86_BUILTIN_CVTPD2UDQ512,
28769   IX86_BUILTIN_CVTPH2PS512,
28770   IX86_BUILTIN_CVTPS2DQ512,
28771   IX86_BUILTIN_CVTPS2PD512,
28772   IX86_BUILTIN_CVTPS2PH512,
28773   IX86_BUILTIN_CVTPS2UDQ512,
28774   IX86_BUILTIN_CVTSD2SS_ROUND,
28775   IX86_BUILTIN_CVTSI2SD64,
28776   IX86_BUILTIN_CVTSI2SS32,
28777   IX86_BUILTIN_CVTSI2SS64,
28778   IX86_BUILTIN_CVTSS2SD_ROUND,
28779   IX86_BUILTIN_CVTTPD2DQ512,
28780   IX86_BUILTIN_CVTTPD2UDQ512,
28781   IX86_BUILTIN_CVTTPS2DQ512,
28782   IX86_BUILTIN_CVTTPS2UDQ512,
28783   IX86_BUILTIN_CVTUDQ2PD512,
28784   IX86_BUILTIN_CVTUDQ2PS512,
28785   IX86_BUILTIN_CVTUSI2SD32,
28786   IX86_BUILTIN_CVTUSI2SD64,
28787   IX86_BUILTIN_CVTUSI2SS32,
28788   IX86_BUILTIN_CVTUSI2SS64,
28789   IX86_BUILTIN_DIVPD512,
28790   IX86_BUILTIN_DIVPS512,
28791   IX86_BUILTIN_DIVSD_ROUND,
28792   IX86_BUILTIN_DIVSS_ROUND,
28793   IX86_BUILTIN_EXPANDPD512,
28794   IX86_BUILTIN_EXPANDPD512Z,
28795   IX86_BUILTIN_EXPANDPDLOAD512,
28796   IX86_BUILTIN_EXPANDPDLOAD512Z,
28797   IX86_BUILTIN_EXPANDPS512,
28798   IX86_BUILTIN_EXPANDPS512Z,
28799   IX86_BUILTIN_EXPANDPSLOAD512,
28800   IX86_BUILTIN_EXPANDPSLOAD512Z,
28801   IX86_BUILTIN_EXTRACTF32X4,
28802   IX86_BUILTIN_EXTRACTF64X4,
28803   IX86_BUILTIN_EXTRACTI32X4,
28804   IX86_BUILTIN_EXTRACTI64X4,
28805   IX86_BUILTIN_FIXUPIMMPD512_MASK,
28806   IX86_BUILTIN_FIXUPIMMPD512_MASKZ,
28807   IX86_BUILTIN_FIXUPIMMPS512_MASK,
28808   IX86_BUILTIN_FIXUPIMMPS512_MASKZ,
28809   IX86_BUILTIN_FIXUPIMMSD128_MASK,
28810   IX86_BUILTIN_FIXUPIMMSD128_MASKZ,
28811   IX86_BUILTIN_FIXUPIMMSS128_MASK,
28812   IX86_BUILTIN_FIXUPIMMSS128_MASKZ,
28813   IX86_BUILTIN_GETEXPPD512,
28814   IX86_BUILTIN_GETEXPPS512,
28815   IX86_BUILTIN_GETEXPSD128,
28816   IX86_BUILTIN_GETEXPSS128,
28817   IX86_BUILTIN_GETMANTPD512,
28818   IX86_BUILTIN_GETMANTPS512,
28819   IX86_BUILTIN_GETMANTSD128,
28820   IX86_BUILTIN_GETMANTSS128,
28821   IX86_BUILTIN_INSERTF32X4,
28822   IX86_BUILTIN_INSERTF64X4,
28823   IX86_BUILTIN_INSERTI32X4,
28824   IX86_BUILTIN_INSERTI64X4,
28825   IX86_BUILTIN_LOADAPD512,
28826   IX86_BUILTIN_LOADAPS512,
28827   IX86_BUILTIN_LOADDQUDI512,
28828   IX86_BUILTIN_LOADDQUSI512,
28829   IX86_BUILTIN_LOADUPD512,
28830   IX86_BUILTIN_LOADUPS512,
28831   IX86_BUILTIN_MAXPD512,
28832   IX86_BUILTIN_MAXPS512,
28833   IX86_BUILTIN_MAXSD_ROUND,
28834   IX86_BUILTIN_MAXSS_ROUND,
28835   IX86_BUILTIN_MINPD512,
28836   IX86_BUILTIN_MINPS512,
28837   IX86_BUILTIN_MINSD_ROUND,
28838   IX86_BUILTIN_MINSS_ROUND,
28839   IX86_BUILTIN_MOVAPD512,
28840   IX86_BUILTIN_MOVAPS512,
28841   IX86_BUILTIN_MOVDDUP512,
28842   IX86_BUILTIN_MOVDQA32LOAD512,
28843   IX86_BUILTIN_MOVDQA32STORE512,
28844   IX86_BUILTIN_MOVDQA32_512,
28845   IX86_BUILTIN_MOVDQA64LOAD512,
28846   IX86_BUILTIN_MOVDQA64STORE512,
28847   IX86_BUILTIN_MOVDQA64_512,
28848   IX86_BUILTIN_MOVNTDQ512,
28849   IX86_BUILTIN_MOVNTDQA512,
28850   IX86_BUILTIN_MOVNTPD512,
28851   IX86_BUILTIN_MOVNTPS512,
28852   IX86_BUILTIN_MOVSHDUP512,
28853   IX86_BUILTIN_MOVSLDUP512,
28854   IX86_BUILTIN_MULPD512,
28855   IX86_BUILTIN_MULPS512,
28856   IX86_BUILTIN_MULSD_ROUND,
28857   IX86_BUILTIN_MULSS_ROUND,
28858   IX86_BUILTIN_PABSD512,
28859   IX86_BUILTIN_PABSQ512,
28860   IX86_BUILTIN_PADDD512,
28861   IX86_BUILTIN_PADDQ512,
28862   IX86_BUILTIN_PANDD512,
28863   IX86_BUILTIN_PANDND512,
28864   IX86_BUILTIN_PANDNQ512,
28865   IX86_BUILTIN_PANDQ512,
28866   IX86_BUILTIN_PBROADCASTD512,
28867   IX86_BUILTIN_PBROADCASTD512_GPR,
28868   IX86_BUILTIN_PBROADCASTMB512,
28869   IX86_BUILTIN_PBROADCASTMW512,
28870   IX86_BUILTIN_PBROADCASTQ512,
28871   IX86_BUILTIN_PBROADCASTQ512_GPR,
28872   IX86_BUILTIN_PCMPEQD512_MASK,
28873   IX86_BUILTIN_PCMPEQQ512_MASK,
28874   IX86_BUILTIN_PCMPGTD512_MASK,
28875   IX86_BUILTIN_PCMPGTQ512_MASK,
28876   IX86_BUILTIN_PCOMPRESSD512,
28877   IX86_BUILTIN_PCOMPRESSDSTORE512,
28878   IX86_BUILTIN_PCOMPRESSQ512,
28879   IX86_BUILTIN_PCOMPRESSQSTORE512,
28880   IX86_BUILTIN_PEXPANDD512,
28881   IX86_BUILTIN_PEXPANDD512Z,
28882   IX86_BUILTIN_PEXPANDDLOAD512,
28883   IX86_BUILTIN_PEXPANDDLOAD512Z,
28884   IX86_BUILTIN_PEXPANDQ512,
28885   IX86_BUILTIN_PEXPANDQ512Z,
28886   IX86_BUILTIN_PEXPANDQLOAD512,
28887   IX86_BUILTIN_PEXPANDQLOAD512Z,
28888   IX86_BUILTIN_PMAXSD512,
28889   IX86_BUILTIN_PMAXSQ512,
28890   IX86_BUILTIN_PMAXUD512,
28891   IX86_BUILTIN_PMAXUQ512,
28892   IX86_BUILTIN_PMINSD512,
28893   IX86_BUILTIN_PMINSQ512,
28894   IX86_BUILTIN_PMINUD512,
28895   IX86_BUILTIN_PMINUQ512,
28896   IX86_BUILTIN_PMOVDB512,
28897   IX86_BUILTIN_PMOVDB512_MEM,
28898   IX86_BUILTIN_PMOVDW512,
28899   IX86_BUILTIN_PMOVDW512_MEM,
28900   IX86_BUILTIN_PMOVQB512,
28901   IX86_BUILTIN_PMOVQB512_MEM,
28902   IX86_BUILTIN_PMOVQD512,
28903   IX86_BUILTIN_PMOVQD512_MEM,
28904   IX86_BUILTIN_PMOVQW512,
28905   IX86_BUILTIN_PMOVQW512_MEM,
28906   IX86_BUILTIN_PMOVSDB512,
28907   IX86_BUILTIN_PMOVSDB512_MEM,
28908   IX86_BUILTIN_PMOVSDW512,
28909   IX86_BUILTIN_PMOVSDW512_MEM,
28910   IX86_BUILTIN_PMOVSQB512,
28911   IX86_BUILTIN_PMOVSQB512_MEM,
28912   IX86_BUILTIN_PMOVSQD512,
28913   IX86_BUILTIN_PMOVSQD512_MEM,
28914   IX86_BUILTIN_PMOVSQW512,
28915   IX86_BUILTIN_PMOVSQW512_MEM,
28916   IX86_BUILTIN_PMOVSXBD512,
28917   IX86_BUILTIN_PMOVSXBQ512,
28918   IX86_BUILTIN_PMOVSXDQ512,
28919   IX86_BUILTIN_PMOVSXWD512,
28920   IX86_BUILTIN_PMOVSXWQ512,
28921   IX86_BUILTIN_PMOVUSDB512,
28922   IX86_BUILTIN_PMOVUSDB512_MEM,
28923   IX86_BUILTIN_PMOVUSDW512,
28924   IX86_BUILTIN_PMOVUSDW512_MEM,
28925   IX86_BUILTIN_PMOVUSQB512,
28926   IX86_BUILTIN_PMOVUSQB512_MEM,
28927   IX86_BUILTIN_PMOVUSQD512,
28928   IX86_BUILTIN_PMOVUSQD512_MEM,
28929   IX86_BUILTIN_PMOVUSQW512,
28930   IX86_BUILTIN_PMOVUSQW512_MEM,
28931   IX86_BUILTIN_PMOVZXBD512,
28932   IX86_BUILTIN_PMOVZXBQ512,
28933   IX86_BUILTIN_PMOVZXDQ512,
28934   IX86_BUILTIN_PMOVZXWD512,
28935   IX86_BUILTIN_PMOVZXWQ512,
28936   IX86_BUILTIN_PMULDQ512,
28937   IX86_BUILTIN_PMULLD512,
28938   IX86_BUILTIN_PMULUDQ512,
28939   IX86_BUILTIN_PORD512,
28940   IX86_BUILTIN_PORQ512,
28941   IX86_BUILTIN_PROLD512,
28942   IX86_BUILTIN_PROLQ512,
28943   IX86_BUILTIN_PROLVD512,
28944   IX86_BUILTIN_PROLVQ512,
28945   IX86_BUILTIN_PRORD512,
28946   IX86_BUILTIN_PRORQ512,
28947   IX86_BUILTIN_PRORVD512,
28948   IX86_BUILTIN_PRORVQ512,
28949   IX86_BUILTIN_PSHUFD512,
28950   IX86_BUILTIN_PSLLD512,
28951   IX86_BUILTIN_PSLLDI512,
28952   IX86_BUILTIN_PSLLQ512,
28953   IX86_BUILTIN_PSLLQI512,
28954   IX86_BUILTIN_PSLLVV16SI,
28955   IX86_BUILTIN_PSLLVV8DI,
28956   IX86_BUILTIN_PSRAD512,
28957   IX86_BUILTIN_PSRADI512,
28958   IX86_BUILTIN_PSRAQ512,
28959   IX86_BUILTIN_PSRAQI512,
28960   IX86_BUILTIN_PSRAVV16SI,
28961   IX86_BUILTIN_PSRAVV8DI,
28962   IX86_BUILTIN_PSRLD512,
28963   IX86_BUILTIN_PSRLDI512,
28964   IX86_BUILTIN_PSRLQ512,
28965   IX86_BUILTIN_PSRLQI512,
28966   IX86_BUILTIN_PSRLVV16SI,
28967   IX86_BUILTIN_PSRLVV8DI,
28968   IX86_BUILTIN_PSUBD512,
28969   IX86_BUILTIN_PSUBQ512,
28970   IX86_BUILTIN_PTESTMD512,
28971   IX86_BUILTIN_PTESTMQ512,
28972   IX86_BUILTIN_PTESTNMD512,
28973   IX86_BUILTIN_PTESTNMQ512,
28974   IX86_BUILTIN_PUNPCKHDQ512,
28975   IX86_BUILTIN_PUNPCKHQDQ512,
28976   IX86_BUILTIN_PUNPCKLDQ512,
28977   IX86_BUILTIN_PUNPCKLQDQ512,
28978   IX86_BUILTIN_PXORD512,
28979   IX86_BUILTIN_PXORQ512,
28980   IX86_BUILTIN_RCP14PD512,
28981   IX86_BUILTIN_RCP14PS512,
28982   IX86_BUILTIN_RCP14SD,
28983   IX86_BUILTIN_RCP14SS,
28984   IX86_BUILTIN_RNDSCALEPD,
28985   IX86_BUILTIN_RNDSCALEPS,
28986   IX86_BUILTIN_RNDSCALESD,
28987   IX86_BUILTIN_RNDSCALESS,
28988   IX86_BUILTIN_RSQRT14PD512,
28989   IX86_BUILTIN_RSQRT14PS512,
28990   IX86_BUILTIN_RSQRT14SD,
28991   IX86_BUILTIN_RSQRT14SS,
28992   IX86_BUILTIN_SCALEFPD512,
28993   IX86_BUILTIN_SCALEFPS512,
28994   IX86_BUILTIN_SCALEFSD,
28995   IX86_BUILTIN_SCALEFSS,
28996   IX86_BUILTIN_SHUFPD512,
28997   IX86_BUILTIN_SHUFPS512,
28998   IX86_BUILTIN_SHUF_F32x4,
28999   IX86_BUILTIN_SHUF_F64x2,
29000   IX86_BUILTIN_SHUF_I32x4,
29001   IX86_BUILTIN_SHUF_I64x2,
29002   IX86_BUILTIN_SQRTPD512,
29003   IX86_BUILTIN_SQRTPD512_MASK,
29004   IX86_BUILTIN_SQRTPS512_MASK,
29005   IX86_BUILTIN_SQRTPS_NR512,
29006   IX86_BUILTIN_SQRTSD_ROUND,
29007   IX86_BUILTIN_SQRTSS_ROUND,
29008   IX86_BUILTIN_STOREAPD512,
29009   IX86_BUILTIN_STOREAPS512,
29010   IX86_BUILTIN_STOREDQUDI512,
29011   IX86_BUILTIN_STOREDQUSI512,
29012   IX86_BUILTIN_STOREUPD512,
29013   IX86_BUILTIN_STOREUPS512,
29014   IX86_BUILTIN_SUBPD512,
29015   IX86_BUILTIN_SUBPS512,
29016   IX86_BUILTIN_SUBSD_ROUND,
29017   IX86_BUILTIN_SUBSS_ROUND,
29018   IX86_BUILTIN_UCMPD512,
29019   IX86_BUILTIN_UCMPQ512,
29020   IX86_BUILTIN_UNPCKHPD512,
29021   IX86_BUILTIN_UNPCKHPS512,
29022   IX86_BUILTIN_UNPCKLPD512,
29023   IX86_BUILTIN_UNPCKLPS512,
29024   IX86_BUILTIN_VCVTSD2SI32,
29025   IX86_BUILTIN_VCVTSD2SI64,
29026   IX86_BUILTIN_VCVTSD2USI32,
29027   IX86_BUILTIN_VCVTSD2USI64,
29028   IX86_BUILTIN_VCVTSS2SI32,
29029   IX86_BUILTIN_VCVTSS2SI64,
29030   IX86_BUILTIN_VCVTSS2USI32,
29031   IX86_BUILTIN_VCVTSS2USI64,
29032   IX86_BUILTIN_VCVTTSD2SI32,
29033   IX86_BUILTIN_VCVTTSD2SI64,
29034   IX86_BUILTIN_VCVTTSD2USI32,
29035   IX86_BUILTIN_VCVTTSD2USI64,
29036   IX86_BUILTIN_VCVTTSS2SI32,
29037   IX86_BUILTIN_VCVTTSS2SI64,
29038   IX86_BUILTIN_VCVTTSS2USI32,
29039   IX86_BUILTIN_VCVTTSS2USI64,
29040   IX86_BUILTIN_VFMADDPD512_MASK,
29041   IX86_BUILTIN_VFMADDPD512_MASK3,
29042   IX86_BUILTIN_VFMADDPD512_MASKZ,
29043   IX86_BUILTIN_VFMADDPS512_MASK,
29044   IX86_BUILTIN_VFMADDPS512_MASK3,
29045   IX86_BUILTIN_VFMADDPS512_MASKZ,
29046   IX86_BUILTIN_VFMADDSD3_ROUND,
29047   IX86_BUILTIN_VFMADDSS3_ROUND,
29048   IX86_BUILTIN_VFMADDSUBPD512_MASK,
29049   IX86_BUILTIN_VFMADDSUBPD512_MASK3,
29050   IX86_BUILTIN_VFMADDSUBPD512_MASKZ,
29051   IX86_BUILTIN_VFMADDSUBPS512_MASK,
29052   IX86_BUILTIN_VFMADDSUBPS512_MASK3,
29053   IX86_BUILTIN_VFMADDSUBPS512_MASKZ,
29054   IX86_BUILTIN_VFMSUBADDPD512_MASK3,
29055   IX86_BUILTIN_VFMSUBADDPS512_MASK3,
29056   IX86_BUILTIN_VFMSUBPD512_MASK3,
29057   IX86_BUILTIN_VFMSUBPS512_MASK3,
29058   IX86_BUILTIN_VFMSUBSD3_MASK3,
29059   IX86_BUILTIN_VFMSUBSS3_MASK3,
29060   IX86_BUILTIN_VFNMADDPD512_MASK,
29061   IX86_BUILTIN_VFNMADDPS512_MASK,
29062   IX86_BUILTIN_VFNMSUBPD512_MASK,
29063   IX86_BUILTIN_VFNMSUBPD512_MASK3,
29064   IX86_BUILTIN_VFNMSUBPS512_MASK,
29065   IX86_BUILTIN_VFNMSUBPS512_MASK3,
29066   IX86_BUILTIN_VPCLZCNTD512,
29067   IX86_BUILTIN_VPCLZCNTQ512,
29068   IX86_BUILTIN_VPCONFLICTD512,
29069   IX86_BUILTIN_VPCONFLICTQ512,
29070   IX86_BUILTIN_VPERMDF512,
29071   IX86_BUILTIN_VPERMDI512,
29072   IX86_BUILTIN_VPERMI2VARD512,
29073   IX86_BUILTIN_VPERMI2VARPD512,
29074   IX86_BUILTIN_VPERMI2VARPS512,
29075   IX86_BUILTIN_VPERMI2VARQ512,
29076   IX86_BUILTIN_VPERMILPD512,
29077   IX86_BUILTIN_VPERMILPS512,
29078   IX86_BUILTIN_VPERMILVARPD512,
29079   IX86_BUILTIN_VPERMILVARPS512,
29080   IX86_BUILTIN_VPERMT2VARD512,
29081   IX86_BUILTIN_VPERMT2VARD512_MASKZ,
29082   IX86_BUILTIN_VPERMT2VARPD512,
29083   IX86_BUILTIN_VPERMT2VARPD512_MASKZ,
29084   IX86_BUILTIN_VPERMT2VARPS512,
29085   IX86_BUILTIN_VPERMT2VARPS512_MASKZ,
29086   IX86_BUILTIN_VPERMT2VARQ512,
29087   IX86_BUILTIN_VPERMT2VARQ512_MASKZ,
29088   IX86_BUILTIN_VPERMVARDF512,
29089   IX86_BUILTIN_VPERMVARDI512,
29090   IX86_BUILTIN_VPERMVARSF512,
29091   IX86_BUILTIN_VPERMVARSI512,
29092   IX86_BUILTIN_VTERNLOGD512_MASK,
29093   IX86_BUILTIN_VTERNLOGD512_MASKZ,
29094   IX86_BUILTIN_VTERNLOGQ512_MASK,
29095   IX86_BUILTIN_VTERNLOGQ512_MASKZ,
29096
29097   /* Mask arithmetic operations */
29098   IX86_BUILTIN_KAND16,
29099   IX86_BUILTIN_KANDN16,
29100   IX86_BUILTIN_KNOT16,
29101   IX86_BUILTIN_KOR16,
29102   IX86_BUILTIN_KORTESTC16,
29103   IX86_BUILTIN_KORTESTZ16,
29104   IX86_BUILTIN_KUNPCKBW,
29105   IX86_BUILTIN_KXNOR16,
29106   IX86_BUILTIN_KXOR16,
29107   IX86_BUILTIN_KMOV16,
29108
29109   /* AVX512VL.  */
29110   IX86_BUILTIN_PMOVUSQD256_MEM,
29111   IX86_BUILTIN_PMOVUSQD128_MEM,
29112   IX86_BUILTIN_PMOVSQD256_MEM,
29113   IX86_BUILTIN_PMOVSQD128_MEM,
29114   IX86_BUILTIN_PMOVQD256_MEM,
29115   IX86_BUILTIN_PMOVQD128_MEM,
29116   IX86_BUILTIN_PMOVUSQW256_MEM,
29117   IX86_BUILTIN_PMOVUSQW128_MEM,
29118   IX86_BUILTIN_PMOVSQW256_MEM,
29119   IX86_BUILTIN_PMOVSQW128_MEM,
29120   IX86_BUILTIN_PMOVQW256_MEM,
29121   IX86_BUILTIN_PMOVQW128_MEM,
29122   IX86_BUILTIN_PMOVUSQB256_MEM,
29123   IX86_BUILTIN_PMOVUSQB128_MEM,
29124   IX86_BUILTIN_PMOVSQB256_MEM,
29125   IX86_BUILTIN_PMOVSQB128_MEM,
29126   IX86_BUILTIN_PMOVQB256_MEM,
29127   IX86_BUILTIN_PMOVQB128_MEM,
29128   IX86_BUILTIN_PMOVUSDW256_MEM,
29129   IX86_BUILTIN_PMOVUSDW128_MEM,
29130   IX86_BUILTIN_PMOVSDW256_MEM,
29131   IX86_BUILTIN_PMOVSDW128_MEM,
29132   IX86_BUILTIN_PMOVDW256_MEM,
29133   IX86_BUILTIN_PMOVDW128_MEM,
29134   IX86_BUILTIN_PMOVUSDB256_MEM,
29135   IX86_BUILTIN_PMOVUSDB128_MEM,
29136   IX86_BUILTIN_PMOVSDB256_MEM,
29137   IX86_BUILTIN_PMOVSDB128_MEM,
29138   IX86_BUILTIN_PMOVDB256_MEM,
29139   IX86_BUILTIN_PMOVDB128_MEM,
29140   IX86_BUILTIN_MOVDQA64LOAD256_MASK,
29141   IX86_BUILTIN_MOVDQA64LOAD128_MASK,
29142   IX86_BUILTIN_MOVDQA32LOAD256_MASK,
29143   IX86_BUILTIN_MOVDQA32LOAD128_MASK,
29144   IX86_BUILTIN_MOVDQA64STORE256_MASK,
29145   IX86_BUILTIN_MOVDQA64STORE128_MASK,
29146   IX86_BUILTIN_MOVDQA32STORE256_MASK,
29147   IX86_BUILTIN_MOVDQA32STORE128_MASK,
29148   IX86_BUILTIN_LOADAPD256_MASK,
29149   IX86_BUILTIN_LOADAPD128_MASK,
29150   IX86_BUILTIN_LOADAPS256_MASK,
29151   IX86_BUILTIN_LOADAPS128_MASK,
29152   IX86_BUILTIN_STOREAPD256_MASK,
29153   IX86_BUILTIN_STOREAPD128_MASK,
29154   IX86_BUILTIN_STOREAPS256_MASK,
29155   IX86_BUILTIN_STOREAPS128_MASK,
29156   IX86_BUILTIN_LOADUPD256_MASK,
29157   IX86_BUILTIN_LOADUPD128_MASK,
29158   IX86_BUILTIN_LOADUPS256_MASK,
29159   IX86_BUILTIN_LOADUPS128_MASK,
29160   IX86_BUILTIN_STOREUPD256_MASK,
29161   IX86_BUILTIN_STOREUPD128_MASK,
29162   IX86_BUILTIN_STOREUPS256_MASK,
29163   IX86_BUILTIN_STOREUPS128_MASK,
29164   IX86_BUILTIN_LOADDQUDI256_MASK,
29165   IX86_BUILTIN_LOADDQUDI128_MASK,
29166   IX86_BUILTIN_LOADDQUSI256_MASK,
29167   IX86_BUILTIN_LOADDQUSI128_MASK,
29168   IX86_BUILTIN_LOADDQUHI256_MASK,
29169   IX86_BUILTIN_LOADDQUHI128_MASK,
29170   IX86_BUILTIN_LOADDQUQI256_MASK,
29171   IX86_BUILTIN_LOADDQUQI128_MASK,
29172   IX86_BUILTIN_STOREDQUDI256_MASK,
29173   IX86_BUILTIN_STOREDQUDI128_MASK,
29174   IX86_BUILTIN_STOREDQUSI256_MASK,
29175   IX86_BUILTIN_STOREDQUSI128_MASK,
29176   IX86_BUILTIN_STOREDQUHI256_MASK,
29177   IX86_BUILTIN_STOREDQUHI128_MASK,
29178   IX86_BUILTIN_STOREDQUQI256_MASK,
29179   IX86_BUILTIN_STOREDQUQI128_MASK,
29180   IX86_BUILTIN_COMPRESSPDSTORE256,
29181   IX86_BUILTIN_COMPRESSPDSTORE128,
29182   IX86_BUILTIN_COMPRESSPSSTORE256,
29183   IX86_BUILTIN_COMPRESSPSSTORE128,
29184   IX86_BUILTIN_PCOMPRESSQSTORE256,
29185   IX86_BUILTIN_PCOMPRESSQSTORE128,
29186   IX86_BUILTIN_PCOMPRESSDSTORE256,
29187   IX86_BUILTIN_PCOMPRESSDSTORE128,
29188   IX86_BUILTIN_EXPANDPDLOAD256,
29189   IX86_BUILTIN_EXPANDPDLOAD128,
29190   IX86_BUILTIN_EXPANDPSLOAD256,
29191   IX86_BUILTIN_EXPANDPSLOAD128,
29192   IX86_BUILTIN_PEXPANDQLOAD256,
29193   IX86_BUILTIN_PEXPANDQLOAD128,
29194   IX86_BUILTIN_PEXPANDDLOAD256,
29195   IX86_BUILTIN_PEXPANDDLOAD128,
29196   IX86_BUILTIN_EXPANDPDLOAD256Z,
29197   IX86_BUILTIN_EXPANDPDLOAD128Z,
29198   IX86_BUILTIN_EXPANDPSLOAD256Z,
29199   IX86_BUILTIN_EXPANDPSLOAD128Z,
29200   IX86_BUILTIN_PEXPANDQLOAD256Z,
29201   IX86_BUILTIN_PEXPANDQLOAD128Z,
29202   IX86_BUILTIN_PEXPANDDLOAD256Z,
29203   IX86_BUILTIN_PEXPANDDLOAD128Z,
29204   IX86_BUILTIN_PALIGNR256_MASK,
29205   IX86_BUILTIN_PALIGNR128_MASK,
29206   IX86_BUILTIN_MOVDQA64_256_MASK,
29207   IX86_BUILTIN_MOVDQA64_128_MASK,
29208   IX86_BUILTIN_MOVDQA32_256_MASK,
29209   IX86_BUILTIN_MOVDQA32_128_MASK,
29210   IX86_BUILTIN_MOVAPD256_MASK,
29211   IX86_BUILTIN_MOVAPD128_MASK,
29212   IX86_BUILTIN_MOVAPS256_MASK,
29213   IX86_BUILTIN_MOVAPS128_MASK,
29214   IX86_BUILTIN_MOVDQUHI256_MASK,
29215   IX86_BUILTIN_MOVDQUHI128_MASK,
29216   IX86_BUILTIN_MOVDQUQI256_MASK,
29217   IX86_BUILTIN_MOVDQUQI128_MASK,
29218   IX86_BUILTIN_MINPS128_MASK,
29219   IX86_BUILTIN_MAXPS128_MASK,
29220   IX86_BUILTIN_MINPD128_MASK,
29221   IX86_BUILTIN_MAXPD128_MASK,
29222   IX86_BUILTIN_MAXPD256_MASK,
29223   IX86_BUILTIN_MAXPS256_MASK,
29224   IX86_BUILTIN_MINPD256_MASK,
29225   IX86_BUILTIN_MINPS256_MASK,
29226   IX86_BUILTIN_MULPS128_MASK,
29227   IX86_BUILTIN_DIVPS128_MASK,
29228   IX86_BUILTIN_MULPD128_MASK,
29229   IX86_BUILTIN_DIVPD128_MASK,
29230   IX86_BUILTIN_DIVPD256_MASK,
29231   IX86_BUILTIN_DIVPS256_MASK,
29232   IX86_BUILTIN_MULPD256_MASK,
29233   IX86_BUILTIN_MULPS256_MASK,
29234   IX86_BUILTIN_ADDPD128_MASK,
29235   IX86_BUILTIN_ADDPD256_MASK,
29236   IX86_BUILTIN_ADDPS128_MASK,
29237   IX86_BUILTIN_ADDPS256_MASK,
29238   IX86_BUILTIN_SUBPD128_MASK,
29239   IX86_BUILTIN_SUBPD256_MASK,
29240   IX86_BUILTIN_SUBPS128_MASK,
29241   IX86_BUILTIN_SUBPS256_MASK,
29242   IX86_BUILTIN_XORPD256_MASK,
29243   IX86_BUILTIN_XORPD128_MASK,
29244   IX86_BUILTIN_XORPS256_MASK,
29245   IX86_BUILTIN_XORPS128_MASK,
29246   IX86_BUILTIN_ORPD256_MASK,
29247   IX86_BUILTIN_ORPD128_MASK,
29248   IX86_BUILTIN_ORPS256_MASK,
29249   IX86_BUILTIN_ORPS128_MASK,
29250   IX86_BUILTIN_BROADCASTF32x2_256,
29251   IX86_BUILTIN_BROADCASTI32x2_256,
29252   IX86_BUILTIN_BROADCASTI32x2_128,
29253   IX86_BUILTIN_BROADCASTF64X2_256,
29254   IX86_BUILTIN_BROADCASTI64X2_256,
29255   IX86_BUILTIN_BROADCASTF32X4_256,
29256   IX86_BUILTIN_BROADCASTI32X4_256,
29257   IX86_BUILTIN_EXTRACTF32X4_256,
29258   IX86_BUILTIN_EXTRACTI32X4_256,
29259   IX86_BUILTIN_DBPSADBW256,
29260   IX86_BUILTIN_DBPSADBW128,
29261   IX86_BUILTIN_CVTTPD2QQ256,
29262   IX86_BUILTIN_CVTTPD2QQ128,
29263   IX86_BUILTIN_CVTTPD2UQQ256,
29264   IX86_BUILTIN_CVTTPD2UQQ128,
29265   IX86_BUILTIN_CVTPD2QQ256,
29266   IX86_BUILTIN_CVTPD2QQ128,
29267   IX86_BUILTIN_CVTPD2UQQ256,
29268   IX86_BUILTIN_CVTPD2UQQ128,
29269   IX86_BUILTIN_CVTPD2UDQ256_MASK,
29270   IX86_BUILTIN_CVTPD2UDQ128_MASK,
29271   IX86_BUILTIN_CVTTPS2QQ256,
29272   IX86_BUILTIN_CVTTPS2QQ128,
29273   IX86_BUILTIN_CVTTPS2UQQ256,
29274   IX86_BUILTIN_CVTTPS2UQQ128,
29275   IX86_BUILTIN_CVTTPS2DQ256_MASK,
29276   IX86_BUILTIN_CVTTPS2DQ128_MASK,
29277   IX86_BUILTIN_CVTTPS2UDQ256,
29278   IX86_BUILTIN_CVTTPS2UDQ128,
29279   IX86_BUILTIN_CVTTPD2DQ256_MASK,
29280   IX86_BUILTIN_CVTTPD2DQ128_MASK,
29281   IX86_BUILTIN_CVTTPD2UDQ256_MASK,
29282   IX86_BUILTIN_CVTTPD2UDQ128_MASK,
29283   IX86_BUILTIN_CVTPD2DQ256_MASK,
29284   IX86_BUILTIN_CVTPD2DQ128_MASK,
29285   IX86_BUILTIN_CVTDQ2PD256_MASK,
29286   IX86_BUILTIN_CVTDQ2PD128_MASK,
29287   IX86_BUILTIN_CVTUDQ2PD256_MASK,
29288   IX86_BUILTIN_CVTUDQ2PD128_MASK,
29289   IX86_BUILTIN_CVTDQ2PS256_MASK,
29290   IX86_BUILTIN_CVTDQ2PS128_MASK,
29291   IX86_BUILTIN_CVTUDQ2PS256_MASK,
29292   IX86_BUILTIN_CVTUDQ2PS128_MASK,
29293   IX86_BUILTIN_CVTPS2PD256_MASK,
29294   IX86_BUILTIN_CVTPS2PD128_MASK,
29295   IX86_BUILTIN_PBROADCASTB256_MASK,
29296   IX86_BUILTIN_PBROADCASTB256_GPR_MASK,
29297   IX86_BUILTIN_PBROADCASTB128_MASK,
29298   IX86_BUILTIN_PBROADCASTB128_GPR_MASK,
29299   IX86_BUILTIN_PBROADCASTW256_MASK,
29300   IX86_BUILTIN_PBROADCASTW256_GPR_MASK,
29301   IX86_BUILTIN_PBROADCASTW128_MASK,
29302   IX86_BUILTIN_PBROADCASTW128_GPR_MASK,
29303   IX86_BUILTIN_PBROADCASTD256_MASK,
29304   IX86_BUILTIN_PBROADCASTD256_GPR_MASK,
29305   IX86_BUILTIN_PBROADCASTD128_MASK,
29306   IX86_BUILTIN_PBROADCASTD128_GPR_MASK,
29307   IX86_BUILTIN_PBROADCASTQ256_MASK,
29308   IX86_BUILTIN_PBROADCASTQ256_GPR_MASK,
29309   IX86_BUILTIN_PBROADCASTQ128_MASK,
29310   IX86_BUILTIN_PBROADCASTQ128_GPR_MASK,
29311   IX86_BUILTIN_BROADCASTSS256,
29312   IX86_BUILTIN_BROADCASTSS128,
29313   IX86_BUILTIN_BROADCASTSD256,
29314   IX86_BUILTIN_EXTRACTF64X2_256,
29315   IX86_BUILTIN_EXTRACTI64X2_256,
29316   IX86_BUILTIN_INSERTF32X4_256,
29317   IX86_BUILTIN_INSERTI32X4_256,
29318   IX86_BUILTIN_PMOVSXBW256_MASK,
29319   IX86_BUILTIN_PMOVSXBW128_MASK,
29320   IX86_BUILTIN_PMOVSXBD256_MASK,
29321   IX86_BUILTIN_PMOVSXBD128_MASK,
29322   IX86_BUILTIN_PMOVSXBQ256_MASK,
29323   IX86_BUILTIN_PMOVSXBQ128_MASK,
29324   IX86_BUILTIN_PMOVSXWD256_MASK,
29325   IX86_BUILTIN_PMOVSXWD128_MASK,
29326   IX86_BUILTIN_PMOVSXWQ256_MASK,
29327   IX86_BUILTIN_PMOVSXWQ128_MASK,
29328   IX86_BUILTIN_PMOVSXDQ256_MASK,
29329   IX86_BUILTIN_PMOVSXDQ128_MASK,
29330   IX86_BUILTIN_PMOVZXBW256_MASK,
29331   IX86_BUILTIN_PMOVZXBW128_MASK,
29332   IX86_BUILTIN_PMOVZXBD256_MASK,
29333   IX86_BUILTIN_PMOVZXBD128_MASK,
29334   IX86_BUILTIN_PMOVZXBQ256_MASK,
29335   IX86_BUILTIN_PMOVZXBQ128_MASK,
29336   IX86_BUILTIN_PMOVZXWD256_MASK,
29337   IX86_BUILTIN_PMOVZXWD128_MASK,
29338   IX86_BUILTIN_PMOVZXWQ256_MASK,
29339   IX86_BUILTIN_PMOVZXWQ128_MASK,
29340   IX86_BUILTIN_PMOVZXDQ256_MASK,
29341   IX86_BUILTIN_PMOVZXDQ128_MASK,
29342   IX86_BUILTIN_REDUCEPD256_MASK,
29343   IX86_BUILTIN_REDUCEPD128_MASK,
29344   IX86_BUILTIN_REDUCEPS256_MASK,
29345   IX86_BUILTIN_REDUCEPS128_MASK,
29346   IX86_BUILTIN_REDUCESD_MASK,
29347   IX86_BUILTIN_REDUCESS_MASK,
29348   IX86_BUILTIN_VPERMVARHI256_MASK,
29349   IX86_BUILTIN_VPERMVARHI128_MASK,
29350   IX86_BUILTIN_VPERMT2VARHI256,
29351   IX86_BUILTIN_VPERMT2VARHI256_MASKZ,
29352   IX86_BUILTIN_VPERMT2VARHI128,
29353   IX86_BUILTIN_VPERMT2VARHI128_MASKZ,
29354   IX86_BUILTIN_VPERMI2VARHI256,
29355   IX86_BUILTIN_VPERMI2VARHI128,
29356   IX86_BUILTIN_RCP14PD256,
29357   IX86_BUILTIN_RCP14PD128,
29358   IX86_BUILTIN_RCP14PS256,
29359   IX86_BUILTIN_RCP14PS128,
29360   IX86_BUILTIN_RSQRT14PD256_MASK,
29361   IX86_BUILTIN_RSQRT14PD128_MASK,
29362   IX86_BUILTIN_RSQRT14PS256_MASK,
29363   IX86_BUILTIN_RSQRT14PS128_MASK,
29364   IX86_BUILTIN_SQRTPD256_MASK,
29365   IX86_BUILTIN_SQRTPD128_MASK,
29366   IX86_BUILTIN_SQRTPS256_MASK,
29367   IX86_BUILTIN_SQRTPS128_MASK,
29368   IX86_BUILTIN_PADDB128_MASK,
29369   IX86_BUILTIN_PADDW128_MASK,
29370   IX86_BUILTIN_PADDD128_MASK,
29371   IX86_BUILTIN_PADDQ128_MASK,
29372   IX86_BUILTIN_PSUBB128_MASK,
29373   IX86_BUILTIN_PSUBW128_MASK,
29374   IX86_BUILTIN_PSUBD128_MASK,
29375   IX86_BUILTIN_PSUBQ128_MASK,
29376   IX86_BUILTIN_PADDSB128_MASK,
29377   IX86_BUILTIN_PADDSW128_MASK,
29378   IX86_BUILTIN_PSUBSB128_MASK,
29379   IX86_BUILTIN_PSUBSW128_MASK,
29380   IX86_BUILTIN_PADDUSB128_MASK,
29381   IX86_BUILTIN_PADDUSW128_MASK,
29382   IX86_BUILTIN_PSUBUSB128_MASK,
29383   IX86_BUILTIN_PSUBUSW128_MASK,
29384   IX86_BUILTIN_PADDB256_MASK,
29385   IX86_BUILTIN_PADDW256_MASK,
29386   IX86_BUILTIN_PADDD256_MASK,
29387   IX86_BUILTIN_PADDQ256_MASK,
29388   IX86_BUILTIN_PADDSB256_MASK,
29389   IX86_BUILTIN_PADDSW256_MASK,
29390   IX86_BUILTIN_PADDUSB256_MASK,
29391   IX86_BUILTIN_PADDUSW256_MASK,
29392   IX86_BUILTIN_PSUBB256_MASK,
29393   IX86_BUILTIN_PSUBW256_MASK,
29394   IX86_BUILTIN_PSUBD256_MASK,
29395   IX86_BUILTIN_PSUBQ256_MASK,
29396   IX86_BUILTIN_PSUBSB256_MASK,
29397   IX86_BUILTIN_PSUBSW256_MASK,
29398   IX86_BUILTIN_PSUBUSB256_MASK,
29399   IX86_BUILTIN_PSUBUSW256_MASK,
29400   IX86_BUILTIN_SHUF_F64x2_256,
29401   IX86_BUILTIN_SHUF_I64x2_256,
29402   IX86_BUILTIN_SHUF_I32x4_256,
29403   IX86_BUILTIN_SHUF_F32x4_256,
29404   IX86_BUILTIN_PMOVWB128,
29405   IX86_BUILTIN_PMOVWB256,
29406   IX86_BUILTIN_PMOVSWB128,
29407   IX86_BUILTIN_PMOVSWB256,
29408   IX86_BUILTIN_PMOVUSWB128,
29409   IX86_BUILTIN_PMOVUSWB256,
29410   IX86_BUILTIN_PMOVDB128,
29411   IX86_BUILTIN_PMOVDB256,
29412   IX86_BUILTIN_PMOVSDB128,
29413   IX86_BUILTIN_PMOVSDB256,
29414   IX86_BUILTIN_PMOVUSDB128,
29415   IX86_BUILTIN_PMOVUSDB256,
29416   IX86_BUILTIN_PMOVDW128,
29417   IX86_BUILTIN_PMOVDW256,
29418   IX86_BUILTIN_PMOVSDW128,
29419   IX86_BUILTIN_PMOVSDW256,
29420   IX86_BUILTIN_PMOVUSDW128,
29421   IX86_BUILTIN_PMOVUSDW256,
29422   IX86_BUILTIN_PMOVQB128,
29423   IX86_BUILTIN_PMOVQB256,
29424   IX86_BUILTIN_PMOVSQB128,
29425   IX86_BUILTIN_PMOVSQB256,
29426   IX86_BUILTIN_PMOVUSQB128,
29427   IX86_BUILTIN_PMOVUSQB256,
29428   IX86_BUILTIN_PMOVQW128,
29429   IX86_BUILTIN_PMOVQW256,
29430   IX86_BUILTIN_PMOVSQW128,
29431   IX86_BUILTIN_PMOVSQW256,
29432   IX86_BUILTIN_PMOVUSQW128,
29433   IX86_BUILTIN_PMOVUSQW256,
29434   IX86_BUILTIN_PMOVQD128,
29435   IX86_BUILTIN_PMOVQD256,
29436   IX86_BUILTIN_PMOVSQD128,
29437   IX86_BUILTIN_PMOVSQD256,
29438   IX86_BUILTIN_PMOVUSQD128,
29439   IX86_BUILTIN_PMOVUSQD256,
29440   IX86_BUILTIN_RANGEPD256,
29441   IX86_BUILTIN_RANGEPD128,
29442   IX86_BUILTIN_RANGEPS256,
29443   IX86_BUILTIN_RANGEPS128,
29444   IX86_BUILTIN_GETEXPPS256,
29445   IX86_BUILTIN_GETEXPPD256,
29446   IX86_BUILTIN_GETEXPPS128,
29447   IX86_BUILTIN_GETEXPPD128,
29448   IX86_BUILTIN_FIXUPIMMPD256_MASK,
29449   IX86_BUILTIN_FIXUPIMMPD256_MASKZ,
29450   IX86_BUILTIN_FIXUPIMMPS256_MASK,
29451   IX86_BUILTIN_FIXUPIMMPS256_MASKZ,
29452   IX86_BUILTIN_FIXUPIMMPD128_MASK,
29453   IX86_BUILTIN_FIXUPIMMPD128_MASKZ,
29454   IX86_BUILTIN_FIXUPIMMPS128_MASK,
29455   IX86_BUILTIN_FIXUPIMMPS128_MASKZ,
29456   IX86_BUILTIN_PABSQ256,
29457   IX86_BUILTIN_PABSQ128,
29458   IX86_BUILTIN_PABSD256_MASK,
29459   IX86_BUILTIN_PABSD128_MASK,
29460   IX86_BUILTIN_PMULHRSW256_MASK,
29461   IX86_BUILTIN_PMULHRSW128_MASK,
29462   IX86_BUILTIN_PMULHUW128_MASK,
29463   IX86_BUILTIN_PMULHUW256_MASK,
29464   IX86_BUILTIN_PMULHW256_MASK,
29465   IX86_BUILTIN_PMULHW128_MASK,
29466   IX86_BUILTIN_PMULLW256_MASK,
29467   IX86_BUILTIN_PMULLW128_MASK,
29468   IX86_BUILTIN_PMULLQ256,
29469   IX86_BUILTIN_PMULLQ128,
29470   IX86_BUILTIN_ANDPD256_MASK,
29471   IX86_BUILTIN_ANDPD128_MASK,
29472   IX86_BUILTIN_ANDPS256_MASK,
29473   IX86_BUILTIN_ANDPS128_MASK,
29474   IX86_BUILTIN_ANDNPD256_MASK,
29475   IX86_BUILTIN_ANDNPD128_MASK,
29476   IX86_BUILTIN_ANDNPS256_MASK,
29477   IX86_BUILTIN_ANDNPS128_MASK,
29478   IX86_BUILTIN_PSLLWI128_MASK,
29479   IX86_BUILTIN_PSLLDI128_MASK,
29480   IX86_BUILTIN_PSLLQI128_MASK,
29481   IX86_BUILTIN_PSLLW128_MASK,
29482   IX86_BUILTIN_PSLLD128_MASK,
29483   IX86_BUILTIN_PSLLQ128_MASK,
29484   IX86_BUILTIN_PSLLWI256_MASK ,
29485   IX86_BUILTIN_PSLLW256_MASK,
29486   IX86_BUILTIN_PSLLDI256_MASK,
29487   IX86_BUILTIN_PSLLD256_MASK,
29488   IX86_BUILTIN_PSLLQI256_MASK,
29489   IX86_BUILTIN_PSLLQ256_MASK,
29490   IX86_BUILTIN_PSRADI128_MASK,
29491   IX86_BUILTIN_PSRAD128_MASK,
29492   IX86_BUILTIN_PSRADI256_MASK,
29493   IX86_BUILTIN_PSRAD256_MASK,
29494   IX86_BUILTIN_PSRAQI128_MASK,
29495   IX86_BUILTIN_PSRAQ128_MASK,
29496   IX86_BUILTIN_PSRAQI256_MASK,
29497   IX86_BUILTIN_PSRAQ256_MASK,
29498   IX86_BUILTIN_PANDD256,
29499   IX86_BUILTIN_PANDD128,
29500   IX86_BUILTIN_PSRLDI128_MASK,
29501   IX86_BUILTIN_PSRLD128_MASK,
29502   IX86_BUILTIN_PSRLDI256_MASK,
29503   IX86_BUILTIN_PSRLD256_MASK,
29504   IX86_BUILTIN_PSRLQI128_MASK,
29505   IX86_BUILTIN_PSRLQ128_MASK,
29506   IX86_BUILTIN_PSRLQI256_MASK,
29507   IX86_BUILTIN_PSRLQ256_MASK,
29508   IX86_BUILTIN_PANDQ256,
29509   IX86_BUILTIN_PANDQ128,
29510   IX86_BUILTIN_PANDND256,
29511   IX86_BUILTIN_PANDND128,
29512   IX86_BUILTIN_PANDNQ256,
29513   IX86_BUILTIN_PANDNQ128,
29514   IX86_BUILTIN_PORD256,
29515   IX86_BUILTIN_PORD128,
29516   IX86_BUILTIN_PORQ256,
29517   IX86_BUILTIN_PORQ128,
29518   IX86_BUILTIN_PXORD256,
29519   IX86_BUILTIN_PXORD128,
29520   IX86_BUILTIN_PXORQ256,
29521   IX86_BUILTIN_PXORQ128,
29522   IX86_BUILTIN_PACKSSWB256_MASK,
29523   IX86_BUILTIN_PACKSSWB128_MASK,
29524   IX86_BUILTIN_PACKUSWB256_MASK,
29525   IX86_BUILTIN_PACKUSWB128_MASK,
29526   IX86_BUILTIN_RNDSCALEPS256,
29527   IX86_BUILTIN_RNDSCALEPD256,
29528   IX86_BUILTIN_RNDSCALEPS128,
29529   IX86_BUILTIN_RNDSCALEPD128,
29530   IX86_BUILTIN_VTERNLOGQ256_MASK,
29531   IX86_BUILTIN_VTERNLOGQ256_MASKZ,
29532   IX86_BUILTIN_VTERNLOGD256_MASK,
29533   IX86_BUILTIN_VTERNLOGD256_MASKZ,
29534   IX86_BUILTIN_VTERNLOGQ128_MASK,
29535   IX86_BUILTIN_VTERNLOGQ128_MASKZ,
29536   IX86_BUILTIN_VTERNLOGD128_MASK,
29537   IX86_BUILTIN_VTERNLOGD128_MASKZ,
29538   IX86_BUILTIN_SCALEFPD256,
29539   IX86_BUILTIN_SCALEFPS256,
29540   IX86_BUILTIN_SCALEFPD128,
29541   IX86_BUILTIN_SCALEFPS128,
29542   IX86_BUILTIN_VFMADDPD256_MASK,
29543   IX86_BUILTIN_VFMADDPD256_MASK3,
29544   IX86_BUILTIN_VFMADDPD256_MASKZ,
29545   IX86_BUILTIN_VFMADDPD128_MASK,
29546   IX86_BUILTIN_VFMADDPD128_MASK3,
29547   IX86_BUILTIN_VFMADDPD128_MASKZ,
29548   IX86_BUILTIN_VFMADDPS256_MASK,
29549   IX86_BUILTIN_VFMADDPS256_MASK3,
29550   IX86_BUILTIN_VFMADDPS256_MASKZ,
29551   IX86_BUILTIN_VFMADDPS128_MASK,
29552   IX86_BUILTIN_VFMADDPS128_MASK3,
29553   IX86_BUILTIN_VFMADDPS128_MASKZ,
29554   IX86_BUILTIN_VFMSUBPD256_MASK3,
29555   IX86_BUILTIN_VFMSUBPD128_MASK3,
29556   IX86_BUILTIN_VFMSUBPS256_MASK3,
29557   IX86_BUILTIN_VFMSUBPS128_MASK3,
29558   IX86_BUILTIN_VFNMADDPD256_MASK,
29559   IX86_BUILTIN_VFNMADDPD128_MASK,
29560   IX86_BUILTIN_VFNMADDPS256_MASK,
29561   IX86_BUILTIN_VFNMADDPS128_MASK,
29562   IX86_BUILTIN_VFNMSUBPD256_MASK,
29563   IX86_BUILTIN_VFNMSUBPD256_MASK3,
29564   IX86_BUILTIN_VFNMSUBPD128_MASK,
29565   IX86_BUILTIN_VFNMSUBPD128_MASK3,
29566   IX86_BUILTIN_VFNMSUBPS256_MASK,
29567   IX86_BUILTIN_VFNMSUBPS256_MASK3,
29568   IX86_BUILTIN_VFNMSUBPS128_MASK,
29569   IX86_BUILTIN_VFNMSUBPS128_MASK3,
29570   IX86_BUILTIN_VFMADDSUBPD256_MASK,
29571   IX86_BUILTIN_VFMADDSUBPD256_MASK3,
29572   IX86_BUILTIN_VFMADDSUBPD256_MASKZ,
29573   IX86_BUILTIN_VFMADDSUBPD128_MASK,
29574   IX86_BUILTIN_VFMADDSUBPD128_MASK3,
29575   IX86_BUILTIN_VFMADDSUBPD128_MASKZ,
29576   IX86_BUILTIN_VFMADDSUBPS256_MASK,
29577   IX86_BUILTIN_VFMADDSUBPS256_MASK3,
29578   IX86_BUILTIN_VFMADDSUBPS256_MASKZ,
29579   IX86_BUILTIN_VFMADDSUBPS128_MASK,
29580   IX86_BUILTIN_VFMADDSUBPS128_MASK3,
29581   IX86_BUILTIN_VFMADDSUBPS128_MASKZ,
29582   IX86_BUILTIN_VFMSUBADDPD256_MASK3,
29583   IX86_BUILTIN_VFMSUBADDPD128_MASK3,
29584   IX86_BUILTIN_VFMSUBADDPS256_MASK3,
29585   IX86_BUILTIN_VFMSUBADDPS128_MASK3,
29586   IX86_BUILTIN_INSERTF64X2_256,
29587   IX86_BUILTIN_INSERTI64X2_256,
29588   IX86_BUILTIN_PSRAVV16HI,
29589   IX86_BUILTIN_PSRAVV8HI,
29590   IX86_BUILTIN_PMADDUBSW256_MASK,
29591   IX86_BUILTIN_PMADDUBSW128_MASK,
29592   IX86_BUILTIN_PMADDWD256_MASK,
29593   IX86_BUILTIN_PMADDWD128_MASK,
29594   IX86_BUILTIN_PSRLVV16HI,
29595   IX86_BUILTIN_PSRLVV8HI,
29596   IX86_BUILTIN_CVTPS2DQ256_MASK,
29597   IX86_BUILTIN_CVTPS2DQ128_MASK,
29598   IX86_BUILTIN_CVTPS2UDQ256,
29599   IX86_BUILTIN_CVTPS2UDQ128,
29600   IX86_BUILTIN_CVTPS2QQ256,
29601   IX86_BUILTIN_CVTPS2QQ128,
29602   IX86_BUILTIN_CVTPS2UQQ256,
29603   IX86_BUILTIN_CVTPS2UQQ128,
29604   IX86_BUILTIN_GETMANTPS256,
29605   IX86_BUILTIN_GETMANTPS128,
29606   IX86_BUILTIN_GETMANTPD256,
29607   IX86_BUILTIN_GETMANTPD128,
29608   IX86_BUILTIN_MOVDDUP256_MASK,
29609   IX86_BUILTIN_MOVDDUP128_MASK,
29610   IX86_BUILTIN_MOVSHDUP256_MASK,
29611   IX86_BUILTIN_MOVSHDUP128_MASK,
29612   IX86_BUILTIN_MOVSLDUP256_MASK,
29613   IX86_BUILTIN_MOVSLDUP128_MASK,
29614   IX86_BUILTIN_CVTQQ2PS256,
29615   IX86_BUILTIN_CVTQQ2PS128,
29616   IX86_BUILTIN_CVTUQQ2PS256,
29617   IX86_BUILTIN_CVTUQQ2PS128,
29618   IX86_BUILTIN_CVTQQ2PD256,
29619   IX86_BUILTIN_CVTQQ2PD128,
29620   IX86_BUILTIN_CVTUQQ2PD256,
29621   IX86_BUILTIN_CVTUQQ2PD128,
29622   IX86_BUILTIN_VPERMT2VARQ256,
29623   IX86_BUILTIN_VPERMT2VARQ256_MASKZ,
29624   IX86_BUILTIN_VPERMT2VARD256,
29625   IX86_BUILTIN_VPERMT2VARD256_MASKZ,
29626   IX86_BUILTIN_VPERMI2VARQ256,
29627   IX86_BUILTIN_VPERMI2VARD256,
29628   IX86_BUILTIN_VPERMT2VARPD256,
29629   IX86_BUILTIN_VPERMT2VARPD256_MASKZ,
29630   IX86_BUILTIN_VPERMT2VARPS256,
29631   IX86_BUILTIN_VPERMT2VARPS256_MASKZ,
29632   IX86_BUILTIN_VPERMI2VARPD256,
29633   IX86_BUILTIN_VPERMI2VARPS256,
29634   IX86_BUILTIN_VPERMT2VARQ128,
29635   IX86_BUILTIN_VPERMT2VARQ128_MASKZ,
29636   IX86_BUILTIN_VPERMT2VARD128,
29637   IX86_BUILTIN_VPERMT2VARD128_MASKZ,
29638   IX86_BUILTIN_VPERMI2VARQ128,
29639   IX86_BUILTIN_VPERMI2VARD128,
29640   IX86_BUILTIN_VPERMT2VARPD128,
29641   IX86_BUILTIN_VPERMT2VARPD128_MASKZ,
29642   IX86_BUILTIN_VPERMT2VARPS128,
29643   IX86_BUILTIN_VPERMT2VARPS128_MASKZ,
29644   IX86_BUILTIN_VPERMI2VARPD128,
29645   IX86_BUILTIN_VPERMI2VARPS128,
29646   IX86_BUILTIN_PSHUFB256_MASK,
29647   IX86_BUILTIN_PSHUFB128_MASK,
29648   IX86_BUILTIN_PSHUFHW256_MASK,
29649   IX86_BUILTIN_PSHUFHW128_MASK,
29650   IX86_BUILTIN_PSHUFLW256_MASK,
29651   IX86_BUILTIN_PSHUFLW128_MASK,
29652   IX86_BUILTIN_PSHUFD256_MASK,
29653   IX86_BUILTIN_PSHUFD128_MASK,
29654   IX86_BUILTIN_SHUFPD256_MASK,
29655   IX86_BUILTIN_SHUFPD128_MASK,
29656   IX86_BUILTIN_SHUFPS256_MASK,
29657   IX86_BUILTIN_SHUFPS128_MASK,
29658   IX86_BUILTIN_PROLVQ256,
29659   IX86_BUILTIN_PROLVQ128,
29660   IX86_BUILTIN_PROLQ256,
29661   IX86_BUILTIN_PROLQ128,
29662   IX86_BUILTIN_PRORVQ256,
29663   IX86_BUILTIN_PRORVQ128,
29664   IX86_BUILTIN_PRORQ256,
29665   IX86_BUILTIN_PRORQ128,
29666   IX86_BUILTIN_PSRAVQ128,
29667   IX86_BUILTIN_PSRAVQ256,
29668   IX86_BUILTIN_PSLLVV4DI_MASK,
29669   IX86_BUILTIN_PSLLVV2DI_MASK,
29670   IX86_BUILTIN_PSLLVV8SI_MASK,
29671   IX86_BUILTIN_PSLLVV4SI_MASK,
29672   IX86_BUILTIN_PSRAVV8SI_MASK,
29673   IX86_BUILTIN_PSRAVV4SI_MASK,
29674   IX86_BUILTIN_PSRLVV4DI_MASK,
29675   IX86_BUILTIN_PSRLVV2DI_MASK,
29676   IX86_BUILTIN_PSRLVV8SI_MASK,
29677   IX86_BUILTIN_PSRLVV4SI_MASK,
29678   IX86_BUILTIN_PSRAWI256_MASK,
29679   IX86_BUILTIN_PSRAW256_MASK,
29680   IX86_BUILTIN_PSRAWI128_MASK,
29681   IX86_BUILTIN_PSRAW128_MASK,
29682   IX86_BUILTIN_PSRLWI256_MASK,
29683   IX86_BUILTIN_PSRLW256_MASK,
29684   IX86_BUILTIN_PSRLWI128_MASK,
29685   IX86_BUILTIN_PSRLW128_MASK,
29686   IX86_BUILTIN_PRORVD256,
29687   IX86_BUILTIN_PROLVD256,
29688   IX86_BUILTIN_PRORD256,
29689   IX86_BUILTIN_PROLD256,
29690   IX86_BUILTIN_PRORVD128,
29691   IX86_BUILTIN_PROLVD128,
29692   IX86_BUILTIN_PRORD128,
29693   IX86_BUILTIN_PROLD128,
29694   IX86_BUILTIN_FPCLASSPD256,
29695   IX86_BUILTIN_FPCLASSPD128,
29696   IX86_BUILTIN_FPCLASSSD,
29697   IX86_BUILTIN_FPCLASSPS256,
29698   IX86_BUILTIN_FPCLASSPS128,
29699   IX86_BUILTIN_FPCLASSSS,
29700   IX86_BUILTIN_CVTB2MASK128,
29701   IX86_BUILTIN_CVTB2MASK256,
29702   IX86_BUILTIN_CVTW2MASK128,
29703   IX86_BUILTIN_CVTW2MASK256,
29704   IX86_BUILTIN_CVTD2MASK128,
29705   IX86_BUILTIN_CVTD2MASK256,
29706   IX86_BUILTIN_CVTQ2MASK128,
29707   IX86_BUILTIN_CVTQ2MASK256,
29708   IX86_BUILTIN_CVTMASK2B128,
29709   IX86_BUILTIN_CVTMASK2B256,
29710   IX86_BUILTIN_CVTMASK2W128,
29711   IX86_BUILTIN_CVTMASK2W256,
29712   IX86_BUILTIN_CVTMASK2D128,
29713   IX86_BUILTIN_CVTMASK2D256,
29714   IX86_BUILTIN_CVTMASK2Q128,
29715   IX86_BUILTIN_CVTMASK2Q256,
29716   IX86_BUILTIN_PCMPEQB128_MASK,
29717   IX86_BUILTIN_PCMPEQB256_MASK,
29718   IX86_BUILTIN_PCMPEQW128_MASK,
29719   IX86_BUILTIN_PCMPEQW256_MASK,
29720   IX86_BUILTIN_PCMPEQD128_MASK,
29721   IX86_BUILTIN_PCMPEQD256_MASK,
29722   IX86_BUILTIN_PCMPEQQ128_MASK,
29723   IX86_BUILTIN_PCMPEQQ256_MASK,
29724   IX86_BUILTIN_PCMPGTB128_MASK,
29725   IX86_BUILTIN_PCMPGTB256_MASK,
29726   IX86_BUILTIN_PCMPGTW128_MASK,
29727   IX86_BUILTIN_PCMPGTW256_MASK,
29728   IX86_BUILTIN_PCMPGTD128_MASK,
29729   IX86_BUILTIN_PCMPGTD256_MASK,
29730   IX86_BUILTIN_PCMPGTQ128_MASK,
29731   IX86_BUILTIN_PCMPGTQ256_MASK,
29732   IX86_BUILTIN_PTESTMB128,
29733   IX86_BUILTIN_PTESTMB256,
29734   IX86_BUILTIN_PTESTMW128,
29735   IX86_BUILTIN_PTESTMW256,
29736   IX86_BUILTIN_PTESTMD128,
29737   IX86_BUILTIN_PTESTMD256,
29738   IX86_BUILTIN_PTESTMQ128,
29739   IX86_BUILTIN_PTESTMQ256,
29740   IX86_BUILTIN_PTESTNMB128,
29741   IX86_BUILTIN_PTESTNMB256,
29742   IX86_BUILTIN_PTESTNMW128,
29743   IX86_BUILTIN_PTESTNMW256,
29744   IX86_BUILTIN_PTESTNMD128,
29745   IX86_BUILTIN_PTESTNMD256,
29746   IX86_BUILTIN_PTESTNMQ128,
29747   IX86_BUILTIN_PTESTNMQ256,
29748   IX86_BUILTIN_PBROADCASTMB128,
29749   IX86_BUILTIN_PBROADCASTMB256,
29750   IX86_BUILTIN_PBROADCASTMW128,
29751   IX86_BUILTIN_PBROADCASTMW256,
29752   IX86_BUILTIN_COMPRESSPD256,
29753   IX86_BUILTIN_COMPRESSPD128,
29754   IX86_BUILTIN_COMPRESSPS256,
29755   IX86_BUILTIN_COMPRESSPS128,
29756   IX86_BUILTIN_PCOMPRESSQ256,
29757   IX86_BUILTIN_PCOMPRESSQ128,
29758   IX86_BUILTIN_PCOMPRESSD256,
29759   IX86_BUILTIN_PCOMPRESSD128,
29760   IX86_BUILTIN_EXPANDPD256,
29761   IX86_BUILTIN_EXPANDPD128,
29762   IX86_BUILTIN_EXPANDPS256,
29763   IX86_BUILTIN_EXPANDPS128,
29764   IX86_BUILTIN_PEXPANDQ256,
29765   IX86_BUILTIN_PEXPANDQ128,
29766   IX86_BUILTIN_PEXPANDD256,
29767   IX86_BUILTIN_PEXPANDD128,
29768   IX86_BUILTIN_EXPANDPD256Z,
29769   IX86_BUILTIN_EXPANDPD128Z,
29770   IX86_BUILTIN_EXPANDPS256Z,
29771   IX86_BUILTIN_EXPANDPS128Z,
29772   IX86_BUILTIN_PEXPANDQ256Z,
29773   IX86_BUILTIN_PEXPANDQ128Z,
29774   IX86_BUILTIN_PEXPANDD256Z,
29775   IX86_BUILTIN_PEXPANDD128Z,
29776   IX86_BUILTIN_PMAXSD256_MASK,
29777   IX86_BUILTIN_PMINSD256_MASK,
29778   IX86_BUILTIN_PMAXUD256_MASK,
29779   IX86_BUILTIN_PMINUD256_MASK,
29780   IX86_BUILTIN_PMAXSD128_MASK,
29781   IX86_BUILTIN_PMINSD128_MASK,
29782   IX86_BUILTIN_PMAXUD128_MASK,
29783   IX86_BUILTIN_PMINUD128_MASK,
29784   IX86_BUILTIN_PMAXSQ256_MASK,
29785   IX86_BUILTIN_PMINSQ256_MASK,
29786   IX86_BUILTIN_PMAXUQ256_MASK,
29787   IX86_BUILTIN_PMINUQ256_MASK,
29788   IX86_BUILTIN_PMAXSQ128_MASK,
29789   IX86_BUILTIN_PMINSQ128_MASK,
29790   IX86_BUILTIN_PMAXUQ128_MASK,
29791   IX86_BUILTIN_PMINUQ128_MASK,
29792   IX86_BUILTIN_PMINSB256_MASK,
29793   IX86_BUILTIN_PMINUB256_MASK,
29794   IX86_BUILTIN_PMAXSB256_MASK,
29795   IX86_BUILTIN_PMAXUB256_MASK,
29796   IX86_BUILTIN_PMINSB128_MASK,
29797   IX86_BUILTIN_PMINUB128_MASK,
29798   IX86_BUILTIN_PMAXSB128_MASK,
29799   IX86_BUILTIN_PMAXUB128_MASK,
29800   IX86_BUILTIN_PMINSW256_MASK,
29801   IX86_BUILTIN_PMINUW256_MASK,
29802   IX86_BUILTIN_PMAXSW256_MASK,
29803   IX86_BUILTIN_PMAXUW256_MASK,
29804   IX86_BUILTIN_PMINSW128_MASK,
29805   IX86_BUILTIN_PMINUW128_MASK,
29806   IX86_BUILTIN_PMAXSW128_MASK,
29807   IX86_BUILTIN_PMAXUW128_MASK,
29808   IX86_BUILTIN_VPCONFLICTQ256,
29809   IX86_BUILTIN_VPCONFLICTD256,
29810   IX86_BUILTIN_VPCLZCNTQ256,
29811   IX86_BUILTIN_VPCLZCNTD256,
29812   IX86_BUILTIN_UNPCKHPD256_MASK,
29813   IX86_BUILTIN_UNPCKHPD128_MASK,
29814   IX86_BUILTIN_UNPCKHPS256_MASK,
29815   IX86_BUILTIN_UNPCKHPS128_MASK,
29816   IX86_BUILTIN_UNPCKLPD256_MASK,
29817   IX86_BUILTIN_UNPCKLPD128_MASK,
29818   IX86_BUILTIN_UNPCKLPS256_MASK,
29819   IX86_BUILTIN_VPCONFLICTQ128,
29820   IX86_BUILTIN_VPCONFLICTD128,
29821   IX86_BUILTIN_VPCLZCNTQ128,
29822   IX86_BUILTIN_VPCLZCNTD128,
29823   IX86_BUILTIN_UNPCKLPS128_MASK,
29824   IX86_BUILTIN_ALIGND256,
29825   IX86_BUILTIN_ALIGNQ256,
29826   IX86_BUILTIN_ALIGND128,
29827   IX86_BUILTIN_ALIGNQ128,
29828   IX86_BUILTIN_CVTPS2PH256_MASK,
29829   IX86_BUILTIN_CVTPS2PH_MASK,
29830   IX86_BUILTIN_CVTPH2PS_MASK,
29831   IX86_BUILTIN_CVTPH2PS256_MASK,
29832   IX86_BUILTIN_PUNPCKHDQ128_MASK,
29833   IX86_BUILTIN_PUNPCKHDQ256_MASK,
29834   IX86_BUILTIN_PUNPCKHQDQ128_MASK,
29835   IX86_BUILTIN_PUNPCKHQDQ256_MASK,
29836   IX86_BUILTIN_PUNPCKLDQ128_MASK,
29837   IX86_BUILTIN_PUNPCKLDQ256_MASK,
29838   IX86_BUILTIN_PUNPCKLQDQ128_MASK,
29839   IX86_BUILTIN_PUNPCKLQDQ256_MASK,
29840   IX86_BUILTIN_PUNPCKHBW128_MASK,
29841   IX86_BUILTIN_PUNPCKHBW256_MASK,
29842   IX86_BUILTIN_PUNPCKHWD128_MASK,
29843   IX86_BUILTIN_PUNPCKHWD256_MASK,
29844   IX86_BUILTIN_PUNPCKLBW128_MASK,
29845   IX86_BUILTIN_PUNPCKLBW256_MASK,
29846   IX86_BUILTIN_PUNPCKLWD128_MASK,
29847   IX86_BUILTIN_PUNPCKLWD256_MASK,
29848   IX86_BUILTIN_PSLLVV16HI,
29849   IX86_BUILTIN_PSLLVV8HI,
29850   IX86_BUILTIN_PACKSSDW256_MASK,
29851   IX86_BUILTIN_PACKSSDW128_MASK,
29852   IX86_BUILTIN_PACKUSDW256_MASK,
29853   IX86_BUILTIN_PACKUSDW128_MASK,
29854   IX86_BUILTIN_PAVGB256_MASK,
29855   IX86_BUILTIN_PAVGW256_MASK,
29856   IX86_BUILTIN_PAVGB128_MASK,
29857   IX86_BUILTIN_PAVGW128_MASK,
29858   IX86_BUILTIN_VPERMVARSF256_MASK,
29859   IX86_BUILTIN_VPERMVARDF256_MASK,
29860   IX86_BUILTIN_VPERMDF256_MASK,
29861   IX86_BUILTIN_PABSB256_MASK,
29862   IX86_BUILTIN_PABSB128_MASK,
29863   IX86_BUILTIN_PABSW256_MASK,
29864   IX86_BUILTIN_PABSW128_MASK,
29865   IX86_BUILTIN_VPERMILVARPD_MASK,
29866   IX86_BUILTIN_VPERMILVARPS_MASK,
29867   IX86_BUILTIN_VPERMILVARPD256_MASK,
29868   IX86_BUILTIN_VPERMILVARPS256_MASK,
29869   IX86_BUILTIN_VPERMILPD_MASK,
29870   IX86_BUILTIN_VPERMILPS_MASK,
29871   IX86_BUILTIN_VPERMILPD256_MASK,
29872   IX86_BUILTIN_VPERMILPS256_MASK,
29873   IX86_BUILTIN_BLENDMQ256,
29874   IX86_BUILTIN_BLENDMD256,
29875   IX86_BUILTIN_BLENDMPD256,
29876   IX86_BUILTIN_BLENDMPS256,
29877   IX86_BUILTIN_BLENDMQ128,
29878   IX86_BUILTIN_BLENDMD128,
29879   IX86_BUILTIN_BLENDMPD128,
29880   IX86_BUILTIN_BLENDMPS128,
29881   IX86_BUILTIN_BLENDMW256,
29882   IX86_BUILTIN_BLENDMB256,
29883   IX86_BUILTIN_BLENDMW128,
29884   IX86_BUILTIN_BLENDMB128,
29885   IX86_BUILTIN_PMULLD256_MASK,
29886   IX86_BUILTIN_PMULLD128_MASK,
29887   IX86_BUILTIN_PMULUDQ256_MASK,
29888   IX86_BUILTIN_PMULDQ256_MASK,
29889   IX86_BUILTIN_PMULDQ128_MASK,
29890   IX86_BUILTIN_PMULUDQ128_MASK,
29891   IX86_BUILTIN_CVTPD2PS256_MASK,
29892   IX86_BUILTIN_CVTPD2PS_MASK,
29893   IX86_BUILTIN_VPERMVARSI256_MASK,
29894   IX86_BUILTIN_VPERMVARDI256_MASK,
29895   IX86_BUILTIN_VPERMDI256_MASK,
29896   IX86_BUILTIN_CMPQ256,
29897   IX86_BUILTIN_CMPD256,
29898   IX86_BUILTIN_UCMPQ256,
29899   IX86_BUILTIN_UCMPD256,
29900   IX86_BUILTIN_CMPB256,
29901   IX86_BUILTIN_CMPW256,
29902   IX86_BUILTIN_UCMPB256,
29903   IX86_BUILTIN_UCMPW256,
29904   IX86_BUILTIN_CMPPD256_MASK,
29905   IX86_BUILTIN_CMPPS256_MASK,
29906   IX86_BUILTIN_CMPQ128,
29907   IX86_BUILTIN_CMPD128,
29908   IX86_BUILTIN_UCMPQ128,
29909   IX86_BUILTIN_UCMPD128,
29910   IX86_BUILTIN_CMPB128,
29911   IX86_BUILTIN_CMPW128,
29912   IX86_BUILTIN_UCMPB128,
29913   IX86_BUILTIN_UCMPW128,
29914   IX86_BUILTIN_CMPPD128_MASK,
29915   IX86_BUILTIN_CMPPS128_MASK,
29916
29917   IX86_BUILTIN_GATHER3SIV8SF,
29918   IX86_BUILTIN_GATHER3SIV4SF,
29919   IX86_BUILTIN_GATHER3SIV4DF,
29920   IX86_BUILTIN_GATHER3SIV2DF,
29921   IX86_BUILTIN_GATHER3DIV8SF,
29922   IX86_BUILTIN_GATHER3DIV4SF,
29923   IX86_BUILTIN_GATHER3DIV4DF,
29924   IX86_BUILTIN_GATHER3DIV2DF,
29925   IX86_BUILTIN_GATHER3SIV8SI,
29926   IX86_BUILTIN_GATHER3SIV4SI,
29927   IX86_BUILTIN_GATHER3SIV4DI,
29928   IX86_BUILTIN_GATHER3SIV2DI,
29929   IX86_BUILTIN_GATHER3DIV8SI,
29930   IX86_BUILTIN_GATHER3DIV4SI,
29931   IX86_BUILTIN_GATHER3DIV4DI,
29932   IX86_BUILTIN_GATHER3DIV2DI,
29933   IX86_BUILTIN_SCATTERSIV8SF,
29934   IX86_BUILTIN_SCATTERSIV4SF,
29935   IX86_BUILTIN_SCATTERSIV4DF,
29936   IX86_BUILTIN_SCATTERSIV2DF,
29937   IX86_BUILTIN_SCATTERDIV8SF,
29938   IX86_BUILTIN_SCATTERDIV4SF,
29939   IX86_BUILTIN_SCATTERDIV4DF,
29940   IX86_BUILTIN_SCATTERDIV2DF,
29941   IX86_BUILTIN_SCATTERSIV8SI,
29942   IX86_BUILTIN_SCATTERSIV4SI,
29943   IX86_BUILTIN_SCATTERSIV4DI,
29944   IX86_BUILTIN_SCATTERSIV2DI,
29945   IX86_BUILTIN_SCATTERDIV8SI,
29946   IX86_BUILTIN_SCATTERDIV4SI,
29947   IX86_BUILTIN_SCATTERDIV4DI,
29948   IX86_BUILTIN_SCATTERDIV2DI,
29949
29950   /* AVX512DQ.  */
29951   IX86_BUILTIN_RANGESD128,
29952   IX86_BUILTIN_RANGESS128,
29953   IX86_BUILTIN_KUNPCKWD,
29954   IX86_BUILTIN_KUNPCKDQ,
29955   IX86_BUILTIN_BROADCASTF32x2_512,
29956   IX86_BUILTIN_BROADCASTI32x2_512,
29957   IX86_BUILTIN_BROADCASTF64X2_512,
29958   IX86_BUILTIN_BROADCASTI64X2_512,
29959   IX86_BUILTIN_BROADCASTF32X8_512,
29960   IX86_BUILTIN_BROADCASTI32X8_512,
29961   IX86_BUILTIN_EXTRACTF64X2_512,
29962   IX86_BUILTIN_EXTRACTF32X8,
29963   IX86_BUILTIN_EXTRACTI64X2_512,
29964   IX86_BUILTIN_EXTRACTI32X8,
29965   IX86_BUILTIN_REDUCEPD512_MASK,
29966   IX86_BUILTIN_REDUCEPS512_MASK,
29967   IX86_BUILTIN_PMULLQ512,
29968   IX86_BUILTIN_XORPD512,
29969   IX86_BUILTIN_XORPS512,
29970   IX86_BUILTIN_ORPD512,
29971   IX86_BUILTIN_ORPS512,
29972   IX86_BUILTIN_ANDPD512,
29973   IX86_BUILTIN_ANDPS512,
29974   IX86_BUILTIN_ANDNPD512,
29975   IX86_BUILTIN_ANDNPS512,
29976   IX86_BUILTIN_INSERTF32X8,
29977   IX86_BUILTIN_INSERTI32X8,
29978   IX86_BUILTIN_INSERTF64X2_512,
29979   IX86_BUILTIN_INSERTI64X2_512,
29980   IX86_BUILTIN_FPCLASSPD512,
29981   IX86_BUILTIN_FPCLASSPS512,
29982   IX86_BUILTIN_CVTD2MASK512,
29983   IX86_BUILTIN_CVTQ2MASK512,
29984   IX86_BUILTIN_CVTMASK2D512,
29985   IX86_BUILTIN_CVTMASK2Q512,
29986   IX86_BUILTIN_CVTPD2QQ512,
29987   IX86_BUILTIN_CVTPS2QQ512,
29988   IX86_BUILTIN_CVTPD2UQQ512,
29989   IX86_BUILTIN_CVTPS2UQQ512,
29990   IX86_BUILTIN_CVTQQ2PS512,
29991   IX86_BUILTIN_CVTUQQ2PS512,
29992   IX86_BUILTIN_CVTQQ2PD512,
29993   IX86_BUILTIN_CVTUQQ2PD512,
29994   IX86_BUILTIN_CVTTPS2QQ512,
29995   IX86_BUILTIN_CVTTPS2UQQ512,
29996   IX86_BUILTIN_CVTTPD2QQ512,
29997   IX86_BUILTIN_CVTTPD2UQQ512,
29998   IX86_BUILTIN_RANGEPS512,
29999   IX86_BUILTIN_RANGEPD512,
30000
30001   /* AVX512BW.  */
30002   IX86_BUILTIN_PACKUSDW512,
30003   IX86_BUILTIN_PACKSSDW512,
30004   IX86_BUILTIN_LOADDQUHI512_MASK,
30005   IX86_BUILTIN_LOADDQUQI512_MASK,
30006   IX86_BUILTIN_PSLLDQ512,
30007   IX86_BUILTIN_PSRLDQ512,
30008   IX86_BUILTIN_STOREDQUHI512_MASK,
30009   IX86_BUILTIN_STOREDQUQI512_MASK,
30010   IX86_BUILTIN_PALIGNR512,
30011   IX86_BUILTIN_PALIGNR512_MASK,
30012   IX86_BUILTIN_MOVDQUHI512_MASK,
30013   IX86_BUILTIN_MOVDQUQI512_MASK,
30014   IX86_BUILTIN_PSADBW512,
30015   IX86_BUILTIN_DBPSADBW512,
30016   IX86_BUILTIN_PBROADCASTB512,
30017   IX86_BUILTIN_PBROADCASTB512_GPR,
30018   IX86_BUILTIN_PBROADCASTW512,
30019   IX86_BUILTIN_PBROADCASTW512_GPR,
30020   IX86_BUILTIN_PMOVSXBW512_MASK,
30021   IX86_BUILTIN_PMOVZXBW512_MASK,
30022   IX86_BUILTIN_VPERMVARHI512_MASK,
30023   IX86_BUILTIN_VPERMT2VARHI512,
30024   IX86_BUILTIN_VPERMT2VARHI512_MASKZ,
30025   IX86_BUILTIN_VPERMI2VARHI512,
30026   IX86_BUILTIN_PAVGB512,
30027   IX86_BUILTIN_PAVGW512,
30028   IX86_BUILTIN_PADDB512,
30029   IX86_BUILTIN_PSUBB512,
30030   IX86_BUILTIN_PSUBSB512,
30031   IX86_BUILTIN_PADDSB512,
30032   IX86_BUILTIN_PSUBUSB512,
30033   IX86_BUILTIN_PADDUSB512,
30034   IX86_BUILTIN_PSUBW512,
30035   IX86_BUILTIN_PADDW512,
30036   IX86_BUILTIN_PSUBSW512,
30037   IX86_BUILTIN_PADDSW512,
30038   IX86_BUILTIN_PSUBUSW512,
30039   IX86_BUILTIN_PADDUSW512,
30040   IX86_BUILTIN_PMAXUW512,
30041   IX86_BUILTIN_PMAXSW512,
30042   IX86_BUILTIN_PMINUW512,
30043   IX86_BUILTIN_PMINSW512,
30044   IX86_BUILTIN_PMAXUB512,
30045   IX86_BUILTIN_PMAXSB512,
30046   IX86_BUILTIN_PMINUB512,
30047   IX86_BUILTIN_PMINSB512,
30048   IX86_BUILTIN_PMOVWB512,
30049   IX86_BUILTIN_PMOVSWB512,
30050   IX86_BUILTIN_PMOVUSWB512,
30051   IX86_BUILTIN_PMULHRSW512_MASK,
30052   IX86_BUILTIN_PMULHUW512_MASK,
30053   IX86_BUILTIN_PMULHW512_MASK,
30054   IX86_BUILTIN_PMULLW512_MASK,
30055   IX86_BUILTIN_PSLLWI512_MASK,
30056   IX86_BUILTIN_PSLLW512_MASK,
30057   IX86_BUILTIN_PACKSSWB512,
30058   IX86_BUILTIN_PACKUSWB512,
30059   IX86_BUILTIN_PSRAVV32HI,
30060   IX86_BUILTIN_PMADDUBSW512_MASK,
30061   IX86_BUILTIN_PMADDWD512_MASK,
30062   IX86_BUILTIN_PSRLVV32HI,
30063   IX86_BUILTIN_PUNPCKHBW512,
30064   IX86_BUILTIN_PUNPCKHWD512,
30065   IX86_BUILTIN_PUNPCKLBW512,
30066   IX86_BUILTIN_PUNPCKLWD512,
30067   IX86_BUILTIN_PSHUFB512,
30068   IX86_BUILTIN_PSHUFHW512,
30069   IX86_BUILTIN_PSHUFLW512,
30070   IX86_BUILTIN_PSRAWI512,
30071   IX86_BUILTIN_PSRAW512,
30072   IX86_BUILTIN_PSRLWI512,
30073   IX86_BUILTIN_PSRLW512,
30074   IX86_BUILTIN_CVTB2MASK512,
30075   IX86_BUILTIN_CVTW2MASK512,
30076   IX86_BUILTIN_CVTMASK2B512,
30077   IX86_BUILTIN_CVTMASK2W512,
30078   IX86_BUILTIN_PCMPEQB512_MASK,
30079   IX86_BUILTIN_PCMPEQW512_MASK,
30080   IX86_BUILTIN_PCMPGTB512_MASK,
30081   IX86_BUILTIN_PCMPGTW512_MASK,
30082   IX86_BUILTIN_PTESTMB512,
30083   IX86_BUILTIN_PTESTMW512,
30084   IX86_BUILTIN_PTESTNMB512,
30085   IX86_BUILTIN_PTESTNMW512,
30086   IX86_BUILTIN_PSLLVV32HI,
30087   IX86_BUILTIN_PABSB512,
30088   IX86_BUILTIN_PABSW512,
30089   IX86_BUILTIN_BLENDMW512,
30090   IX86_BUILTIN_BLENDMB512,
30091   IX86_BUILTIN_CMPB512,
30092   IX86_BUILTIN_CMPW512,
30093   IX86_BUILTIN_UCMPB512,
30094   IX86_BUILTIN_UCMPW512,
30095
30096   /* Alternate 4 and 8 element gather/scatter for the vectorizer
30097      where all operands are 32-byte or 64-byte wide respectively.  */
30098   IX86_BUILTIN_GATHERALTSIV4DF,
30099   IX86_BUILTIN_GATHERALTDIV8SF,
30100   IX86_BUILTIN_GATHERALTSIV4DI,
30101   IX86_BUILTIN_GATHERALTDIV8SI,
30102   IX86_BUILTIN_GATHER3ALTDIV16SF,
30103   IX86_BUILTIN_GATHER3ALTDIV16SI,
30104   IX86_BUILTIN_GATHER3ALTSIV4DF,
30105   IX86_BUILTIN_GATHER3ALTDIV8SF,
30106   IX86_BUILTIN_GATHER3ALTSIV4DI,
30107   IX86_BUILTIN_GATHER3ALTDIV8SI,
30108   IX86_BUILTIN_GATHER3ALTSIV8DF,
30109   IX86_BUILTIN_GATHER3ALTSIV8DI,
30110   IX86_BUILTIN_GATHER3DIV16SF,
30111   IX86_BUILTIN_GATHER3DIV16SI,
30112   IX86_BUILTIN_GATHER3DIV8DF,
30113   IX86_BUILTIN_GATHER3DIV8DI,
30114   IX86_BUILTIN_GATHER3SIV16SF,
30115   IX86_BUILTIN_GATHER3SIV16SI,
30116   IX86_BUILTIN_GATHER3SIV8DF,
30117   IX86_BUILTIN_GATHER3SIV8DI,
30118   IX86_BUILTIN_SCATTERDIV16SF,
30119   IX86_BUILTIN_SCATTERDIV16SI,
30120   IX86_BUILTIN_SCATTERDIV8DF,
30121   IX86_BUILTIN_SCATTERDIV8DI,
30122   IX86_BUILTIN_SCATTERSIV16SF,
30123   IX86_BUILTIN_SCATTERSIV16SI,
30124   IX86_BUILTIN_SCATTERSIV8DF,
30125   IX86_BUILTIN_SCATTERSIV8DI,
30126
30127   /* AVX512PF */
30128   IX86_BUILTIN_GATHERPFQPD,
30129   IX86_BUILTIN_GATHERPFDPS,
30130   IX86_BUILTIN_GATHERPFDPD,
30131   IX86_BUILTIN_GATHERPFQPS,
30132   IX86_BUILTIN_SCATTERPFDPD,
30133   IX86_BUILTIN_SCATTERPFDPS,
30134   IX86_BUILTIN_SCATTERPFQPD,
30135   IX86_BUILTIN_SCATTERPFQPS,
30136
30137   /* AVX-512ER */
30138   IX86_BUILTIN_EXP2PD_MASK,
30139   IX86_BUILTIN_EXP2PS_MASK,
30140   IX86_BUILTIN_EXP2PS,
30141   IX86_BUILTIN_RCP28PD,
30142   IX86_BUILTIN_RCP28PS,
30143   IX86_BUILTIN_RCP28SD,
30144   IX86_BUILTIN_RCP28SS,
30145   IX86_BUILTIN_RSQRT28PD,
30146   IX86_BUILTIN_RSQRT28PS,
30147   IX86_BUILTIN_RSQRT28SD,
30148   IX86_BUILTIN_RSQRT28SS,
30149
30150   /* AVX-512IFMA */
30151   IX86_BUILTIN_VPMADD52LUQ512,
30152   IX86_BUILTIN_VPMADD52HUQ512,
30153   IX86_BUILTIN_VPMADD52LUQ256,
30154   IX86_BUILTIN_VPMADD52HUQ256,
30155   IX86_BUILTIN_VPMADD52LUQ128,
30156   IX86_BUILTIN_VPMADD52HUQ128,
30157   IX86_BUILTIN_VPMADD52LUQ512_MASKZ,
30158   IX86_BUILTIN_VPMADD52HUQ512_MASKZ,
30159   IX86_BUILTIN_VPMADD52LUQ256_MASKZ,
30160   IX86_BUILTIN_VPMADD52HUQ256_MASKZ,
30161   IX86_BUILTIN_VPMADD52LUQ128_MASKZ,
30162   IX86_BUILTIN_VPMADD52HUQ128_MASKZ,
30163
30164   /* AVX-512VBMI */
30165   IX86_BUILTIN_VPMULTISHIFTQB512,
30166   IX86_BUILTIN_VPMULTISHIFTQB256,
30167   IX86_BUILTIN_VPMULTISHIFTQB128,
30168   IX86_BUILTIN_VPERMVARQI512_MASK,
30169   IX86_BUILTIN_VPERMT2VARQI512,
30170   IX86_BUILTIN_VPERMT2VARQI512_MASKZ,
30171   IX86_BUILTIN_VPERMI2VARQI512,
30172   IX86_BUILTIN_VPERMVARQI256_MASK,
30173   IX86_BUILTIN_VPERMVARQI128_MASK,
30174   IX86_BUILTIN_VPERMT2VARQI256,
30175   IX86_BUILTIN_VPERMT2VARQI256_MASKZ,
30176   IX86_BUILTIN_VPERMT2VARQI128,
30177   IX86_BUILTIN_VPERMT2VARQI128_MASKZ,
30178   IX86_BUILTIN_VPERMI2VARQI256,
30179   IX86_BUILTIN_VPERMI2VARQI128,
30180
30181   /* SHA builtins.  */
30182   IX86_BUILTIN_SHA1MSG1,
30183   IX86_BUILTIN_SHA1MSG2,
30184   IX86_BUILTIN_SHA1NEXTE,
30185   IX86_BUILTIN_SHA1RNDS4,
30186   IX86_BUILTIN_SHA256MSG1,
30187   IX86_BUILTIN_SHA256MSG2,
30188   IX86_BUILTIN_SHA256RNDS2,
30189
30190   /* CLWB instructions.  */
30191   IX86_BUILTIN_CLWB,
30192
30193   /* PCOMMIT instructions.  */
30194   IX86_BUILTIN_PCOMMIT,
30195
30196   /* CLFLUSHOPT instructions.  */
30197   IX86_BUILTIN_CLFLUSHOPT,
30198
30199   /* TFmode support builtins.  */
30200   IX86_BUILTIN_INFQ,
30201   IX86_BUILTIN_HUGE_VALQ,
30202   IX86_BUILTIN_FABSQ,
30203   IX86_BUILTIN_COPYSIGNQ,
30204
30205   /* Vectorizer support builtins.  */
30206   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512,
30207   IX86_BUILTIN_CPYSGNPS,
30208   IX86_BUILTIN_CPYSGNPD,
30209   IX86_BUILTIN_CPYSGNPS256,
30210   IX86_BUILTIN_CPYSGNPS512,
30211   IX86_BUILTIN_CPYSGNPD256,
30212   IX86_BUILTIN_CPYSGNPD512,
30213   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512,
30214   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512,
30215
30216
30217   /* FMA4 instructions.  */
30218   IX86_BUILTIN_VFMADDSS,
30219   IX86_BUILTIN_VFMADDSD,
30220   IX86_BUILTIN_VFMADDPS,
30221   IX86_BUILTIN_VFMADDPD,
30222   IX86_BUILTIN_VFMADDPS256,
30223   IX86_BUILTIN_VFMADDPD256,
30224   IX86_BUILTIN_VFMADDSUBPS,
30225   IX86_BUILTIN_VFMADDSUBPD,
30226   IX86_BUILTIN_VFMADDSUBPS256,
30227   IX86_BUILTIN_VFMADDSUBPD256,
30228
30229   /* FMA3 instructions.  */
30230   IX86_BUILTIN_VFMADDSS3,
30231   IX86_BUILTIN_VFMADDSD3,
30232
30233   /* XOP instructions.  */
30234   IX86_BUILTIN_VPCMOV,
30235   IX86_BUILTIN_VPCMOV_V2DI,
30236   IX86_BUILTIN_VPCMOV_V4SI,
30237   IX86_BUILTIN_VPCMOV_V8HI,
30238   IX86_BUILTIN_VPCMOV_V16QI,
30239   IX86_BUILTIN_VPCMOV_V4SF,
30240   IX86_BUILTIN_VPCMOV_V2DF,
30241   IX86_BUILTIN_VPCMOV256,
30242   IX86_BUILTIN_VPCMOV_V4DI256,
30243   IX86_BUILTIN_VPCMOV_V8SI256,
30244   IX86_BUILTIN_VPCMOV_V16HI256,
30245   IX86_BUILTIN_VPCMOV_V32QI256,
30246   IX86_BUILTIN_VPCMOV_V8SF256,
30247   IX86_BUILTIN_VPCMOV_V4DF256,
30248
30249   IX86_BUILTIN_VPPERM,
30250
30251   IX86_BUILTIN_VPMACSSWW,
30252   IX86_BUILTIN_VPMACSWW,
30253   IX86_BUILTIN_VPMACSSWD,
30254   IX86_BUILTIN_VPMACSWD,
30255   IX86_BUILTIN_VPMACSSDD,
30256   IX86_BUILTIN_VPMACSDD,
30257   IX86_BUILTIN_VPMACSSDQL,
30258   IX86_BUILTIN_VPMACSSDQH,
30259   IX86_BUILTIN_VPMACSDQL,
30260   IX86_BUILTIN_VPMACSDQH,
30261   IX86_BUILTIN_VPMADCSSWD,
30262   IX86_BUILTIN_VPMADCSWD,
30263
30264   IX86_BUILTIN_VPHADDBW,
30265   IX86_BUILTIN_VPHADDBD,
30266   IX86_BUILTIN_VPHADDBQ,
30267   IX86_BUILTIN_VPHADDWD,
30268   IX86_BUILTIN_VPHADDWQ,
30269   IX86_BUILTIN_VPHADDDQ,
30270   IX86_BUILTIN_VPHADDUBW,
30271   IX86_BUILTIN_VPHADDUBD,
30272   IX86_BUILTIN_VPHADDUBQ,
30273   IX86_BUILTIN_VPHADDUWD,
30274   IX86_BUILTIN_VPHADDUWQ,
30275   IX86_BUILTIN_VPHADDUDQ,
30276   IX86_BUILTIN_VPHSUBBW,
30277   IX86_BUILTIN_VPHSUBWD,
30278   IX86_BUILTIN_VPHSUBDQ,
30279
30280   IX86_BUILTIN_VPROTB,
30281   IX86_BUILTIN_VPROTW,
30282   IX86_BUILTIN_VPROTD,
30283   IX86_BUILTIN_VPROTQ,
30284   IX86_BUILTIN_VPROTB_IMM,
30285   IX86_BUILTIN_VPROTW_IMM,
30286   IX86_BUILTIN_VPROTD_IMM,
30287   IX86_BUILTIN_VPROTQ_IMM,
30288
30289   IX86_BUILTIN_VPSHLB,
30290   IX86_BUILTIN_VPSHLW,
30291   IX86_BUILTIN_VPSHLD,
30292   IX86_BUILTIN_VPSHLQ,
30293   IX86_BUILTIN_VPSHAB,
30294   IX86_BUILTIN_VPSHAW,
30295   IX86_BUILTIN_VPSHAD,
30296   IX86_BUILTIN_VPSHAQ,
30297
30298   IX86_BUILTIN_VFRCZSS,
30299   IX86_BUILTIN_VFRCZSD,
30300   IX86_BUILTIN_VFRCZPS,
30301   IX86_BUILTIN_VFRCZPD,
30302   IX86_BUILTIN_VFRCZPS256,
30303   IX86_BUILTIN_VFRCZPD256,
30304
30305   IX86_BUILTIN_VPCOMEQUB,
30306   IX86_BUILTIN_VPCOMNEUB,
30307   IX86_BUILTIN_VPCOMLTUB,
30308   IX86_BUILTIN_VPCOMLEUB,
30309   IX86_BUILTIN_VPCOMGTUB,
30310   IX86_BUILTIN_VPCOMGEUB,
30311   IX86_BUILTIN_VPCOMFALSEUB,
30312   IX86_BUILTIN_VPCOMTRUEUB,
30313
30314   IX86_BUILTIN_VPCOMEQUW,
30315   IX86_BUILTIN_VPCOMNEUW,
30316   IX86_BUILTIN_VPCOMLTUW,
30317   IX86_BUILTIN_VPCOMLEUW,
30318   IX86_BUILTIN_VPCOMGTUW,
30319   IX86_BUILTIN_VPCOMGEUW,
30320   IX86_BUILTIN_VPCOMFALSEUW,
30321   IX86_BUILTIN_VPCOMTRUEUW,
30322
30323   IX86_BUILTIN_VPCOMEQUD,
30324   IX86_BUILTIN_VPCOMNEUD,
30325   IX86_BUILTIN_VPCOMLTUD,
30326   IX86_BUILTIN_VPCOMLEUD,
30327   IX86_BUILTIN_VPCOMGTUD,
30328   IX86_BUILTIN_VPCOMGEUD,
30329   IX86_BUILTIN_VPCOMFALSEUD,
30330   IX86_BUILTIN_VPCOMTRUEUD,
30331
30332   IX86_BUILTIN_VPCOMEQUQ,
30333   IX86_BUILTIN_VPCOMNEUQ,
30334   IX86_BUILTIN_VPCOMLTUQ,
30335   IX86_BUILTIN_VPCOMLEUQ,
30336   IX86_BUILTIN_VPCOMGTUQ,
30337   IX86_BUILTIN_VPCOMGEUQ,
30338   IX86_BUILTIN_VPCOMFALSEUQ,
30339   IX86_BUILTIN_VPCOMTRUEUQ,
30340
30341   IX86_BUILTIN_VPCOMEQB,
30342   IX86_BUILTIN_VPCOMNEB,
30343   IX86_BUILTIN_VPCOMLTB,
30344   IX86_BUILTIN_VPCOMLEB,
30345   IX86_BUILTIN_VPCOMGTB,
30346   IX86_BUILTIN_VPCOMGEB,
30347   IX86_BUILTIN_VPCOMFALSEB,
30348   IX86_BUILTIN_VPCOMTRUEB,
30349
30350   IX86_BUILTIN_VPCOMEQW,
30351   IX86_BUILTIN_VPCOMNEW,
30352   IX86_BUILTIN_VPCOMLTW,
30353   IX86_BUILTIN_VPCOMLEW,
30354   IX86_BUILTIN_VPCOMGTW,
30355   IX86_BUILTIN_VPCOMGEW,
30356   IX86_BUILTIN_VPCOMFALSEW,
30357   IX86_BUILTIN_VPCOMTRUEW,
30358
30359   IX86_BUILTIN_VPCOMEQD,
30360   IX86_BUILTIN_VPCOMNED,
30361   IX86_BUILTIN_VPCOMLTD,
30362   IX86_BUILTIN_VPCOMLED,
30363   IX86_BUILTIN_VPCOMGTD,
30364   IX86_BUILTIN_VPCOMGED,
30365   IX86_BUILTIN_VPCOMFALSED,
30366   IX86_BUILTIN_VPCOMTRUED,
30367
30368   IX86_BUILTIN_VPCOMEQQ,
30369   IX86_BUILTIN_VPCOMNEQ,
30370   IX86_BUILTIN_VPCOMLTQ,
30371   IX86_BUILTIN_VPCOMLEQ,
30372   IX86_BUILTIN_VPCOMGTQ,
30373   IX86_BUILTIN_VPCOMGEQ,
30374   IX86_BUILTIN_VPCOMFALSEQ,
30375   IX86_BUILTIN_VPCOMTRUEQ,
30376
30377   /* LWP instructions.  */
30378   IX86_BUILTIN_LLWPCB,
30379   IX86_BUILTIN_SLWPCB,
30380   IX86_BUILTIN_LWPVAL32,
30381   IX86_BUILTIN_LWPVAL64,
30382   IX86_BUILTIN_LWPINS32,
30383   IX86_BUILTIN_LWPINS64,
30384
30385   IX86_BUILTIN_CLZS,
30386
30387   /* RTM */
30388   IX86_BUILTIN_XBEGIN,
30389   IX86_BUILTIN_XEND,
30390   IX86_BUILTIN_XABORT,
30391   IX86_BUILTIN_XTEST,
30392
30393   /* MPX */
30394   IX86_BUILTIN_BNDMK,
30395   IX86_BUILTIN_BNDSTX,
30396   IX86_BUILTIN_BNDLDX,
30397   IX86_BUILTIN_BNDCL,
30398   IX86_BUILTIN_BNDCU,
30399   IX86_BUILTIN_BNDRET,
30400   IX86_BUILTIN_BNDNARROW,
30401   IX86_BUILTIN_BNDINT,
30402   IX86_BUILTIN_SIZEOF,
30403   IX86_BUILTIN_BNDLOWER,
30404   IX86_BUILTIN_BNDUPPER,
30405
30406   /* BMI instructions.  */
30407   IX86_BUILTIN_BEXTR32,
30408   IX86_BUILTIN_BEXTR64,
30409   IX86_BUILTIN_CTZS,
30410
30411   /* TBM instructions.  */
30412   IX86_BUILTIN_BEXTRI32,
30413   IX86_BUILTIN_BEXTRI64,
30414
30415   /* BMI2 instructions. */
30416   IX86_BUILTIN_BZHI32,
30417   IX86_BUILTIN_BZHI64,
30418   IX86_BUILTIN_PDEP32,
30419   IX86_BUILTIN_PDEP64,
30420   IX86_BUILTIN_PEXT32,
30421   IX86_BUILTIN_PEXT64,
30422
30423   /* ADX instructions.  */
30424   IX86_BUILTIN_ADDCARRYX32,
30425   IX86_BUILTIN_ADDCARRYX64,
30426
30427   /* SBB instructions.  */
30428   IX86_BUILTIN_SBB32,
30429   IX86_BUILTIN_SBB64,
30430
30431   /* FSGSBASE instructions.  */
30432   IX86_BUILTIN_RDFSBASE32,
30433   IX86_BUILTIN_RDFSBASE64,
30434   IX86_BUILTIN_RDGSBASE32,
30435   IX86_BUILTIN_RDGSBASE64,
30436   IX86_BUILTIN_WRFSBASE32,
30437   IX86_BUILTIN_WRFSBASE64,
30438   IX86_BUILTIN_WRGSBASE32,
30439   IX86_BUILTIN_WRGSBASE64,
30440
30441   /* RDRND instructions.  */
30442   IX86_BUILTIN_RDRAND16_STEP,
30443   IX86_BUILTIN_RDRAND32_STEP,
30444   IX86_BUILTIN_RDRAND64_STEP,
30445
30446   /* RDSEED instructions.  */
30447   IX86_BUILTIN_RDSEED16_STEP,
30448   IX86_BUILTIN_RDSEED32_STEP,
30449   IX86_BUILTIN_RDSEED64_STEP,
30450
30451   /* F16C instructions.  */
30452   IX86_BUILTIN_CVTPH2PS,
30453   IX86_BUILTIN_CVTPH2PS256,
30454   IX86_BUILTIN_CVTPS2PH,
30455   IX86_BUILTIN_CVTPS2PH256,
30456
30457   /* CFString built-in for darwin */
30458   IX86_BUILTIN_CFSTRING,
30459
30460   /* Builtins to get CPU type and supported features. */
30461   IX86_BUILTIN_CPU_INIT,
30462   IX86_BUILTIN_CPU_IS,
30463   IX86_BUILTIN_CPU_SUPPORTS,
30464
30465   /* Read/write FLAGS register built-ins.  */
30466   IX86_BUILTIN_READ_FLAGS,
30467   IX86_BUILTIN_WRITE_FLAGS,
30468
30469   IX86_BUILTIN_MAX
30470 };
30471
30472 /* Table for the ix86 builtin decls.  */
30473 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
30474
30475 /* Table of all of the builtin functions that are possible with different ISA's
30476    but are waiting to be built until a function is declared to use that
30477    ISA.  */
30478 struct builtin_isa {
30479   const char *name;             /* function name */
30480   enum ix86_builtin_func_type tcode; /* type to use in the declaration */
30481   HOST_WIDE_INT isa;            /* isa_flags this builtin is defined for */
30482   bool const_p;                 /* true if the declaration is constant */
30483   bool leaf_p;                  /* true if the declaration has leaf attribute */
30484   bool nothrow_p;               /* true if the declaration has nothrow attribute */
30485   bool set_and_not_built_p;
30486 };
30487
30488 static struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
30489
30490
30491 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
30492    of which isa_flags to use in the ix86_builtins_isa array.  Stores the
30493    function decl in the ix86_builtins array.  Returns the function decl or
30494    NULL_TREE, if the builtin was not added.
30495
30496    If the front end has a special hook for builtin functions, delay adding
30497    builtin functions that aren't in the current ISA until the ISA is changed
30498    with function specific optimization.  Doing so, can save about 300K for the
30499    default compiler.  When the builtin is expanded, check at that time whether
30500    it is valid.
30501
30502    If the front end doesn't have a special hook, record all builtins, even if
30503    it isn't an instruction set in the current ISA in case the user uses
30504    function specific options for a different ISA, so that we don't get scope
30505    errors if a builtin is added in the middle of a function scope.  */
30506
30507 static inline tree
30508 def_builtin (HOST_WIDE_INT mask, const char *name,
30509              enum ix86_builtin_func_type tcode,
30510              enum ix86_builtins code)
30511 {
30512   tree decl = NULL_TREE;
30513
30514   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
30515     {
30516       ix86_builtins_isa[(int) code].isa = mask;
30517
30518       mask &= ~OPTION_MASK_ISA_64BIT;
30519       if (mask == 0
30520           || (mask & ix86_isa_flags) != 0
30521           || (lang_hooks.builtin_function
30522               == lang_hooks.builtin_function_ext_scope))
30523
30524         {
30525           tree type = ix86_get_builtin_func_type (tcode);
30526           decl = add_builtin_function (name, type, code, BUILT_IN_MD,
30527                                        NULL, NULL_TREE);
30528           ix86_builtins[(int) code] = decl;
30529           ix86_builtins_isa[(int) code].set_and_not_built_p = false;
30530         }
30531       else
30532         {
30533           ix86_builtins[(int) code] = NULL_TREE;
30534           ix86_builtins_isa[(int) code].tcode = tcode;
30535           ix86_builtins_isa[(int) code].name = name;
30536           ix86_builtins_isa[(int) code].leaf_p = false;
30537           ix86_builtins_isa[(int) code].nothrow_p = false;
30538           ix86_builtins_isa[(int) code].const_p = false;
30539           ix86_builtins_isa[(int) code].set_and_not_built_p = true;
30540         }
30541     }
30542
30543   return decl;
30544 }
30545
30546 /* Like def_builtin, but also marks the function decl "const".  */
30547
30548 static inline tree
30549 def_builtin_const (HOST_WIDE_INT mask, const char *name,
30550                    enum ix86_builtin_func_type tcode, enum ix86_builtins code)
30551 {
30552   tree decl = def_builtin (mask, name, tcode, code);
30553   if (decl)
30554     TREE_READONLY (decl) = 1;
30555   else
30556     ix86_builtins_isa[(int) code].const_p = true;
30557
30558   return decl;
30559 }
30560
30561 /* Add any new builtin functions for a given ISA that may not have been
30562    declared.  This saves a bit of space compared to adding all of the
30563    declarations to the tree, even if we didn't use them.  */
30564
30565 static void
30566 ix86_add_new_builtins (HOST_WIDE_INT isa)
30567 {
30568   int i;
30569
30570   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
30571     {
30572       if ((ix86_builtins_isa[i].isa & isa) != 0
30573           && ix86_builtins_isa[i].set_and_not_built_p)
30574         {
30575           tree decl, type;
30576
30577           /* Don't define the builtin again.  */
30578           ix86_builtins_isa[i].set_and_not_built_p = false;
30579
30580           type = ix86_get_builtin_func_type (ix86_builtins_isa[i].tcode);
30581           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
30582                                                  type, i, BUILT_IN_MD, NULL,
30583                                                  NULL_TREE);
30584
30585           ix86_builtins[i] = decl;
30586           if (ix86_builtins_isa[i].const_p)
30587             TREE_READONLY (decl) = 1;
30588           if (ix86_builtins_isa[i].leaf_p)
30589             DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
30590                                                       NULL_TREE);
30591           if (ix86_builtins_isa[i].nothrow_p)
30592             TREE_NOTHROW (decl) = 1;
30593         }
30594     }
30595 }
30596
30597 /* Bits for builtin_description.flag.  */
30598
30599 /* Set when we don't support the comparison natively, and should
30600    swap_comparison in order to support it.  */
30601 #define BUILTIN_DESC_SWAP_OPERANDS      1
30602
30603 struct builtin_description
30604 {
30605   const HOST_WIDE_INT mask;
30606   const enum insn_code icode;
30607   const char *const name;
30608   const enum ix86_builtins code;
30609   const enum rtx_code comparison;
30610   const int flag;
30611 };
30612
30613 static const struct builtin_description bdesc_comi[] =
30614 {
30615   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
30616   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
30617   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
30618   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
30619   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
30620   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
30621   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
30622   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
30623   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
30624   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
30625   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
30626   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
30627   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
30628   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
30629   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
30630   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
30631   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
30632   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
30633   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
30634   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
30635   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
30636   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
30637   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
30638   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
30639 };
30640
30641 static const struct builtin_description bdesc_pcmpestr[] =
30642 {
30643   /* SSE4.2 */
30644   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
30645   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
30646   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
30647   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
30648   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
30649   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
30650   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
30651 };
30652
30653 static const struct builtin_description bdesc_pcmpistr[] =
30654 {
30655   /* SSE4.2 */
30656   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
30657   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
30658   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
30659   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
30660   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
30661   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
30662   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
30663 };
30664
30665 /* Special builtins with variable number of arguments.  */
30666 static const struct builtin_description bdesc_special_args[] =
30667 {
30668   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdtsc", IX86_BUILTIN_RDTSC, UNKNOWN, (int) UINT64_FTYPE_VOID },
30669   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdtscp", IX86_BUILTIN_RDTSCP, UNKNOWN, (int) UINT64_FTYPE_PUNSIGNED },
30670   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_pause, "__builtin_ia32_pause", IX86_BUILTIN_PAUSE, UNKNOWN, (int) VOID_FTYPE_VOID },
30671
30672   /* 80387 (for use internally for atomic compound assignment).  */
30673   { 0, CODE_FOR_fnstenv, "__builtin_ia32_fnstenv", IX86_BUILTIN_FNSTENV, UNKNOWN, (int) VOID_FTYPE_PVOID },
30674   { 0, CODE_FOR_fldenv, "__builtin_ia32_fldenv", IX86_BUILTIN_FLDENV, UNKNOWN, (int) VOID_FTYPE_PCVOID },
30675   { 0, CODE_FOR_fnstsw, "__builtin_ia32_fnstsw", IX86_BUILTIN_FNSTSW, UNKNOWN, (int) USHORT_FTYPE_VOID },
30676   { 0, CODE_FOR_fnclex, "__builtin_ia32_fnclex", IX86_BUILTIN_FNCLEX, UNKNOWN, (int) VOID_FTYPE_VOID },
30677
30678   /* MMX */
30679   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
30680
30681   /* 3DNow! */
30682   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
30683
30684   /* FXSR, XSAVE, XSAVEOPT, XSAVEC and XSAVES.  */
30685   { OPTION_MASK_ISA_FXSR, CODE_FOR_nothing, "__builtin_ia32_fxsave", IX86_BUILTIN_FXSAVE, UNKNOWN, (int) VOID_FTYPE_PVOID },
30686   { OPTION_MASK_ISA_FXSR, CODE_FOR_nothing, "__builtin_ia32_fxrstor", IX86_BUILTIN_FXRSTOR, UNKNOWN, (int) VOID_FTYPE_PVOID },
30687   { OPTION_MASK_ISA_XSAVE, CODE_FOR_nothing, "__builtin_ia32_xsave", IX86_BUILTIN_XSAVE, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30688   { OPTION_MASK_ISA_XSAVE, CODE_FOR_nothing, "__builtin_ia32_xrstor", IX86_BUILTIN_XRSTOR, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30689   { OPTION_MASK_ISA_XSAVEOPT, CODE_FOR_nothing, "__builtin_ia32_xsaveopt", IX86_BUILTIN_XSAVEOPT, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30690   { OPTION_MASK_ISA_XSAVES, CODE_FOR_nothing, "__builtin_ia32_xsaves", IX86_BUILTIN_XSAVES, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30691   { OPTION_MASK_ISA_XSAVES, CODE_FOR_nothing, "__builtin_ia32_xrstors", IX86_BUILTIN_XRSTORS, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30692   { OPTION_MASK_ISA_XSAVEC, CODE_FOR_nothing, "__builtin_ia32_xsavec", IX86_BUILTIN_XSAVEC, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30693
30694   { OPTION_MASK_ISA_FXSR | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_fxsave64", IX86_BUILTIN_FXSAVE64, UNKNOWN, (int) VOID_FTYPE_PVOID },
30695   { OPTION_MASK_ISA_FXSR | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_fxrstor64", IX86_BUILTIN_FXRSTOR64, UNKNOWN, (int) VOID_FTYPE_PVOID },
30696   { OPTION_MASK_ISA_XSAVE | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsave64", IX86_BUILTIN_XSAVE64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30697   { OPTION_MASK_ISA_XSAVE | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xrstor64", IX86_BUILTIN_XRSTOR64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30698   { OPTION_MASK_ISA_XSAVEOPT | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsaveopt64", IX86_BUILTIN_XSAVEOPT64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30699   { OPTION_MASK_ISA_XSAVES | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsaves64", IX86_BUILTIN_XSAVES64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30700   { OPTION_MASK_ISA_XSAVES | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xrstors64", IX86_BUILTIN_XRSTORS64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30701   { OPTION_MASK_ISA_XSAVEC | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsavec64", IX86_BUILTIN_XSAVEC64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30702
30703   /* SSE */
30704   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storeups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30705   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30706   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
30707
30708   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
30709   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
30710   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
30711   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
30712
30713   /* SSE or 3DNow!A  */
30714   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30715   { 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 },
30716
30717   /* SSE2 */
30718   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30719   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30720   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_storeupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30721   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_storedquv16qi, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
30722   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30723   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
30724   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntisi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
30725   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_movntidi, "__builtin_ia32_movnti64", IX86_BUILTIN_MOVNTI64, UNKNOWN, (int) VOID_FTYPE_PLONGLONG_LONGLONG },
30726   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
30727   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loaddquv16qi, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
30728
30729   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
30730   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
30731
30732   /* SSE3 */
30733   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
30734
30735   /* SSE4.1 */
30736   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
30737
30738   /* SSE4A */
30739   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30740   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30741
30742   /* AVX */
30743   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
30744   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, "__builtin_ia32_vzeroupper", IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
30745
30746   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv4sf, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
30747   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv4df, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
30748   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv8sf, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
30749   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_v4df, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
30750   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_v8sf, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
30751
30752   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loadupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
30753   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loadups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
30754   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storeupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
30755   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storeups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
30756   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loaddquv32qi, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
30757   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storedquv32qi, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
30758   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
30759
30760   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
30761   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
30762   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
30763
30764   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DI },
30765   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SI },
30766   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DI },
30767   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SI },
30768   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DI_V2DF },
30769   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SI_V4SF },
30770   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DI_V4DF },
30771   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SI_V8SF },
30772
30773   /* AVX2 */
30774   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_movntdqa, "__builtin_ia32_movntdqa256", IX86_BUILTIN_MOVNTDQA256, UNKNOWN, (int) V4DI_FTYPE_PV4DI },
30775   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadd, "__builtin_ia32_maskloadd", IX86_BUILTIN_MASKLOADD, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI },
30776   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadq, "__builtin_ia32_maskloadq", IX86_BUILTIN_MASKLOADQ, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI },
30777   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadd256, "__builtin_ia32_maskloadd256", IX86_BUILTIN_MASKLOADD256, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI },
30778   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadq256, "__builtin_ia32_maskloadq256", IX86_BUILTIN_MASKLOADQ256, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI },
30779   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstored, "__builtin_ia32_maskstored", IX86_BUILTIN_MASKSTORED, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_V4SI },
30780   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstoreq, "__builtin_ia32_maskstoreq", IX86_BUILTIN_MASKSTOREQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_V2DI },
30781   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstored256, "__builtin_ia32_maskstored256", IX86_BUILTIN_MASKSTORED256, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_V8SI },
30782   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstoreq256, "__builtin_ia32_maskstoreq256", IX86_BUILTIN_MASKSTOREQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_V4DI },
30783
30784   /* AVX512F */
30785   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev16sf_mask, "__builtin_ia32_compressstoresf512_mask", IX86_BUILTIN_COMPRESSPSSTORE512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30786   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev16si_mask, "__builtin_ia32_compressstoresi512_mask", IX86_BUILTIN_PCOMPRESSDSTORE512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30787   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev8df_mask, "__builtin_ia32_compressstoredf512_mask", IX86_BUILTIN_COMPRESSPDSTORE512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30788   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev8di_mask, "__builtin_ia32_compressstoredi512_mask", IX86_BUILTIN_PCOMPRESSQSTORE512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30789   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_mask, "__builtin_ia32_expandloadsf512_mask", IX86_BUILTIN_EXPANDPSLOAD512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30790   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_maskz, "__builtin_ia32_expandloadsf512_maskz", IX86_BUILTIN_EXPANDPSLOAD512Z, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30791   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_mask, "__builtin_ia32_expandloadsi512_mask", IX86_BUILTIN_PEXPANDDLOAD512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30792   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_maskz, "__builtin_ia32_expandloadsi512_maskz", IX86_BUILTIN_PEXPANDDLOAD512Z, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30793   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_mask, "__builtin_ia32_expandloaddf512_mask", IX86_BUILTIN_EXPANDPDLOAD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30794   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_maskz, "__builtin_ia32_expandloaddf512_maskz", IX86_BUILTIN_EXPANDPDLOAD512Z, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30795   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_mask, "__builtin_ia32_expandloaddi512_mask", IX86_BUILTIN_PEXPANDQLOAD512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30796   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_maskz, "__builtin_ia32_expandloaddi512_maskz", IX86_BUILTIN_PEXPANDQLOAD512Z, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30797   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loaddquv16si_mask, "__builtin_ia32_loaddqusi512_mask", IX86_BUILTIN_LOADDQUSI512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30798   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loaddquv8di_mask, "__builtin_ia32_loaddqudi512_mask", IX86_BUILTIN_LOADDQUDI512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30799   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadupd512_mask, "__builtin_ia32_loadupd512_mask", IX86_BUILTIN_LOADUPD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30800   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadups512_mask, "__builtin_ia32_loadups512_mask", IX86_BUILTIN_LOADUPS512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30801   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16sf_mask, "__builtin_ia32_loadaps512_mask", IX86_BUILTIN_LOADAPS512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30802   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16si_mask, "__builtin_ia32_movdqa32load512_mask", IX86_BUILTIN_MOVDQA32LOAD512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30803   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8df_mask, "__builtin_ia32_loadapd512_mask", IX86_BUILTIN_LOADAPD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30804   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8di_mask, "__builtin_ia32_movdqa64load512_mask", IX86_BUILTIN_MOVDQA64LOAD512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30805   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv16sf, "__builtin_ia32_movntps512", IX86_BUILTIN_MOVNTPS512, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V16SF },
30806   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv8df, "__builtin_ia32_movntpd512", IX86_BUILTIN_MOVNTPD512, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V8DF },
30807   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv8di, "__builtin_ia32_movntdq512", IX86_BUILTIN_MOVNTDQ512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI },
30808   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntdqa, "__builtin_ia32_movntdqa512", IX86_BUILTIN_MOVNTDQA512, UNKNOWN, (int) V8DI_FTYPE_PV8DI },
30809   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storedquv16si_mask, "__builtin_ia32_storedqusi512_mask", IX86_BUILTIN_STOREDQUSI512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30810   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storedquv8di_mask, "__builtin_ia32_storedqudi512_mask", IX86_BUILTIN_STOREDQUDI512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30811   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storeupd512_mask, "__builtin_ia32_storeupd512_mask", IX86_BUILTIN_STOREUPD512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30812   { 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 },
30813   { 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 },
30814   { 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 },
30815   { 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 },
30816   { 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 },
30817   { 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 },
30818   { 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 },
30819   { 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 },
30820   { 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 },
30821   { 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 },
30822   { 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 },
30823   { 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 },
30824   { 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 },
30825   { 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 },
30826   { 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 },
30827   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storeups512_mask, "__builtin_ia32_storeups512_mask", IX86_BUILTIN_STOREUPS512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30828   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev16sf_mask, "__builtin_ia32_storeaps512_mask", IX86_BUILTIN_STOREAPS512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30829   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev16si_mask, "__builtin_ia32_movdqa32store512_mask", IX86_BUILTIN_MOVDQA32STORE512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30830   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev8df_mask, "__builtin_ia32_storeapd512_mask", IX86_BUILTIN_STOREAPD512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30831   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev8di_mask, "__builtin_ia32_movdqa64store512_mask", IX86_BUILTIN_MOVDQA64STORE512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30832
30833   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_llwpcb, "__builtin_ia32_llwpcb", IX86_BUILTIN_LLWPCB, UNKNOWN, (int) VOID_FTYPE_PVOID },
30834   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_slwpcb, "__builtin_ia32_slwpcb", IX86_BUILTIN_SLWPCB, UNKNOWN, (int) PVOID_FTYPE_VOID },
30835   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpvalsi3, "__builtin_ia32_lwpval32", IX86_BUILTIN_LWPVAL32, UNKNOWN, (int) VOID_FTYPE_UINT_UINT_UINT },
30836   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpvaldi3, "__builtin_ia32_lwpval64", IX86_BUILTIN_LWPVAL64, UNKNOWN, (int) VOID_FTYPE_UINT64_UINT_UINT },
30837   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinssi3, "__builtin_ia32_lwpins32", IX86_BUILTIN_LWPINS32, UNKNOWN, (int) UCHAR_FTYPE_UINT_UINT_UINT },
30838   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinsdi3, "__builtin_ia32_lwpins64", IX86_BUILTIN_LWPINS64, UNKNOWN, (int) UCHAR_FTYPE_UINT64_UINT_UINT },
30839
30840   /* FSGSBASE */
30841   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdfsbasesi, "__builtin_ia32_rdfsbase32", IX86_BUILTIN_RDFSBASE32, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30842   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdfsbasedi, "__builtin_ia32_rdfsbase64", IX86_BUILTIN_RDFSBASE64, UNKNOWN, (int) UINT64_FTYPE_VOID },
30843   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdgsbasesi, "__builtin_ia32_rdgsbase32", IX86_BUILTIN_RDGSBASE32, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30844   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdgsbasedi, "__builtin_ia32_rdgsbase64", IX86_BUILTIN_RDGSBASE64, UNKNOWN, (int) UINT64_FTYPE_VOID },
30845   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrfsbasesi, "__builtin_ia32_wrfsbase32", IX86_BUILTIN_WRFSBASE32, UNKNOWN, (int) VOID_FTYPE_UNSIGNED },
30846   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrfsbasedi, "__builtin_ia32_wrfsbase64", IX86_BUILTIN_WRFSBASE64, UNKNOWN, (int) VOID_FTYPE_UINT64 },
30847   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrgsbasesi, "__builtin_ia32_wrgsbase32", IX86_BUILTIN_WRGSBASE32, UNKNOWN, (int) VOID_FTYPE_UNSIGNED },
30848   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrgsbasedi, "__builtin_ia32_wrgsbase64", IX86_BUILTIN_WRGSBASE64, UNKNOWN, (int) VOID_FTYPE_UINT64 },
30849
30850   /* RTM */
30851   { OPTION_MASK_ISA_RTM, CODE_FOR_xbegin, "__builtin_ia32_xbegin", IX86_BUILTIN_XBEGIN, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30852   { OPTION_MASK_ISA_RTM, CODE_FOR_xend, "__builtin_ia32_xend", IX86_BUILTIN_XEND, UNKNOWN, (int) VOID_FTYPE_VOID },
30853   { OPTION_MASK_ISA_RTM, CODE_FOR_xtest, "__builtin_ia32_xtest", IX86_BUILTIN_XTEST, UNKNOWN, (int) INT_FTYPE_VOID },
30854
30855   /* AVX512BW */
30856   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_loaddquv32hi_mask, "__builtin_ia32_loaddquhi512_mask", IX86_BUILTIN_LOADDQUHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_PCV32HI_V32HI_SI },
30857   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_loaddquv64qi_mask, "__builtin_ia32_loaddquqi512_mask", IX86_BUILTIN_LOADDQUQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_PCV64QI_V64QI_DI },
30858   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_storedquv32hi_mask, "__builtin_ia32_storedquhi512_mask", IX86_BUILTIN_STOREDQUHI512_MASK, UNKNOWN, (int) VOID_FTYPE_PV32HI_V32HI_SI },
30859   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_storedquv64qi_mask, "__builtin_ia32_storedquqi512_mask", IX86_BUILTIN_STOREDQUQI512_MASK, UNKNOWN, (int) VOID_FTYPE_PV64QI_V64QI_DI },
30860
30861   /* AVX512VL */
30862   { 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 },
30863   { 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 },
30864   { 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 },
30865   { 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 },
30866   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4di_mask, "__builtin_ia32_movdqa64load256_mask", IX86_BUILTIN_MOVDQA64LOAD256_MASK, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30867   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2di_mask, "__builtin_ia32_movdqa64load128_mask", IX86_BUILTIN_MOVDQA64LOAD128_MASK, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30868   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8si_mask, "__builtin_ia32_movdqa32load256_mask", IX86_BUILTIN_MOVDQA32LOAD256_MASK, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30869   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4si_mask, "__builtin_ia32_movdqa32load128_mask", IX86_BUILTIN_MOVDQA32LOAD128_MASK, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30870   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4di_mask, "__builtin_ia32_movdqa64store256_mask", IX86_BUILTIN_MOVDQA64STORE256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
30871   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev2di_mask, "__builtin_ia32_movdqa64store128_mask", IX86_BUILTIN_MOVDQA64STORE128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
30872   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev8si_mask, "__builtin_ia32_movdqa32store256_mask", IX86_BUILTIN_MOVDQA32STORE256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
30873   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4si_mask, "__builtin_ia32_movdqa32store128_mask", IX86_BUILTIN_MOVDQA32STORE128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
30874   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4df_mask, "__builtin_ia32_loadapd256_mask", IX86_BUILTIN_LOADAPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30875   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2df_mask, "__builtin_ia32_loadapd128_mask", IX86_BUILTIN_LOADAPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30876   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8sf_mask, "__builtin_ia32_loadaps256_mask", IX86_BUILTIN_LOADAPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30877   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4sf_mask, "__builtin_ia32_loadaps128_mask", IX86_BUILTIN_LOADAPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30878   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4df_mask, "__builtin_ia32_storeapd256_mask", IX86_BUILTIN_STOREAPD256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
30879   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev2df_mask, "__builtin_ia32_storeapd128_mask", IX86_BUILTIN_STOREAPD128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
30880   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev8sf_mask, "__builtin_ia32_storeaps256_mask", IX86_BUILTIN_STOREAPS256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
30881   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4sf_mask, "__builtin_ia32_storeaps128_mask", IX86_BUILTIN_STOREAPS128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
30882   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loadupd256_mask, "__builtin_ia32_loadupd256_mask", IX86_BUILTIN_LOADUPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30883   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loadupd_mask, "__builtin_ia32_loadupd128_mask", IX86_BUILTIN_LOADUPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30884   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loadups256_mask, "__builtin_ia32_loadups256_mask", IX86_BUILTIN_LOADUPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30885   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_loadups_mask, "__builtin_ia32_loadups128_mask", IX86_BUILTIN_LOADUPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30886   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeupd256_mask, "__builtin_ia32_storeupd256_mask", IX86_BUILTIN_STOREUPD256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
30887   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeupd_mask, "__builtin_ia32_storeupd128_mask", IX86_BUILTIN_STOREUPD128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
30888   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeups256_mask, "__builtin_ia32_storeups256_mask", IX86_BUILTIN_STOREUPS256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
30889   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeups_mask, "__builtin_ia32_storeups128_mask", IX86_BUILTIN_STOREUPS128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
30890   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv4di_mask, "__builtin_ia32_loaddqudi256_mask", IX86_BUILTIN_LOADDQUDI256_MASK, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30891   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv2di_mask, "__builtin_ia32_loaddqudi128_mask", IX86_BUILTIN_LOADDQUDI128_MASK, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30892   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loaddquv8si_mask, "__builtin_ia32_loaddqusi256_mask", IX86_BUILTIN_LOADDQUSI256_MASK, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30893   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loaddquv4si_mask, "__builtin_ia32_loaddqusi128_mask", IX86_BUILTIN_LOADDQUSI128_MASK, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30894   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv4di_mask, "__builtin_ia32_storedqudi256_mask", IX86_BUILTIN_STOREDQUDI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
30895   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv2di_mask, "__builtin_ia32_storedqudi128_mask", IX86_BUILTIN_STOREDQUDI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
30896   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv8si_mask, "__builtin_ia32_storedqusi256_mask", IX86_BUILTIN_STOREDQUSI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
30897   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv4si_mask, "__builtin_ia32_storedqusi128_mask", IX86_BUILTIN_STOREDQUSI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
30898   { 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 },
30899   { 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 },
30900   { 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 },
30901   { 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 },
30902   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4df_mask, "__builtin_ia32_compressstoredf256_mask", IX86_BUILTIN_COMPRESSPDSTORE256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
30903   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev2df_mask, "__builtin_ia32_compressstoredf128_mask", IX86_BUILTIN_COMPRESSPDSTORE128, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
30904   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev8sf_mask, "__builtin_ia32_compressstoresf256_mask", IX86_BUILTIN_COMPRESSPSSTORE256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
30905   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4sf_mask, "__builtin_ia32_compressstoresf128_mask", IX86_BUILTIN_COMPRESSPSSTORE128, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
30906   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4di_mask, "__builtin_ia32_compressstoredi256_mask", IX86_BUILTIN_PCOMPRESSQSTORE256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
30907   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev2di_mask, "__builtin_ia32_compressstoredi128_mask", IX86_BUILTIN_PCOMPRESSQSTORE128, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
30908   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev8si_mask, "__builtin_ia32_compressstoresi256_mask", IX86_BUILTIN_PCOMPRESSDSTORE256, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
30909   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4si_mask, "__builtin_ia32_compressstoresi128_mask", IX86_BUILTIN_PCOMPRESSDSTORE128, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
30910   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_mask, "__builtin_ia32_expandloaddf256_mask", IX86_BUILTIN_EXPANDPDLOAD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30911   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_mask, "__builtin_ia32_expandloaddf128_mask", IX86_BUILTIN_EXPANDPDLOAD128, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30912   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_mask, "__builtin_ia32_expandloadsf256_mask", IX86_BUILTIN_EXPANDPSLOAD256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30913   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_mask, "__builtin_ia32_expandloadsf128_mask", IX86_BUILTIN_EXPANDPSLOAD128, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30914   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_mask, "__builtin_ia32_expandloaddi256_mask", IX86_BUILTIN_PEXPANDQLOAD256, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30915   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_mask, "__builtin_ia32_expandloaddi128_mask", IX86_BUILTIN_PEXPANDQLOAD128, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30916   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_mask, "__builtin_ia32_expandloadsi256_mask", IX86_BUILTIN_PEXPANDDLOAD256, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30917   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_mask, "__builtin_ia32_expandloadsi128_mask", IX86_BUILTIN_PEXPANDDLOAD128, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30918   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_maskz, "__builtin_ia32_expandloaddf256_maskz", IX86_BUILTIN_EXPANDPDLOAD256Z, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30919   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_maskz, "__builtin_ia32_expandloaddf128_maskz", IX86_BUILTIN_EXPANDPDLOAD128Z, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30920   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_maskz, "__builtin_ia32_expandloadsf256_maskz", IX86_BUILTIN_EXPANDPSLOAD256Z, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30921   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_maskz, "__builtin_ia32_expandloadsf128_maskz", IX86_BUILTIN_EXPANDPSLOAD128Z, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30922   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_maskz, "__builtin_ia32_expandloaddi256_maskz", IX86_BUILTIN_PEXPANDQLOAD256Z, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30923   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_maskz, "__builtin_ia32_expandloaddi128_maskz", IX86_BUILTIN_PEXPANDQLOAD128Z, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30924   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_maskz, "__builtin_ia32_expandloadsi256_maskz", IX86_BUILTIN_PEXPANDDLOAD256Z, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30925   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_maskz, "__builtin_ia32_expandloadsi128_maskz", IX86_BUILTIN_PEXPANDDLOAD128Z, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30926   { 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 },
30927   { 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 },
30928   { 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 },
30929   { 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 },
30930   { 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 },
30931   { 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 },
30932   { 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 },
30933   { 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 },
30934   { 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 },
30935   { 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 },
30936   { 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 },
30937   { 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 },
30938   { 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 },
30939   { 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 },
30940   { 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 },
30941   { 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 },
30942   { 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 },
30943   { 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 },
30944   { 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 },
30945   { 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 },
30946   { 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 },
30947   { 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 },
30948   { 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 },
30949   { 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 },
30950   { 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 },
30951   { 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 },
30952   { 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 },
30953   { 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 },
30954   { 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 },
30955   { 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 },
30956
30957   /* PCOMMIT.  */
30958   { OPTION_MASK_ISA_PCOMMIT, CODE_FOR_pcommit, "__builtin_ia32_pcommit", IX86_BUILTIN_PCOMMIT, UNKNOWN, (int) VOID_FTYPE_VOID },
30959 };
30960
30961 /* Builtins with variable number of arguments.  */
30962 static const struct builtin_description bdesc_args[] =
30963 {
30964   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_bsr, "__builtin_ia32_bsrsi", IX86_BUILTIN_BSRSI, UNKNOWN, (int) INT_FTYPE_INT },
30965   { OPTION_MASK_ISA_64BIT, CODE_FOR_bsr_rex64, "__builtin_ia32_bsrdi", IX86_BUILTIN_BSRDI, UNKNOWN, (int) INT64_FTYPE_INT64 },
30966   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdpmc", IX86_BUILTIN_RDPMC, UNKNOWN, (int) UINT64_FTYPE_INT },
30967   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlqi3, "__builtin_ia32_rolqi", IX86_BUILTIN_ROLQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
30968   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlhi3, "__builtin_ia32_rolhi", IX86_BUILTIN_ROLHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
30969   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrqi3, "__builtin_ia32_rorqi", IX86_BUILTIN_RORQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
30970   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrhi3, "__builtin_ia32_rorhi", IX86_BUILTIN_RORHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
30971
30972   /* MMX */
30973   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30974   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30975   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30976   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30977   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30978   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30979
30980   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30981   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30982   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30983   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30984   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30985   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30986   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30987   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30988
30989   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30990   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30991
30992   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30993   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30994   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30995   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30996
30997   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30998   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30999   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31000   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31001   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31002   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31003
31004   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31005   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31006   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31007   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31008   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
31009   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
31010
31011   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
31012   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
31013   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
31014
31015   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
31016
31017   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31018   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31019   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
31020   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31021   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31022   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
31023
31024   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31025   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31026   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
31027   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31028   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31029   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
31030
31031   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31032   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31033   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31034   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31035
31036   /* 3DNow! */
31037   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
31038   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
31039   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31040   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31041
31042   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31043   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31044   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31045   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31046   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31047   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31048   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31049   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31050   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31051   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31052   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31053   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31054   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31055   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31056   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31057
31058   /* 3DNow!A */
31059   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
31060   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
31061   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
31062   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31063   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31064   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31065
31066   /* SSE */
31067   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
31068   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31069   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31070   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31071   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31072   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31073   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
31074   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
31075   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
31076   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
31077   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
31078   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
31079
31080   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31081
31082   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31083   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31084   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31085   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31086   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31087   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31088   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31089   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31090
31091   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
31092   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
31093   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
31094   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31095   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31096   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31097   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
31098   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
31099   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
31100   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31101   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
31102   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31103   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
31104   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
31105   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
31106   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31107   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
31108   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
31109   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
31110   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31111
31112   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31113   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31114   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31115   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31116
31117   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31118   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31119   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31120   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31121
31122   { OPTION_MASK_ISA_SSE, CODE_FOR_copysignv4sf3,  "__builtin_ia32_copysignps", IX86_BUILTIN_CPYSGNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31123
31124   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31125   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31126   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31127   { OPTION_MASK_ISA_SSE, CODE_FOR_vec_interleave_highv4sf, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31128   { OPTION_MASK_ISA_SSE, CODE_FOR_vec_interleave_lowv4sf, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31129
31130   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
31131   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
31132   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
31133
31134   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
31135
31136   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31137   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31138   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31139
31140   { OPTION_MASK_ISA_SSE, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
31141   { OPTION_MASK_ISA_SSE, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
31142
31143   /* SSE MMX or 3Dnow!A */
31144   { 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 },
31145   { 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 },
31146   { 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 },
31147
31148   { 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 },
31149   { 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 },
31150   { 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 },
31151   { 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 },
31152
31153   { 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 },
31154   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
31155
31156   { 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 },
31157
31158   /* SSE2 */
31159   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31160
31161   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
31162   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
31163   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
31164   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
31165   { OPTION_MASK_ISA_SSE2, CODE_FOR_floatv4siv4sf2, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
31166
31167   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
31168   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
31169   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
31170   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
31171   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
31172
31173   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
31174
31175   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
31176   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
31177   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
31178   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
31179
31180   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_fix_notruncv4sfv4si, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31181   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
31182   { OPTION_MASK_ISA_SSE2, CODE_FOR_fix_truncv4sfv4si2, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31183
31184   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31185   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31186   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31187   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31188   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31189   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31190   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31191   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31192
31193   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
31194   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
31195   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
31196   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31197   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
31198   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31199   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
31200   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
31201   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
31202   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31203   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31204   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31205   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
31206   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
31207   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
31208   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31209   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
31210   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
31211   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
31212   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31213
31214   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31215   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31216   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31217   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31218
31219   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31220   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31221   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31222   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31223
31224   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysignv2df3,  "__builtin_ia32_copysignpd", IX86_BUILTIN_CPYSGNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31225
31226   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31227   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv2df, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31228   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv2df, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31229
31230   { 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 },
31231
31232   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31233   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31234   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31235   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31236   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31237   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31238   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31239   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31240
31241   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31242   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31243   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31244   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31245   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31246   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31247   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31248   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31249
31250   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31251   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
31252
31253   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31254   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31255   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31256   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31257
31258   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31259   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31260
31261   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31262   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31263   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
31264   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31265   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31266   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
31267
31268   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31269   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31270   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31271   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31272
31273   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv16qi, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31274   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv8hi, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
31275   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv4si, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
31276   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv2di, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31277   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv16qi, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31278   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv8hi, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31279   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv4si, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31280   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv2di, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31281
31282   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
31283   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
31284   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
31285
31286   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31287   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
31288
31289   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
31290   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_widen_umult_even_v4si, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
31291
31292   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
31293
31294   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
31295   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
31296   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
31297   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
31298
31299   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlv1ti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_CONVERT },
31300   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31301   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31302   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
31303   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31304   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31305   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
31306
31307   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrv1ti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_CONVERT },
31308   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31309   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31310   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
31311   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31312   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31313   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
31314
31315   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31316   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31317   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31318   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31319
31320   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
31321   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
31322   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
31323
31324   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
31325
31326   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31327
31328   /* SSE2 MMX */
31329   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
31330   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
31331
31332   /* SSE3 */
31333   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
31334   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31335
31336   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31337   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31338   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31339   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31340   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31341   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31342
31343   /* SSSE3 */
31344   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
31345   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
31346   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31347   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
31348   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
31349   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
31350
31351   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31352   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31353   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31354   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31355   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31356   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31357   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31358   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31359   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31360   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31361   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31362   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31363   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
31364   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
31365   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31366   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31367   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31368   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31369   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31370   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31371   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31372   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31373   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31374   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31375
31376   /* SSSE3.  */
31377   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT_CONVERT },
31378   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_INT_CONVERT },
31379
31380   /* SSE4.1 */
31381   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31382   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31383   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
31384   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
31385   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31386   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31387   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31388   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
31389   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
31390   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
31391
31392   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
31393   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
31394   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
31395   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
31396   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
31397   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
31398   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
31399   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
31400   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
31401   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
31402   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
31403   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
31404   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31405
31406   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
31407   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31408   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31409   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31410   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31411   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31412   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31413   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31414   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31415   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31416   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
31417   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31418
31419   /* SSE4.1 */
31420   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
31421   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
31422   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31423   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31424
31425   { 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 },
31426   { 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 },
31427   { 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 },
31428   { 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 },
31429
31430   { 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 },
31431   { 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 },
31432
31433   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv2df2, "__builtin_ia32_roundpd_az", IX86_BUILTIN_ROUNDPD_AZ, UNKNOWN, (int) V2DF_FTYPE_V2DF },
31434   { 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 },
31435
31436   { 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 },
31437   { 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 },
31438   { 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 },
31439   { 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 },
31440
31441   { 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 },
31442   { 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 },
31443
31444   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv4sf2, "__builtin_ia32_roundps_az", IX86_BUILTIN_ROUNDPS_AZ, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31445   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv4sf2_sfix, "__builtin_ia32_roundps_az_sfix", IX86_BUILTIN_ROUNDPS_AZ_SFIX, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31446
31447   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31448   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31449   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31450
31451   /* SSE4.2 */
31452   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31453   { 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 },
31454   { 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 },
31455   { 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 },
31456   { 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 },
31457
31458   /* SSE4A */
31459   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
31460   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
31461   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
31462   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31463
31464   /* AES */
31465   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
31466   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31467
31468   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31469   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31470   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31471   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31472
31473   /* PCLMUL */
31474   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
31475
31476   /* AVX */
31477   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31478   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31479   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31480   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31481   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31482   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31483   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31484   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31485   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31486   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31487   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31488   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31489   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31490   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31491   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31492   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31493   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31494   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31495   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31496   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31497   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31498   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31499   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31500   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31501   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31502   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31503
31504   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
31505   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
31506   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
31507   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
31508
31509   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31510   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31511   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
31512   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
31513   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31514   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31515   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31516   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vmcmpv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31517   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vmcmpv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31518   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31519   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31520   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31521   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31522   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
31523   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
31524   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
31525   { OPTION_MASK_ISA_AVX, CODE_FOR_floatv4siv4df2, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
31526   { OPTION_MASK_ISA_AVX, CODE_FOR_floatv8siv8sf2, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
31527   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
31528   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_fix_notruncv8sfv8si, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31529   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
31530   { OPTION_MASK_ISA_AVX, CODE_FOR_fix_truncv4dfv4si2, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
31531   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
31532   { OPTION_MASK_ISA_AVX, CODE_FOR_fix_truncv8sfv8si2, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31533   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31534   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31535   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
31536   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
31537   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
31538   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31539   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
31540   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
31541   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
31542   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
31543
31544   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31545   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31546   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31547
31548   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31549   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31550   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31551   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31552   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31553
31554   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31555
31556   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31557   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
31558
31559   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_floorpd256", IX86_BUILTIN_FLOORPD256, (enum rtx_code) ROUND_FLOOR, (int) V4DF_FTYPE_V4DF_ROUND },
31560   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_ceilpd256", IX86_BUILTIN_CEILPD256, (enum rtx_code) ROUND_CEIL, (int) V4DF_FTYPE_V4DF_ROUND },
31561   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_truncpd256", IX86_BUILTIN_TRUNCPD256, (enum rtx_code) ROUND_TRUNC, (int) V4DF_FTYPE_V4DF_ROUND },
31562   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_rintpd256", IX86_BUILTIN_RINTPD256, (enum rtx_code) ROUND_MXCSR, (int) V4DF_FTYPE_V4DF_ROUND },
31563
31564   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv4df2, "__builtin_ia32_roundpd_az256", IX86_BUILTIN_ROUNDPD_AZ256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31565   { 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 },
31566
31567   { 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 },
31568   { 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 },
31569
31570   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_floorps256", IX86_BUILTIN_FLOORPS256, (enum rtx_code) ROUND_FLOOR, (int) V8SF_FTYPE_V8SF_ROUND },
31571   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_ceilps256", IX86_BUILTIN_CEILPS256, (enum rtx_code) ROUND_CEIL, (int) V8SF_FTYPE_V8SF_ROUND },
31572   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_truncps256", IX86_BUILTIN_TRUNCPS256, (enum rtx_code) ROUND_TRUNC, (int) V8SF_FTYPE_V8SF_ROUND },
31573   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_rintps256", IX86_BUILTIN_RINTPS256, (enum rtx_code) ROUND_MXCSR, (int) V8SF_FTYPE_V8SF_ROUND },
31574
31575   { 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 },
31576   { 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 },
31577
31578   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv8sf2, "__builtin_ia32_roundps_az256", IX86_BUILTIN_ROUNDPS_AZ256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31579   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv8sf2_sfix, "__builtin_ia32_roundps_az_sfix256", IX86_BUILTIN_ROUNDPS_AZ_SFIX256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31580
31581   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31582   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31583   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31584   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31585
31586   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
31587   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
31588   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
31589   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v8si, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
31590   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v8sf, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
31591   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v4df, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
31592
31593   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31594   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31595   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31596   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31597   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31598   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31599   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31600   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31601   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31602   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31603   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31604   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31605   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31606   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31607   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31608
31609   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
31610   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
31611
31612   { OPTION_MASK_ISA_AVX, CODE_FOR_copysignv8sf3,  "__builtin_ia32_copysignps256", IX86_BUILTIN_CPYSGNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31613   { OPTION_MASK_ISA_AVX, CODE_FOR_copysignv4df3,  "__builtin_ia32_copysignpd256", IX86_BUILTIN_CPYSGNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31614
31615   { 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 },
31616
31617   /* AVX2 */
31618   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_mpsadbw, "__builtin_ia32_mpsadbw256", IX86_BUILTIN_MPSADBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_INT },
31619   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv32qi2, "__builtin_ia32_pabsb256", IX86_BUILTIN_PABSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI },
31620   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv16hi2, "__builtin_ia32_pabsw256", IX86_BUILTIN_PABSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI },
31621   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv8si2, "__builtin_ia32_pabsd256", IX86_BUILTIN_PABSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI },
31622   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packssdw, "__builtin_ia32_packssdw256",  IX86_BUILTIN_PACKSSDW256, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI },
31623   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packsswb, "__builtin_ia32_packsswb256",  IX86_BUILTIN_PACKSSWB256, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI },
31624   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packusdw, "__builtin_ia32_packusdw256",  IX86_BUILTIN_PACKUSDW256, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI },
31625   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packuswb, "__builtin_ia32_packuswb256",  IX86_BUILTIN_PACKUSWB256, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI },
31626   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv32qi3, "__builtin_ia32_paddb256", IX86_BUILTIN_PADDB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31627   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv16hi3, "__builtin_ia32_paddw256", IX86_BUILTIN_PADDW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31628   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv8si3, "__builtin_ia32_paddd256", IX86_BUILTIN_PADDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31629   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv4di3, "__builtin_ia32_paddq256", IX86_BUILTIN_PADDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31630   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ssaddv32qi3, "__builtin_ia32_paddsb256", IX86_BUILTIN_PADDSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31631   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ssaddv16hi3, "__builtin_ia32_paddsw256", IX86_BUILTIN_PADDSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31632   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_usaddv32qi3, "__builtin_ia32_paddusb256", IX86_BUILTIN_PADDUSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31633   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_usaddv16hi3, "__builtin_ia32_paddusw256", IX86_BUILTIN_PADDUSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31634   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_palignrv2ti, "__builtin_ia32_palignr256", IX86_BUILTIN_PALIGNR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT_CONVERT },
31635   { OPTION_MASK_ISA_AVX2, CODE_FOR_andv4di3, "__builtin_ia32_andsi256", IX86_BUILTIN_AND256I, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31636   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_andnotv4di3, "__builtin_ia32_andnotsi256", IX86_BUILTIN_ANDNOT256I, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31637   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_uavgv32qi3, "__builtin_ia32_pavgb256",  IX86_BUILTIN_PAVGB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31638   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_uavgv16hi3, "__builtin_ia32_pavgw256",  IX86_BUILTIN_PAVGW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31639   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblendvb, "__builtin_ia32_pblendvb256", IX86_BUILTIN_PBLENDVB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI },
31640   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblendw, "__builtin_ia32_pblendw256", IX86_BUILTIN_PBLENDVW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_INT },
31641   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv32qi3, "__builtin_ia32_pcmpeqb256", IX86_BUILTIN_PCMPEQB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31642   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv16hi3, "__builtin_ia32_pcmpeqw256", IX86_BUILTIN_PCMPEQW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31643   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv8si3, "__builtin_ia32_pcmpeqd256", IX86_BUILTIN_PCMPEQD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI  },
31644   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv4di3, "__builtin_ia32_pcmpeqq256", IX86_BUILTIN_PCMPEQQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI  },
31645   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv32qi3, "__builtin_ia32_pcmpgtb256", IX86_BUILTIN_PCMPGTB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31646   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv16hi3, "__builtin_ia32_pcmpgtw256", IX86_BUILTIN_PCMPGTW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31647   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv8si3, "__builtin_ia32_pcmpgtd256", IX86_BUILTIN_PCMPGTD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI  },
31648   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv4di3, "__builtin_ia32_pcmpgtq256", IX86_BUILTIN_PCMPGTQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI  },
31649   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phaddwv16hi3, "__builtin_ia32_phaddw256", IX86_BUILTIN_PHADDW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31650   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phadddv8si3, "__builtin_ia32_phaddd256", IX86_BUILTIN_PHADDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31651   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phaddswv16hi3, "__builtin_ia32_phaddsw256", IX86_BUILTIN_PHADDSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31652   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubwv16hi3, "__builtin_ia32_phsubw256", IX86_BUILTIN_PHSUBW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31653   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubdv8si3, "__builtin_ia32_phsubd256", IX86_BUILTIN_PHSUBD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31654   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubswv16hi3, "__builtin_ia32_phsubsw256", IX86_BUILTIN_PHSUBSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31655   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmaddubsw256, "__builtin_ia32_pmaddubsw256", IX86_BUILTIN_PMADDUBSW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI },
31656   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmaddwd, "__builtin_ia32_pmaddwd256", IX86_BUILTIN_PMADDWD256, UNKNOWN, (int) V8SI_FTYPE_V16HI_V16HI },
31657   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv32qi3, "__builtin_ia32_pmaxsb256", IX86_BUILTIN_PMAXSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31658   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv16hi3, "__builtin_ia32_pmaxsw256", IX86_BUILTIN_PMAXSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31659   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv8si3 , "__builtin_ia32_pmaxsd256", IX86_BUILTIN_PMAXSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31660   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv32qi3, "__builtin_ia32_pmaxub256", IX86_BUILTIN_PMAXUB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31661   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv16hi3, "__builtin_ia32_pmaxuw256", IX86_BUILTIN_PMAXUW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31662   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv8si3 , "__builtin_ia32_pmaxud256", IX86_BUILTIN_PMAXUD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31663   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv32qi3, "__builtin_ia32_pminsb256", IX86_BUILTIN_PMINSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31664   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv16hi3, "__builtin_ia32_pminsw256", IX86_BUILTIN_PMINSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31665   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv8si3 , "__builtin_ia32_pminsd256", IX86_BUILTIN_PMINSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31666   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv32qi3, "__builtin_ia32_pminub256", IX86_BUILTIN_PMINUB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31667   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv16hi3, "__builtin_ia32_pminuw256", IX86_BUILTIN_PMINUW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31668   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv8si3 , "__builtin_ia32_pminud256", IX86_BUILTIN_PMINUD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31669   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmovmskb, "__builtin_ia32_pmovmskb256", IX86_BUILTIN_PMOVMSKB256, UNKNOWN, (int) INT_FTYPE_V32QI },
31670   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv16qiv16hi2, "__builtin_ia32_pmovsxbw256", IX86_BUILTIN_PMOVSXBW256, UNKNOWN, (int) V16HI_FTYPE_V16QI },
31671   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv8qiv8si2  , "__builtin_ia32_pmovsxbd256", IX86_BUILTIN_PMOVSXBD256, UNKNOWN, (int) V8SI_FTYPE_V16QI },
31672   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4qiv4di2  , "__builtin_ia32_pmovsxbq256", IX86_BUILTIN_PMOVSXBQ256, UNKNOWN, (int) V4DI_FTYPE_V16QI },
31673   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv8hiv8si2  , "__builtin_ia32_pmovsxwd256", IX86_BUILTIN_PMOVSXWD256, UNKNOWN, (int) V8SI_FTYPE_V8HI },
31674   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4hiv4di2  , "__builtin_ia32_pmovsxwq256", IX86_BUILTIN_PMOVSXWQ256, UNKNOWN, (int) V4DI_FTYPE_V8HI },
31675   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4siv4di2  , "__builtin_ia32_pmovsxdq256", IX86_BUILTIN_PMOVSXDQ256, UNKNOWN, (int) V4DI_FTYPE_V4SI },
31676   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv16qiv16hi2, "__builtin_ia32_pmovzxbw256", IX86_BUILTIN_PMOVZXBW256, UNKNOWN, (int) V16HI_FTYPE_V16QI },
31677   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv8qiv8si2  , "__builtin_ia32_pmovzxbd256", IX86_BUILTIN_PMOVZXBD256, UNKNOWN, (int) V8SI_FTYPE_V16QI },
31678   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4qiv4di2  , "__builtin_ia32_pmovzxbq256", IX86_BUILTIN_PMOVZXBQ256, UNKNOWN, (int) V4DI_FTYPE_V16QI },
31679   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv8hiv8si2  , "__builtin_ia32_pmovzxwd256", IX86_BUILTIN_PMOVZXWD256, UNKNOWN, (int) V8SI_FTYPE_V8HI },
31680   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4hiv4di2  , "__builtin_ia32_pmovzxwq256", IX86_BUILTIN_PMOVZXWQ256, UNKNOWN, (int) V4DI_FTYPE_V8HI },
31681   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4siv4di2  , "__builtin_ia32_pmovzxdq256", IX86_BUILTIN_PMOVZXDQ256, UNKNOWN, (int) V4DI_FTYPE_V4SI },
31682   { OPTION_MASK_ISA_AVX2, CODE_FOR_vec_widen_smult_even_v8si, "__builtin_ia32_pmuldq256", IX86_BUILTIN_PMULDQ256, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI },
31683   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmulhrswv16hi3 , "__builtin_ia32_pmulhrsw256", IX86_BUILTIN_PMULHRSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31684   { OPTION_MASK_ISA_AVX2, CODE_FOR_umulv16hi3_highpart, "__builtin_ia32_pmulhuw256" , IX86_BUILTIN_PMULHUW256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31685   { OPTION_MASK_ISA_AVX2, CODE_FOR_smulv16hi3_highpart, "__builtin_ia32_pmulhw256"  , IX86_BUILTIN_PMULHW256  , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31686   { OPTION_MASK_ISA_AVX2, CODE_FOR_mulv16hi3, "__builtin_ia32_pmullw256"  , IX86_BUILTIN_PMULLW256  , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31687   { OPTION_MASK_ISA_AVX2, CODE_FOR_mulv8si3, "__builtin_ia32_pmulld256"  , IX86_BUILTIN_PMULLD256  , UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31688   { OPTION_MASK_ISA_AVX2, CODE_FOR_vec_widen_umult_even_v8si, "__builtin_ia32_pmuludq256", IX86_BUILTIN_PMULUDQ256, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI },
31689   { OPTION_MASK_ISA_AVX2, CODE_FOR_iorv4di3, "__builtin_ia32_por256", IX86_BUILTIN_POR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31690   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psadbw, "__builtin_ia32_psadbw256", IX86_BUILTIN_PSADBW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI },
31691   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufbv32qi3, "__builtin_ia32_pshufb256", IX86_BUILTIN_PSHUFB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31692   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufdv3, "__builtin_ia32_pshufd256", IX86_BUILTIN_PSHUFD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT },
31693   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufhwv3, "__builtin_ia32_pshufhw256", IX86_BUILTIN_PSHUFHW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT },
31694   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshuflwv3, "__builtin_ia32_pshuflw256", IX86_BUILTIN_PSHUFLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT },
31695   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv32qi3, "__builtin_ia32_psignb256", IX86_BUILTIN_PSIGNB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31696   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv16hi3, "__builtin_ia32_psignw256", IX86_BUILTIN_PSIGNW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31697   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv8si3 , "__builtin_ia32_psignd256", IX86_BUILTIN_PSIGND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31698   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlv2ti3, "__builtin_ia32_pslldqi256", IX86_BUILTIN_PSLLDQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_CONVERT },
31699   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv16hi3, "__builtin_ia32_psllwi256", IX86_BUILTIN_PSLLWI256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31700   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv16hi3, "__builtin_ia32_psllw256", IX86_BUILTIN_PSLLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31701   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv8si3, "__builtin_ia32_pslldi256", IX86_BUILTIN_PSLLDI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31702   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv8si3, "__builtin_ia32_pslld256", IX86_BUILTIN_PSLLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31703   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv4di3, "__builtin_ia32_psllqi256", IX86_BUILTIN_PSLLQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_COUNT },
31704   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv4di3, "__builtin_ia32_psllq256", IX86_BUILTIN_PSLLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_COUNT },
31705   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv16hi3, "__builtin_ia32_psrawi256", IX86_BUILTIN_PSRAWI256, UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31706   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv16hi3, "__builtin_ia32_psraw256", IX86_BUILTIN_PSRAW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31707   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv8si3, "__builtin_ia32_psradi256", IX86_BUILTIN_PSRADI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31708   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv8si3, "__builtin_ia32_psrad256", IX86_BUILTIN_PSRAD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31709   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrv2ti3, "__builtin_ia32_psrldqi256", IX86_BUILTIN_PSRLDQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_CONVERT },
31710   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv16hi3, "__builtin_ia32_psrlwi256", IX86_BUILTIN_PSRLWI256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31711   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv16hi3, "__builtin_ia32_psrlw256", IX86_BUILTIN_PSRLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31712   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv8si3, "__builtin_ia32_psrldi256", IX86_BUILTIN_PSRLDI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31713   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv8si3, "__builtin_ia32_psrld256", IX86_BUILTIN_PSRLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31714   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv4di3, "__builtin_ia32_psrlqi256", IX86_BUILTIN_PSRLQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_COUNT },
31715   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv4di3, "__builtin_ia32_psrlq256", IX86_BUILTIN_PSRLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_COUNT },
31716   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv32qi3, "__builtin_ia32_psubb256", IX86_BUILTIN_PSUBB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31717   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv16hi3, "__builtin_ia32_psubw256", IX86_BUILTIN_PSUBW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31718   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv8si3, "__builtin_ia32_psubd256", IX86_BUILTIN_PSUBD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31719   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv4di3, "__builtin_ia32_psubq256", IX86_BUILTIN_PSUBQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31720   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sssubv32qi3, "__builtin_ia32_psubsb256", IX86_BUILTIN_PSUBSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31721   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sssubv16hi3, "__builtin_ia32_psubsw256", IX86_BUILTIN_PSUBSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31722   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ussubv32qi3, "__builtin_ia32_psubusb256", IX86_BUILTIN_PSUBUSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31723   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ussubv16hi3, "__builtin_ia32_psubusw256", IX86_BUILTIN_PSUBUSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31724   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv32qi, "__builtin_ia32_punpckhbw256", IX86_BUILTIN_PUNPCKHBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31725   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv16hi, "__builtin_ia32_punpckhwd256", IX86_BUILTIN_PUNPCKHWD256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI  },
31726   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv8si, "__builtin_ia32_punpckhdq256", IX86_BUILTIN_PUNPCKHDQ256, UNKNOWN,  (int) V8SI_FTYPE_V8SI_V8SI },
31727   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv4di, "__builtin_ia32_punpckhqdq256", IX86_BUILTIN_PUNPCKHQDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31728   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv32qi, "__builtin_ia32_punpcklbw256", IX86_BUILTIN_PUNPCKLBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31729   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv16hi, "__builtin_ia32_punpcklwd256", IX86_BUILTIN_PUNPCKLWD256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31730   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv8si, "__builtin_ia32_punpckldq256", IX86_BUILTIN_PUNPCKLDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31731   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv4di, "__builtin_ia32_punpcklqdq256", IX86_BUILTIN_PUNPCKLQDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31732   { OPTION_MASK_ISA_AVX2, CODE_FOR_xorv4di3, "__builtin_ia32_pxor256", IX86_BUILTIN_PXOR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31733   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv4sf, "__builtin_ia32_vbroadcastss_ps", IX86_BUILTIN_VBROADCASTSS_PS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31734   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv8sf, "__builtin_ia32_vbroadcastss_ps256", IX86_BUILTIN_VBROADCASTSS_PS256, UNKNOWN, (int) V8SF_FTYPE_V4SF },
31735   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv4df, "__builtin_ia32_vbroadcastsd_pd256", IX86_BUILTIN_VBROADCASTSD_PD256, UNKNOWN, (int) V4DF_FTYPE_V2DF },
31736   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vbroadcasti128_v4di, "__builtin_ia32_vbroadcastsi256", IX86_BUILTIN_VBROADCASTSI256, UNKNOWN, (int) V4DI_FTYPE_V2DI },
31737   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblenddv4si, "__builtin_ia32_pblendd128", IX86_BUILTIN_PBLENDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT },
31738   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblenddv8si, "__builtin_ia32_pblendd256", IX86_BUILTIN_PBLENDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
31739   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv32qi, "__builtin_ia32_pbroadcastb256", IX86_BUILTIN_PBROADCASTB256, UNKNOWN, (int) V32QI_FTYPE_V16QI },
31740   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv16hi, "__builtin_ia32_pbroadcastw256", IX86_BUILTIN_PBROADCASTW256, UNKNOWN, (int) V16HI_FTYPE_V8HI },
31741   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv8si, "__builtin_ia32_pbroadcastd256", IX86_BUILTIN_PBROADCASTD256, UNKNOWN, (int) V8SI_FTYPE_V4SI },
31742   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv4di, "__builtin_ia32_pbroadcastq256", IX86_BUILTIN_PBROADCASTQ256, UNKNOWN, (int) V4DI_FTYPE_V2DI },
31743   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv16qi, "__builtin_ia32_pbroadcastb128", IX86_BUILTIN_PBROADCASTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
31744   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv8hi, "__builtin_ia32_pbroadcastw128", IX86_BUILTIN_PBROADCASTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31745   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv4si, "__builtin_ia32_pbroadcastd128", IX86_BUILTIN_PBROADCASTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
31746   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv2di, "__builtin_ia32_pbroadcastq128", IX86_BUILTIN_PBROADCASTQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31747   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permvarv8si, "__builtin_ia32_permvarsi256", IX86_BUILTIN_VPERMVARSI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31748   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permvarv8sf, "__builtin_ia32_permvarsf256", IX86_BUILTIN_VPERMVARSF256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
31749   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv4df, "__builtin_ia32_permdf256", IX86_BUILTIN_VPERMDF256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31750   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv4di, "__builtin_ia32_permdi256", IX86_BUILTIN_VPERMDI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT },
31751   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv2ti, "__builtin_ia32_permti256", IX86_BUILTIN_VPERMTI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT },
31752   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx_vextractf128v4di, "__builtin_ia32_extract128i256", IX86_BUILTIN_VEXTRACT128I256, UNKNOWN, (int) V2DI_FTYPE_V4DI_INT },
31753   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx_vinsertf128v4di, "__builtin_ia32_insert128i256", IX86_BUILTIN_VINSERT128I256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_INT },
31754   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv4di, "__builtin_ia32_psllv4di", IX86_BUILTIN_PSLLVV4DI, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31755   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv2di, "__builtin_ia32_psllv2di", IX86_BUILTIN_PSLLVV2DI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31756   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv8si, "__builtin_ia32_psllv8si", IX86_BUILTIN_PSLLVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31757   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv4si, "__builtin_ia32_psllv4si", IX86_BUILTIN_PSLLVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31758   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashrvv8si, "__builtin_ia32_psrav8si", IX86_BUILTIN_PSRAVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31759   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashrvv4si, "__builtin_ia32_psrav4si", IX86_BUILTIN_PSRAVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31760   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv4di, "__builtin_ia32_psrlv4di", IX86_BUILTIN_PSRLVV4DI, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31761   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv2di, "__builtin_ia32_psrlv2di", IX86_BUILTIN_PSRLVV2DI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31762   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv8si, "__builtin_ia32_psrlv8si", IX86_BUILTIN_PSRLVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31763   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv4si, "__builtin_ia32_psrlv4si", IX86_BUILTIN_PSRLVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31764
31765   { OPTION_MASK_ISA_LZCNT, CODE_FOR_clzhi2_lzcnt,   "__builtin_clzs",   IX86_BUILTIN_CLZS,    UNKNOWN,     (int) UINT16_FTYPE_UINT16 },
31766
31767   /* BMI */
31768   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_bextr_si, "__builtin_ia32_bextr_u32", IX86_BUILTIN_BEXTR32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31769   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_bextr_di, "__builtin_ia32_bextr_u64", IX86_BUILTIN_BEXTR64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31770   { OPTION_MASK_ISA_BMI, CODE_FOR_ctzhi2,       "__builtin_ctzs",           IX86_BUILTIN_CTZS,    UNKNOWN, (int) UINT16_FTYPE_UINT16 },
31771
31772   /* TBM */
31773   { OPTION_MASK_ISA_TBM, CODE_FOR_tbm_bextri_si, "__builtin_ia32_bextri_u32", IX86_BUILTIN_BEXTRI32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31774   { OPTION_MASK_ISA_TBM, CODE_FOR_tbm_bextri_di, "__builtin_ia32_bextri_u64", IX86_BUILTIN_BEXTRI64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31775
31776   /* F16C */
31777   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtph2ps, "__builtin_ia32_vcvtph2ps", IX86_BUILTIN_CVTPH2PS, UNKNOWN, (int) V4SF_FTYPE_V8HI },
31778   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtph2ps256, "__builtin_ia32_vcvtph2ps256", IX86_BUILTIN_CVTPH2PS256, UNKNOWN, (int) V8SF_FTYPE_V8HI },
31779   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtps2ph, "__builtin_ia32_vcvtps2ph", IX86_BUILTIN_CVTPS2PH, UNKNOWN, (int) V8HI_FTYPE_V4SF_INT },
31780   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtps2ph256, "__builtin_ia32_vcvtps2ph256", IX86_BUILTIN_CVTPS2PH256, UNKNOWN, (int) V8HI_FTYPE_V8SF_INT },
31781
31782   /* BMI2 */
31783   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_bzhi_si3, "__builtin_ia32_bzhi_si", IX86_BUILTIN_BZHI32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31784   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_bzhi_di3, "__builtin_ia32_bzhi_di", IX86_BUILTIN_BZHI64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31785   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pdep_si3, "__builtin_ia32_pdep_si", IX86_BUILTIN_PDEP32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31786   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pdep_di3, "__builtin_ia32_pdep_di", IX86_BUILTIN_PDEP64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31787   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pext_si3, "__builtin_ia32_pext_si", IX86_BUILTIN_PEXT32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31788   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pext_di3, "__builtin_ia32_pext_di", IX86_BUILTIN_PEXT64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31789
31790   /* AVX512F */
31791   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_si512_256si, "__builtin_ia32_si512_256si", IX86_BUILTIN_SI512_SI256, UNKNOWN, (int) V16SI_FTYPE_V8SI },
31792   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ps512_256ps, "__builtin_ia32_ps512_256ps", IX86_BUILTIN_PS512_PS256, UNKNOWN, (int) V16SF_FTYPE_V8SF },
31793   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pd512_256pd, "__builtin_ia32_pd512_256pd", IX86_BUILTIN_PD512_PD256, UNKNOWN, (int) V8DF_FTYPE_V4DF },
31794   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_si512_si, "__builtin_ia32_si512_si", IX86_BUILTIN_SI512_SI, UNKNOWN, (int) V16SI_FTYPE_V4SI },
31795   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ps512_ps, "__builtin_ia32_ps512_ps", IX86_BUILTIN_PS512_PS, UNKNOWN, (int) V16SF_FTYPE_V4SF },
31796   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pd512_pd, "__builtin_ia32_pd512_pd", IX86_BUILTIN_PD512_PD, UNKNOWN, (int) V8DF_FTYPE_V2DF },
31797   { 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 },
31798   { 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 },
31799   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv16si, "__builtin_ia32_blendmd_512_mask", IX86_BUILTIN_BLENDMD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31800   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv8df, "__builtin_ia32_blendmpd_512_mask", IX86_BUILTIN_BLENDMPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31801   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv16sf, "__builtin_ia32_blendmps_512_mask", IX86_BUILTIN_BLENDMPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31802   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv8di, "__builtin_ia32_blendmq_512_mask", IX86_BUILTIN_BLENDMQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31803   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv16sf_mask, "__builtin_ia32_broadcastf32x4_512", IX86_BUILTIN_BROADCASTF32X4_512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
31804   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv8df_mask, "__builtin_ia32_broadcastf64x4_512", IX86_BUILTIN_BROADCASTF64X4_512, UNKNOWN, (int) V8DF_FTYPE_V4DF_V8DF_QI },
31805   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv16si_mask, "__builtin_ia32_broadcasti32x4_512", IX86_BUILTIN_BROADCASTI32X4_512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
31806   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv8di_mask, "__builtin_ia32_broadcasti64x4_512", IX86_BUILTIN_BROADCASTI64X4_512, UNKNOWN, (int) V8DI_FTYPE_V4DI_V8DI_QI },
31807   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv8df_mask, "__builtin_ia32_broadcastsd512", IX86_BUILTIN_BROADCASTSD512, UNKNOWN, (int) V8DF_FTYPE_V2DF_V8DF_QI },
31808   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv16sf_mask, "__builtin_ia32_broadcastss512", IX86_BUILTIN_BROADCASTSS512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
31809   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv16si3_mask, "__builtin_ia32_cmpd512_mask", IX86_BUILTIN_CMPD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_INT_HI },
31810   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv8di3_mask, "__builtin_ia32_cmpq512_mask", IX86_BUILTIN_CMPQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_INT_QI },
31811   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv8df_mask, "__builtin_ia32_compressdf512_mask", IX86_BUILTIN_COMPRESSPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31812   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv16sf_mask, "__builtin_ia32_compresssf512_mask", IX86_BUILTIN_COMPRESSPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31813   { OPTION_MASK_ISA_AVX512F, CODE_FOR_floatv8siv8df2_mask, "__builtin_ia32_cvtdq2pd512_mask", IX86_BUILTIN_CVTDQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SI_V8DF_QI },
31814   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtps2ph512_mask,  "__builtin_ia32_vcvtps2ph512_mask", IX86_BUILTIN_CVTPS2PH512, UNKNOWN, (int) V16HI_FTYPE_V16SF_INT_V16HI_HI },
31815   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufloatv8siv8df2_mask, "__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SI_V8DF_QI },
31816   { OPTION_MASK_ISA_AVX512F, CODE_FOR_cvtusi2sd32, "__builtin_ia32_cvtusi2sd32", IX86_BUILTIN_CVTUSI2SD32, UNKNOWN, (int) V2DF_FTYPE_V2DF_UINT },
31817   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_mask, "__builtin_ia32_expanddf512_mask", IX86_BUILTIN_EXPANDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31818   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_maskz, "__builtin_ia32_expanddf512_maskz", IX86_BUILTIN_EXPANDPD512Z, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31819   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_mask, "__builtin_ia32_expandsf512_mask", IX86_BUILTIN_EXPANDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31820   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_maskz, "__builtin_ia32_expandsf512_maskz", IX86_BUILTIN_EXPANDPS512Z, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31821   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextractf32x4_mask, "__builtin_ia32_extractf32x4_mask", IX86_BUILTIN_EXTRACTF32X4, UNKNOWN, (int) V4SF_FTYPE_V16SF_INT_V4SF_QI },
31822   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextractf64x4_mask, "__builtin_ia32_extractf64x4_mask", IX86_BUILTIN_EXTRACTF64X4, UNKNOWN, (int) V4DF_FTYPE_V8DF_INT_V4DF_QI },
31823   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextracti32x4_mask, "__builtin_ia32_extracti32x4_mask", IX86_BUILTIN_EXTRACTI32X4, UNKNOWN, (int) V4SI_FTYPE_V16SI_INT_V4SI_QI },
31824   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextracti64x4_mask, "__builtin_ia32_extracti64x4_mask", IX86_BUILTIN_EXTRACTI64X4, UNKNOWN, (int) V4DI_FTYPE_V8DI_INT_V4DI_QI },
31825   { 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 },
31826   { 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 },
31827   { 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 },
31828   { 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 },
31829   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8df_mask, "__builtin_ia32_movapd512_mask", IX86_BUILTIN_MOVAPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31830   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16sf_mask, "__builtin_ia32_movaps512_mask", IX86_BUILTIN_MOVAPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31831   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movddup512_mask, "__builtin_ia32_movddup512_mask", IX86_BUILTIN_MOVDDUP512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31832   { 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 },
31833   { 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 },
31834   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movshdup512_mask, "__builtin_ia32_movshdup512_mask", IX86_BUILTIN_MOVSHDUP512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31835   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movsldup512_mask, "__builtin_ia32_movsldup512_mask", IX86_BUILTIN_MOVSLDUP512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31836   { OPTION_MASK_ISA_AVX512F, CODE_FOR_absv16si2_mask, "__builtin_ia32_pabsd512_mask", IX86_BUILTIN_PABSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31837   { OPTION_MASK_ISA_AVX512F, CODE_FOR_absv8di2_mask, "__builtin_ia32_pabsq512_mask", IX86_BUILTIN_PABSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31838   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv16si3_mask, "__builtin_ia32_paddd512_mask", IX86_BUILTIN_PADDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31839   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv8di3_mask, "__builtin_ia32_paddq512_mask", IX86_BUILTIN_PADDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31840   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andv16si3_mask, "__builtin_ia32_pandd512_mask", IX86_BUILTIN_PANDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31841   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_andnotv16si3_mask, "__builtin_ia32_pandnd512_mask", IX86_BUILTIN_PANDND512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31842   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_andnotv8di3_mask, "__builtin_ia32_pandnq512_mask", IX86_BUILTIN_PANDNQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31843   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andv8di3_mask, "__builtin_ia32_pandq512_mask", IX86_BUILTIN_PANDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31844   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv16si_mask, "__builtin_ia32_pbroadcastd512", IX86_BUILTIN_PBROADCASTD512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
31845   { 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 },
31846   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskb_vec_dupv8di, "__builtin_ia32_broadcastmb512", IX86_BUILTIN_PBROADCASTMB512, UNKNOWN, (int) V8DI_FTYPE_QI },
31847   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskw_vec_dupv16si, "__builtin_ia32_broadcastmw512", IX86_BUILTIN_PBROADCASTMW512, UNKNOWN, (int) V16SI_FTYPE_HI },
31848   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv8di_mask, "__builtin_ia32_pbroadcastq512", IX86_BUILTIN_PBROADCASTQ512, UNKNOWN, (int) V8DI_FTYPE_V2DI_V8DI_QI },
31849   { 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 },
31850   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_eqv16si3_mask, "__builtin_ia32_pcmpeqd512_mask", IX86_BUILTIN_PCMPEQD512_MASK, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31851   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_eqv8di3_mask, "__builtin_ia32_pcmpeqq512_mask", IX86_BUILTIN_PCMPEQQ512_MASK, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31852   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_gtv16si3_mask, "__builtin_ia32_pcmpgtd512_mask", IX86_BUILTIN_PCMPGTD512_MASK, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31853   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_gtv8di3_mask, "__builtin_ia32_pcmpgtq512_mask", IX86_BUILTIN_PCMPGTQ512_MASK, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31854   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv16si_mask, "__builtin_ia32_compresssi512_mask", IX86_BUILTIN_PCOMPRESSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31855   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv8di_mask, "__builtin_ia32_compressdi512_mask", IX86_BUILTIN_PCOMPRESSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31856   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_mask, "__builtin_ia32_expandsi512_mask", IX86_BUILTIN_PEXPANDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31857   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_maskz, "__builtin_ia32_expandsi512_maskz", IX86_BUILTIN_PEXPANDD512Z, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31858   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_mask, "__builtin_ia32_expanddi512_mask", IX86_BUILTIN_PEXPANDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31859   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_maskz, "__builtin_ia32_expanddi512_maskz", IX86_BUILTIN_PEXPANDQ512Z, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31860   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv16si3_mask, "__builtin_ia32_pmaxsd512_mask", IX86_BUILTIN_PMAXSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31861   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv8di3_mask, "__builtin_ia32_pmaxsq512_mask", IX86_BUILTIN_PMAXSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31862   { OPTION_MASK_ISA_AVX512F, CODE_FOR_umaxv16si3_mask, "__builtin_ia32_pmaxud512_mask", IX86_BUILTIN_PMAXUD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31863   { OPTION_MASK_ISA_AVX512F, CODE_FOR_umaxv8di3_mask, "__builtin_ia32_pmaxuq512_mask", IX86_BUILTIN_PMAXUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31864   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv16si3_mask, "__builtin_ia32_pminsd512_mask", IX86_BUILTIN_PMINSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31865   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv8di3_mask, "__builtin_ia32_pminsq512_mask", IX86_BUILTIN_PMINSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31866   { OPTION_MASK_ISA_AVX512F, CODE_FOR_uminv16si3_mask, "__builtin_ia32_pminud512_mask", IX86_BUILTIN_PMINUD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31867   { OPTION_MASK_ISA_AVX512F, CODE_FOR_uminv8di3_mask, "__builtin_ia32_pminuq512_mask", IX86_BUILTIN_PMINUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31868   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16qi2_mask, "__builtin_ia32_pmovdb512_mask", IX86_BUILTIN_PMOVDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
31869   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16hi2_mask, "__builtin_ia32_pmovdw512_mask", IX86_BUILTIN_PMOVDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
31870   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div16qi2_mask, "__builtin_ia32_pmovqb512_mask", IX86_BUILTIN_PMOVQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
31871   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8si2_mask, "__builtin_ia32_pmovqd512_mask", IX86_BUILTIN_PMOVQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
31872   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8hi2_mask, "__builtin_ia32_pmovqw512_mask", IX86_BUILTIN_PMOVQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
31873   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16qi2_mask, "__builtin_ia32_pmovsdb512_mask", IX86_BUILTIN_PMOVSDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
31874   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16hi2_mask, "__builtin_ia32_pmovsdw512_mask", IX86_BUILTIN_PMOVSDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
31875   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div16qi2_mask, "__builtin_ia32_pmovsqb512_mask", IX86_BUILTIN_PMOVSQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
31876   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8si2_mask, "__builtin_ia32_pmovsqd512_mask", IX86_BUILTIN_PMOVSQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
31877   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8hi2_mask, "__builtin_ia32_pmovsqw512_mask", IX86_BUILTIN_PMOVSQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
31878   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv16qiv16si2_mask, "__builtin_ia32_pmovsxbd512_mask", IX86_BUILTIN_PMOVSXBD512, UNKNOWN, (int) V16SI_FTYPE_V16QI_V16SI_HI },
31879   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8qiv8di2_mask, "__builtin_ia32_pmovsxbq512_mask", IX86_BUILTIN_PMOVSXBQ512, UNKNOWN, (int) V8DI_FTYPE_V16QI_V8DI_QI },
31880   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8siv8di2_mask, "__builtin_ia32_pmovsxdq512_mask", IX86_BUILTIN_PMOVSXDQ512, UNKNOWN, (int) V8DI_FTYPE_V8SI_V8DI_QI },
31881   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv16hiv16si2_mask, "__builtin_ia32_pmovsxwd512_mask", IX86_BUILTIN_PMOVSXWD512, UNKNOWN, (int) V16SI_FTYPE_V16HI_V16SI_HI },
31882   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8hiv8di2_mask, "__builtin_ia32_pmovsxwq512_mask", IX86_BUILTIN_PMOVSXWQ512, UNKNOWN, (int) V8DI_FTYPE_V8HI_V8DI_QI },
31883   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16qi2_mask, "__builtin_ia32_pmovusdb512_mask", IX86_BUILTIN_PMOVUSDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
31884   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16hi2_mask, "__builtin_ia32_pmovusdw512_mask", IX86_BUILTIN_PMOVUSDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
31885   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div16qi2_mask, "__builtin_ia32_pmovusqb512_mask", IX86_BUILTIN_PMOVUSQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
31886   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8si2_mask, "__builtin_ia32_pmovusqd512_mask", IX86_BUILTIN_PMOVUSQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
31887   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8hi2_mask, "__builtin_ia32_pmovusqw512_mask", IX86_BUILTIN_PMOVUSQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
31888   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv16qiv16si2_mask, "__builtin_ia32_pmovzxbd512_mask", IX86_BUILTIN_PMOVZXBD512, UNKNOWN, (int) V16SI_FTYPE_V16QI_V16SI_HI },
31889   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8qiv8di2_mask, "__builtin_ia32_pmovzxbq512_mask", IX86_BUILTIN_PMOVZXBQ512, UNKNOWN, (int) V8DI_FTYPE_V16QI_V8DI_QI },
31890   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8siv8di2_mask, "__builtin_ia32_pmovzxdq512_mask", IX86_BUILTIN_PMOVZXDQ512, UNKNOWN, (int) V8DI_FTYPE_V8SI_V8DI_QI },
31891   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv16hiv16si2_mask, "__builtin_ia32_pmovzxwd512_mask", IX86_BUILTIN_PMOVZXWD512, UNKNOWN, (int) V16SI_FTYPE_V16HI_V16SI_HI },
31892   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8hiv8di2_mask, "__builtin_ia32_pmovzxwq512_mask", IX86_BUILTIN_PMOVZXWQ512, UNKNOWN, (int) V8DI_FTYPE_V8HI_V8DI_QI },
31893   { 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 },
31894   { OPTION_MASK_ISA_AVX512F, CODE_FOR_mulv16si3_mask, "__builtin_ia32_pmulld512_mask"  , IX86_BUILTIN_PMULLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31895   { 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 },
31896   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorv16si3_mask, "__builtin_ia32_pord512_mask", IX86_BUILTIN_PORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31897   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorv8di3_mask, "__builtin_ia32_porq512_mask", IX86_BUILTIN_PORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31898   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolv16si_mask, "__builtin_ia32_prold512_mask", IX86_BUILTIN_PROLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31899   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolv8di_mask, "__builtin_ia32_prolq512_mask", IX86_BUILTIN_PROLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31900   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolvv16si_mask, "__builtin_ia32_prolvd512_mask", IX86_BUILTIN_PROLVD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31901   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolvv8di_mask, "__builtin_ia32_prolvq512_mask", IX86_BUILTIN_PROLVQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31902   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorv16si_mask, "__builtin_ia32_prord512_mask", IX86_BUILTIN_PRORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31903   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorv8di_mask, "__builtin_ia32_prorq512_mask", IX86_BUILTIN_PRORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31904   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorvv16si_mask, "__builtin_ia32_prorvd512_mask", IX86_BUILTIN_PRORVD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31905   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorvv8di_mask, "__builtin_ia32_prorvq512_mask", IX86_BUILTIN_PRORVQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31906   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pshufdv3_mask, "__builtin_ia32_pshufd512_mask", IX86_BUILTIN_PSHUFD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31907   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv16si3_mask, "__builtin_ia32_pslld512_mask", IX86_BUILTIN_PSLLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
31908   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv16si3_mask, "__builtin_ia32_pslldi512_mask", IX86_BUILTIN_PSLLDI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31909   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv8di3_mask, "__builtin_ia32_psllq512_mask", IX86_BUILTIN_PSLLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
31910   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv8di3_mask, "__builtin_ia32_psllqi512_mask", IX86_BUILTIN_PSLLQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31911   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashlvv16si_mask, "__builtin_ia32_psllv16si_mask", IX86_BUILTIN_PSLLVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31912   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashlvv8di_mask, "__builtin_ia32_psllv8di_mask", IX86_BUILTIN_PSLLVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31913   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv16si3_mask, "__builtin_ia32_psrad512_mask", IX86_BUILTIN_PSRAD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
31914   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv16si3_mask, "__builtin_ia32_psradi512_mask", IX86_BUILTIN_PSRADI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31915   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv8di3_mask, "__builtin_ia32_psraq512_mask", IX86_BUILTIN_PSRAQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
31916   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv8di3_mask, "__builtin_ia32_psraqi512_mask", IX86_BUILTIN_PSRAQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31917   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashrvv16si_mask, "__builtin_ia32_psrav16si_mask", IX86_BUILTIN_PSRAVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31918   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashrvv8di_mask, "__builtin_ia32_psrav8di_mask", IX86_BUILTIN_PSRAVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31919   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv16si3_mask, "__builtin_ia32_psrld512_mask", IX86_BUILTIN_PSRLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
31920   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv16si3_mask, "__builtin_ia32_psrldi512_mask", IX86_BUILTIN_PSRLDI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31921   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv8di3_mask, "__builtin_ia32_psrlq512_mask", IX86_BUILTIN_PSRLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
31922   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv8di3_mask, "__builtin_ia32_psrlqi512_mask", IX86_BUILTIN_PSRLQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31923   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_lshrvv16si_mask, "__builtin_ia32_psrlv16si_mask", IX86_BUILTIN_PSRLVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31924   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_lshrvv8di_mask, "__builtin_ia32_psrlv8di_mask", IX86_BUILTIN_PSRLVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31925   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv16si3_mask, "__builtin_ia32_psubd512_mask", IX86_BUILTIN_PSUBD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31926   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv8di3_mask, "__builtin_ia32_psubq512_mask", IX86_BUILTIN_PSUBQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31927   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testmv16si3_mask, "__builtin_ia32_ptestmd512", IX86_BUILTIN_PTESTMD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31928   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testmv8di3_mask, "__builtin_ia32_ptestmq512", IX86_BUILTIN_PTESTMQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31929   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testnmv16si3_mask, "__builtin_ia32_ptestnmd512", IX86_BUILTIN_PTESTNMD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31930   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testnmv8di3_mask, "__builtin_ia32_ptestnmq512", IX86_BUILTIN_PTESTNMQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31931   { 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 },
31932   { 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 },
31933   { 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 },
31934   { 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 },
31935   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorv16si3_mask, "__builtin_ia32_pxord512_mask", IX86_BUILTIN_PXORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31936   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorv8di3_mask, "__builtin_ia32_pxorq512_mask", IX86_BUILTIN_PXORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31937   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rcp14v8df_mask, "__builtin_ia32_rcp14pd512_mask", IX86_BUILTIN_RCP14PD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31938   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rcp14v16sf_mask, "__builtin_ia32_rcp14ps512_mask", IX86_BUILTIN_RCP14PS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31939   { OPTION_MASK_ISA_AVX512F, CODE_FOR_srcp14v2df, "__builtin_ia32_rcp14sd", IX86_BUILTIN_RCP14SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31940   { OPTION_MASK_ISA_AVX512F, CODE_FOR_srcp14v4sf, "__builtin_ia32_rcp14ss", IX86_BUILTIN_RCP14SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31941   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v8df_mask, "__builtin_ia32_rsqrt14pd512_mask", IX86_BUILTIN_RSQRT14PD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31942   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v16sf_mask, "__builtin_ia32_rsqrt14ps512_mask", IX86_BUILTIN_RSQRT14PS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31943   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v2df, "__builtin_ia32_rsqrt14sd", IX86_BUILTIN_RSQRT14SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31944   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v4sf, "__builtin_ia32_rsqrt14ss", IX86_BUILTIN_RSQRT14SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31945   { 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 },
31946   { 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 },
31947   { 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 },
31948   { 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 },
31949   { 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 },
31950   { 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 },
31951   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ucmpv16si3_mask, "__builtin_ia32_ucmpd512_mask", IX86_BUILTIN_UCMPD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_INT_HI },
31952   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ucmpv8di3_mask, "__builtin_ia32_ucmpq512_mask", IX86_BUILTIN_UCMPQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_INT_QI },
31953   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpckhpd512_mask, "__builtin_ia32_unpckhpd512_mask", IX86_BUILTIN_UNPCKHPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
31954   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpckhps512_mask, "__builtin_ia32_unpckhps512_mask", IX86_BUILTIN_UNPCKHPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
31955   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpcklpd512_mask, "__builtin_ia32_unpcklpd512_mask", IX86_BUILTIN_UNPCKLPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
31956   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpcklps512_mask,  "__builtin_ia32_unpcklps512_mask", IX86_BUILTIN_UNPCKLPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
31957   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_clzv16si2_mask, "__builtin_ia32_vplzcntd_512_mask", IX86_BUILTIN_VPCLZCNTD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31958   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_clzv8di2_mask, "__builtin_ia32_vplzcntq_512_mask", IX86_BUILTIN_VPCLZCNTQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31959   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_conflictv16si_mask, "__builtin_ia32_vpconflictsi_512_mask", IX86_BUILTIN_VPCONFLICTD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31960   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_conflictv8di_mask, "__builtin_ia32_vpconflictdi_512_mask", IX86_BUILTIN_VPCONFLICTQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31961   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permv8df_mask, "__builtin_ia32_permdf512_mask", IX86_BUILTIN_VPERMDF512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
31962   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permv8di_mask, "__builtin_ia32_permdi512_mask", IX86_BUILTIN_VPERMDI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31963   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv16si3_mask, "__builtin_ia32_vpermi2vard512_mask", IX86_BUILTIN_VPERMI2VARD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31964   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv8df3_mask, "__builtin_ia32_vpermi2varpd512_mask", IX86_BUILTIN_VPERMI2VARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
31965   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv16sf3_mask, "__builtin_ia32_vpermi2varps512_mask", IX86_BUILTIN_VPERMI2VARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
31966   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv8di3_mask, "__builtin_ia32_vpermi2varq512_mask", IX86_BUILTIN_VPERMI2VARQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31967   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilv8df_mask, "__builtin_ia32_vpermilpd512_mask", IX86_BUILTIN_VPERMILPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
31968   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilv16sf_mask, "__builtin_ia32_vpermilps512_mask", IX86_BUILTIN_VPERMILPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI },
31969   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilvarv8df3_mask, "__builtin_ia32_vpermilvarpd512_mask", IX86_BUILTIN_VPERMILVARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
31970   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilvarv16sf3_mask, "__builtin_ia32_vpermilvarps512_mask", IX86_BUILTIN_VPERMILVARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
31971   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16si3_mask, "__builtin_ia32_vpermt2vard512_mask", IX86_BUILTIN_VPERMT2VARD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31972   { 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 },
31973   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8df3_mask, "__builtin_ia32_vpermt2varpd512_mask", IX86_BUILTIN_VPERMT2VARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_V8DF_QI },
31974   { 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 },
31975   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16sf3_mask, "__builtin_ia32_vpermt2varps512_mask", IX86_BUILTIN_VPERMT2VARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_V16SF_HI },
31976   { 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 },
31977   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8di3_mask, "__builtin_ia32_vpermt2varq512_mask", IX86_BUILTIN_VPERMT2VARQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31978   { 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 },
31979   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv8df_mask, "__builtin_ia32_permvardf512_mask", IX86_BUILTIN_VPERMVARDF512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
31980   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv8di_mask, "__builtin_ia32_permvardi512_mask", IX86_BUILTIN_VPERMVARDI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31981   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv16sf_mask, "__builtin_ia32_permvarsf512_mask", IX86_BUILTIN_VPERMVARSF512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
31982   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv16si_mask, "__builtin_ia32_permvarsi512_mask", IX86_BUILTIN_VPERMVARSI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31983   { 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 },
31984   { 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 },
31985   { 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 },
31986   { 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 },
31987
31988   { OPTION_MASK_ISA_AVX512F, CODE_FOR_copysignv16sf3,  "__builtin_ia32_copysignps512", IX86_BUILTIN_CPYSGNPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF },
31989   { OPTION_MASK_ISA_AVX512F, CODE_FOR_copysignv8df3,  "__builtin_ia32_copysignpd512", IX86_BUILTIN_CPYSGNPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF },
31990   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sqrtv8df2, "__builtin_ia32_sqrtpd512", IX86_BUILTIN_SQRTPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF },
31991   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sqrtv16sf2, "__builtin_ia32_sqrtps512", IX86_BUILTIN_SQRTPS_NR512, UNKNOWN, (int) V16SF_FTYPE_V16SF },
31992   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_exp2v16sf, "__builtin_ia32_exp2ps", IX86_BUILTIN_EXP2PS, UNKNOWN, (int) V16SF_FTYPE_V16SF },
31993   { 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 },
31994   { 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 },
31995   { 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 },
31996
31997   /* Mask arithmetic operations */
31998   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andhi3, "__builtin_ia32_kandhi", IX86_BUILTIN_KAND16, UNKNOWN, (int) HI_FTYPE_HI_HI },
31999   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kandnhi, "__builtin_ia32_kandnhi", IX86_BUILTIN_KANDN16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32000   { OPTION_MASK_ISA_AVX512F, CODE_FOR_one_cmplhi2, "__builtin_ia32_knothi", IX86_BUILTIN_KNOT16, UNKNOWN, (int) HI_FTYPE_HI },
32001   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorhi3, "__builtin_ia32_korhi", IX86_BUILTIN_KOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32002   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kortestchi, "__builtin_ia32_kortestchi", IX86_BUILTIN_KORTESTC16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32003   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kortestzhi, "__builtin_ia32_kortestzhi", IX86_BUILTIN_KORTESTZ16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32004   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kunpckhi, "__builtin_ia32_kunpckhi", IX86_BUILTIN_KUNPCKBW, UNKNOWN, (int) HI_FTYPE_HI_HI },
32005   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kxnorhi, "__builtin_ia32_kxnorhi", IX86_BUILTIN_KXNOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32006   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorhi3, "__builtin_ia32_kxorhi", IX86_BUILTIN_KXOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32007   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kmovw, "__builtin_ia32_kmov16", IX86_BUILTIN_KMOV16, UNKNOWN, (int) HI_FTYPE_HI },
32008
32009   /* SHA */
32010   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1msg1, 0, IX86_BUILTIN_SHA1MSG1, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32011   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1msg2, 0, IX86_BUILTIN_SHA1MSG2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32012   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1nexte, 0, IX86_BUILTIN_SHA1NEXTE, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32013   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1rnds4, 0, IX86_BUILTIN_SHA1RNDS4, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT },
32014   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256msg1, 0, IX86_BUILTIN_SHA256MSG1, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32015   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256msg2, 0, IX86_BUILTIN_SHA256MSG2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32016   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256rnds2, 0, IX86_BUILTIN_SHA256RNDS2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI },
32017
32018   /* AVX512VL.  */
32019   { 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 },
32020   { 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 },
32021   { 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 },
32022   { 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 },
32023   { 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 },
32024   { 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 },
32025   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4df_mask, "__builtin_ia32_movapd256_mask", IX86_BUILTIN_MOVAPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32026   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2df_mask, "__builtin_ia32_movapd128_mask", IX86_BUILTIN_MOVAPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32027   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8sf_mask, "__builtin_ia32_movaps256_mask", IX86_BUILTIN_MOVAPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32028   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4sf_mask, "__builtin_ia32_movaps128_mask", IX86_BUILTIN_MOVAPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32029   { 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 },
32030   { 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 },
32031   { 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 },
32032   { 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 },
32033   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4sf3_mask, "__builtin_ia32_minps_mask", IX86_BUILTIN_MINPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32034   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4sf3_mask, "__builtin_ia32_maxps_mask", IX86_BUILTIN_MAXPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32035   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv2df3_mask, "__builtin_ia32_minpd_mask", IX86_BUILTIN_MINPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32036   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv2df3_mask, "__builtin_ia32_maxpd_mask", IX86_BUILTIN_MAXPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32037   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4df3_mask, "__builtin_ia32_maxpd256_mask", IX86_BUILTIN_MAXPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32038   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8sf3_mask, "__builtin_ia32_maxps256_mask", IX86_BUILTIN_MAXPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32039   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4df3_mask, "__builtin_ia32_minpd256_mask", IX86_BUILTIN_MINPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32040   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8sf3_mask, "__builtin_ia32_minps256_mask", IX86_BUILTIN_MINPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32041   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4sf3_mask, "__builtin_ia32_mulps_mask", IX86_BUILTIN_MULPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32042   { 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 },
32043   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv2df3_mask, "__builtin_ia32_mulpd_mask", IX86_BUILTIN_MULPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32044   { 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 },
32045   { 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 },
32046   { 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 },
32047   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4df3_mask, "__builtin_ia32_mulpd256_mask", IX86_BUILTIN_MULPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32048   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8sf3_mask, "__builtin_ia32_mulps256_mask", IX86_BUILTIN_MULPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32049   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv2df3_mask, "__builtin_ia32_addpd128_mask", IX86_BUILTIN_ADDPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32050   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4df3_mask, "__builtin_ia32_addpd256_mask", IX86_BUILTIN_ADDPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32051   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4sf3_mask, "__builtin_ia32_addps128_mask", IX86_BUILTIN_ADDPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32052   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8sf3_mask, "__builtin_ia32_addps256_mask", IX86_BUILTIN_ADDPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32053   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv2df3_mask, "__builtin_ia32_subpd128_mask", IX86_BUILTIN_SUBPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32054   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4df3_mask, "__builtin_ia32_subpd256_mask", IX86_BUILTIN_SUBPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32055   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4sf3_mask, "__builtin_ia32_subps128_mask", IX86_BUILTIN_SUBPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32056   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8sf3_mask, "__builtin_ia32_subps256_mask", IX86_BUILTIN_SUBPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32057   { 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 },
32058   { 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 },
32059   { 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 },
32060   { 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 },
32061   { 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 },
32062   { 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 },
32063   { 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 },
32064   { 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 },
32065   { 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 },
32066   { 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 },
32067   { 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 },
32068   { 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 },
32069   { 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 },
32070   { 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 },
32071   { 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 },
32072   { 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 },
32073   { 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 },
32074   { 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 },
32075   { 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 },
32076   { 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 },
32077   { 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 },
32078   { 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 },
32079   { 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 },
32080   { 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 },
32081   { 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 },
32082   { 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 },
32083   { 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 },
32084   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv4dfv4si2_mask, "__builtin_ia32_cvtpd2udq256_mask", IX86_BUILTIN_CVTPD2UDQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32085   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv2dfv2si2_mask, "__builtin_ia32_cvtpd2udq128_mask", IX86_BUILTIN_CVTPD2UDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32086   { 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 },
32087   { 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 },
32088   { 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 },
32089   { 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 },
32090   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv8sfv8si2_mask, "__builtin_ia32_cvttps2dq256_mask", IX86_BUILTIN_CVTTPS2DQ256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32091   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4sfv4si2_mask, "__builtin_ia32_cvttps2dq128_mask", IX86_BUILTIN_CVTTPS2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32092   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv8sfv8si2_mask, "__builtin_ia32_cvttps2udq256_mask", IX86_BUILTIN_CVTTPS2UDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32093   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4sfv4si2_mask, "__builtin_ia32_cvttps2udq128_mask", IX86_BUILTIN_CVTTPS2UDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32094   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4dfv4si2_mask, "__builtin_ia32_cvttpd2dq256_mask", IX86_BUILTIN_CVTTPD2DQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32095   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvttpd2dq_mask, "__builtin_ia32_cvttpd2dq128_mask", IX86_BUILTIN_CVTTPD2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32096   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4dfv4si2_mask, "__builtin_ia32_cvttpd2udq256_mask", IX86_BUILTIN_CVTTPD2UDQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32097   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv2dfv2si2_mask, "__builtin_ia32_cvttpd2udq128_mask", IX86_BUILTIN_CVTTPD2UDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32098   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtpd2dq256_mask, "__builtin_ia32_cvtpd2dq256_mask", IX86_BUILTIN_CVTPD2DQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32099   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtpd2dq_mask, "__builtin_ia32_cvtpd2dq128_mask", IX86_BUILTIN_CVTPD2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32100   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4siv4df2_mask, "__builtin_ia32_cvtdq2pd256_mask", IX86_BUILTIN_CVTDQ2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SI_V4DF_QI },
32101   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtdq2pd_mask, "__builtin_ia32_cvtdq2pd128_mask", IX86_BUILTIN_CVTDQ2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SI_V2DF_QI },
32102   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4siv4df2_mask, "__builtin_ia32_cvtudq2pd256_mask", IX86_BUILTIN_CVTUDQ2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SI_V4DF_QI },
32103   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv2siv2df2_mask, "__builtin_ia32_cvtudq2pd128_mask", IX86_BUILTIN_CVTUDQ2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SI_V2DF_QI },
32104   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv8siv8sf2_mask, "__builtin_ia32_cvtdq2ps256_mask", IX86_BUILTIN_CVTDQ2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_QI },
32105   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4siv4sf2_mask, "__builtin_ia32_cvtdq2ps128_mask", IX86_BUILTIN_CVTDQ2PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_QI },
32106   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv8siv8sf2_mask, "__builtin_ia32_cvtudq2ps256_mask", IX86_BUILTIN_CVTUDQ2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_QI },
32107   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4siv4sf2_mask, "__builtin_ia32_cvtudq2ps128_mask", IX86_BUILTIN_CVTUDQ2PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_QI },
32108   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtps2pd256_mask, "__builtin_ia32_cvtps2pd256_mask", IX86_BUILTIN_CVTPS2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SF_V4DF_QI },
32109   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtps2pd_mask, "__builtin_ia32_cvtps2pd128_mask", IX86_BUILTIN_CVTPS2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SF_V2DF_QI },
32110   { 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 },
32111   { 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 },
32112   { 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 },
32113   { 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 },
32114   { 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 },
32115   { 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 },
32116   { 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 },
32117   { 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 },
32118   { 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 },
32119   { 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 },
32120   { 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 },
32121   { 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 },
32122   { 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 },
32123   { 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 },
32124   { 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 },
32125   { 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 },
32126   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv8sf_mask, "__builtin_ia32_broadcastss256_mask", IX86_BUILTIN_BROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_V4SF_V8SF_QI },
32127   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4sf_mask, "__builtin_ia32_broadcastss128_mask", IX86_BUILTIN_BROADCASTSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32128   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4df_mask, "__builtin_ia32_broadcastsd256_mask", IX86_BUILTIN_BROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_V2DF_V4DF_QI },
32129   { 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 },
32130   { 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 },
32131   { 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 },
32132   { 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 },
32133   { 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 },
32134   { 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 },
32135   { 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 },
32136   { 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 },
32137   { 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 },
32138   { 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 },
32139   { 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 },
32140   { 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 },
32141   { 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 },
32142   { 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 },
32143   { 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 },
32144   { 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 },
32145   { 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 },
32146   { 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 },
32147   { 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 },
32148   { 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 },
32149   { 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 },
32150   { 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 },
32151   { 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 },
32152   { 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 },
32153   { 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 },
32154   { 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 },
32155   { 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 },
32156   { 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 },
32157   { 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 },
32158   { 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 },
32159   { 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 },
32160   { 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 },
32161   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducesv2df, "__builtin_ia32_reducesd", IX86_BUILTIN_REDUCESD_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32162   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducesv4sf, "__builtin_ia32_reducess", IX86_BUILTIN_REDUCESS_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32163   { 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 },
32164   { 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 },
32165   { 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 },
32166   { 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 },
32167   { 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 },
32168   { 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 },
32169   { 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 },
32170   { 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 },
32171   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v4df_mask, "__builtin_ia32_rcp14pd256_mask", IX86_BUILTIN_RCP14PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32172   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v2df_mask, "__builtin_ia32_rcp14pd128_mask", IX86_BUILTIN_RCP14PD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32173   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v8sf_mask, "__builtin_ia32_rcp14ps256_mask", IX86_BUILTIN_RCP14PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32174   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v4sf_mask, "__builtin_ia32_rcp14ps128_mask", IX86_BUILTIN_RCP14PS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32175   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v4df_mask, "__builtin_ia32_rsqrt14pd256_mask", IX86_BUILTIN_RSQRT14PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32176   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v2df_mask, "__builtin_ia32_rsqrt14pd128_mask", IX86_BUILTIN_RSQRT14PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32177   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v8sf_mask, "__builtin_ia32_rsqrt14ps256_mask", IX86_BUILTIN_RSQRT14PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32178   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v4sf_mask, "__builtin_ia32_rsqrt14ps128_mask", IX86_BUILTIN_RSQRT14PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32179   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_sqrtv4df2_mask, "__builtin_ia32_sqrtpd256_mask", IX86_BUILTIN_SQRTPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32180   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_sqrtv2df2_mask, "__builtin_ia32_sqrtpd128_mask", IX86_BUILTIN_SQRTPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32181   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_sqrtv8sf2_mask, "__builtin_ia32_sqrtps256_mask", IX86_BUILTIN_SQRTPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32182   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_sqrtv4sf2_mask, "__builtin_ia32_sqrtps128_mask", IX86_BUILTIN_SQRTPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32183   { 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 },
32184   { 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 },
32185   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4si3_mask, "__builtin_ia32_paddd128_mask", IX86_BUILTIN_PADDD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32186   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv2di3_mask, "__builtin_ia32_paddq128_mask", IX86_BUILTIN_PADDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32187   { 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 },
32188   { 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 },
32189   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4si3_mask, "__builtin_ia32_psubd128_mask", IX86_BUILTIN_PSUBD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32190   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv2di3_mask, "__builtin_ia32_psubq128_mask", IX86_BUILTIN_PSUBQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32191   { 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 },
32192   { 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 },
32193   { 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 },
32194   { 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 },
32195   { 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 },
32196   { 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 },
32197   { 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 },
32198   { 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 },
32199   { 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 },
32200   { 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 },
32201   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8si3_mask, "__builtin_ia32_paddd256_mask", IX86_BUILTIN_PADDD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32202   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4di3_mask, "__builtin_ia32_paddq256_mask", IX86_BUILTIN_PADDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32203   { 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 },
32204   { 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 },
32205   { 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 },
32206   { 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 },
32207   { 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 },
32208   { 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 },
32209   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8si3_mask, "__builtin_ia32_psubd256_mask", IX86_BUILTIN_PSUBD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32210   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4di3_mask, "__builtin_ia32_psubq256_mask", IX86_BUILTIN_PSUBQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32211   { 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 },
32212   { 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 },
32213   { 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 },
32214   { 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 },
32215   { 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 },
32216   { 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 },
32217   { 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 },
32218   { 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 },
32219   { 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 },
32220   { 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 },
32221   { 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 },
32222   { 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 },
32223   { 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 },
32224   { 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 },
32225   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4qi2_mask, "__builtin_ia32_pmovdb128_mask", IX86_BUILTIN_PMOVDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32226   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8qi2_mask, "__builtin_ia32_pmovdb256_mask", IX86_BUILTIN_PMOVDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32227   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4qi2_mask, "__builtin_ia32_pmovsdb128_mask", IX86_BUILTIN_PMOVSDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32228   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8qi2_mask, "__builtin_ia32_pmovsdb256_mask", IX86_BUILTIN_PMOVSDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32229   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4qi2_mask, "__builtin_ia32_pmovusdb128_mask", IX86_BUILTIN_PMOVUSDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32230   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8qi2_mask, "__builtin_ia32_pmovusdb256_mask", IX86_BUILTIN_PMOVUSDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32231   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4hi2_mask, "__builtin_ia32_pmovdw128_mask", IX86_BUILTIN_PMOVDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32232   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8hi2_mask, "__builtin_ia32_pmovdw256_mask", IX86_BUILTIN_PMOVDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32233   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4hi2_mask, "__builtin_ia32_pmovsdw128_mask", IX86_BUILTIN_PMOVSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32234   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8hi2_mask, "__builtin_ia32_pmovsdw256_mask", IX86_BUILTIN_PMOVSDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32235   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4hi2_mask, "__builtin_ia32_pmovusdw128_mask", IX86_BUILTIN_PMOVUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32236   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8hi2_mask, "__builtin_ia32_pmovusdw256_mask", IX86_BUILTIN_PMOVUSDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32237   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2qi2_mask, "__builtin_ia32_pmovqb128_mask", IX86_BUILTIN_PMOVQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32238   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4qi2_mask, "__builtin_ia32_pmovqb256_mask", IX86_BUILTIN_PMOVQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32239   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2qi2_mask, "__builtin_ia32_pmovsqb128_mask", IX86_BUILTIN_PMOVSQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32240   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4qi2_mask, "__builtin_ia32_pmovsqb256_mask", IX86_BUILTIN_PMOVSQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32241   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2qi2_mask, "__builtin_ia32_pmovusqb128_mask", IX86_BUILTIN_PMOVUSQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32242   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4qi2_mask, "__builtin_ia32_pmovusqb256_mask", IX86_BUILTIN_PMOVUSQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32243   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2hi2_mask, "__builtin_ia32_pmovqw128_mask", IX86_BUILTIN_PMOVQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32244   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4hi2_mask, "__builtin_ia32_pmovqw256_mask", IX86_BUILTIN_PMOVQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32245   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2hi2_mask, "__builtin_ia32_pmovsqw128_mask", IX86_BUILTIN_PMOVSQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32246   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4hi2_mask, "__builtin_ia32_pmovsqw256_mask", IX86_BUILTIN_PMOVSQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32247   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2hi2_mask, "__builtin_ia32_pmovusqw128_mask", IX86_BUILTIN_PMOVUSQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32248   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4hi2_mask, "__builtin_ia32_pmovusqw256_mask", IX86_BUILTIN_PMOVUSQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32249   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2si2_mask, "__builtin_ia32_pmovqd128_mask", IX86_BUILTIN_PMOVQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32250   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4si2_mask, "__builtin_ia32_pmovqd256_mask", IX86_BUILTIN_PMOVQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32251   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2si2_mask, "__builtin_ia32_pmovsqd128_mask", IX86_BUILTIN_PMOVSQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32252   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4si2_mask, "__builtin_ia32_pmovsqd256_mask", IX86_BUILTIN_PMOVSQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32253   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2si2_mask, "__builtin_ia32_pmovusqd128_mask", IX86_BUILTIN_PMOVUSQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32254   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4si2_mask, "__builtin_ia32_pmovusqd256_mask", IX86_BUILTIN_PMOVUSQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32255   { 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 },
32256   { 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 },
32257   { 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 },
32258   { 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 },
32259   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv8sf_mask, "__builtin_ia32_getexpps256_mask", IX86_BUILTIN_GETEXPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32260   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv4df_mask, "__builtin_ia32_getexppd256_mask", IX86_BUILTIN_GETEXPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32261   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv4sf_mask, "__builtin_ia32_getexpps128_mask", IX86_BUILTIN_GETEXPPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32262   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv2df_mask, "__builtin_ia32_getexppd128_mask", IX86_BUILTIN_GETEXPPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32263   { 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 },
32264   { 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 },
32265   { 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 },
32266   { 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 },
32267   { 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 },
32268   { 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 },
32269   { 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 },
32270   { 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 },
32271   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv4di2_mask, "__builtin_ia32_pabsq256_mask", IX86_BUILTIN_PABSQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32272   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv2di2_mask, "__builtin_ia32_pabsq128_mask", IX86_BUILTIN_PABSQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32273   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv8si2_mask, "__builtin_ia32_pabsd256_mask", IX86_BUILTIN_PABSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32274   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv4si2_mask, "__builtin_ia32_pabsd128_mask", IX86_BUILTIN_PABSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32275   { 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 },
32276   { 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 },
32277   { 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 },
32278   { 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 },
32279   { 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 },
32280   { 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 },
32281   { 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 },
32282   { 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 },
32283   { 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 },
32284   { 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 },
32285   { 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 },
32286   { 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 },
32287   { 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 },
32288   { 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 },
32289   { 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 },
32290   { 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 },
32291   { 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 },
32292   { 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 },
32293   { 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 },
32294   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4si3_mask, "__builtin_ia32_pslldi128_mask", IX86_BUILTIN_PSLLDI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32295   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv2di3_mask, "__builtin_ia32_psllqi128_mask", IX86_BUILTIN_PSLLQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32296   { 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 },
32297   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4si3_mask, "__builtin_ia32_pslld128_mask", IX86_BUILTIN_PSLLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32298   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv2di3_mask, "__builtin_ia32_psllq128_mask", IX86_BUILTIN_PSLLQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32299   { 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 },
32300   { 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 },
32301   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8si3_mask, "__builtin_ia32_pslldi256_mask", IX86_BUILTIN_PSLLDI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32302   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8si3_mask, "__builtin_ia32_pslld256_mask", IX86_BUILTIN_PSLLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32303   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4di3_mask, "__builtin_ia32_psllqi256_mask", IX86_BUILTIN_PSLLQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32304   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4di3_mask, "__builtin_ia32_psllq256_mask", IX86_BUILTIN_PSLLQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32305   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4si3_mask, "__builtin_ia32_psradi128_mask", IX86_BUILTIN_PSRADI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32306   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4si3_mask, "__builtin_ia32_psrad128_mask", IX86_BUILTIN_PSRAD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32307   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8si3_mask, "__builtin_ia32_psradi256_mask", IX86_BUILTIN_PSRADI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32308   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8si3_mask, "__builtin_ia32_psrad256_mask", IX86_BUILTIN_PSRAD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32309   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv2di3_mask, "__builtin_ia32_psraqi128_mask", IX86_BUILTIN_PSRAQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32310   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv2di3_mask, "__builtin_ia32_psraq128_mask", IX86_BUILTIN_PSRAQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32311   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4di3_mask, "__builtin_ia32_psraqi256_mask", IX86_BUILTIN_PSRAQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32312   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4di3_mask, "__builtin_ia32_psraq256_mask", IX86_BUILTIN_PSRAQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32313   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv8si3_mask, "__builtin_ia32_pandd256_mask", IX86_BUILTIN_PANDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32314   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4si3_mask, "__builtin_ia32_pandd128_mask", IX86_BUILTIN_PANDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32315   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4si3_mask, "__builtin_ia32_psrldi128_mask", IX86_BUILTIN_PSRLDI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32316   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4si3_mask, "__builtin_ia32_psrld128_mask", IX86_BUILTIN_PSRLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32317   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8si3_mask, "__builtin_ia32_psrldi256_mask", IX86_BUILTIN_PSRLDI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32318   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8si3_mask, "__builtin_ia32_psrld256_mask", IX86_BUILTIN_PSRLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32319   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv2di3_mask, "__builtin_ia32_psrlqi128_mask", IX86_BUILTIN_PSRLQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32320   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv2di3_mask, "__builtin_ia32_psrlq128_mask", IX86_BUILTIN_PSRLQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32321   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4di3_mask, "__builtin_ia32_psrlqi256_mask", IX86_BUILTIN_PSRLQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32322   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4di3_mask, "__builtin_ia32_psrlq256_mask", IX86_BUILTIN_PSRLQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32323   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4di3_mask, "__builtin_ia32_pandq256_mask", IX86_BUILTIN_PANDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32324   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv2di3_mask, "__builtin_ia32_pandq128_mask", IX86_BUILTIN_PANDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32325   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_andnotv8si3_mask, "__builtin_ia32_pandnd256_mask", IX86_BUILTIN_PANDND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32326   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv4si3_mask, "__builtin_ia32_pandnd128_mask", IX86_BUILTIN_PANDND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32327   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_andnotv4di3_mask, "__builtin_ia32_pandnq256_mask", IX86_BUILTIN_PANDNQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32328   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv2di3_mask, "__builtin_ia32_pandnq128_mask", IX86_BUILTIN_PANDNQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32329   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv8si3_mask, "__builtin_ia32_pord256_mask", IX86_BUILTIN_PORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32330   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4si3_mask, "__builtin_ia32_pord128_mask", IX86_BUILTIN_PORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32331   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4di3_mask, "__builtin_ia32_porq256_mask", IX86_BUILTIN_PORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32332   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv2di3_mask, "__builtin_ia32_porq128_mask", IX86_BUILTIN_PORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32333   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv8si3_mask, "__builtin_ia32_pxord256_mask", IX86_BUILTIN_PXORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32334   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4si3_mask, "__builtin_ia32_pxord128_mask", IX86_BUILTIN_PXORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32335   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4di3_mask, "__builtin_ia32_pxorq256_mask", IX86_BUILTIN_PXORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32336   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv2di3_mask, "__builtin_ia32_pxorq128_mask", IX86_BUILTIN_PXORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32337   { 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 },
32338   { 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 },
32339   { 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 },
32340   { 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 },
32341   { 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 },
32342   { 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 },
32343   { 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 },
32344   { 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 },
32345   { 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 },
32346   { 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 },
32347   { 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 },
32348   { 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 },
32349   { 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 },
32350   { 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 },
32351   { 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 },
32352   { 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 },
32353   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv4df_mask, "__builtin_ia32_scalefpd256_mask", IX86_BUILTIN_SCALEFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32354   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv8sf_mask, "__builtin_ia32_scalefps256_mask", IX86_BUILTIN_SCALEFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32355   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv2df_mask, "__builtin_ia32_scalefpd128_mask", IX86_BUILTIN_SCALEFPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32356   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv4sf_mask, "__builtin_ia32_scalefps128_mask", IX86_BUILTIN_SCALEFPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32357   { 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 },
32358   { 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 },
32359   { 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 },
32360   { 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 },
32361   { 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 },
32362   { 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 },
32363   { 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 },
32364   { 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 },
32365   { 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 },
32366   { 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 },
32367   { 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 },
32368   { 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 },
32369   { 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 },
32370   { 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 },
32371   { 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 },
32372   { 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 },
32373   { 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 },
32374   { 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 },
32375   { 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 },
32376   { 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 },
32377   { 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 },
32378   { 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 },
32379   { 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 },
32380   { 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 },
32381   { 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 },
32382   { 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 },
32383   { 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 },
32384   { 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 },
32385   { 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 },
32386   { 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 },
32387   { 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 },
32388   { 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 },
32389   { 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 },
32390   { 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 },
32391   { 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 },
32392   { 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 },
32393   { 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 },
32394   { 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 },
32395   { 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 },
32396   { 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 },
32397   { 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 },
32398   { 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 },
32399   { 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 },
32400   { 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 },
32401   { 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 },
32402   { 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 },
32403   { 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 },
32404   { 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 },
32405   { 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 },
32406   { 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 },
32407   { 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 },
32408   { 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 },
32409   { 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 },
32410   { 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 },
32411   { 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 },
32412   { 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 },
32413   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ufix_notruncv8sfv8si_mask, "__builtin_ia32_cvtps2udq256_mask", IX86_BUILTIN_CVTPS2UDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32414   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ufix_notruncv4sfv4si_mask, "__builtin_ia32_cvtps2udq128_mask", IX86_BUILTIN_CVTPS2UDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32415   { 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 },
32416   { 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 },
32417   { 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 },
32418   { 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 },
32419   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv8sf_mask, "__builtin_ia32_getmantps256_mask", IX86_BUILTIN_GETMANTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT_V8SF_QI },
32420   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv4sf_mask, "__builtin_ia32_getmantps128_mask", IX86_BUILTIN_GETMANTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_V4SF_QI },
32421   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv4df_mask, "__builtin_ia32_getmantpd256_mask", IX86_BUILTIN_GETMANTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32422   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv2df_mask, "__builtin_ia32_getmantpd128_mask", IX86_BUILTIN_GETMANTPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT_V2DF_QI },
32423   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movddup256_mask, "__builtin_ia32_movddup256_mask", IX86_BUILTIN_MOVDDUP256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32424   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_dupv2df_mask, "__builtin_ia32_movddup128_mask", IX86_BUILTIN_MOVDDUP128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32425   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movshdup256_mask, "__builtin_ia32_movshdup256_mask", IX86_BUILTIN_MOVSHDUP256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32426   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse3_movshdup_mask, "__builtin_ia32_movshdup128_mask", IX86_BUILTIN_MOVSHDUP128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32427   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movsldup256_mask, "__builtin_ia32_movsldup256_mask", IX86_BUILTIN_MOVSLDUP256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32428   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse3_movsldup_mask, "__builtin_ia32_movsldup128_mask", IX86_BUILTIN_MOVSLDUP128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32429   { 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 },
32430   { 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 },
32431   { 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 },
32432   { 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 },
32433   { 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 },
32434   { 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 },
32435   { 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 },
32436   { 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 },
32437   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4di3_mask, "__builtin_ia32_vpermt2varq256_mask", IX86_BUILTIN_VPERMT2VARQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32438   { 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 },
32439   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8si3_mask, "__builtin_ia32_vpermt2vard256_mask", IX86_BUILTIN_VPERMT2VARD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32440   { 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 },
32441   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4di3_mask, "__builtin_ia32_vpermi2varq256_mask", IX86_BUILTIN_VPERMI2VARQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32442   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8si3_mask, "__builtin_ia32_vpermi2vard256_mask", IX86_BUILTIN_VPERMI2VARD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32443   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4df3_mask, "__builtin_ia32_vpermt2varpd256_mask", IX86_BUILTIN_VPERMT2VARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DI_V4DF_V4DF_QI },
32444   { 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 },
32445   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8sf3_mask, "__builtin_ia32_vpermt2varps256_mask", IX86_BUILTIN_VPERMT2VARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_V8SF_QI },
32446   { 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 },
32447   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4df3_mask, "__builtin_ia32_vpermi2varpd256_mask", IX86_BUILTIN_VPERMI2VARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI_V4DF_QI },
32448   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8sf3_mask, "__builtin_ia32_vpermi2varps256_mask", IX86_BUILTIN_VPERMI2VARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI_V8SF_QI },
32449   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2di3_mask, "__builtin_ia32_vpermt2varq128_mask", IX86_BUILTIN_VPERMT2VARQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32450   { 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 },
32451   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4si3_mask, "__builtin_ia32_vpermt2vard128_mask", IX86_BUILTIN_VPERMT2VARD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32452   { 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 },
32453   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv2di3_mask, "__builtin_ia32_vpermi2varq128_mask", IX86_BUILTIN_VPERMI2VARQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32454   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4si3_mask, "__builtin_ia32_vpermi2vard128_mask", IX86_BUILTIN_VPERMI2VARD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32455   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2df3_mask, "__builtin_ia32_vpermt2varpd128_mask", IX86_BUILTIN_VPERMT2VARPD128, UNKNOWN, (int) V2DF_FTYPE_V2DI_V2DF_V2DF_QI },
32456   { 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 },
32457   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4sf3_mask, "__builtin_ia32_vpermt2varps128_mask", IX86_BUILTIN_VPERMT2VARPS128, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_V4SF_QI },
32458   { 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 },
32459   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv2df3_mask, "__builtin_ia32_vpermi2varpd128_mask", IX86_BUILTIN_VPERMI2VARPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI_V2DF_QI },
32460   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4sf3_mask, "__builtin_ia32_vpermi2varps128_mask", IX86_BUILTIN_VPERMI2VARPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI_V4SF_QI },
32461   { 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 },
32462   { 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 },
32463   { 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 },
32464   { 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 },
32465   { 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 },
32466   { 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 },
32467   { 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 },
32468   { 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 },
32469   { 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 },
32470   { 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 },
32471   { 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 },
32472   { 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 },
32473   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv4di_mask, "__builtin_ia32_prolvq256_mask", IX86_BUILTIN_PROLVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32474   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv2di_mask, "__builtin_ia32_prolvq128_mask", IX86_BUILTIN_PROLVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32475   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv4di_mask, "__builtin_ia32_prolq256_mask", IX86_BUILTIN_PROLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32476   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv2di_mask, "__builtin_ia32_prolq128_mask", IX86_BUILTIN_PROLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32477   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv4di_mask, "__builtin_ia32_prorvq256_mask", IX86_BUILTIN_PRORVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32478   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv2di_mask, "__builtin_ia32_prorvq128_mask", IX86_BUILTIN_PRORVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32479   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv4di_mask, "__builtin_ia32_prorq256_mask", IX86_BUILTIN_PRORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32480   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv2di_mask, "__builtin_ia32_prorq128_mask", IX86_BUILTIN_PRORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32481   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv2di_mask, "__builtin_ia32_psravq128_mask", IX86_BUILTIN_PSRAVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32482   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv4di_mask, "__builtin_ia32_psravq256_mask", IX86_BUILTIN_PSRAVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32483   { 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 },
32484   { 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 },
32485   { 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 },
32486   { 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 },
32487   { 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 },
32488   { 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 },
32489   { 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 },
32490   { 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 },
32491   { 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 },
32492   { 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 },
32493   { 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 },
32494   { 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 },
32495   { 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 },
32496   { 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 },
32497   { 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 },
32498   { 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 },
32499   { 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 },
32500   { 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 },
32501   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv8si_mask, "__builtin_ia32_prorvd256_mask", IX86_BUILTIN_PRORVD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32502   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv8si_mask, "__builtin_ia32_prolvd256_mask", IX86_BUILTIN_PROLVD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32503   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv8si_mask, "__builtin_ia32_prord256_mask", IX86_BUILTIN_PRORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32504   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv8si_mask, "__builtin_ia32_prold256_mask", IX86_BUILTIN_PROLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32505   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv4si_mask, "__builtin_ia32_prorvd128_mask", IX86_BUILTIN_PRORVD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32506   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv4si_mask, "__builtin_ia32_prolvd128_mask", IX86_BUILTIN_PROLVD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32507   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv4si_mask, "__builtin_ia32_prord128_mask", IX86_BUILTIN_PRORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32508   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv4si_mask, "__builtin_ia32_prold128_mask", IX86_BUILTIN_PROLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32509   { 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 },
32510   { 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 },
32511   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vmfpclassv2df, "__builtin_ia32_fpclasssd", IX86_BUILTIN_FPCLASSSD, UNKNOWN, (int) QI_FTYPE_V2DF_INT },
32512   { 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 },
32513   { 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 },
32514   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vmfpclassv4sf, "__builtin_ia32_fpclassss", IX86_BUILTIN_FPCLASSSS, UNKNOWN, (int) QI_FTYPE_V4SF_INT },
32515   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtb2maskv16qi, "__builtin_ia32_cvtb2mask128", IX86_BUILTIN_CVTB2MASK128, UNKNOWN, (int) HI_FTYPE_V16QI },
32516   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtb2maskv32qi, "__builtin_ia32_cvtb2mask256", IX86_BUILTIN_CVTB2MASK256, UNKNOWN, (int) SI_FTYPE_V32QI },
32517   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtw2maskv8hi, "__builtin_ia32_cvtw2mask128", IX86_BUILTIN_CVTW2MASK128, UNKNOWN, (int) QI_FTYPE_V8HI },
32518   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtw2maskv16hi, "__builtin_ia32_cvtw2mask256", IX86_BUILTIN_CVTW2MASK256, UNKNOWN, (int) HI_FTYPE_V16HI },
32519   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtd2maskv4si, "__builtin_ia32_cvtd2mask128", IX86_BUILTIN_CVTD2MASK128, UNKNOWN, (int) QI_FTYPE_V4SI },
32520   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtd2maskv8si, "__builtin_ia32_cvtd2mask256", IX86_BUILTIN_CVTD2MASK256, UNKNOWN, (int) QI_FTYPE_V8SI },
32521   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtq2maskv2di, "__builtin_ia32_cvtq2mask128", IX86_BUILTIN_CVTQ2MASK128, UNKNOWN, (int) QI_FTYPE_V2DI },
32522   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtq2maskv4di, "__builtin_ia32_cvtq2mask256", IX86_BUILTIN_CVTQ2MASK256, UNKNOWN, (int) QI_FTYPE_V4DI },
32523   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2bv16qi, "__builtin_ia32_cvtmask2b128", IX86_BUILTIN_CVTMASK2B128, UNKNOWN, (int) V16QI_FTYPE_HI },
32524   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2bv32qi, "__builtin_ia32_cvtmask2b256", IX86_BUILTIN_CVTMASK2B256, UNKNOWN, (int) V32QI_FTYPE_SI },
32525   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2wv8hi, "__builtin_ia32_cvtmask2w128", IX86_BUILTIN_CVTMASK2W128, UNKNOWN, (int) V8HI_FTYPE_QI },
32526   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2wv16hi, "__builtin_ia32_cvtmask2w256", IX86_BUILTIN_CVTMASK2W256, UNKNOWN, (int) V16HI_FTYPE_HI },
32527   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2dv4si, "__builtin_ia32_cvtmask2d128", IX86_BUILTIN_CVTMASK2D128, UNKNOWN, (int) V4SI_FTYPE_QI },
32528   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2dv8si, "__builtin_ia32_cvtmask2d256", IX86_BUILTIN_CVTMASK2D256, UNKNOWN, (int) V8SI_FTYPE_QI },
32529   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2qv2di, "__builtin_ia32_cvtmask2q128", IX86_BUILTIN_CVTMASK2Q128, UNKNOWN, (int) V2DI_FTYPE_QI },
32530   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2qv4di, "__builtin_ia32_cvtmask2q256", IX86_BUILTIN_CVTMASK2Q256, UNKNOWN, (int) V4DI_FTYPE_QI },
32531   { 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 },
32532   { 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 },
32533   { 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 },
32534   { 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 },
32535   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv4si3_mask, "__builtin_ia32_pcmpeqd128_mask", IX86_BUILTIN_PCMPEQD128_MASK, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32536   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv8si3_mask, "__builtin_ia32_pcmpeqd256_mask", IX86_BUILTIN_PCMPEQD256_MASK, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32537   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv2di3_mask, "__builtin_ia32_pcmpeqq128_mask", IX86_BUILTIN_PCMPEQQ128_MASK, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32538   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv4di3_mask, "__builtin_ia32_pcmpeqq256_mask", IX86_BUILTIN_PCMPEQQ256_MASK, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32539   { 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 },
32540   { 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 },
32541   { 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 },
32542   { 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 },
32543   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv4si3_mask, "__builtin_ia32_pcmpgtd128_mask", IX86_BUILTIN_PCMPGTD128_MASK, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32544   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv8si3_mask, "__builtin_ia32_pcmpgtd256_mask", IX86_BUILTIN_PCMPGTD256_MASK, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32545   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv2di3_mask, "__builtin_ia32_pcmpgtq128_mask", IX86_BUILTIN_PCMPGTQ128_MASK, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32546   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv4di3_mask, "__builtin_ia32_pcmpgtq256_mask", IX86_BUILTIN_PCMPGTQ256_MASK, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32547   { 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 },
32548   { 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 },
32549   { 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 },
32550   { 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 },
32551   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv4si3_mask, "__builtin_ia32_ptestmd128", IX86_BUILTIN_PTESTMD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32552   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv8si3_mask, "__builtin_ia32_ptestmd256", IX86_BUILTIN_PTESTMD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32553   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv2di3_mask, "__builtin_ia32_ptestmq128", IX86_BUILTIN_PTESTMQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32554   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv4di3_mask, "__builtin_ia32_ptestmq256", IX86_BUILTIN_PTESTMQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32555   { 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 },
32556   { 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 },
32557   { 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 },
32558   { 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 },
32559   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv4si3_mask, "__builtin_ia32_ptestnmd128", IX86_BUILTIN_PTESTNMD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32560   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv8si3_mask, "__builtin_ia32_ptestnmd256", IX86_BUILTIN_PTESTNMD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32561   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv2di3_mask, "__builtin_ia32_ptestnmq128", IX86_BUILTIN_PTESTNMQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32562   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv4di3_mask, "__builtin_ia32_ptestnmq256", IX86_BUILTIN_PTESTNMQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32563   { 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 },
32564   { 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 },
32565   { 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 },
32566   { 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 },
32567   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4df_mask, "__builtin_ia32_compressdf256_mask", IX86_BUILTIN_COMPRESSPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32568   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv2df_mask, "__builtin_ia32_compressdf128_mask", IX86_BUILTIN_COMPRESSPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32569   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv8sf_mask, "__builtin_ia32_compresssf256_mask", IX86_BUILTIN_COMPRESSPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32570   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4sf_mask, "__builtin_ia32_compresssf128_mask", IX86_BUILTIN_COMPRESSPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32571   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4di_mask, "__builtin_ia32_compressdi256_mask", IX86_BUILTIN_PCOMPRESSQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32572   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv2di_mask, "__builtin_ia32_compressdi128_mask", IX86_BUILTIN_PCOMPRESSQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32573   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv8si_mask, "__builtin_ia32_compresssi256_mask", IX86_BUILTIN_PCOMPRESSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32574   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4si_mask, "__builtin_ia32_compresssi128_mask", IX86_BUILTIN_PCOMPRESSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32575   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_mask, "__builtin_ia32_expanddf256_mask", IX86_BUILTIN_EXPANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32576   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_mask, "__builtin_ia32_expanddf128_mask", IX86_BUILTIN_EXPANDPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32577   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_mask, "__builtin_ia32_expandsf256_mask", IX86_BUILTIN_EXPANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32578   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_mask, "__builtin_ia32_expandsf128_mask", IX86_BUILTIN_EXPANDPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32579   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_mask, "__builtin_ia32_expanddi256_mask", IX86_BUILTIN_PEXPANDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32580   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_mask, "__builtin_ia32_expanddi128_mask", IX86_BUILTIN_PEXPANDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32581   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_mask, "__builtin_ia32_expandsi256_mask", IX86_BUILTIN_PEXPANDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32582   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_mask, "__builtin_ia32_expandsi128_mask", IX86_BUILTIN_PEXPANDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32583   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_maskz, "__builtin_ia32_expanddf256_maskz", IX86_BUILTIN_EXPANDPD256Z, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32584   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_maskz, "__builtin_ia32_expanddf128_maskz", IX86_BUILTIN_EXPANDPD128Z, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32585   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_maskz, "__builtin_ia32_expandsf256_maskz", IX86_BUILTIN_EXPANDPS256Z, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32586   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_maskz, "__builtin_ia32_expandsf128_maskz", IX86_BUILTIN_EXPANDPS128Z, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32587   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_maskz, "__builtin_ia32_expanddi256_maskz", IX86_BUILTIN_PEXPANDQ256Z, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32588   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_maskz, "__builtin_ia32_expanddi128_maskz", IX86_BUILTIN_PEXPANDQ128Z, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32589   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_maskz, "__builtin_ia32_expandsi256_maskz", IX86_BUILTIN_PEXPANDD256Z, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32590   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_maskz, "__builtin_ia32_expandsi128_maskz", IX86_BUILTIN_PEXPANDD128Z, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32591   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8si3_mask, "__builtin_ia32_pmaxsd256_mask", IX86_BUILTIN_PMAXSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32592   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8si3_mask, "__builtin_ia32_pminsd256_mask", IX86_BUILTIN_PMINSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32593   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv8si3_mask, "__builtin_ia32_pmaxud256_mask", IX86_BUILTIN_PMAXUD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32594   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv8si3_mask, "__builtin_ia32_pminud256_mask", IX86_BUILTIN_PMINUD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32595   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4si3_mask, "__builtin_ia32_pmaxsd128_mask", IX86_BUILTIN_PMAXSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32596   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4si3_mask, "__builtin_ia32_pminsd128_mask", IX86_BUILTIN_PMINSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32597   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv4si3_mask, "__builtin_ia32_pmaxud128_mask", IX86_BUILTIN_PMAXUD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32598   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv4si3_mask, "__builtin_ia32_pminud128_mask", IX86_BUILTIN_PMINUD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32599   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4di3_mask, "__builtin_ia32_pmaxsq256_mask", IX86_BUILTIN_PMAXSQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32600   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4di3_mask, "__builtin_ia32_pminsq256_mask", IX86_BUILTIN_PMINSQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32601   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv4di3_mask, "__builtin_ia32_pmaxuq256_mask", IX86_BUILTIN_PMAXUQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32602   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv4di3_mask, "__builtin_ia32_pminuq256_mask", IX86_BUILTIN_PMINUQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32603   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv2di3_mask, "__builtin_ia32_pmaxsq128_mask", IX86_BUILTIN_PMAXSQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32604   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv2di3_mask, "__builtin_ia32_pminsq128_mask", IX86_BUILTIN_PMINSQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32605   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv2di3_mask, "__builtin_ia32_pmaxuq128_mask", IX86_BUILTIN_PMAXUQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32606   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv2di3_mask, "__builtin_ia32_pminuq128_mask", IX86_BUILTIN_PMINUQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32607   { 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 },
32608   { 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 },
32609   { 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 },
32610   { 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 },
32611   { 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 },
32612   { 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 },
32613   { 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 },
32614   { 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 },
32615   { 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 },
32616   { 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 },
32617   { 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 },
32618   { 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 },
32619   { 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 },
32620   { 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 },
32621   { 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 },
32622   { 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 },
32623   { 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 },
32624   { 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 },
32625   { 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 },
32626   { 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 },
32627   { 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 },
32628   { 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 },
32629   { 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 },
32630   { 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 },
32631   { 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 },
32632   { 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 },
32633   { 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 },
32634   { 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 },
32635   { 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 },
32636   { 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 },
32637   { 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 },
32638   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_unpcklps128_mask,  "__builtin_ia32_unpcklps128_mask", IX86_BUILTIN_UNPCKLPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32639   { 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 },
32640   { 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 },
32641   { 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 },
32642   { 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 },
32643   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtps2ph256_mask,  "__builtin_ia32_vcvtps2ph256_mask", IX86_BUILTIN_CVTPS2PH256_MASK, UNKNOWN, (int) V8HI_FTYPE_V8SF_INT_V8HI_QI },
32644   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtps2ph_mask,  "__builtin_ia32_vcvtps2ph_mask", IX86_BUILTIN_CVTPS2PH_MASK, UNKNOWN, (int) V8HI_FTYPE_V4SF_INT_V8HI_QI },
32645   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtph2ps_mask, "__builtin_ia32_vcvtph2ps_mask", IX86_BUILTIN_CVTPH2PS_MASK, UNKNOWN, (int) V4SF_FTYPE_V8HI_V4SF_QI },
32646   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtph2ps256_mask, "__builtin_ia32_vcvtph2ps256_mask", IX86_BUILTIN_CVTPH2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8HI_V8SF_QI },
32647   { 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 },
32648   { 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 },
32649   { 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 },
32650   { 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 },
32651   { 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 },
32652   { 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 },
32653   { 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 },
32654   { 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 },
32655   { 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 },
32656   { 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 },
32657   { 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 },
32658   { 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 },
32659   { 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 },
32660   { 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 },
32661   { 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 },
32662   { 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 },
32663   { 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 },
32664   { 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 },
32665   { 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 },
32666   { 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 },
32667   { 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 },
32668   { 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 },
32669   { 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 },
32670   { 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 },
32671   { 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 },
32672   { 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 },
32673   { 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 },
32674   { 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 },
32675   { 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 },
32676   { 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 },
32677   { 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 },
32678   { 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 },
32679   { 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 },
32680   { 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 },
32681   { 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 },
32682   { 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 },
32683   { 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 },
32684   { 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 },
32685   { 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 },
32686   { 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 },
32687   { 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 },
32688   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4di, "__builtin_ia32_blendmq_256_mask", IX86_BUILTIN_BLENDMQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32689   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8si, "__builtin_ia32_blendmd_256_mask", IX86_BUILTIN_BLENDMD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32690   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4df, "__builtin_ia32_blendmpd_256_mask", IX86_BUILTIN_BLENDMPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32691   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8sf, "__builtin_ia32_blendmps_256_mask", IX86_BUILTIN_BLENDMPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32692   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv2di, "__builtin_ia32_blendmq_128_mask", IX86_BUILTIN_BLENDMQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32693   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4si, "__builtin_ia32_blendmd_128_mask", IX86_BUILTIN_BLENDMD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32694   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv2df, "__builtin_ia32_blendmpd_128_mask", IX86_BUILTIN_BLENDMPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32695   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4sf, "__builtin_ia32_blendmps_128_mask", IX86_BUILTIN_BLENDMPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32696   { 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 },
32697   { 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 },
32698   { 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 },
32699   { 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 },
32700   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8si3_mask, "__builtin_ia32_pmulld256_mask", IX86_BUILTIN_PMULLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32701   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4si3_mask, "__builtin_ia32_pmulld128_mask", IX86_BUILTIN_PMULLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32702   { 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 },
32703   { 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 },
32704   { 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 },
32705   { 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 },
32706   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtpd2ps256_mask, "__builtin_ia32_cvtpd2ps256_mask", IX86_BUILTIN_CVTPD2PS256_MASK, UNKNOWN, (int) V4SF_FTYPE_V4DF_V4SF_QI },
32707   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtpd2ps_mask, "__builtin_ia32_cvtpd2ps_mask", IX86_BUILTIN_CVTPD2PS_MASK, UNKNOWN, (int) V4SF_FTYPE_V2DF_V4SF_QI },
32708   { 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 },
32709   { 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 },
32710   { 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 },
32711   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4di3_mask, "__builtin_ia32_cmpq256_mask", IX86_BUILTIN_CMPQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_INT_QI },
32712   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv8si3_mask, "__builtin_ia32_cmpd256_mask", IX86_BUILTIN_CMPD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_INT_QI },
32713   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv4di3_mask, "__builtin_ia32_ucmpq256_mask", IX86_BUILTIN_UCMPQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_INT_QI },
32714   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv8si3_mask, "__builtin_ia32_ucmpd256_mask", IX86_BUILTIN_UCMPD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_INT_QI },
32715   { 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 },
32716   { 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 },
32717   { 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 },
32718   { 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 },
32719   { 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 },
32720   { 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 },
32721   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv2di3_mask, "__builtin_ia32_cmpq128_mask", IX86_BUILTIN_CMPQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_INT_QI },
32722   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4si3_mask, "__builtin_ia32_cmpd128_mask", IX86_BUILTIN_CMPD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_INT_QI },
32723   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv2di3_mask, "__builtin_ia32_ucmpq128_mask", IX86_BUILTIN_UCMPQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_INT_QI },
32724   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv4si3_mask, "__builtin_ia32_ucmpd128_mask", IX86_BUILTIN_UCMPD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_INT_QI },
32725   { 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 },
32726   { 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 },
32727   { 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 },
32728   { 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 },
32729   { 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 },
32730   { 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 },
32731
32732   /* AVX512DQ.  */
32733   { 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 },
32734   { 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 },
32735   { 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 },
32736   { 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 },
32737   { 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 },
32738   { 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 },
32739   { 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 },
32740   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextractf32x8_mask, "__builtin_ia32_extractf32x8_mask", IX86_BUILTIN_EXTRACTF32X8, UNKNOWN, (int) V8SF_FTYPE_V16SF_INT_V8SF_QI },
32741   { 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 },
32742   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextracti32x8_mask, "__builtin_ia32_extracti32x8_mask", IX86_BUILTIN_EXTRACTI32X8, UNKNOWN, (int) V8SI_FTYPE_V16SI_INT_V8SI_QI },
32743   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducepv8df_mask, "__builtin_ia32_reducepd512_mask", IX86_BUILTIN_REDUCEPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
32744   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducepv16sf_mask, "__builtin_ia32_reduceps512_mask", IX86_BUILTIN_REDUCEPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI },
32745   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_mulv8di3_mask, "__builtin_ia32_pmullq512_mask", IX86_BUILTIN_PMULLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32746   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_xorv8df3_mask, "__builtin_ia32_xorpd512_mask", IX86_BUILTIN_XORPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32747   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_xorv16sf3_mask, "__builtin_ia32_xorps512_mask", IX86_BUILTIN_XORPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32748   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_iorv8df3_mask, "__builtin_ia32_orpd512_mask", IX86_BUILTIN_ORPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32749   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_iorv16sf3_mask, "__builtin_ia32_orps512_mask", IX86_BUILTIN_ORPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32750   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_andv8df3_mask, "__builtin_ia32_andpd512_mask", IX86_BUILTIN_ANDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32751   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_andv16sf3_mask, "__builtin_ia32_andps512_mask", IX86_BUILTIN_ANDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32752   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_andnotv8df3_mask, "__builtin_ia32_andnpd512_mask", IX86_BUILTIN_ANDNPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI},
32753   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_andnotv16sf3_mask, "__builtin_ia32_andnps512_mask", IX86_BUILTIN_ANDNPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32754   { 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 },
32755   { 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 },
32756   { 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 },
32757   { 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 },
32758   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_fpclassv8df_mask, "__builtin_ia32_fpclasspd512_mask", IX86_BUILTIN_FPCLASSPD512, UNKNOWN, (int) QI_FTYPE_V8DF_INT_QI },
32759   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_fpclassv16sf_mask, "__builtin_ia32_fpclassps512_mask", IX86_BUILTIN_FPCLASSPS512, UNKNOWN, (int) HI_FTYPE_V16SF_INT_HI },
32760   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtd2maskv16si, "__builtin_ia32_cvtd2mask512", IX86_BUILTIN_CVTD2MASK512, UNKNOWN, (int) HI_FTYPE_V16SI },
32761   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtq2maskv8di, "__builtin_ia32_cvtq2mask512", IX86_BUILTIN_CVTQ2MASK512, UNKNOWN, (int) QI_FTYPE_V8DI },
32762   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtmask2dv16si, "__builtin_ia32_cvtmask2d512", IX86_BUILTIN_CVTMASK2D512, UNKNOWN, (int) V16SI_FTYPE_HI },
32763   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtmask2qv8di, "__builtin_ia32_cvtmask2q512", IX86_BUILTIN_CVTMASK2Q512, UNKNOWN, (int) V8DI_FTYPE_QI },
32764
32765   /* AVX512BW.  */
32766   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_kunpcksi, "__builtin_ia32_kunpcksi", IX86_BUILTIN_KUNPCKWD, UNKNOWN, (int) SI_FTYPE_SI_SI },
32767   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_kunpckdi, "__builtin_ia32_kunpckdi", IX86_BUILTIN_KUNPCKDQ, UNKNOWN, (int) DI_FTYPE_DI_DI },
32768   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packusdw_mask, "__builtin_ia32_packusdw512_mask",  IX86_BUILTIN_PACKUSDW512, UNKNOWN, (int) V32HI_FTYPE_V16SI_V16SI_V32HI_SI },
32769   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashlv4ti3, "__builtin_ia32_pslldq512", IX86_BUILTIN_PSLLDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_CONVERT },
32770   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_lshrv4ti3, "__builtin_ia32_psrldq512", IX86_BUILTIN_PSRLDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_CONVERT },
32771   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packssdw_mask, "__builtin_ia32_packssdw512_mask",  IX86_BUILTIN_PACKSSDW512, UNKNOWN, (int) V32HI_FTYPE_V16SI_V16SI_V32HI_SI },
32772   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_palignrv4ti, "__builtin_ia32_palignr512", IX86_BUILTIN_PALIGNR512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_INT_CONVERT },
32773   { 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 },
32774   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_loaddquv32hi_mask, "__builtin_ia32_movdquhi512_mask", IX86_BUILTIN_MOVDQUHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32775   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_loaddquv64qi_mask, "__builtin_ia32_movdquqi512_mask", IX86_BUILTIN_MOVDQUQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32776   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_psadbw, "__builtin_ia32_psadbw512", IX86_BUILTIN_PSADBW512, UNKNOWN, (int) V8DI_FTYPE_V64QI_V64QI },
32777   { 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 },
32778   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dupv64qi_mask, "__builtin_ia32_pbroadcastb512_mask", IX86_BUILTIN_PBROADCASTB512, UNKNOWN, (int) V64QI_FTYPE_V16QI_V64QI_DI },
32779   { 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 },
32780   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dupv32hi_mask, "__builtin_ia32_pbroadcastw512_mask", IX86_BUILTIN_PBROADCASTW512, UNKNOWN, (int) V32HI_FTYPE_V8HI_V32HI_SI },
32781   { 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 },
32782   { 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 },
32783   { 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 },
32784   { 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 },
32785   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermt2varv32hi3_mask, "__builtin_ia32_vpermt2varhi512_mask", IX86_BUILTIN_VPERMT2VARHI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32786   { 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 },
32787   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermi2varv32hi3_mask, "__builtin_ia32_vpermi2varhi512_mask", IX86_BUILTIN_VPERMI2VARHI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32788   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_uavgv64qi3_mask, "__builtin_ia32_pavgb512_mask", IX86_BUILTIN_PAVGB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32789   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_uavgv32hi3_mask, "__builtin_ia32_pavgw512_mask", IX86_BUILTIN_PAVGW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32790   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_addv64qi3_mask, "__builtin_ia32_paddb512_mask", IX86_BUILTIN_PADDB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32791   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_subv64qi3_mask, "__builtin_ia32_psubb512_mask", IX86_BUILTIN_PSUBB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32792   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sssubv64qi3_mask, "__builtin_ia32_psubsb512_mask", IX86_BUILTIN_PSUBSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32793   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ssaddv64qi3_mask, "__builtin_ia32_paddsb512_mask", IX86_BUILTIN_PADDSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32794   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ussubv64qi3_mask, "__builtin_ia32_psubusb512_mask", IX86_BUILTIN_PSUBUSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32795   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_usaddv64qi3_mask, "__builtin_ia32_paddusb512_mask", IX86_BUILTIN_PADDUSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32796   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_subv32hi3_mask, "__builtin_ia32_psubw512_mask", IX86_BUILTIN_PSUBW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32797   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_addv32hi3_mask, "__builtin_ia32_paddw512_mask", IX86_BUILTIN_PADDW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32798   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sssubv32hi3_mask, "__builtin_ia32_psubsw512_mask", IX86_BUILTIN_PSUBSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32799   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ssaddv32hi3_mask, "__builtin_ia32_paddsw512_mask", IX86_BUILTIN_PADDSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32800   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ussubv32hi3_mask, "__builtin_ia32_psubusw512_mask", IX86_BUILTIN_PSUBUSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32801   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_usaddv32hi3_mask, "__builtin_ia32_paddusw512_mask", IX86_BUILTIN_PADDUSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32802   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umaxv32hi3_mask, "__builtin_ia32_pmaxuw512_mask", IX86_BUILTIN_PMAXUW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32803   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smaxv32hi3_mask, "__builtin_ia32_pmaxsw512_mask", IX86_BUILTIN_PMAXSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32804   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_uminv32hi3_mask, "__builtin_ia32_pminuw512_mask", IX86_BUILTIN_PMINUW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32805   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_sminv32hi3_mask, "__builtin_ia32_pminsw512_mask", IX86_BUILTIN_PMINSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32806   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umaxv64qi3_mask, "__builtin_ia32_pmaxub512_mask", IX86_BUILTIN_PMAXUB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32807   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smaxv64qi3_mask, "__builtin_ia32_pmaxsb512_mask", IX86_BUILTIN_PMAXSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32808   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_uminv64qi3_mask, "__builtin_ia32_pminub512_mask", IX86_BUILTIN_PMINUB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32809   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_sminv64qi3_mask, "__builtin_ia32_pminsb512_mask", IX86_BUILTIN_PMINSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32810   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovwb512_mask", IX86_BUILTIN_PMOVWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32811   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ss_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovswb512_mask", IX86_BUILTIN_PMOVSWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32812   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_us_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovuswb512_mask", IX86_BUILTIN_PMOVUSWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32813   { 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 },
32814   { 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 },
32815   { 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 },
32816   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_mulv32hi3_mask, "__builtin_ia32_pmullw512_mask", IX86_BUILTIN_PMULLW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32817   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashlv32hi3_mask, "__builtin_ia32_psllwi512_mask", IX86_BUILTIN_PSLLWI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32818   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashlv32hi3_mask, "__builtin_ia32_psllw512_mask", IX86_BUILTIN_PSLLW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32819   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packsswb_mask, "__builtin_ia32_packsswb512_mask",  IX86_BUILTIN_PACKSSWB512, UNKNOWN, (int) V64QI_FTYPE_V32HI_V32HI_V64QI_DI },
32820   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packuswb_mask, "__builtin_ia32_packuswb512_mask",  IX86_BUILTIN_PACKUSWB512, UNKNOWN, (int) V64QI_FTYPE_V32HI_V32HI_V64QI_DI },
32821   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashrvv32hi_mask, "__builtin_ia32_psrav32hi_mask", IX86_BUILTIN_PSRAVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32822   { 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 },
32823   { 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 },
32824   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_lshrvv32hi_mask, "__builtin_ia32_psrlv32hi_mask", IX86_BUILTIN_PSRLVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32825   { 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 },
32826   { 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 },
32827   { 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 },
32828   { 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 },
32829   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshufbv64qi3_mask, "__builtin_ia32_pshufb512_mask", IX86_BUILTIN_PSHUFB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32830   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshufhwv32hi_mask, "__builtin_ia32_pshufhw512_mask", IX86_BUILTIN_PSHUFHW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32831   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshuflwv32hi_mask, "__builtin_ia32_pshuflw512_mask", IX86_BUILTIN_PSHUFLW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32832   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashrv32hi3_mask, "__builtin_ia32_psrawi512_mask", IX86_BUILTIN_PSRAWI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32833   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashrv32hi3_mask, "__builtin_ia32_psraw512_mask", IX86_BUILTIN_PSRAW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32834   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_lshrv32hi3_mask, "__builtin_ia32_psrlwi512_mask", IX86_BUILTIN_PSRLWI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32835   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_lshrv32hi3_mask, "__builtin_ia32_psrlw512_mask", IX86_BUILTIN_PSRLW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32836   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtb2maskv64qi, "__builtin_ia32_cvtb2mask512", IX86_BUILTIN_CVTB2MASK512, UNKNOWN, (int) DI_FTYPE_V64QI },
32837   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtw2maskv32hi, "__builtin_ia32_cvtw2mask512", IX86_BUILTIN_CVTW2MASK512, UNKNOWN, (int) SI_FTYPE_V32HI },
32838   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtmask2bv64qi, "__builtin_ia32_cvtmask2b512", IX86_BUILTIN_CVTMASK2B512, UNKNOWN, (int) V64QI_FTYPE_DI },
32839   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtmask2wv32hi, "__builtin_ia32_cvtmask2w512", IX86_BUILTIN_CVTMASK2W512, UNKNOWN, (int) V32HI_FTYPE_SI },
32840   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_eqv64qi3_mask, "__builtin_ia32_pcmpeqb512_mask", IX86_BUILTIN_PCMPEQB512_MASK, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32841   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_eqv32hi3_mask, "__builtin_ia32_pcmpeqw512_mask", IX86_BUILTIN_PCMPEQW512_MASK, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32842   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_gtv64qi3_mask, "__builtin_ia32_pcmpgtb512_mask", IX86_BUILTIN_PCMPGTB512_MASK, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32843   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_gtv32hi3_mask, "__builtin_ia32_pcmpgtw512_mask", IX86_BUILTIN_PCMPGTW512_MASK, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32844   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testmv64qi3_mask, "__builtin_ia32_ptestmb512", IX86_BUILTIN_PTESTMB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32845   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testmv32hi3_mask, "__builtin_ia32_ptestmw512", IX86_BUILTIN_PTESTMW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32846   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testnmv64qi3_mask, "__builtin_ia32_ptestnmb512", IX86_BUILTIN_PTESTNMB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32847   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testnmv32hi3_mask, "__builtin_ia32_ptestnmw512", IX86_BUILTIN_PTESTNMW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32848   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashlvv32hi_mask, "__builtin_ia32_psllv32hi_mask", IX86_BUILTIN_PSLLVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32849   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_absv64qi2_mask, "__builtin_ia32_pabsb512_mask", IX86_BUILTIN_PABSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32850   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_absv32hi2_mask, "__builtin_ia32_pabsw512_mask", IX86_BUILTIN_PABSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32851   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_blendmv32hi, "__builtin_ia32_blendmw_512_mask", IX86_BUILTIN_BLENDMW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32852   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_blendmv64qi, "__builtin_ia32_blendmb_512_mask", IX86_BUILTIN_BLENDMB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32853   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cmpv64qi3_mask, "__builtin_ia32_cmpb512_mask", IX86_BUILTIN_CMPB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_INT_DI },
32854   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cmpv32hi3_mask, "__builtin_ia32_cmpw512_mask", IX86_BUILTIN_CMPW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_INT_SI },
32855   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ucmpv64qi3_mask, "__builtin_ia32_ucmpb512_mask", IX86_BUILTIN_UCMPB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_INT_DI },
32856   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ucmpv32hi3_mask, "__builtin_ia32_ucmpw512_mask", IX86_BUILTIN_UCMPW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_INT_SI },
32857
32858   /* AVX512IFMA */
32859   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52luqv8di_mask, "__builtin_ia32_vpmadd52luq512_mask", IX86_BUILTIN_VPMADD52LUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32860   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52luqv8di_maskz, "__builtin_ia32_vpmadd52luq512_maskz", IX86_BUILTIN_VPMADD52LUQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32861   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52huqv8di_mask, "__builtin_ia32_vpmadd52huq512_mask", IX86_BUILTIN_VPMADD52HUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32862   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52huqv8di_maskz, "__builtin_ia32_vpmadd52huq512_maskz", IX86_BUILTIN_VPMADD52HUQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32863   { 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 },
32864   { 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 },
32865   { 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 },
32866   { 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 },
32867   { 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 },
32868   { 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 },
32869   { 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 },
32870   { 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 },
32871
32872   /* AVX512VBMI */
32873   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_vpmultishiftqbv64qi_mask, "__builtin_ia32_vpmultishiftqb512_mask", IX86_BUILTIN_VPMULTISHIFTQB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32874   { 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 },
32875   { 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 },
32876   { 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 },
32877   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermt2varv64qi3_mask, "__builtin_ia32_vpermt2varqi512_mask", IX86_BUILTIN_VPERMT2VARQI512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32878   { 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 },
32879   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermi2varv64qi3_mask, "__builtin_ia32_vpermi2varqi512_mask", IX86_BUILTIN_VPERMI2VARQI512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32880   { 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 },
32881   { 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 },
32882   { 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 },
32883   { 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 },
32884   { 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 },
32885   { 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 },
32886   { 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 },
32887   { 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 },
32888 };
32889
32890 /* Builtins with rounding support.  */
32891 static const struct builtin_description bdesc_round_args[] =
32892 {
32893   /* AVX512F */
32894   { 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 },
32895   { 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 },
32896   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmaddv2df3_round, "__builtin_ia32_addsd_round", IX86_BUILTIN_ADDSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32897   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmaddv4sf3_round, "__builtin_ia32_addss_round", IX86_BUILTIN_ADDSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32898   { 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 },
32899   { 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 },
32900   { 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 },
32901   { 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 },
32902   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_comi_round, "__builtin_ia32_vcomisd", IX86_BUILTIN_COMIDF, UNKNOWN, (int) INT_FTYPE_V2DF_V2DF_INT_INT },
32903   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_comi_round, "__builtin_ia32_vcomiss", IX86_BUILTIN_COMISF, UNKNOWN, (int) INT_FTYPE_V4SF_V4SF_INT_INT },
32904   { OPTION_MASK_ISA_AVX512F, CODE_FOR_floatv16siv16sf2_mask_round, "__builtin_ia32_cvtdq2ps512_mask", IX86_BUILTIN_CVTDQ2PS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_HI_INT },
32905   { 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 },
32906   { 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 },
32907   { 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 },
32908   { 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 },
32909   { 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 },
32910   { 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 },
32911   { 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 },
32912   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtsd2ss_round, "__builtin_ia32_cvtsd2ss_round", IX86_BUILTIN_CVTSD2SS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF_INT },
32913   { 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 },
32914   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvtsi2ss_round, "__builtin_ia32_cvtsi2ss32", IX86_BUILTIN_CVTSI2SS32, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_INT },
32915   { 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 },
32916   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtss2sd_round, "__builtin_ia32_cvtss2sd_round", IX86_BUILTIN_CVTSS2SD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF_INT },
32917   { 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 },
32918   { 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 },
32919   { 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 },
32920   { 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 },
32921   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufloatv16siv16sf2_mask_round, "__builtin_ia32_cvtudq2ps512_mask", IX86_BUILTIN_CVTUDQ2PS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_HI_INT },
32922   { 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 },
32923   { OPTION_MASK_ISA_AVX512F, CODE_FOR_cvtusi2ss32_round, "__builtin_ia32_cvtusi2ss32", IX86_BUILTIN_CVTUSI2SS32, UNKNOWN, (int) V4SF_FTYPE_V4SF_UINT_INT },
32924   { 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 },
32925   { 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 },
32926   { 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 },
32927   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmdivv2df3_round, "__builtin_ia32_divsd_round", IX86_BUILTIN_DIVSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32928   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmdivv4sf3_round, "__builtin_ia32_divss_round", IX86_BUILTIN_DIVSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32929   { 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 },
32930   { 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 },
32931   { 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 },
32932   { 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 },
32933   { 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 },
32934   { 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 },
32935   { 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 },
32936   { 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 },
32937   { 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 },
32938   { 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 },
32939   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sgetexpv2df_round, "__builtin_ia32_getexpsd128_round", IX86_BUILTIN_GETEXPSD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32940   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sgetexpv4sf_round, "__builtin_ia32_getexpss128_round", IX86_BUILTIN_GETEXPSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32941   { 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 },
32942   { 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 },
32943   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vgetmantv2df_round, "__builtin_ia32_getmantsd_round", IX86_BUILTIN_GETMANTSD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
32944   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vgetmantv4sf_round, "__builtin_ia32_getmantss_round", IX86_BUILTIN_GETMANTSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
32945   { 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 },
32946   { 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 },
32947   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsmaxv2df3_round, "__builtin_ia32_maxsd_round", IX86_BUILTIN_MAXSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32948   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsmaxv4sf3_round, "__builtin_ia32_maxss_round", IX86_BUILTIN_MAXSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32949   { 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 },
32950   { 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 },
32951   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsminv2df3_round, "__builtin_ia32_minsd_round", IX86_BUILTIN_MINSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32952   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsminv4sf3_round, "__builtin_ia32_minss_round", IX86_BUILTIN_MINSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32953   { 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 },
32954   { 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 },
32955   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmmulv2df3_round, "__builtin_ia32_mulsd_round", IX86_BUILTIN_MULSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32956   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmmulv4sf3_round, "__builtin_ia32_mulss_round", IX86_BUILTIN_MULSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32957   { 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 },
32958   { 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 },
32959   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev2df_round, "__builtin_ia32_rndscalesd_round", IX86_BUILTIN_RNDSCALESD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
32960   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev4sf_round, "__builtin_ia32_rndscaless_round", IX86_BUILTIN_RNDSCALESS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
32961   { 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 },
32962   { 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 },
32963   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmscalefv2df_round, "__builtin_ia32_scalefsd_round", IX86_BUILTIN_SCALEFSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32964   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmscalefv4sf_round, "__builtin_ia32_scalefss_round", IX86_BUILTIN_SCALEFSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32965   { 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 },
32966   { 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 },
32967   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsqrtv2df2_round, "__builtin_ia32_sqrtsd_round", IX86_BUILTIN_SQRTSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32968   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsqrtv4sf2_round, "__builtin_ia32_sqrtss_round", IX86_BUILTIN_SQRTSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32969   { 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 },
32970   { 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 },
32971   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsubv2df3_round, "__builtin_ia32_subsd_round", IX86_BUILTIN_SUBSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32972   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsubv4sf3_round, "__builtin_ia32_subss_round", IX86_BUILTIN_SUBSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32973   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtsd2si_round, "__builtin_ia32_vcvtsd2si32", IX86_BUILTIN_VCVTSD2SI32, UNKNOWN, (int) INT_FTYPE_V2DF_INT },
32974   { 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 },
32975   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtsd2usi_round, "__builtin_ia32_vcvtsd2usi32", IX86_BUILTIN_VCVTSD2USI32, UNKNOWN, (int) UINT_FTYPE_V2DF_INT },
32976   { 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 },
32977   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvtss2si_round, "__builtin_ia32_vcvtss2si32", IX86_BUILTIN_VCVTSS2SI32, UNKNOWN, (int) INT_FTYPE_V4SF_INT },
32978   { 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 },
32979   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtss2usi_round, "__builtin_ia32_vcvtss2usi32", IX86_BUILTIN_VCVTSS2USI32, UNKNOWN, (int) UINT_FTYPE_V4SF_INT },
32980   { 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 },
32981   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvttsd2si_round, "__builtin_ia32_vcvttsd2si32", IX86_BUILTIN_VCVTTSD2SI32, UNKNOWN, (int) INT_FTYPE_V2DF_INT },
32982   { 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 },
32983   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvttsd2usi_round, "__builtin_ia32_vcvttsd2usi32", IX86_BUILTIN_VCVTTSD2USI32, UNKNOWN, (int) UINT_FTYPE_V2DF_INT },
32984   { 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 },
32985   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvttss2si_round, "__builtin_ia32_vcvttss2si32", IX86_BUILTIN_VCVTTSS2SI32, UNKNOWN, (int) INT_FTYPE_V4SF_INT },
32986   { 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 },
32987   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvttss2usi_round, "__builtin_ia32_vcvttss2usi32", IX86_BUILTIN_VCVTTSS2USI32, UNKNOWN, (int) UINT_FTYPE_V4SF_INT },
32988   { 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 },
32989   { 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 },
32990   { 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 },
32991   { 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 },
32992   { 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 },
32993   { 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 },
32994   { 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 },
32995   { 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 },
32996   { 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 },
32997   { 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 },
32998   { 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 },
32999   { 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 },
33000   { 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 },
33001   { 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 },
33002   { 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 },
33003   { 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 },
33004   { 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 },
33005   { 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 },
33006   { 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 },
33007   { 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 },
33008   { 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 },
33009   { 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 },
33010   { 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 },
33011   { 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 },
33012   { 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 },
33013
33014   /* AVX512ER */
33015   { 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 },
33016   { 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 },
33017   { 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 },
33018   { 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 },
33019   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrcp28v2df_round, "__builtin_ia32_rcp28sd_round", IX86_BUILTIN_RCP28SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33020   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrcp28v4sf_round, "__builtin_ia32_rcp28ss_round", IX86_BUILTIN_RCP28SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33021   { 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 },
33022   { 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 },
33023   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrsqrt28v2df_round, "__builtin_ia32_rsqrt28sd_round", IX86_BUILTIN_RSQRT28SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33024   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrsqrt28v4sf_round, "__builtin_ia32_rsqrt28ss_round", IX86_BUILTIN_RSQRT28SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33025
33026   /* AVX512DQ.  */
33027   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangesv2df_round, "__builtin_ia32_rangesd128_round", IX86_BUILTIN_RANGESD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
33028   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangesv4sf_round, "__builtin_ia32_rangess128_round", IX86_BUILTIN_RANGESS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
33029   { 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 },
33030   { 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 },
33031   { 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 },
33032   { 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 },
33033   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_floatv8div8sf2_mask_round, "__builtin_ia32_cvtqq2ps512_mask", IX86_BUILTIN_CVTQQ2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DI_V8SF_QI_INT },
33034   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufloatv8div8sf2_mask_round, "__builtin_ia32_cvtuqq2ps512_mask", IX86_BUILTIN_CVTUQQ2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DI_V8SF_QI_INT },
33035   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_floatv8div8df2_mask_round, "__builtin_ia32_cvtqq2pd512_mask", IX86_BUILTIN_CVTQQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_QI_INT },
33036   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufloatv8div8df2_mask_round, "__builtin_ia32_cvtuqq2pd512_mask", IX86_BUILTIN_CVTUQQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_QI_INT },
33037   { 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 },
33038   { 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 },
33039   { 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 },
33040   { 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 },
33041   { 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 },
33042   { 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 },
33043 };
33044
33045 /* Bultins for MPX.  */
33046 static const struct builtin_description bdesc_mpx[] =
33047 {
33048   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndstx", IX86_BUILTIN_BNDSTX, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND_PCVOID },
33049   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndcl", IX86_BUILTIN_BNDCL, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND },
33050   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndcu", IX86_BUILTIN_BNDCU, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND },
33051 };
33052
33053 /* Const builtins for MPX.  */
33054 static const struct builtin_description bdesc_mpx_const[] =
33055 {
33056   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndmk", IX86_BUILTIN_BNDMK, UNKNOWN, (int) BND_FTYPE_PCVOID_ULONG },
33057   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndldx", IX86_BUILTIN_BNDLDX, UNKNOWN, (int) BND_FTYPE_PCVOID_PCVOID },
33058   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_narrow_bounds", IX86_BUILTIN_BNDNARROW, UNKNOWN, (int) PVOID_FTYPE_PCVOID_BND_ULONG },
33059   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndint", IX86_BUILTIN_BNDINT, UNKNOWN, (int) BND_FTYPE_BND_BND },
33060   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_sizeof", IX86_BUILTIN_SIZEOF, UNKNOWN, (int) ULONG_FTYPE_VOID },
33061   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndlower", IX86_BUILTIN_BNDLOWER, UNKNOWN, (int) PVOID_FTYPE_BND },
33062   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndupper", IX86_BUILTIN_BNDUPPER, UNKNOWN, (int) PVOID_FTYPE_BND },
33063   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndret", IX86_BUILTIN_BNDRET, UNKNOWN, (int) BND_FTYPE_PCVOID },
33064 };
33065
33066 /* FMA4 and XOP.  */
33067 #define MULTI_ARG_4_DF2_DI_I    V2DF_FTYPE_V2DF_V2DF_V2DI_INT
33068 #define MULTI_ARG_4_DF2_DI_I1   V4DF_FTYPE_V4DF_V4DF_V4DI_INT
33069 #define MULTI_ARG_4_SF2_SI_I    V4SF_FTYPE_V4SF_V4SF_V4SI_INT
33070 #define MULTI_ARG_4_SF2_SI_I1   V8SF_FTYPE_V8SF_V8SF_V8SI_INT
33071 #define MULTI_ARG_3_SF          V4SF_FTYPE_V4SF_V4SF_V4SF
33072 #define MULTI_ARG_3_DF          V2DF_FTYPE_V2DF_V2DF_V2DF
33073 #define MULTI_ARG_3_SF2         V8SF_FTYPE_V8SF_V8SF_V8SF
33074 #define MULTI_ARG_3_DF2         V4DF_FTYPE_V4DF_V4DF_V4DF
33075 #define MULTI_ARG_3_DI          V2DI_FTYPE_V2DI_V2DI_V2DI
33076 #define MULTI_ARG_3_SI          V4SI_FTYPE_V4SI_V4SI_V4SI
33077 #define MULTI_ARG_3_SI_DI       V4SI_FTYPE_V4SI_V4SI_V2DI
33078 #define MULTI_ARG_3_HI          V8HI_FTYPE_V8HI_V8HI_V8HI
33079 #define MULTI_ARG_3_HI_SI       V8HI_FTYPE_V8HI_V8HI_V4SI
33080 #define MULTI_ARG_3_QI          V16QI_FTYPE_V16QI_V16QI_V16QI
33081 #define MULTI_ARG_3_DI2         V4DI_FTYPE_V4DI_V4DI_V4DI
33082 #define MULTI_ARG_3_SI2         V8SI_FTYPE_V8SI_V8SI_V8SI
33083 #define MULTI_ARG_3_HI2         V16HI_FTYPE_V16HI_V16HI_V16HI
33084 #define MULTI_ARG_3_QI2         V32QI_FTYPE_V32QI_V32QI_V32QI
33085 #define MULTI_ARG_2_SF          V4SF_FTYPE_V4SF_V4SF
33086 #define MULTI_ARG_2_DF          V2DF_FTYPE_V2DF_V2DF
33087 #define MULTI_ARG_2_DI          V2DI_FTYPE_V2DI_V2DI
33088 #define MULTI_ARG_2_SI          V4SI_FTYPE_V4SI_V4SI
33089 #define MULTI_ARG_2_HI          V8HI_FTYPE_V8HI_V8HI
33090 #define MULTI_ARG_2_QI          V16QI_FTYPE_V16QI_V16QI
33091 #define MULTI_ARG_2_DI_IMM      V2DI_FTYPE_V2DI_SI
33092 #define MULTI_ARG_2_SI_IMM      V4SI_FTYPE_V4SI_SI
33093 #define MULTI_ARG_2_HI_IMM      V8HI_FTYPE_V8HI_SI
33094 #define MULTI_ARG_2_QI_IMM      V16QI_FTYPE_V16QI_SI
33095 #define MULTI_ARG_2_DI_CMP      V2DI_FTYPE_V2DI_V2DI_CMP
33096 #define MULTI_ARG_2_SI_CMP      V4SI_FTYPE_V4SI_V4SI_CMP
33097 #define MULTI_ARG_2_HI_CMP      V8HI_FTYPE_V8HI_V8HI_CMP
33098 #define MULTI_ARG_2_QI_CMP      V16QI_FTYPE_V16QI_V16QI_CMP
33099 #define MULTI_ARG_2_SF_TF       V4SF_FTYPE_V4SF_V4SF_TF
33100 #define MULTI_ARG_2_DF_TF       V2DF_FTYPE_V2DF_V2DF_TF
33101 #define MULTI_ARG_2_DI_TF       V2DI_FTYPE_V2DI_V2DI_TF
33102 #define MULTI_ARG_2_SI_TF       V4SI_FTYPE_V4SI_V4SI_TF
33103 #define MULTI_ARG_2_HI_TF       V8HI_FTYPE_V8HI_V8HI_TF
33104 #define MULTI_ARG_2_QI_TF       V16QI_FTYPE_V16QI_V16QI_TF
33105 #define MULTI_ARG_1_SF          V4SF_FTYPE_V4SF
33106 #define MULTI_ARG_1_DF          V2DF_FTYPE_V2DF
33107 #define MULTI_ARG_1_SF2         V8SF_FTYPE_V8SF
33108 #define MULTI_ARG_1_DF2         V4DF_FTYPE_V4DF
33109 #define MULTI_ARG_1_DI          V2DI_FTYPE_V2DI
33110 #define MULTI_ARG_1_SI          V4SI_FTYPE_V4SI
33111 #define MULTI_ARG_1_HI          V8HI_FTYPE_V8HI
33112 #define MULTI_ARG_1_QI          V16QI_FTYPE_V16QI
33113 #define MULTI_ARG_1_SI_DI       V2DI_FTYPE_V4SI
33114 #define MULTI_ARG_1_HI_DI       V2DI_FTYPE_V8HI
33115 #define MULTI_ARG_1_HI_SI       V4SI_FTYPE_V8HI
33116 #define MULTI_ARG_1_QI_DI       V2DI_FTYPE_V16QI
33117 #define MULTI_ARG_1_QI_SI       V4SI_FTYPE_V16QI
33118 #define MULTI_ARG_1_QI_HI       V8HI_FTYPE_V16QI
33119
33120 static const struct builtin_description bdesc_multi_arg[] =
33121 {
33122   { OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_vmfmadd_v4sf,
33123     "__builtin_ia32_vfmaddss", IX86_BUILTIN_VFMADDSS,
33124     UNKNOWN, (int)MULTI_ARG_3_SF },
33125   { OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_vmfmadd_v2df,
33126     "__builtin_ia32_vfmaddsd", IX86_BUILTIN_VFMADDSD,
33127     UNKNOWN, (int)MULTI_ARG_3_DF },
33128
33129   { OPTION_MASK_ISA_FMA, CODE_FOR_fmai_vmfmadd_v4sf,
33130     "__builtin_ia32_vfmaddss3", IX86_BUILTIN_VFMADDSS3,
33131     UNKNOWN, (int)MULTI_ARG_3_SF },
33132   { OPTION_MASK_ISA_FMA, CODE_FOR_fmai_vmfmadd_v2df,
33133     "__builtin_ia32_vfmaddsd3", IX86_BUILTIN_VFMADDSD3,
33134     UNKNOWN, (int)MULTI_ARG_3_DF },
33135
33136   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v4sf,
33137     "__builtin_ia32_vfmaddps", IX86_BUILTIN_VFMADDPS,
33138     UNKNOWN, (int)MULTI_ARG_3_SF },
33139   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v2df,
33140     "__builtin_ia32_vfmaddpd", IX86_BUILTIN_VFMADDPD,
33141     UNKNOWN, (int)MULTI_ARG_3_DF },
33142   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v8sf,
33143     "__builtin_ia32_vfmaddps256", IX86_BUILTIN_VFMADDPS256,
33144     UNKNOWN, (int)MULTI_ARG_3_SF2 },
33145   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v4df,
33146     "__builtin_ia32_vfmaddpd256", IX86_BUILTIN_VFMADDPD256,
33147     UNKNOWN, (int)MULTI_ARG_3_DF2 },
33148
33149   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v4sf,
33150     "__builtin_ia32_vfmaddsubps", IX86_BUILTIN_VFMADDSUBPS,
33151     UNKNOWN, (int)MULTI_ARG_3_SF },
33152   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v2df,
33153     "__builtin_ia32_vfmaddsubpd", IX86_BUILTIN_VFMADDSUBPD,
33154     UNKNOWN, (int)MULTI_ARG_3_DF },
33155   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v8sf,
33156     "__builtin_ia32_vfmaddsubps256", IX86_BUILTIN_VFMADDSUBPS256,
33157     UNKNOWN, (int)MULTI_ARG_3_SF2 },
33158   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v4df,
33159     "__builtin_ia32_vfmaddsubpd256", IX86_BUILTIN_VFMADDSUBPD256,
33160     UNKNOWN, (int)MULTI_ARG_3_DF2 },
33161
33162   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2di,        "__builtin_ia32_vpcmov",      IX86_BUILTIN_VPCMOV,      UNKNOWN,      (int)MULTI_ARG_3_DI },
33163   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2di,        "__builtin_ia32_vpcmov_v2di", IX86_BUILTIN_VPCMOV_V2DI, UNKNOWN,      (int)MULTI_ARG_3_DI },
33164   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4si,        "__builtin_ia32_vpcmov_v4si", IX86_BUILTIN_VPCMOV_V4SI, UNKNOWN,      (int)MULTI_ARG_3_SI },
33165   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8hi,        "__builtin_ia32_vpcmov_v8hi", IX86_BUILTIN_VPCMOV_V8HI, UNKNOWN,      (int)MULTI_ARG_3_HI },
33166   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v16qi,       "__builtin_ia32_vpcmov_v16qi",IX86_BUILTIN_VPCMOV_V16QI,UNKNOWN,      (int)MULTI_ARG_3_QI },
33167   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2df,        "__builtin_ia32_vpcmov_v2df", IX86_BUILTIN_VPCMOV_V2DF, UNKNOWN,      (int)MULTI_ARG_3_DF },
33168   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4sf,        "__builtin_ia32_vpcmov_v4sf", IX86_BUILTIN_VPCMOV_V4SF, UNKNOWN,      (int)MULTI_ARG_3_SF },
33169
33170   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4di256,        "__builtin_ia32_vpcmov256",       IX86_BUILTIN_VPCMOV256,       UNKNOWN,      (int)MULTI_ARG_3_DI2 },
33171   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4di256,        "__builtin_ia32_vpcmov_v4di256",  IX86_BUILTIN_VPCMOV_V4DI256,  UNKNOWN,      (int)MULTI_ARG_3_DI2 },
33172   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8si256,        "__builtin_ia32_vpcmov_v8si256",  IX86_BUILTIN_VPCMOV_V8SI256,  UNKNOWN,      (int)MULTI_ARG_3_SI2 },
33173   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v16hi256,       "__builtin_ia32_vpcmov_v16hi256", IX86_BUILTIN_VPCMOV_V16HI256, UNKNOWN,      (int)MULTI_ARG_3_HI2 },
33174   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v32qi256,       "__builtin_ia32_vpcmov_v32qi256", IX86_BUILTIN_VPCMOV_V32QI256, UNKNOWN,      (int)MULTI_ARG_3_QI2 },
33175   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4df256,        "__builtin_ia32_vpcmov_v4df256",  IX86_BUILTIN_VPCMOV_V4DF256,  UNKNOWN,      (int)MULTI_ARG_3_DF2 },
33176   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8sf256,        "__builtin_ia32_vpcmov_v8sf256",  IX86_BUILTIN_VPCMOV_V8SF256,  UNKNOWN,      (int)MULTI_ARG_3_SF2 },
33177
33178   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pperm,             "__builtin_ia32_vpperm",      IX86_BUILTIN_VPPERM,      UNKNOWN,      (int)MULTI_ARG_3_QI },
33179
33180   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssww,          "__builtin_ia32_vpmacssww",   IX86_BUILTIN_VPMACSSWW,   UNKNOWN,      (int)MULTI_ARG_3_HI },
33181   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsww,           "__builtin_ia32_vpmacsww",    IX86_BUILTIN_VPMACSWW,    UNKNOWN,      (int)MULTI_ARG_3_HI },
33182   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsswd,          "__builtin_ia32_vpmacsswd",   IX86_BUILTIN_VPMACSSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33183   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacswd,           "__builtin_ia32_vpmacswd",    IX86_BUILTIN_VPMACSWD,    UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33184   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdd,          "__builtin_ia32_vpmacssdd",   IX86_BUILTIN_VPMACSSDD,   UNKNOWN,      (int)MULTI_ARG_3_SI },
33185   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdd,           "__builtin_ia32_vpmacsdd",    IX86_BUILTIN_VPMACSDD,    UNKNOWN,      (int)MULTI_ARG_3_SI },
33186   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdql,         "__builtin_ia32_vpmacssdql",  IX86_BUILTIN_VPMACSSDQL,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33187   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdqh,         "__builtin_ia32_vpmacssdqh",  IX86_BUILTIN_VPMACSSDQH,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33188   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdql,          "__builtin_ia32_vpmacsdql",   IX86_BUILTIN_VPMACSDQL,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33189   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdqh,          "__builtin_ia32_vpmacsdqh",   IX86_BUILTIN_VPMACSDQH,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33190   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmadcsswd,         "__builtin_ia32_vpmadcsswd",  IX86_BUILTIN_VPMADCSSWD,  UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33191   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmadcswd,          "__builtin_ia32_vpmadcswd",   IX86_BUILTIN_VPMADCSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33192
33193   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv2di3,        "__builtin_ia32_vprotq",      IX86_BUILTIN_VPROTQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33194   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv4si3,        "__builtin_ia32_vprotd",      IX86_BUILTIN_VPROTD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33195   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv8hi3,        "__builtin_ia32_vprotw",      IX86_BUILTIN_VPROTW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33196   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv16qi3,       "__builtin_ia32_vprotb",      IX86_BUILTIN_VPROTB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33197   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv2di3,         "__builtin_ia32_vprotqi",     IX86_BUILTIN_VPROTQ_IMM,  UNKNOWN,      (int)MULTI_ARG_2_DI_IMM },
33198   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv4si3,         "__builtin_ia32_vprotdi",     IX86_BUILTIN_VPROTD_IMM,  UNKNOWN,      (int)MULTI_ARG_2_SI_IMM },
33199   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv8hi3,         "__builtin_ia32_vprotwi",     IX86_BUILTIN_VPROTW_IMM,  UNKNOWN,      (int)MULTI_ARG_2_HI_IMM },
33200   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv16qi3,        "__builtin_ia32_vprotbi",     IX86_BUILTIN_VPROTB_IMM,  UNKNOWN,      (int)MULTI_ARG_2_QI_IMM },
33201   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav2di3,         "__builtin_ia32_vpshaq",      IX86_BUILTIN_VPSHAQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33202   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav4si3,         "__builtin_ia32_vpshad",      IX86_BUILTIN_VPSHAD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33203   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav8hi3,         "__builtin_ia32_vpshaw",      IX86_BUILTIN_VPSHAW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33204   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav16qi3,        "__builtin_ia32_vpshab",      IX86_BUILTIN_VPSHAB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33205   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv2di3,         "__builtin_ia32_vpshlq",      IX86_BUILTIN_VPSHLQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33206   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv4si3,         "__builtin_ia32_vpshld",      IX86_BUILTIN_VPSHLD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33207   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv8hi3,         "__builtin_ia32_vpshlw",      IX86_BUILTIN_VPSHLW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33208   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv16qi3,        "__builtin_ia32_vpshlb",      IX86_BUILTIN_VPSHLB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33209
33210   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vmfrczv4sf2,       "__builtin_ia32_vfrczss",     IX86_BUILTIN_VFRCZSS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
33211   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vmfrczv2df2,       "__builtin_ia32_vfrczsd",     IX86_BUILTIN_VFRCZSD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
33212   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv4sf2,         "__builtin_ia32_vfrczps",     IX86_BUILTIN_VFRCZPS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
33213   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv2df2,         "__builtin_ia32_vfrczpd",     IX86_BUILTIN_VFRCZPD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
33214   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv8sf2,         "__builtin_ia32_vfrczps256",  IX86_BUILTIN_VFRCZPS256,  UNKNOWN,      (int)MULTI_ARG_1_SF2 },
33215   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv4df2,         "__builtin_ia32_vfrczpd256",  IX86_BUILTIN_VFRCZPD256,  UNKNOWN,      (int)MULTI_ARG_1_DF2 },
33216
33217   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbw,           "__builtin_ia32_vphaddbw",    IX86_BUILTIN_VPHADDBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33218   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbd,           "__builtin_ia32_vphaddbd",    IX86_BUILTIN_VPHADDBD,    UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
33219   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbq,           "__builtin_ia32_vphaddbq",    IX86_BUILTIN_VPHADDBQ,    UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
33220   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddwd,           "__builtin_ia32_vphaddwd",    IX86_BUILTIN_VPHADDWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33221   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddwq,           "__builtin_ia32_vphaddwq",    IX86_BUILTIN_VPHADDWQ,    UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
33222   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadddq,           "__builtin_ia32_vphadddq",    IX86_BUILTIN_VPHADDDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33223   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubw,          "__builtin_ia32_vphaddubw",   IX86_BUILTIN_VPHADDUBW,   UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33224   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubd,          "__builtin_ia32_vphaddubd",   IX86_BUILTIN_VPHADDUBD,   UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
33225   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubq,          "__builtin_ia32_vphaddubq",   IX86_BUILTIN_VPHADDUBQ,   UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
33226   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadduwd,          "__builtin_ia32_vphadduwd",   IX86_BUILTIN_VPHADDUWD,   UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33227   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadduwq,          "__builtin_ia32_vphadduwq",   IX86_BUILTIN_VPHADDUWQ,   UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
33228   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddudq,          "__builtin_ia32_vphaddudq",   IX86_BUILTIN_VPHADDUDQ,   UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33229   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubbw,           "__builtin_ia32_vphsubbw",    IX86_BUILTIN_VPHSUBBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33230   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubwd,           "__builtin_ia32_vphsubwd",    IX86_BUILTIN_VPHSUBWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33231   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubdq,           "__builtin_ia32_vphsubdq",    IX86_BUILTIN_VPHSUBDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33232
33233   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomeqb",    IX86_BUILTIN_VPCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
33234   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomneb",    IX86_BUILTIN_VPCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
33235   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomneqb",   IX86_BUILTIN_VPCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
33236   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomltb",    IX86_BUILTIN_VPCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
33237   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomleb",    IX86_BUILTIN_VPCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
33238   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomgtb",    IX86_BUILTIN_VPCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
33239   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomgeb",    IX86_BUILTIN_VPCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
33240
33241   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomeqw",    IX86_BUILTIN_VPCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
33242   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomnew",    IX86_BUILTIN_VPCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
33243   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomneqw",   IX86_BUILTIN_VPCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
33244   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomltw",    IX86_BUILTIN_VPCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
33245   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomlew",    IX86_BUILTIN_VPCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
33246   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomgtw",    IX86_BUILTIN_VPCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
33247   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomgew",    IX86_BUILTIN_VPCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
33248
33249   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomeqd",    IX86_BUILTIN_VPCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
33250   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomned",    IX86_BUILTIN_VPCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
33251   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomneqd",   IX86_BUILTIN_VPCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
33252   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomltd",    IX86_BUILTIN_VPCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
33253   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomled",    IX86_BUILTIN_VPCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
33254   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomgtd",    IX86_BUILTIN_VPCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
33255   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomged",    IX86_BUILTIN_VPCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
33256
33257   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomeqq",    IX86_BUILTIN_VPCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
33258   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomneq",    IX86_BUILTIN_VPCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
33259   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomneqq",   IX86_BUILTIN_VPCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
33260   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomltq",    IX86_BUILTIN_VPCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
33261   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomleq",    IX86_BUILTIN_VPCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
33262   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomgtq",    IX86_BUILTIN_VPCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
33263   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomgeq",    IX86_BUILTIN_VPCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
33264
33265   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomequb",   IX86_BUILTIN_VPCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
33266   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomneub",   IX86_BUILTIN_VPCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
33267   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomnequb",  IX86_BUILTIN_VPCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
33268   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomltub",   IX86_BUILTIN_VPCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
33269   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomleub",   IX86_BUILTIN_VPCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
33270   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomgtub",   IX86_BUILTIN_VPCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
33271   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomgeub",   IX86_BUILTIN_VPCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
33272
33273   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomequw",   IX86_BUILTIN_VPCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
33274   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomneuw",   IX86_BUILTIN_VPCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
33275   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomnequw",  IX86_BUILTIN_VPCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
33276   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomltuw",   IX86_BUILTIN_VPCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
33277   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomleuw",   IX86_BUILTIN_VPCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
33278   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomgtuw",   IX86_BUILTIN_VPCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
33279   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomgeuw",   IX86_BUILTIN_VPCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
33280
33281   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomequd",   IX86_BUILTIN_VPCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
33282   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomneud",   IX86_BUILTIN_VPCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
33283   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomnequd",  IX86_BUILTIN_VPCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
33284   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomltud",   IX86_BUILTIN_VPCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
33285   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomleud",   IX86_BUILTIN_VPCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
33286   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomgtud",   IX86_BUILTIN_VPCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
33287   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomgeud",   IX86_BUILTIN_VPCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
33288
33289   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomequq",   IX86_BUILTIN_VPCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
33290   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomneuq",   IX86_BUILTIN_VPCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
33291   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomnequq",  IX86_BUILTIN_VPCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
33292   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomltuq",   IX86_BUILTIN_VPCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
33293   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomleuq",   IX86_BUILTIN_VPCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
33294   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomgtuq",   IX86_BUILTIN_VPCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
33295   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomgeuq",   IX86_BUILTIN_VPCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
33296
33297   { 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 },
33298   { 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 },
33299   { 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 },
33300   { 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 },
33301   { 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 },
33302   { 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 },
33303   { 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 },
33304   { 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 },
33305
33306   { 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 },
33307   { 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 },
33308   { 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 },
33309   { 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 },
33310   { 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 },
33311   { 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 },
33312   { 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 },
33313   { 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 },
33314
33315   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v2df3,     "__builtin_ia32_vpermil2pd",  IX86_BUILTIN_VPERMIL2PD, UNKNOWN, (int)MULTI_ARG_4_DF2_DI_I },
33316   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v4sf3,     "__builtin_ia32_vpermil2ps",  IX86_BUILTIN_VPERMIL2PS, UNKNOWN, (int)MULTI_ARG_4_SF2_SI_I },
33317   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v4df3,     "__builtin_ia32_vpermil2pd256", IX86_BUILTIN_VPERMIL2PD256, UNKNOWN, (int)MULTI_ARG_4_DF2_DI_I1 },
33318   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v8sf3,     "__builtin_ia32_vpermil2ps256", IX86_BUILTIN_VPERMIL2PS256, UNKNOWN, (int)MULTI_ARG_4_SF2_SI_I1 },
33319
33320 };
33321 \f
33322 /* TM vector builtins.  */
33323
33324 /* Reuse the existing x86-specific `struct builtin_description' cause
33325    we're lazy.  Add casts to make them fit.  */
33326 static const struct builtin_description bdesc_tm[] =
33327 {
33328   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WM64", (enum ix86_builtins) BUILT_IN_TM_STORE_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33329   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WaRM64", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33330   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WaWM64", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33331   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33332   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RaRM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33333   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RaWM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33334   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RfWM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33335
33336   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WM128", (enum ix86_builtins) BUILT_IN_TM_STORE_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33337   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WaRM128", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33338   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WaWM128", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33339   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33340   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RaRM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33341   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RaWM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33342   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RfWM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33343
33344   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WM256", (enum ix86_builtins) BUILT_IN_TM_STORE_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33345   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WaRM256", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33346   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WaWM256", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33347   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33348   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RaRM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33349   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RaWM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33350   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RfWM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33351
33352   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_LM64", (enum ix86_builtins) BUILT_IN_TM_LOG_M64, UNKNOWN, VOID_FTYPE_PCVOID },
33353   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_LM128", (enum ix86_builtins) BUILT_IN_TM_LOG_M128, UNKNOWN, VOID_FTYPE_PCVOID },
33354   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_LM256", (enum ix86_builtins) BUILT_IN_TM_LOG_M256, UNKNOWN, VOID_FTYPE_PCVOID },
33355 };
33356
33357 /* TM callbacks.  */
33358
33359 /* Return the builtin decl needed to load a vector of TYPE.  */
33360
33361 static tree
33362 ix86_builtin_tm_load (tree type)
33363 {
33364   if (TREE_CODE (type) == VECTOR_TYPE)
33365     {
33366       switch (tree_to_uhwi (TYPE_SIZE (type)))
33367         {
33368         case 64:
33369           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M64);
33370         case 128:
33371           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M128);
33372         case 256:
33373           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M256);
33374         }
33375     }
33376   return NULL_TREE;
33377 }
33378
33379 /* Return the builtin decl needed to store a vector of TYPE.  */
33380
33381 static tree
33382 ix86_builtin_tm_store (tree type)
33383 {
33384   if (TREE_CODE (type) == VECTOR_TYPE)
33385     {
33386       switch (tree_to_uhwi (TYPE_SIZE (type)))
33387         {
33388         case 64:
33389           return builtin_decl_explicit (BUILT_IN_TM_STORE_M64);
33390         case 128:
33391           return builtin_decl_explicit (BUILT_IN_TM_STORE_M128);
33392         case 256:
33393           return builtin_decl_explicit (BUILT_IN_TM_STORE_M256);
33394         }
33395     }
33396   return NULL_TREE;
33397 }
33398 \f
33399 /* Initialize the transactional memory vector load/store builtins.  */
33400
33401 static void
33402 ix86_init_tm_builtins (void)
33403 {
33404   enum ix86_builtin_func_type ftype;
33405   const struct builtin_description *d;
33406   size_t i;
33407   tree decl;
33408   tree attrs_load, attrs_type_load, attrs_store, attrs_type_store;
33409   tree attrs_log, attrs_type_log;
33410
33411   if (!flag_tm)
33412     return;
33413
33414   /* If there are no builtins defined, we must be compiling in a
33415      language without trans-mem support.  */
33416   if (!builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
33417     return;
33418
33419   /* Use whatever attributes a normal TM load has.  */
33420   decl = builtin_decl_explicit (BUILT_IN_TM_LOAD_1);
33421   attrs_load = DECL_ATTRIBUTES (decl);
33422   attrs_type_load = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33423   /* Use whatever attributes a normal TM store has.  */
33424   decl = builtin_decl_explicit (BUILT_IN_TM_STORE_1);
33425   attrs_store = DECL_ATTRIBUTES (decl);
33426   attrs_type_store = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33427   /* Use whatever attributes a normal TM log has.  */
33428   decl = builtin_decl_explicit (BUILT_IN_TM_LOG);
33429   attrs_log = DECL_ATTRIBUTES (decl);
33430   attrs_type_log = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33431
33432   for (i = 0, d = bdesc_tm;
33433        i < ARRAY_SIZE (bdesc_tm);
33434        i++, d++)
33435     {
33436       if ((d->mask & ix86_isa_flags) != 0
33437           || (lang_hooks.builtin_function
33438               == lang_hooks.builtin_function_ext_scope))
33439         {
33440           tree type, attrs, attrs_type;
33441           enum built_in_function code = (enum built_in_function) d->code;
33442
33443           ftype = (enum ix86_builtin_func_type) d->flag;
33444           type = ix86_get_builtin_func_type (ftype);
33445
33446           if (BUILTIN_TM_LOAD_P (code))
33447             {
33448               attrs = attrs_load;
33449               attrs_type = attrs_type_load;
33450             }
33451           else if (BUILTIN_TM_STORE_P (code))
33452             {
33453               attrs = attrs_store;
33454               attrs_type = attrs_type_store;
33455             }
33456           else
33457             {
33458               attrs = attrs_log;
33459               attrs_type = attrs_type_log;
33460             }
33461           decl = add_builtin_function (d->name, type, code, BUILT_IN_NORMAL,
33462                                        /* The builtin without the prefix for
33463                                           calling it directly.  */
33464                                        d->name + strlen ("__builtin_"),
33465                                        attrs);
33466           /* add_builtin_function() will set the DECL_ATTRIBUTES, now
33467              set the TYPE_ATTRIBUTES.  */
33468           decl_attributes (&TREE_TYPE (decl), attrs_type, ATTR_FLAG_BUILT_IN);
33469
33470           set_builtin_decl (code, decl, false);
33471         }
33472     }
33473 }
33474
33475 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
33476    in the current target ISA to allow the user to compile particular modules
33477    with different target specific options that differ from the command line
33478    options.  */
33479 static void
33480 ix86_init_mmx_sse_builtins (void)
33481 {
33482   const struct builtin_description * d;
33483   enum ix86_builtin_func_type ftype;
33484   size_t i;
33485
33486   /* Add all special builtins with variable number of operands.  */
33487   for (i = 0, d = bdesc_special_args;
33488        i < ARRAY_SIZE (bdesc_special_args);
33489        i++, d++)
33490     {
33491       if (d->name == 0)
33492         continue;
33493
33494       ftype = (enum ix86_builtin_func_type) d->flag;
33495       def_builtin (d->mask, d->name, ftype, d->code);
33496     }
33497
33498   /* Add all builtins with variable number of operands.  */
33499   for (i = 0, d = bdesc_args;
33500        i < ARRAY_SIZE (bdesc_args);
33501        i++, d++)
33502     {
33503       if (d->name == 0)
33504         continue;
33505
33506       ftype = (enum ix86_builtin_func_type) d->flag;
33507       def_builtin_const (d->mask, d->name, ftype, d->code);
33508     }
33509
33510   /* Add all builtins with rounding.  */
33511   for (i = 0, d = bdesc_round_args;
33512        i < ARRAY_SIZE (bdesc_round_args);
33513        i++, d++)
33514     {
33515       if (d->name == 0)
33516         continue;
33517
33518       ftype = (enum ix86_builtin_func_type) d->flag;
33519       def_builtin_const (d->mask, d->name, ftype, d->code);
33520     }
33521
33522   /* pcmpestr[im] insns.  */
33523   for (i = 0, d = bdesc_pcmpestr;
33524        i < ARRAY_SIZE (bdesc_pcmpestr);
33525        i++, d++)
33526     {
33527       if (d->code == IX86_BUILTIN_PCMPESTRM128)
33528         ftype = V16QI_FTYPE_V16QI_INT_V16QI_INT_INT;
33529       else
33530         ftype = INT_FTYPE_V16QI_INT_V16QI_INT_INT;
33531       def_builtin_const (d->mask, d->name, ftype, d->code);
33532     }
33533
33534   /* pcmpistr[im] insns.  */
33535   for (i = 0, d = bdesc_pcmpistr;
33536        i < ARRAY_SIZE (bdesc_pcmpistr);
33537        i++, d++)
33538     {
33539       if (d->code == IX86_BUILTIN_PCMPISTRM128)
33540         ftype = V16QI_FTYPE_V16QI_V16QI_INT;
33541       else
33542         ftype = INT_FTYPE_V16QI_V16QI_INT;
33543       def_builtin_const (d->mask, d->name, ftype, d->code);
33544     }
33545
33546   /* comi/ucomi insns.  */
33547   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
33548     {
33549       if (d->mask == OPTION_MASK_ISA_SSE2)
33550         ftype = INT_FTYPE_V2DF_V2DF;
33551       else
33552         ftype = INT_FTYPE_V4SF_V4SF;
33553       def_builtin_const (d->mask, d->name, ftype, d->code);
33554     }
33555
33556   /* SSE */
33557   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr",
33558                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_LDMXCSR);
33559   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr",
33560                UNSIGNED_FTYPE_VOID, IX86_BUILTIN_STMXCSR);
33561
33562   /* SSE or 3DNow!A */
33563   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
33564                "__builtin_ia32_maskmovq", VOID_FTYPE_V8QI_V8QI_PCHAR,
33565                IX86_BUILTIN_MASKMOVQ);
33566
33567   /* SSE2 */
33568   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu",
33569                VOID_FTYPE_V16QI_V16QI_PCHAR, IX86_BUILTIN_MASKMOVDQU);
33570
33571   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush",
33572                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLFLUSH);
33573   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence",
33574                             VOID_FTYPE_VOID, IX86_BUILTIN_MFENCE);
33575
33576   /* SSE3.  */
33577   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor",
33578                VOID_FTYPE_PCVOID_UNSIGNED_UNSIGNED, IX86_BUILTIN_MONITOR);
33579   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait",
33580                VOID_FTYPE_UNSIGNED_UNSIGNED, IX86_BUILTIN_MWAIT);
33581
33582   /* AES */
33583   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128",
33584                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENC128);
33585   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128",
33586                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENCLAST128);
33587   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128",
33588                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDEC128);
33589   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128",
33590                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDECLAST128);
33591   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128",
33592                      V2DI_FTYPE_V2DI, IX86_BUILTIN_AESIMC128);
33593   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128",
33594                      V2DI_FTYPE_V2DI_INT, IX86_BUILTIN_AESKEYGENASSIST128);
33595
33596   /* PCLMUL */
33597   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128",
33598                      V2DI_FTYPE_V2DI_V2DI_INT, IX86_BUILTIN_PCLMULQDQ128);
33599
33600   /* RDRND */
33601   def_builtin (OPTION_MASK_ISA_RDRND, "__builtin_ia32_rdrand16_step",
33602                INT_FTYPE_PUSHORT, IX86_BUILTIN_RDRAND16_STEP);
33603   def_builtin (OPTION_MASK_ISA_RDRND, "__builtin_ia32_rdrand32_step",
33604                INT_FTYPE_PUNSIGNED, IX86_BUILTIN_RDRAND32_STEP);
33605   def_builtin (OPTION_MASK_ISA_RDRND | OPTION_MASK_ISA_64BIT,
33606                "__builtin_ia32_rdrand64_step", INT_FTYPE_PULONGLONG,
33607                IX86_BUILTIN_RDRAND64_STEP);
33608
33609   /* AVX2 */
33610   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv2df",
33611                V2DF_FTYPE_V2DF_PCDOUBLE_V4SI_V2DF_INT,
33612                IX86_BUILTIN_GATHERSIV2DF);
33613
33614   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4df",
33615                V4DF_FTYPE_V4DF_PCDOUBLE_V4SI_V4DF_INT,
33616                IX86_BUILTIN_GATHERSIV4DF);
33617
33618   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv2df",
33619                V2DF_FTYPE_V2DF_PCDOUBLE_V2DI_V2DF_INT,
33620                IX86_BUILTIN_GATHERDIV2DF);
33621
33622   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4df",
33623                V4DF_FTYPE_V4DF_PCDOUBLE_V4DI_V4DF_INT,
33624                IX86_BUILTIN_GATHERDIV4DF);
33625
33626   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4sf",
33627                V4SF_FTYPE_V4SF_PCFLOAT_V4SI_V4SF_INT,
33628                IX86_BUILTIN_GATHERSIV4SF);
33629
33630   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv8sf",
33631                V8SF_FTYPE_V8SF_PCFLOAT_V8SI_V8SF_INT,
33632                IX86_BUILTIN_GATHERSIV8SF);
33633
33634   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4sf",
33635                V4SF_FTYPE_V4SF_PCFLOAT_V2DI_V4SF_INT,
33636                IX86_BUILTIN_GATHERDIV4SF);
33637
33638   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4sf256",
33639                V4SF_FTYPE_V4SF_PCFLOAT_V4DI_V4SF_INT,
33640                IX86_BUILTIN_GATHERDIV8SF);
33641
33642   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv2di",
33643                V2DI_FTYPE_V2DI_PCINT64_V4SI_V2DI_INT,
33644                IX86_BUILTIN_GATHERSIV2DI);
33645
33646   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4di",
33647                V4DI_FTYPE_V4DI_PCINT64_V4SI_V4DI_INT,
33648                IX86_BUILTIN_GATHERSIV4DI);
33649
33650   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv2di",
33651                V2DI_FTYPE_V2DI_PCINT64_V2DI_V2DI_INT,
33652                IX86_BUILTIN_GATHERDIV2DI);
33653
33654   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4di",
33655                V4DI_FTYPE_V4DI_PCINT64_V4DI_V4DI_INT,
33656                IX86_BUILTIN_GATHERDIV4DI);
33657
33658   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4si",
33659                V4SI_FTYPE_V4SI_PCINT_V4SI_V4SI_INT,
33660                IX86_BUILTIN_GATHERSIV4SI);
33661
33662   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv8si",
33663                V8SI_FTYPE_V8SI_PCINT_V8SI_V8SI_INT,
33664                IX86_BUILTIN_GATHERSIV8SI);
33665
33666   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4si",
33667                V4SI_FTYPE_V4SI_PCINT_V2DI_V4SI_INT,
33668                IX86_BUILTIN_GATHERDIV4SI);
33669
33670   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4si256",
33671                V4SI_FTYPE_V4SI_PCINT_V4DI_V4SI_INT,
33672                IX86_BUILTIN_GATHERDIV8SI);
33673
33674   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df ",
33675                V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_V4DF_INT,
33676                IX86_BUILTIN_GATHERALTSIV4DF);
33677
33678   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256 ",
33679                V8SF_FTYPE_V8SF_PCFLOAT_V4DI_V8SF_INT,
33680                IX86_BUILTIN_GATHERALTDIV8SF);
33681
33682   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di ",
33683                V4DI_FTYPE_V4DI_PCINT64_V8SI_V4DI_INT,
33684                IX86_BUILTIN_GATHERALTSIV4DI);
33685
33686   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",
33687                V8SI_FTYPE_V8SI_PCINT_V4DI_V8SI_INT,
33688                IX86_BUILTIN_GATHERALTDIV8SI);
33689
33690   /* AVX512F */
33691   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv16sf",
33692                V16SF_FTYPE_V16SF_PCFLOAT_V16SI_HI_INT,
33693                IX86_BUILTIN_GATHER3SIV16SF);
33694
33695   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv8df",
33696                V8DF_FTYPE_V8DF_PCDOUBLE_V8SI_QI_INT,
33697                IX86_BUILTIN_GATHER3SIV8DF);
33698
33699   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv16sf",
33700                V8SF_FTYPE_V8SF_PCFLOAT_V8DI_QI_INT,
33701                IX86_BUILTIN_GATHER3DIV16SF);
33702
33703   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv8df",
33704                V8DF_FTYPE_V8DF_PCDOUBLE_V8DI_QI_INT,
33705                IX86_BUILTIN_GATHER3DIV8DF);
33706
33707   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv16si",
33708                V16SI_FTYPE_V16SI_PCINT_V16SI_HI_INT,
33709                IX86_BUILTIN_GATHER3SIV16SI);
33710
33711   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv8di",
33712                V8DI_FTYPE_V8DI_PCINT64_V8SI_QI_INT,
33713                IX86_BUILTIN_GATHER3SIV8DI);
33714
33715   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv16si",
33716                V8SI_FTYPE_V8SI_PCINT_V8DI_QI_INT,
33717                IX86_BUILTIN_GATHER3DIV16SI);
33718
33719   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv8di",
33720                V8DI_FTYPE_V8DI_PCINT64_V8DI_QI_INT,
33721                IX86_BUILTIN_GATHER3DIV8DI);
33722
33723   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df ",
33724                V8DF_FTYPE_V8DF_PCDOUBLE_V16SI_QI_INT,
33725                IX86_BUILTIN_GATHER3ALTSIV8DF);
33726
33727   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf ",
33728                V16SF_FTYPE_V16SF_PCFLOAT_V8DI_HI_INT,
33729                IX86_BUILTIN_GATHER3ALTDIV16SF);
33730
33731   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di ",
33732                V8DI_FTYPE_V8DI_PCINT64_V16SI_QI_INT,
33733                IX86_BUILTIN_GATHER3ALTSIV8DI);
33734
33735   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si ",
33736                V16SI_FTYPE_V16SI_PCINT_V8DI_HI_INT,
33737                IX86_BUILTIN_GATHER3ALTDIV16SI);
33738
33739   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv16sf",
33740                VOID_FTYPE_PFLOAT_HI_V16SI_V16SF_INT,
33741                IX86_BUILTIN_SCATTERSIV16SF);
33742
33743   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv8df",
33744                VOID_FTYPE_PDOUBLE_QI_V8SI_V8DF_INT,
33745                IX86_BUILTIN_SCATTERSIV8DF);
33746
33747   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv16sf",
33748                VOID_FTYPE_PFLOAT_QI_V8DI_V8SF_INT,
33749                IX86_BUILTIN_SCATTERDIV16SF);
33750
33751   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv8df",
33752                VOID_FTYPE_PDOUBLE_QI_V8DI_V8DF_INT,
33753                IX86_BUILTIN_SCATTERDIV8DF);
33754
33755   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv16si",
33756                VOID_FTYPE_PINT_HI_V16SI_V16SI_INT,
33757                IX86_BUILTIN_SCATTERSIV16SI);
33758
33759   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv8di",
33760                VOID_FTYPE_PLONGLONG_QI_V8SI_V8DI_INT,
33761                IX86_BUILTIN_SCATTERSIV8DI);
33762
33763   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv16si",
33764                VOID_FTYPE_PINT_QI_V8DI_V8SI_INT,
33765                IX86_BUILTIN_SCATTERDIV16SI);
33766
33767   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv8di",
33768                VOID_FTYPE_PLONGLONG_QI_V8DI_V8DI_INT,
33769                IX86_BUILTIN_SCATTERDIV8DI);
33770
33771   /* AVX512VL */
33772   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv2df",
33773                V2DF_FTYPE_V2DF_PCDOUBLE_V4SI_QI_INT,
33774                IX86_BUILTIN_GATHER3SIV2DF);
33775
33776   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4df",
33777                V4DF_FTYPE_V4DF_PCDOUBLE_V4SI_QI_INT,
33778                IX86_BUILTIN_GATHER3SIV4DF);
33779
33780   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div2df",
33781                V2DF_FTYPE_V2DF_PCDOUBLE_V2DI_QI_INT,
33782                IX86_BUILTIN_GATHER3DIV2DF);
33783
33784   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4df",
33785                V4DF_FTYPE_V4DF_PCDOUBLE_V4DI_QI_INT,
33786                IX86_BUILTIN_GATHER3DIV4DF);
33787
33788   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4sf",
33789                V4SF_FTYPE_V4SF_PCFLOAT_V4SI_QI_INT,
33790                IX86_BUILTIN_GATHER3SIV4SF);
33791
33792   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv8sf",
33793                V8SF_FTYPE_V8SF_PCFLOAT_V8SI_QI_INT,
33794                IX86_BUILTIN_GATHER3SIV8SF);
33795
33796   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4sf",
33797                V4SF_FTYPE_V4SF_PCFLOAT_V2DI_QI_INT,
33798                IX86_BUILTIN_GATHER3DIV4SF);
33799
33800   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div8sf",
33801                V4SF_FTYPE_V4SF_PCFLOAT_V4DI_QI_INT,
33802                IX86_BUILTIN_GATHER3DIV8SF);
33803
33804   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv2di",
33805                V2DI_FTYPE_V2DI_PCINT64_V4SI_QI_INT,
33806                IX86_BUILTIN_GATHER3SIV2DI);
33807
33808   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4di",
33809                V4DI_FTYPE_V4DI_PCINT64_V4SI_QI_INT,
33810                IX86_BUILTIN_GATHER3SIV4DI);
33811
33812   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div2di",
33813                V2DI_FTYPE_V2DI_PCINT64_V2DI_QI_INT,
33814                IX86_BUILTIN_GATHER3DIV2DI);
33815
33816   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4di",
33817                V4DI_FTYPE_V4DI_PCINT64_V4DI_QI_INT,
33818                IX86_BUILTIN_GATHER3DIV4DI);
33819
33820   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4si",
33821                V4SI_FTYPE_V4SI_PCINT_V4SI_QI_INT,
33822                IX86_BUILTIN_GATHER3SIV4SI);
33823
33824   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv8si",
33825                V8SI_FTYPE_V8SI_PCINT_V8SI_QI_INT,
33826                IX86_BUILTIN_GATHER3SIV8SI);
33827
33828   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4si",
33829                V4SI_FTYPE_V4SI_PCINT_V2DI_QI_INT,
33830                IX86_BUILTIN_GATHER3DIV4SI);
33831
33832   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div8si",
33833                V4SI_FTYPE_V4SI_PCINT_V4DI_QI_INT,
33834                IX86_BUILTIN_GATHER3DIV8SI);
33835
33836   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df ",
33837                V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_QI_INT,
33838                IX86_BUILTIN_GATHER3ALTSIV4DF);
33839
33840   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf ",
33841                V8SF_FTYPE_V8SF_PCFLOAT_V4DI_QI_INT,
33842                IX86_BUILTIN_GATHER3ALTDIV8SF);
33843
33844   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di ",
33845                V4DI_FTYPE_V4DI_PCINT64_V8SI_QI_INT,
33846                IX86_BUILTIN_GATHER3ALTSIV4DI);
33847
33848   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si ",
33849                V8SI_FTYPE_V8SI_PCINT_V4DI_QI_INT,
33850                IX86_BUILTIN_GATHER3ALTDIV8SI);
33851
33852   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv8sf",
33853                VOID_FTYPE_PFLOAT_QI_V8SI_V8SF_INT,
33854                IX86_BUILTIN_SCATTERSIV8SF);
33855
33856   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4sf",
33857                VOID_FTYPE_PFLOAT_QI_V4SI_V4SF_INT,
33858                IX86_BUILTIN_SCATTERSIV4SF);
33859
33860   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4df",
33861                VOID_FTYPE_PDOUBLE_QI_V4SI_V4DF_INT,
33862                IX86_BUILTIN_SCATTERSIV4DF);
33863
33864   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv2df",
33865                VOID_FTYPE_PDOUBLE_QI_V4SI_V2DF_INT,
33866                IX86_BUILTIN_SCATTERSIV2DF);
33867
33868   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv8sf",
33869                VOID_FTYPE_PFLOAT_QI_V4DI_V4SF_INT,
33870                IX86_BUILTIN_SCATTERDIV8SF);
33871
33872   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4sf",
33873                VOID_FTYPE_PFLOAT_QI_V2DI_V4SF_INT,
33874                IX86_BUILTIN_SCATTERDIV4SF);
33875
33876   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4df",
33877                VOID_FTYPE_PDOUBLE_QI_V4DI_V4DF_INT,
33878                IX86_BUILTIN_SCATTERDIV4DF);
33879
33880   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2df",
33881                VOID_FTYPE_PDOUBLE_QI_V2DI_V2DF_INT,
33882                IX86_BUILTIN_SCATTERDIV2DF);
33883
33884   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv8si",
33885                VOID_FTYPE_PINT_QI_V8SI_V8SI_INT,
33886                IX86_BUILTIN_SCATTERSIV8SI);
33887
33888   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4si",
33889                VOID_FTYPE_PINT_QI_V4SI_V4SI_INT,
33890                IX86_BUILTIN_SCATTERSIV4SI);
33891
33892   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4di",
33893                VOID_FTYPE_PLONGLONG_QI_V4SI_V4DI_INT,
33894                IX86_BUILTIN_SCATTERSIV4DI);
33895
33896   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv2di",
33897                VOID_FTYPE_PLONGLONG_QI_V4SI_V2DI_INT,
33898                IX86_BUILTIN_SCATTERSIV2DI);
33899
33900   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv8si",
33901                VOID_FTYPE_PINT_QI_V4DI_V4SI_INT,
33902                IX86_BUILTIN_SCATTERDIV8SI);
33903
33904   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4si",
33905                VOID_FTYPE_PINT_QI_V2DI_V4SI_INT,
33906                IX86_BUILTIN_SCATTERDIV4SI);
33907
33908   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4di",
33909                VOID_FTYPE_PLONGLONG_QI_V4DI_V4DI_INT,
33910                IX86_BUILTIN_SCATTERDIV4DI);
33911
33912   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2di",
33913                VOID_FTYPE_PLONGLONG_QI_V2DI_V2DI_INT,
33914                IX86_BUILTIN_SCATTERDIV2DI);
33915
33916   /* AVX512PF */
33917   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfdpd",
33918                VOID_FTYPE_QI_V8SI_PCINT64_INT_INT,
33919                IX86_BUILTIN_GATHERPFDPD);
33920   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfdps",
33921                VOID_FTYPE_HI_V16SI_PCINT_INT_INT,
33922                IX86_BUILTIN_GATHERPFDPS);
33923   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfqpd",
33924                VOID_FTYPE_QI_V8DI_PCINT64_INT_INT,
33925                IX86_BUILTIN_GATHERPFQPD);
33926   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfqps",
33927                VOID_FTYPE_QI_V8DI_PCINT_INT_INT,
33928                IX86_BUILTIN_GATHERPFQPS);
33929   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfdpd",
33930                VOID_FTYPE_QI_V8SI_PCINT64_INT_INT,
33931                IX86_BUILTIN_SCATTERPFDPD);
33932   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfdps",
33933                VOID_FTYPE_HI_V16SI_PCINT_INT_INT,
33934                IX86_BUILTIN_SCATTERPFDPS);
33935   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfqpd",
33936                VOID_FTYPE_QI_V8DI_PCINT64_INT_INT,
33937                IX86_BUILTIN_SCATTERPFQPD);
33938   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfqps",
33939                VOID_FTYPE_QI_V8DI_PCINT_INT_INT,
33940                IX86_BUILTIN_SCATTERPFQPS);
33941
33942   /* SHA */
33943   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1msg1",
33944                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1MSG1);
33945   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1msg2",
33946                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1MSG2);
33947   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1nexte",
33948                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1NEXTE);
33949   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1rnds4",
33950                      V4SI_FTYPE_V4SI_V4SI_INT, IX86_BUILTIN_SHA1RNDS4);
33951   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256msg1",
33952                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA256MSG1);
33953   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256msg2",
33954                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA256MSG2);
33955   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256rnds2",
33956                      V4SI_FTYPE_V4SI_V4SI_V4SI, IX86_BUILTIN_SHA256RNDS2);
33957
33958   /* RTM.  */
33959   def_builtin (OPTION_MASK_ISA_RTM, "__builtin_ia32_xabort",
33960                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_XABORT);
33961
33962   /* MMX access to the vec_init patterns.  */
33963   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si",
33964                      V2SI_FTYPE_INT_INT, IX86_BUILTIN_VEC_INIT_V2SI);
33965
33966   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi",
33967                      V4HI_FTYPE_HI_HI_HI_HI,
33968                      IX86_BUILTIN_VEC_INIT_V4HI);
33969
33970   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi",
33971                      V8QI_FTYPE_QI_QI_QI_QI_QI_QI_QI_QI,
33972                      IX86_BUILTIN_VEC_INIT_V8QI);
33973
33974   /* Access to the vec_extract patterns.  */
33975   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df",
33976                      DOUBLE_FTYPE_V2DF_INT, IX86_BUILTIN_VEC_EXT_V2DF);
33977   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di",
33978                      DI_FTYPE_V2DI_INT, IX86_BUILTIN_VEC_EXT_V2DI);
33979   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf",
33980                      FLOAT_FTYPE_V4SF_INT, IX86_BUILTIN_VEC_EXT_V4SF);
33981   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si",
33982                      SI_FTYPE_V4SI_INT, IX86_BUILTIN_VEC_EXT_V4SI);
33983   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi",
33984                      HI_FTYPE_V8HI_INT, IX86_BUILTIN_VEC_EXT_V8HI);
33985
33986   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
33987                      "__builtin_ia32_vec_ext_v4hi",
33988                      HI_FTYPE_V4HI_INT, IX86_BUILTIN_VEC_EXT_V4HI);
33989
33990   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si",
33991                      SI_FTYPE_V2SI_INT, IX86_BUILTIN_VEC_EXT_V2SI);
33992
33993   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi",
33994                      QI_FTYPE_V16QI_INT, IX86_BUILTIN_VEC_EXT_V16QI);
33995
33996   /* Access to the vec_set patterns.  */
33997   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT,
33998                      "__builtin_ia32_vec_set_v2di",
33999                      V2DI_FTYPE_V2DI_DI_INT, IX86_BUILTIN_VEC_SET_V2DI);
34000
34001   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf",
34002                      V4SF_FTYPE_V4SF_FLOAT_INT, IX86_BUILTIN_VEC_SET_V4SF);
34003
34004   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si",
34005                      V4SI_FTYPE_V4SI_SI_INT, IX86_BUILTIN_VEC_SET_V4SI);
34006
34007   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi",
34008                      V8HI_FTYPE_V8HI_HI_INT, IX86_BUILTIN_VEC_SET_V8HI);
34009
34010   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
34011                      "__builtin_ia32_vec_set_v4hi",
34012                      V4HI_FTYPE_V4HI_HI_INT, IX86_BUILTIN_VEC_SET_V4HI);
34013
34014   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi",
34015                      V16QI_FTYPE_V16QI_QI_INT, IX86_BUILTIN_VEC_SET_V16QI);
34016
34017   /* RDSEED */
34018   def_builtin (OPTION_MASK_ISA_RDSEED, "__builtin_ia32_rdseed_hi_step",
34019                INT_FTYPE_PUSHORT, IX86_BUILTIN_RDSEED16_STEP);
34020   def_builtin (OPTION_MASK_ISA_RDSEED, "__builtin_ia32_rdseed_si_step",
34021                INT_FTYPE_PUNSIGNED, IX86_BUILTIN_RDSEED32_STEP);
34022   def_builtin (OPTION_MASK_ISA_RDSEED | OPTION_MASK_ISA_64BIT,
34023                "__builtin_ia32_rdseed_di_step",
34024                INT_FTYPE_PULONGLONG, IX86_BUILTIN_RDSEED64_STEP);
34025
34026   /* ADCX */
34027   def_builtin (0, "__builtin_ia32_addcarryx_u32",
34028                UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED, IX86_BUILTIN_ADDCARRYX32);
34029   def_builtin (OPTION_MASK_ISA_64BIT,
34030                "__builtin_ia32_addcarryx_u64",
34031                UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG,
34032                IX86_BUILTIN_ADDCARRYX64);
34033
34034   /* SBB */
34035   def_builtin (0, "__builtin_ia32_sbb_u32",
34036                UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED, IX86_BUILTIN_SBB32);
34037   def_builtin (OPTION_MASK_ISA_64BIT,
34038                "__builtin_ia32_sbb_u64",
34039                UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG,
34040                IX86_BUILTIN_SBB64);
34041
34042   /* Read/write FLAGS.  */
34043   def_builtin (~OPTION_MASK_ISA_64BIT, "__builtin_ia32_readeflags_u32",
34044                UNSIGNED_FTYPE_VOID, IX86_BUILTIN_READ_FLAGS);
34045   def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_ia32_readeflags_u64",
34046                UINT64_FTYPE_VOID, IX86_BUILTIN_READ_FLAGS);
34047   def_builtin (~OPTION_MASK_ISA_64BIT, "__builtin_ia32_writeeflags_u32",
34048                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_WRITE_FLAGS);
34049   def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_ia32_writeeflags_u64",
34050                VOID_FTYPE_UINT64, IX86_BUILTIN_WRITE_FLAGS);
34051
34052   /* CLFLUSHOPT.  */
34053   def_builtin (OPTION_MASK_ISA_CLFLUSHOPT, "__builtin_ia32_clflushopt",
34054                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLFLUSHOPT);
34055
34056   /* CLWB.  */
34057   def_builtin (OPTION_MASK_ISA_CLWB, "__builtin_ia32_clwb",
34058                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLWB);
34059
34060   /* Add FMA4 multi-arg argument instructions */
34061   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
34062     {
34063       if (d->name == 0)
34064         continue;
34065
34066       ftype = (enum ix86_builtin_func_type) d->flag;
34067       def_builtin_const (d->mask, d->name, ftype, d->code);
34068     }
34069 }
34070
34071 static void
34072 ix86_init_mpx_builtins ()
34073 {
34074   const struct builtin_description * d;
34075   enum ix86_builtin_func_type ftype;
34076   tree decl;
34077   size_t i;
34078
34079   for (i = 0, d = bdesc_mpx;
34080        i < ARRAY_SIZE (bdesc_mpx);
34081        i++, d++)
34082     {
34083       if (d->name == 0)
34084         continue;
34085
34086       ftype = (enum ix86_builtin_func_type) d->flag;
34087       decl = def_builtin (d->mask, d->name, ftype, d->code);
34088
34089       /* With no leaf and nothrow flags for MPX builtins
34090          abnormal edges may follow its call when setjmp
34091          presents in the function.  Since we may have a lot
34092          of MPX builtins calls it causes lots of useless
34093          edges and enormous PHI nodes.  To avoid this we mark
34094          MPX builtins as leaf and nothrow.  */
34095       if (decl)
34096         {
34097           DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
34098                                                     NULL_TREE);
34099           TREE_NOTHROW (decl) = 1;
34100         }
34101       else
34102         {
34103           ix86_builtins_isa[(int)d->code].leaf_p = true;
34104           ix86_builtins_isa[(int)d->code].nothrow_p = true;
34105         }
34106     }
34107
34108   for (i = 0, d = bdesc_mpx_const;
34109        i < ARRAY_SIZE (bdesc_mpx_const);
34110        i++, d++)
34111     {
34112       if (d->name == 0)
34113         continue;
34114
34115       ftype = (enum ix86_builtin_func_type) d->flag;
34116       decl = def_builtin_const (d->mask, d->name, ftype, d->code);
34117
34118       if (decl)
34119         {
34120           DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
34121                                                     NULL_TREE);
34122           TREE_NOTHROW (decl) = 1;
34123         }
34124       else
34125         {
34126           ix86_builtins_isa[(int)d->code].leaf_p = true;
34127           ix86_builtins_isa[(int)d->code].nothrow_p = true;
34128         }
34129     }
34130 }
34131
34132 /* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL
34133    to return a pointer to VERSION_DECL if the outcome of the expression
34134    formed by PREDICATE_CHAIN is true.  This function will be called during
34135    version dispatch to decide which function version to execute.  It returns
34136    the basic block at the end, to which more conditions can be added.  */
34137
34138 static basic_block
34139 add_condition_to_bb (tree function_decl, tree version_decl,
34140                      tree predicate_chain, basic_block new_bb)
34141 {
34142   gimple return_stmt;
34143   tree convert_expr, result_var;
34144   gimple convert_stmt;
34145   gimple call_cond_stmt;
34146   gimple if_else_stmt;
34147
34148   basic_block bb1, bb2, bb3;
34149   edge e12, e23;
34150
34151   tree cond_var, and_expr_var = NULL_TREE;
34152   gimple_seq gseq;
34153
34154   tree predicate_decl, predicate_arg;
34155
34156   push_cfun (DECL_STRUCT_FUNCTION (function_decl));
34157
34158   gcc_assert (new_bb != NULL);
34159   gseq = bb_seq (new_bb);
34160
34161
34162   convert_expr = build1 (CONVERT_EXPR, ptr_type_node,
34163                          build_fold_addr_expr (version_decl));
34164   result_var = create_tmp_var (ptr_type_node);
34165   convert_stmt = gimple_build_assign (result_var, convert_expr); 
34166   return_stmt = gimple_build_return (result_var);
34167
34168   if (predicate_chain == NULL_TREE)
34169     {
34170       gimple_seq_add_stmt (&gseq, convert_stmt);
34171       gimple_seq_add_stmt (&gseq, return_stmt);
34172       set_bb_seq (new_bb, gseq);
34173       gimple_set_bb (convert_stmt, new_bb);
34174       gimple_set_bb (return_stmt, new_bb);
34175       pop_cfun ();
34176       return new_bb;
34177     }
34178
34179   while (predicate_chain != NULL)
34180     {
34181       cond_var = create_tmp_var (integer_type_node);
34182       predicate_decl = TREE_PURPOSE (predicate_chain);
34183       predicate_arg = TREE_VALUE (predicate_chain);
34184       call_cond_stmt = gimple_build_call (predicate_decl, 1, predicate_arg);
34185       gimple_call_set_lhs (call_cond_stmt, cond_var);
34186
34187       gimple_set_block (call_cond_stmt, DECL_INITIAL (function_decl));
34188       gimple_set_bb (call_cond_stmt, new_bb);
34189       gimple_seq_add_stmt (&gseq, call_cond_stmt);
34190
34191       predicate_chain = TREE_CHAIN (predicate_chain);
34192       
34193       if (and_expr_var == NULL)
34194         and_expr_var = cond_var;
34195       else
34196         {
34197           gimple assign_stmt;
34198           /* Use MIN_EXPR to check if any integer is zero?.
34199              and_expr_var = min_expr <cond_var, and_expr_var>  */
34200           assign_stmt = gimple_build_assign (and_expr_var,
34201                           build2 (MIN_EXPR, integer_type_node,
34202                                   cond_var, and_expr_var));
34203
34204           gimple_set_block (assign_stmt, DECL_INITIAL (function_decl));
34205           gimple_set_bb (assign_stmt, new_bb);
34206           gimple_seq_add_stmt (&gseq, assign_stmt);
34207         }
34208     }
34209
34210   if_else_stmt = gimple_build_cond (GT_EXPR, and_expr_var,
34211                                     integer_zero_node,
34212                                     NULL_TREE, NULL_TREE);
34213   gimple_set_block (if_else_stmt, DECL_INITIAL (function_decl));
34214   gimple_set_bb (if_else_stmt, new_bb);
34215   gimple_seq_add_stmt (&gseq, if_else_stmt);
34216
34217   gimple_seq_add_stmt (&gseq, convert_stmt);
34218   gimple_seq_add_stmt (&gseq, return_stmt);
34219   set_bb_seq (new_bb, gseq);
34220
34221   bb1 = new_bb;
34222   e12 = split_block (bb1, if_else_stmt);
34223   bb2 = e12->dest;
34224   e12->flags &= ~EDGE_FALLTHRU;
34225   e12->flags |= EDGE_TRUE_VALUE;
34226
34227   e23 = split_block (bb2, return_stmt);
34228
34229   gimple_set_bb (convert_stmt, bb2);
34230   gimple_set_bb (return_stmt, bb2);
34231
34232   bb3 = e23->dest;
34233   make_edge (bb1, bb3, EDGE_FALSE_VALUE); 
34234
34235   remove_edge (e23);
34236   make_edge (bb2, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
34237
34238   pop_cfun ();
34239
34240   return bb3;
34241 }
34242
34243 /* This parses the attribute arguments to target in DECL and determines
34244    the right builtin to use to match the platform specification.
34245    It returns the priority value for this version decl.  If PREDICATE_LIST
34246    is not NULL, it stores the list of cpu features that need to be checked
34247    before dispatching this function.  */
34248
34249 static unsigned int
34250 get_builtin_code_for_version (tree decl, tree *predicate_list)
34251 {
34252   tree attrs;
34253   struct cl_target_option cur_target;
34254   tree target_node;
34255   struct cl_target_option *new_target;
34256   const char *arg_str = NULL;
34257   const char *attrs_str = NULL;
34258   char *tok_str = NULL;
34259   char *token;
34260
34261   /* Priority of i386 features, greater value is higher priority.   This is
34262      used to decide the order in which function dispatch must happen.  For
34263      instance, a version specialized for SSE4.2 should be checked for dispatch
34264      before a version for SSE3, as SSE4.2 implies SSE3.  */
34265   enum feature_priority
34266   {
34267     P_ZERO = 0,
34268     P_MMX,
34269     P_SSE,
34270     P_SSE2,
34271     P_SSE3,
34272     P_SSSE3,
34273     P_PROC_SSSE3,
34274     P_SSE4_A,
34275     P_PROC_SSE4_A,
34276     P_SSE4_1,
34277     P_SSE4_2,
34278     P_PROC_SSE4_2,
34279     P_POPCNT,
34280     P_AVX,
34281     P_PROC_AVX,
34282     P_FMA4,
34283     P_XOP,
34284     P_PROC_XOP,
34285     P_FMA,    
34286     P_PROC_FMA,
34287     P_AVX2,
34288     P_PROC_AVX2,
34289     P_AVX512F,
34290     P_PROC_AVX512F
34291   };
34292
34293  enum feature_priority priority = P_ZERO;
34294
34295   /* These are the target attribute strings for which a dispatcher is
34296      available, from fold_builtin_cpu.  */
34297
34298   static struct _feature_list
34299     {
34300       const char *const name;
34301       const enum feature_priority priority;
34302     }
34303   const feature_list[] =
34304     {
34305       {"mmx", P_MMX},
34306       {"sse", P_SSE},
34307       {"sse2", P_SSE2},
34308       {"sse3", P_SSE3},
34309       {"sse4a", P_SSE4_A},
34310       {"ssse3", P_SSSE3},
34311       {"sse4.1", P_SSE4_1},
34312       {"sse4.2", P_SSE4_2},
34313       {"popcnt", P_POPCNT},
34314       {"avx", P_AVX},
34315       {"fma4", P_FMA4},
34316       {"xop", P_XOP},
34317       {"fma", P_FMA},
34318       {"avx2", P_AVX2},
34319       {"avx512f", P_AVX512F}
34320     };
34321
34322
34323   static unsigned int NUM_FEATURES
34324     = sizeof (feature_list) / sizeof (struct _feature_list);
34325
34326   unsigned int i;
34327
34328   tree predicate_chain = NULL_TREE;
34329   tree predicate_decl, predicate_arg;
34330
34331   attrs = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34332   gcc_assert (attrs != NULL);
34333
34334   attrs = TREE_VALUE (TREE_VALUE (attrs));
34335
34336   gcc_assert (TREE_CODE (attrs) == STRING_CST);
34337   attrs_str = TREE_STRING_POINTER (attrs);
34338
34339   /* Return priority zero for default function.  */
34340   if (strcmp (attrs_str, "default") == 0)
34341     return 0;
34342
34343   /* Handle arch= if specified.  For priority, set it to be 1 more than
34344      the best instruction set the processor can handle.  For instance, if
34345      there is a version for atom and a version for ssse3 (the highest ISA
34346      priority for atom), the atom version must be checked for dispatch
34347      before the ssse3 version. */
34348   if (strstr (attrs_str, "arch=") != NULL)
34349     {
34350       cl_target_option_save (&cur_target, &global_options);
34351       target_node = ix86_valid_target_attribute_tree (attrs, &global_options,
34352                                                       &global_options_set);
34353     
34354       gcc_assert (target_node);
34355       new_target = TREE_TARGET_OPTION (target_node);
34356       gcc_assert (new_target);
34357       
34358       if (new_target->arch_specified && new_target->arch > 0)
34359         {
34360           switch (new_target->arch)
34361             {
34362             case PROCESSOR_CORE2:
34363               arg_str = "core2";
34364               priority = P_PROC_SSSE3;
34365               break;
34366             case PROCESSOR_NEHALEM:
34367               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_AES)
34368                 arg_str = "westmere";
34369               else
34370                 /* We translate "arch=corei7" and "arch=nehalem" to
34371                    "corei7" so that it will be mapped to M_INTEL_COREI7
34372                    as cpu type to cover all M_INTEL_COREI7_XXXs.  */
34373                 arg_str = "corei7";
34374               priority = P_PROC_SSE4_2;
34375               break;
34376             case PROCESSOR_SANDYBRIDGE:
34377               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_F16C)
34378                 arg_str = "ivybridge";
34379               else
34380                 arg_str = "sandybridge";
34381               priority = P_PROC_AVX;
34382               break;
34383             case PROCESSOR_HASWELL:
34384               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_ADX)
34385                 arg_str = "broadwell";
34386               else
34387                 arg_str = "haswell";
34388               priority = P_PROC_AVX2;
34389               break;
34390             case PROCESSOR_BONNELL:
34391               arg_str = "bonnell";
34392               priority = P_PROC_SSSE3;
34393               break;
34394             case PROCESSOR_KNL:
34395               arg_str = "knl";
34396               priority = P_PROC_AVX512F;
34397               break;
34398             case PROCESSOR_SILVERMONT:
34399               arg_str = "silvermont";
34400               priority = P_PROC_SSE4_2;
34401               break;
34402             case PROCESSOR_AMDFAM10:
34403               arg_str = "amdfam10h";
34404               priority = P_PROC_SSE4_A;
34405               break;
34406             case PROCESSOR_BTVER1:
34407               arg_str = "btver1";
34408               priority = P_PROC_SSE4_A;
34409               break;
34410             case PROCESSOR_BTVER2:
34411               arg_str = "btver2";
34412               priority = P_PROC_AVX;
34413               break;
34414             case PROCESSOR_BDVER1:
34415               arg_str = "bdver1";
34416               priority = P_PROC_XOP;
34417               break;
34418             case PROCESSOR_BDVER2:
34419               arg_str = "bdver2";
34420               priority = P_PROC_FMA;
34421               break;
34422             case PROCESSOR_BDVER3:
34423               arg_str = "bdver3";
34424               priority = P_PROC_FMA;
34425               break;
34426             case PROCESSOR_BDVER4:
34427               arg_str = "bdver4";
34428               priority = P_PROC_AVX2;
34429               break;
34430             }  
34431         }    
34432     
34433       cl_target_option_restore (&global_options, &cur_target);
34434         
34435       if (predicate_list && arg_str == NULL)
34436         {
34437           error_at (DECL_SOURCE_LOCATION (decl),
34438                 "No dispatcher found for the versioning attributes");
34439           return 0;
34440         }
34441     
34442       if (predicate_list)
34443         {
34444           predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_IS];
34445           /* For a C string literal the length includes the trailing NULL.  */
34446           predicate_arg = build_string_literal (strlen (arg_str) + 1, arg_str);
34447           predicate_chain = tree_cons (predicate_decl, predicate_arg,
34448                                        predicate_chain);
34449         }
34450     }
34451
34452   /* Process feature name.  */
34453   tok_str =  (char *) xmalloc (strlen (attrs_str) + 1);
34454   strcpy (tok_str, attrs_str);
34455   token = strtok (tok_str, ",");
34456   predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_SUPPORTS];
34457
34458   while (token != NULL)
34459     {
34460       /* Do not process "arch="  */
34461       if (strncmp (token, "arch=", 5) == 0)
34462         {
34463           token = strtok (NULL, ",");
34464           continue;
34465         }
34466       for (i = 0; i < NUM_FEATURES; ++i)
34467         {
34468           if (strcmp (token, feature_list[i].name) == 0)
34469             {
34470               if (predicate_list)
34471                 {
34472                   predicate_arg = build_string_literal (
34473                                   strlen (feature_list[i].name) + 1,
34474                                   feature_list[i].name);
34475                   predicate_chain = tree_cons (predicate_decl, predicate_arg,
34476                                                predicate_chain);
34477                 }
34478               /* Find the maximum priority feature.  */
34479               if (feature_list[i].priority > priority)
34480                 priority = feature_list[i].priority;
34481
34482               break;
34483             }
34484         }
34485       if (predicate_list && i == NUM_FEATURES)
34486         {
34487           error_at (DECL_SOURCE_LOCATION (decl),
34488                     "No dispatcher found for %s", token);
34489           return 0;
34490         }
34491       token = strtok (NULL, ",");
34492     }
34493   free (tok_str);
34494
34495   if (predicate_list && predicate_chain == NULL_TREE)
34496     {
34497       error_at (DECL_SOURCE_LOCATION (decl),
34498                 "No dispatcher found for the versioning attributes : %s",
34499                 attrs_str);
34500       return 0;
34501     }
34502   else if (predicate_list)
34503     {
34504       predicate_chain = nreverse (predicate_chain);
34505       *predicate_list = predicate_chain;
34506     }
34507
34508   return priority; 
34509 }
34510
34511 /* This compares the priority of target features in function DECL1
34512    and DECL2.  It returns positive value if DECL1 is higher priority,
34513    negative value if DECL2 is higher priority and 0 if they are the
34514    same.  */
34515
34516 static int
34517 ix86_compare_version_priority (tree decl1, tree decl2)
34518 {
34519   unsigned int priority1 = get_builtin_code_for_version (decl1, NULL);
34520   unsigned int priority2 = get_builtin_code_for_version (decl2, NULL);
34521
34522   return (int)priority1 - (int)priority2;
34523 }
34524
34525 /* V1 and V2 point to function versions with different priorities
34526    based on the target ISA.  This function compares their priorities.  */
34527  
34528 static int
34529 feature_compare (const void *v1, const void *v2)
34530 {
34531   typedef struct _function_version_info
34532     {
34533       tree version_decl;
34534       tree predicate_chain;
34535       unsigned int dispatch_priority;
34536     } function_version_info;
34537
34538   const function_version_info c1 = *(const function_version_info *)v1;
34539   const function_version_info c2 = *(const function_version_info *)v2;
34540   return (c2.dispatch_priority - c1.dispatch_priority);
34541 }
34542
34543 /* This function generates the dispatch function for
34544    multi-versioned functions.  DISPATCH_DECL is the function which will
34545    contain the dispatch logic.  FNDECLS are the function choices for
34546    dispatch, and is a tree chain.  EMPTY_BB is the basic block pointer
34547    in DISPATCH_DECL in which the dispatch code is generated.  */
34548
34549 static int
34550 dispatch_function_versions (tree dispatch_decl,
34551                             void *fndecls_p,
34552                             basic_block *empty_bb)
34553 {
34554   tree default_decl;
34555   gimple ifunc_cpu_init_stmt;
34556   gimple_seq gseq;
34557   int ix;
34558   tree ele;
34559   vec<tree> *fndecls;
34560   unsigned int num_versions = 0;
34561   unsigned int actual_versions = 0;
34562   unsigned int i;
34563
34564   struct _function_version_info
34565     {
34566       tree version_decl;
34567       tree predicate_chain;
34568       unsigned int dispatch_priority;
34569     }*function_version_info;
34570
34571   gcc_assert (dispatch_decl != NULL
34572               && fndecls_p != NULL
34573               && empty_bb != NULL);
34574
34575   /*fndecls_p is actually a vector.  */
34576   fndecls = static_cast<vec<tree> *> (fndecls_p);
34577
34578   /* At least one more version other than the default.  */
34579   num_versions = fndecls->length ();
34580   gcc_assert (num_versions >= 2);
34581
34582   function_version_info = (struct _function_version_info *)
34583     XNEWVEC (struct _function_version_info, (num_versions - 1));
34584
34585   /* The first version in the vector is the default decl.  */
34586   default_decl = (*fndecls)[0];
34587
34588   push_cfun (DECL_STRUCT_FUNCTION (dispatch_decl));
34589
34590   gseq = bb_seq (*empty_bb);
34591   /* Function version dispatch is via IFUNC.  IFUNC resolvers fire before
34592      constructors, so explicity call __builtin_cpu_init here.  */
34593   ifunc_cpu_init_stmt = gimple_build_call_vec (
34594                      ix86_builtins [(int) IX86_BUILTIN_CPU_INIT], vNULL);
34595   gimple_seq_add_stmt (&gseq, ifunc_cpu_init_stmt);
34596   gimple_set_bb (ifunc_cpu_init_stmt, *empty_bb);
34597   set_bb_seq (*empty_bb, gseq);
34598
34599   pop_cfun ();
34600
34601
34602   for (ix = 1; fndecls->iterate (ix, &ele); ++ix)
34603     {
34604       tree version_decl = ele;
34605       tree predicate_chain = NULL_TREE;
34606       unsigned int priority;
34607       /* Get attribute string, parse it and find the right predicate decl.
34608          The predicate function could be a lengthy combination of many
34609          features, like arch-type and various isa-variants.  */
34610       priority = get_builtin_code_for_version (version_decl,
34611                                                &predicate_chain);
34612
34613       if (predicate_chain == NULL_TREE)
34614         continue;
34615
34616       function_version_info [actual_versions].version_decl = version_decl;
34617       function_version_info [actual_versions].predicate_chain
34618          = predicate_chain;
34619       function_version_info [actual_versions].dispatch_priority = priority;
34620       actual_versions++;
34621     }
34622
34623   /* Sort the versions according to descending order of dispatch priority.  The
34624      priority is based on the ISA.  This is not a perfect solution.  There
34625      could still be ambiguity.  If more than one function version is suitable
34626      to execute,  which one should be dispatched?  In future, allow the user
34627      to specify a dispatch  priority next to the version.  */
34628   qsort (function_version_info, actual_versions,
34629          sizeof (struct _function_version_info), feature_compare);
34630
34631   for  (i = 0; i < actual_versions; ++i)
34632     *empty_bb = add_condition_to_bb (dispatch_decl,
34633                                      function_version_info[i].version_decl,
34634                                      function_version_info[i].predicate_chain,
34635                                      *empty_bb);
34636
34637   /* dispatch default version at the end.  */
34638   *empty_bb = add_condition_to_bb (dispatch_decl, default_decl,
34639                                    NULL, *empty_bb);
34640
34641   free (function_version_info);
34642   return 0;
34643 }
34644
34645 /* Comparator function to be used in qsort routine to sort attribute
34646    specification strings to "target".  */
34647
34648 static int
34649 attr_strcmp (const void *v1, const void *v2)
34650 {
34651   const char *c1 = *(char *const*)v1;
34652   const char *c2 = *(char *const*)v2;
34653   return strcmp (c1, c2);
34654 }
34655
34656 /* ARGLIST is the argument to target attribute.  This function tokenizes
34657    the comma separated arguments, sorts them and returns a string which
34658    is a unique identifier for the comma separated arguments.   It also
34659    replaces non-identifier characters "=,-" with "_".  */
34660
34661 static char *
34662 sorted_attr_string (tree arglist)
34663 {
34664   tree arg;
34665   size_t str_len_sum = 0;
34666   char **args = NULL;
34667   char *attr_str, *ret_str;
34668   char *attr = NULL;
34669   unsigned int argnum = 1;
34670   unsigned int i;
34671
34672   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
34673     {
34674       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
34675       size_t len = strlen (str);
34676       str_len_sum += len + 1;
34677       if (arg != arglist)
34678         argnum++;
34679       for (i = 0; i < strlen (str); i++)
34680         if (str[i] == ',')
34681           argnum++;
34682     }
34683
34684   attr_str = XNEWVEC (char, str_len_sum);
34685   str_len_sum = 0;
34686   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
34687     {
34688       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
34689       size_t len = strlen (str);
34690       memcpy (attr_str + str_len_sum, str, len);
34691       attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0';
34692       str_len_sum += len + 1;
34693     }
34694
34695   /* Replace "=,-" with "_".  */
34696   for (i = 0; i < strlen (attr_str); i++)
34697     if (attr_str[i] == '=' || attr_str[i]== '-')
34698       attr_str[i] = '_';
34699
34700   if (argnum == 1)
34701     return attr_str;
34702
34703   args = XNEWVEC (char *, argnum);
34704
34705   i = 0;
34706   attr = strtok (attr_str, ",");
34707   while (attr != NULL)
34708     {
34709       args[i] = attr;
34710       i++;
34711       attr = strtok (NULL, ",");
34712     }
34713
34714   qsort (args, argnum, sizeof (char *), attr_strcmp);
34715
34716   ret_str = XNEWVEC (char, str_len_sum);
34717   str_len_sum = 0;
34718   for (i = 0; i < argnum; i++)
34719     {
34720       size_t len = strlen (args[i]);
34721       memcpy (ret_str + str_len_sum, args[i], len);
34722       ret_str[str_len_sum + len] = i < argnum - 1 ? '_' : '\0';
34723       str_len_sum += len + 1;
34724     }
34725
34726   XDELETEVEC (args);
34727   XDELETEVEC (attr_str);
34728   return ret_str;
34729 }
34730
34731 /* This function changes the assembler name for functions that are
34732    versions.  If DECL is a function version and has a "target"
34733    attribute, it appends the attribute string to its assembler name.  */
34734
34735 static tree
34736 ix86_mangle_function_version_assembler_name (tree decl, tree id)
34737 {
34738   tree version_attr;
34739   const char *orig_name, *version_string;
34740   char *attr_str, *assembler_name;
34741
34742   if (DECL_DECLARED_INLINE_P (decl)
34743       && lookup_attribute ("gnu_inline",
34744                            DECL_ATTRIBUTES (decl)))
34745     error_at (DECL_SOURCE_LOCATION (decl),
34746               "Function versions cannot be marked as gnu_inline,"
34747               " bodies have to be generated");
34748
34749   if (DECL_VIRTUAL_P (decl)
34750       || DECL_VINDEX (decl))
34751     sorry ("Virtual function multiversioning not supported");
34752
34753   version_attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34754
34755   /* target attribute string cannot be NULL.  */
34756   gcc_assert (version_attr != NULL_TREE);
34757
34758   orig_name = IDENTIFIER_POINTER (id);
34759   version_string
34760     = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (version_attr)));
34761
34762   if (strcmp (version_string, "default") == 0)
34763     return id;
34764
34765   attr_str = sorted_attr_string (TREE_VALUE (version_attr));
34766   assembler_name = XNEWVEC (char, strlen (orig_name) + strlen (attr_str) + 2);
34767
34768   sprintf (assembler_name, "%s.%s", orig_name, attr_str);
34769
34770   /* Allow assembler name to be modified if already set.  */
34771   if (DECL_ASSEMBLER_NAME_SET_P (decl))
34772     SET_DECL_RTL (decl, NULL);
34773
34774   tree ret = get_identifier (assembler_name);
34775   XDELETEVEC (attr_str);
34776   XDELETEVEC (assembler_name);
34777   return ret;
34778 }
34779
34780 /* This function returns true if FN1 and FN2 are versions of the same function,
34781    that is, the target strings of the function decls are different.  This assumes
34782    that FN1 and FN2 have the same signature.  */
34783
34784 static bool
34785 ix86_function_versions (tree fn1, tree fn2)
34786 {
34787   tree attr1, attr2;
34788   char *target1, *target2;
34789   bool result;
34790
34791   if (TREE_CODE (fn1) != FUNCTION_DECL
34792       || TREE_CODE (fn2) != FUNCTION_DECL)
34793     return false;
34794
34795   attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
34796   attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
34797
34798   /* At least one function decl should have the target attribute specified.  */
34799   if (attr1 == NULL_TREE && attr2 == NULL_TREE)
34800     return false;
34801
34802   /* Diagnose missing target attribute if one of the decls is already
34803      multi-versioned.  */
34804   if (attr1 == NULL_TREE || attr2 == NULL_TREE)
34805     {
34806       if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
34807         {
34808           if (attr2 != NULL_TREE)
34809             {
34810               tree tem = fn1;
34811               fn1 = fn2;
34812               fn2 = tem;
34813               attr1 = attr2;
34814             }
34815           error_at (DECL_SOURCE_LOCATION (fn2),
34816                     "missing %<target%> attribute for multi-versioned %D",
34817                     fn2);
34818           inform (DECL_SOURCE_LOCATION (fn1),
34819                   "previous declaration of %D", fn1);
34820           /* Prevent diagnosing of the same error multiple times.  */
34821           DECL_ATTRIBUTES (fn2)
34822             = tree_cons (get_identifier ("target"),
34823                          copy_node (TREE_VALUE (attr1)),
34824                          DECL_ATTRIBUTES (fn2));
34825         }
34826       return false;
34827     }
34828
34829   target1 = sorted_attr_string (TREE_VALUE (attr1));
34830   target2 = sorted_attr_string (TREE_VALUE (attr2));
34831
34832   /* The sorted target strings must be different for fn1 and fn2
34833      to be versions.  */
34834   if (strcmp (target1, target2) == 0)
34835     result = false;
34836   else
34837     result = true;
34838
34839   XDELETEVEC (target1);
34840   XDELETEVEC (target2); 
34841   
34842   return result;
34843 }
34844
34845 static tree 
34846 ix86_mangle_decl_assembler_name (tree decl, tree id)
34847 {
34848   /* For function version, add the target suffix to the assembler name.  */
34849   if (TREE_CODE (decl) == FUNCTION_DECL
34850       && DECL_FUNCTION_VERSIONED (decl))
34851     id = ix86_mangle_function_version_assembler_name (decl, id);
34852 #ifdef SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME
34853   id = SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME (decl, id);
34854 #endif
34855
34856   return id;
34857 }
34858
34859 /* Return a new name by appending SUFFIX to the DECL name.  If make_unique
34860    is true, append the full path name of the source file.  */
34861
34862 static char *
34863 make_name (tree decl, const char *suffix, bool make_unique)
34864 {
34865   char *global_var_name;
34866   int name_len;
34867   const char *name;
34868   const char *unique_name = NULL;
34869
34870   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
34871
34872   /* Get a unique name that can be used globally without any chances
34873      of collision at link time.  */
34874   if (make_unique)
34875     unique_name = IDENTIFIER_POINTER (get_file_function_name ("\0"));
34876
34877   name_len = strlen (name) + strlen (suffix) + 2;
34878
34879   if (make_unique)
34880     name_len += strlen (unique_name) + 1;
34881   global_var_name = XNEWVEC (char, name_len);
34882
34883   /* Use '.' to concatenate names as it is demangler friendly.  */
34884   if (make_unique)
34885     snprintf (global_var_name, name_len, "%s.%s.%s", name, unique_name,
34886               suffix);
34887   else
34888     snprintf (global_var_name, name_len, "%s.%s", name, suffix);
34889
34890   return global_var_name;
34891 }
34892
34893 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
34894
34895 /* Make a dispatcher declaration for the multi-versioned function DECL.
34896    Calls to DECL function will be replaced with calls to the dispatcher
34897    by the front-end.  Return the decl created.  */
34898
34899 static tree
34900 make_dispatcher_decl (const tree decl)
34901 {
34902   tree func_decl;
34903   char *func_name;
34904   tree fn_type, func_type;
34905   bool is_uniq = false;
34906
34907   if (TREE_PUBLIC (decl) == 0)
34908     is_uniq = true;
34909
34910   func_name = make_name (decl, "ifunc", is_uniq);
34911
34912   fn_type = TREE_TYPE (decl);
34913   func_type = build_function_type (TREE_TYPE (fn_type),
34914                                    TYPE_ARG_TYPES (fn_type));
34915   
34916   func_decl = build_fn_decl (func_name, func_type);
34917   XDELETEVEC (func_name);
34918   TREE_USED (func_decl) = 1;
34919   DECL_CONTEXT (func_decl) = NULL_TREE;
34920   DECL_INITIAL (func_decl) = error_mark_node;
34921   DECL_ARTIFICIAL (func_decl) = 1;
34922   /* Mark this func as external, the resolver will flip it again if
34923      it gets generated.  */
34924   DECL_EXTERNAL (func_decl) = 1;
34925   /* This will be of type IFUNCs have to be externally visible.  */
34926   TREE_PUBLIC (func_decl) = 1;
34927
34928   return func_decl;  
34929 }
34930
34931 #endif
34932
34933 /* Returns true if decl is multi-versioned and DECL is the default function,
34934    that is it is not tagged with target specific optimization.  */
34935
34936 static bool
34937 is_function_default_version (const tree decl)
34938 {
34939   if (TREE_CODE (decl) != FUNCTION_DECL
34940       || !DECL_FUNCTION_VERSIONED (decl))
34941     return false;
34942   tree attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34943   gcc_assert (attr);
34944   attr = TREE_VALUE (TREE_VALUE (attr));
34945   return (TREE_CODE (attr) == STRING_CST
34946           && strcmp (TREE_STRING_POINTER (attr), "default") == 0);
34947 }
34948
34949 /* Make a dispatcher declaration for the multi-versioned function DECL.
34950    Calls to DECL function will be replaced with calls to the dispatcher
34951    by the front-end.  Returns the decl of the dispatcher function.  */
34952
34953 static tree
34954 ix86_get_function_versions_dispatcher (void *decl)
34955 {
34956   tree fn = (tree) decl;
34957   struct cgraph_node *node = NULL;
34958   struct cgraph_node *default_node = NULL;
34959   struct cgraph_function_version_info *node_v = NULL;
34960   struct cgraph_function_version_info *first_v = NULL;
34961
34962   tree dispatch_decl = NULL;
34963
34964   struct cgraph_function_version_info *default_version_info = NULL;
34965  
34966   gcc_assert (fn != NULL && DECL_FUNCTION_VERSIONED (fn));
34967
34968   node = cgraph_node::get (fn);
34969   gcc_assert (node != NULL);
34970
34971   node_v = node->function_version ();
34972   gcc_assert (node_v != NULL);
34973  
34974   if (node_v->dispatcher_resolver != NULL)
34975     return node_v->dispatcher_resolver;
34976
34977   /* Find the default version and make it the first node.  */
34978   first_v = node_v;
34979   /* Go to the beginning of the chain.  */
34980   while (first_v->prev != NULL)
34981     first_v = first_v->prev;
34982   default_version_info = first_v;
34983   while (default_version_info != NULL)
34984     {
34985       if (is_function_default_version
34986             (default_version_info->this_node->decl))
34987         break;
34988       default_version_info = default_version_info->next;
34989     }
34990
34991   /* If there is no default node, just return NULL.  */
34992   if (default_version_info == NULL)
34993     return NULL;
34994
34995   /* Make default info the first node.  */
34996   if (first_v != default_version_info)
34997     {
34998       default_version_info->prev->next = default_version_info->next;
34999       if (default_version_info->next)
35000         default_version_info->next->prev = default_version_info->prev;
35001       first_v->prev = default_version_info;
35002       default_version_info->next = first_v;
35003       default_version_info->prev = NULL;
35004     }
35005
35006   default_node = default_version_info->this_node;
35007
35008 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
35009   if (targetm.has_ifunc_p ())
35010     {
35011       struct cgraph_function_version_info *it_v = NULL;
35012       struct cgraph_node *dispatcher_node = NULL;
35013       struct cgraph_function_version_info *dispatcher_version_info = NULL;
35014
35015       /* Right now, the dispatching is done via ifunc.  */
35016       dispatch_decl = make_dispatcher_decl (default_node->decl);
35017
35018       dispatcher_node = cgraph_node::get_create (dispatch_decl);
35019       gcc_assert (dispatcher_node != NULL);
35020       dispatcher_node->dispatcher_function = 1;
35021       dispatcher_version_info
35022         = dispatcher_node->insert_new_function_version ();
35023       dispatcher_version_info->next = default_version_info;
35024       dispatcher_node->definition = 1;
35025
35026       /* Set the dispatcher for all the versions.  */
35027       it_v = default_version_info;
35028       while (it_v != NULL)
35029         {
35030           it_v->dispatcher_resolver = dispatch_decl;
35031           it_v = it_v->next;
35032         }
35033     }
35034   else
35035 #endif
35036     {
35037       error_at (DECL_SOURCE_LOCATION (default_node->decl),
35038                 "multiversioning needs ifunc which is not supported "
35039                 "on this target");
35040     }
35041
35042   return dispatch_decl;
35043 }
35044
35045 /* Makes a function attribute of the form NAME(ARG_NAME) and chains
35046    it to CHAIN.  */
35047
35048 static tree
35049 make_attribute (const char *name, const char *arg_name, tree chain)
35050 {
35051   tree attr_name;
35052   tree attr_arg_name;
35053   tree attr_args;
35054   tree attr;
35055
35056   attr_name = get_identifier (name);
35057   attr_arg_name = build_string (strlen (arg_name), arg_name);
35058   attr_args = tree_cons (NULL_TREE, attr_arg_name, NULL_TREE);
35059   attr = tree_cons (attr_name, attr_args, chain);
35060   return attr;
35061 }
35062
35063 /* Make the resolver function decl to dispatch the versions of
35064    a multi-versioned function,  DEFAULT_DECL.  Create an
35065    empty basic block in the resolver and store the pointer in
35066    EMPTY_BB.  Return the decl of the resolver function.  */
35067
35068 static tree
35069 make_resolver_func (const tree default_decl,
35070                     const tree dispatch_decl,
35071                     basic_block *empty_bb)
35072 {
35073   char *resolver_name;
35074   tree decl, type, decl_name, t;
35075   bool is_uniq = false;
35076
35077   /* IFUNC's have to be globally visible.  So, if the default_decl is
35078      not, then the name of the IFUNC should be made unique.  */
35079   if (TREE_PUBLIC (default_decl) == 0)
35080     is_uniq = true;
35081
35082   /* Append the filename to the resolver function if the versions are
35083      not externally visible.  This is because the resolver function has
35084      to be externally visible for the loader to find it.  So, appending
35085      the filename will prevent conflicts with a resolver function from
35086      another module which is based on the same version name.  */
35087   resolver_name = make_name (default_decl, "resolver", is_uniq);
35088
35089   /* The resolver function should return a (void *). */
35090   type = build_function_type_list (ptr_type_node, NULL_TREE);
35091
35092   decl = build_fn_decl (resolver_name, type);
35093   decl_name = get_identifier (resolver_name);
35094   SET_DECL_ASSEMBLER_NAME (decl, decl_name);
35095
35096   DECL_NAME (decl) = decl_name;
35097   TREE_USED (decl) = 1;
35098   DECL_ARTIFICIAL (decl) = 1;
35099   DECL_IGNORED_P (decl) = 0;
35100   /* IFUNC resolvers have to be externally visible.  */
35101   TREE_PUBLIC (decl) = 1;
35102   DECL_UNINLINABLE (decl) = 1;
35103
35104   /* Resolver is not external, body is generated.  */
35105   DECL_EXTERNAL (decl) = 0;
35106   DECL_EXTERNAL (dispatch_decl) = 0;
35107
35108   DECL_CONTEXT (decl) = NULL_TREE;
35109   DECL_INITIAL (decl) = make_node (BLOCK);
35110   DECL_STATIC_CONSTRUCTOR (decl) = 0;
35111
35112   if (DECL_COMDAT_GROUP (default_decl)
35113       || TREE_PUBLIC (default_decl))
35114     {
35115       /* In this case, each translation unit with a call to this
35116          versioned function will put out a resolver.  Ensure it
35117          is comdat to keep just one copy.  */
35118       DECL_COMDAT (decl) = 1;
35119       make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
35120     }
35121   /* Build result decl and add to function_decl. */
35122   t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node);
35123   DECL_ARTIFICIAL (t) = 1;
35124   DECL_IGNORED_P (t) = 1;
35125   DECL_RESULT (decl) = t;
35126
35127   gimplify_function_tree (decl);
35128   push_cfun (DECL_STRUCT_FUNCTION (decl));
35129   *empty_bb = init_lowered_empty_function (decl, false);
35130
35131   cgraph_node::add_new_function (decl, true);
35132   symtab->call_cgraph_insertion_hooks (cgraph_node::get_create (decl));
35133
35134   pop_cfun ();
35135
35136   gcc_assert (dispatch_decl != NULL);
35137   /* Mark dispatch_decl as "ifunc" with resolver as resolver_name.  */
35138   DECL_ATTRIBUTES (dispatch_decl) 
35139     = make_attribute ("ifunc", resolver_name, DECL_ATTRIBUTES (dispatch_decl));
35140
35141   /* Create the alias for dispatch to resolver here.  */
35142   /*cgraph_create_function_alias (dispatch_decl, decl);*/
35143   cgraph_node::create_same_body_alias (dispatch_decl, decl);
35144   XDELETEVEC (resolver_name);
35145   return decl;
35146 }
35147
35148 /* Generate the dispatching code body to dispatch multi-versioned function
35149    DECL.  The target hook is called to process the "target" attributes and
35150    provide the code to dispatch the right function at run-time.  NODE points
35151    to the dispatcher decl whose body will be created.  */
35152
35153 static tree 
35154 ix86_generate_version_dispatcher_body (void *node_p)
35155 {
35156   tree resolver_decl;
35157   basic_block empty_bb;
35158   tree default_ver_decl;
35159   struct cgraph_node *versn;
35160   struct cgraph_node *node;
35161
35162   struct cgraph_function_version_info *node_version_info = NULL;
35163   struct cgraph_function_version_info *versn_info = NULL;
35164
35165   node = (cgraph_node *)node_p;
35166
35167   node_version_info = node->function_version ();
35168   gcc_assert (node->dispatcher_function
35169               && node_version_info != NULL);
35170
35171   if (node_version_info->dispatcher_resolver)
35172     return node_version_info->dispatcher_resolver;
35173
35174   /* The first version in the chain corresponds to the default version.  */
35175   default_ver_decl = node_version_info->next->this_node->decl;
35176
35177   /* node is going to be an alias, so remove the finalized bit.  */
35178   node->definition = false;
35179
35180   resolver_decl = make_resolver_func (default_ver_decl,
35181                                       node->decl, &empty_bb);
35182
35183   node_version_info->dispatcher_resolver = resolver_decl;
35184
35185   push_cfun (DECL_STRUCT_FUNCTION (resolver_decl));
35186
35187   auto_vec<tree, 2> fn_ver_vec;
35188
35189   for (versn_info = node_version_info->next; versn_info;
35190        versn_info = versn_info->next)
35191     {
35192       versn = versn_info->this_node;
35193       /* Check for virtual functions here again, as by this time it should
35194          have been determined if this function needs a vtable index or
35195          not.  This happens for methods in derived classes that override
35196          virtual methods in base classes but are not explicitly marked as
35197          virtual.  */
35198       if (DECL_VINDEX (versn->decl))
35199         sorry ("Virtual function multiversioning not supported");
35200
35201       fn_ver_vec.safe_push (versn->decl);
35202     }
35203
35204   dispatch_function_versions (resolver_decl, &fn_ver_vec, &empty_bb);
35205   cgraph_edge::rebuild_edges ();
35206   pop_cfun ();
35207   return resolver_decl;
35208 }
35209 /* This builds the processor_model struct type defined in
35210    libgcc/config/i386/cpuinfo.c  */
35211
35212 static tree
35213 build_processor_model_struct (void)
35214 {
35215   const char *field_name[] = {"__cpu_vendor", "__cpu_type", "__cpu_subtype",
35216                               "__cpu_features"};
35217   tree field = NULL_TREE, field_chain = NULL_TREE;
35218   int i;
35219   tree type = make_node (RECORD_TYPE);
35220
35221   /* The first 3 fields are unsigned int.  */
35222   for (i = 0; i < 3; ++i)
35223     {
35224       field = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
35225                           get_identifier (field_name[i]), unsigned_type_node);
35226       if (field_chain != NULL_TREE)
35227         DECL_CHAIN (field) = field_chain;
35228       field_chain = field;
35229     }
35230
35231   /* The last field is an array of unsigned integers of size one.  */
35232   field = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
35233                       get_identifier (field_name[3]),
35234                       build_array_type (unsigned_type_node,
35235                                         build_index_type (size_one_node)));
35236   if (field_chain != NULL_TREE)
35237     DECL_CHAIN (field) = field_chain;
35238   field_chain = field;
35239
35240   finish_builtin_struct (type, "__processor_model", field_chain, NULL_TREE);
35241   return type;
35242 }
35243
35244 /* Returns a extern, comdat VAR_DECL of type TYPE and name NAME. */
35245
35246 static tree
35247 make_var_decl (tree type, const char *name)
35248 {
35249   tree new_decl;
35250
35251   new_decl = build_decl (UNKNOWN_LOCATION,
35252                          VAR_DECL,
35253                          get_identifier(name),
35254                          type);
35255
35256   DECL_EXTERNAL (new_decl) = 1;
35257   TREE_STATIC (new_decl) = 1;
35258   TREE_PUBLIC (new_decl) = 1;
35259   DECL_INITIAL (new_decl) = 0;
35260   DECL_ARTIFICIAL (new_decl) = 0;
35261   DECL_PRESERVE_P (new_decl) = 1;
35262
35263   make_decl_one_only (new_decl, DECL_ASSEMBLER_NAME (new_decl));
35264   assemble_variable (new_decl, 0, 0, 0);
35265
35266   return new_decl;
35267 }
35268
35269 /* FNDECL is a __builtin_cpu_is or a __builtin_cpu_supports call that is folded
35270    into an integer defined in libgcc/config/i386/cpuinfo.c */
35271
35272 static tree
35273 fold_builtin_cpu (tree fndecl, tree *args)
35274 {
35275   unsigned int i;
35276   enum ix86_builtins fn_code = (enum ix86_builtins)
35277                                 DECL_FUNCTION_CODE (fndecl);
35278   tree param_string_cst = NULL;
35279
35280   /* This is the order of bit-fields in __processor_features in cpuinfo.c */
35281   enum processor_features
35282   {
35283     F_CMOV = 0,
35284     F_MMX,
35285     F_POPCNT,
35286     F_SSE,
35287     F_SSE2,
35288     F_SSE3,
35289     F_SSSE3,
35290     F_SSE4_1,
35291     F_SSE4_2,
35292     F_AVX,
35293     F_AVX2,
35294     F_SSE4_A,
35295     F_FMA4,
35296     F_XOP,
35297     F_FMA,
35298     F_AVX512F,
35299     F_MAX
35300   };
35301
35302   /* These are the values for vendor types and cpu types  and subtypes
35303      in cpuinfo.c.  Cpu types and subtypes should be subtracted by
35304      the corresponding start value.  */
35305   enum processor_model
35306   {
35307     M_INTEL = 1,
35308     M_AMD,
35309     M_CPU_TYPE_START,
35310     M_INTEL_BONNELL,
35311     M_INTEL_CORE2,
35312     M_INTEL_COREI7,
35313     M_AMDFAM10H,
35314     M_AMDFAM15H,
35315     M_INTEL_SILVERMONT,
35316     M_INTEL_KNL,
35317     M_AMD_BTVER1,
35318     M_AMD_BTVER2,    
35319     M_CPU_SUBTYPE_START,
35320     M_INTEL_COREI7_NEHALEM,
35321     M_INTEL_COREI7_WESTMERE,
35322     M_INTEL_COREI7_SANDYBRIDGE,
35323     M_AMDFAM10H_BARCELONA,
35324     M_AMDFAM10H_SHANGHAI,
35325     M_AMDFAM10H_ISTANBUL,
35326     M_AMDFAM15H_BDVER1,
35327     M_AMDFAM15H_BDVER2,
35328     M_AMDFAM15H_BDVER3,
35329     M_AMDFAM15H_BDVER4,
35330     M_INTEL_COREI7_IVYBRIDGE,
35331     M_INTEL_COREI7_HASWELL
35332   };
35333
35334   static struct _arch_names_table
35335     {
35336       const char *const name;
35337       const enum processor_model model;
35338     }
35339   const arch_names_table[] =
35340     {
35341       {"amd", M_AMD},
35342       {"intel", M_INTEL},
35343       {"atom", M_INTEL_BONNELL},
35344       {"slm", M_INTEL_SILVERMONT},
35345       {"core2", M_INTEL_CORE2},
35346       {"corei7", M_INTEL_COREI7},
35347       {"nehalem", M_INTEL_COREI7_NEHALEM},
35348       {"westmere", M_INTEL_COREI7_WESTMERE},
35349       {"sandybridge", M_INTEL_COREI7_SANDYBRIDGE},
35350       {"ivybridge", M_INTEL_COREI7_IVYBRIDGE},
35351       {"haswell", M_INTEL_COREI7_HASWELL},
35352       {"bonnell", M_INTEL_BONNELL},
35353       {"silvermont", M_INTEL_SILVERMONT},
35354       {"knl", M_INTEL_KNL},
35355       {"amdfam10h", M_AMDFAM10H},
35356       {"barcelona", M_AMDFAM10H_BARCELONA},
35357       {"shanghai", M_AMDFAM10H_SHANGHAI},
35358       {"istanbul", M_AMDFAM10H_ISTANBUL},
35359       {"btver1", M_AMD_BTVER1},      
35360       {"amdfam15h", M_AMDFAM15H},
35361       {"bdver1", M_AMDFAM15H_BDVER1},
35362       {"bdver2", M_AMDFAM15H_BDVER2},
35363       {"bdver3", M_AMDFAM15H_BDVER3},
35364       {"bdver4", M_AMDFAM15H_BDVER4},
35365       {"btver2", M_AMD_BTVER2},      
35366     };
35367
35368   static struct _isa_names_table
35369     {
35370       const char *const name;
35371       const enum processor_features feature;
35372     }
35373   const isa_names_table[] =
35374     {
35375       {"cmov",   F_CMOV},
35376       {"mmx",    F_MMX},
35377       {"popcnt", F_POPCNT},
35378       {"sse",    F_SSE},
35379       {"sse2",   F_SSE2},
35380       {"sse3",   F_SSE3},
35381       {"ssse3",  F_SSSE3},
35382       {"sse4a",  F_SSE4_A},
35383       {"sse4.1", F_SSE4_1},
35384       {"sse4.2", F_SSE4_2},
35385       {"avx",    F_AVX},
35386       {"fma4",   F_FMA4},
35387       {"xop",    F_XOP},
35388       {"fma",    F_FMA},
35389       {"avx2",   F_AVX2},
35390       {"avx512f",F_AVX512F}
35391     };
35392
35393   tree __processor_model_type = build_processor_model_struct ();
35394   tree __cpu_model_var = make_var_decl (__processor_model_type,
35395                                         "__cpu_model");
35396
35397
35398   varpool_node::add (__cpu_model_var);
35399
35400   gcc_assert ((args != NULL) && (*args != NULL));
35401
35402   param_string_cst = *args;
35403   while (param_string_cst
35404          && TREE_CODE (param_string_cst) !=  STRING_CST)
35405     {
35406       /* *args must be a expr that can contain other EXPRS leading to a
35407          STRING_CST.   */
35408       if (!EXPR_P (param_string_cst))
35409         {
35410           error ("Parameter to builtin must be a string constant or literal");
35411           return integer_zero_node;
35412         }
35413       param_string_cst = TREE_OPERAND (EXPR_CHECK (param_string_cst), 0);
35414     }
35415
35416   gcc_assert (param_string_cst);
35417
35418   if (fn_code == IX86_BUILTIN_CPU_IS)
35419     {
35420       tree ref;
35421       tree field;
35422       tree final;
35423
35424       unsigned int field_val = 0;
35425       unsigned int NUM_ARCH_NAMES
35426         = sizeof (arch_names_table) / sizeof (struct _arch_names_table);
35427
35428       for (i = 0; i < NUM_ARCH_NAMES; i++)
35429         if (strcmp (arch_names_table[i].name,
35430             TREE_STRING_POINTER (param_string_cst)) == 0)
35431           break;
35432
35433       if (i == NUM_ARCH_NAMES)
35434         {
35435           error ("Parameter to builtin not valid: %s",
35436                  TREE_STRING_POINTER (param_string_cst));
35437           return integer_zero_node;
35438         }
35439
35440       field = TYPE_FIELDS (__processor_model_type);
35441       field_val = arch_names_table[i].model;
35442
35443       /* CPU types are stored in the next field.  */
35444       if (field_val > M_CPU_TYPE_START
35445           && field_val < M_CPU_SUBTYPE_START)
35446         {
35447           field = DECL_CHAIN (field);
35448           field_val -= M_CPU_TYPE_START;
35449         }
35450
35451       /* CPU subtypes are stored in the next field.  */
35452       if (field_val > M_CPU_SUBTYPE_START)
35453         {
35454           field = DECL_CHAIN ( DECL_CHAIN (field));
35455           field_val -= M_CPU_SUBTYPE_START;
35456         }
35457
35458       /* Get the appropriate field in __cpu_model.  */
35459       ref =  build3 (COMPONENT_REF, TREE_TYPE (field), __cpu_model_var,
35460                      field, NULL_TREE);
35461
35462       /* Check the value.  */
35463       final = build2 (EQ_EXPR, unsigned_type_node, ref,
35464                       build_int_cstu (unsigned_type_node, field_val));
35465       return build1 (CONVERT_EXPR, integer_type_node, final);
35466     }
35467   else if (fn_code == IX86_BUILTIN_CPU_SUPPORTS)
35468     {
35469       tree ref;
35470       tree array_elt;
35471       tree field;
35472       tree final;
35473
35474       unsigned int field_val = 0;
35475       unsigned int NUM_ISA_NAMES
35476         = sizeof (isa_names_table) / sizeof (struct _isa_names_table);
35477
35478       for (i = 0; i < NUM_ISA_NAMES; i++)
35479         if (strcmp (isa_names_table[i].name,
35480             TREE_STRING_POINTER (param_string_cst)) == 0)
35481           break;
35482
35483       if (i == NUM_ISA_NAMES)
35484         {
35485           error ("Parameter to builtin not valid: %s",
35486                  TREE_STRING_POINTER (param_string_cst));
35487           return integer_zero_node;
35488         }
35489
35490       field = TYPE_FIELDS (__processor_model_type);
35491       /* Get the last field, which is __cpu_features.  */
35492       while (DECL_CHAIN (field))
35493         field = DECL_CHAIN (field);
35494
35495       /* Get the appropriate field: __cpu_model.__cpu_features  */
35496       ref =  build3 (COMPONENT_REF, TREE_TYPE (field), __cpu_model_var,
35497                      field, NULL_TREE);
35498
35499       /* Access the 0th element of __cpu_features array.  */
35500       array_elt = build4 (ARRAY_REF, unsigned_type_node, ref,
35501                           integer_zero_node, NULL_TREE, NULL_TREE);
35502
35503       field_val = (1 << isa_names_table[i].feature);
35504       /* Return __cpu_model.__cpu_features[0] & field_val  */
35505       final = build2 (BIT_AND_EXPR, unsigned_type_node, array_elt,
35506                       build_int_cstu (unsigned_type_node, field_val));
35507       return build1 (CONVERT_EXPR, integer_type_node, final);
35508     }
35509   gcc_unreachable ();
35510 }
35511
35512 static tree
35513 ix86_fold_builtin (tree fndecl, int n_args,
35514                    tree *args, bool ignore ATTRIBUTE_UNUSED)
35515 {
35516   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
35517     {
35518       enum ix86_builtins fn_code = (enum ix86_builtins)
35519                                    DECL_FUNCTION_CODE (fndecl);
35520       if (fn_code ==  IX86_BUILTIN_CPU_IS
35521           || fn_code == IX86_BUILTIN_CPU_SUPPORTS)
35522         {
35523           gcc_assert (n_args == 1);
35524           return fold_builtin_cpu (fndecl, args);
35525         }
35526     }
35527
35528 #ifdef SUBTARGET_FOLD_BUILTIN
35529   return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore);
35530 #endif
35531
35532   return NULL_TREE;
35533 }
35534
35535 /* Make builtins to detect cpu type and features supported.  NAME is
35536    the builtin name, CODE is the builtin code, and FTYPE is the function
35537    type of the builtin.  */
35538
35539 static void
35540 make_cpu_type_builtin (const char* name, int code,
35541                        enum ix86_builtin_func_type ftype, bool is_const)
35542 {
35543   tree decl;
35544   tree type;
35545
35546   type = ix86_get_builtin_func_type (ftype);
35547   decl = add_builtin_function (name, type, code, BUILT_IN_MD,
35548                                NULL, NULL_TREE);
35549   gcc_assert (decl != NULL_TREE);
35550   ix86_builtins[(int) code] = decl;
35551   TREE_READONLY (decl) = is_const;
35552 }
35553
35554 /* Make builtins to get CPU type and features supported.  The created
35555    builtins are :
35556
35557    __builtin_cpu_init (), to detect cpu type and features,
35558    __builtin_cpu_is ("<CPUNAME>"), to check if cpu is of type <CPUNAME>,
35559    __builtin_cpu_supports ("<FEATURE>"), to check if cpu supports <FEATURE>
35560    */
35561
35562 static void
35563 ix86_init_platform_type_builtins (void)
35564 {
35565   make_cpu_type_builtin ("__builtin_cpu_init", IX86_BUILTIN_CPU_INIT,
35566                          INT_FTYPE_VOID, false);
35567   make_cpu_type_builtin ("__builtin_cpu_is", IX86_BUILTIN_CPU_IS,
35568                          INT_FTYPE_PCCHAR, true);
35569   make_cpu_type_builtin ("__builtin_cpu_supports", IX86_BUILTIN_CPU_SUPPORTS,
35570                          INT_FTYPE_PCCHAR, true);
35571 }
35572
35573 /* Internal method for ix86_init_builtins.  */
35574
35575 static void
35576 ix86_init_builtins_va_builtins_abi (void)
35577 {
35578   tree ms_va_ref, sysv_va_ref;
35579   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
35580   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
35581   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
35582   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
35583
35584   if (!TARGET_64BIT)
35585     return;
35586   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
35587   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
35588   ms_va_ref = build_reference_type (ms_va_list_type_node);
35589   sysv_va_ref =
35590     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
35591
35592   fnvoid_va_end_ms =
35593     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
35594   fnvoid_va_start_ms =
35595     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
35596   fnvoid_va_end_sysv =
35597     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
35598   fnvoid_va_start_sysv =
35599     build_varargs_function_type_list (void_type_node, sysv_va_ref,
35600                                        NULL_TREE);
35601   fnvoid_va_copy_ms =
35602     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
35603                               NULL_TREE);
35604   fnvoid_va_copy_sysv =
35605     build_function_type_list (void_type_node, sysv_va_ref,
35606                               sysv_va_ref, NULL_TREE);
35607
35608   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
35609                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
35610   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
35611                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
35612   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
35613                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
35614   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
35615                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35616   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
35617                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35618   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
35619                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35620 }
35621
35622 static void
35623 ix86_init_builtin_types (void)
35624 {
35625   tree float128_type_node, float80_type_node;
35626
35627   /* The __float80 type.  */
35628   float80_type_node = long_double_type_node;
35629   if (TYPE_MODE (float80_type_node) != XFmode)
35630     {
35631       /* The __float80 type.  */
35632       float80_type_node = make_node (REAL_TYPE);
35633
35634       TYPE_PRECISION (float80_type_node) = 80;
35635       layout_type (float80_type_node);
35636     }
35637   lang_hooks.types.register_builtin_type (float80_type_node, "__float80");
35638
35639   /* The __float128 type.  */
35640   float128_type_node = make_node (REAL_TYPE);
35641   TYPE_PRECISION (float128_type_node) = 128;
35642   layout_type (float128_type_node);
35643   lang_hooks.types.register_builtin_type (float128_type_node, "__float128");
35644
35645   /* This macro is built by i386-builtin-types.awk.  */
35646   DEFINE_BUILTIN_PRIMITIVE_TYPES;
35647 }
35648
35649 static void
35650 ix86_init_builtins (void)
35651 {
35652   tree t;
35653
35654   ix86_init_builtin_types ();
35655
35656   /* Builtins to get CPU type and features. */
35657   ix86_init_platform_type_builtins ();
35658
35659   /* TFmode support builtins.  */
35660   def_builtin_const (0, "__builtin_infq",
35661                      FLOAT128_FTYPE_VOID, IX86_BUILTIN_INFQ);
35662   def_builtin_const (0, "__builtin_huge_valq",
35663                      FLOAT128_FTYPE_VOID, IX86_BUILTIN_HUGE_VALQ);
35664
35665   /* We will expand them to normal call if SSE isn't available since
35666      they are used by libgcc. */
35667   t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128);
35668   t = add_builtin_function ("__builtin_fabsq", t, IX86_BUILTIN_FABSQ,
35669                             BUILT_IN_MD, "__fabstf2", NULL_TREE);
35670   TREE_READONLY (t) = 1;
35671   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = t;
35672
35673   t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128_FLOAT128);
35674   t = add_builtin_function ("__builtin_copysignq", t, IX86_BUILTIN_COPYSIGNQ,
35675                             BUILT_IN_MD, "__copysigntf3", NULL_TREE);
35676   TREE_READONLY (t) = 1;
35677   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = t;
35678
35679   ix86_init_tm_builtins ();
35680   ix86_init_mmx_sse_builtins ();
35681   ix86_init_mpx_builtins ();
35682
35683   if (TARGET_LP64)
35684     ix86_init_builtins_va_builtins_abi ();
35685
35686 #ifdef SUBTARGET_INIT_BUILTINS
35687   SUBTARGET_INIT_BUILTINS;
35688 #endif
35689 }
35690
35691 /* Return the ix86 builtin for CODE.  */
35692
35693 static tree
35694 ix86_builtin_decl (unsigned code, bool)
35695 {
35696   if (code >= IX86_BUILTIN_MAX)
35697     return error_mark_node;
35698
35699   return ix86_builtins[code];
35700 }
35701
35702 /* Errors in the source file can cause expand_expr to return const0_rtx
35703    where we expect a vector.  To avoid crashing, use one of the vector
35704    clear instructions.  */
35705 static rtx
35706 safe_vector_operand (rtx x, machine_mode mode)
35707 {
35708   if (x == const0_rtx)
35709     x = CONST0_RTX (mode);
35710   return x;
35711 }
35712
35713 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
35714
35715 static rtx
35716 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
35717 {
35718   rtx pat;
35719   tree arg0 = CALL_EXPR_ARG (exp, 0);
35720   tree arg1 = CALL_EXPR_ARG (exp, 1);
35721   rtx op0 = expand_normal (arg0);
35722   rtx op1 = expand_normal (arg1);
35723   machine_mode tmode = insn_data[icode].operand[0].mode;
35724   machine_mode mode0 = insn_data[icode].operand[1].mode;
35725   machine_mode mode1 = insn_data[icode].operand[2].mode;
35726
35727   if (VECTOR_MODE_P (mode0))
35728     op0 = safe_vector_operand (op0, mode0);
35729   if (VECTOR_MODE_P (mode1))
35730     op1 = safe_vector_operand (op1, mode1);
35731
35732   if (optimize || !target
35733       || GET_MODE (target) != tmode
35734       || !insn_data[icode].operand[0].predicate (target, tmode))
35735     target = gen_reg_rtx (tmode);
35736
35737   if (GET_MODE (op1) == SImode && mode1 == TImode)
35738     {
35739       rtx x = gen_reg_rtx (V4SImode);
35740       emit_insn (gen_sse2_loadd (x, op1));
35741       op1 = gen_lowpart (TImode, x);
35742     }
35743
35744   if (!insn_data[icode].operand[1].predicate (op0, mode0))
35745     op0 = copy_to_mode_reg (mode0, op0);
35746   if (!insn_data[icode].operand[2].predicate (op1, mode1))
35747     op1 = copy_to_mode_reg (mode1, op1);
35748
35749   pat = GEN_FCN (icode) (target, op0, op1);
35750   if (! pat)
35751     return 0;
35752
35753   emit_insn (pat);
35754
35755   return target;
35756 }
35757
35758 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
35759
35760 static rtx
35761 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
35762                                enum ix86_builtin_func_type m_type,
35763                                enum rtx_code sub_code)
35764 {
35765   rtx pat;
35766   int i;
35767   int nargs;
35768   bool comparison_p = false;
35769   bool tf_p = false;
35770   bool last_arg_constant = false;
35771   int num_memory = 0;
35772   struct {
35773     rtx op;
35774     machine_mode mode;
35775   } args[4];
35776
35777   machine_mode tmode = insn_data[icode].operand[0].mode;
35778
35779   switch (m_type)
35780     {
35781     case MULTI_ARG_4_DF2_DI_I:
35782     case MULTI_ARG_4_DF2_DI_I1:
35783     case MULTI_ARG_4_SF2_SI_I:
35784     case MULTI_ARG_4_SF2_SI_I1:
35785       nargs = 4;
35786       last_arg_constant = true;
35787       break;
35788
35789     case MULTI_ARG_3_SF:
35790     case MULTI_ARG_3_DF:
35791     case MULTI_ARG_3_SF2:
35792     case MULTI_ARG_3_DF2:
35793     case MULTI_ARG_3_DI:
35794     case MULTI_ARG_3_SI:
35795     case MULTI_ARG_3_SI_DI:
35796     case MULTI_ARG_3_HI:
35797     case MULTI_ARG_3_HI_SI:
35798     case MULTI_ARG_3_QI:
35799     case MULTI_ARG_3_DI2:
35800     case MULTI_ARG_3_SI2:
35801     case MULTI_ARG_3_HI2:
35802     case MULTI_ARG_3_QI2:
35803       nargs = 3;
35804       break;
35805
35806     case MULTI_ARG_2_SF:
35807     case MULTI_ARG_2_DF:
35808     case MULTI_ARG_2_DI:
35809     case MULTI_ARG_2_SI:
35810     case MULTI_ARG_2_HI:
35811     case MULTI_ARG_2_QI:
35812       nargs = 2;
35813       break;
35814
35815     case MULTI_ARG_2_DI_IMM:
35816     case MULTI_ARG_2_SI_IMM:
35817     case MULTI_ARG_2_HI_IMM:
35818     case MULTI_ARG_2_QI_IMM:
35819       nargs = 2;
35820       last_arg_constant = true;
35821       break;
35822
35823     case MULTI_ARG_1_SF:
35824     case MULTI_ARG_1_DF:
35825     case MULTI_ARG_1_SF2:
35826     case MULTI_ARG_1_DF2:
35827     case MULTI_ARG_1_DI:
35828     case MULTI_ARG_1_SI:
35829     case MULTI_ARG_1_HI:
35830     case MULTI_ARG_1_QI:
35831     case MULTI_ARG_1_SI_DI:
35832     case MULTI_ARG_1_HI_DI:
35833     case MULTI_ARG_1_HI_SI:
35834     case MULTI_ARG_1_QI_DI:
35835     case MULTI_ARG_1_QI_SI:
35836     case MULTI_ARG_1_QI_HI:
35837       nargs = 1;
35838       break;
35839
35840     case MULTI_ARG_2_DI_CMP:
35841     case MULTI_ARG_2_SI_CMP:
35842     case MULTI_ARG_2_HI_CMP:
35843     case MULTI_ARG_2_QI_CMP:
35844       nargs = 2;
35845       comparison_p = true;
35846       break;
35847
35848     case MULTI_ARG_2_SF_TF:
35849     case MULTI_ARG_2_DF_TF:
35850     case MULTI_ARG_2_DI_TF:
35851     case MULTI_ARG_2_SI_TF:
35852     case MULTI_ARG_2_HI_TF:
35853     case MULTI_ARG_2_QI_TF:
35854       nargs = 2;
35855       tf_p = true;
35856       break;
35857
35858     default:
35859       gcc_unreachable ();
35860     }
35861
35862   if (optimize || !target
35863       || GET_MODE (target) != tmode
35864       || !insn_data[icode].operand[0].predicate (target, tmode))
35865     target = gen_reg_rtx (tmode);
35866
35867   gcc_assert (nargs <= 4);
35868
35869   for (i = 0; i < nargs; i++)
35870     {
35871       tree arg = CALL_EXPR_ARG (exp, i);
35872       rtx op = expand_normal (arg);
35873       int adjust = (comparison_p) ? 1 : 0;
35874       machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
35875
35876       if (last_arg_constant && i == nargs - 1)
35877         {
35878           if (!insn_data[icode].operand[i + 1].predicate (op, mode))
35879             {
35880               enum insn_code new_icode = icode;
35881               switch (icode)
35882                 {
35883                 case CODE_FOR_xop_vpermil2v2df3:
35884                 case CODE_FOR_xop_vpermil2v4sf3:
35885                 case CODE_FOR_xop_vpermil2v4df3:
35886                 case CODE_FOR_xop_vpermil2v8sf3:
35887                   error ("the last argument must be a 2-bit immediate");
35888                   return gen_reg_rtx (tmode);
35889                 case CODE_FOR_xop_rotlv2di3:
35890                   new_icode = CODE_FOR_rotlv2di3;
35891                   goto xop_rotl;
35892                 case CODE_FOR_xop_rotlv4si3:
35893                   new_icode = CODE_FOR_rotlv4si3;
35894                   goto xop_rotl;
35895                 case CODE_FOR_xop_rotlv8hi3:
35896                   new_icode = CODE_FOR_rotlv8hi3;
35897                   goto xop_rotl;
35898                 case CODE_FOR_xop_rotlv16qi3:
35899                   new_icode = CODE_FOR_rotlv16qi3;
35900                 xop_rotl:
35901                   if (CONST_INT_P (op))
35902                     {
35903                       int mask = GET_MODE_BITSIZE (GET_MODE_INNER (tmode)) - 1;
35904                       op = GEN_INT (INTVAL (op) & mask);
35905                       gcc_checking_assert
35906                         (insn_data[icode].operand[i + 1].predicate (op, mode));
35907                     }
35908                   else
35909                     {
35910                       gcc_checking_assert
35911                         (nargs == 2
35912                          && insn_data[new_icode].operand[0].mode == tmode
35913                          && insn_data[new_icode].operand[1].mode == tmode
35914                          && insn_data[new_icode].operand[2].mode == mode
35915                          && insn_data[new_icode].operand[0].predicate
35916                             == insn_data[icode].operand[0].predicate
35917                          && insn_data[new_icode].operand[1].predicate
35918                             == insn_data[icode].operand[1].predicate);
35919                       icode = new_icode;
35920                       goto non_constant;
35921                     }
35922                   break;
35923                 default:
35924                   gcc_unreachable ();
35925                 }
35926             }
35927         }
35928       else
35929         {
35930         non_constant:
35931           if (VECTOR_MODE_P (mode))
35932             op = safe_vector_operand (op, mode);
35933
35934           /* If we aren't optimizing, only allow one memory operand to be
35935              generated.  */
35936           if (memory_operand (op, mode))
35937             num_memory++;
35938
35939           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
35940
35941           if (optimize
35942               || !insn_data[icode].operand[i+adjust+1].predicate (op, mode)
35943               || num_memory > 1)
35944             op = force_reg (mode, op);
35945         }
35946
35947       args[i].op = op;
35948       args[i].mode = mode;
35949     }
35950
35951   switch (nargs)
35952     {
35953     case 1:
35954       pat = GEN_FCN (icode) (target, args[0].op);
35955       break;
35956
35957     case 2:
35958       if (tf_p)
35959         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
35960                                GEN_INT ((int)sub_code));
35961       else if (! comparison_p)
35962         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
35963       else
35964         {
35965           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
35966                                        args[0].op,
35967                                        args[1].op);
35968
35969           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
35970         }
35971       break;
35972
35973     case 3:
35974       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
35975       break;
35976
35977     case 4:
35978       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op, args[3].op);
35979       break;
35980
35981     default:
35982       gcc_unreachable ();
35983     }
35984
35985   if (! pat)
35986     return 0;
35987
35988   emit_insn (pat);
35989   return target;
35990 }
35991
35992 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
35993    insns with vec_merge.  */
35994
35995 static rtx
35996 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
35997                                     rtx target)
35998 {
35999   rtx pat;
36000   tree arg0 = CALL_EXPR_ARG (exp, 0);
36001   rtx op1, op0 = expand_normal (arg0);
36002   machine_mode tmode = insn_data[icode].operand[0].mode;
36003   machine_mode mode0 = insn_data[icode].operand[1].mode;
36004
36005   if (optimize || !target
36006       || GET_MODE (target) != tmode
36007       || !insn_data[icode].operand[0].predicate (target, tmode))
36008     target = gen_reg_rtx (tmode);
36009
36010   if (VECTOR_MODE_P (mode0))
36011     op0 = safe_vector_operand (op0, mode0);
36012
36013   if ((optimize && !register_operand (op0, mode0))
36014       || !insn_data[icode].operand[1].predicate (op0, mode0))
36015     op0 = copy_to_mode_reg (mode0, op0);
36016
36017   op1 = op0;
36018   if (!insn_data[icode].operand[2].predicate (op1, mode0))
36019     op1 = copy_to_mode_reg (mode0, op1);
36020
36021   pat = GEN_FCN (icode) (target, op0, op1);
36022   if (! pat)
36023     return 0;
36024   emit_insn (pat);
36025   return target;
36026 }
36027
36028 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
36029
36030 static rtx
36031 ix86_expand_sse_compare (const struct builtin_description *d,
36032                          tree exp, rtx target, bool swap)
36033 {
36034   rtx pat;
36035   tree arg0 = CALL_EXPR_ARG (exp, 0);
36036   tree arg1 = CALL_EXPR_ARG (exp, 1);
36037   rtx op0 = expand_normal (arg0);
36038   rtx op1 = expand_normal (arg1);
36039   rtx op2;
36040   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36041   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36042   machine_mode mode1 = insn_data[d->icode].operand[2].mode;
36043   enum rtx_code comparison = d->comparison;
36044
36045   if (VECTOR_MODE_P (mode0))
36046     op0 = safe_vector_operand (op0, mode0);
36047   if (VECTOR_MODE_P (mode1))
36048     op1 = safe_vector_operand (op1, mode1);
36049
36050   /* Swap operands if we have a comparison that isn't available in
36051      hardware.  */
36052   if (swap)
36053     std::swap (op0, op1);
36054
36055   if (optimize || !target
36056       || GET_MODE (target) != tmode
36057       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36058     target = gen_reg_rtx (tmode);
36059
36060   if ((optimize && !register_operand (op0, mode0))
36061       || !insn_data[d->icode].operand[1].predicate (op0, mode0))
36062     op0 = copy_to_mode_reg (mode0, op0);
36063   if ((optimize && !register_operand (op1, mode1))
36064       || !insn_data[d->icode].operand[2].predicate (op1, mode1))
36065     op1 = copy_to_mode_reg (mode1, op1);
36066
36067   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
36068   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
36069   if (! pat)
36070     return 0;
36071   emit_insn (pat);
36072   return target;
36073 }
36074
36075 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
36076
36077 static rtx
36078 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
36079                       rtx target)
36080 {
36081   rtx pat;
36082   tree arg0 = CALL_EXPR_ARG (exp, 0);
36083   tree arg1 = CALL_EXPR_ARG (exp, 1);
36084   rtx op0 = expand_normal (arg0);
36085   rtx op1 = expand_normal (arg1);
36086   machine_mode mode0 = insn_data[d->icode].operand[0].mode;
36087   machine_mode mode1 = insn_data[d->icode].operand[1].mode;
36088   enum rtx_code comparison = d->comparison;
36089
36090   if (VECTOR_MODE_P (mode0))
36091     op0 = safe_vector_operand (op0, mode0);
36092   if (VECTOR_MODE_P (mode1))
36093     op1 = safe_vector_operand (op1, mode1);
36094
36095   /* Swap operands if we have a comparison that isn't available in
36096      hardware.  */
36097   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
36098     std::swap (op0, op1);
36099
36100   target = gen_reg_rtx (SImode);
36101   emit_move_insn (target, const0_rtx);
36102   target = gen_rtx_SUBREG (QImode, target, 0);
36103
36104   if ((optimize && !register_operand (op0, mode0))
36105       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36106     op0 = copy_to_mode_reg (mode0, op0);
36107   if ((optimize && !register_operand (op1, mode1))
36108       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36109     op1 = copy_to_mode_reg (mode1, op1);
36110
36111   pat = GEN_FCN (d->icode) (op0, op1);
36112   if (! pat)
36113     return 0;
36114   emit_insn (pat);
36115   emit_insn (gen_rtx_SET (VOIDmode,
36116                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36117                           gen_rtx_fmt_ee (comparison, QImode,
36118                                           SET_DEST (pat),
36119                                           const0_rtx)));
36120
36121   return SUBREG_REG (target);
36122 }
36123
36124 /* Subroutines of ix86_expand_args_builtin to take care of round insns.  */
36125
36126 static rtx
36127 ix86_expand_sse_round (const struct builtin_description *d, tree exp,
36128                        rtx target)
36129 {
36130   rtx pat;
36131   tree arg0 = CALL_EXPR_ARG (exp, 0);
36132   rtx op1, op0 = expand_normal (arg0);
36133   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36134   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36135
36136   if (optimize || target == 0
36137       || GET_MODE (target) != tmode
36138       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36139     target = gen_reg_rtx (tmode);
36140
36141   if (VECTOR_MODE_P (mode0))
36142     op0 = safe_vector_operand (op0, mode0);
36143
36144   if ((optimize && !register_operand (op0, mode0))
36145       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36146     op0 = copy_to_mode_reg (mode0, op0);
36147
36148   op1 = GEN_INT (d->comparison);
36149
36150   pat = GEN_FCN (d->icode) (target, op0, op1);
36151   if (! pat)
36152     return 0;
36153   emit_insn (pat);
36154   return target;
36155 }
36156
36157 static rtx
36158 ix86_expand_sse_round_vec_pack_sfix (const struct builtin_description *d,
36159                                      tree exp, rtx target)
36160 {
36161   rtx pat;
36162   tree arg0 = CALL_EXPR_ARG (exp, 0);
36163   tree arg1 = CALL_EXPR_ARG (exp, 1);
36164   rtx op0 = expand_normal (arg0);
36165   rtx op1 = expand_normal (arg1);
36166   rtx op2;
36167   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36168   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36169   machine_mode mode1 = insn_data[d->icode].operand[2].mode;
36170
36171   if (optimize || target == 0
36172       || GET_MODE (target) != tmode
36173       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36174     target = gen_reg_rtx (tmode);
36175
36176   op0 = safe_vector_operand (op0, mode0);
36177   op1 = safe_vector_operand (op1, mode1);
36178
36179   if ((optimize && !register_operand (op0, mode0))
36180       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36181     op0 = copy_to_mode_reg (mode0, op0);
36182   if ((optimize && !register_operand (op1, mode1))
36183       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36184     op1 = copy_to_mode_reg (mode1, op1);
36185
36186   op2 = GEN_INT (d->comparison);
36187
36188   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
36189   if (! pat)
36190     return 0;
36191   emit_insn (pat);
36192   return target;
36193 }
36194
36195 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
36196
36197 static rtx
36198 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
36199                        rtx target)
36200 {
36201   rtx pat;
36202   tree arg0 = CALL_EXPR_ARG (exp, 0);
36203   tree arg1 = CALL_EXPR_ARG (exp, 1);
36204   rtx op0 = expand_normal (arg0);
36205   rtx op1 = expand_normal (arg1);
36206   machine_mode mode0 = insn_data[d->icode].operand[0].mode;
36207   machine_mode mode1 = insn_data[d->icode].operand[1].mode;
36208   enum rtx_code comparison = d->comparison;
36209
36210   if (VECTOR_MODE_P (mode0))
36211     op0 = safe_vector_operand (op0, mode0);
36212   if (VECTOR_MODE_P (mode1))
36213     op1 = safe_vector_operand (op1, mode1);
36214
36215   target = gen_reg_rtx (SImode);
36216   emit_move_insn (target, const0_rtx);
36217   target = gen_rtx_SUBREG (QImode, target, 0);
36218
36219   if ((optimize && !register_operand (op0, mode0))
36220       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36221     op0 = copy_to_mode_reg (mode0, op0);
36222   if ((optimize && !register_operand (op1, mode1))
36223       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36224     op1 = copy_to_mode_reg (mode1, op1);
36225
36226   pat = GEN_FCN (d->icode) (op0, op1);
36227   if (! pat)
36228     return 0;
36229   emit_insn (pat);
36230   emit_insn (gen_rtx_SET (VOIDmode,
36231                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36232                           gen_rtx_fmt_ee (comparison, QImode,
36233                                           SET_DEST (pat),
36234                                           const0_rtx)));
36235
36236   return SUBREG_REG (target);
36237 }
36238
36239 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
36240
36241 static rtx
36242 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
36243                           tree exp, rtx target)
36244 {
36245   rtx pat;
36246   tree arg0 = CALL_EXPR_ARG (exp, 0);
36247   tree arg1 = CALL_EXPR_ARG (exp, 1);
36248   tree arg2 = CALL_EXPR_ARG (exp, 2);
36249   tree arg3 = CALL_EXPR_ARG (exp, 3);
36250   tree arg4 = CALL_EXPR_ARG (exp, 4);
36251   rtx scratch0, scratch1;
36252   rtx op0 = expand_normal (arg0);
36253   rtx op1 = expand_normal (arg1);
36254   rtx op2 = expand_normal (arg2);
36255   rtx op3 = expand_normal (arg3);
36256   rtx op4 = expand_normal (arg4);
36257   machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
36258
36259   tmode0 = insn_data[d->icode].operand[0].mode;
36260   tmode1 = insn_data[d->icode].operand[1].mode;
36261   modev2 = insn_data[d->icode].operand[2].mode;
36262   modei3 = insn_data[d->icode].operand[3].mode;
36263   modev4 = insn_data[d->icode].operand[4].mode;
36264   modei5 = insn_data[d->icode].operand[5].mode;
36265   modeimm = insn_data[d->icode].operand[6].mode;
36266
36267   if (VECTOR_MODE_P (modev2))
36268     op0 = safe_vector_operand (op0, modev2);
36269   if (VECTOR_MODE_P (modev4))
36270     op2 = safe_vector_operand (op2, modev4);
36271
36272   if (!insn_data[d->icode].operand[2].predicate (op0, modev2))
36273     op0 = copy_to_mode_reg (modev2, op0);
36274   if (!insn_data[d->icode].operand[3].predicate (op1, modei3))
36275     op1 = copy_to_mode_reg (modei3, op1);
36276   if ((optimize && !register_operand (op2, modev4))
36277       || !insn_data[d->icode].operand[4].predicate (op2, modev4))
36278     op2 = copy_to_mode_reg (modev4, op2);
36279   if (!insn_data[d->icode].operand[5].predicate (op3, modei5))
36280     op3 = copy_to_mode_reg (modei5, op3);
36281
36282   if (!insn_data[d->icode].operand[6].predicate (op4, modeimm))
36283     {
36284       error ("the fifth argument must be an 8-bit immediate");
36285       return const0_rtx;
36286     }
36287
36288   if (d->code == IX86_BUILTIN_PCMPESTRI128)
36289     {
36290       if (optimize || !target
36291           || GET_MODE (target) != tmode0
36292           || !insn_data[d->icode].operand[0].predicate (target, tmode0))
36293         target = gen_reg_rtx (tmode0);
36294
36295       scratch1 = gen_reg_rtx (tmode1);
36296
36297       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
36298     }
36299   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
36300     {
36301       if (optimize || !target
36302           || GET_MODE (target) != tmode1
36303           || !insn_data[d->icode].operand[1].predicate (target, tmode1))
36304         target = gen_reg_rtx (tmode1);
36305
36306       scratch0 = gen_reg_rtx (tmode0);
36307
36308       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
36309     }
36310   else
36311     {
36312       gcc_assert (d->flag);
36313
36314       scratch0 = gen_reg_rtx (tmode0);
36315       scratch1 = gen_reg_rtx (tmode1);
36316
36317       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
36318     }
36319
36320   if (! pat)
36321     return 0;
36322
36323   emit_insn (pat);
36324
36325   if (d->flag)
36326     {
36327       target = gen_reg_rtx (SImode);
36328       emit_move_insn (target, const0_rtx);
36329       target = gen_rtx_SUBREG (QImode, target, 0);
36330
36331       emit_insn
36332         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36333                       gen_rtx_fmt_ee (EQ, QImode,
36334                                       gen_rtx_REG ((machine_mode) d->flag,
36335                                                    FLAGS_REG),
36336                                       const0_rtx)));
36337       return SUBREG_REG (target);
36338     }
36339   else
36340     return target;
36341 }
36342
36343
36344 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
36345
36346 static rtx
36347 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
36348                           tree exp, rtx target)
36349 {
36350   rtx pat;
36351   tree arg0 = CALL_EXPR_ARG (exp, 0);
36352   tree arg1 = CALL_EXPR_ARG (exp, 1);
36353   tree arg2 = CALL_EXPR_ARG (exp, 2);
36354   rtx scratch0, scratch1;
36355   rtx op0 = expand_normal (arg0);
36356   rtx op1 = expand_normal (arg1);
36357   rtx op2 = expand_normal (arg2);
36358   machine_mode tmode0, tmode1, modev2, modev3, modeimm;
36359
36360   tmode0 = insn_data[d->icode].operand[0].mode;
36361   tmode1 = insn_data[d->icode].operand[1].mode;
36362   modev2 = insn_data[d->icode].operand[2].mode;
36363   modev3 = insn_data[d->icode].operand[3].mode;
36364   modeimm = insn_data[d->icode].operand[4].mode;
36365
36366   if (VECTOR_MODE_P (modev2))
36367     op0 = safe_vector_operand (op0, modev2);
36368   if (VECTOR_MODE_P (modev3))
36369     op1 = safe_vector_operand (op1, modev3);
36370
36371   if (!insn_data[d->icode].operand[2].predicate (op0, modev2))
36372     op0 = copy_to_mode_reg (modev2, op0);
36373   if ((optimize && !register_operand (op1, modev3))
36374       || !insn_data[d->icode].operand[3].predicate (op1, modev3))
36375     op1 = copy_to_mode_reg (modev3, op1);
36376
36377   if (!insn_data[d->icode].operand[4].predicate (op2, modeimm))
36378     {
36379       error ("the third argument must be an 8-bit immediate");
36380       return const0_rtx;
36381     }
36382
36383   if (d->code == IX86_BUILTIN_PCMPISTRI128)
36384     {
36385       if (optimize || !target
36386           || GET_MODE (target) != tmode0
36387           || !insn_data[d->icode].operand[0].predicate (target, tmode0))
36388         target = gen_reg_rtx (tmode0);
36389
36390       scratch1 = gen_reg_rtx (tmode1);
36391
36392       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
36393     }
36394   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
36395     {
36396       if (optimize || !target
36397           || GET_MODE (target) != tmode1
36398           || !insn_data[d->icode].operand[1].predicate (target, tmode1))
36399         target = gen_reg_rtx (tmode1);
36400
36401       scratch0 = gen_reg_rtx (tmode0);
36402
36403       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
36404     }
36405   else
36406     {
36407       gcc_assert (d->flag);
36408
36409       scratch0 = gen_reg_rtx (tmode0);
36410       scratch1 = gen_reg_rtx (tmode1);
36411
36412       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
36413     }
36414
36415   if (! pat)
36416     return 0;
36417
36418   emit_insn (pat);
36419
36420   if (d->flag)
36421     {
36422       target = gen_reg_rtx (SImode);
36423       emit_move_insn (target, const0_rtx);
36424       target = gen_rtx_SUBREG (QImode, target, 0);
36425
36426       emit_insn
36427         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36428                       gen_rtx_fmt_ee (EQ, QImode,
36429                                       gen_rtx_REG ((machine_mode) d->flag,
36430                                                    FLAGS_REG),
36431                                       const0_rtx)));
36432       return SUBREG_REG (target);
36433     }
36434   else
36435     return target;
36436 }
36437
36438 /* Subroutine of ix86_expand_builtin to take care of insns with
36439    variable number of operands.  */
36440
36441 static rtx
36442 ix86_expand_args_builtin (const struct builtin_description *d,
36443                           tree exp, rtx target)
36444 {
36445   rtx pat, real_target;
36446   unsigned int i, nargs;
36447   unsigned int nargs_constant = 0;
36448   unsigned int mask_pos = 0;
36449   int num_memory = 0;
36450   struct
36451     {
36452       rtx op;
36453       machine_mode mode;
36454     } args[6];
36455   bool last_arg_count = false;
36456   enum insn_code icode = d->icode;
36457   const struct insn_data_d *insn_p = &insn_data[icode];
36458   machine_mode tmode = insn_p->operand[0].mode;
36459   machine_mode rmode = VOIDmode;
36460   bool swap = false;
36461   enum rtx_code comparison = d->comparison;
36462
36463   switch ((enum ix86_builtin_func_type) d->flag)
36464     {
36465     case V2DF_FTYPE_V2DF_ROUND:
36466     case V4DF_FTYPE_V4DF_ROUND:
36467     case V4SF_FTYPE_V4SF_ROUND:
36468     case V8SF_FTYPE_V8SF_ROUND:
36469     case V4SI_FTYPE_V4SF_ROUND:
36470     case V8SI_FTYPE_V8SF_ROUND:
36471       return ix86_expand_sse_round (d, exp, target);
36472     case V4SI_FTYPE_V2DF_V2DF_ROUND:
36473     case V8SI_FTYPE_V4DF_V4DF_ROUND:
36474     case V16SI_FTYPE_V8DF_V8DF_ROUND:
36475       return ix86_expand_sse_round_vec_pack_sfix (d, exp, target);
36476     case INT_FTYPE_V8SF_V8SF_PTEST:
36477     case INT_FTYPE_V4DI_V4DI_PTEST:
36478     case INT_FTYPE_V4DF_V4DF_PTEST:
36479     case INT_FTYPE_V4SF_V4SF_PTEST:
36480     case INT_FTYPE_V2DI_V2DI_PTEST:
36481     case INT_FTYPE_V2DF_V2DF_PTEST:
36482       return ix86_expand_sse_ptest (d, exp, target);
36483     case FLOAT128_FTYPE_FLOAT128:
36484     case FLOAT_FTYPE_FLOAT:
36485     case INT_FTYPE_INT:
36486     case UINT64_FTYPE_INT:
36487     case UINT16_FTYPE_UINT16:
36488     case INT64_FTYPE_INT64:
36489     case INT64_FTYPE_V4SF:
36490     case INT64_FTYPE_V2DF:
36491     case INT_FTYPE_V16QI:
36492     case INT_FTYPE_V8QI:
36493     case INT_FTYPE_V8SF:
36494     case INT_FTYPE_V4DF:
36495     case INT_FTYPE_V4SF:
36496     case INT_FTYPE_V2DF:
36497     case INT_FTYPE_V32QI:
36498     case V16QI_FTYPE_V16QI:
36499     case V8SI_FTYPE_V8SF:
36500     case V8SI_FTYPE_V4SI:
36501     case V8HI_FTYPE_V8HI:
36502     case V8HI_FTYPE_V16QI:
36503     case V8QI_FTYPE_V8QI:
36504     case V8SF_FTYPE_V8SF:
36505     case V8SF_FTYPE_V8SI:
36506     case V8SF_FTYPE_V4SF:
36507     case V8SF_FTYPE_V8HI:
36508     case V4SI_FTYPE_V4SI:
36509     case V4SI_FTYPE_V16QI:
36510     case V4SI_FTYPE_V4SF:
36511     case V4SI_FTYPE_V8SI:
36512     case V4SI_FTYPE_V8HI:
36513     case V4SI_FTYPE_V4DF:
36514     case V4SI_FTYPE_V2DF:
36515     case V4HI_FTYPE_V4HI:
36516     case V4DF_FTYPE_V4DF:
36517     case V4DF_FTYPE_V4SI:
36518     case V4DF_FTYPE_V4SF:
36519     case V4DF_FTYPE_V2DF:
36520     case V4SF_FTYPE_V4SF:
36521     case V4SF_FTYPE_V4SI:
36522     case V4SF_FTYPE_V8SF:
36523     case V4SF_FTYPE_V4DF:
36524     case V4SF_FTYPE_V8HI:
36525     case V4SF_FTYPE_V2DF:
36526     case V2DI_FTYPE_V2DI:
36527     case V2DI_FTYPE_V16QI:
36528     case V2DI_FTYPE_V8HI:
36529     case V2DI_FTYPE_V4SI:
36530     case V2DF_FTYPE_V2DF:
36531     case V2DF_FTYPE_V4SI:
36532     case V2DF_FTYPE_V4DF:
36533     case V2DF_FTYPE_V4SF:
36534     case V2DF_FTYPE_V2SI:
36535     case V2SI_FTYPE_V2SI:
36536     case V2SI_FTYPE_V4SF:
36537     case V2SI_FTYPE_V2SF:
36538     case V2SI_FTYPE_V2DF:
36539     case V2SF_FTYPE_V2SF:
36540     case V2SF_FTYPE_V2SI:
36541     case V32QI_FTYPE_V32QI:
36542     case V32QI_FTYPE_V16QI:
36543     case V16HI_FTYPE_V16HI:
36544     case V16HI_FTYPE_V8HI:
36545     case V8SI_FTYPE_V8SI:
36546     case V16HI_FTYPE_V16QI:
36547     case V8SI_FTYPE_V16QI:
36548     case V4DI_FTYPE_V16QI:
36549     case V8SI_FTYPE_V8HI:
36550     case V4DI_FTYPE_V8HI:
36551     case V4DI_FTYPE_V4SI:
36552     case V4DI_FTYPE_V2DI:
36553     case HI_FTYPE_HI:
36554     case HI_FTYPE_V16QI:
36555     case SI_FTYPE_V32QI:
36556     case DI_FTYPE_V64QI:
36557     case V16QI_FTYPE_HI:
36558     case V32QI_FTYPE_SI:
36559     case V64QI_FTYPE_DI:
36560     case V8HI_FTYPE_QI:
36561     case V16HI_FTYPE_HI:
36562     case V32HI_FTYPE_SI:
36563     case V4SI_FTYPE_QI:
36564     case V8SI_FTYPE_QI:
36565     case V4SI_FTYPE_HI:
36566     case V8SI_FTYPE_HI:
36567     case QI_FTYPE_V8HI:
36568     case HI_FTYPE_V16HI:
36569     case SI_FTYPE_V32HI:
36570     case QI_FTYPE_V4SI:
36571     case QI_FTYPE_V8SI:
36572     case HI_FTYPE_V16SI:
36573     case QI_FTYPE_V2DI:
36574     case QI_FTYPE_V4DI:
36575     case QI_FTYPE_V8DI:
36576     case UINT_FTYPE_V2DF:
36577     case UINT_FTYPE_V4SF:
36578     case UINT64_FTYPE_V2DF:
36579     case UINT64_FTYPE_V4SF:
36580     case V16QI_FTYPE_V8DI:
36581     case V16HI_FTYPE_V16SI:
36582     case V16SI_FTYPE_HI:
36583     case V2DI_FTYPE_QI:
36584     case V4DI_FTYPE_QI:
36585     case V16SI_FTYPE_V16SI:
36586     case V16SI_FTYPE_INT:
36587     case V16SF_FTYPE_FLOAT:
36588     case V16SF_FTYPE_V8SF:
36589     case V16SI_FTYPE_V8SI:
36590     case V16SF_FTYPE_V4SF:
36591     case V16SI_FTYPE_V4SI:
36592     case V16SF_FTYPE_V16SF:
36593     case V8HI_FTYPE_V8DI:
36594     case V8UHI_FTYPE_V8UHI:
36595     case V8SI_FTYPE_V8DI:
36596     case V8SF_FTYPE_V8DF:
36597     case V8DI_FTYPE_QI:
36598     case V8DI_FTYPE_INT64:
36599     case V8DI_FTYPE_V4DI:
36600     case V8DI_FTYPE_V8DI:
36601     case V8DF_FTYPE_DOUBLE:
36602     case V8DF_FTYPE_V4DF:
36603     case V8DF_FTYPE_V2DF:
36604     case V8DF_FTYPE_V8DF:
36605     case V8DF_FTYPE_V8SI:
36606       nargs = 1;
36607       break;
36608     case V4SF_FTYPE_V4SF_VEC_MERGE:
36609     case V2DF_FTYPE_V2DF_VEC_MERGE:
36610       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
36611     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
36612     case V16QI_FTYPE_V16QI_V16QI:
36613     case V16QI_FTYPE_V8HI_V8HI:
36614     case V16SI_FTYPE_V16SI_V16SI:
36615     case V16SF_FTYPE_V16SF_V16SF:
36616     case V16SF_FTYPE_V16SF_V16SI:
36617     case V8QI_FTYPE_V8QI_V8QI:
36618     case V8QI_FTYPE_V4HI_V4HI:
36619     case V8HI_FTYPE_V8HI_V8HI:
36620     case V8HI_FTYPE_V16QI_V16QI:
36621     case V8HI_FTYPE_V4SI_V4SI:
36622     case V8SF_FTYPE_V8SF_V8SF:
36623     case V8SF_FTYPE_V8SF_V8SI:
36624     case V8DI_FTYPE_V8DI_V8DI:
36625     case V8DF_FTYPE_V8DF_V8DF:
36626     case V8DF_FTYPE_V8DF_V8DI:
36627     case V4SI_FTYPE_V4SI_V4SI:
36628     case V4SI_FTYPE_V8HI_V8HI:
36629     case V4SI_FTYPE_V4SF_V4SF:
36630     case V4SI_FTYPE_V2DF_V2DF:
36631     case V4HI_FTYPE_V4HI_V4HI:
36632     case V4HI_FTYPE_V8QI_V8QI:
36633     case V4HI_FTYPE_V2SI_V2SI:
36634     case V4DF_FTYPE_V4DF_V4DF:
36635     case V4DF_FTYPE_V4DF_V4DI:
36636     case V4SF_FTYPE_V4SF_V4SF:
36637     case V4SF_FTYPE_V4SF_V4SI:
36638     case V4SF_FTYPE_V4SF_V2SI:
36639     case V4SF_FTYPE_V4SF_V2DF:
36640     case V4SF_FTYPE_V4SF_UINT:
36641     case V4SF_FTYPE_V4SF_UINT64:
36642     case V4SF_FTYPE_V4SF_DI:
36643     case V4SF_FTYPE_V4SF_SI:
36644     case V2DI_FTYPE_V2DI_V2DI:
36645     case V2DI_FTYPE_V16QI_V16QI:
36646     case V2DI_FTYPE_V4SI_V4SI:
36647     case V2UDI_FTYPE_V4USI_V4USI:
36648     case V2DI_FTYPE_V2DI_V16QI:
36649     case V2DI_FTYPE_V2DF_V2DF:
36650     case V2SI_FTYPE_V2SI_V2SI:
36651     case V2SI_FTYPE_V4HI_V4HI:
36652     case V2SI_FTYPE_V2SF_V2SF:
36653     case V2DF_FTYPE_V2DF_V2DF:
36654     case V2DF_FTYPE_V2DF_V4SF:
36655     case V2DF_FTYPE_V2DF_V2DI:
36656     case V2DF_FTYPE_V2DF_DI:
36657     case V2DF_FTYPE_V2DF_SI:
36658     case V2DF_FTYPE_V2DF_UINT:
36659     case V2DF_FTYPE_V2DF_UINT64:
36660     case V2SF_FTYPE_V2SF_V2SF:
36661     case V1DI_FTYPE_V1DI_V1DI:
36662     case V1DI_FTYPE_V8QI_V8QI:
36663     case V1DI_FTYPE_V2SI_V2SI:
36664     case V32QI_FTYPE_V16HI_V16HI:
36665     case V16HI_FTYPE_V8SI_V8SI:
36666     case V32QI_FTYPE_V32QI_V32QI:
36667     case V16HI_FTYPE_V32QI_V32QI:
36668     case V16HI_FTYPE_V16HI_V16HI:
36669     case V8SI_FTYPE_V4DF_V4DF:
36670     case V8SI_FTYPE_V8SI_V8SI:
36671     case V8SI_FTYPE_V16HI_V16HI:
36672     case V4DI_FTYPE_V4DI_V4DI:
36673     case V4DI_FTYPE_V8SI_V8SI:
36674     case V4UDI_FTYPE_V8USI_V8USI:
36675     case QI_FTYPE_V8DI_V8DI:
36676     case V8DI_FTYPE_V64QI_V64QI:
36677     case HI_FTYPE_V16SI_V16SI:
36678       if (comparison == UNKNOWN)
36679         return ix86_expand_binop_builtin (icode, exp, target);
36680       nargs = 2;
36681       break;
36682     case V4SF_FTYPE_V4SF_V4SF_SWAP:
36683     case V2DF_FTYPE_V2DF_V2DF_SWAP:
36684       gcc_assert (comparison != UNKNOWN);
36685       nargs = 2;
36686       swap = true;
36687       break;
36688     case V16HI_FTYPE_V16HI_V8HI_COUNT:
36689     case V16HI_FTYPE_V16HI_SI_COUNT:
36690     case V8SI_FTYPE_V8SI_V4SI_COUNT:
36691     case V8SI_FTYPE_V8SI_SI_COUNT:
36692     case V4DI_FTYPE_V4DI_V2DI_COUNT:
36693     case V4DI_FTYPE_V4DI_INT_COUNT:
36694     case V8HI_FTYPE_V8HI_V8HI_COUNT:
36695     case V8HI_FTYPE_V8HI_SI_COUNT:
36696     case V4SI_FTYPE_V4SI_V4SI_COUNT:
36697     case V4SI_FTYPE_V4SI_SI_COUNT:
36698     case V4HI_FTYPE_V4HI_V4HI_COUNT:
36699     case V4HI_FTYPE_V4HI_SI_COUNT:
36700     case V2DI_FTYPE_V2DI_V2DI_COUNT:
36701     case V2DI_FTYPE_V2DI_SI_COUNT:
36702     case V2SI_FTYPE_V2SI_V2SI_COUNT:
36703     case V2SI_FTYPE_V2SI_SI_COUNT:
36704     case V1DI_FTYPE_V1DI_V1DI_COUNT:
36705     case V1DI_FTYPE_V1DI_SI_COUNT:
36706       nargs = 2;
36707       last_arg_count = true;
36708       break;
36709     case UINT64_FTYPE_UINT64_UINT64:
36710     case UINT_FTYPE_UINT_UINT:
36711     case UINT_FTYPE_UINT_USHORT:
36712     case UINT_FTYPE_UINT_UCHAR:
36713     case UINT16_FTYPE_UINT16_INT:
36714     case UINT8_FTYPE_UINT8_INT:
36715     case HI_FTYPE_HI_HI:
36716     case SI_FTYPE_SI_SI:
36717     case DI_FTYPE_DI_DI:
36718     case V16SI_FTYPE_V8DF_V8DF:
36719       nargs = 2;
36720       break;
36721     case V2DI_FTYPE_V2DI_INT_CONVERT:
36722       nargs = 2;
36723       rmode = V1TImode;
36724       nargs_constant = 1;
36725       break;
36726     case V4DI_FTYPE_V4DI_INT_CONVERT:
36727       nargs = 2;
36728       rmode = V2TImode;
36729       nargs_constant = 1;
36730       break;
36731     case V8DI_FTYPE_V8DI_INT_CONVERT:
36732       nargs = 2;
36733       rmode = V4TImode;
36734       nargs_constant = 1;
36735       break;
36736     case V8HI_FTYPE_V8HI_INT:
36737     case V8HI_FTYPE_V8SF_INT:
36738     case V16HI_FTYPE_V16SF_INT:
36739     case V8HI_FTYPE_V4SF_INT:
36740     case V8SF_FTYPE_V8SF_INT:
36741     case V4SF_FTYPE_V16SF_INT:
36742     case V16SF_FTYPE_V16SF_INT:
36743     case V4SI_FTYPE_V4SI_INT:
36744     case V4SI_FTYPE_V8SI_INT:
36745     case V4HI_FTYPE_V4HI_INT:
36746     case V4DF_FTYPE_V4DF_INT:
36747     case V4DF_FTYPE_V8DF_INT:
36748     case V4SF_FTYPE_V4SF_INT:
36749     case V4SF_FTYPE_V8SF_INT:
36750     case V2DI_FTYPE_V2DI_INT:
36751     case V2DF_FTYPE_V2DF_INT:
36752     case V2DF_FTYPE_V4DF_INT:
36753     case V16HI_FTYPE_V16HI_INT:
36754     case V8SI_FTYPE_V8SI_INT:
36755     case V16SI_FTYPE_V16SI_INT:
36756     case V4SI_FTYPE_V16SI_INT:
36757     case V4DI_FTYPE_V4DI_INT:
36758     case V2DI_FTYPE_V4DI_INT:
36759     case V4DI_FTYPE_V8DI_INT:
36760     case HI_FTYPE_HI_INT:
36761     case QI_FTYPE_V4SF_INT:
36762     case QI_FTYPE_V2DF_INT:
36763       nargs = 2;
36764       nargs_constant = 1;
36765       break;
36766     case V16QI_FTYPE_V16QI_V16QI_V16QI:
36767     case V8SF_FTYPE_V8SF_V8SF_V8SF:
36768     case V4DF_FTYPE_V4DF_V4DF_V4DF:
36769     case V4SF_FTYPE_V4SF_V4SF_V4SF:
36770     case V2DF_FTYPE_V2DF_V2DF_V2DF:
36771     case V32QI_FTYPE_V32QI_V32QI_V32QI:
36772     case HI_FTYPE_V16SI_V16SI_HI:
36773     case QI_FTYPE_V8DI_V8DI_QI:
36774     case V16HI_FTYPE_V16SI_V16HI_HI:
36775     case V16QI_FTYPE_V16SI_V16QI_HI:
36776     case V16QI_FTYPE_V8DI_V16QI_QI:
36777     case V16SF_FTYPE_V16SF_V16SF_HI:
36778     case V16SF_FTYPE_V16SF_V16SF_V16SF:
36779     case V16SF_FTYPE_V16SF_V16SI_V16SF:
36780     case V16SF_FTYPE_V16SI_V16SF_HI:
36781     case V16SF_FTYPE_V16SI_V16SF_V16SF:
36782     case V16SF_FTYPE_V4SF_V16SF_HI:
36783     case V16SI_FTYPE_SI_V16SI_HI:
36784     case V16SI_FTYPE_V16HI_V16SI_HI:
36785     case V16SI_FTYPE_V16QI_V16SI_HI:
36786     case V16SI_FTYPE_V16SF_V16SI_HI:
36787     case V8SF_FTYPE_V4SF_V8SF_QI:
36788     case V4DF_FTYPE_V2DF_V4DF_QI:
36789     case V8SI_FTYPE_V4SI_V8SI_QI:
36790     case V8SI_FTYPE_SI_V8SI_QI:
36791     case V4SI_FTYPE_V4SI_V4SI_QI:
36792     case V4SI_FTYPE_SI_V4SI_QI:
36793     case V4DI_FTYPE_V2DI_V4DI_QI:
36794     case V4DI_FTYPE_DI_V4DI_QI:
36795     case V2DI_FTYPE_V2DI_V2DI_QI:
36796     case V2DI_FTYPE_DI_V2DI_QI:
36797     case V64QI_FTYPE_V64QI_V64QI_DI:
36798     case V64QI_FTYPE_V16QI_V64QI_DI:
36799     case V64QI_FTYPE_QI_V64QI_DI:
36800     case V32QI_FTYPE_V32QI_V32QI_SI:
36801     case V32QI_FTYPE_V16QI_V32QI_SI:
36802     case V32QI_FTYPE_QI_V32QI_SI:
36803     case V16QI_FTYPE_V16QI_V16QI_HI:
36804     case V16QI_FTYPE_QI_V16QI_HI:
36805     case V32HI_FTYPE_V8HI_V32HI_SI:
36806     case V32HI_FTYPE_HI_V32HI_SI:
36807     case V16HI_FTYPE_V8HI_V16HI_HI:
36808     case V16HI_FTYPE_HI_V16HI_HI:
36809     case V8HI_FTYPE_V8HI_V8HI_QI:
36810     case V8HI_FTYPE_HI_V8HI_QI:
36811     case V8SF_FTYPE_V8HI_V8SF_QI:
36812     case V4SF_FTYPE_V8HI_V4SF_QI:
36813     case V8SI_FTYPE_V8SF_V8SI_QI:
36814     case V4SI_FTYPE_V4SF_V4SI_QI:
36815     case V8DI_FTYPE_V8SF_V8DI_QI:
36816     case V4DI_FTYPE_V4SF_V4DI_QI:
36817     case V2DI_FTYPE_V4SF_V2DI_QI:
36818     case V8SF_FTYPE_V8DI_V8SF_QI:
36819     case V4SF_FTYPE_V4DI_V4SF_QI:
36820     case V4SF_FTYPE_V2DI_V4SF_QI:
36821     case V8DF_FTYPE_V8DI_V8DF_QI:
36822     case V4DF_FTYPE_V4DI_V4DF_QI:
36823     case V2DF_FTYPE_V2DI_V2DF_QI:
36824     case V16QI_FTYPE_V8HI_V16QI_QI:
36825     case V16QI_FTYPE_V16HI_V16QI_HI:
36826     case V16QI_FTYPE_V4SI_V16QI_QI:
36827     case V16QI_FTYPE_V8SI_V16QI_QI:
36828     case V8HI_FTYPE_V4SI_V8HI_QI:
36829     case V8HI_FTYPE_V8SI_V8HI_QI:
36830     case V16QI_FTYPE_V2DI_V16QI_QI:
36831     case V16QI_FTYPE_V4DI_V16QI_QI:
36832     case V8HI_FTYPE_V2DI_V8HI_QI:
36833     case V8HI_FTYPE_V4DI_V8HI_QI:
36834     case V4SI_FTYPE_V2DI_V4SI_QI:
36835     case V4SI_FTYPE_V4DI_V4SI_QI:
36836     case V32QI_FTYPE_V32HI_V32QI_SI:
36837     case HI_FTYPE_V16QI_V16QI_HI:
36838     case SI_FTYPE_V32QI_V32QI_SI:
36839     case DI_FTYPE_V64QI_V64QI_DI:
36840     case QI_FTYPE_V8HI_V8HI_QI:
36841     case HI_FTYPE_V16HI_V16HI_HI:
36842     case SI_FTYPE_V32HI_V32HI_SI:
36843     case QI_FTYPE_V4SI_V4SI_QI:
36844     case QI_FTYPE_V8SI_V8SI_QI:
36845     case QI_FTYPE_V2DI_V2DI_QI:
36846     case QI_FTYPE_V4DI_V4DI_QI:
36847     case V4SF_FTYPE_V2DF_V4SF_QI:
36848     case V4SF_FTYPE_V4DF_V4SF_QI:
36849     case V16SI_FTYPE_V16SI_V16SI_HI:
36850     case V16SI_FTYPE_V16SI_V16SI_V16SI:
36851     case V16SI_FTYPE_V4SI_V16SI_HI:
36852     case V2DI_FTYPE_V2DI_V2DI_V2DI:
36853     case V2DI_FTYPE_V4SI_V2DI_QI:
36854     case V2DI_FTYPE_V8HI_V2DI_QI:
36855     case V2DI_FTYPE_V16QI_V2DI_QI:
36856     case V4DI_FTYPE_V4DI_V4DI_QI:
36857     case V4DI_FTYPE_V4SI_V4DI_QI:
36858     case V4DI_FTYPE_V8HI_V4DI_QI:
36859     case V4DI_FTYPE_V16QI_V4DI_QI:
36860     case V8DI_FTYPE_V8DF_V8DI_QI:
36861     case V4DI_FTYPE_V4DF_V4DI_QI:
36862     case V2DI_FTYPE_V2DF_V2DI_QI:
36863     case V4SI_FTYPE_V4DF_V4SI_QI:
36864     case V4SI_FTYPE_V2DF_V4SI_QI:
36865     case V4SI_FTYPE_V8HI_V4SI_QI:
36866     case V4SI_FTYPE_V16QI_V4SI_QI:
36867     case V8SI_FTYPE_V8SI_V8SI_V8SI:
36868     case V4DI_FTYPE_V4DI_V4DI_V4DI:
36869     case V8DF_FTYPE_V2DF_V8DF_QI:
36870     case V8DF_FTYPE_V4DF_V8DF_QI:
36871     case V8DF_FTYPE_V8DF_V8DF_QI:
36872     case V8DF_FTYPE_V8DF_V8DF_V8DF:
36873     case V8SF_FTYPE_V8SF_V8SF_QI:
36874     case V8SF_FTYPE_V8SI_V8SF_QI:
36875     case V4DF_FTYPE_V4DF_V4DF_QI:
36876     case V4SF_FTYPE_V4SF_V4SF_QI:
36877     case V2DF_FTYPE_V2DF_V2DF_QI:
36878     case V2DF_FTYPE_V4SF_V2DF_QI:
36879     case V2DF_FTYPE_V4SI_V2DF_QI:
36880     case V4SF_FTYPE_V4SI_V4SF_QI:
36881     case V4DF_FTYPE_V4SF_V4DF_QI:
36882     case V4DF_FTYPE_V4SI_V4DF_QI:
36883     case V8SI_FTYPE_V8SI_V8SI_QI:
36884     case V8SI_FTYPE_V8HI_V8SI_QI:
36885     case V8SI_FTYPE_V16QI_V8SI_QI:
36886     case V8DF_FTYPE_V8DF_V8DI_V8DF:
36887     case V8DF_FTYPE_V8DI_V8DF_V8DF:
36888     case V8DF_FTYPE_V8SF_V8DF_QI:
36889     case V8DF_FTYPE_V8SI_V8DF_QI:
36890     case V8DI_FTYPE_DI_V8DI_QI:
36891     case V16SF_FTYPE_V8SF_V16SF_HI:
36892     case V16SI_FTYPE_V8SI_V16SI_HI:
36893     case V16HI_FTYPE_V16HI_V16HI_HI:
36894     case V8HI_FTYPE_V16QI_V8HI_QI:
36895     case V16HI_FTYPE_V16QI_V16HI_HI:
36896     case V32HI_FTYPE_V32HI_V32HI_SI:
36897     case V32HI_FTYPE_V32QI_V32HI_SI:
36898     case V8DI_FTYPE_V16QI_V8DI_QI:
36899     case V8DI_FTYPE_V2DI_V8DI_QI:
36900     case V8DI_FTYPE_V4DI_V8DI_QI:
36901     case V8DI_FTYPE_V8DI_V8DI_QI:
36902     case V8DI_FTYPE_V8DI_V8DI_V8DI:
36903     case V8DI_FTYPE_V8HI_V8DI_QI:
36904     case V8DI_FTYPE_V8SI_V8DI_QI:
36905     case V8HI_FTYPE_V8DI_V8HI_QI:
36906     case V8SF_FTYPE_V8DF_V8SF_QI:
36907     case V8SI_FTYPE_V8DF_V8SI_QI:
36908     case V8SI_FTYPE_V8DI_V8SI_QI:
36909     case V4SI_FTYPE_V4SI_V4SI_V4SI:
36910       nargs = 3;
36911       break;
36912     case V32QI_FTYPE_V32QI_V32QI_INT:
36913     case V16HI_FTYPE_V16HI_V16HI_INT:
36914     case V16QI_FTYPE_V16QI_V16QI_INT:
36915     case V4DI_FTYPE_V4DI_V4DI_INT:
36916     case V8HI_FTYPE_V8HI_V8HI_INT:
36917     case V8SI_FTYPE_V8SI_V8SI_INT:
36918     case V8SI_FTYPE_V8SI_V4SI_INT:
36919     case V8SF_FTYPE_V8SF_V8SF_INT:
36920     case V8SF_FTYPE_V8SF_V4SF_INT:
36921     case V4SI_FTYPE_V4SI_V4SI_INT:
36922     case V4DF_FTYPE_V4DF_V4DF_INT:
36923     case V16SF_FTYPE_V16SF_V16SF_INT:
36924     case V16SF_FTYPE_V16SF_V4SF_INT:
36925     case V16SI_FTYPE_V16SI_V4SI_INT:
36926     case V4DF_FTYPE_V4DF_V2DF_INT:
36927     case V4SF_FTYPE_V4SF_V4SF_INT:
36928     case V2DI_FTYPE_V2DI_V2DI_INT:
36929     case V4DI_FTYPE_V4DI_V2DI_INT:
36930     case V2DF_FTYPE_V2DF_V2DF_INT:
36931     case QI_FTYPE_V8DI_V8DI_INT:
36932     case QI_FTYPE_V8DF_V8DF_INT:
36933     case QI_FTYPE_V2DF_V2DF_INT:
36934     case QI_FTYPE_V4SF_V4SF_INT:
36935     case HI_FTYPE_V16SI_V16SI_INT:
36936     case HI_FTYPE_V16SF_V16SF_INT:
36937       nargs = 3;
36938       nargs_constant = 1;
36939       break;
36940     case V4DI_FTYPE_V4DI_V4DI_INT_CONVERT:
36941       nargs = 3;
36942       rmode = V4DImode;
36943       nargs_constant = 1;
36944       break;
36945     case V2DI_FTYPE_V2DI_V2DI_INT_CONVERT:
36946       nargs = 3;
36947       rmode = V2DImode;
36948       nargs_constant = 1;
36949       break;
36950     case V1DI_FTYPE_V1DI_V1DI_INT_CONVERT:
36951       nargs = 3;
36952       rmode = DImode;
36953       nargs_constant = 1;
36954       break;
36955     case V2DI_FTYPE_V2DI_UINT_UINT:
36956       nargs = 3;
36957       nargs_constant = 2;
36958       break;
36959     case V8DI_FTYPE_V8DI_V8DI_INT_CONVERT:
36960       nargs = 3;
36961       rmode = V8DImode;
36962       nargs_constant = 1;
36963       break;
36964     case V8DI_FTYPE_V8DI_V8DI_INT_V8DI_DI_CONVERT:
36965       nargs = 5;
36966       rmode = V8DImode;
36967       mask_pos = 2;
36968       nargs_constant = 1;
36969       break;
36970     case QI_FTYPE_V8DF_INT_QI:
36971     case QI_FTYPE_V4DF_INT_QI:
36972     case QI_FTYPE_V2DF_INT_QI:
36973     case HI_FTYPE_V16SF_INT_HI:
36974     case QI_FTYPE_V8SF_INT_QI:
36975     case QI_FTYPE_V4SF_INT_QI:
36976       nargs = 3;
36977       mask_pos = 1;
36978       nargs_constant = 1;
36979       break;
36980     case V4DI_FTYPE_V4DI_V4DI_INT_V4DI_SI_CONVERT:
36981       nargs = 5;
36982       rmode = V4DImode;
36983       mask_pos = 2;
36984       nargs_constant = 1;
36985       break;
36986     case V2DI_FTYPE_V2DI_V2DI_INT_V2DI_HI_CONVERT:
36987       nargs = 5;
36988       rmode = V2DImode;
36989       mask_pos = 2;
36990       nargs_constant = 1;
36991       break;
36992     case V32QI_FTYPE_V32QI_V32QI_V32QI_SI:
36993     case V32HI_FTYPE_V32HI_V32HI_V32HI_SI:
36994     case V32HI_FTYPE_V64QI_V64QI_V32HI_SI:
36995     case V16SI_FTYPE_V32HI_V32HI_V16SI_HI:
36996     case V64QI_FTYPE_V64QI_V64QI_V64QI_DI:
36997     case V32HI_FTYPE_V32HI_V8HI_V32HI_SI:
36998     case V16HI_FTYPE_V16HI_V8HI_V16HI_HI:
36999     case V8SI_FTYPE_V8SI_V4SI_V8SI_QI:
37000     case V4DI_FTYPE_V4DI_V2DI_V4DI_QI:
37001     case V64QI_FTYPE_V32HI_V32HI_V64QI_DI:
37002     case V32QI_FTYPE_V16HI_V16HI_V32QI_SI:
37003     case V16QI_FTYPE_V8HI_V8HI_V16QI_HI:
37004     case V32HI_FTYPE_V16SI_V16SI_V32HI_SI:
37005     case V16HI_FTYPE_V8SI_V8SI_V16HI_HI:
37006     case V8HI_FTYPE_V4SI_V4SI_V8HI_QI:
37007     case V4DF_FTYPE_V4DF_V4DI_V4DF_QI:
37008     case V8SF_FTYPE_V8SF_V8SI_V8SF_QI:
37009     case V4SF_FTYPE_V4SF_V4SI_V4SF_QI:
37010     case V2DF_FTYPE_V2DF_V2DI_V2DF_QI:
37011     case V2DI_FTYPE_V4SI_V4SI_V2DI_QI:
37012     case V4DI_FTYPE_V8SI_V8SI_V4DI_QI:
37013     case V4DF_FTYPE_V4DI_V4DF_V4DF_QI:
37014     case V8SF_FTYPE_V8SI_V8SF_V8SF_QI:
37015     case V2DF_FTYPE_V2DI_V2DF_V2DF_QI:
37016     case V4SF_FTYPE_V4SI_V4SF_V4SF_QI:
37017     case V16SF_FTYPE_V16SF_V16SF_V16SF_HI:
37018     case V16SF_FTYPE_V16SF_V16SI_V16SF_HI:
37019     case V16SF_FTYPE_V16SI_V16SF_V16SF_HI:
37020     case V16SI_FTYPE_V16SI_V16SI_V16SI_HI:
37021     case V16SI_FTYPE_V16SI_V4SI_V16SI_HI:
37022     case V8HI_FTYPE_V8HI_V8HI_V8HI_QI:
37023     case V8SI_FTYPE_V8SI_V8SI_V8SI_QI:
37024     case V4SI_FTYPE_V4SI_V4SI_V4SI_QI:
37025     case V8SF_FTYPE_V8SF_V8SF_V8SF_QI:
37026     case V16QI_FTYPE_V16QI_V16QI_V16QI_HI:
37027     case V16HI_FTYPE_V16HI_V16HI_V16HI_HI:
37028     case V2DI_FTYPE_V2DI_V2DI_V2DI_QI:
37029     case V2DF_FTYPE_V2DF_V2DF_V2DF_QI:
37030     case V2DF_FTYPE_V2DF_V4SF_V2DF_QI:
37031     case V4DI_FTYPE_V4DI_V4DI_V4DI_QI:
37032     case V4DF_FTYPE_V4DF_V4DF_V4DF_QI:
37033     case V4SF_FTYPE_V4SF_V2DF_V4SF_QI:
37034     case V4SF_FTYPE_V4SF_V4SF_V4SF_QI:
37035     case V8DF_FTYPE_V8DF_V8DF_V8DF_QI:
37036     case V8DF_FTYPE_V8DF_V8DI_V8DF_QI:
37037     case V8DF_FTYPE_V8DI_V8DF_V8DF_QI:
37038     case V8DI_FTYPE_V16SI_V16SI_V8DI_QI:
37039     case V8DI_FTYPE_V8DI_SI_V8DI_V8DI:
37040     case V8DI_FTYPE_V8DI_V2DI_V8DI_QI:
37041     case V8DI_FTYPE_V8DI_V8DI_V8DI_QI:
37042     case V8HI_FTYPE_V16QI_V16QI_V8HI_QI:
37043     case V16HI_FTYPE_V32QI_V32QI_V16HI_HI:
37044     case V8SI_FTYPE_V16HI_V16HI_V8SI_QI:
37045     case V4SI_FTYPE_V8HI_V8HI_V4SI_QI:
37046       nargs = 4;
37047       break;
37048     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
37049     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
37050     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
37051     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
37052     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT:
37053       nargs = 4;
37054       nargs_constant = 1;
37055       break;
37056     case QI_FTYPE_V4DI_V4DI_INT_QI:
37057     case QI_FTYPE_V8SI_V8SI_INT_QI:
37058     case QI_FTYPE_V4DF_V4DF_INT_QI:
37059     case QI_FTYPE_V8SF_V8SF_INT_QI:
37060     case QI_FTYPE_V2DI_V2DI_INT_QI:
37061     case QI_FTYPE_V4SI_V4SI_INT_QI:
37062     case QI_FTYPE_V2DF_V2DF_INT_QI:
37063     case QI_FTYPE_V4SF_V4SF_INT_QI:
37064     case DI_FTYPE_V64QI_V64QI_INT_DI:
37065     case SI_FTYPE_V32QI_V32QI_INT_SI:
37066     case HI_FTYPE_V16QI_V16QI_INT_HI:
37067     case SI_FTYPE_V32HI_V32HI_INT_SI:
37068     case HI_FTYPE_V16HI_V16HI_INT_HI:
37069     case QI_FTYPE_V8HI_V8HI_INT_QI:
37070       nargs = 4;
37071       mask_pos = 1;
37072       nargs_constant = 1;
37073       break;
37074     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
37075       nargs = 4;
37076       nargs_constant = 2;
37077       break;
37078     case UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED:
37079     case UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG:
37080       nargs = 4;
37081       break;
37082     case QI_FTYPE_V8DI_V8DI_INT_QI:
37083     case HI_FTYPE_V16SI_V16SI_INT_HI:
37084     case QI_FTYPE_V8DF_V8DF_INT_QI:
37085     case HI_FTYPE_V16SF_V16SF_INT_HI:
37086       mask_pos = 1;
37087       nargs = 4;
37088       nargs_constant = 1;
37089       break;
37090     case V8SF_FTYPE_V8SF_INT_V8SF_QI:
37091     case V4SF_FTYPE_V4SF_INT_V4SF_QI:
37092     case V2DF_FTYPE_V4DF_INT_V2DF_QI:
37093     case V2DI_FTYPE_V4DI_INT_V2DI_QI:
37094     case V8SF_FTYPE_V16SF_INT_V8SF_QI:
37095     case V8SI_FTYPE_V16SI_INT_V8SI_QI:
37096     case V2DF_FTYPE_V8DF_INT_V2DF_QI:
37097     case V2DI_FTYPE_V8DI_INT_V2DI_QI:
37098     case V4SF_FTYPE_V8SF_INT_V4SF_QI:
37099     case V4SI_FTYPE_V8SI_INT_V4SI_QI:
37100     case V8HI_FTYPE_V8SF_INT_V8HI_QI:
37101     case V8HI_FTYPE_V4SF_INT_V8HI_QI:
37102     case V32HI_FTYPE_V32HI_INT_V32HI_SI:
37103     case V16HI_FTYPE_V16HI_INT_V16HI_HI:
37104     case V8HI_FTYPE_V8HI_INT_V8HI_QI:
37105     case V4DI_FTYPE_V4DI_INT_V4DI_QI:
37106     case V2DI_FTYPE_V2DI_INT_V2DI_QI:
37107     case V8SI_FTYPE_V8SI_INT_V8SI_QI:
37108     case V4SI_FTYPE_V4SI_INT_V4SI_QI:
37109     case V4DF_FTYPE_V4DF_INT_V4DF_QI:
37110     case V2DF_FTYPE_V2DF_INT_V2DF_QI:
37111     case V8DF_FTYPE_V8DF_INT_V8DF_QI:
37112     case V16SF_FTYPE_V16SF_INT_V16SF_HI:
37113     case V16HI_FTYPE_V16SF_INT_V16HI_HI:
37114     case V16SI_FTYPE_V16SI_INT_V16SI_HI:
37115     case V4SI_FTYPE_V16SI_INT_V4SI_QI:
37116     case V4DI_FTYPE_V8DI_INT_V4DI_QI:
37117     case V4DF_FTYPE_V8DF_INT_V4DF_QI:
37118     case V4SF_FTYPE_V16SF_INT_V4SF_QI:
37119     case V8DI_FTYPE_V8DI_INT_V8DI_QI:
37120       nargs = 4;
37121       mask_pos = 2;
37122       nargs_constant = 1;
37123       break;
37124     case V16SF_FTYPE_V16SF_V4SF_INT_V16SF_HI:
37125     case V16SI_FTYPE_V16SI_V4SI_INT_V16SI_HI:
37126     case V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI:
37127     case V8DI_FTYPE_V8DI_V8DI_INT_V8DI_QI:
37128     case V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI:
37129     case V16SI_FTYPE_V16SI_V16SI_INT_V16SI_HI:
37130     case V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI:
37131     case V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI:
37132     case V8DF_FTYPE_V8DF_V4DF_INT_V8DF_QI:
37133     case V8DI_FTYPE_V8DI_V4DI_INT_V8DI_QI:
37134     case V4DF_FTYPE_V4DF_V4DF_INT_V4DF_QI:
37135     case V8SF_FTYPE_V8SF_V8SF_INT_V8SF_QI:
37136     case V8DF_FTYPE_V8DF_V2DF_INT_V8DF_QI:
37137     case V8DI_FTYPE_V8DI_V2DI_INT_V8DI_QI:
37138     case V8SI_FTYPE_V8SI_V8SI_INT_V8SI_QI:
37139     case V4DI_FTYPE_V4DI_V4DI_INT_V4DI_QI:
37140     case V4SI_FTYPE_V4SI_V4SI_INT_V4SI_QI:
37141     case V2DI_FTYPE_V2DI_V2DI_INT_V2DI_QI:
37142     case V32HI_FTYPE_V64QI_V64QI_INT_V32HI_SI:
37143     case V16HI_FTYPE_V32QI_V32QI_INT_V16HI_HI:
37144     case V8HI_FTYPE_V16QI_V16QI_INT_V8HI_QI:
37145     case V16SF_FTYPE_V16SF_V8SF_INT_V16SF_HI:
37146     case V16SI_FTYPE_V16SI_V8SI_INT_V16SI_HI:
37147     case V8SF_FTYPE_V8SF_V4SF_INT_V8SF_QI:
37148     case V8SI_FTYPE_V8SI_V4SI_INT_V8SI_QI:
37149     case V4DI_FTYPE_V4DI_V2DI_INT_V4DI_QI:
37150     case V4DF_FTYPE_V4DF_V2DF_INT_V4DF_QI:
37151       nargs = 5;
37152       mask_pos = 2;
37153       nargs_constant = 1;
37154       break;
37155     case V8DI_FTYPE_V8DI_V8DI_V8DI_INT_QI:
37156     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI:
37157     case V16SI_FTYPE_V16SI_V16SI_V16SI_INT_HI:
37158     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI:
37159     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI:
37160     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT_QI:
37161     case V8SI_FTYPE_V8SI_V8SI_V8SI_INT_QI:
37162     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT_QI:
37163     case V4DI_FTYPE_V4DI_V4DI_V4DI_INT_QI:
37164     case V4SI_FTYPE_V4SI_V4SI_V4SI_INT_QI:
37165     case V2DI_FTYPE_V2DI_V2DI_V2DI_INT_QI:
37166        nargs = 5;
37167       nargs = 5;
37168       mask_pos = 1;
37169       nargs_constant = 1;
37170       break;
37171
37172     default:
37173       gcc_unreachable ();
37174     }
37175
37176   gcc_assert (nargs <= ARRAY_SIZE (args));
37177
37178   if (comparison != UNKNOWN)
37179     {
37180       gcc_assert (nargs == 2);
37181       return ix86_expand_sse_compare (d, exp, target, swap);
37182     }
37183
37184   if (rmode == VOIDmode || rmode == tmode)
37185     {
37186       if (optimize
37187           || target == 0
37188           || GET_MODE (target) != tmode
37189           || !insn_p->operand[0].predicate (target, tmode))
37190         target = gen_reg_rtx (tmode);
37191       real_target = target;
37192     }
37193   else
37194     {
37195       real_target = gen_reg_rtx (tmode);
37196       target = simplify_gen_subreg (rmode, real_target, tmode, 0);
37197     }
37198
37199   for (i = 0; i < nargs; i++)
37200     {
37201       tree arg = CALL_EXPR_ARG (exp, i);
37202       rtx op = expand_normal (arg);
37203       machine_mode mode = insn_p->operand[i + 1].mode;
37204       bool match = insn_p->operand[i + 1].predicate (op, mode);
37205
37206       if (last_arg_count && (i + 1) == nargs)
37207         {
37208           /* SIMD shift insns take either an 8-bit immediate or
37209              register as count.  But builtin functions take int as
37210              count.  If count doesn't match, we put it in register.  */
37211           if (!match)
37212             {
37213               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
37214               if (!insn_p->operand[i + 1].predicate (op, mode))
37215                 op = copy_to_reg (op);
37216             }
37217         }
37218       else if ((mask_pos && (nargs - i - mask_pos) == nargs_constant) ||
37219                (!mask_pos && (nargs - i) <= nargs_constant))
37220         {
37221           if (!match)
37222             switch (icode)
37223               {
37224               case CODE_FOR_avx_vinsertf128v4di:
37225               case CODE_FOR_avx_vextractf128v4di:
37226                 error ("the last argument must be an 1-bit immediate");
37227                 return const0_rtx;
37228
37229               case CODE_FOR_avx512f_cmpv8di3_mask:
37230               case CODE_FOR_avx512f_cmpv16si3_mask:
37231               case CODE_FOR_avx512f_ucmpv8di3_mask:
37232               case CODE_FOR_avx512f_ucmpv16si3_mask:
37233               case CODE_FOR_avx512vl_cmpv4di3_mask:
37234               case CODE_FOR_avx512vl_cmpv8si3_mask:
37235               case CODE_FOR_avx512vl_ucmpv4di3_mask:
37236               case CODE_FOR_avx512vl_ucmpv8si3_mask:
37237               case CODE_FOR_avx512vl_cmpv2di3_mask:
37238               case CODE_FOR_avx512vl_cmpv4si3_mask:
37239               case CODE_FOR_avx512vl_ucmpv2di3_mask:
37240               case CODE_FOR_avx512vl_ucmpv4si3_mask:
37241                 error ("the last argument must be a 3-bit immediate");
37242                 return const0_rtx;
37243
37244               case CODE_FOR_sse4_1_roundsd:
37245               case CODE_FOR_sse4_1_roundss:
37246
37247               case CODE_FOR_sse4_1_roundpd:
37248               case CODE_FOR_sse4_1_roundps:
37249               case CODE_FOR_avx_roundpd256:
37250               case CODE_FOR_avx_roundps256:
37251
37252               case CODE_FOR_sse4_1_roundpd_vec_pack_sfix:
37253               case CODE_FOR_sse4_1_roundps_sfix:
37254               case CODE_FOR_avx_roundpd_vec_pack_sfix256:
37255               case CODE_FOR_avx_roundps_sfix256:
37256
37257               case CODE_FOR_sse4_1_blendps:
37258               case CODE_FOR_avx_blendpd256:
37259               case CODE_FOR_avx_vpermilv4df:
37260               case CODE_FOR_avx_vpermilv4df_mask:
37261               case CODE_FOR_avx512f_getmantv8df_mask:
37262               case CODE_FOR_avx512f_getmantv16sf_mask:
37263               case CODE_FOR_avx512vl_getmantv8sf_mask:
37264               case CODE_FOR_avx512vl_getmantv4df_mask:
37265               case CODE_FOR_avx512vl_getmantv4sf_mask:
37266               case CODE_FOR_avx512vl_getmantv2df_mask:
37267               case CODE_FOR_avx512dq_rangepv8df_mask_round:
37268               case CODE_FOR_avx512dq_rangepv16sf_mask_round:
37269               case CODE_FOR_avx512dq_rangepv4df_mask:
37270               case CODE_FOR_avx512dq_rangepv8sf_mask:
37271               case CODE_FOR_avx512dq_rangepv2df_mask:
37272               case CODE_FOR_avx512dq_rangepv4sf_mask:
37273               case CODE_FOR_avx_shufpd256_mask:
37274                 error ("the last argument must be a 4-bit immediate");
37275                 return const0_rtx;
37276
37277               case CODE_FOR_sha1rnds4:
37278               case CODE_FOR_sse4_1_blendpd:
37279               case CODE_FOR_avx_vpermilv2df:
37280               case CODE_FOR_avx_vpermilv2df_mask:
37281               case CODE_FOR_xop_vpermil2v2df3:
37282               case CODE_FOR_xop_vpermil2v4sf3:
37283               case CODE_FOR_xop_vpermil2v4df3:
37284               case CODE_FOR_xop_vpermil2v8sf3:
37285               case CODE_FOR_avx512f_vinsertf32x4_mask:
37286               case CODE_FOR_avx512f_vinserti32x4_mask:
37287               case CODE_FOR_avx512f_vextractf32x4_mask:
37288               case CODE_FOR_avx512f_vextracti32x4_mask:
37289               case CODE_FOR_sse2_shufpd:
37290               case CODE_FOR_sse2_shufpd_mask:
37291               case CODE_FOR_avx512dq_shuf_f64x2_mask:
37292               case CODE_FOR_avx512dq_shuf_i64x2_mask:
37293               case CODE_FOR_avx512vl_shuf_i32x4_mask:
37294               case CODE_FOR_avx512vl_shuf_f32x4_mask:
37295                 error ("the last argument must be a 2-bit immediate");
37296                 return const0_rtx;
37297
37298               case CODE_FOR_avx_vextractf128v4df:
37299               case CODE_FOR_avx_vextractf128v8sf:
37300               case CODE_FOR_avx_vextractf128v8si:
37301               case CODE_FOR_avx_vinsertf128v4df:
37302               case CODE_FOR_avx_vinsertf128v8sf:
37303               case CODE_FOR_avx_vinsertf128v8si:
37304               case CODE_FOR_avx512f_vinsertf64x4_mask:
37305               case CODE_FOR_avx512f_vinserti64x4_mask:
37306               case CODE_FOR_avx512f_vextractf64x4_mask:
37307               case CODE_FOR_avx512f_vextracti64x4_mask:
37308               case CODE_FOR_avx512dq_vinsertf32x8_mask:
37309               case CODE_FOR_avx512dq_vinserti32x8_mask:
37310               case CODE_FOR_avx512vl_vinsertv4df:
37311               case CODE_FOR_avx512vl_vinsertv4di:
37312               case CODE_FOR_avx512vl_vinsertv8sf:
37313               case CODE_FOR_avx512vl_vinsertv8si:
37314                 error ("the last argument must be a 1-bit immediate");
37315                 return const0_rtx;
37316
37317               case CODE_FOR_avx_vmcmpv2df3:
37318               case CODE_FOR_avx_vmcmpv4sf3:
37319               case CODE_FOR_avx_cmpv2df3:
37320               case CODE_FOR_avx_cmpv4sf3:
37321               case CODE_FOR_avx_cmpv4df3:
37322               case CODE_FOR_avx_cmpv8sf3:
37323               case CODE_FOR_avx512f_cmpv8df3_mask:
37324               case CODE_FOR_avx512f_cmpv16sf3_mask:
37325               case CODE_FOR_avx512f_vmcmpv2df3_mask:
37326               case CODE_FOR_avx512f_vmcmpv4sf3_mask:
37327                 error ("the last argument must be a 5-bit immediate");
37328                 return const0_rtx;
37329
37330               default:
37331                 switch (nargs_constant)
37332                   {
37333                   case 2:
37334                     if ((mask_pos && (nargs - i - mask_pos) == nargs_constant) ||
37335                         (!mask_pos && (nargs - i) == nargs_constant))
37336                       {
37337                         error ("the next to last argument must be an 8-bit immediate");
37338                         break;
37339                       }
37340                   case 1:
37341                     error ("the last argument must be an 8-bit immediate");
37342                     break;
37343                   default:
37344                     gcc_unreachable ();
37345                   }
37346                 return const0_rtx;
37347               }
37348         }
37349       else
37350         {
37351           if (VECTOR_MODE_P (mode))
37352             op = safe_vector_operand (op, mode);
37353
37354           /* If we aren't optimizing, only allow one memory operand to
37355              be generated.  */
37356           if (memory_operand (op, mode))
37357             num_memory++;
37358
37359           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
37360             {
37361               if (optimize || !match || num_memory > 1)
37362                 op = copy_to_mode_reg (mode, op);
37363             }
37364           else
37365             {
37366               op = copy_to_reg (op);
37367               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
37368             }
37369         }
37370
37371       args[i].op = op;
37372       args[i].mode = mode;
37373     }
37374
37375   switch (nargs)
37376     {
37377     case 1:
37378       pat = GEN_FCN (icode) (real_target, args[0].op);
37379       break;
37380     case 2:
37381       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
37382       break;
37383     case 3:
37384       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37385                              args[2].op);
37386       break;
37387     case 4:
37388       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37389                              args[2].op, args[3].op);
37390       break;
37391     case 5:
37392       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37393                              args[2].op, args[3].op, args[4].op);
37394     case 6:
37395       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37396                              args[2].op, args[3].op, args[4].op,
37397                              args[5].op);
37398       break;
37399     default:
37400       gcc_unreachable ();
37401     }
37402
37403   if (! pat)
37404     return 0;
37405
37406   emit_insn (pat);
37407   return target;
37408 }
37409
37410 /* Transform pattern of following layout:
37411      (parallel [
37412        set (A B)
37413        (unspec [C] UNSPEC_EMBEDDED_ROUNDING)])
37414      ])
37415    into:
37416      (set (A B))
37417
37418    Or:
37419      (parallel [ A B
37420      ...
37421      (unspec [C] UNSPEC_EMBEDDED_ROUNDING)
37422      ...
37423      ])
37424    into:
37425      (parallel [ A B ... ])  */
37426
37427 static rtx
37428 ix86_erase_embedded_rounding (rtx pat)
37429 {
37430   if (GET_CODE (pat) == INSN)
37431     pat = PATTERN (pat);
37432
37433   gcc_assert (GET_CODE (pat) == PARALLEL);
37434
37435   if (XVECLEN (pat, 0) == 2)
37436     {
37437       rtx p0 = XVECEXP (pat, 0, 0);
37438       rtx p1 = XVECEXP (pat, 0, 1);
37439
37440       gcc_assert (GET_CODE (p0) == SET
37441                   && GET_CODE (p1) == UNSPEC
37442                   && XINT (p1, 1) == UNSPEC_EMBEDDED_ROUNDING);
37443
37444       return p0;
37445     }
37446   else
37447     {
37448       rtx *res = XALLOCAVEC (rtx, XVECLEN (pat, 0));
37449       int i = 0;
37450       int j = 0;
37451
37452       for (; i < XVECLEN (pat, 0); ++i)
37453         {
37454           rtx elem = XVECEXP (pat, 0, i);
37455           if (GET_CODE (elem) != UNSPEC
37456               || XINT (elem, 1) != UNSPEC_EMBEDDED_ROUNDING)
37457             res [j++] = elem;
37458         }
37459
37460       /*  No more than 1 occurence was removed.  */
37461       gcc_assert (j >= XVECLEN (pat, 0) - 1);
37462
37463       return gen_rtx_PARALLEL (GET_MODE (pat), gen_rtvec_v (j, res));
37464     }
37465 }
37466
37467 /* Subroutine of ix86_expand_round_builtin to take care of comi insns
37468    with rounding.  */
37469 static rtx
37470 ix86_expand_sse_comi_round (const struct builtin_description *d,
37471                             tree exp, rtx target)
37472 {
37473   rtx pat, set_dst;
37474   tree arg0 = CALL_EXPR_ARG (exp, 0);
37475   tree arg1 = CALL_EXPR_ARG (exp, 1);
37476   tree arg2 = CALL_EXPR_ARG (exp, 2);
37477   tree arg3 = CALL_EXPR_ARG (exp, 3);
37478   rtx op0 = expand_normal (arg0);
37479   rtx op1 = expand_normal (arg1);
37480   rtx op2 = expand_normal (arg2);
37481   rtx op3 = expand_normal (arg3);
37482   enum insn_code icode = d->icode;
37483   const struct insn_data_d *insn_p = &insn_data[icode];
37484   machine_mode mode0 = insn_p->operand[0].mode;
37485   machine_mode mode1 = insn_p->operand[1].mode;
37486   enum rtx_code comparison = UNEQ;
37487   bool need_ucomi = false;
37488
37489   /* See avxintrin.h for values.  */
37490   enum rtx_code comi_comparisons[32] =
37491     {
37492       UNEQ, GT, GE, UNORDERED, LTGT, UNLE, UNLT, ORDERED, UNEQ, UNLT,
37493       UNLE, LT, LTGT, GE, GT, LT, UNEQ, GT, GE, UNORDERED, LTGT, UNLE,
37494       UNLT, ORDERED, UNEQ, UNLT, UNLE, LT, LTGT, GE, GT, LT
37495     };
37496   bool need_ucomi_values[32] =
37497     {
37498       true,  false, false, true,  true,  false, false, true,
37499       true,  false, false, true,  true,  false, false, true,
37500       false, true,  true,  false, false, true,  true,  false,
37501       false, true,  true,  false, false, true,  true,  false
37502     };
37503
37504   if (!CONST_INT_P (op2))
37505     {
37506       error ("the third argument must be comparison constant");
37507       return const0_rtx;
37508     }
37509   if (INTVAL (op2) < 0 || INTVAL (op2) >= 32)
37510     {
37511       error ("incorect comparison mode");
37512       return const0_rtx;
37513     }
37514
37515   if (!insn_p->operand[2].predicate (op3, SImode))
37516     {
37517       error ("incorrect rounding operand");
37518       return const0_rtx;
37519     }
37520
37521   comparison = comi_comparisons[INTVAL (op2)];
37522   need_ucomi = need_ucomi_values[INTVAL (op2)];
37523
37524   if (VECTOR_MODE_P (mode0))
37525     op0 = safe_vector_operand (op0, mode0);
37526   if (VECTOR_MODE_P (mode1))
37527     op1 = safe_vector_operand (op1, mode1);
37528
37529   target = gen_reg_rtx (SImode);
37530   emit_move_insn (target, const0_rtx);
37531   target = gen_rtx_SUBREG (QImode, target, 0);
37532
37533   if ((optimize && !register_operand (op0, mode0))
37534       || !insn_p->operand[0].predicate (op0, mode0))
37535     op0 = copy_to_mode_reg (mode0, op0);
37536   if ((optimize && !register_operand (op1, mode1))
37537       || !insn_p->operand[1].predicate (op1, mode1))
37538     op1 = copy_to_mode_reg (mode1, op1);
37539
37540   if (need_ucomi)
37541     icode = icode == CODE_FOR_sse_comi_round
37542                      ? CODE_FOR_sse_ucomi_round
37543                      : CODE_FOR_sse2_ucomi_round;
37544
37545   pat = GEN_FCN (icode) (op0, op1, op3);
37546   if (! pat)
37547     return 0;
37548
37549   /* Rounding operand can be either NO_ROUND or ROUND_SAE at this point.  */
37550   if (INTVAL (op3) == NO_ROUND)
37551     {
37552       pat = ix86_erase_embedded_rounding (pat);
37553       if (! pat)
37554         return 0;
37555
37556       set_dst = SET_DEST (pat);
37557     }
37558   else
37559     {
37560       gcc_assert (GET_CODE (XVECEXP (pat, 0, 0)) == SET);
37561       set_dst = SET_DEST (XVECEXP (pat, 0, 0));
37562     }
37563
37564   emit_insn (pat);
37565   emit_insn (gen_rtx_SET (VOIDmode,
37566                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
37567                           gen_rtx_fmt_ee (comparison, QImode,
37568                                           set_dst,
37569                                           const0_rtx)));
37570
37571   return SUBREG_REG (target);
37572 }
37573
37574 static rtx
37575 ix86_expand_round_builtin (const struct builtin_description *d,
37576                            tree exp, rtx target)
37577 {
37578   rtx pat;
37579   unsigned int i, nargs;
37580   struct
37581     {
37582       rtx op;
37583       machine_mode mode;
37584     } args[6];
37585   enum insn_code icode = d->icode;
37586   const struct insn_data_d *insn_p = &insn_data[icode];
37587   machine_mode tmode = insn_p->operand[0].mode;
37588   unsigned int nargs_constant = 0;
37589   unsigned int redundant_embed_rnd = 0;
37590
37591   switch ((enum ix86_builtin_func_type) d->flag)
37592     {
37593     case UINT64_FTYPE_V2DF_INT:
37594     case UINT64_FTYPE_V4SF_INT:
37595     case UINT_FTYPE_V2DF_INT:
37596     case UINT_FTYPE_V4SF_INT:
37597     case INT64_FTYPE_V2DF_INT:
37598     case INT64_FTYPE_V4SF_INT:
37599     case INT_FTYPE_V2DF_INT:
37600     case INT_FTYPE_V4SF_INT:
37601       nargs = 2;
37602       break;
37603     case V4SF_FTYPE_V4SF_UINT_INT:
37604     case V4SF_FTYPE_V4SF_UINT64_INT:
37605     case V2DF_FTYPE_V2DF_UINT64_INT:
37606     case V4SF_FTYPE_V4SF_INT_INT:
37607     case V4SF_FTYPE_V4SF_INT64_INT:
37608     case V2DF_FTYPE_V2DF_INT64_INT:
37609     case V4SF_FTYPE_V4SF_V4SF_INT:
37610     case V2DF_FTYPE_V2DF_V2DF_INT:
37611     case V4SF_FTYPE_V4SF_V2DF_INT:
37612     case V2DF_FTYPE_V2DF_V4SF_INT:
37613       nargs = 3;
37614       break;
37615     case V8SF_FTYPE_V8DF_V8SF_QI_INT:
37616     case V8DF_FTYPE_V8DF_V8DF_QI_INT:
37617     case V8SI_FTYPE_V8DF_V8SI_QI_INT:
37618     case V8DI_FTYPE_V8DF_V8DI_QI_INT:
37619     case V8SF_FTYPE_V8DI_V8SF_QI_INT:
37620     case V8DF_FTYPE_V8DI_V8DF_QI_INT:
37621     case V16SF_FTYPE_V16SF_V16SF_HI_INT:
37622     case V8DI_FTYPE_V8SF_V8DI_QI_INT:
37623     case V16SF_FTYPE_V16SI_V16SF_HI_INT:
37624     case V16SI_FTYPE_V16SF_V16SI_HI_INT:
37625     case V8DF_FTYPE_V8SF_V8DF_QI_INT:
37626     case V16SF_FTYPE_V16HI_V16SF_HI_INT:
37627     case V2DF_FTYPE_V2DF_V2DF_V2DF_INT:
37628     case V4SF_FTYPE_V4SF_V4SF_V4SF_INT:
37629       nargs = 4;
37630       break;
37631     case V4SF_FTYPE_V4SF_V4SF_INT_INT:
37632     case V2DF_FTYPE_V2DF_V2DF_INT_INT:
37633       nargs_constant = 2;
37634       nargs = 4;
37635       break;
37636     case INT_FTYPE_V4SF_V4SF_INT_INT:
37637     case INT_FTYPE_V2DF_V2DF_INT_INT:
37638       return ix86_expand_sse_comi_round (d, exp, target);
37639     case V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT:
37640     case V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT:
37641     case V2DF_FTYPE_V2DF_V2DF_V2DF_QI_INT:
37642     case V2DF_FTYPE_V2DF_V4SF_V2DF_QI_INT:
37643     case V4SF_FTYPE_V4SF_V4SF_V4SF_QI_INT:
37644     case V4SF_FTYPE_V4SF_V2DF_V4SF_QI_INT:
37645       nargs = 5;
37646       break;
37647     case V16SF_FTYPE_V16SF_INT_V16SF_HI_INT:
37648     case V8DF_FTYPE_V8DF_INT_V8DF_QI_INT:
37649       nargs_constant = 4;
37650       nargs = 5;
37651       break;
37652     case QI_FTYPE_V8DF_V8DF_INT_QI_INT:
37653     case QI_FTYPE_V2DF_V2DF_INT_QI_INT:
37654     case HI_FTYPE_V16SF_V16SF_INT_HI_INT:
37655     case QI_FTYPE_V4SF_V4SF_INT_QI_INT:
37656       nargs_constant = 3;
37657       nargs = 5;
37658       break;
37659     case V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI_INT:
37660     case V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI_INT:
37661     case V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI_INT:
37662     case V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI_INT:
37663       nargs = 6;
37664       nargs_constant = 4;
37665       break;
37666     case V8DF_FTYPE_V8DF_V8DF_V8DI_INT_QI_INT:
37667     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI_INT:
37668     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI_INT:
37669     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI_INT:
37670       nargs = 6;
37671       nargs_constant = 3;
37672       break;
37673     default:
37674       gcc_unreachable ();
37675     }
37676   gcc_assert (nargs <= ARRAY_SIZE (args));
37677
37678   if (optimize
37679       || target == 0
37680       || GET_MODE (target) != tmode
37681       || !insn_p->operand[0].predicate (target, tmode))
37682     target = gen_reg_rtx (tmode);
37683
37684   for (i = 0; i < nargs; i++)
37685     {
37686       tree arg = CALL_EXPR_ARG (exp, i);
37687       rtx op = expand_normal (arg);
37688       machine_mode mode = insn_p->operand[i + 1].mode;
37689       bool match = insn_p->operand[i + 1].predicate (op, mode);
37690
37691       if (i == nargs - nargs_constant)
37692         {
37693           if (!match)
37694             {
37695               switch (icode)
37696                 {
37697                 case CODE_FOR_avx512f_getmantv8df_mask_round:
37698                 case CODE_FOR_avx512f_getmantv16sf_mask_round:
37699                 case CODE_FOR_avx512f_vgetmantv2df_round:
37700                 case CODE_FOR_avx512f_vgetmantv4sf_round:
37701                   error ("the immediate argument must be a 4-bit immediate");
37702                   return const0_rtx;
37703                 case CODE_FOR_avx512f_cmpv8df3_mask_round:
37704                 case CODE_FOR_avx512f_cmpv16sf3_mask_round:
37705                 case CODE_FOR_avx512f_vmcmpv2df3_mask_round:
37706                 case CODE_FOR_avx512f_vmcmpv4sf3_mask_round:
37707                   error ("the immediate argument must be a 5-bit immediate");
37708                   return const0_rtx;
37709                 default:
37710                   error ("the immediate argument must be an 8-bit immediate");
37711                   return const0_rtx;
37712                 }
37713             }
37714         }
37715       else if (i == nargs-1)
37716         {
37717           if (!insn_p->operand[nargs].predicate (op, SImode))
37718             {
37719               error ("incorrect rounding operand");
37720               return const0_rtx;
37721             }
37722
37723           /* If there is no rounding use normal version of the pattern.  */
37724           if (INTVAL (op) == NO_ROUND)
37725             redundant_embed_rnd = 1;
37726         }
37727       else
37728         {
37729           if (VECTOR_MODE_P (mode))
37730             op = safe_vector_operand (op, mode);
37731
37732           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
37733             {
37734               if (optimize || !match)
37735                 op = copy_to_mode_reg (mode, op);
37736             }
37737           else
37738             {
37739               op = copy_to_reg (op);
37740               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
37741             }
37742         }
37743
37744       args[i].op = op;
37745       args[i].mode = mode;
37746     }
37747
37748   switch (nargs)
37749     {
37750     case 1:
37751       pat = GEN_FCN (icode) (target, args[0].op);
37752       break;
37753     case 2:
37754       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
37755       break;
37756     case 3:
37757       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37758                              args[2].op);
37759       break;
37760     case 4:
37761       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37762                              args[2].op, args[3].op);
37763       break;
37764     case 5:
37765       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37766                              args[2].op, args[3].op, args[4].op);
37767     case 6:
37768       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37769                              args[2].op, args[3].op, args[4].op,
37770                              args[5].op);
37771       break;
37772     default:
37773       gcc_unreachable ();
37774     }
37775
37776   if (!pat)
37777     return 0;
37778
37779   if (redundant_embed_rnd)
37780     pat = ix86_erase_embedded_rounding (pat);
37781
37782   emit_insn (pat);
37783   return target;
37784 }
37785
37786 /* Subroutine of ix86_expand_builtin to take care of special insns
37787    with variable number of operands.  */
37788
37789 static rtx
37790 ix86_expand_special_args_builtin (const struct builtin_description *d,
37791                                   tree exp, rtx target)
37792 {
37793   tree arg;
37794   rtx pat, op;
37795   unsigned int i, nargs, arg_adjust, memory;
37796   bool aligned_mem = false;
37797   struct
37798     {
37799       rtx op;
37800       machine_mode mode;
37801     } args[3];
37802   enum insn_code icode = d->icode;
37803   bool last_arg_constant = false;
37804   const struct insn_data_d *insn_p = &insn_data[icode];
37805   machine_mode tmode = insn_p->operand[0].mode;
37806   enum { load, store } klass;
37807
37808   switch ((enum ix86_builtin_func_type) d->flag)
37809     {
37810     case VOID_FTYPE_VOID:
37811       emit_insn (GEN_FCN (icode) (target));
37812       return 0;
37813     case VOID_FTYPE_UINT64:
37814     case VOID_FTYPE_UNSIGNED:
37815       nargs = 0;
37816       klass = store;
37817       memory = 0;
37818       break;
37819
37820     case INT_FTYPE_VOID:
37821     case USHORT_FTYPE_VOID:
37822     case UINT64_FTYPE_VOID:
37823     case UNSIGNED_FTYPE_VOID:
37824       nargs = 0;
37825       klass = load;
37826       memory = 0;
37827       break;
37828     case UINT64_FTYPE_PUNSIGNED:
37829     case V2DI_FTYPE_PV2DI:
37830     case V4DI_FTYPE_PV4DI:
37831     case V32QI_FTYPE_PCCHAR:
37832     case V16QI_FTYPE_PCCHAR:
37833     case V8SF_FTYPE_PCV4SF:
37834     case V8SF_FTYPE_PCFLOAT:
37835     case V4SF_FTYPE_PCFLOAT:
37836     case V4DF_FTYPE_PCV2DF:
37837     case V4DF_FTYPE_PCDOUBLE:
37838     case V2DF_FTYPE_PCDOUBLE:
37839     case VOID_FTYPE_PVOID:
37840     case V16SI_FTYPE_PV4SI:
37841     case V16SF_FTYPE_PV4SF:
37842     case V8DI_FTYPE_PV4DI:
37843     case V8DI_FTYPE_PV8DI:
37844     case V8DF_FTYPE_PV4DF:
37845       nargs = 1;
37846       klass = load;
37847       memory = 0;
37848       switch (icode)
37849         {
37850         case CODE_FOR_sse4_1_movntdqa:
37851         case CODE_FOR_avx2_movntdqa:
37852         case CODE_FOR_avx512f_movntdqa:
37853           aligned_mem = true;
37854           break;
37855         default:
37856           break;
37857         }
37858       break;
37859     case VOID_FTYPE_PV2SF_V4SF:
37860     case VOID_FTYPE_PV8DI_V8DI:
37861     case VOID_FTYPE_PV4DI_V4DI:
37862     case VOID_FTYPE_PV2DI_V2DI:
37863     case VOID_FTYPE_PCHAR_V32QI:
37864     case VOID_FTYPE_PCHAR_V16QI:
37865     case VOID_FTYPE_PFLOAT_V16SF:
37866     case VOID_FTYPE_PFLOAT_V8SF:
37867     case VOID_FTYPE_PFLOAT_V4SF:
37868     case VOID_FTYPE_PDOUBLE_V8DF:
37869     case VOID_FTYPE_PDOUBLE_V4DF:
37870     case VOID_FTYPE_PDOUBLE_V2DF:
37871     case VOID_FTYPE_PLONGLONG_LONGLONG:
37872     case VOID_FTYPE_PULONGLONG_ULONGLONG:
37873     case VOID_FTYPE_PINT_INT:
37874       nargs = 1;
37875       klass = store;
37876       /* Reserve memory operand for target.  */
37877       memory = ARRAY_SIZE (args);
37878       switch (icode)
37879         {
37880         /* These builtins and instructions require the memory
37881            to be properly aligned.  */
37882         case CODE_FOR_avx_movntv4di:
37883         case CODE_FOR_sse2_movntv2di:
37884         case CODE_FOR_avx_movntv8sf:
37885         case CODE_FOR_sse_movntv4sf:
37886         case CODE_FOR_sse4a_vmmovntv4sf:
37887         case CODE_FOR_avx_movntv4df:
37888         case CODE_FOR_sse2_movntv2df:
37889         case CODE_FOR_sse4a_vmmovntv2df:
37890         case CODE_FOR_sse2_movntidi:
37891         case CODE_FOR_sse_movntq:
37892         case CODE_FOR_sse2_movntisi:
37893         case CODE_FOR_avx512f_movntv16sf:
37894         case CODE_FOR_avx512f_movntv8df:
37895         case CODE_FOR_avx512f_movntv8di:
37896           aligned_mem = true;
37897           break;
37898         default:
37899           break;
37900         }
37901       break;
37902     case V4SF_FTYPE_V4SF_PCV2SF:
37903     case V2DF_FTYPE_V2DF_PCDOUBLE:
37904       nargs = 2;
37905       klass = load;
37906       memory = 1;
37907       break;
37908     case V8SF_FTYPE_PCV8SF_V8SI:
37909     case V4DF_FTYPE_PCV4DF_V4DI:
37910     case V4SF_FTYPE_PCV4SF_V4SI:
37911     case V2DF_FTYPE_PCV2DF_V2DI:
37912     case V8SI_FTYPE_PCV8SI_V8SI:
37913     case V4DI_FTYPE_PCV4DI_V4DI:
37914     case V4SI_FTYPE_PCV4SI_V4SI:
37915     case V2DI_FTYPE_PCV2DI_V2DI:
37916       nargs = 2;
37917       klass = load;
37918       memory = 0;
37919       break;
37920     case VOID_FTYPE_PV8DF_V8DF_QI:
37921     case VOID_FTYPE_PV16SF_V16SF_HI:
37922     case VOID_FTYPE_PV8DI_V8DI_QI:
37923     case VOID_FTYPE_PV4DI_V4DI_QI:
37924     case VOID_FTYPE_PV2DI_V2DI_QI:
37925     case VOID_FTYPE_PV16SI_V16SI_HI:
37926     case VOID_FTYPE_PV8SI_V8SI_QI:
37927     case VOID_FTYPE_PV4SI_V4SI_QI:
37928       switch (icode)
37929         {
37930         /* These builtins and instructions require the memory
37931            to be properly aligned.  */
37932         case CODE_FOR_avx512f_storev16sf_mask:
37933         case CODE_FOR_avx512f_storev16si_mask:
37934         case CODE_FOR_avx512f_storev8df_mask:
37935         case CODE_FOR_avx512f_storev8di_mask:
37936         case CODE_FOR_avx512vl_storev8sf_mask:
37937         case CODE_FOR_avx512vl_storev8si_mask:
37938         case CODE_FOR_avx512vl_storev4df_mask:
37939         case CODE_FOR_avx512vl_storev4di_mask:
37940         case CODE_FOR_avx512vl_storev4sf_mask:
37941         case CODE_FOR_avx512vl_storev4si_mask:
37942         case CODE_FOR_avx512vl_storev2df_mask:
37943         case CODE_FOR_avx512vl_storev2di_mask:
37944           aligned_mem = true;
37945           break;
37946         default:
37947           break;
37948         }
37949       /* FALLTHRU */
37950     case VOID_FTYPE_PV8SF_V8SI_V8SF:
37951     case VOID_FTYPE_PV4DF_V4DI_V4DF:
37952     case VOID_FTYPE_PV4SF_V4SI_V4SF:
37953     case VOID_FTYPE_PV2DF_V2DI_V2DF:
37954     case VOID_FTYPE_PV8SI_V8SI_V8SI:
37955     case VOID_FTYPE_PV4DI_V4DI_V4DI:
37956     case VOID_FTYPE_PV4SI_V4SI_V4SI:
37957     case VOID_FTYPE_PV2DI_V2DI_V2DI:
37958     case VOID_FTYPE_PDOUBLE_V2DF_QI:
37959     case VOID_FTYPE_PFLOAT_V4SF_QI:
37960     case VOID_FTYPE_PV8SI_V8DI_QI:
37961     case VOID_FTYPE_PV8HI_V8DI_QI:
37962     case VOID_FTYPE_PV16HI_V16SI_HI:
37963     case VOID_FTYPE_PV16QI_V8DI_QI:
37964     case VOID_FTYPE_PV16QI_V16SI_HI:
37965     case VOID_FTYPE_PV4SI_V4DI_QI:
37966     case VOID_FTYPE_PV4SI_V2DI_QI:
37967     case VOID_FTYPE_PV8HI_V4DI_QI:
37968     case VOID_FTYPE_PV8HI_V2DI_QI:
37969     case VOID_FTYPE_PV8HI_V8SI_QI:
37970     case VOID_FTYPE_PV8HI_V4SI_QI:
37971     case VOID_FTYPE_PV16QI_V4DI_QI:
37972     case VOID_FTYPE_PV16QI_V2DI_QI:
37973     case VOID_FTYPE_PV16QI_V8SI_QI:
37974     case VOID_FTYPE_PV16QI_V4SI_QI:
37975     case VOID_FTYPE_PV8HI_V8HI_QI:
37976     case VOID_FTYPE_PV16HI_V16HI_HI:
37977     case VOID_FTYPE_PV32HI_V32HI_SI:
37978     case VOID_FTYPE_PV16QI_V16QI_HI:
37979     case VOID_FTYPE_PV32QI_V32QI_SI:
37980     case VOID_FTYPE_PV64QI_V64QI_DI:
37981     case VOID_FTYPE_PV4DF_V4DF_QI:
37982     case VOID_FTYPE_PV2DF_V2DF_QI:
37983     case VOID_FTYPE_PV8SF_V8SF_QI:
37984     case VOID_FTYPE_PV4SF_V4SF_QI:
37985       nargs = 2;
37986       klass = store;
37987       /* Reserve memory operand for target.  */
37988       memory = ARRAY_SIZE (args);
37989       break;
37990     case V4SF_FTYPE_PCV4SF_V4SF_QI:
37991     case V8SF_FTYPE_PCV8SF_V8SF_QI:
37992     case V16SF_FTYPE_PCV16SF_V16SF_HI:
37993     case V4SI_FTYPE_PCV4SI_V4SI_QI:
37994     case V8SI_FTYPE_PCV8SI_V8SI_QI:
37995     case V16SI_FTYPE_PCV16SI_V16SI_HI:
37996     case V2DF_FTYPE_PCV2DF_V2DF_QI:
37997     case V4DF_FTYPE_PCV4DF_V4DF_QI:
37998     case V8DF_FTYPE_PCV8DF_V8DF_QI:
37999     case V2DI_FTYPE_PCV2DI_V2DI_QI:
38000     case V4DI_FTYPE_PCV4DI_V4DI_QI:
38001     case V8DI_FTYPE_PCV8DI_V8DI_QI:
38002     case V2DF_FTYPE_PCDOUBLE_V2DF_QI:
38003     case V4SF_FTYPE_PCFLOAT_V4SF_QI:
38004     case V8HI_FTYPE_PCV8HI_V8HI_QI:
38005     case V16HI_FTYPE_PCV16HI_V16HI_HI:
38006     case V32HI_FTYPE_PCV32HI_V32HI_SI:
38007     case V16QI_FTYPE_PCV16QI_V16QI_HI:
38008     case V32QI_FTYPE_PCV32QI_V32QI_SI:
38009     case V64QI_FTYPE_PCV64QI_V64QI_DI:
38010       nargs = 3;
38011       klass = load;
38012       memory = 0;
38013       switch (icode)
38014         {
38015         /* These builtins and instructions require the memory
38016            to be properly aligned.  */
38017         case CODE_FOR_avx512f_loadv16sf_mask:
38018         case CODE_FOR_avx512f_loadv16si_mask:
38019         case CODE_FOR_avx512f_loadv8df_mask:
38020         case CODE_FOR_avx512f_loadv8di_mask:
38021         case CODE_FOR_avx512vl_loadv8sf_mask:
38022         case CODE_FOR_avx512vl_loadv8si_mask:
38023         case CODE_FOR_avx512vl_loadv4df_mask:
38024         case CODE_FOR_avx512vl_loadv4di_mask:
38025         case CODE_FOR_avx512vl_loadv4sf_mask:
38026         case CODE_FOR_avx512vl_loadv4si_mask:
38027         case CODE_FOR_avx512vl_loadv2df_mask:
38028         case CODE_FOR_avx512vl_loadv2di_mask:
38029         case CODE_FOR_avx512bw_loadv64qi_mask:
38030         case CODE_FOR_avx512vl_loadv32qi_mask:
38031         case CODE_FOR_avx512vl_loadv16qi_mask:
38032         case CODE_FOR_avx512bw_loadv32hi_mask:
38033         case CODE_FOR_avx512vl_loadv16hi_mask:
38034         case CODE_FOR_avx512vl_loadv8hi_mask:
38035           aligned_mem = true;
38036           break;
38037         default:
38038           break;
38039         }
38040       break;
38041     case VOID_FTYPE_UINT_UINT_UINT:
38042     case VOID_FTYPE_UINT64_UINT_UINT:
38043     case UCHAR_FTYPE_UINT_UINT_UINT:
38044     case UCHAR_FTYPE_UINT64_UINT_UINT:
38045       nargs = 3;
38046       klass = load;
38047       memory = ARRAY_SIZE (args);
38048       last_arg_constant = true;
38049       break;
38050     default:
38051       gcc_unreachable ();
38052     }
38053
38054   gcc_assert (nargs <= ARRAY_SIZE (args));
38055
38056   if (klass == store)
38057     {
38058       arg = CALL_EXPR_ARG (exp, 0);
38059       op = expand_normal (arg);
38060       gcc_assert (target == 0);
38061       if (memory)
38062         {
38063           op = ix86_zero_extend_to_Pmode (op);
38064           target = gen_rtx_MEM (tmode, op);
38065           /* target at this point has just BITS_PER_UNIT MEM_ALIGN
38066              on it.  Try to improve it using get_pointer_alignment,
38067              and if the special builtin is one that requires strict
38068              mode alignment, also from it's GET_MODE_ALIGNMENT.
38069              Failure to do so could lead to ix86_legitimate_combined_insn
38070              rejecting all changes to such insns.  */
38071           unsigned int align = get_pointer_alignment (arg);
38072           if (aligned_mem && align < GET_MODE_ALIGNMENT (tmode))
38073             align = GET_MODE_ALIGNMENT (tmode);
38074           if (MEM_ALIGN (target) < align)
38075             set_mem_align (target, align);
38076         }
38077       else
38078         target = force_reg (tmode, op);
38079       arg_adjust = 1;
38080     }
38081   else
38082     {
38083       arg_adjust = 0;
38084       if (optimize
38085           || target == 0
38086           || !register_operand (target, tmode)
38087           || GET_MODE (target) != tmode)
38088         target = gen_reg_rtx (tmode);
38089     }
38090
38091   for (i = 0; i < nargs; i++)
38092     {
38093       machine_mode mode = insn_p->operand[i + 1].mode;
38094       bool match;
38095
38096       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
38097       op = expand_normal (arg);
38098       match = insn_p->operand[i + 1].predicate (op, mode);
38099
38100       if (last_arg_constant && (i + 1) == nargs)
38101         {
38102           if (!match)
38103             {
38104               if (icode == CODE_FOR_lwp_lwpvalsi3
38105                   || icode == CODE_FOR_lwp_lwpinssi3
38106                   || icode == CODE_FOR_lwp_lwpvaldi3
38107                   || icode == CODE_FOR_lwp_lwpinsdi3)
38108                 error ("the last argument must be a 32-bit immediate");
38109               else
38110                 error ("the last argument must be an 8-bit immediate");
38111               return const0_rtx;
38112             }
38113         }
38114       else
38115         {
38116           if (i == memory)
38117             {
38118               /* This must be the memory operand.  */
38119               op = ix86_zero_extend_to_Pmode (op);
38120               op = gen_rtx_MEM (mode, op);
38121               /* op at this point has just BITS_PER_UNIT MEM_ALIGN
38122                  on it.  Try to improve it using get_pointer_alignment,
38123                  and if the special builtin is one that requires strict
38124                  mode alignment, also from it's GET_MODE_ALIGNMENT.
38125                  Failure to do so could lead to ix86_legitimate_combined_insn
38126                  rejecting all changes to such insns.  */
38127               unsigned int align = get_pointer_alignment (arg);
38128               if (aligned_mem && align < GET_MODE_ALIGNMENT (mode))
38129                 align = GET_MODE_ALIGNMENT (mode);
38130               if (MEM_ALIGN (op) < align)
38131                 set_mem_align (op, align);
38132             }
38133           else
38134             {
38135               /* This must be register.  */
38136               if (VECTOR_MODE_P (mode))
38137                 op = safe_vector_operand (op, mode);
38138
38139               if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
38140                 op = copy_to_mode_reg (mode, op);
38141               else
38142                 {
38143                   op = copy_to_reg (op);
38144                   op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
38145                 }
38146             }
38147         }
38148
38149       args[i].op = op;
38150       args[i].mode = mode;
38151     }
38152
38153   switch (nargs)
38154     {
38155     case 0:
38156       pat = GEN_FCN (icode) (target);
38157       break;
38158     case 1:
38159       pat = GEN_FCN (icode) (target, args[0].op);
38160       break;
38161     case 2:
38162       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
38163       break;
38164     case 3:
38165       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
38166       break;
38167     default:
38168       gcc_unreachable ();
38169     }
38170
38171   if (! pat)
38172     return 0;
38173   emit_insn (pat);
38174   return klass == store ? 0 : target;
38175 }
38176
38177 /* Return the integer constant in ARG.  Constrain it to be in the range
38178    of the subparts of VEC_TYPE; issue an error if not.  */
38179
38180 static int
38181 get_element_number (tree vec_type, tree arg)
38182 {
38183   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
38184
38185   if (!tree_fits_uhwi_p (arg)
38186       || (elt = tree_to_uhwi (arg), elt > max))
38187     {
38188       error ("selector must be an integer constant in the range 0..%wi", max);
38189       return 0;
38190     }
38191
38192   return elt;
38193 }
38194
38195 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38196    ix86_expand_vector_init.  We DO have language-level syntax for this, in
38197    the form of  (type){ init-list }.  Except that since we can't place emms
38198    instructions from inside the compiler, we can't allow the use of MMX
38199    registers unless the user explicitly asks for it.  So we do *not* define
38200    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
38201    we have builtins invoked by mmintrin.h that gives us license to emit
38202    these sorts of instructions.  */
38203
38204 static rtx
38205 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
38206 {
38207   machine_mode tmode = TYPE_MODE (type);
38208   machine_mode inner_mode = GET_MODE_INNER (tmode);
38209   int i, n_elt = GET_MODE_NUNITS (tmode);
38210   rtvec v = rtvec_alloc (n_elt);
38211
38212   gcc_assert (VECTOR_MODE_P (tmode));
38213   gcc_assert (call_expr_nargs (exp) == n_elt);
38214
38215   for (i = 0; i < n_elt; ++i)
38216     {
38217       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
38218       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
38219     }
38220
38221   if (!target || !register_operand (target, tmode))
38222     target = gen_reg_rtx (tmode);
38223
38224   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
38225   return target;
38226 }
38227
38228 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38229    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
38230    had a language-level syntax for referencing vector elements.  */
38231
38232 static rtx
38233 ix86_expand_vec_ext_builtin (tree exp, rtx target)
38234 {
38235   machine_mode tmode, mode0;
38236   tree arg0, arg1;
38237   int elt;
38238   rtx op0;
38239
38240   arg0 = CALL_EXPR_ARG (exp, 0);
38241   arg1 = CALL_EXPR_ARG (exp, 1);
38242
38243   op0 = expand_normal (arg0);
38244   elt = get_element_number (TREE_TYPE (arg0), arg1);
38245
38246   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
38247   mode0 = TYPE_MODE (TREE_TYPE (arg0));
38248   gcc_assert (VECTOR_MODE_P (mode0));
38249
38250   op0 = force_reg (mode0, op0);
38251
38252   if (optimize || !target || !register_operand (target, tmode))
38253     target = gen_reg_rtx (tmode);
38254
38255   ix86_expand_vector_extract (true, target, op0, elt);
38256
38257   return target;
38258 }
38259
38260 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38261    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
38262    a language-level syntax for referencing vector elements.  */
38263
38264 static rtx
38265 ix86_expand_vec_set_builtin (tree exp)
38266 {
38267   machine_mode tmode, mode1;
38268   tree arg0, arg1, arg2;
38269   int elt;
38270   rtx op0, op1, target;
38271
38272   arg0 = CALL_EXPR_ARG (exp, 0);
38273   arg1 = CALL_EXPR_ARG (exp, 1);
38274   arg2 = CALL_EXPR_ARG (exp, 2);
38275
38276   tmode = TYPE_MODE (TREE_TYPE (arg0));
38277   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
38278   gcc_assert (VECTOR_MODE_P (tmode));
38279
38280   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
38281   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
38282   elt = get_element_number (TREE_TYPE (arg0), arg2);
38283
38284   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
38285     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
38286
38287   op0 = force_reg (tmode, op0);
38288   op1 = force_reg (mode1, op1);
38289
38290   /* OP0 is the source of these builtin functions and shouldn't be
38291      modified.  Create a copy, use it and return it as target.  */
38292   target = gen_reg_rtx (tmode);
38293   emit_move_insn (target, op0);
38294   ix86_expand_vector_set (true, target, op1, elt);
38295
38296   return target;
38297 }
38298
38299 /* Emit conditional move of SRC to DST with condition
38300    OP1 CODE OP2.  */
38301 static void
38302 ix86_emit_cmove (rtx dst, rtx src, enum rtx_code code, rtx op1, rtx op2)
38303 {
38304   rtx t;
38305
38306   if (TARGET_CMOVE)
38307     {
38308       t = ix86_expand_compare (code, op1, op2);
38309       emit_insn (gen_rtx_SET (VOIDmode, dst,
38310                               gen_rtx_IF_THEN_ELSE (GET_MODE (dst), t,
38311                                                     src, dst)));
38312     }
38313   else
38314     {
38315       rtx nomove = gen_label_rtx ();
38316       emit_cmp_and_jump_insns (op1, op2, reverse_condition (code),
38317                                const0_rtx, GET_MODE (op1), 1, nomove);
38318       emit_move_insn (dst, src);
38319       emit_label (nomove);
38320     }
38321 }
38322
38323 /* Choose max of DST and SRC and put it to DST.  */
38324 static void
38325 ix86_emit_move_max (rtx dst, rtx src)
38326 {
38327   ix86_emit_cmove (dst, src, LTU, dst, src);
38328 }
38329
38330 /* Expand an expression EXP that calls a built-in function,
38331    with result going to TARGET if that's convenient
38332    (and in mode MODE if that's convenient).
38333    SUBTARGET may be used as the target for computing one of EXP's operands.
38334    IGNORE is nonzero if the value is to be ignored.  */
38335
38336 static rtx
38337 ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
38338                      machine_mode mode, int ignore)
38339 {
38340   const struct builtin_description *d;
38341   size_t i;
38342   enum insn_code icode;
38343   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
38344   tree arg0, arg1, arg2, arg3, arg4;
38345   rtx op0, op1, op2, op3, op4, pat, insn;
38346   machine_mode mode0, mode1, mode2, mode3, mode4;
38347   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
38348
38349   /* For CPU builtins that can be folded, fold first and expand the fold.  */
38350   switch (fcode)
38351     {
38352     case IX86_BUILTIN_CPU_INIT:
38353       {
38354         /* Make it call __cpu_indicator_init in libgcc. */
38355         tree call_expr, fndecl, type;
38356         type = build_function_type_list (integer_type_node, NULL_TREE); 
38357         fndecl = build_fn_decl ("__cpu_indicator_init", type);
38358         call_expr = build_call_expr (fndecl, 0); 
38359         return expand_expr (call_expr, target, mode, EXPAND_NORMAL);
38360       }
38361     case IX86_BUILTIN_CPU_IS:
38362     case IX86_BUILTIN_CPU_SUPPORTS:
38363       {
38364         tree arg0 = CALL_EXPR_ARG (exp, 0);
38365         tree fold_expr = fold_builtin_cpu (fndecl, &arg0);
38366         gcc_assert (fold_expr != NULL_TREE);
38367         return expand_expr (fold_expr, target, mode, EXPAND_NORMAL);
38368       }
38369     }
38370
38371   /* Determine whether the builtin function is available under the current ISA.
38372      Originally the builtin was not created if it wasn't applicable to the
38373      current ISA based on the command line switches.  With function specific
38374      options, we need to check in the context of the function making the call
38375      whether it is supported.  */
38376   if (ix86_builtins_isa[fcode].isa
38377       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
38378     {
38379       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
38380                                        NULL, (enum fpmath_unit) 0, false);
38381
38382       if (!opts)
38383         error ("%qE needs unknown isa option", fndecl);
38384       else
38385         {
38386           gcc_assert (opts != NULL);
38387           error ("%qE needs isa option %s", fndecl, opts);
38388           free (opts);
38389         }
38390       return const0_rtx;
38391     }
38392
38393   switch (fcode)
38394     {
38395     case IX86_BUILTIN_BNDMK:
38396       if (!target
38397           || GET_MODE (target) != BNDmode
38398           || !register_operand (target, BNDmode))
38399         target = gen_reg_rtx (BNDmode);
38400
38401       arg0 = CALL_EXPR_ARG (exp, 0);
38402       arg1 = CALL_EXPR_ARG (exp, 1);
38403
38404       op0 = expand_normal (arg0);
38405       op1 = expand_normal (arg1);
38406
38407       if (!register_operand (op0, Pmode))
38408         op0 = ix86_zero_extend_to_Pmode (op0);
38409       if (!register_operand (op1, Pmode))
38410         op1 = ix86_zero_extend_to_Pmode (op1);
38411
38412       /* Builtin arg1 is size of block but instruction op1 should
38413          be (size - 1).  */
38414       op1 = expand_simple_binop (Pmode, PLUS, op1, constm1_rtx,
38415                                  NULL_RTX, 1, OPTAB_DIRECT);
38416
38417       emit_insn (BNDmode == BND64mode
38418                  ? gen_bnd64_mk (target, op0, op1)
38419                  : gen_bnd32_mk (target, op0, op1));
38420       return target;
38421
38422     case IX86_BUILTIN_BNDSTX:
38423       arg0 = CALL_EXPR_ARG (exp, 0);
38424       arg1 = CALL_EXPR_ARG (exp, 1);
38425       arg2 = CALL_EXPR_ARG (exp, 2);
38426
38427       op0 = expand_normal (arg0);
38428       op1 = expand_normal (arg1);
38429       op2 = expand_normal (arg2);
38430
38431       if (!register_operand (op0, Pmode))
38432         op0 = ix86_zero_extend_to_Pmode (op0);
38433       if (!register_operand (op1, BNDmode))
38434         op1 = copy_to_mode_reg (BNDmode, op1);
38435       if (!register_operand (op2, Pmode))
38436         op2 = ix86_zero_extend_to_Pmode (op2);
38437
38438       emit_insn (BNDmode == BND64mode
38439                  ? gen_bnd64_stx (op2, op0, op1)
38440                  : gen_bnd32_stx (op2, op0, op1));
38441       return 0;
38442
38443     case IX86_BUILTIN_BNDLDX:
38444       if (!target
38445           || GET_MODE (target) != BNDmode
38446           || !register_operand (target, BNDmode))
38447         target = gen_reg_rtx (BNDmode);
38448
38449       arg0 = CALL_EXPR_ARG (exp, 0);
38450       arg1 = CALL_EXPR_ARG (exp, 1);
38451
38452       op0 = expand_normal (arg0);
38453       op1 = expand_normal (arg1);
38454
38455       if (!register_operand (op0, Pmode))
38456         op0 = ix86_zero_extend_to_Pmode (op0);
38457       if (!register_operand (op1, Pmode))
38458         op1 = ix86_zero_extend_to_Pmode (op1);
38459
38460       emit_insn (BNDmode == BND64mode
38461                  ? gen_bnd64_ldx (target, op0, op1)
38462                  : gen_bnd32_ldx (target, op0, op1));
38463       return target;
38464
38465     case IX86_BUILTIN_BNDCL:
38466       arg0 = CALL_EXPR_ARG (exp, 0);
38467       arg1 = CALL_EXPR_ARG (exp, 1);
38468
38469       op0 = expand_normal (arg0);
38470       op1 = expand_normal (arg1);
38471
38472       if (!register_operand (op0, Pmode))
38473         op0 = ix86_zero_extend_to_Pmode (op0);
38474       if (!register_operand (op1, BNDmode))
38475         op1 = copy_to_mode_reg (BNDmode, op1);
38476
38477       emit_insn (BNDmode == BND64mode
38478                  ? gen_bnd64_cl (op1, op0)
38479                  : gen_bnd32_cl (op1, op0));
38480       return 0;
38481
38482     case IX86_BUILTIN_BNDCU:
38483       arg0 = CALL_EXPR_ARG (exp, 0);
38484       arg1 = CALL_EXPR_ARG (exp, 1);
38485
38486       op0 = expand_normal (arg0);
38487       op1 = expand_normal (arg1);
38488
38489       if (!register_operand (op0, Pmode))
38490         op0 = ix86_zero_extend_to_Pmode (op0);
38491       if (!register_operand (op1, BNDmode))
38492         op1 = copy_to_mode_reg (BNDmode, op1);
38493
38494       emit_insn (BNDmode == BND64mode
38495                  ? gen_bnd64_cu (op1, op0)
38496                  : gen_bnd32_cu (op1, op0));
38497       return 0;
38498
38499     case IX86_BUILTIN_BNDRET:
38500       arg0 = CALL_EXPR_ARG (exp, 0);
38501       gcc_assert (TREE_CODE (arg0) == SSA_NAME);
38502       target = chkp_get_rtl_bounds (arg0);
38503
38504       /* If no bounds were specified for returned value,
38505          then use INIT bounds.  It usually happens when
38506          some built-in function is expanded.  */
38507       if (!target)
38508         {
38509           rtx t1 = gen_reg_rtx (Pmode);
38510           rtx t2 = gen_reg_rtx (Pmode);
38511           target = gen_reg_rtx (BNDmode);
38512           emit_move_insn (t1, const0_rtx);
38513           emit_move_insn (t2, constm1_rtx);
38514           emit_insn (BNDmode == BND64mode
38515                      ? gen_bnd64_mk (target, t1, t2)
38516                      : gen_bnd32_mk (target, t1, t2));
38517         }
38518
38519       gcc_assert (target && REG_P (target));
38520       return target;
38521
38522     case IX86_BUILTIN_BNDNARROW:
38523       {
38524         rtx m1, m1h1, m1h2, lb, ub, t1;
38525
38526         /* Return value and lb.  */
38527         arg0 = CALL_EXPR_ARG (exp, 0);
38528         /* Bounds.  */
38529         arg1 = CALL_EXPR_ARG (exp, 1);
38530         /* Size.  */
38531         arg2 = CALL_EXPR_ARG (exp, 2);
38532
38533         lb = expand_normal (arg0);
38534         op1 = expand_normal (arg1);
38535         op2 = expand_normal (arg2);
38536
38537         /* Size was passed but we need to use (size - 1) as for bndmk.  */
38538         op2 = expand_simple_binop (Pmode, PLUS, op2, constm1_rtx,
38539                                    NULL_RTX, 1, OPTAB_DIRECT);
38540
38541         /* Add LB to size and inverse to get UB.  */
38542         op2 = expand_simple_binop (Pmode, PLUS, op2, lb,
38543                                    op2, 1, OPTAB_DIRECT);
38544         ub = expand_simple_unop (Pmode, NOT, op2, op2, 1);
38545
38546         if (!register_operand (lb, Pmode))
38547           lb = ix86_zero_extend_to_Pmode (lb);
38548         if (!register_operand (ub, Pmode))
38549           ub = ix86_zero_extend_to_Pmode (ub);
38550
38551         /* We need to move bounds to memory before any computations.  */
38552         if (MEM_P (op1))
38553           m1 = op1;
38554         else
38555           {
38556             m1 = assign_386_stack_local (BNDmode, SLOT_TEMP);
38557             emit_move_insn (m1, op1);
38558           }
38559
38560         /* Generate mem expression to be used for access to LB and UB.  */
38561         m1h1 = adjust_address (m1, Pmode, 0);
38562         m1h2 = adjust_address (m1, Pmode, GET_MODE_SIZE (Pmode));
38563
38564         t1 = gen_reg_rtx (Pmode);
38565
38566         /* Compute LB.  */
38567         emit_move_insn (t1, m1h1);
38568         ix86_emit_move_max (t1, lb);
38569         emit_move_insn (m1h1, t1);
38570
38571         /* Compute UB.  UB is stored in 1's complement form.  Therefore
38572            we also use max here.  */
38573         emit_move_insn (t1, m1h2);
38574         ix86_emit_move_max (t1, ub);
38575         emit_move_insn (m1h2, t1);
38576
38577         op2 = gen_reg_rtx (BNDmode);
38578         emit_move_insn (op2, m1);
38579
38580         return chkp_join_splitted_slot (lb, op2);
38581       }
38582
38583     case IX86_BUILTIN_BNDINT:
38584       {
38585         rtx res, rh1, rh2, lb1, lb2, ub1, ub2;
38586
38587         if (!target
38588             || GET_MODE (target) != BNDmode
38589             || !register_operand (target, BNDmode))
38590           target = gen_reg_rtx (BNDmode);
38591
38592         arg0 = CALL_EXPR_ARG (exp, 0);
38593         arg1 = CALL_EXPR_ARG (exp, 1);
38594
38595         op0 = expand_normal (arg0);
38596         op1 = expand_normal (arg1);
38597
38598         res = assign_386_stack_local (BNDmode, SLOT_TEMP);
38599         rh1 = adjust_address (res, Pmode, 0);
38600         rh2 = adjust_address (res, Pmode, GET_MODE_SIZE (Pmode));
38601
38602         /* Put first bounds to temporaries.  */
38603         lb1 = gen_reg_rtx (Pmode);
38604         ub1 = gen_reg_rtx (Pmode);
38605         if (MEM_P (op0))
38606           {
38607             emit_move_insn (lb1, adjust_address (op0, Pmode, 0));
38608             emit_move_insn (ub1, adjust_address (op0, Pmode,
38609                                                  GET_MODE_SIZE (Pmode)));
38610           }
38611         else
38612           {
38613             emit_move_insn (res, op0);
38614             emit_move_insn (lb1, rh1);
38615             emit_move_insn (ub1, rh2);
38616           }
38617
38618         /* Put second bounds to temporaries.  */
38619         lb2 = gen_reg_rtx (Pmode);
38620         ub2 = gen_reg_rtx (Pmode);
38621         if (MEM_P (op1))
38622           {
38623             emit_move_insn (lb2, adjust_address (op1, Pmode, 0));
38624             emit_move_insn (ub2, adjust_address (op1, Pmode,
38625                                                  GET_MODE_SIZE (Pmode)));
38626           }
38627         else
38628           {
38629             emit_move_insn (res, op1);
38630             emit_move_insn (lb2, rh1);
38631             emit_move_insn (ub2, rh2);
38632           }
38633
38634         /* Compute LB.  */
38635         ix86_emit_move_max (lb1, lb2);
38636         emit_move_insn (rh1, lb1);
38637
38638         /* Compute UB.  UB is stored in 1's complement form.  Therefore
38639            we also use max here.  */
38640         ix86_emit_move_max (ub1, ub2);
38641         emit_move_insn (rh2, ub1);
38642
38643         emit_move_insn (target, res);
38644
38645         return target;
38646       }
38647
38648     case IX86_BUILTIN_SIZEOF:
38649       {
38650         tree name;
38651         rtx symbol;
38652
38653         if (!target
38654             || GET_MODE (target) != Pmode
38655             || !register_operand (target, Pmode))
38656           target = gen_reg_rtx (Pmode);
38657
38658         arg0 = CALL_EXPR_ARG (exp, 0);
38659         gcc_assert (TREE_CODE (arg0) == VAR_DECL);
38660
38661         name = DECL_ASSEMBLER_NAME (arg0);
38662         symbol = gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (name));
38663
38664         emit_insn (Pmode == SImode
38665                    ? gen_move_size_reloc_si (target, symbol)
38666                    : gen_move_size_reloc_di (target, symbol));
38667
38668         return target;
38669       }
38670
38671     case IX86_BUILTIN_BNDLOWER:
38672       {
38673         rtx mem, hmem;
38674
38675         if (!target
38676             || GET_MODE (target) != Pmode
38677             || !register_operand (target, Pmode))
38678           target = gen_reg_rtx (Pmode);
38679
38680         arg0 = CALL_EXPR_ARG (exp, 0);
38681         op0 = expand_normal (arg0);
38682
38683         /* We need to move bounds to memory first.  */
38684         if (MEM_P (op0))
38685           mem = op0;
38686         else
38687           {
38688             mem = assign_386_stack_local (BNDmode, SLOT_TEMP);
38689             emit_move_insn (mem, op0);
38690           }
38691
38692         /* Generate mem expression to access LB and load it.  */
38693         hmem = adjust_address (mem, Pmode, 0);
38694         emit_move_insn (target, hmem);
38695
38696         return target;
38697       }
38698
38699     case IX86_BUILTIN_BNDUPPER:
38700       {
38701         rtx mem, hmem, res;
38702
38703         if (!target
38704             || GET_MODE (target) != Pmode
38705             || !register_operand (target, Pmode))
38706           target = gen_reg_rtx (Pmode);
38707
38708         arg0 = CALL_EXPR_ARG (exp, 0);
38709         op0 = expand_normal (arg0);
38710
38711         /* We need to move bounds to memory first.  */
38712         if (MEM_P (op0))
38713           mem = op0;
38714         else
38715           {
38716             mem = assign_386_stack_local (BNDmode, SLOT_TEMP);
38717             emit_move_insn (mem, op0);
38718           }
38719
38720         /* Generate mem expression to access UB.  */
38721         hmem = adjust_address (mem, Pmode, GET_MODE_SIZE (Pmode));
38722
38723         /* We need to inverse all bits of UB.  */
38724         res = expand_simple_unop (Pmode, NOT, hmem, target, 1);
38725
38726         if (res != target)
38727           emit_move_insn (target, res);
38728
38729         return target;
38730       }
38731
38732     case IX86_BUILTIN_MASKMOVQ:
38733     case IX86_BUILTIN_MASKMOVDQU:
38734       icode = (fcode == IX86_BUILTIN_MASKMOVQ
38735                ? CODE_FOR_mmx_maskmovq
38736                : CODE_FOR_sse2_maskmovdqu);
38737       /* Note the arg order is different from the operand order.  */
38738       arg1 = CALL_EXPR_ARG (exp, 0);
38739       arg2 = CALL_EXPR_ARG (exp, 1);
38740       arg0 = CALL_EXPR_ARG (exp, 2);
38741       op0 = expand_normal (arg0);
38742       op1 = expand_normal (arg1);
38743       op2 = expand_normal (arg2);
38744       mode0 = insn_data[icode].operand[0].mode;
38745       mode1 = insn_data[icode].operand[1].mode;
38746       mode2 = insn_data[icode].operand[2].mode;
38747
38748       op0 = ix86_zero_extend_to_Pmode (op0);
38749       op0 = gen_rtx_MEM (mode1, op0);
38750
38751       if (!insn_data[icode].operand[0].predicate (op0, mode0))
38752         op0 = copy_to_mode_reg (mode0, op0);
38753       if (!insn_data[icode].operand[1].predicate (op1, mode1))
38754         op1 = copy_to_mode_reg (mode1, op1);
38755       if (!insn_data[icode].operand[2].predicate (op2, mode2))
38756         op2 = copy_to_mode_reg (mode2, op2);
38757       pat = GEN_FCN (icode) (op0, op1, op2);
38758       if (! pat)
38759         return 0;
38760       emit_insn (pat);
38761       return 0;
38762
38763     case IX86_BUILTIN_LDMXCSR:
38764       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
38765       target = assign_386_stack_local (SImode, SLOT_TEMP);
38766       emit_move_insn (target, op0);
38767       emit_insn (gen_sse_ldmxcsr (target));
38768       return 0;
38769
38770     case IX86_BUILTIN_STMXCSR:
38771       target = assign_386_stack_local (SImode, SLOT_TEMP);
38772       emit_insn (gen_sse_stmxcsr (target));
38773       return copy_to_mode_reg (SImode, target);
38774
38775     case IX86_BUILTIN_CLFLUSH:
38776         arg0 = CALL_EXPR_ARG (exp, 0);
38777         op0 = expand_normal (arg0);
38778         icode = CODE_FOR_sse2_clflush;
38779         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38780           op0 = ix86_zero_extend_to_Pmode (op0);
38781
38782         emit_insn (gen_sse2_clflush (op0));
38783         return 0;
38784
38785     case IX86_BUILTIN_CLWB:
38786         arg0 = CALL_EXPR_ARG (exp, 0);
38787         op0 = expand_normal (arg0);
38788         icode = CODE_FOR_clwb;
38789         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38790           op0 = ix86_zero_extend_to_Pmode (op0);
38791
38792         emit_insn (gen_clwb (op0));
38793         return 0;
38794
38795     case IX86_BUILTIN_CLFLUSHOPT:
38796         arg0 = CALL_EXPR_ARG (exp, 0);
38797         op0 = expand_normal (arg0);
38798         icode = CODE_FOR_clflushopt;
38799         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38800           op0 = ix86_zero_extend_to_Pmode (op0);
38801
38802         emit_insn (gen_clflushopt (op0));
38803         return 0;
38804
38805     case IX86_BUILTIN_MONITOR:
38806       arg0 = CALL_EXPR_ARG (exp, 0);
38807       arg1 = CALL_EXPR_ARG (exp, 1);
38808       arg2 = CALL_EXPR_ARG (exp, 2);
38809       op0 = expand_normal (arg0);
38810       op1 = expand_normal (arg1);
38811       op2 = expand_normal (arg2);
38812       if (!REG_P (op0))
38813         op0 = ix86_zero_extend_to_Pmode (op0);
38814       if (!REG_P (op1))
38815         op1 = copy_to_mode_reg (SImode, op1);
38816       if (!REG_P (op2))
38817         op2 = copy_to_mode_reg (SImode, op2);
38818       emit_insn (ix86_gen_monitor (op0, op1, op2));
38819       return 0;
38820
38821     case IX86_BUILTIN_MWAIT:
38822       arg0 = CALL_EXPR_ARG (exp, 0);
38823       arg1 = CALL_EXPR_ARG (exp, 1);
38824       op0 = expand_normal (arg0);
38825       op1 = expand_normal (arg1);
38826       if (!REG_P (op0))
38827         op0 = copy_to_mode_reg (SImode, op0);
38828       if (!REG_P (op1))
38829         op1 = copy_to_mode_reg (SImode, op1);
38830       emit_insn (gen_sse3_mwait (op0, op1));
38831       return 0;
38832
38833     case IX86_BUILTIN_VEC_INIT_V2SI:
38834     case IX86_BUILTIN_VEC_INIT_V4HI:
38835     case IX86_BUILTIN_VEC_INIT_V8QI:
38836       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
38837
38838     case IX86_BUILTIN_VEC_EXT_V2DF:
38839     case IX86_BUILTIN_VEC_EXT_V2DI:
38840     case IX86_BUILTIN_VEC_EXT_V4SF:
38841     case IX86_BUILTIN_VEC_EXT_V4SI:
38842     case IX86_BUILTIN_VEC_EXT_V8HI:
38843     case IX86_BUILTIN_VEC_EXT_V2SI:
38844     case IX86_BUILTIN_VEC_EXT_V4HI:
38845     case IX86_BUILTIN_VEC_EXT_V16QI:
38846       return ix86_expand_vec_ext_builtin (exp, target);
38847
38848     case IX86_BUILTIN_VEC_SET_V2DI:
38849     case IX86_BUILTIN_VEC_SET_V4SF:
38850     case IX86_BUILTIN_VEC_SET_V4SI:
38851     case IX86_BUILTIN_VEC_SET_V8HI:
38852     case IX86_BUILTIN_VEC_SET_V4HI:
38853     case IX86_BUILTIN_VEC_SET_V16QI:
38854       return ix86_expand_vec_set_builtin (exp);
38855
38856     case IX86_BUILTIN_INFQ:
38857     case IX86_BUILTIN_HUGE_VALQ:
38858       {
38859         REAL_VALUE_TYPE inf;
38860         rtx tmp;
38861
38862         real_inf (&inf);
38863         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
38864
38865         tmp = validize_mem (force_const_mem (mode, tmp));
38866
38867         if (target == 0)
38868           target = gen_reg_rtx (mode);
38869
38870         emit_move_insn (target, tmp);
38871         return target;
38872       }
38873
38874     case IX86_BUILTIN_RDPMC:
38875     case IX86_BUILTIN_RDTSC:
38876     case IX86_BUILTIN_RDTSCP:
38877
38878       op0 = gen_reg_rtx (DImode);
38879       op1 = gen_reg_rtx (DImode);
38880
38881       if (fcode == IX86_BUILTIN_RDPMC)
38882         {
38883           arg0 = CALL_EXPR_ARG (exp, 0);
38884           op2 = expand_normal (arg0);
38885           if (!register_operand (op2, SImode))
38886             op2 = copy_to_mode_reg (SImode, op2);
38887
38888           insn = (TARGET_64BIT
38889                   ? gen_rdpmc_rex64 (op0, op1, op2)
38890                   : gen_rdpmc (op0, op2));
38891           emit_insn (insn);
38892         }
38893       else if (fcode == IX86_BUILTIN_RDTSC)
38894         {
38895           insn = (TARGET_64BIT
38896                   ? gen_rdtsc_rex64 (op0, op1)
38897                   : gen_rdtsc (op0));
38898           emit_insn (insn);
38899         }
38900       else
38901         {
38902           op2 = gen_reg_rtx (SImode);
38903
38904           insn = (TARGET_64BIT
38905                   ? gen_rdtscp_rex64 (op0, op1, op2)
38906                   : gen_rdtscp (op0, op2));
38907           emit_insn (insn);
38908
38909           arg0 = CALL_EXPR_ARG (exp, 0);
38910           op4 = expand_normal (arg0);
38911           if (!address_operand (op4, VOIDmode))
38912             {
38913               op4 = convert_memory_address (Pmode, op4);
38914               op4 = copy_addr_to_reg (op4);
38915             }
38916           emit_move_insn (gen_rtx_MEM (SImode, op4), op2);
38917         }
38918
38919       if (target == 0)
38920         {
38921           /* mode is VOIDmode if __builtin_rd* has been called
38922              without lhs.  */
38923           if (mode == VOIDmode)
38924             return target;
38925           target = gen_reg_rtx (mode);
38926         }
38927
38928       if (TARGET_64BIT)
38929         {
38930           op1 = expand_simple_binop (DImode, ASHIFT, op1, GEN_INT (32),
38931                                      op1, 1, OPTAB_DIRECT);
38932           op0 = expand_simple_binop (DImode, IOR, op0, op1,
38933                                      op0, 1, OPTAB_DIRECT);
38934         }
38935
38936       emit_move_insn (target, op0);
38937       return target;
38938
38939     case IX86_BUILTIN_FXSAVE:
38940     case IX86_BUILTIN_FXRSTOR:
38941     case IX86_BUILTIN_FXSAVE64:
38942     case IX86_BUILTIN_FXRSTOR64:
38943     case IX86_BUILTIN_FNSTENV:
38944     case IX86_BUILTIN_FLDENV:
38945       mode0 = BLKmode;
38946       switch (fcode)
38947         {
38948         case IX86_BUILTIN_FXSAVE:
38949           icode = CODE_FOR_fxsave;
38950           break;
38951         case IX86_BUILTIN_FXRSTOR:
38952           icode = CODE_FOR_fxrstor;
38953           break;
38954         case IX86_BUILTIN_FXSAVE64:
38955           icode = CODE_FOR_fxsave64;
38956           break;
38957         case IX86_BUILTIN_FXRSTOR64:
38958           icode = CODE_FOR_fxrstor64;
38959           break;
38960         case IX86_BUILTIN_FNSTENV:
38961           icode = CODE_FOR_fnstenv;
38962           break;
38963         case IX86_BUILTIN_FLDENV:
38964           icode = CODE_FOR_fldenv;
38965           break;
38966         default:
38967           gcc_unreachable ();
38968         }
38969
38970       arg0 = CALL_EXPR_ARG (exp, 0);
38971       op0 = expand_normal (arg0);
38972
38973       if (!address_operand (op0, VOIDmode))
38974         {
38975           op0 = convert_memory_address (Pmode, op0);
38976           op0 = copy_addr_to_reg (op0);
38977         }
38978       op0 = gen_rtx_MEM (mode0, op0);
38979
38980       pat = GEN_FCN (icode) (op0);
38981       if (pat)
38982         emit_insn (pat);
38983       return 0;
38984
38985     case IX86_BUILTIN_XSAVE:
38986     case IX86_BUILTIN_XRSTOR:
38987     case IX86_BUILTIN_XSAVE64:
38988     case IX86_BUILTIN_XRSTOR64:
38989     case IX86_BUILTIN_XSAVEOPT:
38990     case IX86_BUILTIN_XSAVEOPT64:
38991     case IX86_BUILTIN_XSAVES:
38992     case IX86_BUILTIN_XRSTORS:
38993     case IX86_BUILTIN_XSAVES64:
38994     case IX86_BUILTIN_XRSTORS64:
38995     case IX86_BUILTIN_XSAVEC:
38996     case IX86_BUILTIN_XSAVEC64:
38997       arg0 = CALL_EXPR_ARG (exp, 0);
38998       arg1 = CALL_EXPR_ARG (exp, 1);
38999       op0 = expand_normal (arg0);
39000       op1 = expand_normal (arg1);
39001
39002       if (!address_operand (op0, VOIDmode))
39003         {
39004           op0 = convert_memory_address (Pmode, op0);
39005           op0 = copy_addr_to_reg (op0);
39006         }
39007       op0 = gen_rtx_MEM (BLKmode, op0);
39008
39009       op1 = force_reg (DImode, op1);
39010
39011       if (TARGET_64BIT)
39012         {
39013           op2 = expand_simple_binop (DImode, LSHIFTRT, op1, GEN_INT (32),
39014                                      NULL, 1, OPTAB_DIRECT);
39015           switch (fcode)
39016             {
39017             case IX86_BUILTIN_XSAVE:
39018               icode = CODE_FOR_xsave_rex64;
39019               break;
39020             case IX86_BUILTIN_XRSTOR:
39021               icode = CODE_FOR_xrstor_rex64;
39022               break;
39023             case IX86_BUILTIN_XSAVE64:
39024               icode = CODE_FOR_xsave64;
39025               break;
39026             case IX86_BUILTIN_XRSTOR64:
39027               icode = CODE_FOR_xrstor64;
39028               break;
39029             case IX86_BUILTIN_XSAVEOPT:
39030               icode = CODE_FOR_xsaveopt_rex64;
39031               break;
39032             case IX86_BUILTIN_XSAVEOPT64:
39033               icode = CODE_FOR_xsaveopt64;
39034               break;
39035             case IX86_BUILTIN_XSAVES:
39036               icode = CODE_FOR_xsaves_rex64;
39037               break;
39038             case IX86_BUILTIN_XRSTORS:
39039               icode = CODE_FOR_xrstors_rex64;
39040               break;
39041             case IX86_BUILTIN_XSAVES64:
39042               icode = CODE_FOR_xsaves64;
39043               break;
39044             case IX86_BUILTIN_XRSTORS64:
39045               icode = CODE_FOR_xrstors64;
39046               break;
39047             case IX86_BUILTIN_XSAVEC:
39048               icode = CODE_FOR_xsavec_rex64;
39049               break;
39050             case IX86_BUILTIN_XSAVEC64:
39051               icode = CODE_FOR_xsavec64;
39052               break;
39053             default:
39054               gcc_unreachable ();
39055             }
39056
39057           op2 = gen_lowpart (SImode, op2);
39058           op1 = gen_lowpart (SImode, op1);
39059           pat = GEN_FCN (icode) (op0, op1, op2);
39060         }
39061       else
39062         {
39063           switch (fcode)
39064             {
39065             case IX86_BUILTIN_XSAVE:
39066               icode = CODE_FOR_xsave;
39067               break;
39068             case IX86_BUILTIN_XRSTOR:
39069               icode = CODE_FOR_xrstor;
39070               break;
39071             case IX86_BUILTIN_XSAVEOPT:
39072               icode = CODE_FOR_xsaveopt;
39073               break;
39074             case IX86_BUILTIN_XSAVES:
39075               icode = CODE_FOR_xsaves;
39076               break;
39077             case IX86_BUILTIN_XRSTORS:
39078               icode = CODE_FOR_xrstors;
39079               break;
39080             case IX86_BUILTIN_XSAVEC:
39081               icode = CODE_FOR_xsavec;
39082               break;
39083             default:
39084               gcc_unreachable ();
39085             }
39086           pat = GEN_FCN (icode) (op0, op1);
39087         }
39088
39089       if (pat)
39090         emit_insn (pat);
39091       return 0;
39092
39093     case IX86_BUILTIN_LLWPCB:
39094       arg0 = CALL_EXPR_ARG (exp, 0);
39095       op0 = expand_normal (arg0);
39096       icode = CODE_FOR_lwp_llwpcb;
39097       if (!insn_data[icode].operand[0].predicate (op0, Pmode))
39098         op0 = ix86_zero_extend_to_Pmode (op0);
39099       emit_insn (gen_lwp_llwpcb (op0));
39100       return 0;
39101
39102     case IX86_BUILTIN_SLWPCB:
39103       icode = CODE_FOR_lwp_slwpcb;
39104       if (!target
39105           || !insn_data[icode].operand[0].predicate (target, Pmode))
39106         target = gen_reg_rtx (Pmode);
39107       emit_insn (gen_lwp_slwpcb (target));
39108       return target;
39109
39110     case IX86_BUILTIN_BEXTRI32:
39111     case IX86_BUILTIN_BEXTRI64:
39112       arg0 = CALL_EXPR_ARG (exp, 0);
39113       arg1 = CALL_EXPR_ARG (exp, 1);
39114       op0 = expand_normal (arg0);
39115       op1 = expand_normal (arg1);
39116       icode = (fcode == IX86_BUILTIN_BEXTRI32
39117           ? CODE_FOR_tbm_bextri_si
39118           : CODE_FOR_tbm_bextri_di);
39119       if (!CONST_INT_P (op1))
39120         {
39121           error ("last argument must be an immediate");
39122           return const0_rtx;
39123         }
39124       else
39125         {
39126           unsigned char length = (INTVAL (op1) >> 8) & 0xFF;
39127           unsigned char lsb_index = INTVAL (op1) & 0xFF;
39128           op1 = GEN_INT (length);
39129           op2 = GEN_INT (lsb_index);
39130           pat = GEN_FCN (icode) (target, op0, op1, op2);
39131           if (pat)
39132             emit_insn (pat);
39133           return target;
39134         }
39135
39136     case IX86_BUILTIN_RDRAND16_STEP:
39137       icode = CODE_FOR_rdrandhi_1;
39138       mode0 = HImode;
39139       goto rdrand_step;
39140
39141     case IX86_BUILTIN_RDRAND32_STEP:
39142       icode = CODE_FOR_rdrandsi_1;
39143       mode0 = SImode;
39144       goto rdrand_step;
39145
39146     case IX86_BUILTIN_RDRAND64_STEP:
39147       icode = CODE_FOR_rdranddi_1;
39148       mode0 = DImode;
39149
39150 rdrand_step:
39151       op0 = gen_reg_rtx (mode0);
39152       emit_insn (GEN_FCN (icode) (op0));
39153
39154       arg0 = CALL_EXPR_ARG (exp, 0);
39155       op1 = expand_normal (arg0);
39156       if (!address_operand (op1, VOIDmode))
39157         {
39158           op1 = convert_memory_address (Pmode, op1);
39159           op1 = copy_addr_to_reg (op1);
39160         }
39161       emit_move_insn (gen_rtx_MEM (mode0, op1), op0);
39162
39163       op1 = gen_reg_rtx (SImode);
39164       emit_move_insn (op1, CONST1_RTX (SImode));
39165
39166       /* Emit SImode conditional move.  */
39167       if (mode0 == HImode)
39168         {
39169           op2 = gen_reg_rtx (SImode);
39170           emit_insn (gen_zero_extendhisi2 (op2, op0));
39171         }
39172       else if (mode0 == SImode)
39173         op2 = op0;
39174       else
39175         op2 = gen_rtx_SUBREG (SImode, op0, 0);
39176
39177       if (target == 0
39178           || !register_operand (target, SImode))
39179         target = gen_reg_rtx (SImode);
39180
39181       pat = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG),
39182                          const0_rtx);
39183       emit_insn (gen_rtx_SET (VOIDmode, target,
39184                               gen_rtx_IF_THEN_ELSE (SImode, pat, op2, op1)));
39185       return target;
39186
39187     case IX86_BUILTIN_RDSEED16_STEP:
39188       icode = CODE_FOR_rdseedhi_1;
39189       mode0 = HImode;
39190       goto rdseed_step;
39191
39192     case IX86_BUILTIN_RDSEED32_STEP:
39193       icode = CODE_FOR_rdseedsi_1;
39194       mode0 = SImode;
39195       goto rdseed_step;
39196
39197     case IX86_BUILTIN_RDSEED64_STEP:
39198       icode = CODE_FOR_rdseeddi_1;
39199       mode0 = DImode;
39200
39201 rdseed_step:
39202       op0 = gen_reg_rtx (mode0);
39203       emit_insn (GEN_FCN (icode) (op0));
39204
39205       arg0 = CALL_EXPR_ARG (exp, 0);
39206       op1 = expand_normal (arg0);
39207       if (!address_operand (op1, VOIDmode))
39208         {
39209           op1 = convert_memory_address (Pmode, op1);
39210           op1 = copy_addr_to_reg (op1);
39211         }
39212       emit_move_insn (gen_rtx_MEM (mode0, op1), op0);
39213
39214       op2 = gen_reg_rtx (QImode);
39215
39216       pat = gen_rtx_LTU (QImode, gen_rtx_REG (CCCmode, FLAGS_REG),
39217                          const0_rtx);
39218       emit_insn (gen_rtx_SET (VOIDmode, op2, pat));
39219
39220       if (target == 0
39221           || !register_operand (target, SImode))
39222         target = gen_reg_rtx (SImode);
39223
39224       emit_insn (gen_zero_extendqisi2 (target, op2));
39225       return target;
39226
39227     case IX86_BUILTIN_SBB32:
39228       icode = CODE_FOR_subsi3_carry;
39229       mode0 = SImode;
39230       goto addcarryx;
39231
39232     case IX86_BUILTIN_SBB64:
39233       icode = CODE_FOR_subdi3_carry;
39234       mode0 = DImode;
39235       goto addcarryx;
39236
39237     case IX86_BUILTIN_ADDCARRYX32:
39238       icode = TARGET_ADX ? CODE_FOR_adcxsi3 : CODE_FOR_addsi3_carry;
39239       mode0 = SImode;
39240       goto addcarryx;
39241
39242     case IX86_BUILTIN_ADDCARRYX64:
39243       icode = TARGET_ADX ? CODE_FOR_adcxdi3 : CODE_FOR_adddi3_carry;
39244       mode0 = DImode;
39245
39246 addcarryx:
39247       arg0 = CALL_EXPR_ARG (exp, 0); /* unsigned char c_in.  */
39248       arg1 = CALL_EXPR_ARG (exp, 1); /* unsigned int src1.  */
39249       arg2 = CALL_EXPR_ARG (exp, 2); /* unsigned int src2.  */
39250       arg3 = CALL_EXPR_ARG (exp, 3); /* unsigned int *sum_out.  */
39251
39252       op0 = gen_reg_rtx (QImode);
39253
39254       /* Generate CF from input operand.  */
39255       op1 = expand_normal (arg0);
39256       op1 = copy_to_mode_reg (QImode, convert_to_mode (QImode, op1, 1));
39257       emit_insn (gen_addqi3_cc (op0, op1, constm1_rtx));
39258
39259       /* Gen ADCX instruction to compute X+Y+CF.  */
39260       op2 = expand_normal (arg1);
39261       op3 = expand_normal (arg2);
39262
39263       if (!REG_P (op2))
39264         op2 = copy_to_mode_reg (mode0, op2);
39265       if (!REG_P (op3))
39266         op3 = copy_to_mode_reg (mode0, op3);
39267
39268       op0 = gen_reg_rtx (mode0);
39269
39270       op4 = gen_rtx_REG (CCCmode, FLAGS_REG);
39271       pat = gen_rtx_LTU (VOIDmode, op4, const0_rtx);
39272       emit_insn (GEN_FCN (icode) (op0, op2, op3, op4, pat));
39273
39274       /* Store the result.  */
39275       op4 = expand_normal (arg3);
39276       if (!address_operand (op4, VOIDmode))
39277         {
39278           op4 = convert_memory_address (Pmode, op4);
39279           op4 = copy_addr_to_reg (op4);
39280         }
39281       emit_move_insn (gen_rtx_MEM (mode0, op4), op0);
39282
39283       /* Return current CF value.  */
39284       if (target == 0)
39285         target = gen_reg_rtx (QImode);
39286
39287       PUT_MODE (pat, QImode);
39288       emit_insn (gen_rtx_SET (VOIDmode, target, pat));
39289       return target;
39290
39291     case IX86_BUILTIN_READ_FLAGS:
39292       emit_insn (gen_push (gen_rtx_REG (word_mode, FLAGS_REG)));
39293
39294       if (optimize
39295           || target == NULL_RTX
39296           || !nonimmediate_operand (target, word_mode)
39297           || GET_MODE (target) != word_mode)
39298         target = gen_reg_rtx (word_mode);
39299
39300       emit_insn (gen_pop (target));
39301       return target;
39302
39303     case IX86_BUILTIN_WRITE_FLAGS:
39304
39305       arg0 = CALL_EXPR_ARG (exp, 0);
39306       op0 = expand_normal (arg0);
39307       if (!general_no_elim_operand (op0, word_mode))
39308         op0 = copy_to_mode_reg (word_mode, op0);
39309
39310       emit_insn (gen_push (op0));
39311       emit_insn (gen_pop (gen_rtx_REG (word_mode, FLAGS_REG)));
39312       return 0;
39313
39314     case IX86_BUILTIN_KORTESTC16:
39315       icode = CODE_FOR_kortestchi;
39316       mode0 = HImode;
39317       mode1 = CCCmode;
39318       goto kortest;
39319
39320     case IX86_BUILTIN_KORTESTZ16:
39321       icode = CODE_FOR_kortestzhi;
39322       mode0 = HImode;
39323       mode1 = CCZmode;
39324
39325     kortest:
39326       arg0 = CALL_EXPR_ARG (exp, 0); /* Mask reg src1.  */
39327       arg1 = CALL_EXPR_ARG (exp, 1); /* Mask reg src2.  */
39328       op0 = expand_normal (arg0);
39329       op1 = expand_normal (arg1);
39330
39331       op0 = copy_to_reg (op0);
39332       op0 = simplify_gen_subreg (mode0, op0, GET_MODE (op0), 0);
39333       op1 = copy_to_reg (op1);
39334       op1 = simplify_gen_subreg (mode0, op1, GET_MODE (op1), 0);
39335
39336       target = gen_reg_rtx (QImode);
39337       emit_insn (gen_rtx_SET (mode0, target, const0_rtx));
39338
39339       /* Emit kortest.  */
39340       emit_insn (GEN_FCN (icode) (op0, op1));
39341       /* And use setcc to return result from flags.  */
39342       ix86_expand_setcc (target, EQ,
39343                          gen_rtx_REG (mode1, FLAGS_REG), const0_rtx);
39344       return target;
39345
39346     case IX86_BUILTIN_GATHERSIV2DF:
39347       icode = CODE_FOR_avx2_gathersiv2df;
39348       goto gather_gen;
39349     case IX86_BUILTIN_GATHERSIV4DF:
39350       icode = CODE_FOR_avx2_gathersiv4df;
39351       goto gather_gen;
39352     case IX86_BUILTIN_GATHERDIV2DF:
39353       icode = CODE_FOR_avx2_gatherdiv2df;
39354       goto gather_gen;
39355     case IX86_BUILTIN_GATHERDIV4DF:
39356       icode = CODE_FOR_avx2_gatherdiv4df;
39357       goto gather_gen;
39358     case IX86_BUILTIN_GATHERSIV4SF:
39359       icode = CODE_FOR_avx2_gathersiv4sf;
39360       goto gather_gen;
39361     case IX86_BUILTIN_GATHERSIV8SF:
39362       icode = CODE_FOR_avx2_gathersiv8sf;
39363       goto gather_gen;
39364     case IX86_BUILTIN_GATHERDIV4SF:
39365       icode = CODE_FOR_avx2_gatherdiv4sf;
39366       goto gather_gen;
39367     case IX86_BUILTIN_GATHERDIV8SF:
39368       icode = CODE_FOR_avx2_gatherdiv8sf;
39369       goto gather_gen;
39370     case IX86_BUILTIN_GATHERSIV2DI:
39371       icode = CODE_FOR_avx2_gathersiv2di;
39372       goto gather_gen;
39373     case IX86_BUILTIN_GATHERSIV4DI:
39374       icode = CODE_FOR_avx2_gathersiv4di;
39375       goto gather_gen;
39376     case IX86_BUILTIN_GATHERDIV2DI:
39377       icode = CODE_FOR_avx2_gatherdiv2di;
39378       goto gather_gen;
39379     case IX86_BUILTIN_GATHERDIV4DI:
39380       icode = CODE_FOR_avx2_gatherdiv4di;
39381       goto gather_gen;
39382     case IX86_BUILTIN_GATHERSIV4SI:
39383       icode = CODE_FOR_avx2_gathersiv4si;
39384       goto gather_gen;
39385     case IX86_BUILTIN_GATHERSIV8SI:
39386       icode = CODE_FOR_avx2_gathersiv8si;
39387       goto gather_gen;
39388     case IX86_BUILTIN_GATHERDIV4SI:
39389       icode = CODE_FOR_avx2_gatherdiv4si;
39390       goto gather_gen;
39391     case IX86_BUILTIN_GATHERDIV8SI:
39392       icode = CODE_FOR_avx2_gatherdiv8si;
39393       goto gather_gen;
39394     case IX86_BUILTIN_GATHERALTSIV4DF:
39395       icode = CODE_FOR_avx2_gathersiv4df;
39396       goto gather_gen;
39397     case IX86_BUILTIN_GATHERALTDIV8SF:
39398       icode = CODE_FOR_avx2_gatherdiv8sf;
39399       goto gather_gen;
39400     case IX86_BUILTIN_GATHERALTSIV4DI:
39401       icode = CODE_FOR_avx2_gathersiv4di;
39402       goto gather_gen;
39403     case IX86_BUILTIN_GATHERALTDIV8SI:
39404       icode = CODE_FOR_avx2_gatherdiv8si;
39405       goto gather_gen;
39406     case IX86_BUILTIN_GATHER3SIV16SF:
39407       icode = CODE_FOR_avx512f_gathersiv16sf;
39408       goto gather_gen;
39409     case IX86_BUILTIN_GATHER3SIV8DF:
39410       icode = CODE_FOR_avx512f_gathersiv8df;
39411       goto gather_gen;
39412     case IX86_BUILTIN_GATHER3DIV16SF:
39413       icode = CODE_FOR_avx512f_gatherdiv16sf;
39414       goto gather_gen;
39415     case IX86_BUILTIN_GATHER3DIV8DF:
39416       icode = CODE_FOR_avx512f_gatherdiv8df;
39417       goto gather_gen;
39418     case IX86_BUILTIN_GATHER3SIV16SI:
39419       icode = CODE_FOR_avx512f_gathersiv16si;
39420       goto gather_gen;
39421     case IX86_BUILTIN_GATHER3SIV8DI:
39422       icode = CODE_FOR_avx512f_gathersiv8di;
39423       goto gather_gen;
39424     case IX86_BUILTIN_GATHER3DIV16SI:
39425       icode = CODE_FOR_avx512f_gatherdiv16si;
39426       goto gather_gen;
39427     case IX86_BUILTIN_GATHER3DIV8DI:
39428       icode = CODE_FOR_avx512f_gatherdiv8di;
39429       goto gather_gen;
39430     case IX86_BUILTIN_GATHER3ALTSIV8DF:
39431       icode = CODE_FOR_avx512f_gathersiv8df;
39432       goto gather_gen;
39433     case IX86_BUILTIN_GATHER3ALTDIV16SF:
39434       icode = CODE_FOR_avx512f_gatherdiv16sf;
39435       goto gather_gen;
39436     case IX86_BUILTIN_GATHER3ALTSIV8DI:
39437       icode = CODE_FOR_avx512f_gathersiv8di;
39438       goto gather_gen;
39439     case IX86_BUILTIN_GATHER3ALTDIV16SI:
39440       icode = CODE_FOR_avx512f_gatherdiv16si;
39441       goto gather_gen;
39442     case IX86_BUILTIN_GATHER3SIV2DF:
39443       icode = CODE_FOR_avx512vl_gathersiv2df;
39444       goto gather_gen;
39445     case IX86_BUILTIN_GATHER3SIV4DF:
39446       icode = CODE_FOR_avx512vl_gathersiv4df;
39447       goto gather_gen;
39448     case IX86_BUILTIN_GATHER3DIV2DF:
39449       icode = CODE_FOR_avx512vl_gatherdiv2df;
39450       goto gather_gen;
39451     case IX86_BUILTIN_GATHER3DIV4DF:
39452       icode = CODE_FOR_avx512vl_gatherdiv4df;
39453       goto gather_gen;
39454     case IX86_BUILTIN_GATHER3SIV4SF:
39455       icode = CODE_FOR_avx512vl_gathersiv4sf;
39456       goto gather_gen;
39457     case IX86_BUILTIN_GATHER3SIV8SF:
39458       icode = CODE_FOR_avx512vl_gathersiv8sf;
39459       goto gather_gen;
39460     case IX86_BUILTIN_GATHER3DIV4SF:
39461       icode = CODE_FOR_avx512vl_gatherdiv4sf;
39462       goto gather_gen;
39463     case IX86_BUILTIN_GATHER3DIV8SF:
39464       icode = CODE_FOR_avx512vl_gatherdiv8sf;
39465       goto gather_gen;
39466     case IX86_BUILTIN_GATHER3SIV2DI:
39467       icode = CODE_FOR_avx512vl_gathersiv2di;
39468       goto gather_gen;
39469     case IX86_BUILTIN_GATHER3SIV4DI:
39470       icode = CODE_FOR_avx512vl_gathersiv4di;
39471       goto gather_gen;
39472     case IX86_BUILTIN_GATHER3DIV2DI:
39473       icode = CODE_FOR_avx512vl_gatherdiv2di;
39474       goto gather_gen;
39475     case IX86_BUILTIN_GATHER3DIV4DI:
39476       icode = CODE_FOR_avx512vl_gatherdiv4di;
39477       goto gather_gen;
39478     case IX86_BUILTIN_GATHER3SIV4SI:
39479       icode = CODE_FOR_avx512vl_gathersiv4si;
39480       goto gather_gen;
39481     case IX86_BUILTIN_GATHER3SIV8SI:
39482       icode = CODE_FOR_avx512vl_gathersiv8si;
39483       goto gather_gen;
39484     case IX86_BUILTIN_GATHER3DIV4SI:
39485       icode = CODE_FOR_avx512vl_gatherdiv4si;
39486       goto gather_gen;
39487     case IX86_BUILTIN_GATHER3DIV8SI:
39488       icode = CODE_FOR_avx512vl_gatherdiv8si;
39489       goto gather_gen;
39490     case IX86_BUILTIN_GATHER3ALTSIV4DF:
39491       icode = CODE_FOR_avx512vl_gathersiv4df;
39492       goto gather_gen;
39493     case IX86_BUILTIN_GATHER3ALTDIV8SF:
39494       icode = CODE_FOR_avx512vl_gatherdiv8sf;
39495       goto gather_gen;
39496     case IX86_BUILTIN_GATHER3ALTSIV4DI:
39497       icode = CODE_FOR_avx512vl_gathersiv4di;
39498       goto gather_gen;
39499     case IX86_BUILTIN_GATHER3ALTDIV8SI:
39500       icode = CODE_FOR_avx512vl_gatherdiv8si;
39501       goto gather_gen;
39502     case IX86_BUILTIN_SCATTERSIV16SF:
39503       icode = CODE_FOR_avx512f_scattersiv16sf;
39504       goto scatter_gen;
39505     case IX86_BUILTIN_SCATTERSIV8DF:
39506       icode = CODE_FOR_avx512f_scattersiv8df;
39507       goto scatter_gen;
39508     case IX86_BUILTIN_SCATTERDIV16SF:
39509       icode = CODE_FOR_avx512f_scatterdiv16sf;
39510       goto scatter_gen;
39511     case IX86_BUILTIN_SCATTERDIV8DF:
39512       icode = CODE_FOR_avx512f_scatterdiv8df;
39513       goto scatter_gen;
39514     case IX86_BUILTIN_SCATTERSIV16SI:
39515       icode = CODE_FOR_avx512f_scattersiv16si;
39516       goto scatter_gen;
39517     case IX86_BUILTIN_SCATTERSIV8DI:
39518       icode = CODE_FOR_avx512f_scattersiv8di;
39519       goto scatter_gen;
39520     case IX86_BUILTIN_SCATTERDIV16SI:
39521       icode = CODE_FOR_avx512f_scatterdiv16si;
39522       goto scatter_gen;
39523     case IX86_BUILTIN_SCATTERDIV8DI:
39524       icode = CODE_FOR_avx512f_scatterdiv8di;
39525       goto scatter_gen;
39526     case IX86_BUILTIN_SCATTERSIV8SF:
39527       icode = CODE_FOR_avx512vl_scattersiv8sf;
39528       goto scatter_gen;
39529     case IX86_BUILTIN_SCATTERSIV4SF:
39530       icode = CODE_FOR_avx512vl_scattersiv4sf;
39531       goto scatter_gen;
39532     case IX86_BUILTIN_SCATTERSIV4DF:
39533       icode = CODE_FOR_avx512vl_scattersiv4df;
39534       goto scatter_gen;
39535     case IX86_BUILTIN_SCATTERSIV2DF:
39536       icode = CODE_FOR_avx512vl_scattersiv2df;
39537       goto scatter_gen;
39538     case IX86_BUILTIN_SCATTERDIV8SF:
39539       icode = CODE_FOR_avx512vl_scatterdiv8sf;
39540       goto scatter_gen;
39541     case IX86_BUILTIN_SCATTERDIV4SF:
39542       icode = CODE_FOR_avx512vl_scatterdiv4sf;
39543       goto scatter_gen;
39544     case IX86_BUILTIN_SCATTERDIV4DF:
39545       icode = CODE_FOR_avx512vl_scatterdiv4df;
39546       goto scatter_gen;
39547     case IX86_BUILTIN_SCATTERDIV2DF:
39548       icode = CODE_FOR_avx512vl_scatterdiv2df;
39549       goto scatter_gen;
39550     case IX86_BUILTIN_SCATTERSIV8SI:
39551       icode = CODE_FOR_avx512vl_scattersiv8si;
39552       goto scatter_gen;
39553     case IX86_BUILTIN_SCATTERSIV4SI:
39554       icode = CODE_FOR_avx512vl_scattersiv4si;
39555       goto scatter_gen;
39556     case IX86_BUILTIN_SCATTERSIV4DI:
39557       icode = CODE_FOR_avx512vl_scattersiv4di;
39558       goto scatter_gen;
39559     case IX86_BUILTIN_SCATTERSIV2DI:
39560       icode = CODE_FOR_avx512vl_scattersiv2di;
39561       goto scatter_gen;
39562     case IX86_BUILTIN_SCATTERDIV8SI:
39563       icode = CODE_FOR_avx512vl_scatterdiv8si;
39564       goto scatter_gen;
39565     case IX86_BUILTIN_SCATTERDIV4SI:
39566       icode = CODE_FOR_avx512vl_scatterdiv4si;
39567       goto scatter_gen;
39568     case IX86_BUILTIN_SCATTERDIV4DI:
39569       icode = CODE_FOR_avx512vl_scatterdiv4di;
39570       goto scatter_gen;
39571     case IX86_BUILTIN_SCATTERDIV2DI:
39572       icode = CODE_FOR_avx512vl_scatterdiv2di;
39573       goto scatter_gen;
39574     case IX86_BUILTIN_GATHERPFDPD:
39575       icode = CODE_FOR_avx512pf_gatherpfv8sidf;
39576       goto vec_prefetch_gen;
39577     case IX86_BUILTIN_GATHERPFDPS:
39578       icode = CODE_FOR_avx512pf_gatherpfv16sisf;
39579       goto vec_prefetch_gen;
39580     case IX86_BUILTIN_GATHERPFQPD:
39581       icode = CODE_FOR_avx512pf_gatherpfv8didf;
39582       goto vec_prefetch_gen;
39583     case IX86_BUILTIN_GATHERPFQPS:
39584       icode = CODE_FOR_avx512pf_gatherpfv8disf;
39585       goto vec_prefetch_gen;
39586     case IX86_BUILTIN_SCATTERPFDPD:
39587       icode = CODE_FOR_avx512pf_scatterpfv8sidf;
39588       goto vec_prefetch_gen;
39589     case IX86_BUILTIN_SCATTERPFDPS:
39590       icode = CODE_FOR_avx512pf_scatterpfv16sisf;
39591       goto vec_prefetch_gen;
39592     case IX86_BUILTIN_SCATTERPFQPD:
39593       icode = CODE_FOR_avx512pf_scatterpfv8didf;
39594       goto vec_prefetch_gen;
39595     case IX86_BUILTIN_SCATTERPFQPS:
39596       icode = CODE_FOR_avx512pf_scatterpfv8disf;
39597       goto vec_prefetch_gen;
39598
39599     gather_gen:
39600       rtx half;
39601       rtx (*gen) (rtx, rtx);
39602
39603       arg0 = CALL_EXPR_ARG (exp, 0);
39604       arg1 = CALL_EXPR_ARG (exp, 1);
39605       arg2 = CALL_EXPR_ARG (exp, 2);
39606       arg3 = CALL_EXPR_ARG (exp, 3);
39607       arg4 = CALL_EXPR_ARG (exp, 4);
39608       op0 = expand_normal (arg0);
39609       op1 = expand_normal (arg1);
39610       op2 = expand_normal (arg2);
39611       op3 = expand_normal (arg3);
39612       op4 = expand_normal (arg4);
39613       /* Note the arg order is different from the operand order.  */
39614       mode0 = insn_data[icode].operand[1].mode;
39615       mode2 = insn_data[icode].operand[3].mode;
39616       mode3 = insn_data[icode].operand[4].mode;
39617       mode4 = insn_data[icode].operand[5].mode;
39618
39619       if (target == NULL_RTX
39620           || GET_MODE (target) != insn_data[icode].operand[0].mode
39621           || !insn_data[icode].operand[0].predicate (target,
39622                                                      GET_MODE (target)))
39623         subtarget = gen_reg_rtx (insn_data[icode].operand[0].mode);
39624       else
39625         subtarget = target;
39626
39627       switch (fcode)
39628         {
39629         case IX86_BUILTIN_GATHER3ALTSIV8DF:
39630         case IX86_BUILTIN_GATHER3ALTSIV8DI:
39631           half = gen_reg_rtx (V8SImode);
39632           if (!nonimmediate_operand (op2, V16SImode))
39633             op2 = copy_to_mode_reg (V16SImode, op2);
39634           emit_insn (gen_vec_extract_lo_v16si (half, op2));
39635           op2 = half;
39636           break;
39637         case IX86_BUILTIN_GATHER3ALTSIV4DF:
39638         case IX86_BUILTIN_GATHER3ALTSIV4DI:
39639         case IX86_BUILTIN_GATHERALTSIV4DF:
39640         case IX86_BUILTIN_GATHERALTSIV4DI:
39641           half = gen_reg_rtx (V4SImode);
39642           if (!nonimmediate_operand (op2, V8SImode))
39643             op2 = copy_to_mode_reg (V8SImode, op2);
39644           emit_insn (gen_vec_extract_lo_v8si (half, op2));
39645           op2 = half;
39646           break;
39647         case IX86_BUILTIN_GATHER3ALTDIV16SF:
39648         case IX86_BUILTIN_GATHER3ALTDIV16SI:
39649           half = gen_reg_rtx (mode0);
39650           if (mode0 == V8SFmode)
39651             gen = gen_vec_extract_lo_v16sf;
39652           else
39653             gen = gen_vec_extract_lo_v16si;
39654           if (!nonimmediate_operand (op0, GET_MODE (op0)))
39655             op0 = copy_to_mode_reg (GET_MODE (op0), op0);
39656           emit_insn (gen (half, op0));
39657           op0 = half;
39658           if (GET_MODE (op3) != VOIDmode)
39659             {
39660               if (!nonimmediate_operand (op3, GET_MODE (op3)))
39661                 op3 = copy_to_mode_reg (GET_MODE (op3), op3);
39662               emit_insn (gen (half, op3));
39663               op3 = half;
39664             }
39665           break;
39666         case IX86_BUILTIN_GATHER3ALTDIV8SF:
39667         case IX86_BUILTIN_GATHER3ALTDIV8SI:
39668         case IX86_BUILTIN_GATHERALTDIV8SF:
39669         case IX86_BUILTIN_GATHERALTDIV8SI:
39670           half = gen_reg_rtx (mode0);
39671           if (mode0 == V4SFmode)
39672             gen = gen_vec_extract_lo_v8sf;
39673           else
39674             gen = gen_vec_extract_lo_v8si;
39675           if (!nonimmediate_operand (op0, GET_MODE (op0)))
39676             op0 = copy_to_mode_reg (GET_MODE (op0), op0);
39677           emit_insn (gen (half, op0));
39678           op0 = half;
39679           if (GET_MODE (op3) != VOIDmode)
39680             {
39681               if (!nonimmediate_operand (op3, GET_MODE (op3)))
39682                 op3 = copy_to_mode_reg (GET_MODE (op3), op3);
39683               emit_insn (gen (half, op3));
39684               op3 = half;
39685             }
39686           break;
39687         default:
39688           break;
39689         }
39690
39691       /* Force memory operand only with base register here.  But we
39692          don't want to do it on memory operand for other builtin
39693          functions.  */
39694       op1 = ix86_zero_extend_to_Pmode (op1);
39695
39696       if (!insn_data[icode].operand[1].predicate (op0, mode0))
39697         op0 = copy_to_mode_reg (mode0, op0);
39698       if (!insn_data[icode].operand[2].predicate (op1, Pmode))
39699         op1 = copy_to_mode_reg (Pmode, op1);
39700       if (!insn_data[icode].operand[3].predicate (op2, mode2))
39701         op2 = copy_to_mode_reg (mode2, op2);
39702       if (GET_MODE (op3) == mode3 || GET_MODE (op3) == VOIDmode)
39703         {
39704           if (!insn_data[icode].operand[4].predicate (op3, mode3))
39705             op3 = copy_to_mode_reg (mode3, op3);
39706         }
39707       else
39708         {
39709           op3 = copy_to_reg (op3);
39710           op3 = simplify_gen_subreg (mode3, op3, GET_MODE (op3), 0);
39711         }
39712       if (!insn_data[icode].operand[5].predicate (op4, mode4))
39713         {
39714           error ("the last argument must be scale 1, 2, 4, 8");
39715           return const0_rtx;
39716         }
39717
39718       /* Optimize.  If mask is known to have all high bits set,
39719          replace op0 with pc_rtx to signal that the instruction
39720          overwrites the whole destination and doesn't use its
39721          previous contents.  */
39722       if (optimize)
39723         {
39724           if (TREE_CODE (arg3) == INTEGER_CST)
39725             {
39726               if (integer_all_onesp (arg3))
39727                 op0 = pc_rtx;
39728             }
39729           else if (TREE_CODE (arg3) == VECTOR_CST)
39730             {
39731               unsigned int negative = 0;
39732               for (i = 0; i < VECTOR_CST_NELTS (arg3); ++i)
39733                 {
39734                   tree cst = VECTOR_CST_ELT (arg3, i);
39735                   if (TREE_CODE (cst) == INTEGER_CST
39736                       && tree_int_cst_sign_bit (cst))
39737                     negative++;
39738                   else if (TREE_CODE (cst) == REAL_CST
39739                            && REAL_VALUE_NEGATIVE (TREE_REAL_CST (cst)))
39740                     negative++;
39741                 }
39742               if (negative == TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg3)))
39743                 op0 = pc_rtx;
39744             }
39745           else if (TREE_CODE (arg3) == SSA_NAME
39746                    && TREE_CODE (TREE_TYPE (arg3)) == VECTOR_TYPE)
39747             {
39748               /* Recognize also when mask is like:
39749                  __v2df src = _mm_setzero_pd ();
39750                  __v2df mask = _mm_cmpeq_pd (src, src);
39751                  or
39752                  __v8sf src = _mm256_setzero_ps ();
39753                  __v8sf mask = _mm256_cmp_ps (src, src, _CMP_EQ_OQ);
39754                  as that is a cheaper way to load all ones into
39755                  a register than having to load a constant from
39756                  memory.  */
39757               gimple def_stmt = SSA_NAME_DEF_STMT (arg3);
39758               if (is_gimple_call (def_stmt))
39759                 {
39760                   tree fndecl = gimple_call_fndecl (def_stmt);
39761                   if (fndecl
39762                       && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
39763                     switch ((unsigned int) DECL_FUNCTION_CODE (fndecl))
39764                       {
39765                       case IX86_BUILTIN_CMPPD:
39766                       case IX86_BUILTIN_CMPPS:
39767                       case IX86_BUILTIN_CMPPD256:
39768                       case IX86_BUILTIN_CMPPS256:
39769                         if (!integer_zerop (gimple_call_arg (def_stmt, 2)))
39770                           break;
39771                         /* FALLTHRU */
39772                       case IX86_BUILTIN_CMPEQPD:
39773                       case IX86_BUILTIN_CMPEQPS:
39774                         if (initializer_zerop (gimple_call_arg (def_stmt, 0))
39775                             && initializer_zerop (gimple_call_arg (def_stmt,
39776                                                                    1)))
39777                           op0 = pc_rtx;
39778                         break;
39779                       default:
39780                         break;
39781                       }
39782                 }
39783             }
39784         }
39785
39786       pat = GEN_FCN (icode) (subtarget, op0, op1, op2, op3, op4);
39787       if (! pat)
39788         return const0_rtx;
39789       emit_insn (pat);
39790
39791       switch (fcode)
39792         {
39793         case IX86_BUILTIN_GATHER3DIV16SF:
39794           if (target == NULL_RTX)
39795             target = gen_reg_rtx (V8SFmode);
39796           emit_insn (gen_vec_extract_lo_v16sf (target, subtarget));
39797           break;
39798         case IX86_BUILTIN_GATHER3DIV16SI:
39799           if (target == NULL_RTX)
39800             target = gen_reg_rtx (V8SImode);
39801           emit_insn (gen_vec_extract_lo_v16si (target, subtarget));
39802           break;
39803         case IX86_BUILTIN_GATHER3DIV8SF:
39804         case IX86_BUILTIN_GATHERDIV8SF:
39805           if (target == NULL_RTX)
39806             target = gen_reg_rtx (V4SFmode);
39807           emit_insn (gen_vec_extract_lo_v8sf (target, subtarget));
39808           break;
39809         case IX86_BUILTIN_GATHER3DIV8SI:
39810         case IX86_BUILTIN_GATHERDIV8SI:
39811           if (target == NULL_RTX)
39812             target = gen_reg_rtx (V4SImode);
39813           emit_insn (gen_vec_extract_lo_v8si (target, subtarget));
39814           break;
39815         default:
39816           target = subtarget;
39817           break;
39818         }
39819       return target;
39820
39821     scatter_gen:
39822       arg0 = CALL_EXPR_ARG (exp, 0);
39823       arg1 = CALL_EXPR_ARG (exp, 1);
39824       arg2 = CALL_EXPR_ARG (exp, 2);
39825       arg3 = CALL_EXPR_ARG (exp, 3);
39826       arg4 = CALL_EXPR_ARG (exp, 4);
39827       op0 = expand_normal (arg0);
39828       op1 = expand_normal (arg1);
39829       op2 = expand_normal (arg2);
39830       op3 = expand_normal (arg3);
39831       op4 = expand_normal (arg4);
39832       mode1 = insn_data[icode].operand[1].mode;
39833       mode2 = insn_data[icode].operand[2].mode;
39834       mode3 = insn_data[icode].operand[3].mode;
39835       mode4 = insn_data[icode].operand[4].mode;
39836
39837       /* Force memory operand only with base register here.  But we
39838          don't want to do it on memory operand for other builtin
39839          functions.  */
39840       op0 = force_reg (Pmode, convert_to_mode (Pmode, op0, 1));
39841
39842       if (!insn_data[icode].operand[0].predicate (op0, Pmode))
39843         op0 = copy_to_mode_reg (Pmode, op0);
39844
39845       if (GET_MODE (op1) == mode1 || GET_MODE (op1) == VOIDmode)
39846         {
39847           if (!insn_data[icode].operand[1].predicate (op1, mode1))
39848             op1 = copy_to_mode_reg (mode1, op1);
39849         }
39850       else
39851         {
39852           op1 = copy_to_reg (op1);
39853           op1 = simplify_gen_subreg (mode1, op1, GET_MODE (op1), 0);
39854         }
39855
39856       if (!insn_data[icode].operand[2].predicate (op2, mode2))
39857         op2 = copy_to_mode_reg (mode2, op2);
39858
39859       if (!insn_data[icode].operand[3].predicate (op3, mode3))
39860         op3 = copy_to_mode_reg (mode3, op3);
39861
39862       if (!insn_data[icode].operand[4].predicate (op4, mode4))
39863         {
39864           error ("the last argument must be scale 1, 2, 4, 8");
39865           return const0_rtx;
39866         }
39867
39868       pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
39869       if (! pat)
39870         return const0_rtx;
39871
39872       emit_insn (pat);
39873       return 0;
39874
39875     vec_prefetch_gen:
39876       arg0 = CALL_EXPR_ARG (exp, 0);
39877       arg1 = CALL_EXPR_ARG (exp, 1);
39878       arg2 = CALL_EXPR_ARG (exp, 2);
39879       arg3 = CALL_EXPR_ARG (exp, 3);
39880       arg4 = CALL_EXPR_ARG (exp, 4);
39881       op0 = expand_normal (arg0);
39882       op1 = expand_normal (arg1);
39883       op2 = expand_normal (arg2);
39884       op3 = expand_normal (arg3);
39885       op4 = expand_normal (arg4);
39886       mode0 = insn_data[icode].operand[0].mode;
39887       mode1 = insn_data[icode].operand[1].mode;
39888       mode3 = insn_data[icode].operand[3].mode;
39889       mode4 = insn_data[icode].operand[4].mode;
39890
39891       if (GET_MODE (op0) == mode0
39892           || (GET_MODE (op0) == VOIDmode && op0 != constm1_rtx))
39893         {
39894           if (!insn_data[icode].operand[0].predicate (op0, mode0))
39895             op0 = copy_to_mode_reg (mode0, op0);
39896         }
39897       else if (op0 != constm1_rtx)
39898         {
39899           op0 = copy_to_reg (op0);
39900           op0 = simplify_gen_subreg (mode0, op0, GET_MODE (op0), 0);
39901         }
39902
39903       if (!insn_data[icode].operand[1].predicate (op1, mode1))
39904         op1 = copy_to_mode_reg (mode1, op1);
39905
39906       /* Force memory operand only with base register here.  But we
39907          don't want to do it on memory operand for other builtin
39908          functions.  */
39909       op2 = force_reg (Pmode, convert_to_mode (Pmode, op2, 1));
39910
39911       if (!insn_data[icode].operand[2].predicate (op2, Pmode))
39912         op2 = copy_to_mode_reg (Pmode, op2);
39913
39914       if (!insn_data[icode].operand[3].predicate (op3, mode3))
39915         {
39916           error ("the forth argument must be scale 1, 2, 4, 8");
39917           return const0_rtx;
39918         }
39919
39920       if (!insn_data[icode].operand[4].predicate (op4, mode4))
39921         {
39922           error ("incorrect hint operand");
39923           return const0_rtx;
39924         }
39925
39926       pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
39927       if (! pat)
39928         return const0_rtx;
39929
39930       emit_insn (pat);
39931
39932       return 0;
39933
39934     case IX86_BUILTIN_XABORT:
39935       icode = CODE_FOR_xabort;
39936       arg0 = CALL_EXPR_ARG (exp, 0);
39937       op0 = expand_normal (arg0);
39938       mode0 = insn_data[icode].operand[0].mode;
39939       if (!insn_data[icode].operand[0].predicate (op0, mode0))
39940         {
39941           error ("the xabort's argument must be an 8-bit immediate");
39942           return const0_rtx;
39943         }
39944       emit_insn (gen_xabort (op0));
39945       return 0;
39946
39947     default:
39948       break;
39949     }
39950
39951   for (i = 0, d = bdesc_special_args;
39952        i < ARRAY_SIZE (bdesc_special_args);
39953        i++, d++)
39954     if (d->code == fcode)
39955       return ix86_expand_special_args_builtin (d, exp, target);
39956
39957   for (i = 0, d = bdesc_args;
39958        i < ARRAY_SIZE (bdesc_args);
39959        i++, d++)
39960     if (d->code == fcode)
39961       switch (fcode)
39962         {
39963         case IX86_BUILTIN_FABSQ:
39964         case IX86_BUILTIN_COPYSIGNQ:
39965           if (!TARGET_SSE)
39966             /* Emit a normal call if SSE isn't available.  */
39967             return expand_call (exp, target, ignore);
39968         default:
39969           return ix86_expand_args_builtin (d, exp, target);
39970         }
39971
39972   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
39973     if (d->code == fcode)
39974       return ix86_expand_sse_comi (d, exp, target);
39975
39976   for (i = 0, d = bdesc_round_args; i < ARRAY_SIZE (bdesc_round_args); i++, d++)
39977     if (d->code == fcode)
39978       return ix86_expand_round_builtin (d, exp, target);
39979
39980   for (i = 0, d = bdesc_pcmpestr;
39981        i < ARRAY_SIZE (bdesc_pcmpestr);
39982        i++, d++)
39983     if (d->code == fcode)
39984       return ix86_expand_sse_pcmpestr (d, exp, target);
39985
39986   for (i = 0, d = bdesc_pcmpistr;
39987        i < ARRAY_SIZE (bdesc_pcmpistr);
39988        i++, d++)
39989     if (d->code == fcode)
39990       return ix86_expand_sse_pcmpistr (d, exp, target);
39991
39992   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
39993     if (d->code == fcode)
39994       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
39995                                             (enum ix86_builtin_func_type)
39996                                             d->flag, d->comparison);
39997
39998   gcc_unreachable ();
39999 }
40000
40001 /* This returns the target-specific builtin with code CODE if
40002    current_function_decl has visibility on this builtin, which is checked
40003    using isa flags.  Returns NULL_TREE otherwise.  */
40004
40005 static tree ix86_get_builtin (enum ix86_builtins code)
40006 {
40007   struct cl_target_option *opts;
40008   tree target_tree = NULL_TREE;
40009
40010   /* Determine the isa flags of current_function_decl.  */
40011
40012   if (current_function_decl)
40013     target_tree = DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl);
40014
40015   if (target_tree == NULL)
40016     target_tree = target_option_default_node;
40017
40018   opts = TREE_TARGET_OPTION (target_tree);
40019
40020   if (ix86_builtins_isa[(int) code].isa & opts->x_ix86_isa_flags)
40021     return ix86_builtin_decl (code, true);
40022   else
40023     return NULL_TREE;
40024 }
40025
40026 /* Return function decl for target specific builtin
40027    for given MPX builtin passed i FCODE.  */
40028 static tree
40029 ix86_builtin_mpx_function (unsigned fcode)
40030 {
40031   switch (fcode)
40032     {
40033     case BUILT_IN_CHKP_BNDMK:
40034       return ix86_builtins[IX86_BUILTIN_BNDMK];
40035
40036     case BUILT_IN_CHKP_BNDSTX:
40037       return ix86_builtins[IX86_BUILTIN_BNDSTX];
40038
40039     case BUILT_IN_CHKP_BNDLDX:
40040       return ix86_builtins[IX86_BUILTIN_BNDLDX];
40041
40042     case BUILT_IN_CHKP_BNDCL:
40043       return ix86_builtins[IX86_BUILTIN_BNDCL];
40044
40045     case BUILT_IN_CHKP_BNDCU:
40046       return ix86_builtins[IX86_BUILTIN_BNDCU];
40047
40048     case BUILT_IN_CHKP_BNDRET:
40049       return ix86_builtins[IX86_BUILTIN_BNDRET];
40050
40051     case BUILT_IN_CHKP_INTERSECT:
40052       return ix86_builtins[IX86_BUILTIN_BNDINT];
40053
40054     case BUILT_IN_CHKP_NARROW:
40055       return ix86_builtins[IX86_BUILTIN_BNDNARROW];
40056
40057     case BUILT_IN_CHKP_SIZEOF:
40058       return ix86_builtins[IX86_BUILTIN_SIZEOF];
40059
40060     case BUILT_IN_CHKP_EXTRACT_LOWER:
40061       return ix86_builtins[IX86_BUILTIN_BNDLOWER];
40062
40063     case BUILT_IN_CHKP_EXTRACT_UPPER:
40064       return ix86_builtins[IX86_BUILTIN_BNDUPPER];
40065
40066     default:
40067       return NULL_TREE;
40068     }
40069
40070   gcc_unreachable ();
40071 }
40072
40073 /* Helper function for ix86_load_bounds and ix86_store_bounds.
40074
40075    Return an address to be used to load/store bounds for pointer
40076    passed in SLOT.
40077
40078    SLOT_NO is an integer constant holding number of a target
40079    dependent special slot to be used in case SLOT is not a memory.
40080
40081    SPECIAL_BASE is a pointer to be used as a base of fake address
40082    to access special slots in Bounds Table.  SPECIAL_BASE[-1],
40083    SPECIAL_BASE[-2] etc. will be used as fake pointer locations.  */
40084
40085 static rtx
40086 ix86_get_arg_address_for_bt (rtx slot, rtx slot_no, rtx special_base)
40087 {
40088   rtx addr = NULL;
40089
40090   /* NULL slot means we pass bounds for pointer not passed to the
40091      function at all.  Register slot means we pass pointer in a
40092      register.  In both these cases bounds are passed via Bounds
40093      Table.  Since we do not have actual pointer stored in memory,
40094      we have to use fake addresses to access Bounds Table.  We
40095      start with (special_base - sizeof (void*)) and decrease this
40096      address by pointer size to get addresses for other slots.  */
40097   if (!slot || REG_P (slot))
40098     {
40099       gcc_assert (CONST_INT_P (slot_no));
40100       addr = plus_constant (Pmode, special_base,
40101                             -(INTVAL (slot_no) + 1) * GET_MODE_SIZE (Pmode));
40102     }
40103   /* If pointer is passed in a memory then its address is used to
40104      access Bounds Table.  */
40105   else if (MEM_P (slot))
40106     {
40107       addr = XEXP (slot, 0);
40108       if (!register_operand (addr, Pmode))
40109         addr = copy_addr_to_reg (addr);
40110     }
40111   else
40112     gcc_unreachable ();
40113
40114   return addr;
40115 }
40116
40117 /* Expand pass uses this hook to load bounds for function parameter
40118    PTR passed in SLOT in case its bounds are not passed in a register.
40119
40120    If SLOT is a memory, then bounds are loaded as for regular pointer
40121    loaded from memory.  PTR may be NULL in case SLOT is a memory.
40122    In such case value of PTR (if required) may be loaded from SLOT.
40123
40124    If SLOT is NULL or a register then SLOT_NO is an integer constant
40125    holding number of the target dependent special slot which should be
40126    used to obtain bounds.
40127
40128    Return loaded bounds.  */
40129
40130 static rtx
40131 ix86_load_bounds (rtx slot, rtx ptr, rtx slot_no)
40132 {
40133   rtx reg = gen_reg_rtx (BNDmode);
40134   rtx addr;
40135
40136   /* Get address to be used to access Bounds Table.  Special slots start
40137      at the location of return address of the current function.  */
40138   addr = ix86_get_arg_address_for_bt (slot, slot_no, arg_pointer_rtx);
40139
40140   /* Load pointer value from a memory if we don't have it.  */
40141   if (!ptr)
40142     {
40143       gcc_assert (MEM_P (slot));
40144       ptr = copy_addr_to_reg (slot);
40145     }
40146
40147   emit_insn (BNDmode == BND64mode
40148              ? gen_bnd64_ldx (reg, addr, ptr)
40149              : gen_bnd32_ldx (reg, addr, ptr));
40150
40151   return reg;
40152 }
40153
40154 /* Expand pass uses this hook to store BOUNDS for call argument PTR
40155    passed in SLOT in case BOUNDS are not passed in a register.
40156
40157    If SLOT is a memory, then BOUNDS are stored as for regular pointer
40158    stored in memory.  PTR may be NULL in case SLOT is a memory.
40159    In such case value of PTR (if required) may be loaded from SLOT.
40160
40161    If SLOT is NULL or a register then SLOT_NO is an integer constant
40162    holding number of the target dependent special slot which should be
40163    used to store BOUNDS.  */
40164
40165 static void
40166 ix86_store_bounds (rtx ptr, rtx slot, rtx bounds, rtx slot_no)
40167 {
40168   rtx addr;
40169
40170   /* Get address to be used to access Bounds Table.  Special slots start
40171      at the location of return address of a called function.  */
40172   addr = ix86_get_arg_address_for_bt (slot, slot_no, stack_pointer_rtx);
40173
40174   /* Load pointer value from a memory if we don't have it.  */
40175   if (!ptr)
40176     {
40177       gcc_assert (MEM_P (slot));
40178       ptr = copy_addr_to_reg (slot);
40179     }
40180
40181   gcc_assert (POINTER_BOUNDS_MODE_P (GET_MODE (bounds)));
40182   if (!register_operand (bounds, BNDmode))
40183     bounds = copy_to_mode_reg (BNDmode, bounds);
40184
40185   emit_insn (BNDmode == BND64mode
40186              ? gen_bnd64_stx (addr, ptr, bounds)
40187              : gen_bnd32_stx (addr, ptr, bounds));
40188 }
40189
40190 /* Load and return bounds returned by function in SLOT.  */
40191
40192 static rtx
40193 ix86_load_returned_bounds (rtx slot)
40194 {
40195   rtx res;
40196
40197   gcc_assert (REG_P (slot));
40198   res = gen_reg_rtx (BNDmode);
40199   emit_move_insn (res, slot);
40200
40201   return res;
40202 }
40203
40204 /* Store BOUNDS returned by function into SLOT.  */
40205
40206 static void
40207 ix86_store_returned_bounds (rtx slot, rtx bounds)
40208 {
40209   gcc_assert (REG_P (slot));
40210   emit_move_insn (slot, bounds);
40211 }
40212
40213 /* Returns a function decl for a vectorized version of the builtin function
40214    with builtin function code FN and the result vector type TYPE, or NULL_TREE
40215    if it is not available.  */
40216
40217 static tree
40218 ix86_builtin_vectorized_function (tree fndecl, tree type_out,
40219                                   tree type_in)
40220 {
40221   machine_mode in_mode, out_mode;
40222   int in_n, out_n;
40223   enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
40224
40225   if (TREE_CODE (type_out) != VECTOR_TYPE
40226       || TREE_CODE (type_in) != VECTOR_TYPE
40227       || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
40228     return NULL_TREE;
40229
40230   out_mode = TYPE_MODE (TREE_TYPE (type_out));
40231   out_n = TYPE_VECTOR_SUBPARTS (type_out);
40232   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40233   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40234
40235   switch (fn)
40236     {
40237     case BUILT_IN_SQRT:
40238       if (out_mode == DFmode && in_mode == DFmode)
40239         {
40240           if (out_n == 2 && in_n == 2)
40241             return ix86_get_builtin (IX86_BUILTIN_SQRTPD);
40242           else if (out_n == 4 && in_n == 4)
40243             return ix86_get_builtin (IX86_BUILTIN_SQRTPD256);
40244           else if (out_n == 8 && in_n == 8)
40245             return ix86_get_builtin (IX86_BUILTIN_SQRTPD512);
40246         }
40247       break;
40248
40249     case BUILT_IN_EXP2F:
40250       if (out_mode == SFmode && in_mode == SFmode)
40251         {
40252           if (out_n == 16 && in_n == 16)
40253             return ix86_get_builtin (IX86_BUILTIN_EXP2PS);
40254         }
40255       break;
40256
40257     case BUILT_IN_SQRTF:
40258       if (out_mode == SFmode && in_mode == SFmode)
40259         {
40260           if (out_n == 4 && in_n == 4)
40261             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR);
40262           else if (out_n == 8 && in_n == 8)
40263             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR256);
40264           else if (out_n == 16 && in_n == 16)
40265             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR512);
40266         }
40267       break;
40268
40269     case BUILT_IN_IFLOOR:
40270     case BUILT_IN_LFLOOR:
40271     case BUILT_IN_LLFLOOR:
40272       /* The round insn does not trap on denormals.  */
40273       if (flag_trapping_math || !TARGET_ROUND)
40274         break;
40275
40276       if (out_mode == SImode && in_mode == DFmode)
40277         {
40278           if (out_n == 4 && in_n == 2)
40279             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX);
40280           else if (out_n == 8 && in_n == 4)
40281             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256);
40282           else if (out_n == 16 && in_n == 8)
40283             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512);
40284         }
40285       break;
40286
40287     case BUILT_IN_IFLOORF:
40288     case BUILT_IN_LFLOORF:
40289     case BUILT_IN_LLFLOORF:
40290       /* The round insn does not trap on denormals.  */
40291       if (flag_trapping_math || !TARGET_ROUND)
40292         break;
40293
40294       if (out_mode == SImode && in_mode == SFmode)
40295         {
40296           if (out_n == 4 && in_n == 4)
40297             return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX);
40298           else if (out_n == 8 && in_n == 8)
40299             return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX256);
40300         }
40301       break;
40302
40303     case BUILT_IN_ICEIL:
40304     case BUILT_IN_LCEIL:
40305     case BUILT_IN_LLCEIL:
40306       /* The round insn does not trap on denormals.  */
40307       if (flag_trapping_math || !TARGET_ROUND)
40308         break;
40309
40310       if (out_mode == SImode && in_mode == DFmode)
40311         {
40312           if (out_n == 4 && in_n == 2)
40313             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX);
40314           else if (out_n == 8 && in_n == 4)
40315             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256);
40316           else if (out_n == 16 && in_n == 8)
40317             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512);
40318         }
40319       break;
40320
40321     case BUILT_IN_ICEILF:
40322     case BUILT_IN_LCEILF:
40323     case BUILT_IN_LLCEILF:
40324       /* The round insn does not trap on denormals.  */
40325       if (flag_trapping_math || !TARGET_ROUND)
40326         break;
40327
40328       if (out_mode == SImode && in_mode == SFmode)
40329         {
40330           if (out_n == 4 && in_n == 4)
40331             return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX);
40332           else if (out_n == 8 && in_n == 8)
40333             return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX256);
40334         }
40335       break;
40336
40337     case BUILT_IN_IRINT:
40338     case BUILT_IN_LRINT:
40339     case BUILT_IN_LLRINT:
40340       if (out_mode == SImode && in_mode == DFmode)
40341         {
40342           if (out_n == 4 && in_n == 2)
40343             return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX);
40344           else if (out_n == 8 && in_n == 4)
40345             return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX256);
40346         }
40347       break;
40348
40349     case BUILT_IN_IRINTF:
40350     case BUILT_IN_LRINTF:
40351     case BUILT_IN_LLRINTF:
40352       if (out_mode == SImode && in_mode == SFmode)
40353         {
40354           if (out_n == 4 && in_n == 4)
40355             return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ);
40356           else if (out_n == 8 && in_n == 8)
40357             return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ256);
40358         }
40359       break;
40360
40361     case BUILT_IN_IROUND:
40362     case BUILT_IN_LROUND:
40363     case BUILT_IN_LLROUND:
40364       /* The round insn does not trap on denormals.  */
40365       if (flag_trapping_math || !TARGET_ROUND)
40366         break;
40367
40368       if (out_mode == SImode && in_mode == DFmode)
40369         {
40370           if (out_n == 4 && in_n == 2)
40371             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX);
40372           else if (out_n == 8 && in_n == 4)
40373             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256);
40374           else if (out_n == 16 && in_n == 8)
40375             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512);
40376         }
40377       break;
40378
40379     case BUILT_IN_IROUNDF:
40380     case BUILT_IN_LROUNDF:
40381     case BUILT_IN_LLROUNDF:
40382       /* The round insn does not trap on denormals.  */
40383       if (flag_trapping_math || !TARGET_ROUND)
40384         break;
40385
40386       if (out_mode == SImode && in_mode == SFmode)
40387         {
40388           if (out_n == 4 && in_n == 4)
40389             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX);
40390           else if (out_n == 8 && in_n == 8)
40391             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX256);
40392         }
40393       break;
40394
40395     case BUILT_IN_COPYSIGN:
40396       if (out_mode == DFmode && in_mode == DFmode)
40397         {
40398           if (out_n == 2 && in_n == 2)
40399             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD);
40400           else if (out_n == 4 && in_n == 4)
40401             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD256);
40402           else if (out_n == 8 && in_n == 8)
40403             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD512);
40404         }
40405       break;
40406
40407     case BUILT_IN_COPYSIGNF:
40408       if (out_mode == SFmode && in_mode == SFmode)
40409         {
40410           if (out_n == 4 && in_n == 4)
40411             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS);
40412           else if (out_n == 8 && in_n == 8)
40413             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS256);
40414           else if (out_n == 16 && in_n == 16)
40415             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS512);
40416         }
40417       break;
40418
40419     case BUILT_IN_FLOOR:
40420       /* The round insn does not trap on denormals.  */
40421       if (flag_trapping_math || !TARGET_ROUND)
40422         break;
40423
40424       if (out_mode == DFmode && in_mode == DFmode)
40425         {
40426           if (out_n == 2 && in_n == 2)
40427             return ix86_get_builtin (IX86_BUILTIN_FLOORPD);
40428           else if (out_n == 4 && in_n == 4)
40429             return ix86_get_builtin (IX86_BUILTIN_FLOORPD256);
40430         }
40431       break;
40432
40433     case BUILT_IN_FLOORF:
40434       /* The round insn does not trap on denormals.  */
40435       if (flag_trapping_math || !TARGET_ROUND)
40436         break;
40437
40438       if (out_mode == SFmode && in_mode == SFmode)
40439         {
40440           if (out_n == 4 && in_n == 4)
40441             return ix86_get_builtin (IX86_BUILTIN_FLOORPS);
40442           else if (out_n == 8 && in_n == 8)
40443             return ix86_get_builtin (IX86_BUILTIN_FLOORPS256);
40444         }
40445       break;
40446
40447     case BUILT_IN_CEIL:
40448       /* The round insn does not trap on denormals.  */
40449       if (flag_trapping_math || !TARGET_ROUND)
40450         break;
40451
40452       if (out_mode == DFmode && in_mode == DFmode)
40453         {
40454           if (out_n == 2 && in_n == 2)
40455             return ix86_get_builtin (IX86_BUILTIN_CEILPD);
40456           else if (out_n == 4 && in_n == 4)
40457             return ix86_get_builtin (IX86_BUILTIN_CEILPD256);
40458         }
40459       break;
40460
40461     case BUILT_IN_CEILF:
40462       /* The round insn does not trap on denormals.  */
40463       if (flag_trapping_math || !TARGET_ROUND)
40464         break;
40465
40466       if (out_mode == SFmode && in_mode == SFmode)
40467         {
40468           if (out_n == 4 && in_n == 4)
40469             return ix86_get_builtin (IX86_BUILTIN_CEILPS);
40470           else if (out_n == 8 && in_n == 8)
40471             return ix86_get_builtin (IX86_BUILTIN_CEILPS256);
40472         }
40473       break;
40474
40475     case BUILT_IN_TRUNC:
40476       /* The round insn does not trap on denormals.  */
40477       if (flag_trapping_math || !TARGET_ROUND)
40478         break;
40479
40480       if (out_mode == DFmode && in_mode == DFmode)
40481         {
40482           if (out_n == 2 && in_n == 2)
40483             return ix86_get_builtin (IX86_BUILTIN_TRUNCPD);
40484           else if (out_n == 4 && in_n == 4)
40485             return ix86_get_builtin (IX86_BUILTIN_TRUNCPD256);
40486         }
40487       break;
40488
40489     case BUILT_IN_TRUNCF:
40490       /* The round insn does not trap on denormals.  */
40491       if (flag_trapping_math || !TARGET_ROUND)
40492         break;
40493
40494       if (out_mode == SFmode && in_mode == SFmode)
40495         {
40496           if (out_n == 4 && in_n == 4)
40497             return ix86_get_builtin (IX86_BUILTIN_TRUNCPS);
40498           else if (out_n == 8 && in_n == 8)
40499             return ix86_get_builtin (IX86_BUILTIN_TRUNCPS256);
40500         }
40501       break;
40502
40503     case BUILT_IN_RINT:
40504       /* The round insn does not trap on denormals.  */
40505       if (flag_trapping_math || !TARGET_ROUND)
40506         break;
40507
40508       if (out_mode == DFmode && in_mode == DFmode)
40509         {
40510           if (out_n == 2 && in_n == 2)
40511             return ix86_get_builtin (IX86_BUILTIN_RINTPD);
40512           else if (out_n == 4 && in_n == 4)
40513             return ix86_get_builtin (IX86_BUILTIN_RINTPD256);
40514         }
40515       break;
40516
40517     case BUILT_IN_RINTF:
40518       /* The round insn does not trap on denormals.  */
40519       if (flag_trapping_math || !TARGET_ROUND)
40520         break;
40521
40522       if (out_mode == SFmode && in_mode == SFmode)
40523         {
40524           if (out_n == 4 && in_n == 4)
40525             return ix86_get_builtin (IX86_BUILTIN_RINTPS);
40526           else if (out_n == 8 && in_n == 8)
40527             return ix86_get_builtin (IX86_BUILTIN_RINTPS256);
40528         }
40529       break;
40530
40531     case BUILT_IN_ROUND:
40532       /* The round insn does not trap on denormals.  */
40533       if (flag_trapping_math || !TARGET_ROUND)
40534         break;
40535
40536       if (out_mode == DFmode && in_mode == DFmode)
40537         {
40538           if (out_n == 2 && in_n == 2)
40539             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ);
40540           else if (out_n == 4 && in_n == 4)
40541             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ256);
40542         }
40543       break;
40544
40545     case BUILT_IN_ROUNDF:
40546       /* The round insn does not trap on denormals.  */
40547       if (flag_trapping_math || !TARGET_ROUND)
40548         break;
40549
40550       if (out_mode == SFmode && in_mode == SFmode)
40551         {
40552           if (out_n == 4 && in_n == 4)
40553             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ);
40554           else if (out_n == 8 && in_n == 8)
40555             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ256);
40556         }
40557       break;
40558
40559     case BUILT_IN_FMA:
40560       if (out_mode == DFmode && in_mode == DFmode)
40561         {
40562           if (out_n == 2 && in_n == 2)
40563             return ix86_get_builtin (IX86_BUILTIN_VFMADDPD);
40564           if (out_n == 4 && in_n == 4)
40565             return ix86_get_builtin (IX86_BUILTIN_VFMADDPD256);
40566         }
40567       break;
40568
40569     case BUILT_IN_FMAF:
40570       if (out_mode == SFmode && in_mode == SFmode)
40571         {
40572           if (out_n == 4 && in_n == 4)
40573             return ix86_get_builtin (IX86_BUILTIN_VFMADDPS);
40574           if (out_n == 8 && in_n == 8)
40575             return ix86_get_builtin (IX86_BUILTIN_VFMADDPS256);
40576         }
40577       break;
40578
40579     default:
40580       break;
40581     }
40582
40583   /* Dispatch to a handler for a vectorization library.  */
40584   if (ix86_veclib_handler)
40585     return ix86_veclib_handler ((enum built_in_function) fn, type_out,
40586                                 type_in);
40587
40588   return NULL_TREE;
40589 }
40590
40591 /* Handler for an SVML-style interface to
40592    a library with vectorized intrinsics.  */
40593
40594 static tree
40595 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
40596 {
40597   char name[20];
40598   tree fntype, new_fndecl, args;
40599   unsigned arity;
40600   const char *bname;
40601   machine_mode el_mode, in_mode;
40602   int n, in_n;
40603
40604   /* The SVML is suitable for unsafe math only.  */
40605   if (!flag_unsafe_math_optimizations)
40606     return NULL_TREE;
40607
40608   el_mode = TYPE_MODE (TREE_TYPE (type_out));
40609   n = TYPE_VECTOR_SUBPARTS (type_out);
40610   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40611   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40612   if (el_mode != in_mode
40613       || n != in_n)
40614     return NULL_TREE;
40615
40616   switch (fn)
40617     {
40618     case BUILT_IN_EXP:
40619     case BUILT_IN_LOG:
40620     case BUILT_IN_LOG10:
40621     case BUILT_IN_POW:
40622     case BUILT_IN_TANH:
40623     case BUILT_IN_TAN:
40624     case BUILT_IN_ATAN:
40625     case BUILT_IN_ATAN2:
40626     case BUILT_IN_ATANH:
40627     case BUILT_IN_CBRT:
40628     case BUILT_IN_SINH:
40629     case BUILT_IN_SIN:
40630     case BUILT_IN_ASINH:
40631     case BUILT_IN_ASIN:
40632     case BUILT_IN_COSH:
40633     case BUILT_IN_COS:
40634     case BUILT_IN_ACOSH:
40635     case BUILT_IN_ACOS:
40636       if (el_mode != DFmode || n != 2)
40637         return NULL_TREE;
40638       break;
40639
40640     case BUILT_IN_EXPF:
40641     case BUILT_IN_LOGF:
40642     case BUILT_IN_LOG10F:
40643     case BUILT_IN_POWF:
40644     case BUILT_IN_TANHF:
40645     case BUILT_IN_TANF:
40646     case BUILT_IN_ATANF:
40647     case BUILT_IN_ATAN2F:
40648     case BUILT_IN_ATANHF:
40649     case BUILT_IN_CBRTF:
40650     case BUILT_IN_SINHF:
40651     case BUILT_IN_SINF:
40652     case BUILT_IN_ASINHF:
40653     case BUILT_IN_ASINF:
40654     case BUILT_IN_COSHF:
40655     case BUILT_IN_COSF:
40656     case BUILT_IN_ACOSHF:
40657     case BUILT_IN_ACOSF:
40658       if (el_mode != SFmode || n != 4)
40659         return NULL_TREE;
40660       break;
40661
40662     default:
40663       return NULL_TREE;
40664     }
40665
40666   bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
40667
40668   if (fn == BUILT_IN_LOGF)
40669     strcpy (name, "vmlsLn4");
40670   else if (fn == BUILT_IN_LOG)
40671     strcpy (name, "vmldLn2");
40672   else if (n == 4)
40673     {
40674       sprintf (name, "vmls%s", bname+10);
40675       name[strlen (name)-1] = '4';
40676     }
40677   else
40678     sprintf (name, "vmld%s2", bname+10);
40679
40680   /* Convert to uppercase. */
40681   name[4] &= ~0x20;
40682
40683   arity = 0;
40684   for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
40685        args;
40686        args = TREE_CHAIN (args))
40687     arity++;
40688
40689   if (arity == 1)
40690     fntype = build_function_type_list (type_out, type_in, NULL);
40691   else
40692     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
40693
40694   /* Build a function declaration for the vectorized function.  */
40695   new_fndecl = build_decl (BUILTINS_LOCATION,
40696                            FUNCTION_DECL, get_identifier (name), fntype);
40697   TREE_PUBLIC (new_fndecl) = 1;
40698   DECL_EXTERNAL (new_fndecl) = 1;
40699   DECL_IS_NOVOPS (new_fndecl) = 1;
40700   TREE_READONLY (new_fndecl) = 1;
40701
40702   return new_fndecl;
40703 }
40704
40705 /* Handler for an ACML-style interface to
40706    a library with vectorized intrinsics.  */
40707
40708 static tree
40709 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
40710 {
40711   char name[20] = "__vr.._";
40712   tree fntype, new_fndecl, args;
40713   unsigned arity;
40714   const char *bname;
40715   machine_mode el_mode, in_mode;
40716   int n, in_n;
40717
40718   /* The ACML is 64bits only and suitable for unsafe math only as
40719      it does not correctly support parts of IEEE with the required
40720      precision such as denormals.  */
40721   if (!TARGET_64BIT
40722       || !flag_unsafe_math_optimizations)
40723     return NULL_TREE;
40724
40725   el_mode = TYPE_MODE (TREE_TYPE (type_out));
40726   n = TYPE_VECTOR_SUBPARTS (type_out);
40727   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40728   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40729   if (el_mode != in_mode
40730       || n != in_n)
40731     return NULL_TREE;
40732
40733   switch (fn)
40734     {
40735     case BUILT_IN_SIN:
40736     case BUILT_IN_COS:
40737     case BUILT_IN_EXP:
40738     case BUILT_IN_LOG:
40739     case BUILT_IN_LOG2:
40740     case BUILT_IN_LOG10:
40741       name[4] = 'd';
40742       name[5] = '2';
40743       if (el_mode != DFmode
40744           || n != 2)
40745         return NULL_TREE;
40746       break;
40747
40748     case BUILT_IN_SINF:
40749     case BUILT_IN_COSF:
40750     case BUILT_IN_EXPF:
40751     case BUILT_IN_POWF:
40752     case BUILT_IN_LOGF:
40753     case BUILT_IN_LOG2F:
40754     case BUILT_IN_LOG10F:
40755       name[4] = 's';
40756       name[5] = '4';
40757       if (el_mode != SFmode
40758           || n != 4)
40759         return NULL_TREE;
40760       break;
40761
40762     default:
40763       return NULL_TREE;
40764     }
40765
40766   bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
40767   sprintf (name + 7, "%s", bname+10);
40768
40769   arity = 0;
40770   for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
40771        args;
40772        args = TREE_CHAIN (args))
40773     arity++;
40774
40775   if (arity == 1)
40776     fntype = build_function_type_list (type_out, type_in, NULL);
40777   else
40778     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
40779
40780   /* Build a function declaration for the vectorized function.  */
40781   new_fndecl = build_decl (BUILTINS_LOCATION,
40782                            FUNCTION_DECL, get_identifier (name), fntype);
40783   TREE_PUBLIC (new_fndecl) = 1;
40784   DECL_EXTERNAL (new_fndecl) = 1;
40785   DECL_IS_NOVOPS (new_fndecl) = 1;
40786   TREE_READONLY (new_fndecl) = 1;
40787
40788   return new_fndecl;
40789 }
40790
40791 /* Returns a decl of a function that implements gather load with
40792    memory type MEM_VECTYPE and index type INDEX_VECTYPE and SCALE.
40793    Return NULL_TREE if it is not available.  */
40794
40795 static tree
40796 ix86_vectorize_builtin_gather (const_tree mem_vectype,
40797                                const_tree index_type, int scale)
40798 {
40799   bool si;
40800   enum ix86_builtins code;
40801
40802   if (! TARGET_AVX2)
40803     return NULL_TREE;
40804
40805   if ((TREE_CODE (index_type) != INTEGER_TYPE
40806        && !POINTER_TYPE_P (index_type))
40807       || (TYPE_MODE (index_type) != SImode
40808           && TYPE_MODE (index_type) != DImode))
40809     return NULL_TREE;
40810
40811   if (TYPE_PRECISION (index_type) > POINTER_SIZE)
40812     return NULL_TREE;
40813
40814   /* v*gather* insn sign extends index to pointer mode.  */
40815   if (TYPE_PRECISION (index_type) < POINTER_SIZE
40816       && TYPE_UNSIGNED (index_type))
40817     return NULL_TREE;
40818
40819   if (scale <= 0
40820       || scale > 8
40821       || (scale & (scale - 1)) != 0)
40822     return NULL_TREE;
40823
40824   si = TYPE_MODE (index_type) == SImode;
40825   switch (TYPE_MODE (mem_vectype))
40826     {
40827     case V2DFmode:
40828       if (TARGET_AVX512VL)
40829         code = si ? IX86_BUILTIN_GATHER3SIV2DF : IX86_BUILTIN_GATHER3DIV2DF;
40830       else
40831         code = si ? IX86_BUILTIN_GATHERSIV2DF : IX86_BUILTIN_GATHERDIV2DF;
40832       break;
40833     case V4DFmode:
40834       if (TARGET_AVX512VL)
40835         code = si ? IX86_BUILTIN_GATHER3ALTSIV4DF : IX86_BUILTIN_GATHER3DIV4DF;
40836       else
40837         code = si ? IX86_BUILTIN_GATHERALTSIV4DF : IX86_BUILTIN_GATHERDIV4DF;
40838       break;
40839     case V2DImode:
40840       if (TARGET_AVX512VL)
40841         code = si ? IX86_BUILTIN_GATHER3SIV2DI : IX86_BUILTIN_GATHER3DIV2DI;
40842       else
40843         code = si ? IX86_BUILTIN_GATHERSIV2DI : IX86_BUILTIN_GATHERDIV2DI;
40844       break;
40845     case V4DImode:
40846       if (TARGET_AVX512VL)
40847         code = si ? IX86_BUILTIN_GATHER3ALTSIV4DI : IX86_BUILTIN_GATHER3DIV4DI;
40848       else
40849         code = si ? IX86_BUILTIN_GATHERALTSIV4DI : IX86_BUILTIN_GATHERDIV4DI;
40850       break;
40851     case V4SFmode:
40852       if (TARGET_AVX512VL)
40853         code = si ? IX86_BUILTIN_GATHER3SIV4SF : IX86_BUILTIN_GATHER3DIV4SF;
40854       else
40855         code = si ? IX86_BUILTIN_GATHERSIV4SF : IX86_BUILTIN_GATHERDIV4SF;
40856       break;
40857     case V8SFmode:
40858       if (TARGET_AVX512VL)
40859         code = si ? IX86_BUILTIN_GATHER3SIV8SF : IX86_BUILTIN_GATHER3ALTDIV8SF;
40860       else
40861         code = si ? IX86_BUILTIN_GATHERSIV8SF : IX86_BUILTIN_GATHERALTDIV8SF;
40862       break;
40863     case V4SImode:
40864       if (TARGET_AVX512VL)
40865         code = si ? IX86_BUILTIN_GATHER3SIV4SI : IX86_BUILTIN_GATHER3DIV4SI;
40866       else
40867         code = si ? IX86_BUILTIN_GATHERSIV4SI : IX86_BUILTIN_GATHERDIV4SI;
40868       break;
40869     case V8SImode:
40870       if (TARGET_AVX512VL)
40871         code = si ? IX86_BUILTIN_GATHER3SIV8SI : IX86_BUILTIN_GATHER3ALTDIV8SI;
40872       else
40873         code = si ? IX86_BUILTIN_GATHERSIV8SI : IX86_BUILTIN_GATHERALTDIV8SI;
40874       break;
40875     case V8DFmode:
40876       if (TARGET_AVX512F)
40877         code = si ? IX86_BUILTIN_GATHER3ALTSIV8DF : IX86_BUILTIN_GATHER3DIV8DF;
40878       else
40879         return NULL_TREE;
40880       break;
40881     case V8DImode:
40882       if (TARGET_AVX512F)
40883         code = si ? IX86_BUILTIN_GATHER3ALTSIV8DI : IX86_BUILTIN_GATHER3DIV8DI;
40884       else
40885         return NULL_TREE;
40886       break;
40887     case V16SFmode:
40888       if (TARGET_AVX512F)
40889         code = si ? IX86_BUILTIN_GATHER3SIV16SF : IX86_BUILTIN_GATHER3ALTDIV16SF;
40890       else
40891         return NULL_TREE;
40892       break;
40893     case V16SImode:
40894       if (TARGET_AVX512F)
40895         code = si ? IX86_BUILTIN_GATHER3SIV16SI : IX86_BUILTIN_GATHER3ALTDIV16SI;
40896       else
40897         return NULL_TREE;
40898       break;
40899     default:
40900       return NULL_TREE;
40901     }
40902
40903   return ix86_get_builtin (code);
40904 }
40905
40906 /* Returns a code for a target-specific builtin that implements
40907    reciprocal of the function, or NULL_TREE if not available.  */
40908
40909 static tree
40910 ix86_builtin_reciprocal (unsigned int fn, bool md_fn, bool)
40911 {
40912   if (! (TARGET_SSE_MATH && !optimize_insn_for_size_p ()
40913          && flag_finite_math_only && !flag_trapping_math
40914          && flag_unsafe_math_optimizations))
40915     return NULL_TREE;
40916
40917   if (md_fn)
40918     /* Machine dependent builtins.  */
40919     switch (fn)
40920       {
40921         /* Vectorized version of sqrt to rsqrt conversion.  */
40922       case IX86_BUILTIN_SQRTPS_NR:
40923         return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR);
40924
40925       case IX86_BUILTIN_SQRTPS_NR256:
40926         return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR256);
40927
40928       default:
40929         return NULL_TREE;
40930       }
40931   else
40932     /* Normal builtins.  */
40933     switch (fn)
40934       {
40935         /* Sqrt to rsqrt conversion.  */
40936       case BUILT_IN_SQRTF:
40937         return ix86_get_builtin (IX86_BUILTIN_RSQRTF);
40938
40939       default:
40940         return NULL_TREE;
40941       }
40942 }
40943 \f
40944 /* Helper for avx_vpermilps256_operand et al.  This is also used by
40945    the expansion functions to turn the parallel back into a mask.
40946    The return value is 0 for no match and the imm8+1 for a match.  */
40947
40948 int
40949 avx_vpermilp_parallel (rtx par, machine_mode mode)
40950 {
40951   unsigned i, nelt = GET_MODE_NUNITS (mode);
40952   unsigned mask = 0;
40953   unsigned char ipar[16] = {};  /* Silence -Wuninitialized warning.  */
40954
40955   if (XVECLEN (par, 0) != (int) nelt)
40956     return 0;
40957
40958   /* Validate that all of the elements are constants, and not totally
40959      out of range.  Copy the data into an integral array to make the
40960      subsequent checks easier.  */
40961   for (i = 0; i < nelt; ++i)
40962     {
40963       rtx er = XVECEXP (par, 0, i);
40964       unsigned HOST_WIDE_INT ei;
40965
40966       if (!CONST_INT_P (er))
40967         return 0;
40968       ei = INTVAL (er);
40969       if (ei >= nelt)
40970         return 0;
40971       ipar[i] = ei;
40972     }
40973
40974   switch (mode)
40975     {
40976     case V8DFmode:
40977       /* In the 512-bit DFmode case, we can only move elements within
40978          a 128-bit lane.  First fill the second part of the mask,
40979          then fallthru.  */
40980       for (i = 4; i < 6; ++i)
40981         {
40982           if (ipar[i] < 4 || ipar[i] >= 6)
40983             return 0;
40984           mask |= (ipar[i] - 4) << i;
40985         }
40986       for (i = 6; i < 8; ++i)
40987         {
40988           if (ipar[i] < 6)
40989             return 0;
40990           mask |= (ipar[i] - 6) << i;
40991         }
40992       /* FALLTHRU */
40993
40994     case V4DFmode:
40995       /* In the 256-bit DFmode case, we can only move elements within
40996          a 128-bit lane.  */
40997       for (i = 0; i < 2; ++i)
40998         {
40999           if (ipar[i] >= 2)
41000             return 0;
41001           mask |= ipar[i] << i;
41002         }
41003       for (i = 2; i < 4; ++i)
41004         {
41005           if (ipar[i] < 2)
41006             return 0;
41007           mask |= (ipar[i] - 2) << i;
41008         }
41009       break;
41010
41011     case V16SFmode:
41012       /* In 512 bit SFmode case, permutation in the upper 256 bits
41013          must mirror the permutation in the lower 256-bits.  */
41014       for (i = 0; i < 8; ++i)
41015         if (ipar[i] + 8 != ipar[i + 8])
41016           return 0;
41017       /* FALLTHRU */
41018
41019     case V8SFmode:
41020       /* In 256 bit SFmode case, we have full freedom of
41021          movement within the low 128-bit lane, but the high 128-bit
41022          lane must mirror the exact same pattern.  */
41023       for (i = 0; i < 4; ++i)
41024         if (ipar[i] + 4 != ipar[i + 4])
41025           return 0;
41026       nelt = 4;
41027       /* FALLTHRU */
41028
41029     case V2DFmode:
41030     case V4SFmode:
41031       /* In the 128-bit case, we've full freedom in the placement of
41032          the elements from the source operand.  */
41033       for (i = 0; i < nelt; ++i)
41034         mask |= ipar[i] << (i * (nelt / 2));
41035       break;
41036
41037     default:
41038       gcc_unreachable ();
41039     }
41040
41041   /* Make sure success has a non-zero value by adding one.  */
41042   return mask + 1;
41043 }
41044
41045 /* Helper for avx_vperm2f128_v4df_operand et al.  This is also used by
41046    the expansion functions to turn the parallel back into a mask.
41047    The return value is 0 for no match and the imm8+1 for a match.  */
41048
41049 int
41050 avx_vperm2f128_parallel (rtx par, machine_mode mode)
41051 {
41052   unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2;
41053   unsigned mask = 0;
41054   unsigned char ipar[8] = {};  /* Silence -Wuninitialized warning.  */
41055
41056   if (XVECLEN (par, 0) != (int) nelt)
41057     return 0;
41058
41059   /* Validate that all of the elements are constants, and not totally
41060      out of range.  Copy the data into an integral array to make the
41061      subsequent checks easier.  */
41062   for (i = 0; i < nelt; ++i)
41063     {
41064       rtx er = XVECEXP (par, 0, i);
41065       unsigned HOST_WIDE_INT ei;
41066
41067       if (!CONST_INT_P (er))
41068         return 0;
41069       ei = INTVAL (er);
41070       if (ei >= 2 * nelt)
41071         return 0;
41072       ipar[i] = ei;
41073     }
41074
41075   /* Validate that the halves of the permute are halves.  */
41076   for (i = 0; i < nelt2 - 1; ++i)
41077     if (ipar[i] + 1 != ipar[i + 1])
41078       return 0;
41079   for (i = nelt2; i < nelt - 1; ++i)
41080     if (ipar[i] + 1 != ipar[i + 1])
41081       return 0;
41082
41083   /* Reconstruct the mask.  */
41084   for (i = 0; i < 2; ++i)
41085     {
41086       unsigned e = ipar[i * nelt2];
41087       if (e % nelt2)
41088         return 0;
41089       e /= nelt2;
41090       mask |= e << (i * 4);
41091     }
41092
41093   /* Make sure success has a non-zero value by adding one.  */
41094   return mask + 1;
41095 }
41096 \f
41097 /* Return a register priority for hard reg REGNO.  */
41098 static int
41099 ix86_register_priority (int hard_regno)
41100 {
41101   /* ebp and r13 as the base always wants a displacement, r12 as the
41102      base always wants an index.  So discourage their usage in an
41103      address.  */
41104   if (hard_regno == R12_REG || hard_regno == R13_REG)
41105     return 0;
41106   if (hard_regno == BP_REG)
41107     return 1;
41108   /* New x86-64 int registers result in bigger code size.  Discourage
41109      them.  */
41110   if (FIRST_REX_INT_REG <= hard_regno && hard_regno <= LAST_REX_INT_REG)
41111     return 2;
41112   /* New x86-64 SSE registers result in bigger code size.  Discourage
41113      them.  */
41114   if (FIRST_REX_SSE_REG <= hard_regno && hard_regno <= LAST_REX_SSE_REG)
41115     return 2;
41116   /* Usage of AX register results in smaller code.  Prefer it.  */
41117   if (hard_regno == 0)
41118     return 4;
41119   return 3;
41120 }
41121
41122 /* Implement TARGET_PREFERRED_RELOAD_CLASS.
41123
41124    Put float CONST_DOUBLE in the constant pool instead of fp regs.
41125    QImode must go into class Q_REGS.
41126    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
41127    movdf to do mem-to-mem moves through integer regs.  */
41128
41129 static reg_class_t
41130 ix86_preferred_reload_class (rtx x, reg_class_t regclass)
41131 {
41132   machine_mode mode = GET_MODE (x);
41133
41134   /* We're only allowed to return a subclass of CLASS.  Many of the
41135      following checks fail for NO_REGS, so eliminate that early.  */
41136   if (regclass == NO_REGS)
41137     return NO_REGS;
41138
41139   /* All classes can load zeros.  */
41140   if (x == CONST0_RTX (mode))
41141     return regclass;
41142
41143   /* Force constants into memory if we are loading a (nonzero) constant into
41144      an MMX, SSE or MASK register.  This is because there are no MMX/SSE/MASK
41145      instructions to load from a constant.  */
41146   if (CONSTANT_P (x)
41147       && (MAYBE_MMX_CLASS_P (regclass)
41148           || MAYBE_SSE_CLASS_P (regclass)
41149           || MAYBE_MASK_CLASS_P (regclass)))
41150     return NO_REGS;
41151
41152   /* Prefer SSE regs only, if we can use them for math.  */
41153   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
41154     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
41155
41156   /* Floating-point constants need more complex checks.  */
41157   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
41158     {
41159       /* General regs can load everything.  */
41160       if (reg_class_subset_p (regclass, GENERAL_REGS))
41161         return regclass;
41162
41163       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
41164          zero above.  We only want to wind up preferring 80387 registers if
41165          we plan on doing computation with them.  */
41166       if (TARGET_80387
41167           && standard_80387_constant_p (x) > 0)
41168         {
41169           /* Limit class to non-sse.  */
41170           if (regclass == FLOAT_SSE_REGS)
41171             return FLOAT_REGS;
41172           if (regclass == FP_TOP_SSE_REGS)
41173             return FP_TOP_REG;
41174           if (regclass == FP_SECOND_SSE_REGS)
41175             return FP_SECOND_REG;
41176           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
41177             return regclass;
41178         }
41179
41180       return NO_REGS;
41181     }
41182
41183   /* Generally when we see PLUS here, it's the function invariant
41184      (plus soft-fp const_int).  Which can only be computed into general
41185      regs.  */
41186   if (GET_CODE (x) == PLUS)
41187     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
41188
41189   /* QImode constants are easy to load, but non-constant QImode data
41190      must go into Q_REGS.  */
41191   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
41192     {
41193       if (reg_class_subset_p (regclass, Q_REGS))
41194         return regclass;
41195       if (reg_class_subset_p (Q_REGS, regclass))
41196         return Q_REGS;
41197       return NO_REGS;
41198     }
41199
41200   return regclass;
41201 }
41202
41203 /* Discourage putting floating-point values in SSE registers unless
41204    SSE math is being used, and likewise for the 387 registers.  */
41205 static reg_class_t
41206 ix86_preferred_output_reload_class (rtx x, reg_class_t regclass)
41207 {
41208   machine_mode mode = GET_MODE (x);
41209
41210   /* Restrict the output reload class to the register bank that we are doing
41211      math on.  If we would like not to return a subset of CLASS, reject this
41212      alternative: if reload cannot do this, it will still use its choice.  */
41213   mode = GET_MODE (x);
41214   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
41215     return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS;
41216
41217   if (X87_FLOAT_MODE_P (mode))
41218     {
41219       if (regclass == FP_TOP_SSE_REGS)
41220         return FP_TOP_REG;
41221       else if (regclass == FP_SECOND_SSE_REGS)
41222         return FP_SECOND_REG;
41223       else
41224         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
41225     }
41226
41227   return regclass;
41228 }
41229
41230 static reg_class_t
41231 ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
41232                        machine_mode mode, secondary_reload_info *sri)
41233 {
41234   /* Double-word spills from general registers to non-offsettable memory
41235      references (zero-extended addresses) require special handling.  */
41236   if (TARGET_64BIT
41237       && MEM_P (x)
41238       && GET_MODE_SIZE (mode) > UNITS_PER_WORD
41239       && INTEGER_CLASS_P (rclass)
41240       && !offsettable_memref_p (x))
41241     {
41242       sri->icode = (in_p
41243                     ? CODE_FOR_reload_noff_load
41244                     : CODE_FOR_reload_noff_store);
41245       /* Add the cost of moving address to a temporary.  */
41246       sri->extra_cost = 1;
41247
41248       return NO_REGS;
41249     }
41250
41251   /* QImode spills from non-QI registers require
41252      intermediate register on 32bit targets.  */
41253   if (mode == QImode
41254       && (MAYBE_MASK_CLASS_P (rclass)
41255           || (!TARGET_64BIT && !in_p
41256               && INTEGER_CLASS_P (rclass)
41257               && MAYBE_NON_Q_CLASS_P (rclass))))
41258     {
41259       int regno;
41260
41261       if (REG_P (x))
41262         regno = REGNO (x);
41263       else
41264         regno = -1;
41265
41266       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
41267         regno = true_regnum (x);
41268
41269       /* Return Q_REGS if the operand is in memory.  */
41270       if (regno == -1)
41271         return Q_REGS;
41272     }
41273
41274   /* This condition handles corner case where an expression involving
41275      pointers gets vectorized.  We're trying to use the address of a
41276      stack slot as a vector initializer.
41277
41278      (set (reg:V2DI 74 [ vect_cst_.2 ])
41279           (vec_duplicate:V2DI (reg/f:DI 20 frame)))
41280
41281      Eventually frame gets turned into sp+offset like this:
41282
41283      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41284           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
41285                                        (const_int 392 [0x188]))))
41286
41287      That later gets turned into:
41288
41289      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41290           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
41291             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))))
41292
41293      We'll have the following reload recorded:
41294
41295      Reload 0: reload_in (DI) =
41296            (plus:DI (reg/f:DI 7 sp)
41297             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))
41298      reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41299      SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine
41300      reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188]))
41301      reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41302      reload_reg_rtx: (reg:V2DI 22 xmm1)
41303
41304      Which isn't going to work since SSE instructions can't handle scalar
41305      additions.  Returning GENERAL_REGS forces the addition into integer
41306      register and reload can handle subsequent reloads without problems.  */
41307
41308   if (in_p && GET_CODE (x) == PLUS
41309       && SSE_CLASS_P (rclass)
41310       && SCALAR_INT_MODE_P (mode))
41311     return GENERAL_REGS;
41312
41313   return NO_REGS;
41314 }
41315
41316 /* Implement TARGET_CLASS_LIKELY_SPILLED_P.  */
41317
41318 static bool
41319 ix86_class_likely_spilled_p (reg_class_t rclass)
41320 {
41321   switch (rclass)
41322     {
41323       case AREG:
41324       case DREG:
41325       case CREG:
41326       case BREG:
41327       case AD_REGS:
41328       case SIREG:
41329       case DIREG:
41330       case SSE_FIRST_REG:
41331       case FP_TOP_REG:
41332       case FP_SECOND_REG:
41333       case BND_REGS:
41334         return true;
41335
41336       default:
41337         break;
41338     }
41339
41340   return false;
41341 }
41342
41343 /* If we are copying between general and FP registers, we need a memory
41344    location. The same is true for SSE and MMX registers.
41345
41346    To optimize register_move_cost performance, allow inline variant.
41347
41348    The macro can't work reliably when one of the CLASSES is class containing
41349    registers from multiple units (SSE, MMX, integer).  We avoid this by never
41350    combining those units in single alternative in the machine description.
41351    Ensure that this constraint holds to avoid unexpected surprises.
41352
41353    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
41354    enforce these sanity checks.  */
41355
41356 static inline bool
41357 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
41358                                 machine_mode mode, int strict)
41359 {
41360   if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
41361     return false;
41362   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
41363       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
41364       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
41365       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
41366       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
41367       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
41368     {
41369       gcc_assert (!strict || lra_in_progress);
41370       return true;
41371     }
41372
41373   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
41374     return true;
41375
41376   /* Between mask and general, we have moves no larger than word size.  */
41377   if ((MAYBE_MASK_CLASS_P (class1) != MAYBE_MASK_CLASS_P (class2))
41378       && (GET_MODE_SIZE (mode) > UNITS_PER_WORD))
41379   return true;
41380
41381   /* ??? This is a lie.  We do have moves between mmx/general, and for
41382      mmx/sse2.  But by saying we need secondary memory we discourage the
41383      register allocator from using the mmx registers unless needed.  */
41384   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
41385     return true;
41386
41387   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
41388     {
41389       /* SSE1 doesn't have any direct moves from other classes.  */
41390       if (!TARGET_SSE2)
41391         return true;
41392
41393       /* If the target says that inter-unit moves are more expensive
41394          than moving through memory, then don't generate them.  */
41395       if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC)
41396           || (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC))
41397         return true;
41398
41399       /* Between SSE and general, we have moves no larger than word size.  */
41400       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
41401         return true;
41402     }
41403
41404   return false;
41405 }
41406
41407 bool
41408 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
41409                               machine_mode mode, int strict)
41410 {
41411   return inline_secondary_memory_needed (class1, class2, mode, strict);
41412 }
41413
41414 /* Implement the TARGET_CLASS_MAX_NREGS hook.
41415
41416    On the 80386, this is the size of MODE in words,
41417    except in the FP regs, where a single reg is always enough.  */
41418
41419 static unsigned char
41420 ix86_class_max_nregs (reg_class_t rclass, machine_mode mode)
41421 {
41422   if (MAYBE_INTEGER_CLASS_P (rclass))
41423     {
41424       if (mode == XFmode)
41425         return (TARGET_64BIT ? 2 : 3);
41426       else if (mode == XCmode)
41427         return (TARGET_64BIT ? 4 : 6);
41428       else
41429         return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
41430     }
41431   else
41432     {
41433       if (COMPLEX_MODE_P (mode))
41434         return 2;
41435       else
41436         return 1;
41437     }
41438 }
41439
41440 /* Return true if the registers in CLASS cannot represent the change from
41441    modes FROM to TO.  */
41442
41443 bool
41444 ix86_cannot_change_mode_class (machine_mode from, machine_mode to,
41445                                enum reg_class regclass)
41446 {
41447   if (from == to)
41448     return false;
41449
41450   /* x87 registers can't do subreg at all, as all values are reformatted
41451      to extended precision.  */
41452   if (MAYBE_FLOAT_CLASS_P (regclass))
41453     return true;
41454
41455   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
41456     {
41457       /* Vector registers do not support QI or HImode loads.  If we don't
41458          disallow a change to these modes, reload will assume it's ok to
41459          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
41460          the vec_dupv4hi pattern.  */
41461       if (GET_MODE_SIZE (from) < 4)
41462         return true;
41463     }
41464
41465   return false;
41466 }
41467
41468 /* Return the cost of moving data of mode M between a
41469    register and memory.  A value of 2 is the default; this cost is
41470    relative to those in `REGISTER_MOVE_COST'.
41471
41472    This function is used extensively by register_move_cost that is used to
41473    build tables at startup.  Make it inline in this case.
41474    When IN is 2, return maximum of in and out move cost.
41475
41476    If moving between registers and memory is more expensive than
41477    between two registers, you should define this macro to express the
41478    relative cost.
41479
41480    Model also increased moving costs of QImode registers in non
41481    Q_REGS classes.
41482  */
41483 static inline int
41484 inline_memory_move_cost (machine_mode mode, enum reg_class regclass,
41485                          int in)
41486 {
41487   int cost;
41488   if (FLOAT_CLASS_P (regclass))
41489     {
41490       int index;
41491       switch (mode)
41492         {
41493           case SFmode:
41494             index = 0;
41495             break;
41496           case DFmode:
41497             index = 1;
41498             break;
41499           case XFmode:
41500             index = 2;
41501             break;
41502           default:
41503             return 100;
41504         }
41505       if (in == 2)
41506         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
41507       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
41508     }
41509   if (SSE_CLASS_P (regclass))
41510     {
41511       int index;
41512       switch (GET_MODE_SIZE (mode))
41513         {
41514           case 4:
41515             index = 0;
41516             break;
41517           case 8:
41518             index = 1;
41519             break;
41520           case 16:
41521             index = 2;
41522             break;
41523           default:
41524             return 100;
41525         }
41526       if (in == 2)
41527         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
41528       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
41529     }
41530   if (MMX_CLASS_P (regclass))
41531     {
41532       int index;
41533       switch (GET_MODE_SIZE (mode))
41534         {
41535           case 4:
41536             index = 0;
41537             break;
41538           case 8:
41539             index = 1;
41540             break;
41541           default:
41542             return 100;
41543         }
41544       if (in)
41545         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
41546       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
41547     }
41548   switch (GET_MODE_SIZE (mode))
41549     {
41550       case 1:
41551         if (Q_CLASS_P (regclass) || TARGET_64BIT)
41552           {
41553             if (!in)
41554               return ix86_cost->int_store[0];
41555             if (TARGET_PARTIAL_REG_DEPENDENCY
41556                 && optimize_function_for_speed_p (cfun))
41557               cost = ix86_cost->movzbl_load;
41558             else
41559               cost = ix86_cost->int_load[0];
41560             if (in == 2)
41561               return MAX (cost, ix86_cost->int_store[0]);
41562             return cost;
41563           }
41564         else
41565           {
41566            if (in == 2)
41567              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
41568            if (in)
41569              return ix86_cost->movzbl_load;
41570            else
41571              return ix86_cost->int_store[0] + 4;
41572           }
41573         break;
41574       case 2:
41575         if (in == 2)
41576           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
41577         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
41578       default:
41579         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
41580         if (mode == TFmode)
41581           mode = XFmode;
41582         if (in == 2)
41583           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
41584         else if (in)
41585           cost = ix86_cost->int_load[2];
41586         else
41587           cost = ix86_cost->int_store[2];
41588         return (cost * (((int) GET_MODE_SIZE (mode)
41589                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
41590     }
41591 }
41592
41593 static int
41594 ix86_memory_move_cost (machine_mode mode, reg_class_t regclass,
41595                        bool in)
41596 {
41597   return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0);
41598 }
41599
41600
41601 /* Return the cost of moving data from a register in class CLASS1 to
41602    one in class CLASS2.
41603
41604    It is not required that the cost always equal 2 when FROM is the same as TO;
41605    on some machines it is expensive to move between registers if they are not
41606    general registers.  */
41607
41608 static int
41609 ix86_register_move_cost (machine_mode mode, reg_class_t class1_i,
41610                          reg_class_t class2_i)
41611 {
41612   enum reg_class class1 = (enum reg_class) class1_i;
41613   enum reg_class class2 = (enum reg_class) class2_i;
41614
41615   /* In case we require secondary memory, compute cost of the store followed
41616      by load.  In order to avoid bad register allocation choices, we need
41617      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
41618
41619   if (inline_secondary_memory_needed (class1, class2, mode, 0))
41620     {
41621       int cost = 1;
41622
41623       cost += inline_memory_move_cost (mode, class1, 2);
41624       cost += inline_memory_move_cost (mode, class2, 2);
41625
41626       /* In case of copying from general_purpose_register we may emit multiple
41627          stores followed by single load causing memory size mismatch stall.
41628          Count this as arbitrarily high cost of 20.  */
41629       if (targetm.class_max_nregs (class1, mode)
41630           > targetm.class_max_nregs (class2, mode))
41631         cost += 20;
41632
41633       /* In the case of FP/MMX moves, the registers actually overlap, and we
41634          have to switch modes in order to treat them differently.  */
41635       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
41636           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
41637         cost += 20;
41638
41639       return cost;
41640     }
41641
41642   /* Moves between SSE/MMX and integer unit are expensive.  */
41643   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
41644       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
41645
41646     /* ??? By keeping returned value relatively high, we limit the number
41647        of moves between integer and MMX/SSE registers for all targets.
41648        Additionally, high value prevents problem with x86_modes_tieable_p(),
41649        where integer modes in MMX/SSE registers are not tieable
41650        because of missing QImode and HImode moves to, from or between
41651        MMX/SSE registers.  */
41652     return MAX (8, ix86_cost->mmxsse_to_integer);
41653
41654   if (MAYBE_FLOAT_CLASS_P (class1))
41655     return ix86_cost->fp_move;
41656   if (MAYBE_SSE_CLASS_P (class1))
41657     return ix86_cost->sse_move;
41658   if (MAYBE_MMX_CLASS_P (class1))
41659     return ix86_cost->mmx_move;
41660   return 2;
41661 }
41662
41663 /* Return TRUE if hard register REGNO can hold a value of machine-mode
41664    MODE.  */
41665
41666 bool
41667 ix86_hard_regno_mode_ok (int regno, machine_mode mode)
41668 {
41669   /* Flags and only flags can only hold CCmode values.  */
41670   if (CC_REGNO_P (regno))
41671     return GET_MODE_CLASS (mode) == MODE_CC;
41672   if (GET_MODE_CLASS (mode) == MODE_CC
41673       || GET_MODE_CLASS (mode) == MODE_RANDOM
41674       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
41675     return false;
41676   if (STACK_REGNO_P (regno))
41677     return VALID_FP_MODE_P (mode);
41678   if (MASK_REGNO_P (regno))
41679     return (VALID_MASK_REG_MODE (mode)
41680             || (TARGET_AVX512BW
41681                 && VALID_MASK_AVX512BW_MODE (mode)));
41682   if (BND_REGNO_P (regno))
41683     return VALID_BND_REG_MODE (mode);
41684   if (SSE_REGNO_P (regno))
41685     {
41686       /* We implement the move patterns for all vector modes into and
41687          out of SSE registers, even when no operation instructions
41688          are available.  */
41689
41690       /* For AVX-512 we allow, regardless of regno:
41691           - XI mode
41692           - any of 512-bit wide vector mode
41693           - any scalar mode.  */
41694       if (TARGET_AVX512F
41695           && (mode == XImode
41696               || VALID_AVX512F_REG_MODE (mode)
41697               || VALID_AVX512F_SCALAR_MODE (mode)))
41698         return true;
41699
41700       /* TODO check for QI/HI scalars.  */
41701       /* AVX512VL allows sse regs16+ for 128/256 bit modes.  */
41702       if (TARGET_AVX512VL
41703           && (mode == OImode
41704               || mode == TImode
41705               || VALID_AVX256_REG_MODE (mode)
41706               || VALID_AVX512VL_128_REG_MODE (mode)))
41707         return true;
41708
41709       /* xmm16-xmm31 are only available for AVX-512.  */
41710       if (EXT_REX_SSE_REGNO_P (regno))
41711         return false;
41712
41713       /* OImode and AVX modes are available only when AVX is enabled.  */
41714       return ((TARGET_AVX
41715                && VALID_AVX256_REG_OR_OI_MODE (mode))
41716               || VALID_SSE_REG_MODE (mode)
41717               || VALID_SSE2_REG_MODE (mode)
41718               || VALID_MMX_REG_MODE (mode)
41719               || VALID_MMX_REG_MODE_3DNOW (mode));
41720     }
41721   if (MMX_REGNO_P (regno))
41722     {
41723       /* We implement the move patterns for 3DNOW modes even in MMX mode,
41724          so if the register is available at all, then we can move data of
41725          the given mode into or out of it.  */
41726       return (VALID_MMX_REG_MODE (mode)
41727               || VALID_MMX_REG_MODE_3DNOW (mode));
41728     }
41729
41730   if (mode == QImode)
41731     {
41732       /* Take care for QImode values - they can be in non-QI regs,
41733          but then they do cause partial register stalls.  */
41734       if (ANY_QI_REGNO_P (regno))
41735         return true;
41736       if (!TARGET_PARTIAL_REG_STALL)
41737         return true;
41738       /* LRA checks if the hard register is OK for the given mode.
41739          QImode values can live in non-QI regs, so we allow all
41740          registers here.  */
41741       if (lra_in_progress)
41742        return true;
41743       return !can_create_pseudo_p ();
41744     }
41745   /* We handle both integer and floats in the general purpose registers.  */
41746   else if (VALID_INT_MODE_P (mode))
41747     return true;
41748   else if (VALID_FP_MODE_P (mode))
41749     return true;
41750   else if (VALID_DFP_MODE_P (mode))
41751     return true;
41752   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
41753      on to use that value in smaller contexts, this can easily force a
41754      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
41755      supporting DImode, allow it.  */
41756   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
41757     return true;
41758
41759   return false;
41760 }
41761
41762 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
41763    tieable integer mode.  */
41764
41765 static bool
41766 ix86_tieable_integer_mode_p (machine_mode mode)
41767 {
41768   switch (mode)
41769     {
41770     case HImode:
41771     case SImode:
41772       return true;
41773
41774     case QImode:
41775       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
41776
41777     case DImode:
41778       return TARGET_64BIT;
41779
41780     default:
41781       return false;
41782     }
41783 }
41784
41785 /* Return true if MODE1 is accessible in a register that can hold MODE2
41786    without copying.  That is, all register classes that can hold MODE2
41787    can also hold MODE1.  */
41788
41789 bool
41790 ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2)
41791 {
41792   if (mode1 == mode2)
41793     return true;
41794
41795   if (ix86_tieable_integer_mode_p (mode1)
41796       && ix86_tieable_integer_mode_p (mode2))
41797     return true;
41798
41799   /* MODE2 being XFmode implies fp stack or general regs, which means we
41800      can tie any smaller floating point modes to it.  Note that we do not
41801      tie this with TFmode.  */
41802   if (mode2 == XFmode)
41803     return mode1 == SFmode || mode1 == DFmode;
41804
41805   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
41806      that we can tie it with SFmode.  */
41807   if (mode2 == DFmode)
41808     return mode1 == SFmode;
41809
41810   /* If MODE2 is only appropriate for an SSE register, then tie with
41811      any other mode acceptable to SSE registers.  */
41812   if (GET_MODE_SIZE (mode2) == 32
41813       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
41814     return (GET_MODE_SIZE (mode1) == 32
41815             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
41816   if (GET_MODE_SIZE (mode2) == 16
41817       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
41818     return (GET_MODE_SIZE (mode1) == 16
41819             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
41820
41821   /* If MODE2 is appropriate for an MMX register, then tie
41822      with any other mode acceptable to MMX registers.  */
41823   if (GET_MODE_SIZE (mode2) == 8
41824       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
41825     return (GET_MODE_SIZE (mode1) == 8
41826             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
41827
41828   return false;
41829 }
41830
41831 /* Return the cost of moving between two registers of mode MODE.  */
41832
41833 static int
41834 ix86_set_reg_reg_cost (machine_mode mode)
41835 {
41836   unsigned int units = UNITS_PER_WORD;
41837
41838   switch (GET_MODE_CLASS (mode))
41839     {
41840     default:
41841       break;
41842
41843     case MODE_CC:
41844       units = GET_MODE_SIZE (CCmode);
41845       break;
41846
41847     case MODE_FLOAT:
41848       if ((TARGET_SSE && mode == TFmode)
41849           || (TARGET_80387 && mode == XFmode)
41850           || ((TARGET_80387 || TARGET_SSE2) && mode == DFmode)
41851           || ((TARGET_80387 || TARGET_SSE) && mode == SFmode))
41852         units = GET_MODE_SIZE (mode);
41853       break;
41854
41855     case MODE_COMPLEX_FLOAT:
41856       if ((TARGET_SSE && mode == TCmode)
41857           || (TARGET_80387 && mode == XCmode)
41858           || ((TARGET_80387 || TARGET_SSE2) && mode == DCmode)
41859           || ((TARGET_80387 || TARGET_SSE) && mode == SCmode))
41860         units = GET_MODE_SIZE (mode);
41861       break;
41862
41863     case MODE_VECTOR_INT:
41864     case MODE_VECTOR_FLOAT:
41865       if ((TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
41866           || (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
41867           || (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
41868           || (TARGET_SSE && VALID_SSE_REG_MODE (mode))
41869           || (TARGET_MMX && VALID_MMX_REG_MODE (mode)))
41870         units = GET_MODE_SIZE (mode);
41871     }
41872
41873   /* Return the cost of moving between two registers of mode MODE,
41874      assuming that the move will be in pieces of at most UNITS bytes.  */
41875   return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
41876 }
41877
41878 /* Compute a (partial) cost for rtx X.  Return true if the complete
41879    cost has been computed, and false if subexpressions should be
41880    scanned.  In either case, *TOTAL contains the cost result.  */
41881
41882 static bool
41883 ix86_rtx_costs (rtx x, int code_i, int outer_code_i, int opno, int *total,
41884                 bool speed)
41885 {
41886   rtx mask;
41887   enum rtx_code code = (enum rtx_code) code_i;
41888   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
41889   machine_mode mode = GET_MODE (x);
41890   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
41891
41892   switch (code)
41893     {
41894     case SET:
41895       if (register_operand (SET_DEST (x), VOIDmode)
41896           && reg_or_0_operand (SET_SRC (x), VOIDmode))
41897         {
41898           *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
41899           return true;
41900         }
41901       return false;
41902
41903     case CONST_INT:
41904     case CONST:
41905     case LABEL_REF:
41906     case SYMBOL_REF:
41907       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
41908         *total = 3;
41909       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
41910         *total = 2;
41911       else if (flag_pic && SYMBOLIC_CONST (x)
41912                && !(TARGET_64BIT
41913                     && (GET_CODE (x) == LABEL_REF
41914                         || (GET_CODE (x) == SYMBOL_REF
41915                             && SYMBOL_REF_LOCAL_P (x)))))
41916         *total = 1;
41917       else
41918         *total = 0;
41919       return true;
41920
41921     case CONST_DOUBLE:
41922       if (mode == VOIDmode)
41923         {
41924           *total = 0;
41925           return true;
41926         }
41927       switch (standard_80387_constant_p (x))
41928         {
41929         case 1: /* 0.0 */
41930           *total = 1;
41931           return true;
41932         default: /* Other constants */
41933           *total = 2;
41934           return true;
41935         case 0:
41936         case -1:
41937           break;
41938         }
41939       if (SSE_FLOAT_MODE_P (mode))
41940         {
41941     case CONST_VECTOR:
41942           switch (standard_sse_constant_p (x))
41943             {
41944             case 0:
41945               break;
41946             case 1:  /* 0: xor eliminates false dependency */
41947               *total = 0;
41948               return true;
41949             default: /* -1: cmp contains false dependency */
41950               *total = 1;
41951               return true;
41952             }
41953         }
41954       /* Fall back to (MEM (SYMBOL_REF)), since that's where
41955          it'll probably end up.  Add a penalty for size.  */
41956       *total = (COSTS_N_INSNS (1)
41957                 + (flag_pic != 0 && !TARGET_64BIT)
41958                 + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
41959       return true;
41960
41961     case ZERO_EXTEND:
41962       /* The zero extensions is often completely free on x86_64, so make
41963          it as cheap as possible.  */
41964       if (TARGET_64BIT && mode == DImode
41965           && GET_MODE (XEXP (x, 0)) == SImode)
41966         *total = 1;
41967       else if (TARGET_ZERO_EXTEND_WITH_AND)
41968         *total = cost->add;
41969       else
41970         *total = cost->movzx;
41971       return false;
41972
41973     case SIGN_EXTEND:
41974       *total = cost->movsx;
41975       return false;
41976
41977     case ASHIFT:
41978       if (SCALAR_INT_MODE_P (mode)
41979           && GET_MODE_SIZE (mode) < UNITS_PER_WORD
41980           && CONST_INT_P (XEXP (x, 1)))
41981         {
41982           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
41983           if (value == 1)
41984             {
41985               *total = cost->add;
41986               return false;
41987             }
41988           if ((value == 2 || value == 3)
41989               && cost->lea <= cost->shift_const)
41990             {
41991               *total = cost->lea;
41992               return false;
41993             }
41994         }
41995       /* FALLTHRU */
41996
41997     case ROTATE:
41998     case ASHIFTRT:
41999     case LSHIFTRT:
42000     case ROTATERT:
42001       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42002         {
42003           /* ??? Should be SSE vector operation cost.  */
42004           /* At least for published AMD latencies, this really is the same
42005              as the latency for a simple fpu operation like fabs.  */
42006           /* V*QImode is emulated with 1-11 insns.  */
42007           if (mode == V16QImode || mode == V32QImode)
42008             {
42009               int count = 11;
42010               if (TARGET_XOP && mode == V16QImode)
42011                 {
42012                   /* For XOP we use vpshab, which requires a broadcast of the
42013                      value to the variable shift insn.  For constants this
42014                      means a V16Q const in mem; even when we can perform the
42015                      shift with one insn set the cost to prefer paddb.  */
42016                   if (CONSTANT_P (XEXP (x, 1)))
42017                     {
42018                       *total = (cost->fabs
42019                                 + rtx_cost (XEXP (x, 0), code, 0, speed)
42020                                 + (speed ? 2 : COSTS_N_BYTES (16)));
42021                       return true;
42022                     }
42023                   count = 3;
42024                 }
42025               else if (TARGET_SSSE3)
42026                 count = 7;
42027               *total = cost->fabs * count;
42028             }
42029           else
42030             *total = cost->fabs;
42031         }
42032       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42033         {
42034           if (CONST_INT_P (XEXP (x, 1)))
42035             {
42036               if (INTVAL (XEXP (x, 1)) > 32)
42037                 *total = cost->shift_const + COSTS_N_INSNS (2);
42038               else
42039                 *total = cost->shift_const * 2;
42040             }
42041           else
42042             {
42043               if (GET_CODE (XEXP (x, 1)) == AND)
42044                 *total = cost->shift_var * 2;
42045               else
42046                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
42047             }
42048         }
42049       else
42050         {
42051           if (CONST_INT_P (XEXP (x, 1)))
42052             *total = cost->shift_const;
42053           else if (GET_CODE (XEXP (x, 1)) == SUBREG
42054                    && GET_CODE (XEXP (XEXP (x, 1), 0)) == AND)
42055             {
42056               /* Return the cost after shift-and truncation.  */
42057               *total = cost->shift_var;
42058               return true;
42059             }
42060           else
42061             *total = cost->shift_var;
42062         }
42063       return false;
42064
42065     case FMA:
42066       {
42067         rtx sub;
42068
42069         gcc_assert (FLOAT_MODE_P (mode));
42070         gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F);
42071
42072         /* ??? SSE scalar/vector cost should be used here.  */
42073         /* ??? Bald assumption that fma has the same cost as fmul.  */
42074         *total = cost->fmul;
42075         *total += rtx_cost (XEXP (x, 1), FMA, 1, speed);
42076
42077         /* Negate in op0 or op2 is free: FMS, FNMA, FNMS.  */
42078         sub = XEXP (x, 0);
42079         if (GET_CODE (sub) == NEG)
42080           sub = XEXP (sub, 0);
42081         *total += rtx_cost (sub, FMA, 0, speed);
42082
42083         sub = XEXP (x, 2);
42084         if (GET_CODE (sub) == NEG)
42085           sub = XEXP (sub, 0);
42086         *total += rtx_cost (sub, FMA, 2, speed);
42087         return true;
42088       }
42089
42090     case MULT:
42091       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42092         {
42093           /* ??? SSE scalar cost should be used here.  */
42094           *total = cost->fmul;
42095           return false;
42096         }
42097       else if (X87_FLOAT_MODE_P (mode))
42098         {
42099           *total = cost->fmul;
42100           return false;
42101         }
42102       else if (FLOAT_MODE_P (mode))
42103         {
42104           /* ??? SSE vector cost should be used here.  */
42105           *total = cost->fmul;
42106           return false;
42107         }
42108       else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42109         {
42110           /* V*QImode is emulated with 7-13 insns.  */
42111           if (mode == V16QImode || mode == V32QImode)
42112             {
42113               int extra = 11;
42114               if (TARGET_XOP && mode == V16QImode)
42115                 extra = 5;
42116               else if (TARGET_SSSE3)
42117                 extra = 6;
42118               *total = cost->fmul * 2 + cost->fabs * extra;
42119             }
42120           /* V*DImode is emulated with 5-8 insns.  */
42121           else if (mode == V2DImode || mode == V4DImode)
42122             {
42123               if (TARGET_XOP && mode == V2DImode)
42124                 *total = cost->fmul * 2 + cost->fabs * 3;
42125               else
42126                 *total = cost->fmul * 3 + cost->fabs * 5;
42127             }
42128           /* Without sse4.1, we don't have PMULLD; it's emulated with 7
42129              insns, including two PMULUDQ.  */
42130           else if (mode == V4SImode && !(TARGET_SSE4_1 || TARGET_AVX))
42131             *total = cost->fmul * 2 + cost->fabs * 5;
42132           else
42133             *total = cost->fmul;
42134           return false;
42135         }
42136       else
42137         {
42138           rtx op0 = XEXP (x, 0);
42139           rtx op1 = XEXP (x, 1);
42140           int nbits;
42141           if (CONST_INT_P (XEXP (x, 1)))
42142             {
42143               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
42144               for (nbits = 0; value != 0; value &= value - 1)
42145                 nbits++;
42146             }
42147           else
42148             /* This is arbitrary.  */
42149             nbits = 7;
42150
42151           /* Compute costs correctly for widening multiplication.  */
42152           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
42153               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
42154                  == GET_MODE_SIZE (mode))
42155             {
42156               int is_mulwiden = 0;
42157               machine_mode inner_mode = GET_MODE (op0);
42158
42159               if (GET_CODE (op0) == GET_CODE (op1))
42160                 is_mulwiden = 1, op1 = XEXP (op1, 0);
42161               else if (CONST_INT_P (op1))
42162                 {
42163                   if (GET_CODE (op0) == SIGN_EXTEND)
42164                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
42165                                   == INTVAL (op1);
42166                   else
42167                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
42168                 }
42169
42170               if (is_mulwiden)
42171                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
42172             }
42173
42174           *total = (cost->mult_init[MODE_INDEX (mode)]
42175                     + nbits * cost->mult_bit
42176                     + rtx_cost (op0, outer_code, opno, speed)
42177                     + rtx_cost (op1, outer_code, opno, speed));
42178
42179           return true;
42180         }
42181
42182     case DIV:
42183     case UDIV:
42184     case MOD:
42185     case UMOD:
42186       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42187         /* ??? SSE cost should be used here.  */
42188         *total = cost->fdiv;
42189       else if (X87_FLOAT_MODE_P (mode))
42190         *total = cost->fdiv;
42191       else if (FLOAT_MODE_P (mode))
42192         /* ??? SSE vector cost should be used here.  */
42193         *total = cost->fdiv;
42194       else
42195         *total = cost->divide[MODE_INDEX (mode)];
42196       return false;
42197
42198     case PLUS:
42199       if (GET_MODE_CLASS (mode) == MODE_INT
42200           && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
42201         {
42202           if (GET_CODE (XEXP (x, 0)) == PLUS
42203               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
42204               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
42205               && CONSTANT_P (XEXP (x, 1)))
42206             {
42207               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
42208               if (val == 2 || val == 4 || val == 8)
42209                 {
42210                   *total = cost->lea;
42211                   *total += rtx_cost (XEXP (XEXP (x, 0), 1),
42212                                       outer_code, opno, speed);
42213                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
42214                                       outer_code, opno, speed);
42215                   *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42216                   return true;
42217                 }
42218             }
42219           else if (GET_CODE (XEXP (x, 0)) == MULT
42220                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
42221             {
42222               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
42223               if (val == 2 || val == 4 || val == 8)
42224                 {
42225                   *total = cost->lea;
42226                   *total += rtx_cost (XEXP (XEXP (x, 0), 0),
42227                                       outer_code, opno, speed);
42228                   *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42229                   return true;
42230                 }
42231             }
42232           else if (GET_CODE (XEXP (x, 0)) == PLUS)
42233             {
42234               *total = cost->lea;
42235               *total += rtx_cost (XEXP (XEXP (x, 0), 0),
42236                                   outer_code, opno, speed);
42237               *total += rtx_cost (XEXP (XEXP (x, 0), 1),
42238                                   outer_code, opno, speed);
42239               *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42240               return true;
42241             }
42242         }
42243       /* FALLTHRU */
42244
42245     case MINUS:
42246       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42247         {
42248           /* ??? SSE cost should be used here.  */
42249           *total = cost->fadd;
42250           return false;
42251         }
42252       else if (X87_FLOAT_MODE_P (mode))
42253         {
42254           *total = cost->fadd;
42255           return false;
42256         }
42257       else if (FLOAT_MODE_P (mode))
42258         {
42259           /* ??? SSE vector cost should be used here.  */
42260           *total = cost->fadd;
42261           return false;
42262         }
42263       /* FALLTHRU */
42264
42265     case AND:
42266     case IOR:
42267     case XOR:
42268       if (GET_MODE_CLASS (mode) == MODE_INT
42269           && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42270         {
42271           *total = (cost->add * 2
42272                     + (rtx_cost (XEXP (x, 0), outer_code, opno, speed)
42273                        << (GET_MODE (XEXP (x, 0)) != DImode))
42274                     + (rtx_cost (XEXP (x, 1), outer_code, opno, speed)
42275                        << (GET_MODE (XEXP (x, 1)) != DImode)));
42276           return true;
42277         }
42278       /* FALLTHRU */
42279
42280     case NEG:
42281       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42282         {
42283           /* ??? SSE cost should be used here.  */
42284           *total = cost->fchs;
42285           return false;
42286         }
42287       else if (X87_FLOAT_MODE_P (mode))
42288         {
42289           *total = cost->fchs;
42290           return false;
42291         }
42292       else if (FLOAT_MODE_P (mode))
42293         {
42294           /* ??? SSE vector cost should be used here.  */
42295           *total = cost->fchs;
42296           return false;
42297         }
42298       /* FALLTHRU */
42299
42300     case NOT:
42301       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42302         {
42303           /* ??? Should be SSE vector operation cost.  */
42304           /* At least for published AMD latencies, this really is the same
42305              as the latency for a simple fpu operation like fabs.  */
42306           *total = cost->fabs;
42307         }
42308       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42309         *total = cost->add * 2;
42310       else
42311         *total = cost->add;
42312       return false;
42313
42314     case COMPARE:
42315       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
42316           && XEXP (XEXP (x, 0), 1) == const1_rtx
42317           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
42318           && XEXP (x, 1) == const0_rtx)
42319         {
42320           /* This kind of construct is implemented using test[bwl].
42321              Treat it as if we had an AND.  */
42322           *total = (cost->add
42323                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, opno, speed)
42324                     + rtx_cost (const1_rtx, outer_code, opno, speed));
42325           return true;
42326         }
42327       return false;
42328
42329     case FLOAT_EXTEND:
42330       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
42331         *total = 0;
42332       return false;
42333
42334     case ABS:
42335       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42336         /* ??? SSE cost should be used here.  */
42337         *total = cost->fabs;
42338       else if (X87_FLOAT_MODE_P (mode))
42339         *total = cost->fabs;
42340       else if (FLOAT_MODE_P (mode))
42341         /* ??? SSE vector cost should be used here.  */
42342         *total = cost->fabs;
42343       return false;
42344
42345     case SQRT:
42346       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42347         /* ??? SSE cost should be used here.  */
42348         *total = cost->fsqrt;
42349       else if (X87_FLOAT_MODE_P (mode))
42350         *total = cost->fsqrt;
42351       else if (FLOAT_MODE_P (mode))
42352         /* ??? SSE vector cost should be used here.  */
42353         *total = cost->fsqrt;
42354       return false;
42355
42356     case UNSPEC:
42357       if (XINT (x, 1) == UNSPEC_TP)
42358         *total = 0;
42359       return false;
42360
42361     case VEC_SELECT:
42362     case VEC_CONCAT:
42363     case VEC_DUPLICATE:
42364       /* ??? Assume all of these vector manipulation patterns are
42365          recognizable.  In which case they all pretty much have the
42366          same cost.  */
42367      *total = cost->fabs;
42368      return true;
42369     case VEC_MERGE:
42370       mask = XEXP (x, 2);
42371       /* This is masked instruction, assume the same cost,
42372          as nonmasked variant.  */
42373       if (TARGET_AVX512F && register_operand (mask, GET_MODE (mask)))
42374         *total = rtx_cost (XEXP (x, 0), outer_code, opno, speed);
42375       else
42376         *total = cost->fabs;
42377       return true;
42378
42379     default:
42380       return false;
42381     }
42382 }
42383
42384 #if TARGET_MACHO
42385
42386 static int current_machopic_label_num;
42387
42388 /* Given a symbol name and its associated stub, write out the
42389    definition of the stub.  */
42390
42391 void
42392 machopic_output_stub (FILE *file, const char *symb, const char *stub)
42393 {
42394   unsigned int length;
42395   char *binder_name, *symbol_name, lazy_ptr_name[32];
42396   int label = ++current_machopic_label_num;
42397
42398   /* For 64-bit we shouldn't get here.  */
42399   gcc_assert (!TARGET_64BIT);
42400
42401   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
42402   symb = targetm.strip_name_encoding (symb);
42403
42404   length = strlen (stub);
42405   binder_name = XALLOCAVEC (char, length + 32);
42406   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
42407
42408   length = strlen (symb);
42409   symbol_name = XALLOCAVEC (char, length + 32);
42410   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
42411
42412   sprintf (lazy_ptr_name, "L%d$lz", label);
42413
42414   if (MACHOPIC_ATT_STUB)
42415     switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]);
42416   else if (MACHOPIC_PURE)
42417     switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]);
42418   else
42419     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
42420
42421   fprintf (file, "%s:\n", stub);
42422   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
42423
42424   if (MACHOPIC_ATT_STUB)
42425     {
42426       fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n");
42427     }
42428   else if (MACHOPIC_PURE)
42429     {
42430       /* PIC stub.  */
42431       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
42432       rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */);
42433       output_set_got (tmp, NULL_RTX);   /* "CALL ___<cpu>.get_pc_thunk.cx".  */
42434       fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n",
42435                label, lazy_ptr_name, label);
42436       fprintf (file, "\tjmp\t*%%ecx\n");
42437     }
42438   else
42439     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
42440
42441   /* The AT&T-style ("self-modifying") stub is not lazily bound, thus
42442      it needs no stub-binding-helper.  */
42443   if (MACHOPIC_ATT_STUB)
42444     return;
42445
42446   fprintf (file, "%s:\n", binder_name);
42447
42448   if (MACHOPIC_PURE)
42449     {
42450       fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name);
42451       fprintf (file, "\tpushl\t%%ecx\n");
42452     }
42453   else
42454     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
42455
42456   fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
42457
42458   /* N.B. Keep the correspondence of these
42459      'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the
42460      old-pic/new-pic/non-pic stubs; altering this will break
42461      compatibility with existing dylibs.  */
42462   if (MACHOPIC_PURE)
42463     {
42464       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
42465       switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]);
42466     }
42467   else
42468     /* 16-byte -mdynamic-no-pic stub.  */
42469     switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]);
42470
42471   fprintf (file, "%s:\n", lazy_ptr_name);
42472   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
42473   fprintf (file, ASM_LONG "%s\n", binder_name);
42474 }
42475 #endif /* TARGET_MACHO */
42476
42477 /* Order the registers for register allocator.  */
42478
42479 void
42480 x86_order_regs_for_local_alloc (void)
42481 {
42482    int pos = 0;
42483    int i;
42484
42485    /* First allocate the local general purpose registers.  */
42486    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
42487      if (GENERAL_REGNO_P (i) && call_used_regs[i])
42488         reg_alloc_order [pos++] = i;
42489
42490    /* Global general purpose registers.  */
42491    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
42492      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
42493         reg_alloc_order [pos++] = i;
42494
42495    /* x87 registers come first in case we are doing FP math
42496       using them.  */
42497    if (!TARGET_SSE_MATH)
42498      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
42499        reg_alloc_order [pos++] = i;
42500
42501    /* SSE registers.  */
42502    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
42503      reg_alloc_order [pos++] = i;
42504    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
42505      reg_alloc_order [pos++] = i;
42506
42507    /* Extended REX SSE registers.  */
42508    for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
42509      reg_alloc_order [pos++] = i;
42510
42511    /* Mask register.  */
42512    for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
42513      reg_alloc_order [pos++] = i;
42514
42515    /* MPX bound registers.  */
42516    for (i = FIRST_BND_REG; i <= LAST_BND_REG; i++)
42517      reg_alloc_order [pos++] = i;
42518
42519    /* x87 registers.  */
42520    if (TARGET_SSE_MATH)
42521      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
42522        reg_alloc_order [pos++] = i;
42523
42524    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
42525      reg_alloc_order [pos++] = i;
42526
42527    /* Initialize the rest of array as we do not allocate some registers
42528       at all.  */
42529    while (pos < FIRST_PSEUDO_REGISTER)
42530      reg_alloc_order [pos++] = 0;
42531 }
42532
42533 /* Handle a "callee_pop_aggregate_return" attribute; arguments as
42534    in struct attribute_spec handler.  */
42535 static tree
42536 ix86_handle_callee_pop_aggregate_return (tree *node, tree name,
42537                                               tree args,
42538                                               int,
42539                                               bool *no_add_attrs)
42540 {
42541   if (TREE_CODE (*node) != FUNCTION_TYPE
42542       && TREE_CODE (*node) != METHOD_TYPE
42543       && TREE_CODE (*node) != FIELD_DECL
42544       && TREE_CODE (*node) != TYPE_DECL)
42545     {
42546       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42547                name);
42548       *no_add_attrs = true;
42549       return NULL_TREE;
42550     }
42551   if (TARGET_64BIT)
42552     {
42553       warning (OPT_Wattributes, "%qE attribute only available for 32-bit",
42554                name);
42555       *no_add_attrs = true;
42556       return NULL_TREE;
42557     }
42558   if (is_attribute_p ("callee_pop_aggregate_return", name))
42559     {
42560       tree cst;
42561
42562       cst = TREE_VALUE (args);
42563       if (TREE_CODE (cst) != INTEGER_CST)
42564         {
42565           warning (OPT_Wattributes,
42566                    "%qE attribute requires an integer constant argument",
42567                    name);
42568           *no_add_attrs = true;
42569         }
42570       else if (compare_tree_int (cst, 0) != 0
42571                && compare_tree_int (cst, 1) != 0)
42572         {
42573           warning (OPT_Wattributes,
42574                    "argument to %qE attribute is neither zero, nor one",
42575                    name);
42576           *no_add_attrs = true;
42577         }
42578
42579       return NULL_TREE;
42580     }
42581
42582   return NULL_TREE;
42583 }
42584
42585 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
42586    struct attribute_spec.handler.  */
42587 static tree
42588 ix86_handle_abi_attribute (tree *node, tree name, tree, int,
42589                            bool *no_add_attrs)
42590 {
42591   if (TREE_CODE (*node) != FUNCTION_TYPE
42592       && TREE_CODE (*node) != METHOD_TYPE
42593       && TREE_CODE (*node) != FIELD_DECL
42594       && TREE_CODE (*node) != TYPE_DECL)
42595     {
42596       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42597                name);
42598       *no_add_attrs = true;
42599       return NULL_TREE;
42600     }
42601
42602   /* Can combine regparm with all attributes but fastcall.  */
42603   if (is_attribute_p ("ms_abi", name))
42604     {
42605       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
42606         {
42607           error ("ms_abi and sysv_abi attributes are not compatible");
42608         }
42609
42610       return NULL_TREE;
42611     }
42612   else if (is_attribute_p ("sysv_abi", name))
42613     {
42614       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
42615         {
42616           error ("ms_abi and sysv_abi attributes are not compatible");
42617         }
42618
42619       return NULL_TREE;
42620     }
42621
42622   return NULL_TREE;
42623 }
42624
42625 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
42626    struct attribute_spec.handler.  */
42627 static tree
42628 ix86_handle_struct_attribute (tree *node, tree name, tree, int,
42629                               bool *no_add_attrs)
42630 {
42631   tree *type = NULL;
42632   if (DECL_P (*node))
42633     {
42634       if (TREE_CODE (*node) == TYPE_DECL)
42635         type = &TREE_TYPE (*node);
42636     }
42637   else
42638     type = node;
42639
42640   if (!(type && RECORD_OR_UNION_TYPE_P (*type)))
42641     {
42642       warning (OPT_Wattributes, "%qE attribute ignored",
42643                name);
42644       *no_add_attrs = true;
42645     }
42646
42647   else if ((is_attribute_p ("ms_struct", name)
42648             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
42649            || ((is_attribute_p ("gcc_struct", name)
42650                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
42651     {
42652       warning (OPT_Wattributes, "%qE incompatible attribute ignored",
42653                name);
42654       *no_add_attrs = true;
42655     }
42656
42657   return NULL_TREE;
42658 }
42659
42660 static tree
42661 ix86_handle_fndecl_attribute (tree *node, tree name, tree, int,
42662                               bool *no_add_attrs)
42663 {
42664   if (TREE_CODE (*node) != FUNCTION_DECL)
42665     {
42666       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42667                name);
42668       *no_add_attrs = true;
42669     }
42670   return NULL_TREE;
42671 }
42672
42673 static bool
42674 ix86_ms_bitfield_layout_p (const_tree record_type)
42675 {
42676   return ((TARGET_MS_BITFIELD_LAYOUT
42677            && !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
42678           || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type)));
42679 }
42680
42681 /* Returns an expression indicating where the this parameter is
42682    located on entry to the FUNCTION.  */
42683
42684 static rtx
42685 x86_this_parameter (tree function)
42686 {
42687   tree type = TREE_TYPE (function);
42688   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
42689   int nregs;
42690
42691   if (TARGET_64BIT)
42692     {
42693       const int *parm_regs;
42694
42695       if (ix86_function_type_abi (type) == MS_ABI)
42696         parm_regs = x86_64_ms_abi_int_parameter_registers;
42697       else
42698         parm_regs = x86_64_int_parameter_registers;
42699       return gen_rtx_REG (Pmode, parm_regs[aggr]);
42700     }
42701
42702   nregs = ix86_function_regparm (type, function);
42703
42704   if (nregs > 0 && !stdarg_p (type))
42705     {
42706       int regno;
42707       unsigned int ccvt = ix86_get_callcvt (type);
42708
42709       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
42710         regno = aggr ? DX_REG : CX_REG;
42711       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
42712         {
42713           regno = CX_REG;
42714           if (aggr)
42715             return gen_rtx_MEM (SImode,
42716                                 plus_constant (Pmode, stack_pointer_rtx, 4));
42717         }
42718       else
42719         {
42720           regno = AX_REG;
42721           if (aggr)
42722             {
42723               regno = DX_REG;
42724               if (nregs == 1)
42725                 return gen_rtx_MEM (SImode,
42726                                     plus_constant (Pmode,
42727                                                    stack_pointer_rtx, 4));
42728             }
42729         }
42730       return gen_rtx_REG (SImode, regno);
42731     }
42732
42733   return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx,
42734                                              aggr ? 8 : 4));
42735 }
42736
42737 /* Determine whether x86_output_mi_thunk can succeed.  */
42738
42739 static bool
42740 x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset,
42741                          const_tree function)
42742 {
42743   /* 64-bit can handle anything.  */
42744   if (TARGET_64BIT)
42745     return true;
42746
42747   /* For 32-bit, everything's fine if we have one free register.  */
42748   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
42749     return true;
42750
42751   /* Need a free register for vcall_offset.  */
42752   if (vcall_offset)
42753     return false;
42754
42755   /* Need a free register for GOT references.  */
42756   if (flag_pic && !targetm.binds_local_p (function))
42757     return false;
42758
42759   /* Otherwise ok.  */
42760   return true;
42761 }
42762
42763 /* Output the assembler code for a thunk function.  THUNK_DECL is the
42764    declaration for the thunk function itself, FUNCTION is the decl for
42765    the target function.  DELTA is an immediate constant offset to be
42766    added to THIS.  If VCALL_OFFSET is nonzero, the word at
42767    *(*this + vcall_offset) should be added to THIS.  */
42768
42769 static void
42770 x86_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta,
42771                      HOST_WIDE_INT vcall_offset, tree function)
42772 {
42773   rtx this_param = x86_this_parameter (function);
42774   rtx this_reg, tmp, fnaddr;
42775   unsigned int tmp_regno;
42776   rtx_insn *insn;
42777
42778   if (TARGET_64BIT)
42779     tmp_regno = R10_REG;
42780   else
42781     {
42782       unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
42783       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
42784         tmp_regno = AX_REG;
42785       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
42786         tmp_regno = DX_REG;
42787       else
42788         tmp_regno = CX_REG;
42789     }
42790
42791   emit_note (NOTE_INSN_PROLOGUE_END);
42792
42793   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
42794      pull it in now and let DELTA benefit.  */
42795   if (REG_P (this_param))
42796     this_reg = this_param;
42797   else if (vcall_offset)
42798     {
42799       /* Put the this parameter into %eax.  */
42800       this_reg = gen_rtx_REG (Pmode, AX_REG);
42801       emit_move_insn (this_reg, this_param);
42802     }
42803   else
42804     this_reg = NULL_RTX;
42805
42806   /* Adjust the this parameter by a fixed constant.  */
42807   if (delta)
42808     {
42809       rtx delta_rtx = GEN_INT (delta);
42810       rtx delta_dst = this_reg ? this_reg : this_param;
42811
42812       if (TARGET_64BIT)
42813         {
42814           if (!x86_64_general_operand (delta_rtx, Pmode))
42815             {
42816               tmp = gen_rtx_REG (Pmode, tmp_regno);
42817               emit_move_insn (tmp, delta_rtx);
42818               delta_rtx = tmp;
42819             }
42820         }
42821
42822       ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx);
42823     }
42824
42825   /* Adjust the this parameter by a value stored in the vtable.  */
42826   if (vcall_offset)
42827     {
42828       rtx vcall_addr, vcall_mem, this_mem;
42829
42830       tmp = gen_rtx_REG (Pmode, tmp_regno);
42831
42832       this_mem = gen_rtx_MEM (ptr_mode, this_reg);
42833       if (Pmode != ptr_mode)
42834         this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem);
42835       emit_move_insn (tmp, this_mem);
42836
42837       /* Adjust the this parameter.  */
42838       vcall_addr = plus_constant (Pmode, tmp, vcall_offset);
42839       if (TARGET_64BIT
42840           && !ix86_legitimate_address_p (ptr_mode, vcall_addr, true))
42841         {
42842           rtx tmp2 = gen_rtx_REG (Pmode, R11_REG);
42843           emit_move_insn (tmp2, GEN_INT (vcall_offset));
42844           vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2);
42845         }
42846
42847       vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr);
42848       if (Pmode != ptr_mode)
42849         emit_insn (gen_addsi_1_zext (this_reg,
42850                                      gen_rtx_REG (ptr_mode,
42851                                                   REGNO (this_reg)),
42852                                      vcall_mem));
42853       else
42854         ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem);
42855     }
42856
42857   /* If necessary, drop THIS back to its stack slot.  */
42858   if (this_reg && this_reg != this_param)
42859     emit_move_insn (this_param, this_reg);
42860
42861   fnaddr = XEXP (DECL_RTL (function), 0);
42862   if (TARGET_64BIT)
42863     {
42864       if (!flag_pic || targetm.binds_local_p (function)
42865           || TARGET_PECOFF)
42866         ;
42867       else
42868         {
42869           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL);
42870           tmp = gen_rtx_CONST (Pmode, tmp);
42871           fnaddr = gen_const_mem (Pmode, tmp);
42872         }
42873     }
42874   else
42875     {
42876       if (!flag_pic || targetm.binds_local_p (function))
42877         ;
42878 #if TARGET_MACHO
42879       else if (TARGET_MACHO)
42880         {
42881           fnaddr = machopic_indirect_call_target (DECL_RTL (function));
42882           fnaddr = XEXP (fnaddr, 0);
42883         }
42884 #endif /* TARGET_MACHO */
42885       else
42886         {
42887           tmp = gen_rtx_REG (Pmode, CX_REG);
42888           output_set_got (tmp, NULL_RTX);
42889
42890           fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT);
42891           fnaddr = gen_rtx_CONST (Pmode, fnaddr);
42892           fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr);
42893           fnaddr = gen_const_mem (Pmode, fnaddr);
42894         }
42895     }
42896
42897   /* Our sibling call patterns do not allow memories, because we have no
42898      predicate that can distinguish between frame and non-frame memory.
42899      For our purposes here, we can get away with (ab)using a jump pattern,
42900      because we're going to do no optimization.  */
42901   if (MEM_P (fnaddr))
42902     {
42903       if (sibcall_insn_operand (fnaddr, word_mode))
42904         {
42905           fnaddr = XEXP (DECL_RTL (function), 0);
42906           tmp = gen_rtx_MEM (QImode, fnaddr);
42907           tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
42908           tmp = emit_call_insn (tmp);
42909           SIBLING_CALL_P (tmp) = 1;
42910         }
42911       else
42912         emit_jump_insn (gen_indirect_jump (fnaddr));
42913     }
42914   else
42915     {
42916       if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr))
42917         {
42918           // CM_LARGE_PIC always uses pseudo PIC register which is
42919           // uninitialized.  Since FUNCTION is local and calling it
42920           // doesn't go through PLT, we use scratch register %r11 as
42921           // PIC register and initialize it here.
42922           pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG);
42923           ix86_init_large_pic_reg (tmp_regno);
42924           fnaddr = legitimize_pic_address (fnaddr,
42925                                            gen_rtx_REG (Pmode, tmp_regno));
42926         }
42927
42928       if (!sibcall_insn_operand (fnaddr, word_mode))
42929         {
42930           tmp = gen_rtx_REG (word_mode, tmp_regno);
42931           if (GET_MODE (fnaddr) != word_mode)
42932             fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr);
42933           emit_move_insn (tmp, fnaddr);
42934           fnaddr = tmp;
42935         }
42936
42937       tmp = gen_rtx_MEM (QImode, fnaddr);
42938       tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
42939       tmp = emit_call_insn (tmp);
42940       SIBLING_CALL_P (tmp) = 1;
42941     }
42942   emit_barrier ();
42943
42944   /* Emit just enough of rest_of_compilation to get the insns emitted.
42945      Note that use_thunk calls assemble_start_function et al.  */
42946   insn = get_insns ();
42947   shorten_branches (insn);
42948   final_start_function (insn, file, 1);
42949   final (insn, file, 1);
42950   final_end_function ();
42951 }
42952
42953 static void
42954 x86_file_start (void)
42955 {
42956   default_file_start ();
42957   if (TARGET_16BIT)
42958     fputs ("\t.code16gcc\n", asm_out_file);
42959 #if TARGET_MACHO
42960   darwin_file_start ();
42961 #endif
42962   if (X86_FILE_START_VERSION_DIRECTIVE)
42963     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
42964   if (X86_FILE_START_FLTUSED)
42965     fputs ("\t.global\t__fltused\n", asm_out_file);
42966   if (ix86_asm_dialect == ASM_INTEL)
42967     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
42968 }
42969
42970 int
42971 x86_field_alignment (tree field, int computed)
42972 {
42973   machine_mode mode;
42974   tree type = TREE_TYPE (field);
42975
42976   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
42977     return computed;
42978   mode = TYPE_MODE (strip_array_types (type));
42979   if (mode == DFmode || mode == DCmode
42980       || GET_MODE_CLASS (mode) == MODE_INT
42981       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
42982     return MIN (32, computed);
42983   return computed;
42984 }
42985
42986 /* Print call to TARGET to FILE.  */
42987
42988 static void
42989 x86_print_call_or_nop (FILE *file, const char *target)
42990 {
42991   if (flag_nop_mcount)
42992     fprintf (file, "1:\tnopl 0x00(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
42993   else
42994     fprintf (file, "1:\tcall\t%s\n", target);
42995 }
42996
42997 /* Output assembler code to FILE to increment profiler label # LABELNO
42998    for profiling a function entry.  */
42999 void
43000 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
43001 {
43002   const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE
43003                                          : MCOUNT_NAME);
43004   if (TARGET_64BIT)
43005     {
43006 #ifndef NO_PROFILE_COUNTERS
43007       fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
43008 #endif
43009
43010       if (!TARGET_PECOFF && flag_pic)
43011         fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
43012       else
43013         x86_print_call_or_nop (file, mcount_name);
43014     }
43015   else if (flag_pic)
43016     {
43017 #ifndef NO_PROFILE_COUNTERS
43018       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n",
43019                LPREFIX, labelno);
43020 #endif
43021       fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
43022     }
43023   else
43024     {
43025 #ifndef NO_PROFILE_COUNTERS
43026       fprintf (file, "\tmovl\t$%sP%d,%%" PROFILE_COUNT_REGISTER "\n",
43027                LPREFIX, labelno);
43028 #endif
43029       x86_print_call_or_nop (file, mcount_name);
43030     }
43031
43032   if (flag_record_mcount)
43033     {
43034       fprintf (file, "\t.section __mcount_loc, \"a\",@progbits\n");
43035       fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
43036       fprintf (file, "\t.previous\n");
43037     }
43038 }
43039
43040 /* We don't have exact information about the insn sizes, but we may assume
43041    quite safely that we are informed about all 1 byte insns and memory
43042    address sizes.  This is enough to eliminate unnecessary padding in
43043    99% of cases.  */
43044
43045 static int
43046 min_insn_size (rtx_insn *insn)
43047 {
43048   int l = 0, len;
43049
43050   if (!INSN_P (insn) || !active_insn_p (insn))
43051     return 0;
43052
43053   /* Discard alignments we've emit and jump instructions.  */
43054   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
43055       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
43056     return 0;
43057
43058   /* Important case - calls are always 5 bytes.
43059      It is common to have many calls in the row.  */
43060   if (CALL_P (insn)
43061       && symbolic_reference_mentioned_p (PATTERN (insn))
43062       && !SIBLING_CALL_P (insn))
43063     return 5;
43064   len = get_attr_length (insn);
43065   if (len <= 1)
43066     return 1;
43067
43068   /* For normal instructions we rely on get_attr_length being exact,
43069      with a few exceptions.  */
43070   if (!JUMP_P (insn))
43071     {
43072       enum attr_type type = get_attr_type (insn);
43073
43074       switch (type)
43075         {
43076         case TYPE_MULTI:
43077           if (GET_CODE (PATTERN (insn)) == ASM_INPUT
43078               || asm_noperands (PATTERN (insn)) >= 0)
43079             return 0;
43080           break;
43081         case TYPE_OTHER:
43082         case TYPE_FCMP:
43083           break;
43084         default:
43085           /* Otherwise trust get_attr_length.  */
43086           return len;
43087         }
43088
43089       l = get_attr_length_address (insn);
43090       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
43091         l = 4;
43092     }
43093   if (l)
43094     return 1+l;
43095   else
43096     return 2;
43097 }
43098
43099 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
43100
43101 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
43102    window.  */
43103
43104 static void
43105 ix86_avoid_jump_mispredicts (void)
43106 {
43107   rtx_insn *insn, *start = get_insns ();
43108   int nbytes = 0, njumps = 0;
43109   bool isjump = false;
43110
43111   /* Look for all minimal intervals of instructions containing 4 jumps.
43112      The intervals are bounded by START and INSN.  NBYTES is the total
43113      size of instructions in the interval including INSN and not including
43114      START.  When the NBYTES is smaller than 16 bytes, it is possible
43115      that the end of START and INSN ends up in the same 16byte page.
43116
43117      The smallest offset in the page INSN can start is the case where START
43118      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
43119      We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
43120
43121      Don't consider asm goto as jump, while it can contain a jump, it doesn't
43122      have to, control transfer to label(s) can be performed through other
43123      means, and also we estimate minimum length of all asm stmts as 0.  */
43124   for (insn = start; insn; insn = NEXT_INSN (insn))
43125     {
43126       int min_size;
43127
43128       if (LABEL_P (insn))
43129         {
43130           int align = label_to_alignment (insn);
43131           int max_skip = label_to_max_skip (insn);
43132
43133           if (max_skip > 15)
43134             max_skip = 15;
43135           /* If align > 3, only up to 16 - max_skip - 1 bytes can be
43136              already in the current 16 byte page, because otherwise
43137              ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
43138              bytes to reach 16 byte boundary.  */
43139           if (align <= 0
43140               || (align <= 3 && max_skip != (1 << align) - 1))
43141             max_skip = 0;
43142           if (dump_file)
43143             fprintf (dump_file, "Label %i with max_skip %i\n",
43144                      INSN_UID (insn), max_skip);
43145           if (max_skip)
43146             {
43147               while (nbytes + max_skip >= 16)
43148                 {
43149                   start = NEXT_INSN (start);
43150                   if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
43151                       || CALL_P (start))
43152                     njumps--, isjump = true;
43153                   else
43154                     isjump = false;
43155                   nbytes -= min_insn_size (start);
43156                 }
43157             }
43158           continue;
43159         }
43160
43161       min_size = min_insn_size (insn);
43162       nbytes += min_size;
43163       if (dump_file)
43164         fprintf (dump_file, "Insn %i estimated to %i bytes\n",
43165                  INSN_UID (insn), min_size);
43166       if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0)
43167           || CALL_P (insn))
43168         njumps++;
43169       else
43170         continue;
43171
43172       while (njumps > 3)
43173         {
43174           start = NEXT_INSN (start);
43175           if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
43176               || CALL_P (start))
43177             njumps--, isjump = true;
43178           else
43179             isjump = false;
43180           nbytes -= min_insn_size (start);
43181         }
43182       gcc_assert (njumps >= 0);
43183       if (dump_file)
43184         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
43185                  INSN_UID (start), INSN_UID (insn), nbytes);
43186
43187       if (njumps == 3 && isjump && nbytes < 16)
43188         {
43189           int padsize = 15 - nbytes + min_insn_size (insn);
43190
43191           if (dump_file)
43192             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
43193                      INSN_UID (insn), padsize);
43194           emit_insn_before (gen_pad (GEN_INT (padsize)), insn);
43195         }
43196     }
43197 }
43198 #endif
43199
43200 /* AMD Athlon works faster
43201    when RET is not destination of conditional jump or directly preceded
43202    by other jump instruction.  We avoid the penalty by inserting NOP just
43203    before the RET instructions in such cases.  */
43204 static void
43205 ix86_pad_returns (void)
43206 {
43207   edge e;
43208   edge_iterator ei;
43209
43210   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43211     {
43212       basic_block bb = e->src;
43213       rtx_insn *ret = BB_END (bb);
43214       rtx_insn *prev;
43215       bool replace = false;
43216
43217       if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret))
43218           || optimize_bb_for_size_p (bb))
43219         continue;
43220       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
43221         if (active_insn_p (prev) || LABEL_P (prev))
43222           break;
43223       if (prev && LABEL_P (prev))
43224         {
43225           edge e;
43226           edge_iterator ei;
43227
43228           FOR_EACH_EDGE (e, ei, bb->preds)
43229             if (EDGE_FREQUENCY (e) && e->src->index >= 0
43230                 && !(e->flags & EDGE_FALLTHRU))
43231               {
43232                 replace = true;
43233                 break;
43234               }
43235         }
43236       if (!replace)
43237         {
43238           prev = prev_active_insn (ret);
43239           if (prev
43240               && ((JUMP_P (prev) && any_condjump_p (prev))
43241                   || CALL_P (prev)))
43242             replace = true;
43243           /* Empty functions get branch mispredict even when
43244              the jump destination is not visible to us.  */
43245           if (!prev && !optimize_function_for_size_p (cfun))
43246             replace = true;
43247         }
43248       if (replace)
43249         {
43250           emit_jump_insn_before (gen_simple_return_internal_long (), ret);
43251           delete_insn (ret);
43252         }
43253     }
43254 }
43255
43256 /* Count the minimum number of instructions in BB.  Return 4 if the
43257    number of instructions >= 4.  */
43258
43259 static int
43260 ix86_count_insn_bb (basic_block bb)
43261 {
43262   rtx_insn *insn;
43263   int insn_count = 0;
43264
43265   /* Count number of instructions in this block.  Return 4 if the number
43266      of instructions >= 4.  */
43267   FOR_BB_INSNS (bb, insn)
43268     {
43269       /* Only happen in exit blocks.  */
43270       if (JUMP_P (insn)
43271           && ANY_RETURN_P (PATTERN (insn)))
43272         break;
43273
43274       if (NONDEBUG_INSN_P (insn)
43275           && GET_CODE (PATTERN (insn)) != USE
43276           && GET_CODE (PATTERN (insn)) != CLOBBER)
43277         {
43278           insn_count++;
43279           if (insn_count >= 4)
43280             return insn_count;
43281         }
43282     }
43283
43284   return insn_count;
43285 }
43286
43287
43288 /* Count the minimum number of instructions in code path in BB.
43289    Return 4 if the number of instructions >= 4.  */
43290
43291 static int
43292 ix86_count_insn (basic_block bb)
43293 {
43294   edge e;
43295   edge_iterator ei;
43296   int min_prev_count;
43297
43298   /* Only bother counting instructions along paths with no
43299      more than 2 basic blocks between entry and exit.  Given
43300      that BB has an edge to exit, determine if a predecessor
43301      of BB has an edge from entry.  If so, compute the number
43302      of instructions in the predecessor block.  If there
43303      happen to be multiple such blocks, compute the minimum.  */
43304   min_prev_count = 4;
43305   FOR_EACH_EDGE (e, ei, bb->preds)
43306     {
43307       edge prev_e;
43308       edge_iterator prev_ei;
43309
43310       if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
43311         {
43312           min_prev_count = 0;
43313           break;
43314         }
43315       FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds)
43316         {
43317           if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
43318             {
43319               int count = ix86_count_insn_bb (e->src);
43320               if (count < min_prev_count)
43321                 min_prev_count = count;
43322               break;
43323             }
43324         }
43325     }
43326
43327   if (min_prev_count < 4)
43328     min_prev_count += ix86_count_insn_bb (bb);
43329
43330   return min_prev_count;
43331 }
43332
43333 /* Pad short function to 4 instructions.   */
43334
43335 static void
43336 ix86_pad_short_function (void)
43337 {
43338   edge e;
43339   edge_iterator ei;
43340
43341   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43342     {
43343       rtx_insn *ret = BB_END (e->src);
43344       if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret)))
43345         {
43346           int insn_count = ix86_count_insn (e->src);
43347
43348           /* Pad short function.  */
43349           if (insn_count < 4)
43350             {
43351               rtx_insn *insn = ret;
43352
43353               /* Find epilogue.  */
43354               while (insn
43355                      && (!NOTE_P (insn)
43356                          || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG))
43357                 insn = PREV_INSN (insn);
43358
43359               if (!insn)
43360                 insn = ret;
43361
43362               /* Two NOPs count as one instruction.  */
43363               insn_count = 2 * (4 - insn_count);
43364               emit_insn_before (gen_nops (GEN_INT (insn_count)), insn);
43365             }
43366         }
43367     }
43368 }
43369
43370 /* Fix up a Windows system unwinder issue.  If an EH region falls through into
43371    the epilogue, the Windows system unwinder will apply epilogue logic and
43372    produce incorrect offsets.  This can be avoided by adding a nop between
43373    the last insn that can throw and the first insn of the epilogue.  */
43374
43375 static void
43376 ix86_seh_fixup_eh_fallthru (void)
43377 {
43378   edge e;
43379   edge_iterator ei;
43380
43381   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43382     {
43383       rtx_insn *insn, *next;
43384
43385       /* Find the beginning of the epilogue.  */
43386       for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn))
43387         if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
43388           break;
43389       if (insn == NULL)
43390         continue;
43391
43392       /* We only care about preceding insns that can throw.  */
43393       insn = prev_active_insn (insn);
43394       if (insn == NULL || !can_throw_internal (insn))
43395         continue;
43396
43397       /* Do not separate calls from their debug information.  */
43398       for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next))
43399         if (NOTE_P (next)
43400             && (NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION
43401                 || NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION))
43402           insn = next;
43403         else
43404           break;
43405
43406       emit_insn_after (gen_nops (const1_rtx), insn);
43407     }
43408 }
43409
43410 /* Implement machine specific optimizations.  We implement padding of returns
43411    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
43412 static void
43413 ix86_reorg (void)
43414 {
43415   /* We are freeing block_for_insn in the toplev to keep compatibility
43416      with old MDEP_REORGS that are not CFG based.  Recompute it now.  */
43417   compute_bb_for_insn ();
43418
43419   if (TARGET_SEH && current_function_has_exception_handlers ())
43420     ix86_seh_fixup_eh_fallthru ();
43421
43422   if (optimize && optimize_function_for_speed_p (cfun))
43423     {
43424       if (TARGET_PAD_SHORT_FUNCTION)
43425         ix86_pad_short_function ();
43426       else if (TARGET_PAD_RETURNS)
43427         ix86_pad_returns ();
43428 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
43429       if (TARGET_FOUR_JUMP_LIMIT)
43430         ix86_avoid_jump_mispredicts ();
43431 #endif
43432     }
43433 }
43434
43435 /* Return nonzero when QImode register that must be represented via REX prefix
43436    is used.  */
43437 bool
43438 x86_extended_QIreg_mentioned_p (rtx_insn *insn)
43439 {
43440   int i;
43441   extract_insn_cached (insn);
43442   for (i = 0; i < recog_data.n_operands; i++)
43443     if (GENERAL_REG_P (recog_data.operand[i])
43444         && !QI_REGNO_P (REGNO (recog_data.operand[i])))
43445        return true;
43446   return false;
43447 }
43448
43449 /* Return true when INSN mentions register that must be encoded using REX
43450    prefix.  */
43451 bool
43452 x86_extended_reg_mentioned_p (rtx insn)
43453 {
43454   subrtx_iterator::array_type array;
43455   FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
43456     {
43457       const_rtx x = *iter;
43458       if (REG_P (x)
43459           && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x))))
43460         return true;
43461     }
43462   return false;
43463 }
43464
43465 /* If profitable, negate (without causing overflow) integer constant
43466    of mode MODE at location LOC.  Return true in this case.  */
43467 bool
43468 x86_maybe_negate_const_int (rtx *loc, machine_mode mode)
43469 {
43470   HOST_WIDE_INT val;
43471
43472   if (!CONST_INT_P (*loc))
43473     return false;
43474
43475   switch (mode)
43476     {
43477     case DImode:
43478       /* DImode x86_64 constants must fit in 32 bits.  */
43479       gcc_assert (x86_64_immediate_operand (*loc, mode));
43480
43481       mode = SImode;
43482       break;
43483
43484     case SImode:
43485     case HImode:
43486     case QImode:
43487       break;
43488
43489     default:
43490       gcc_unreachable ();
43491     }
43492
43493   /* Avoid overflows.  */
43494   if (mode_signbit_p (mode, *loc))
43495     return false;
43496
43497   val = INTVAL (*loc);
43498
43499   /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
43500      Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
43501   if ((val < 0 && val != -128)
43502       || val == 128)
43503     {
43504       *loc = GEN_INT (-val);
43505       return true;
43506     }
43507
43508   return false;
43509 }
43510
43511 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
43512    optabs would emit if we didn't have TFmode patterns.  */
43513
43514 void
43515 x86_emit_floatuns (rtx operands[2])
43516 {
43517   rtx_code_label *neglab, *donelab;
43518   rtx i0, i1, f0, in, out;
43519   machine_mode mode, inmode;
43520
43521   inmode = GET_MODE (operands[1]);
43522   gcc_assert (inmode == SImode || inmode == DImode);
43523
43524   out = operands[0];
43525   in = force_reg (inmode, operands[1]);
43526   mode = GET_MODE (out);
43527   neglab = gen_label_rtx ();
43528   donelab = gen_label_rtx ();
43529   f0 = gen_reg_rtx (mode);
43530
43531   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
43532
43533   expand_float (out, in, 0);
43534
43535   emit_jump_insn (gen_jump (donelab));
43536   emit_barrier ();
43537
43538   emit_label (neglab);
43539
43540   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
43541                             1, OPTAB_DIRECT);
43542   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
43543                             1, OPTAB_DIRECT);
43544   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
43545
43546   expand_float (f0, i0, 0);
43547
43548   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
43549
43550   emit_label (donelab);
43551 }
43552 \f
43553 static bool canonicalize_perm (struct expand_vec_perm_d *d);
43554 static bool expand_vec_perm_1 (struct expand_vec_perm_d *d);
43555 static bool expand_vec_perm_broadcast_1 (struct expand_vec_perm_d *d);
43556 static bool expand_vec_perm_palignr (struct expand_vec_perm_d *d, bool);
43557
43558 /* Get a vector mode of the same size as the original but with elements
43559    twice as wide.  This is only guaranteed to apply to integral vectors.  */
43560
43561 static inline machine_mode
43562 get_mode_wider_vector (machine_mode o)
43563 {
43564   /* ??? Rely on the ordering that genmodes.c gives to vectors.  */
43565   machine_mode n = GET_MODE_WIDER_MODE (o);
43566   gcc_assert (GET_MODE_NUNITS (o) == GET_MODE_NUNITS (n) * 2);
43567   gcc_assert (GET_MODE_SIZE (o) == GET_MODE_SIZE (n));
43568   return n;
43569 }
43570
43571 /* A subroutine of ix86_expand_vector_init_duplicate.  Tries to
43572    fill target with val via vec_duplicate.  */
43573
43574 static bool
43575 ix86_vector_duplicate_value (machine_mode mode, rtx target, rtx val)
43576 {
43577   bool ok;
43578   rtx_insn *insn;
43579   rtx dup;
43580
43581   /* First attempt to recognize VAL as-is.  */
43582   dup = gen_rtx_VEC_DUPLICATE (mode, val);
43583   insn = emit_insn (gen_rtx_SET (VOIDmode, target, dup));
43584   if (recog_memoized (insn) < 0)
43585     {
43586       rtx_insn *seq;
43587       /* If that fails, force VAL into a register.  */
43588
43589       start_sequence ();
43590       XEXP (dup, 0) = force_reg (GET_MODE_INNER (mode), val);
43591       seq = get_insns ();
43592       end_sequence ();
43593       if (seq)
43594         emit_insn_before (seq, insn);
43595
43596       ok = recog_memoized (insn) >= 0;
43597       gcc_assert (ok);
43598     }
43599   return true;
43600 }
43601
43602 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43603    with all elements equal to VAR.  Return true if successful.  */
43604
43605 static bool
43606 ix86_expand_vector_init_duplicate (bool mmx_ok, machine_mode mode,
43607                                    rtx target, rtx val)
43608 {
43609   bool ok;
43610
43611   switch (mode)
43612     {
43613     case V2SImode:
43614     case V2SFmode:
43615       if (!mmx_ok)
43616         return false;
43617       /* FALLTHRU */
43618
43619     case V4DFmode:
43620     case V4DImode:
43621     case V8SFmode:
43622     case V8SImode:
43623     case V2DFmode:
43624     case V2DImode:
43625     case V4SFmode:
43626     case V4SImode:
43627     case V16SImode:
43628     case V8DImode:
43629     case V16SFmode:
43630     case V8DFmode:
43631       return ix86_vector_duplicate_value (mode, target, val);
43632
43633     case V4HImode:
43634       if (!mmx_ok)
43635         return false;
43636       if (TARGET_SSE || TARGET_3DNOW_A)
43637         {
43638           rtx x;
43639
43640           val = gen_lowpart (SImode, val);
43641           x = gen_rtx_TRUNCATE (HImode, val);
43642           x = gen_rtx_VEC_DUPLICATE (mode, x);
43643           emit_insn (gen_rtx_SET (VOIDmode, target, x));
43644           return true;
43645         }
43646       goto widen;
43647
43648     case V8QImode:
43649       if (!mmx_ok)
43650         return false;
43651       goto widen;
43652
43653     case V8HImode:
43654       if (TARGET_AVX2)
43655         return ix86_vector_duplicate_value (mode, target, val);
43656
43657       if (TARGET_SSE2)
43658         {
43659           struct expand_vec_perm_d dperm;
43660           rtx tmp1, tmp2;
43661
43662         permute:
43663           memset (&dperm, 0, sizeof (dperm));
43664           dperm.target = target;
43665           dperm.vmode = mode;
43666           dperm.nelt = GET_MODE_NUNITS (mode);
43667           dperm.op0 = dperm.op1 = gen_reg_rtx (mode);
43668           dperm.one_operand_p = true;
43669
43670           /* Extend to SImode using a paradoxical SUBREG.  */
43671           tmp1 = gen_reg_rtx (SImode);
43672           emit_move_insn (tmp1, gen_lowpart (SImode, val));
43673
43674           /* Insert the SImode value as low element of a V4SImode vector. */
43675           tmp2 = gen_reg_rtx (V4SImode);
43676           emit_insn (gen_vec_setv4si_0 (tmp2, CONST0_RTX (V4SImode), tmp1));
43677           emit_move_insn (dperm.op0, gen_lowpart (mode, tmp2));
43678
43679           ok = (expand_vec_perm_1 (&dperm)
43680                 || expand_vec_perm_broadcast_1 (&dperm));
43681           gcc_assert (ok);
43682           return ok;
43683         }
43684       goto widen;
43685
43686     case V16QImode:
43687       if (TARGET_AVX2)
43688         return ix86_vector_duplicate_value (mode, target, val);
43689
43690       if (TARGET_SSE2)
43691         goto permute;
43692       goto widen;
43693
43694     widen:
43695       /* Replicate the value once into the next wider mode and recurse.  */
43696       {
43697         machine_mode smode, wsmode, wvmode;
43698         rtx x;
43699
43700         smode = GET_MODE_INNER (mode);
43701         wvmode = get_mode_wider_vector (mode);
43702         wsmode = GET_MODE_INNER (wvmode);
43703
43704         val = convert_modes (wsmode, smode, val, true);
43705         x = expand_simple_binop (wsmode, ASHIFT, val,
43706                                  GEN_INT (GET_MODE_BITSIZE (smode)),
43707                                  NULL_RTX, 1, OPTAB_LIB_WIDEN);
43708         val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
43709
43710         x = gen_reg_rtx (wvmode);
43711         ok = ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val);
43712         gcc_assert (ok);
43713         emit_move_insn (target, gen_lowpart (GET_MODE (target), x));
43714         return ok;
43715       }
43716
43717     case V16HImode:
43718     case V32QImode:
43719       if (TARGET_AVX2)
43720         return ix86_vector_duplicate_value (mode, target, val);
43721       else
43722         {
43723           machine_mode hvmode = (mode == V16HImode ? V8HImode : V16QImode);
43724           rtx x = gen_reg_rtx (hvmode);
43725
43726           ok = ix86_expand_vector_init_duplicate (false, hvmode, x, val);
43727           gcc_assert (ok);
43728
43729           x = gen_rtx_VEC_CONCAT (mode, x, x);
43730           emit_insn (gen_rtx_SET (VOIDmode, target, x));
43731         }
43732       return true;
43733
43734     case V64QImode:
43735     case V32HImode:
43736       if (TARGET_AVX512BW)
43737         return ix86_vector_duplicate_value (mode, target, val);
43738       else
43739         {
43740           machine_mode hvmode = (mode == V32HImode ? V16HImode : V32QImode);
43741           rtx x = gen_reg_rtx (hvmode);
43742
43743           ok = ix86_expand_vector_init_duplicate (false, hvmode, x, val);
43744           gcc_assert (ok);
43745
43746           x = gen_rtx_VEC_CONCAT (mode, x, x);
43747           emit_insn (gen_rtx_SET (VOIDmode, target, x));
43748         }
43749       return true;
43750
43751     default:
43752       return false;
43753     }
43754 }
43755
43756 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43757    whose ONE_VAR element is VAR, and other elements are zero.  Return true
43758    if successful.  */
43759
43760 static bool
43761 ix86_expand_vector_init_one_nonzero (bool mmx_ok, machine_mode mode,
43762                                      rtx target, rtx var, int one_var)
43763 {
43764   machine_mode vsimode;
43765   rtx new_target;
43766   rtx x, tmp;
43767   bool use_vector_set = false;
43768
43769   switch (mode)
43770     {
43771     case V2DImode:
43772       /* For SSE4.1, we normally use vector set.  But if the second
43773          element is zero and inter-unit moves are OK, we use movq
43774          instead.  */
43775       use_vector_set = (TARGET_64BIT && TARGET_SSE4_1
43776                         && !(TARGET_INTER_UNIT_MOVES_TO_VEC
43777                              && one_var == 0));
43778       break;
43779     case V16QImode:
43780     case V4SImode:
43781     case V4SFmode:
43782       use_vector_set = TARGET_SSE4_1;
43783       break;
43784     case V8HImode:
43785       use_vector_set = TARGET_SSE2;
43786       break;
43787     case V4HImode:
43788       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
43789       break;
43790     case V32QImode:
43791     case V16HImode:
43792     case V8SImode:
43793     case V8SFmode:
43794     case V4DFmode:
43795       use_vector_set = TARGET_AVX;
43796       break;
43797     case V4DImode:
43798       /* Use ix86_expand_vector_set in 64bit mode only.  */
43799       use_vector_set = TARGET_AVX && TARGET_64BIT;
43800       break;
43801     default:
43802       break;
43803     }
43804
43805   if (use_vector_set)
43806     {
43807       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
43808       var = force_reg (GET_MODE_INNER (mode), var);
43809       ix86_expand_vector_set (mmx_ok, target, var, one_var);
43810       return true;
43811     }
43812
43813   switch (mode)
43814     {
43815     case V2SFmode:
43816     case V2SImode:
43817       if (!mmx_ok)
43818         return false;
43819       /* FALLTHRU */
43820
43821     case V2DFmode:
43822     case V2DImode:
43823       if (one_var != 0)
43824         return false;
43825       var = force_reg (GET_MODE_INNER (mode), var);
43826       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
43827       emit_insn (gen_rtx_SET (VOIDmode, target, x));
43828       return true;
43829
43830     case V4SFmode:
43831     case V4SImode:
43832       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
43833         new_target = gen_reg_rtx (mode);
43834       else
43835         new_target = target;
43836       var = force_reg (GET_MODE_INNER (mode), var);
43837       x = gen_rtx_VEC_DUPLICATE (mode, var);
43838       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
43839       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
43840       if (one_var != 0)
43841         {
43842           /* We need to shuffle the value to the correct position, so
43843              create a new pseudo to store the intermediate result.  */
43844
43845           /* With SSE2, we can use the integer shuffle insns.  */
43846           if (mode != V4SFmode && TARGET_SSE2)
43847             {
43848               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
43849                                             const1_rtx,
43850                                             GEN_INT (one_var == 1 ? 0 : 1),
43851                                             GEN_INT (one_var == 2 ? 0 : 1),
43852                                             GEN_INT (one_var == 3 ? 0 : 1)));
43853               if (target != new_target)
43854                 emit_move_insn (target, new_target);
43855               return true;
43856             }
43857
43858           /* Otherwise convert the intermediate result to V4SFmode and
43859              use the SSE1 shuffle instructions.  */
43860           if (mode != V4SFmode)
43861             {
43862               tmp = gen_reg_rtx (V4SFmode);
43863               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
43864             }
43865           else
43866             tmp = new_target;
43867
43868           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
43869                                        const1_rtx,
43870                                        GEN_INT (one_var == 1 ? 0 : 1),
43871                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
43872                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
43873
43874           if (mode != V4SFmode)
43875             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
43876           else if (tmp != target)
43877             emit_move_insn (target, tmp);
43878         }
43879       else if (target != new_target)
43880         emit_move_insn (target, new_target);
43881       return true;
43882
43883     case V8HImode:
43884     case V16QImode:
43885       vsimode = V4SImode;
43886       goto widen;
43887     case V4HImode:
43888     case V8QImode:
43889       if (!mmx_ok)
43890         return false;
43891       vsimode = V2SImode;
43892       goto widen;
43893     widen:
43894       if (one_var != 0)
43895         return false;
43896
43897       /* Zero extend the variable element to SImode and recurse.  */
43898       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
43899
43900       x = gen_reg_rtx (vsimode);
43901       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
43902                                                 var, one_var))
43903         gcc_unreachable ();
43904
43905       emit_move_insn (target, gen_lowpart (mode, x));
43906       return true;
43907
43908     default:
43909       return false;
43910     }
43911 }
43912
43913 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43914    consisting of the values in VALS.  It is known that all elements
43915    except ONE_VAR are constants.  Return true if successful.  */
43916
43917 static bool
43918 ix86_expand_vector_init_one_var (bool mmx_ok, machine_mode mode,
43919                                  rtx target, rtx vals, int one_var)
43920 {
43921   rtx var = XVECEXP (vals, 0, one_var);
43922   machine_mode wmode;
43923   rtx const_vec, x;
43924
43925   const_vec = copy_rtx (vals);
43926   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
43927   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
43928
43929   switch (mode)
43930     {
43931     case V2DFmode:
43932     case V2DImode:
43933     case V2SFmode:
43934     case V2SImode:
43935       /* For the two element vectors, it's just as easy to use
43936          the general case.  */
43937       return false;
43938
43939     case V4DImode:
43940       /* Use ix86_expand_vector_set in 64bit mode only.  */
43941       if (!TARGET_64BIT)
43942         return false;
43943     case V4DFmode:
43944     case V8SFmode:
43945     case V8SImode:
43946     case V16HImode:
43947     case V32QImode:
43948     case V4SFmode:
43949     case V4SImode:
43950     case V8HImode:
43951     case V4HImode:
43952       break;
43953
43954     case V16QImode:
43955       if (TARGET_SSE4_1)
43956         break;
43957       wmode = V8HImode;
43958       goto widen;
43959     case V8QImode:
43960       wmode = V4HImode;
43961       goto widen;
43962     widen:
43963       /* There's no way to set one QImode entry easily.  Combine
43964          the variable value with its adjacent constant value, and
43965          promote to an HImode set.  */
43966       x = XVECEXP (vals, 0, one_var ^ 1);
43967       if (one_var & 1)
43968         {
43969           var = convert_modes (HImode, QImode, var, true);
43970           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
43971                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
43972           x = GEN_INT (INTVAL (x) & 0xff);
43973         }
43974       else
43975         {
43976           var = convert_modes (HImode, QImode, var, true);
43977           x = gen_int_mode (INTVAL (x) << 8, HImode);
43978         }
43979       if (x != const0_rtx)
43980         var = expand_simple_binop (HImode, IOR, var, x, var,
43981                                    1, OPTAB_LIB_WIDEN);
43982
43983       x = gen_reg_rtx (wmode);
43984       emit_move_insn (x, gen_lowpart (wmode, const_vec));
43985       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
43986
43987       emit_move_insn (target, gen_lowpart (mode, x));
43988       return true;
43989
43990     default:
43991       return false;
43992     }
43993
43994   emit_move_insn (target, const_vec);
43995   ix86_expand_vector_set (mmx_ok, target, var, one_var);
43996   return true;
43997 }
43998
43999 /* A subroutine of ix86_expand_vector_init_general.  Use vector
44000    concatenate to handle the most general case: all values variable,
44001    and none identical.  */
44002
44003 static void
44004 ix86_expand_vector_init_concat (machine_mode mode,
44005                                 rtx target, rtx *ops, int n)
44006 {
44007   machine_mode cmode, hmode = VOIDmode, gmode = VOIDmode;
44008   rtx first[16], second[8], third[4];
44009   rtvec v;
44010   int i, j;
44011
44012   switch (n)
44013     {
44014     case 2:
44015       switch (mode)
44016         {
44017         case V16SImode:
44018           cmode = V8SImode;
44019           break;
44020         case V16SFmode:
44021           cmode = V8SFmode;
44022           break;
44023         case V8DImode:
44024           cmode = V4DImode;
44025           break;
44026         case V8DFmode:
44027           cmode = V4DFmode;
44028           break;
44029         case V8SImode:
44030           cmode = V4SImode;
44031           break;
44032         case V8SFmode:
44033           cmode = V4SFmode;
44034           break;
44035         case V4DImode:
44036           cmode = V2DImode;
44037           break;
44038         case V4DFmode:
44039           cmode = V2DFmode;
44040           break;
44041         case V4SImode:
44042           cmode = V2SImode;
44043           break;
44044         case V4SFmode:
44045           cmode = V2SFmode;
44046           break;
44047         case V2DImode:
44048           cmode = DImode;
44049           break;
44050         case V2SImode:
44051           cmode = SImode;
44052           break;
44053         case V2DFmode:
44054           cmode = DFmode;
44055           break;
44056         case V2SFmode:
44057           cmode = SFmode;
44058           break;
44059         default:
44060           gcc_unreachable ();
44061         }
44062
44063       if (!register_operand (ops[1], cmode))
44064         ops[1] = force_reg (cmode, ops[1]);
44065       if (!register_operand (ops[0], cmode))
44066         ops[0] = force_reg (cmode, ops[0]);
44067       emit_insn (gen_rtx_SET (VOIDmode, target,
44068                               gen_rtx_VEC_CONCAT (mode, ops[0],
44069                                                   ops[1])));
44070       break;
44071
44072     case 4:
44073       switch (mode)
44074         {
44075         case V4DImode:
44076           cmode = V2DImode;
44077           break;
44078         case V4DFmode:
44079           cmode = V2DFmode;
44080           break;
44081         case V4SImode:
44082           cmode = V2SImode;
44083           break;
44084         case V4SFmode:
44085           cmode = V2SFmode;
44086           break;
44087         default:
44088           gcc_unreachable ();
44089         }
44090       goto half;
44091
44092     case 8:
44093       switch (mode)
44094         {
44095         case V8DImode:
44096           cmode = V2DImode;
44097           hmode = V4DImode;
44098           break;
44099         case V8DFmode:
44100           cmode = V2DFmode;
44101           hmode = V4DFmode;
44102           break;
44103         case V8SImode:
44104           cmode = V2SImode;
44105           hmode = V4SImode;
44106           break;
44107         case V8SFmode:
44108           cmode = V2SFmode;
44109           hmode = V4SFmode;
44110           break;
44111         default:
44112           gcc_unreachable ();
44113         }
44114       goto half;
44115
44116     case 16:
44117       switch (mode)
44118         {
44119         case V16SImode:
44120           cmode = V2SImode;
44121           hmode = V4SImode;
44122           gmode = V8SImode;
44123           break;
44124         case V16SFmode:
44125           cmode = V2SFmode;
44126           hmode = V4SFmode;
44127           gmode = V8SFmode;
44128           break;
44129         default:
44130           gcc_unreachable ();
44131         }
44132       goto half;
44133
44134 half:
44135       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
44136       i = n - 1;
44137       j = (n >> 1) - 1;
44138       for (; i > 0; i -= 2, j--)
44139         {
44140           first[j] = gen_reg_rtx (cmode);
44141           v = gen_rtvec (2, ops[i - 1], ops[i]);
44142           ix86_expand_vector_init (false, first[j],
44143                                    gen_rtx_PARALLEL (cmode, v));
44144         }
44145
44146       n >>= 1;
44147       if (n > 4)
44148         {
44149           gcc_assert (hmode != VOIDmode);
44150           gcc_assert (gmode != VOIDmode);
44151           for (i = j = 0; i < n; i += 2, j++)
44152             {
44153               second[j] = gen_reg_rtx (hmode);
44154               ix86_expand_vector_init_concat (hmode, second [j],
44155                                               &first [i], 2);
44156             }
44157           n >>= 1;
44158           for (i = j = 0; i < n; i += 2, j++)
44159             {
44160               third[j] = gen_reg_rtx (gmode);
44161               ix86_expand_vector_init_concat (gmode, third[j],
44162                                               &second[i], 2);
44163             }
44164           n >>= 1;
44165           ix86_expand_vector_init_concat (mode, target, third, n);
44166         }
44167       else if (n > 2)
44168         {
44169           gcc_assert (hmode != VOIDmode);
44170           for (i = j = 0; i < n; i += 2, j++)
44171             {
44172               second[j] = gen_reg_rtx (hmode);
44173               ix86_expand_vector_init_concat (hmode, second [j],
44174                                               &first [i], 2);
44175             }
44176           n >>= 1;
44177           ix86_expand_vector_init_concat (mode, target, second, n);
44178         }
44179       else
44180         ix86_expand_vector_init_concat (mode, target, first, n);
44181       break;
44182
44183     default:
44184       gcc_unreachable ();
44185     }
44186 }
44187
44188 /* A subroutine of ix86_expand_vector_init_general.  Use vector
44189    interleave to handle the most general case: all values variable,
44190    and none identical.  */
44191
44192 static void
44193 ix86_expand_vector_init_interleave (machine_mode mode,
44194                                     rtx target, rtx *ops, int n)
44195 {
44196   machine_mode first_imode, second_imode, third_imode, inner_mode;
44197   int i, j;
44198   rtx op0, op1;
44199   rtx (*gen_load_even) (rtx, rtx, rtx);
44200   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
44201   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
44202
44203   switch (mode)
44204     {
44205     case V8HImode:
44206       gen_load_even = gen_vec_setv8hi;
44207       gen_interleave_first_low = gen_vec_interleave_lowv4si;
44208       gen_interleave_second_low = gen_vec_interleave_lowv2di;
44209       inner_mode = HImode;
44210       first_imode = V4SImode;
44211       second_imode = V2DImode;
44212       third_imode = VOIDmode;
44213       break;
44214     case V16QImode:
44215       gen_load_even = gen_vec_setv16qi;
44216       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
44217       gen_interleave_second_low = gen_vec_interleave_lowv4si;
44218       inner_mode = QImode;
44219       first_imode = V8HImode;
44220       second_imode = V4SImode;
44221       third_imode = V2DImode;
44222       break;
44223     default:
44224       gcc_unreachable ();
44225     }
44226
44227   for (i = 0; i < n; i++)
44228     {
44229       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
44230       op0 = gen_reg_rtx (SImode);
44231       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
44232
44233       /* Insert the SImode value as low element of V4SImode vector. */
44234       op1 = gen_reg_rtx (V4SImode);
44235       op0 = gen_rtx_VEC_MERGE (V4SImode,
44236                                gen_rtx_VEC_DUPLICATE (V4SImode,
44237                                                       op0),
44238                                CONST0_RTX (V4SImode),
44239                                const1_rtx);
44240       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
44241
44242       /* Cast the V4SImode vector back to a vector in orignal mode.  */
44243       op0 = gen_reg_rtx (mode);
44244       emit_move_insn (op0, gen_lowpart (mode, op1));
44245
44246       /* Load even elements into the second position.  */
44247       emit_insn (gen_load_even (op0,
44248                                 force_reg (inner_mode,
44249                                            ops [i + i + 1]),
44250                                 const1_rtx));
44251
44252       /* Cast vector to FIRST_IMODE vector.  */
44253       ops[i] = gen_reg_rtx (first_imode);
44254       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
44255     }
44256
44257   /* Interleave low FIRST_IMODE vectors.  */
44258   for (i = j = 0; i < n; i += 2, j++)
44259     {
44260       op0 = gen_reg_rtx (first_imode);
44261       emit_insn (gen_interleave_first_low (op0, ops[i], ops[i + 1]));
44262
44263       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
44264       ops[j] = gen_reg_rtx (second_imode);
44265       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
44266     }
44267
44268   /* Interleave low SECOND_IMODE vectors.  */
44269   switch (second_imode)
44270     {
44271     case V4SImode:
44272       for (i = j = 0; i < n / 2; i += 2, j++)
44273         {
44274           op0 = gen_reg_rtx (second_imode);
44275           emit_insn (gen_interleave_second_low (op0, ops[i],
44276                                                 ops[i + 1]));
44277
44278           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
44279              vector.  */
44280           ops[j] = gen_reg_rtx (third_imode);
44281           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
44282         }
44283       second_imode = V2DImode;
44284       gen_interleave_second_low = gen_vec_interleave_lowv2di;
44285       /* FALLTHRU */
44286
44287     case V2DImode:
44288       op0 = gen_reg_rtx (second_imode);
44289       emit_insn (gen_interleave_second_low (op0, ops[0],
44290                                             ops[1]));
44291
44292       /* Cast the SECOND_IMODE vector back to a vector on original
44293          mode.  */
44294       emit_insn (gen_rtx_SET (VOIDmode, target,
44295                               gen_lowpart (mode, op0)));
44296       break;
44297
44298     default:
44299       gcc_unreachable ();
44300     }
44301 }
44302
44303 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
44304    all values variable, and none identical.  */
44305
44306 static void
44307 ix86_expand_vector_init_general (bool mmx_ok, machine_mode mode,
44308                                  rtx target, rtx vals)
44309 {
44310   rtx ops[64], op0, op1, op2, op3, op4, op5;
44311   machine_mode half_mode = VOIDmode;
44312   machine_mode quarter_mode = VOIDmode;
44313   int n, i;
44314
44315   switch (mode)
44316     {
44317     case V2SFmode:
44318     case V2SImode:
44319       if (!mmx_ok && !TARGET_SSE)
44320         break;
44321       /* FALLTHRU */
44322
44323     case V16SImode:
44324     case V16SFmode:
44325     case V8DFmode:
44326     case V8DImode:
44327     case V8SFmode:
44328     case V8SImode:
44329     case V4DFmode:
44330     case V4DImode:
44331     case V4SFmode:
44332     case V4SImode:
44333     case V2DFmode:
44334     case V2DImode:
44335       n = GET_MODE_NUNITS (mode);
44336       for (i = 0; i < n; i++)
44337         ops[i] = XVECEXP (vals, 0, i);
44338       ix86_expand_vector_init_concat (mode, target, ops, n);
44339       return;
44340
44341     case V32QImode:
44342       half_mode = V16QImode;
44343       goto half;
44344
44345     case V16HImode:
44346       half_mode = V8HImode;
44347       goto half;
44348
44349 half:
44350       n = GET_MODE_NUNITS (mode);
44351       for (i = 0; i < n; i++)
44352         ops[i] = XVECEXP (vals, 0, i);
44353       op0 = gen_reg_rtx (half_mode);
44354       op1 = gen_reg_rtx (half_mode);
44355       ix86_expand_vector_init_interleave (half_mode, op0, ops,
44356                                           n >> 2);
44357       ix86_expand_vector_init_interleave (half_mode, op1,
44358                                           &ops [n >> 1], n >> 2);
44359       emit_insn (gen_rtx_SET (VOIDmode, target,
44360                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
44361       return;
44362
44363     case V64QImode:
44364       quarter_mode = V16QImode;
44365       half_mode = V32QImode;
44366       goto quarter;
44367
44368     case V32HImode:
44369       quarter_mode = V8HImode;
44370       half_mode = V16HImode;
44371       goto quarter;
44372
44373 quarter:
44374       n = GET_MODE_NUNITS (mode);
44375       for (i = 0; i < n; i++)
44376         ops[i] = XVECEXP (vals, 0, i);
44377       op0 = gen_reg_rtx (quarter_mode);
44378       op1 = gen_reg_rtx (quarter_mode);
44379       op2 = gen_reg_rtx (quarter_mode);
44380       op3 = gen_reg_rtx (quarter_mode);
44381       op4 = gen_reg_rtx (half_mode);
44382       op5 = gen_reg_rtx (half_mode);
44383       ix86_expand_vector_init_interleave (quarter_mode, op0, ops,
44384                                           n >> 3);
44385       ix86_expand_vector_init_interleave (quarter_mode, op1,
44386                                           &ops [n >> 2], n >> 3);
44387       ix86_expand_vector_init_interleave (quarter_mode, op2,
44388                                           &ops [n >> 1], n >> 3);
44389       ix86_expand_vector_init_interleave (quarter_mode, op3,
44390                                           &ops [(n >> 1) | (n >> 2)], n >> 3);
44391       emit_insn (gen_rtx_SET (VOIDmode, op4,
44392                               gen_rtx_VEC_CONCAT (half_mode, op0, op1)));
44393       emit_insn (gen_rtx_SET (VOIDmode, op5,
44394                               gen_rtx_VEC_CONCAT (half_mode, op2, op3)));
44395       emit_insn (gen_rtx_SET (VOIDmode, target,
44396                               gen_rtx_VEC_CONCAT (mode, op4, op5)));
44397       return;
44398
44399     case V16QImode:
44400       if (!TARGET_SSE4_1)
44401         break;
44402       /* FALLTHRU */
44403
44404     case V8HImode:
44405       if (!TARGET_SSE2)
44406         break;
44407
44408       /* Don't use ix86_expand_vector_init_interleave if we can't
44409          move from GPR to SSE register directly.  */
44410       if (!TARGET_INTER_UNIT_MOVES_TO_VEC)
44411         break;
44412
44413       n = GET_MODE_NUNITS (mode);
44414       for (i = 0; i < n; i++)
44415         ops[i] = XVECEXP (vals, 0, i);
44416       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
44417       return;
44418
44419     case V4HImode:
44420     case V8QImode:
44421       break;
44422
44423     default:
44424       gcc_unreachable ();
44425     }
44426
44427     {
44428       int i, j, n_elts, n_words, n_elt_per_word;
44429       machine_mode inner_mode;
44430       rtx words[4], shift;
44431
44432       inner_mode = GET_MODE_INNER (mode);
44433       n_elts = GET_MODE_NUNITS (mode);
44434       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
44435       n_elt_per_word = n_elts / n_words;
44436       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
44437
44438       for (i = 0; i < n_words; ++i)
44439         {
44440           rtx word = NULL_RTX;
44441
44442           for (j = 0; j < n_elt_per_word; ++j)
44443             {
44444               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
44445               elt = convert_modes (word_mode, inner_mode, elt, true);
44446
44447               if (j == 0)
44448                 word = elt;
44449               else
44450                 {
44451                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
44452                                               word, 1, OPTAB_LIB_WIDEN);
44453                   word = expand_simple_binop (word_mode, IOR, word, elt,
44454                                               word, 1, OPTAB_LIB_WIDEN);
44455                 }
44456             }
44457
44458           words[i] = word;
44459         }
44460
44461       if (n_words == 1)
44462         emit_move_insn (target, gen_lowpart (mode, words[0]));
44463       else if (n_words == 2)
44464         {
44465           rtx tmp = gen_reg_rtx (mode);
44466           emit_clobber (tmp);
44467           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
44468           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
44469           emit_move_insn (target, tmp);
44470         }
44471       else if (n_words == 4)
44472         {
44473           rtx tmp = gen_reg_rtx (V4SImode);
44474           gcc_assert (word_mode == SImode);
44475           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
44476           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
44477           emit_move_insn (target, gen_lowpart (mode, tmp));
44478         }
44479       else
44480         gcc_unreachable ();
44481     }
44482 }
44483
44484 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
44485    instructions unless MMX_OK is true.  */
44486
44487 void
44488 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
44489 {
44490   machine_mode mode = GET_MODE (target);
44491   machine_mode inner_mode = GET_MODE_INNER (mode);
44492   int n_elts = GET_MODE_NUNITS (mode);
44493   int n_var = 0, one_var = -1;
44494   bool all_same = true, all_const_zero = true;
44495   int i;
44496   rtx x;
44497
44498   for (i = 0; i < n_elts; ++i)
44499     {
44500       x = XVECEXP (vals, 0, i);
44501       if (!(CONST_INT_P (x)
44502             || GET_CODE (x) == CONST_DOUBLE
44503             || GET_CODE (x) == CONST_FIXED))
44504         n_var++, one_var = i;
44505       else if (x != CONST0_RTX (inner_mode))
44506         all_const_zero = false;
44507       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
44508         all_same = false;
44509     }
44510
44511   /* Constants are best loaded from the constant pool.  */
44512   if (n_var == 0)
44513     {
44514       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
44515       return;
44516     }
44517
44518   /* If all values are identical, broadcast the value.  */
44519   if (all_same
44520       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
44521                                             XVECEXP (vals, 0, 0)))
44522     return;
44523
44524   /* Values where only one field is non-constant are best loaded from
44525      the pool and overwritten via move later.  */
44526   if (n_var == 1)
44527     {
44528       if (all_const_zero
44529           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
44530                                                   XVECEXP (vals, 0, one_var),
44531                                                   one_var))
44532         return;
44533
44534       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
44535         return;
44536     }
44537
44538   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
44539 }
44540
44541 void
44542 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
44543 {
44544   machine_mode mode = GET_MODE (target);
44545   machine_mode inner_mode = GET_MODE_INNER (mode);
44546   machine_mode half_mode;
44547   bool use_vec_merge = false;
44548   rtx tmp;
44549   static rtx (*gen_extract[6][2]) (rtx, rtx)
44550     = {
44551         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
44552         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
44553         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
44554         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
44555         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
44556         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
44557       };
44558   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
44559     = {
44560         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
44561         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
44562         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
44563         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
44564         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
44565         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
44566       };
44567   int i, j, n;
44568
44569   switch (mode)
44570     {
44571     case V2SFmode:
44572     case V2SImode:
44573       if (mmx_ok)
44574         {
44575           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
44576           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
44577           if (elt == 0)
44578             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
44579           else
44580             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
44581           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44582           return;
44583         }
44584       break;
44585
44586     case V2DImode:
44587       use_vec_merge = TARGET_SSE4_1 && TARGET_64BIT;
44588       if (use_vec_merge)
44589         break;
44590
44591       tmp = gen_reg_rtx (GET_MODE_INNER (mode));
44592       ix86_expand_vector_extract (false, tmp, target, 1 - elt);
44593       if (elt == 0)
44594         tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
44595       else
44596         tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
44597       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44598       return;
44599
44600     case V2DFmode:
44601       {
44602         rtx op0, op1;
44603
44604         /* For the two element vectors, we implement a VEC_CONCAT with
44605            the extraction of the other element.  */
44606
44607         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
44608         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
44609
44610         if (elt == 0)
44611           op0 = val, op1 = tmp;
44612         else
44613           op0 = tmp, op1 = val;
44614
44615         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
44616         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44617       }
44618       return;
44619
44620     case V4SFmode:
44621       use_vec_merge = TARGET_SSE4_1;
44622       if (use_vec_merge)
44623         break;
44624
44625       switch (elt)
44626         {
44627         case 0:
44628           use_vec_merge = true;
44629           break;
44630
44631         case 1:
44632           /* tmp = target = A B C D */
44633           tmp = copy_to_reg (target);
44634           /* target = A A B B */
44635           emit_insn (gen_vec_interleave_lowv4sf (target, target, target));
44636           /* target = X A B B */
44637           ix86_expand_vector_set (false, target, val, 0);
44638           /* target = A X C D  */
44639           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44640                                           const1_rtx, const0_rtx,
44641                                           GEN_INT (2+4), GEN_INT (3+4)));
44642           return;
44643
44644         case 2:
44645           /* tmp = target = A B C D */
44646           tmp = copy_to_reg (target);
44647           /* tmp = X B C D */
44648           ix86_expand_vector_set (false, tmp, val, 0);
44649           /* target = A B X D */
44650           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44651                                           const0_rtx, const1_rtx,
44652                                           GEN_INT (0+4), GEN_INT (3+4)));
44653           return;
44654
44655         case 3:
44656           /* tmp = target = A B C D */
44657           tmp = copy_to_reg (target);
44658           /* tmp = X B C D */
44659           ix86_expand_vector_set (false, tmp, val, 0);
44660           /* target = A B X D */
44661           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44662                                           const0_rtx, const1_rtx,
44663                                           GEN_INT (2+4), GEN_INT (0+4)));
44664           return;
44665
44666         default:
44667           gcc_unreachable ();
44668         }
44669       break;
44670
44671     case V4SImode:
44672       use_vec_merge = TARGET_SSE4_1;
44673       if (use_vec_merge)
44674         break;
44675
44676       /* Element 0 handled by vec_merge below.  */
44677       if (elt == 0)
44678         {
44679           use_vec_merge = true;
44680           break;
44681         }
44682
44683       if (TARGET_SSE2)
44684         {
44685           /* With SSE2, use integer shuffles to swap element 0 and ELT,
44686              store into element 0, then shuffle them back.  */
44687
44688           rtx order[4];
44689
44690           order[0] = GEN_INT (elt);
44691           order[1] = const1_rtx;
44692           order[2] = const2_rtx;
44693           order[3] = GEN_INT (3);
44694           order[elt] = const0_rtx;
44695
44696           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
44697                                         order[1], order[2], order[3]));
44698
44699           ix86_expand_vector_set (false, target, val, 0);
44700
44701           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
44702                                         order[1], order[2], order[3]));
44703         }
44704       else
44705         {
44706           /* For SSE1, we have to reuse the V4SF code.  */
44707           rtx t = gen_reg_rtx (V4SFmode);
44708           ix86_expand_vector_set (false, t, gen_lowpart (SFmode, val), elt);
44709           emit_move_insn (target, gen_lowpart (mode, t));
44710         }
44711       return;
44712
44713     case V8HImode:
44714       use_vec_merge = TARGET_SSE2;
44715       break;
44716     case V4HImode:
44717       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
44718       break;
44719
44720     case V16QImode:
44721       use_vec_merge = TARGET_SSE4_1;
44722       break;
44723
44724     case V8QImode:
44725       break;
44726
44727     case V32QImode:
44728       half_mode = V16QImode;
44729       j = 0;
44730       n = 16;
44731       goto half;
44732
44733     case V16HImode:
44734       half_mode = V8HImode;
44735       j = 1;
44736       n = 8;
44737       goto half;
44738
44739     case V8SImode:
44740       half_mode = V4SImode;
44741       j = 2;
44742       n = 4;
44743       goto half;
44744
44745     case V4DImode:
44746       half_mode = V2DImode;
44747       j = 3;
44748       n = 2;
44749       goto half;
44750
44751     case V8SFmode:
44752       half_mode = V4SFmode;
44753       j = 4;
44754       n = 4;
44755       goto half;
44756
44757     case V4DFmode:
44758       half_mode = V2DFmode;
44759       j = 5;
44760       n = 2;
44761       goto half;
44762
44763 half:
44764       /* Compute offset.  */
44765       i = elt / n;
44766       elt %= n;
44767
44768       gcc_assert (i <= 1);
44769
44770       /* Extract the half.  */
44771       tmp = gen_reg_rtx (half_mode);
44772       emit_insn (gen_extract[j][i] (tmp, target));
44773
44774       /* Put val in tmp at elt.  */
44775       ix86_expand_vector_set (false, tmp, val, elt);
44776
44777       /* Put it back.  */
44778       emit_insn (gen_insert[j][i] (target, target, tmp));
44779       return;
44780
44781     case V8DFmode:
44782       if (TARGET_AVX512F)
44783         {
44784           tmp = gen_reg_rtx (mode);
44785           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44786                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44787           emit_insn (gen_avx512f_blendmv8df (target, tmp, target,
44788                                              force_reg (QImode, GEN_INT (1 << elt))));
44789           return;
44790         }
44791       else
44792         break;
44793     case V8DImode:
44794       if (TARGET_AVX512F)
44795         {
44796           tmp = gen_reg_rtx (mode);
44797           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44798                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44799           emit_insn (gen_avx512f_blendmv8di (target, tmp, target,
44800                                              force_reg (QImode, GEN_INT (1 << elt))));
44801           return;
44802         }
44803       else
44804         break;
44805     case V16SFmode:
44806       if (TARGET_AVX512F)
44807         {
44808           tmp = gen_reg_rtx (mode);
44809           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44810                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44811           emit_insn (gen_avx512f_blendmv16sf (target, tmp, target,
44812                                               force_reg (HImode, GEN_INT (1 << elt))));
44813           return;
44814         }
44815       else
44816         break;
44817     case V16SImode:
44818       if (TARGET_AVX512F)
44819         {
44820           tmp = gen_reg_rtx (mode);
44821           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44822                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44823           emit_insn (gen_avx512f_blendmv16si (target, tmp, target,
44824                                               force_reg (HImode, GEN_INT (1 << elt))));
44825           return;
44826         }
44827       else
44828         break;
44829     case V32HImode:
44830       if (TARGET_AVX512F && TARGET_AVX512BW)
44831         {
44832           tmp = gen_reg_rtx (mode);
44833           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44834                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44835           emit_insn (gen_avx512bw_blendmv32hi (target, tmp, target,
44836                                                force_reg (SImode, GEN_INT (1 << elt))));
44837           return;
44838         }
44839       else
44840         break;
44841     case V64QImode:
44842       if (TARGET_AVX512F && TARGET_AVX512BW)
44843         {
44844           tmp = gen_reg_rtx (mode);
44845           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44846                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44847           emit_insn (gen_avx512bw_blendmv64qi (target, tmp, target,
44848                                                force_reg (DImode, GEN_INT (1 << elt))));
44849           return;
44850         }
44851       else
44852         break;
44853
44854     default:
44855       break;
44856     }
44857
44858   if (use_vec_merge)
44859     {
44860       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
44861       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
44862       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44863     }
44864   else
44865     {
44866       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
44867
44868       emit_move_insn (mem, target);
44869
44870       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
44871       emit_move_insn (tmp, val);
44872
44873       emit_move_insn (target, mem);
44874     }
44875 }
44876
44877 void
44878 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
44879 {
44880   machine_mode mode = GET_MODE (vec);
44881   machine_mode inner_mode = GET_MODE_INNER (mode);
44882   bool use_vec_extr = false;
44883   rtx tmp;
44884
44885   switch (mode)
44886     {
44887     case V2SImode:
44888     case V2SFmode:
44889       if (!mmx_ok)
44890         break;
44891       /* FALLTHRU */
44892
44893     case V2DFmode:
44894     case V2DImode:
44895       use_vec_extr = true;
44896       break;
44897
44898     case V4SFmode:
44899       use_vec_extr = TARGET_SSE4_1;
44900       if (use_vec_extr)
44901         break;
44902
44903       switch (elt)
44904         {
44905         case 0:
44906           tmp = vec;
44907           break;
44908
44909         case 1:
44910         case 3:
44911           tmp = gen_reg_rtx (mode);
44912           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
44913                                        GEN_INT (elt), GEN_INT (elt),
44914                                        GEN_INT (elt+4), GEN_INT (elt+4)));
44915           break;
44916
44917         case 2:
44918           tmp = gen_reg_rtx (mode);
44919           emit_insn (gen_vec_interleave_highv4sf (tmp, vec, vec));
44920           break;
44921
44922         default:
44923           gcc_unreachable ();
44924         }
44925       vec = tmp;
44926       use_vec_extr = true;
44927       elt = 0;
44928       break;
44929
44930     case V4SImode:
44931       use_vec_extr = TARGET_SSE4_1;
44932       if (use_vec_extr)
44933         break;
44934
44935       if (TARGET_SSE2)
44936         {
44937           switch (elt)
44938             {
44939             case 0:
44940               tmp = vec;
44941               break;
44942
44943             case 1:
44944             case 3:
44945               tmp = gen_reg_rtx (mode);
44946               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
44947                                             GEN_INT (elt), GEN_INT (elt),
44948                                             GEN_INT (elt), GEN_INT (elt)));
44949               break;
44950
44951             case 2:
44952               tmp = gen_reg_rtx (mode);
44953               emit_insn (gen_vec_interleave_highv4si (tmp, vec, vec));
44954               break;
44955
44956             default:
44957               gcc_unreachable ();
44958             }
44959           vec = tmp;
44960           use_vec_extr = true;
44961           elt = 0;
44962         }
44963       else
44964         {
44965           /* For SSE1, we have to reuse the V4SF code.  */
44966           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
44967                                       gen_lowpart (V4SFmode, vec), elt);
44968           return;
44969         }
44970       break;
44971
44972     case V8HImode:
44973       use_vec_extr = TARGET_SSE2;
44974       break;
44975     case V4HImode:
44976       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
44977       break;
44978
44979     case V16QImode:
44980       use_vec_extr = TARGET_SSE4_1;
44981       break;
44982
44983     case V8SFmode:
44984       if (TARGET_AVX)
44985         {
44986           tmp = gen_reg_rtx (V4SFmode);
44987           if (elt < 4)
44988             emit_insn (gen_vec_extract_lo_v8sf (tmp, vec));
44989           else
44990             emit_insn (gen_vec_extract_hi_v8sf (tmp, vec));
44991           ix86_expand_vector_extract (false, target, tmp, elt & 3);
44992           return;
44993         }
44994       break;
44995
44996     case V4DFmode:
44997       if (TARGET_AVX)
44998         {
44999           tmp = gen_reg_rtx (V2DFmode);
45000           if (elt < 2)
45001             emit_insn (gen_vec_extract_lo_v4df (tmp, vec));
45002           else
45003             emit_insn (gen_vec_extract_hi_v4df (tmp, vec));
45004           ix86_expand_vector_extract (false, target, tmp, elt & 1);
45005           return;
45006         }
45007       break;
45008
45009     case V32QImode:
45010       if (TARGET_AVX)
45011         {
45012           tmp = gen_reg_rtx (V16QImode);
45013           if (elt < 16)
45014             emit_insn (gen_vec_extract_lo_v32qi (tmp, vec));
45015           else
45016             emit_insn (gen_vec_extract_hi_v32qi (tmp, vec));
45017           ix86_expand_vector_extract (false, target, tmp, elt & 15);
45018           return;
45019         }
45020       break;
45021
45022     case V16HImode:
45023       if (TARGET_AVX)
45024         {
45025           tmp = gen_reg_rtx (V8HImode);
45026           if (elt < 8)
45027             emit_insn (gen_vec_extract_lo_v16hi (tmp, vec));
45028           else
45029             emit_insn (gen_vec_extract_hi_v16hi (tmp, vec));
45030           ix86_expand_vector_extract (false, target, tmp, elt & 7);
45031           return;
45032         }
45033       break;
45034
45035     case V8SImode:
45036       if (TARGET_AVX)
45037         {
45038           tmp = gen_reg_rtx (V4SImode);
45039           if (elt < 4)
45040             emit_insn (gen_vec_extract_lo_v8si (tmp, vec));
45041           else
45042             emit_insn (gen_vec_extract_hi_v8si (tmp, vec));
45043           ix86_expand_vector_extract (false, target, tmp, elt & 3);
45044           return;
45045         }
45046       break;
45047
45048     case V4DImode:
45049       if (TARGET_AVX)
45050         {
45051           tmp = gen_reg_rtx (V2DImode);
45052           if (elt < 2)
45053             emit_insn (gen_vec_extract_lo_v4di (tmp, vec));
45054           else
45055             emit_insn (gen_vec_extract_hi_v4di (tmp, vec));
45056           ix86_expand_vector_extract (false, target, tmp, elt & 1);
45057           return;
45058         }
45059       break;
45060
45061     case V32HImode:
45062       if (TARGET_AVX512BW)
45063         {
45064           tmp = gen_reg_rtx (V16HImode);
45065           if (elt < 16)
45066             emit_insn (gen_vec_extract_lo_v32hi (tmp, vec));
45067           else
45068             emit_insn (gen_vec_extract_hi_v32hi (tmp, vec));
45069           ix86_expand_vector_extract (false, target, tmp, elt & 15);
45070           return;
45071         }
45072       break;
45073
45074     case V64QImode:
45075       if (TARGET_AVX512BW)
45076         {
45077           tmp = gen_reg_rtx (V32QImode);
45078           if (elt < 32)
45079             emit_insn (gen_vec_extract_lo_v64qi (tmp, vec));
45080           else
45081             emit_insn (gen_vec_extract_hi_v64qi (tmp, vec));
45082           ix86_expand_vector_extract (false, target, tmp, elt & 31);
45083           return;
45084         }
45085       break;
45086
45087     case V16SFmode:
45088       tmp = gen_reg_rtx (V8SFmode);
45089       if (elt < 8)
45090         emit_insn (gen_vec_extract_lo_v16sf (tmp, vec));
45091       else
45092         emit_insn (gen_vec_extract_hi_v16sf (tmp, vec));
45093       ix86_expand_vector_extract (false, target, tmp, elt & 7);
45094       return;
45095
45096     case V8DFmode:
45097       tmp = gen_reg_rtx (V4DFmode);
45098       if (elt < 4)
45099         emit_insn (gen_vec_extract_lo_v8df (tmp, vec));
45100       else
45101         emit_insn (gen_vec_extract_hi_v8df (tmp, vec));
45102       ix86_expand_vector_extract (false, target, tmp, elt & 3);
45103       return;
45104
45105     case V16SImode:
45106       tmp = gen_reg_rtx (V8SImode);
45107       if (elt < 8)
45108         emit_insn (gen_vec_extract_lo_v16si (tmp, vec));
45109       else
45110         emit_insn (gen_vec_extract_hi_v16si (tmp, vec));
45111       ix86_expand_vector_extract (false, target, tmp, elt & 7);
45112       return;
45113
45114     case V8DImode:
45115       tmp = gen_reg_rtx (V4DImode);
45116       if (elt < 4)
45117         emit_insn (gen_vec_extract_lo_v8di (tmp, vec));
45118       else
45119         emit_insn (gen_vec_extract_hi_v8di (tmp, vec));
45120       ix86_expand_vector_extract (false, target, tmp, elt & 3);
45121       return;
45122
45123     case V8QImode:
45124       /* ??? Could extract the appropriate HImode element and shift.  */
45125     default:
45126       break;
45127     }
45128
45129   if (use_vec_extr)
45130     {
45131       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
45132       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
45133
45134       /* Let the rtl optimizers know about the zero extension performed.  */
45135       if (inner_mode == QImode || inner_mode == HImode)
45136         {
45137           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
45138           target = gen_lowpart (SImode, target);
45139         }
45140
45141       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
45142     }
45143   else
45144     {
45145       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
45146
45147       emit_move_insn (mem, vec);
45148
45149       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
45150       emit_move_insn (target, tmp);
45151     }
45152 }
45153
45154 /* Generate code to copy vector bits i / 2 ... i - 1 from vector SRC
45155    to bits 0 ... i / 2 - 1 of vector DEST, which has the same mode.
45156    The upper bits of DEST are undefined, though they shouldn't cause
45157    exceptions (some bits from src or all zeros are ok).  */
45158
45159 static void
45160 emit_reduc_half (rtx dest, rtx src, int i)
45161 {
45162   rtx tem, d = dest;
45163   switch (GET_MODE (src))
45164     {
45165     case V4SFmode:
45166       if (i == 128)
45167         tem = gen_sse_movhlps (dest, src, src);
45168       else
45169         tem = gen_sse_shufps_v4sf (dest, src, src, const1_rtx, const1_rtx,
45170                                    GEN_INT (1 + 4), GEN_INT (1 + 4));
45171       break;
45172     case V2DFmode:
45173       tem = gen_vec_interleave_highv2df (dest, src, src);
45174       break;
45175     case V16QImode:
45176     case V8HImode:
45177     case V4SImode:
45178     case V2DImode:
45179       d = gen_reg_rtx (V1TImode);
45180       tem = gen_sse2_lshrv1ti3 (d, gen_lowpart (V1TImode, src),
45181                                 GEN_INT (i / 2));
45182       break;
45183     case V8SFmode:
45184       if (i == 256)
45185         tem = gen_avx_vperm2f128v8sf3 (dest, src, src, const1_rtx);
45186       else
45187         tem = gen_avx_shufps256 (dest, src, src,
45188                                  GEN_INT (i == 128 ? 2 + (3 << 2) : 1));
45189       break;
45190     case V4DFmode:
45191       if (i == 256)
45192         tem = gen_avx_vperm2f128v4df3 (dest, src, src, const1_rtx);
45193       else
45194         tem = gen_avx_shufpd256 (dest, src, src, const1_rtx);
45195       break;
45196     case V32QImode:
45197     case V16HImode:
45198     case V8SImode:
45199     case V4DImode:
45200       if (i == 256)
45201         {
45202           if (GET_MODE (dest) != V4DImode)
45203             d = gen_reg_rtx (V4DImode);
45204           tem = gen_avx2_permv2ti (d, gen_lowpart (V4DImode, src),
45205                                    gen_lowpart (V4DImode, src),
45206                                    const1_rtx);
45207         }
45208       else
45209         {
45210           d = gen_reg_rtx (V2TImode);
45211           tem = gen_avx2_lshrv2ti3 (d, gen_lowpart (V2TImode, src),
45212                                     GEN_INT (i / 2));
45213         }
45214       break;
45215     case V64QImode:
45216     case V32HImode:
45217     case V16SImode:
45218     case V16SFmode:
45219     case V8DImode:
45220     case V8DFmode:
45221       if (i > 128)
45222         tem = gen_avx512f_shuf_i32x4_1 (gen_lowpart (V16SImode, dest),
45223                                       gen_lowpart (V16SImode, src),
45224                                       gen_lowpart (V16SImode, src),
45225                                       GEN_INT (0x4 + (i == 512 ? 4 : 0)),
45226                                       GEN_INT (0x5 + (i == 512 ? 4 : 0)),
45227                                       GEN_INT (0x6 + (i == 512 ? 4 : 0)),
45228                                       GEN_INT (0x7 + (i == 512 ? 4 : 0)),
45229                                       GEN_INT (0xC), GEN_INT (0xD),
45230                                       GEN_INT (0xE), GEN_INT (0xF),
45231                                       GEN_INT (0x10), GEN_INT (0x11),
45232                                       GEN_INT (0x12), GEN_INT (0x13),
45233                                       GEN_INT (0x14), GEN_INT (0x15),
45234                                       GEN_INT (0x16), GEN_INT (0x17));
45235       else
45236         tem = gen_avx512f_pshufd_1 (gen_lowpart (V16SImode, dest),
45237                                    gen_lowpart (V16SImode, src),
45238                                    GEN_INT (i == 128 ? 0x2 : 0x1),
45239                                    GEN_INT (0x3),
45240                                    GEN_INT (0x3),
45241                                    GEN_INT (0x3),
45242                                    GEN_INT (i == 128 ? 0x6 : 0x5),
45243                                    GEN_INT (0x7),
45244                                    GEN_INT (0x7),
45245                                    GEN_INT (0x7),
45246                                    GEN_INT (i == 128 ? 0xA : 0x9),
45247                                    GEN_INT (0xB),
45248                                    GEN_INT (0xB),
45249                                    GEN_INT (0xB),
45250                                    GEN_INT (i == 128 ? 0xE : 0xD),
45251                                    GEN_INT (0xF),
45252                                    GEN_INT (0xF),
45253                                    GEN_INT (0xF));
45254       break;
45255     default:
45256       gcc_unreachable ();
45257     }
45258   emit_insn (tem);
45259   if (d != dest)
45260     emit_move_insn (dest, gen_lowpart (GET_MODE (dest), d));
45261 }
45262
45263 /* Expand a vector reduction.  FN is the binary pattern to reduce;
45264    DEST is the destination; IN is the input vector.  */
45265
45266 void
45267 ix86_expand_reduc (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
45268 {
45269   rtx half, dst, vec = in;
45270   machine_mode mode = GET_MODE (in);
45271   int i;
45272
45273   /* SSE4 has a special instruction for V8HImode UMIN reduction.  */
45274   if (TARGET_SSE4_1
45275       && mode == V8HImode
45276       && fn == gen_uminv8hi3)
45277     {
45278       emit_insn (gen_sse4_1_phminposuw (dest, in));
45279       return;
45280     }
45281
45282   for (i = GET_MODE_BITSIZE (mode);
45283        i > GET_MODE_BITSIZE (GET_MODE_INNER (mode));
45284        i >>= 1)
45285     {
45286       half = gen_reg_rtx (mode);
45287       emit_reduc_half (half, vec, i);
45288       if (i == GET_MODE_BITSIZE (GET_MODE_INNER (mode)) * 2)
45289         dst = dest;
45290       else
45291         dst = gen_reg_rtx (mode);
45292       emit_insn (fn (dst, half, vec));
45293       vec = dst;
45294     }
45295 }
45296 \f
45297 /* Target hook for scalar_mode_supported_p.  */
45298 static bool
45299 ix86_scalar_mode_supported_p (machine_mode mode)
45300 {
45301   if (DECIMAL_FLOAT_MODE_P (mode))
45302     return default_decimal_float_supported_p ();
45303   else if (mode == TFmode)
45304     return true;
45305   else
45306     return default_scalar_mode_supported_p (mode);
45307 }
45308
45309 /* Implements target hook vector_mode_supported_p.  */
45310 static bool
45311 ix86_vector_mode_supported_p (machine_mode mode)
45312 {
45313   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
45314     return true;
45315   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
45316     return true;
45317   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
45318     return true;
45319   if (TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
45320     return true;
45321   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
45322     return true;
45323   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
45324     return true;
45325   return false;
45326 }
45327
45328 /* Implement target hook libgcc_floating_mode_supported_p.  */
45329 static bool
45330 ix86_libgcc_floating_mode_supported_p (machine_mode mode)
45331 {
45332   switch (mode)
45333     {
45334     case SFmode:
45335     case DFmode:
45336     case XFmode:
45337       return true;
45338
45339     case TFmode:
45340 #ifdef IX86_NO_LIBGCC_TFMODE
45341       return false;
45342 #elif defined IX86_MAYBE_NO_LIBGCC_TFMODE
45343       return TARGET_LONG_DOUBLE_128;
45344 #else
45345       return true;
45346 #endif
45347
45348     default:
45349       return false;
45350     }
45351 }
45352
45353 /* Target hook for c_mode_for_suffix.  */
45354 static machine_mode
45355 ix86_c_mode_for_suffix (char suffix)
45356 {
45357   if (suffix == 'q')
45358     return TFmode;
45359   if (suffix == 'w')
45360     return XFmode;
45361
45362   return VOIDmode;
45363 }
45364
45365 /* Worker function for TARGET_MD_ASM_CLOBBERS.
45366
45367    We do this in the new i386 backend to maintain source compatibility
45368    with the old cc0-based compiler.  */
45369
45370 static tree
45371 ix86_md_asm_clobbers (tree, tree, tree clobbers)
45372 {
45373   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
45374                         clobbers);
45375   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
45376                         clobbers);
45377   return clobbers;
45378 }
45379
45380 /* Implements target vector targetm.asm.encode_section_info.  */
45381
45382 static void ATTRIBUTE_UNUSED
45383 ix86_encode_section_info (tree decl, rtx rtl, int first)
45384 {
45385   default_encode_section_info (decl, rtl, first);
45386
45387   if (ix86_in_large_data_p (decl))
45388     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
45389 }
45390
45391 /* Worker function for REVERSE_CONDITION.  */
45392
45393 enum rtx_code
45394 ix86_reverse_condition (enum rtx_code code, machine_mode mode)
45395 {
45396   return (mode != CCFPmode && mode != CCFPUmode
45397           ? reverse_condition (code)
45398           : reverse_condition_maybe_unordered (code));
45399 }
45400
45401 /* Output code to perform an x87 FP register move, from OPERANDS[1]
45402    to OPERANDS[0].  */
45403
45404 const char *
45405 output_387_reg_move (rtx insn, rtx *operands)
45406 {
45407   if (REG_P (operands[0]))
45408     {
45409       if (REG_P (operands[1])
45410           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
45411         {
45412           if (REGNO (operands[0]) == FIRST_STACK_REG)
45413             return output_387_ffreep (operands, 0);
45414           return "fstp\t%y0";
45415         }
45416       if (STACK_TOP_P (operands[0]))
45417         return "fld%Z1\t%y1";
45418       return "fst\t%y0";
45419     }
45420   else if (MEM_P (operands[0]))
45421     {
45422       gcc_assert (REG_P (operands[1]));
45423       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
45424         return "fstp%Z0\t%y0";
45425       else
45426         {
45427           /* There is no non-popping store to memory for XFmode.
45428              So if we need one, follow the store with a load.  */
45429           if (GET_MODE (operands[0]) == XFmode)
45430             return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
45431           else
45432             return "fst%Z0\t%y0";
45433         }
45434     }
45435   else
45436     gcc_unreachable();
45437 }
45438
45439 /* Output code to perform a conditional jump to LABEL, if C2 flag in
45440    FP status register is set.  */
45441
45442 void
45443 ix86_emit_fp_unordered_jump (rtx label)
45444 {
45445   rtx reg = gen_reg_rtx (HImode);
45446   rtx temp;
45447
45448   emit_insn (gen_x86_fnstsw_1 (reg));
45449
45450   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
45451     {
45452       emit_insn (gen_x86_sahf_1 (reg));
45453
45454       temp = gen_rtx_REG (CCmode, FLAGS_REG);
45455       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
45456     }
45457   else
45458     {
45459       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
45460
45461       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
45462       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
45463     }
45464
45465   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
45466                               gen_rtx_LABEL_REF (VOIDmode, label),
45467                               pc_rtx);
45468   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
45469
45470   emit_jump_insn (temp);
45471   predict_jump (REG_BR_PROB_BASE * 10 / 100);
45472 }
45473
45474 /* Output code to perform a log1p XFmode calculation.  */
45475
45476 void ix86_emit_i387_log1p (rtx op0, rtx op1)
45477 {
45478   rtx_code_label *label1 = gen_label_rtx ();
45479   rtx_code_label *label2 = gen_label_rtx ();
45480
45481   rtx tmp = gen_reg_rtx (XFmode);
45482   rtx tmp2 = gen_reg_rtx (XFmode);
45483   rtx test;
45484
45485   emit_insn (gen_absxf2 (tmp, op1));
45486   test = gen_rtx_GE (VOIDmode, tmp,
45487     CONST_DOUBLE_FROM_REAL_VALUE (
45488        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
45489        XFmode));
45490   emit_jump_insn (gen_cbranchxf4 (test, XEXP (test, 0), XEXP (test, 1), label1));
45491
45492   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
45493   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
45494   emit_jump (label2);
45495
45496   emit_label (label1);
45497   emit_move_insn (tmp, CONST1_RTX (XFmode));
45498   emit_insn (gen_addxf3 (tmp, op1, tmp));
45499   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
45500   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
45501
45502   emit_label (label2);
45503 }
45504
45505 /* Emit code for round calculation.  */
45506 void ix86_emit_i387_round (rtx op0, rtx op1)
45507 {
45508   machine_mode inmode = GET_MODE (op1);
45509   machine_mode outmode = GET_MODE (op0);
45510   rtx e1, e2, res, tmp, tmp1, half;
45511   rtx scratch = gen_reg_rtx (HImode);
45512   rtx flags = gen_rtx_REG (CCNOmode, FLAGS_REG);
45513   rtx_code_label *jump_label = gen_label_rtx ();
45514   rtx insn;
45515   rtx (*gen_abs) (rtx, rtx);
45516   rtx (*gen_neg) (rtx, rtx);
45517
45518   switch (inmode)
45519     {
45520     case SFmode:
45521       gen_abs = gen_abssf2;
45522       break;
45523     case DFmode:
45524       gen_abs = gen_absdf2;
45525       break;
45526     case XFmode:
45527       gen_abs = gen_absxf2;
45528       break;
45529     default:
45530       gcc_unreachable ();
45531     }
45532
45533   switch (outmode)
45534     {
45535     case SFmode:
45536       gen_neg = gen_negsf2;
45537       break;
45538     case DFmode:
45539       gen_neg = gen_negdf2;
45540       break;
45541     case XFmode:
45542       gen_neg = gen_negxf2;
45543       break;
45544     case HImode:
45545       gen_neg = gen_neghi2;
45546       break;
45547     case SImode:
45548       gen_neg = gen_negsi2;
45549       break;
45550     case DImode:
45551       gen_neg = gen_negdi2;
45552       break;
45553     default:
45554       gcc_unreachable ();
45555     }
45556
45557   e1 = gen_reg_rtx (inmode);
45558   e2 = gen_reg_rtx (inmode);
45559   res = gen_reg_rtx (outmode);
45560
45561   half = CONST_DOUBLE_FROM_REAL_VALUE (dconsthalf, inmode);
45562
45563   /* round(a) = sgn(a) * floor(fabs(a) + 0.5) */
45564
45565   /* scratch = fxam(op1) */
45566   emit_insn (gen_rtx_SET (VOIDmode, scratch,
45567                           gen_rtx_UNSPEC (HImode, gen_rtvec (1, op1),
45568                                           UNSPEC_FXAM)));
45569   /* e1 = fabs(op1) */
45570   emit_insn (gen_abs (e1, op1));
45571
45572   /* e2 = e1 + 0.5 */
45573   half = force_reg (inmode, half);
45574   emit_insn (gen_rtx_SET (VOIDmode, e2,
45575                           gen_rtx_PLUS (inmode, e1, half)));
45576
45577   /* res = floor(e2) */
45578   if (inmode != XFmode)
45579     {
45580       tmp1 = gen_reg_rtx (XFmode);
45581
45582       emit_insn (gen_rtx_SET (VOIDmode, tmp1,
45583                               gen_rtx_FLOAT_EXTEND (XFmode, e2)));
45584     }
45585   else
45586     tmp1 = e2;
45587
45588   switch (outmode)
45589     {
45590     case SFmode:
45591     case DFmode:
45592       {
45593         rtx tmp0 = gen_reg_rtx (XFmode);
45594
45595         emit_insn (gen_frndintxf2_floor (tmp0, tmp1));
45596
45597         emit_insn (gen_rtx_SET (VOIDmode, res,
45598                                 gen_rtx_UNSPEC (outmode, gen_rtvec (1, tmp0),
45599                                                 UNSPEC_TRUNC_NOOP)));
45600       }
45601       break;
45602     case XFmode:
45603       emit_insn (gen_frndintxf2_floor (res, tmp1));
45604       break;
45605     case HImode:
45606       emit_insn (gen_lfloorxfhi2 (res, tmp1));
45607       break;
45608     case SImode:
45609       emit_insn (gen_lfloorxfsi2 (res, tmp1));
45610       break;
45611     case DImode:
45612       emit_insn (gen_lfloorxfdi2 (res, tmp1));
45613         break;
45614     default:
45615       gcc_unreachable ();
45616     }
45617
45618   /* flags = signbit(a) */
45619   emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x02)));
45620
45621   /* if (flags) then res = -res */
45622   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
45623                               gen_rtx_EQ (VOIDmode, flags, const0_rtx),
45624                               gen_rtx_LABEL_REF (VOIDmode, jump_label),
45625                               pc_rtx);
45626   insn = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
45627   predict_jump (REG_BR_PROB_BASE * 50 / 100);
45628   JUMP_LABEL (insn) = jump_label;
45629
45630   emit_insn (gen_neg (res, res));
45631
45632   emit_label (jump_label);
45633   LABEL_NUSES (jump_label) = 1;
45634
45635   emit_move_insn (op0, res);
45636 }
45637
45638 /* Output code to perform a Newton-Rhapson approximation of a single precision
45639    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
45640
45641 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, machine_mode mode)
45642 {
45643   rtx x0, x1, e0, e1;
45644
45645   x0 = gen_reg_rtx (mode);
45646   e0 = gen_reg_rtx (mode);
45647   e1 = gen_reg_rtx (mode);
45648   x1 = gen_reg_rtx (mode);
45649
45650   /* a / b = a * ((rcp(b) + rcp(b)) - (b * rcp(b) * rcp (b))) */
45651
45652   b = force_reg (mode, b);
45653
45654   /* x0 = rcp(b) estimate */
45655   if (mode == V16SFmode || mode == V8DFmode)
45656     emit_insn (gen_rtx_SET (VOIDmode, x0,
45657                             gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
45658                                             UNSPEC_RCP14)));
45659   else
45660     emit_insn (gen_rtx_SET (VOIDmode, x0,
45661                             gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
45662                                             UNSPEC_RCP)));
45663
45664   /* e0 = x0 * b */
45665   emit_insn (gen_rtx_SET (VOIDmode, e0,
45666                           gen_rtx_MULT (mode, x0, b)));
45667
45668   /* e0 = x0 * e0 */
45669   emit_insn (gen_rtx_SET (VOIDmode, e0,
45670                           gen_rtx_MULT (mode, x0, e0)));
45671
45672   /* e1 = x0 + x0 */
45673   emit_insn (gen_rtx_SET (VOIDmode, e1,
45674                           gen_rtx_PLUS (mode, x0, x0)));
45675
45676   /* x1 = e1 - e0 */
45677   emit_insn (gen_rtx_SET (VOIDmode, x1,
45678                           gen_rtx_MINUS (mode, e1, e0)));
45679
45680   /* res = a * x1 */
45681   emit_insn (gen_rtx_SET (VOIDmode, res,
45682                           gen_rtx_MULT (mode, a, x1)));
45683 }
45684
45685 /* Output code to perform a Newton-Rhapson approximation of a
45686    single precision floating point [reciprocal] square root.  */
45687
45688 void ix86_emit_swsqrtsf (rtx res, rtx a, machine_mode mode,
45689                          bool recip)
45690 {
45691   rtx x0, e0, e1, e2, e3, mthree, mhalf;
45692   REAL_VALUE_TYPE r;
45693   int unspec;
45694
45695   x0 = gen_reg_rtx (mode);
45696   e0 = gen_reg_rtx (mode);
45697   e1 = gen_reg_rtx (mode);
45698   e2 = gen_reg_rtx (mode);
45699   e3 = gen_reg_rtx (mode);
45700
45701   real_from_integer (&r, VOIDmode, -3, SIGNED);
45702   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
45703
45704   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
45705   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
45706   unspec = UNSPEC_RSQRT;
45707
45708   if (VECTOR_MODE_P (mode))
45709     {
45710       mthree = ix86_build_const_vector (mode, true, mthree);
45711       mhalf = ix86_build_const_vector (mode, true, mhalf);
45712       /* There is no 512-bit rsqrt.  There is however rsqrt14.  */
45713       if (GET_MODE_SIZE (mode) == 64)
45714         unspec = UNSPEC_RSQRT14;
45715     }
45716
45717   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
45718      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
45719
45720   a = force_reg (mode, a);
45721
45722   /* x0 = rsqrt(a) estimate */
45723   emit_insn (gen_rtx_SET (VOIDmode, x0,
45724                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
45725                                           unspec)));
45726
45727   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
45728   if (!recip)
45729     {
45730       rtx zero, mask;
45731
45732       zero = gen_reg_rtx (mode);
45733       mask = gen_reg_rtx (mode);
45734
45735       zero = force_reg (mode, CONST0_RTX(mode));
45736
45737       /* Handle masked compare.  */
45738       if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
45739         {
45740           mask = gen_reg_rtx (HImode);
45741           /* Imm value 0x4 corresponds to not-equal comparison.  */
45742           emit_insn (gen_avx512f_cmpv16sf3 (mask, zero, a, GEN_INT (0x4)));
45743           emit_insn (gen_avx512f_blendmv16sf (x0, zero, x0, mask));
45744         }
45745       else
45746         {
45747           emit_insn (gen_rtx_SET (VOIDmode, mask,
45748                                   gen_rtx_NE (mode, zero, a)));
45749
45750           emit_insn (gen_rtx_SET (VOIDmode, x0,
45751                                   gen_rtx_AND (mode, x0, mask)));
45752         }
45753     }
45754
45755   /* e0 = x0 * a */
45756   emit_insn (gen_rtx_SET (VOIDmode, e0,
45757                           gen_rtx_MULT (mode, x0, a)));
45758   /* e1 = e0 * x0 */
45759   emit_insn (gen_rtx_SET (VOIDmode, e1,
45760                           gen_rtx_MULT (mode, e0, x0)));
45761
45762   /* e2 = e1 - 3. */
45763   mthree = force_reg (mode, mthree);
45764   emit_insn (gen_rtx_SET (VOIDmode, e2,
45765                           gen_rtx_PLUS (mode, e1, mthree)));
45766
45767   mhalf = force_reg (mode, mhalf);
45768   if (recip)
45769     /* e3 = -.5 * x0 */
45770     emit_insn (gen_rtx_SET (VOIDmode, e3,
45771                             gen_rtx_MULT (mode, x0, mhalf)));
45772   else
45773     /* e3 = -.5 * e0 */
45774     emit_insn (gen_rtx_SET (VOIDmode, e3,
45775                             gen_rtx_MULT (mode, e0, mhalf)));
45776   /* ret = e2 * e3 */
45777   emit_insn (gen_rtx_SET (VOIDmode, res,
45778                           gen_rtx_MULT (mode, e2, e3)));
45779 }
45780
45781 #ifdef TARGET_SOLARIS
45782 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
45783
45784 static void
45785 i386_solaris_elf_named_section (const char *name, unsigned int flags,
45786                                 tree decl)
45787 {
45788   /* With Binutils 2.15, the "@unwind" marker must be specified on
45789      every occurrence of the ".eh_frame" section, not just the first
45790      one.  */
45791   if (TARGET_64BIT
45792       && strcmp (name, ".eh_frame") == 0)
45793     {
45794       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
45795                flags & SECTION_WRITE ? "aw" : "a");
45796       return;
45797     }
45798
45799 #ifndef USE_GAS
45800   if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
45801     {
45802       solaris_elf_asm_comdat_section (name, flags, decl);
45803       return;
45804     }
45805 #endif
45806
45807   default_elf_asm_named_section (name, flags, decl);
45808 }
45809 #endif /* TARGET_SOLARIS */
45810
45811 /* Return the mangling of TYPE if it is an extended fundamental type.  */
45812
45813 static const char *
45814 ix86_mangle_type (const_tree type)
45815 {
45816   type = TYPE_MAIN_VARIANT (type);
45817
45818   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
45819       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
45820     return NULL;
45821
45822   switch (TYPE_MODE (type))
45823     {
45824     case TFmode:
45825       /* __float128 is "g".  */
45826       return "g";
45827     case XFmode:
45828       /* "long double" or __float80 is "e".  */
45829       return "e";
45830     default:
45831       return NULL;
45832     }
45833 }
45834
45835 /* For 32-bit code we can save PIC register setup by using
45836    __stack_chk_fail_local hidden function instead of calling
45837    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
45838    register, so it is better to call __stack_chk_fail directly.  */
45839
45840 static tree ATTRIBUTE_UNUSED
45841 ix86_stack_protect_fail (void)
45842 {
45843   return TARGET_64BIT
45844          ? default_external_stack_protect_fail ()
45845          : default_hidden_stack_protect_fail ();
45846 }
45847
45848 /* Select a format to encode pointers in exception handling data.  CODE
45849    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
45850    true if the symbol may be affected by dynamic relocations.
45851
45852    ??? All x86 object file formats are capable of representing this.
45853    After all, the relocation needed is the same as for the call insn.
45854    Whether or not a particular assembler allows us to enter such, I
45855    guess we'll have to see.  */
45856 int
45857 asm_preferred_eh_data_format (int code, int global)
45858 {
45859   if (flag_pic)
45860     {
45861       int type = DW_EH_PE_sdata8;
45862       if (!TARGET_64BIT
45863           || ix86_cmodel == CM_SMALL_PIC
45864           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
45865         type = DW_EH_PE_sdata4;
45866       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
45867     }
45868   if (ix86_cmodel == CM_SMALL
45869       || (ix86_cmodel == CM_MEDIUM && code))
45870     return DW_EH_PE_udata4;
45871   return DW_EH_PE_absptr;
45872 }
45873 \f
45874 /* Expand copysign from SIGN to the positive value ABS_VALUE
45875    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
45876    the sign-bit.  */
45877 static void
45878 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
45879 {
45880   machine_mode mode = GET_MODE (sign);
45881   rtx sgn = gen_reg_rtx (mode);
45882   if (mask == NULL_RTX)
45883     {
45884       machine_mode vmode;
45885
45886       if (mode == SFmode)
45887         vmode = V4SFmode;
45888       else if (mode == DFmode)
45889         vmode = V2DFmode;
45890       else
45891         vmode = mode;
45892
45893       mask = ix86_build_signbit_mask (vmode, VECTOR_MODE_P (mode), false);
45894       if (!VECTOR_MODE_P (mode))
45895         {
45896           /* We need to generate a scalar mode mask in this case.  */
45897           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
45898           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
45899           mask = gen_reg_rtx (mode);
45900           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
45901         }
45902     }
45903   else
45904     mask = gen_rtx_NOT (mode, mask);
45905   emit_insn (gen_rtx_SET (VOIDmode, sgn,
45906                           gen_rtx_AND (mode, mask, sign)));
45907   emit_insn (gen_rtx_SET (VOIDmode, result,
45908                           gen_rtx_IOR (mode, abs_value, sgn)));
45909 }
45910
45911 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
45912    mask for masking out the sign-bit is stored in *SMASK, if that is
45913    non-null.  */
45914 static rtx
45915 ix86_expand_sse_fabs (rtx op0, rtx *smask)
45916 {
45917   machine_mode vmode, mode = GET_MODE (op0);
45918   rtx xa, mask;
45919
45920   xa = gen_reg_rtx (mode);
45921   if (mode == SFmode)
45922     vmode = V4SFmode;
45923   else if (mode == DFmode)
45924     vmode = V2DFmode;
45925   else
45926     vmode = mode;
45927   mask = ix86_build_signbit_mask (vmode, VECTOR_MODE_P (mode), true);
45928   if (!VECTOR_MODE_P (mode))
45929     {
45930       /* We need to generate a scalar mode mask in this case.  */
45931       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
45932       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
45933       mask = gen_reg_rtx (mode);
45934       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
45935     }
45936   emit_insn (gen_rtx_SET (VOIDmode, xa,
45937                           gen_rtx_AND (mode, op0, mask)));
45938
45939   if (smask)
45940     *smask = mask;
45941
45942   return xa;
45943 }
45944
45945 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
45946    swapping the operands if SWAP_OPERANDS is true.  The expanded
45947    code is a forward jump to a newly created label in case the
45948    comparison is true.  The generated label rtx is returned.  */
45949 static rtx_code_label *
45950 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
45951                                   bool swap_operands)
45952 {
45953   machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
45954   rtx_code_label *label;
45955   rtx tmp;
45956
45957   if (swap_operands)
45958     std::swap (op0, op1);
45959
45960   label = gen_label_rtx ();
45961   tmp = gen_rtx_REG (fpcmp_mode, FLAGS_REG);
45962   emit_insn (gen_rtx_SET (VOIDmode, tmp,
45963                           gen_rtx_COMPARE (fpcmp_mode, op0, op1)));
45964   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
45965   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
45966                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
45967   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
45968   JUMP_LABEL (tmp) = label;
45969
45970   return label;
45971 }
45972
45973 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
45974    using comparison code CODE.  Operands are swapped for the comparison if
45975    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
45976 static rtx
45977 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
45978                               bool swap_operands)
45979 {
45980   rtx (*insn)(rtx, rtx, rtx, rtx);
45981   machine_mode mode = GET_MODE (op0);
45982   rtx mask = gen_reg_rtx (mode);
45983
45984   if (swap_operands)
45985     std::swap (op0, op1);
45986
45987   insn = mode == DFmode ? gen_setcc_df_sse : gen_setcc_sf_sse;
45988
45989   emit_insn (insn (mask, op0, op1,
45990                    gen_rtx_fmt_ee (code, mode, op0, op1)));
45991   return mask;
45992 }
45993
45994 /* Generate and return a rtx of mode MODE for 2**n where n is the number
45995    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
45996 static rtx
45997 ix86_gen_TWO52 (machine_mode mode)
45998 {
45999   REAL_VALUE_TYPE TWO52r;
46000   rtx TWO52;
46001
46002   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
46003   TWO52 = const_double_from_real_value (TWO52r, mode);
46004   TWO52 = force_reg (mode, TWO52);
46005
46006   return TWO52;
46007 }
46008
46009 /* Expand SSE sequence for computing lround from OP1 storing
46010    into OP0.  */
46011 void
46012 ix86_expand_lround (rtx op0, rtx op1)
46013 {
46014   /* C code for the stuff we're doing below:
46015        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
46016        return (long)tmp;
46017    */
46018   machine_mode mode = GET_MODE (op1);
46019   const struct real_format *fmt;
46020   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46021   rtx adj;
46022
46023   /* load nextafter (0.5, 0.0) */
46024   fmt = REAL_MODE_FORMAT (mode);
46025   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46026   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46027
46028   /* adj = copysign (0.5, op1) */
46029   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
46030   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
46031
46032   /* adj = op1 + adj */
46033   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
46034
46035   /* op0 = (imode)adj */
46036   expand_fix (op0, adj, 0);
46037 }
46038
46039 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
46040    into OPERAND0.  */
46041 void
46042 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
46043 {
46044   /* C code for the stuff we're doing below (for do_floor):
46045         xi = (long)op1;
46046         xi -= (double)xi > op1 ? 1 : 0;
46047         return xi;
46048    */
46049   machine_mode fmode = GET_MODE (op1);
46050   machine_mode imode = GET_MODE (op0);
46051   rtx ireg, freg, tmp;
46052   rtx_code_label *label;
46053
46054   /* reg = (long)op1 */
46055   ireg = gen_reg_rtx (imode);
46056   expand_fix (ireg, op1, 0);
46057
46058   /* freg = (double)reg */
46059   freg = gen_reg_rtx (fmode);
46060   expand_float (freg, ireg, 0);
46061
46062   /* ireg = (freg > op1) ? ireg - 1 : ireg */
46063   label = ix86_expand_sse_compare_and_jump (UNLE,
46064                                             freg, op1, !do_floor);
46065   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
46066                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
46067   emit_move_insn (ireg, tmp);
46068
46069   emit_label (label);
46070   LABEL_NUSES (label) = 1;
46071
46072   emit_move_insn (op0, ireg);
46073 }
46074
46075 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
46076    result in OPERAND0.  */
46077 void
46078 ix86_expand_rint (rtx operand0, rtx operand1)
46079 {
46080   /* C code for the stuff we're doing below:
46081         xa = fabs (operand1);
46082         if (!isless (xa, 2**52))
46083           return operand1;
46084         xa = xa + 2**52 - 2**52;
46085         return copysign (xa, operand1);
46086    */
46087   machine_mode mode = GET_MODE (operand0);
46088   rtx res, xa, TWO52, mask;
46089   rtx_code_label *label;
46090
46091   res = gen_reg_rtx (mode);
46092   emit_move_insn (res, operand1);
46093
46094   /* xa = abs (operand1) */
46095   xa = ix86_expand_sse_fabs (res, &mask);
46096
46097   /* if (!isless (xa, TWO52)) goto label; */
46098   TWO52 = ix86_gen_TWO52 (mode);
46099   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46100
46101   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46102   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
46103
46104   ix86_sse_copysign_to_positive (res, xa, res, mask);
46105
46106   emit_label (label);
46107   LABEL_NUSES (label) = 1;
46108
46109   emit_move_insn (operand0, res);
46110 }
46111
46112 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
46113    into OPERAND0.  */
46114 void
46115 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
46116 {
46117   /* C code for the stuff we expand below.
46118         double xa = fabs (x), x2;
46119         if (!isless (xa, TWO52))
46120           return x;
46121         xa = xa + TWO52 - TWO52;
46122         x2 = copysign (xa, x);
46123      Compensate.  Floor:
46124         if (x2 > x)
46125           x2 -= 1;
46126      Compensate.  Ceil:
46127         if (x2 < x)
46128           x2 -= -1;
46129         return x2;
46130    */
46131   machine_mode mode = GET_MODE (operand0);
46132   rtx xa, TWO52, tmp, one, res, mask;
46133   rtx_code_label *label;
46134
46135   TWO52 = ix86_gen_TWO52 (mode);
46136
46137   /* Temporary for holding the result, initialized to the input
46138      operand to ease control flow.  */
46139   res = gen_reg_rtx (mode);
46140   emit_move_insn (res, operand1);
46141
46142   /* xa = abs (operand1) */
46143   xa = ix86_expand_sse_fabs (res, &mask);
46144
46145   /* if (!isless (xa, TWO52)) goto label; */
46146   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46147
46148   /* xa = xa + TWO52 - TWO52; */
46149   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46150   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
46151
46152   /* xa = copysign (xa, operand1) */
46153   ix86_sse_copysign_to_positive (xa, xa, res, mask);
46154
46155   /* generate 1.0 or -1.0 */
46156   one = force_reg (mode,
46157                    const_double_from_real_value (do_floor
46158                                                  ? dconst1 : dconstm1, mode));
46159
46160   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
46161   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
46162   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46163                           gen_rtx_AND (mode, one, tmp)));
46164   /* We always need to subtract here to preserve signed zero.  */
46165   tmp = expand_simple_binop (mode, MINUS,
46166                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46167   emit_move_insn (res, tmp);
46168
46169   emit_label (label);
46170   LABEL_NUSES (label) = 1;
46171
46172   emit_move_insn (operand0, res);
46173 }
46174
46175 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
46176    into OPERAND0.  */
46177 void
46178 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
46179 {
46180   /* C code for the stuff we expand below.
46181         double xa = fabs (x), x2;
46182         if (!isless (xa, TWO52))
46183           return x;
46184         x2 = (double)(long)x;
46185      Compensate.  Floor:
46186         if (x2 > x)
46187           x2 -= 1;
46188      Compensate.  Ceil:
46189         if (x2 < x)
46190           x2 += 1;
46191         if (HONOR_SIGNED_ZEROS (mode))
46192           return copysign (x2, x);
46193         return x2;
46194    */
46195   machine_mode mode = GET_MODE (operand0);
46196   rtx xa, xi, TWO52, tmp, one, res, mask;
46197   rtx_code_label *label;
46198
46199   TWO52 = ix86_gen_TWO52 (mode);
46200
46201   /* Temporary for holding the result, initialized to the input
46202      operand to ease control flow.  */
46203   res = gen_reg_rtx (mode);
46204   emit_move_insn (res, operand1);
46205
46206   /* xa = abs (operand1) */
46207   xa = ix86_expand_sse_fabs (res, &mask);
46208
46209   /* if (!isless (xa, TWO52)) goto label; */
46210   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46211
46212   /* xa = (double)(long)x */
46213   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46214   expand_fix (xi, res, 0);
46215   expand_float (xa, xi, 0);
46216
46217   /* generate 1.0 */
46218   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
46219
46220   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
46221   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
46222   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46223                           gen_rtx_AND (mode, one, tmp)));
46224   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
46225                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46226   emit_move_insn (res, tmp);
46227
46228   if (HONOR_SIGNED_ZEROS (mode))
46229     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
46230
46231   emit_label (label);
46232   LABEL_NUSES (label) = 1;
46233
46234   emit_move_insn (operand0, res);
46235 }
46236
46237 /* Expand SSE sequence for computing round from OPERAND1 storing
46238    into OPERAND0.  Sequence that works without relying on DImode truncation
46239    via cvttsd2siq that is only available on 64bit targets.  */
46240 void
46241 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
46242 {
46243   /* C code for the stuff we expand below.
46244         double xa = fabs (x), xa2, x2;
46245         if (!isless (xa, TWO52))
46246           return x;
46247      Using the absolute value and copying back sign makes
46248      -0.0 -> -0.0 correct.
46249         xa2 = xa + TWO52 - TWO52;
46250      Compensate.
46251         dxa = xa2 - xa;
46252         if (dxa <= -0.5)
46253           xa2 += 1;
46254         else if (dxa > 0.5)
46255           xa2 -= 1;
46256         x2 = copysign (xa2, x);
46257         return x2;
46258    */
46259   machine_mode mode = GET_MODE (operand0);
46260   rtx xa, xa2, dxa, TWO52, tmp, half, mhalf, one, res, mask;
46261   rtx_code_label *label;
46262
46263   TWO52 = ix86_gen_TWO52 (mode);
46264
46265   /* Temporary for holding the result, initialized to the input
46266      operand to ease control flow.  */
46267   res = gen_reg_rtx (mode);
46268   emit_move_insn (res, operand1);
46269
46270   /* xa = abs (operand1) */
46271   xa = ix86_expand_sse_fabs (res, &mask);
46272
46273   /* if (!isless (xa, TWO52)) goto label; */
46274   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46275
46276   /* xa2 = xa + TWO52 - TWO52; */
46277   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46278   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
46279
46280   /* dxa = xa2 - xa; */
46281   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
46282
46283   /* generate 0.5, 1.0 and -0.5 */
46284   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
46285   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
46286   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
46287                                0, OPTAB_DIRECT);
46288
46289   /* Compensate.  */
46290   tmp = gen_reg_rtx (mode);
46291   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
46292   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
46293   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46294                           gen_rtx_AND (mode, one, tmp)));
46295   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46296   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
46297   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
46298   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46299                           gen_rtx_AND (mode, one, tmp)));
46300   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46301
46302   /* res = copysign (xa2, operand1) */
46303   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
46304
46305   emit_label (label);
46306   LABEL_NUSES (label) = 1;
46307
46308   emit_move_insn (operand0, res);
46309 }
46310
46311 /* Expand SSE sequence for computing trunc from OPERAND1 storing
46312    into OPERAND0.  */
46313 void
46314 ix86_expand_trunc (rtx operand0, rtx operand1)
46315 {
46316   /* C code for SSE variant we expand below.
46317         double xa = fabs (x), x2;
46318         if (!isless (xa, TWO52))
46319           return x;
46320         x2 = (double)(long)x;
46321         if (HONOR_SIGNED_ZEROS (mode))
46322           return copysign (x2, x);
46323         return x2;
46324    */
46325   machine_mode mode = GET_MODE (operand0);
46326   rtx xa, xi, TWO52, res, mask;
46327   rtx_code_label *label;
46328
46329   TWO52 = ix86_gen_TWO52 (mode);
46330
46331   /* Temporary for holding the result, initialized to the input
46332      operand to ease control flow.  */
46333   res = gen_reg_rtx (mode);
46334   emit_move_insn (res, operand1);
46335
46336   /* xa = abs (operand1) */
46337   xa = ix86_expand_sse_fabs (res, &mask);
46338
46339   /* if (!isless (xa, TWO52)) goto label; */
46340   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46341
46342   /* x = (double)(long)x */
46343   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46344   expand_fix (xi, res, 0);
46345   expand_float (res, xi, 0);
46346
46347   if (HONOR_SIGNED_ZEROS (mode))
46348     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
46349
46350   emit_label (label);
46351   LABEL_NUSES (label) = 1;
46352
46353   emit_move_insn (operand0, res);
46354 }
46355
46356 /* Expand SSE sequence for computing trunc from OPERAND1 storing
46357    into OPERAND0.  */
46358 void
46359 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
46360 {
46361   machine_mode mode = GET_MODE (operand0);
46362   rtx xa, mask, TWO52, one, res, smask, tmp;
46363   rtx_code_label *label;
46364
46365   /* C code for SSE variant we expand below.
46366         double xa = fabs (x), x2;
46367         if (!isless (xa, TWO52))
46368           return x;
46369         xa2 = xa + TWO52 - TWO52;
46370      Compensate:
46371         if (xa2 > xa)
46372           xa2 -= 1.0;
46373         x2 = copysign (xa2, x);
46374         return x2;
46375    */
46376
46377   TWO52 = ix86_gen_TWO52 (mode);
46378
46379   /* Temporary for holding the result, initialized to the input
46380      operand to ease control flow.  */
46381   res = gen_reg_rtx (mode);
46382   emit_move_insn (res, operand1);
46383
46384   /* xa = abs (operand1) */
46385   xa = ix86_expand_sse_fabs (res, &smask);
46386
46387   /* if (!isless (xa, TWO52)) goto label; */
46388   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46389
46390   /* res = xa + TWO52 - TWO52; */
46391   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46392   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
46393   emit_move_insn (res, tmp);
46394
46395   /* generate 1.0 */
46396   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
46397
46398   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
46399   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
46400   emit_insn (gen_rtx_SET (VOIDmode, mask,
46401                           gen_rtx_AND (mode, mask, one)));
46402   tmp = expand_simple_binop (mode, MINUS,
46403                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
46404   emit_move_insn (res, tmp);
46405
46406   /* res = copysign (res, operand1) */
46407   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
46408
46409   emit_label (label);
46410   LABEL_NUSES (label) = 1;
46411
46412   emit_move_insn (operand0, res);
46413 }
46414
46415 /* Expand SSE sequence for computing round from OPERAND1 storing
46416    into OPERAND0.  */
46417 void
46418 ix86_expand_round (rtx operand0, rtx operand1)
46419 {
46420   /* C code for the stuff we're doing below:
46421         double xa = fabs (x);
46422         if (!isless (xa, TWO52))
46423           return x;
46424         xa = (double)(long)(xa + nextafter (0.5, 0.0));
46425         return copysign (xa, x);
46426    */
46427   machine_mode mode = GET_MODE (operand0);
46428   rtx res, TWO52, xa, xi, half, mask;
46429   rtx_code_label *label;
46430   const struct real_format *fmt;
46431   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46432
46433   /* Temporary for holding the result, initialized to the input
46434      operand to ease control flow.  */
46435   res = gen_reg_rtx (mode);
46436   emit_move_insn (res, operand1);
46437
46438   TWO52 = ix86_gen_TWO52 (mode);
46439   xa = ix86_expand_sse_fabs (res, &mask);
46440   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46441
46442   /* load nextafter (0.5, 0.0) */
46443   fmt = REAL_MODE_FORMAT (mode);
46444   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46445   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46446
46447   /* xa = xa + 0.5 */
46448   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
46449   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
46450
46451   /* xa = (double)(int64_t)xa */
46452   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46453   expand_fix (xi, xa, 0);
46454   expand_float (xa, xi, 0);
46455
46456   /* res = copysign (xa, operand1) */
46457   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
46458
46459   emit_label (label);
46460   LABEL_NUSES (label) = 1;
46461
46462   emit_move_insn (operand0, res);
46463 }
46464
46465 /* Expand SSE sequence for computing round
46466    from OP1 storing into OP0 using sse4 round insn.  */
46467 void
46468 ix86_expand_round_sse4 (rtx op0, rtx op1)
46469 {
46470   machine_mode mode = GET_MODE (op0);
46471   rtx e1, e2, res, half;
46472   const struct real_format *fmt;
46473   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46474   rtx (*gen_copysign) (rtx, rtx, rtx);
46475   rtx (*gen_round) (rtx, rtx, rtx);
46476
46477   switch (mode)
46478     {
46479     case SFmode:
46480       gen_copysign = gen_copysignsf3;
46481       gen_round = gen_sse4_1_roundsf2;
46482       break;
46483     case DFmode:
46484       gen_copysign = gen_copysigndf3;
46485       gen_round = gen_sse4_1_rounddf2;
46486       break;
46487     default:
46488       gcc_unreachable ();
46489     }
46490
46491   /* round (a) = trunc (a + copysign (0.5, a)) */
46492
46493   /* load nextafter (0.5, 0.0) */
46494   fmt = REAL_MODE_FORMAT (mode);
46495   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46496   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46497   half = const_double_from_real_value (pred_half, mode);
46498
46499   /* e1 = copysign (0.5, op1) */
46500   e1 = gen_reg_rtx (mode);
46501   emit_insn (gen_copysign (e1, half, op1));
46502
46503   /* e2 = op1 + e1 */
46504   e2 = expand_simple_binop (mode, PLUS, op1, e1, NULL_RTX, 0, OPTAB_DIRECT);
46505
46506   /* res = trunc (e2) */
46507   res = gen_reg_rtx (mode);
46508   emit_insn (gen_round (res, e2, GEN_INT (ROUND_TRUNC)));
46509
46510   emit_move_insn (op0, res);
46511 }
46512 \f
46513
46514 /* Table of valid machine attributes.  */
46515 static const struct attribute_spec ix86_attribute_table[] =
46516 {
46517   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
46518        affects_type_identity } */
46519   /* Stdcall attribute says callee is responsible for popping arguments
46520      if they are not variable.  */
46521   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46522     true },
46523   /* Fastcall attribute says callee is responsible for popping arguments
46524      if they are not variable.  */
46525   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46526     true },
46527   /* Thiscall attribute says callee is responsible for popping arguments
46528      if they are not variable.  */
46529   { "thiscall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46530     true },
46531   /* Cdecl attribute says the callee is a normal C declaration */
46532   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46533     true },
46534   /* Regparm attribute specifies how many integer arguments are to be
46535      passed in registers.  */
46536   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute,
46537     true },
46538   /* Sseregparm attribute says we are using x86_64 calling conventions
46539      for FP arguments.  */
46540   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute,
46541     true },
46542   /* The transactional memory builtins are implicitly regparm or fastcall
46543      depending on the ABI.  Override the generic do-nothing attribute that
46544      these builtins were declared with.  */
46545   { "*tm regparm", 0, 0, false, true, true, ix86_handle_tm_regparm_attribute,
46546     true },
46547   /* force_align_arg_pointer says this function realigns the stack at entry.  */
46548   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
46549     false, true,  true, ix86_handle_cconv_attribute, false },
46550 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
46551   { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false },
46552   { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false },
46553   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute,
46554     false },
46555 #endif
46556   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute,
46557     false },
46558   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute,
46559     false },
46560 #ifdef SUBTARGET_ATTRIBUTE_TABLE
46561   SUBTARGET_ATTRIBUTE_TABLE,
46562 #endif
46563   /* ms_abi and sysv_abi calling convention function attributes.  */
46564   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute, true },
46565   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute, true },
46566   { "ms_hook_prologue", 0, 0, true, false, false, ix86_handle_fndecl_attribute,
46567     false },
46568   { "callee_pop_aggregate_return", 1, 1, false, true, true,
46569     ix86_handle_callee_pop_aggregate_return, true },
46570   /* End element.  */
46571   { NULL,        0, 0, false, false, false, NULL, false }
46572 };
46573
46574 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
46575 static int
46576 ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
46577                                  tree vectype, int)
46578 {
46579   unsigned elements;
46580
46581   switch (type_of_cost)
46582     {
46583       case scalar_stmt:
46584         return ix86_cost->scalar_stmt_cost;
46585
46586       case scalar_load:
46587         return ix86_cost->scalar_load_cost;
46588
46589       case scalar_store:
46590         return ix86_cost->scalar_store_cost;
46591
46592       case vector_stmt:
46593         return ix86_cost->vec_stmt_cost;
46594
46595       case vector_load:
46596         return ix86_cost->vec_align_load_cost;
46597
46598       case vector_store:
46599         return ix86_cost->vec_store_cost;
46600
46601       case vec_to_scalar:
46602         return ix86_cost->vec_to_scalar_cost;
46603
46604       case scalar_to_vec:
46605         return ix86_cost->scalar_to_vec_cost;
46606
46607       case unaligned_load:
46608       case unaligned_store:
46609         return ix86_cost->vec_unalign_load_cost;
46610
46611       case cond_branch_taken:
46612         return ix86_cost->cond_taken_branch_cost;
46613
46614       case cond_branch_not_taken:
46615         return ix86_cost->cond_not_taken_branch_cost;
46616
46617       case vec_perm:
46618       case vec_promote_demote:
46619         return ix86_cost->vec_stmt_cost;
46620
46621       case vec_construct:
46622         elements = TYPE_VECTOR_SUBPARTS (vectype);
46623         return elements / 2 + 1;
46624
46625       default:
46626         gcc_unreachable ();
46627     }
46628 }
46629
46630 /* A cached (set (nil) (vselect (vconcat (nil) (nil)) (parallel [])))
46631    insn, so that expand_vselect{,_vconcat} doesn't have to create a fresh
46632    insn every time.  */
46633
46634 static GTY(()) rtx_insn *vselect_insn;
46635
46636 /* Initialize vselect_insn.  */
46637
46638 static void
46639 init_vselect_insn (void)
46640 {
46641   unsigned i;
46642   rtx x;
46643
46644   x = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (MAX_VECT_LEN));
46645   for (i = 0; i < MAX_VECT_LEN; ++i)
46646     XVECEXP (x, 0, i) = const0_rtx;
46647   x = gen_rtx_VEC_SELECT (V2DFmode, gen_rtx_VEC_CONCAT (V4DFmode, const0_rtx,
46648                                                         const0_rtx), x);
46649   x = gen_rtx_SET (VOIDmode, const0_rtx, x);
46650   start_sequence ();
46651   vselect_insn = emit_insn (x);
46652   end_sequence ();
46653 }
46654
46655 /* Construct (set target (vec_select op0 (parallel perm))) and
46656    return true if that's a valid instruction in the active ISA.  */
46657
46658 static bool
46659 expand_vselect (rtx target, rtx op0, const unsigned char *perm,
46660                 unsigned nelt, bool testing_p)
46661 {
46662   unsigned int i;
46663   rtx x, save_vconcat;
46664   int icode;
46665
46666   if (vselect_insn == NULL_RTX)
46667     init_vselect_insn ();
46668
46669   x = XEXP (SET_SRC (PATTERN (vselect_insn)), 1);
46670   PUT_NUM_ELEM (XVEC (x, 0), nelt);
46671   for (i = 0; i < nelt; ++i)
46672     XVECEXP (x, 0, i) = GEN_INT (perm[i]);
46673   save_vconcat = XEXP (SET_SRC (PATTERN (vselect_insn)), 0);
46674   XEXP (SET_SRC (PATTERN (vselect_insn)), 0) = op0;
46675   PUT_MODE (SET_SRC (PATTERN (vselect_insn)), GET_MODE (target));
46676   SET_DEST (PATTERN (vselect_insn)) = target;
46677   icode = recog_memoized (vselect_insn);
46678
46679   if (icode >= 0 && !testing_p)
46680     emit_insn (copy_rtx (PATTERN (vselect_insn)));
46681
46682   SET_DEST (PATTERN (vselect_insn)) = const0_rtx;
46683   XEXP (SET_SRC (PATTERN (vselect_insn)), 0) = save_vconcat;
46684   INSN_CODE (vselect_insn) = -1;
46685
46686   return icode >= 0;
46687 }
46688
46689 /* Similar, but generate a vec_concat from op0 and op1 as well.  */
46690
46691 static bool
46692 expand_vselect_vconcat (rtx target, rtx op0, rtx op1,
46693                         const unsigned char *perm, unsigned nelt,
46694                         bool testing_p)
46695 {
46696   machine_mode v2mode;
46697   rtx x;
46698   bool ok;
46699
46700   if (vselect_insn == NULL_RTX)
46701     init_vselect_insn ();
46702
46703   v2mode = GET_MODE_2XWIDER_MODE (GET_MODE (op0));
46704   x = XEXP (SET_SRC (PATTERN (vselect_insn)), 0);
46705   PUT_MODE (x, v2mode);
46706   XEXP (x, 0) = op0;
46707   XEXP (x, 1) = op1;
46708   ok = expand_vselect (target, x, perm, nelt, testing_p);
46709   XEXP (x, 0) = const0_rtx;
46710   XEXP (x, 1) = const0_rtx;
46711   return ok;
46712 }
46713
46714 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
46715    in terms of blendp[sd] / pblendw / pblendvb / vpblendd.  */
46716
46717 static bool
46718 expand_vec_perm_blend (struct expand_vec_perm_d *d)
46719 {
46720   machine_mode vmode = d->vmode;
46721   unsigned i, mask, nelt = d->nelt;
46722   rtx target, op0, op1, x;
46723   rtx rperm[32], vperm;
46724
46725   if (d->one_operand_p)
46726     return false;
46727   if (TARGET_AVX512F && GET_MODE_SIZE (vmode) == 64
46728       && GET_MODE_SIZE (GET_MODE_INNER (vmode)) >= 4)
46729     ;
46730   else if (TARGET_AVX2 && GET_MODE_SIZE (vmode) == 32)
46731     ;
46732   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
46733     ;
46734   else if (TARGET_SSE4_1 && GET_MODE_SIZE (vmode) == 16)
46735     ;
46736   else
46737     return false;
46738
46739   /* This is a blend, not a permute.  Elements must stay in their
46740      respective lanes.  */
46741   for (i = 0; i < nelt; ++i)
46742     {
46743       unsigned e = d->perm[i];
46744       if (!(e == i || e == i + nelt))
46745         return false;
46746     }
46747
46748   if (d->testing_p)
46749     return true;
46750
46751   /* ??? Without SSE4.1, we could implement this with and/andn/or.  This
46752      decision should be extracted elsewhere, so that we only try that
46753      sequence once all budget==3 options have been tried.  */
46754   target = d->target;
46755   op0 = d->op0;
46756   op1 = d->op1;
46757   mask = 0;
46758
46759   switch (vmode)
46760     {
46761     case V8DFmode:
46762     case V16SFmode:
46763     case V4DFmode:
46764     case V8SFmode:
46765     case V2DFmode:
46766     case V4SFmode:
46767     case V8HImode:
46768     case V8SImode:
46769     case V32HImode:
46770     case V64QImode:
46771     case V16SImode:
46772     case V8DImode:
46773       for (i = 0; i < nelt; ++i)
46774         mask |= (d->perm[i] >= nelt) << i;
46775       break;
46776
46777     case V2DImode:
46778       for (i = 0; i < 2; ++i)
46779         mask |= (d->perm[i] >= 2 ? 15 : 0) << (i * 4);
46780       vmode = V8HImode;
46781       goto do_subreg;
46782
46783     case V4SImode:
46784       for (i = 0; i < 4; ++i)
46785         mask |= (d->perm[i] >= 4 ? 3 : 0) << (i * 2);
46786       vmode = V8HImode;
46787       goto do_subreg;
46788
46789     case V16QImode:
46790       /* See if bytes move in pairs so we can use pblendw with
46791          an immediate argument, rather than pblendvb with a vector
46792          argument.  */
46793       for (i = 0; i < 16; i += 2)
46794         if (d->perm[i] + 1 != d->perm[i + 1])
46795           {
46796           use_pblendvb:
46797             for (i = 0; i < nelt; ++i)
46798               rperm[i] = (d->perm[i] < nelt ? const0_rtx : constm1_rtx);
46799
46800           finish_pblendvb:
46801             vperm = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (nelt, rperm));
46802             vperm = force_reg (vmode, vperm);
46803
46804             if (GET_MODE_SIZE (vmode) == 16)
46805               emit_insn (gen_sse4_1_pblendvb (target, op0, op1, vperm));
46806             else
46807               emit_insn (gen_avx2_pblendvb (target, op0, op1, vperm));
46808             if (target != d->target)
46809               emit_move_insn (d->target, gen_lowpart (d->vmode, target));
46810             return true;
46811           }
46812
46813       for (i = 0; i < 8; ++i)
46814         mask |= (d->perm[i * 2] >= 16) << i;
46815       vmode = V8HImode;
46816       /* FALLTHRU */
46817
46818     do_subreg:
46819       target = gen_reg_rtx (vmode);
46820       op0 = gen_lowpart (vmode, op0);
46821       op1 = gen_lowpart (vmode, op1);
46822       break;
46823
46824     case V32QImode:
46825       /* See if bytes move in pairs.  If not, vpblendvb must be used.  */
46826       for (i = 0; i < 32; i += 2)
46827         if (d->perm[i] + 1 != d->perm[i + 1])
46828           goto use_pblendvb;
46829       /* See if bytes move in quadruplets.  If yes, vpblendd
46830          with immediate can be used.  */
46831       for (i = 0; i < 32; i += 4)
46832         if (d->perm[i] + 2 != d->perm[i + 2])
46833           break;
46834       if (i < 32)
46835         {
46836           /* See if bytes move the same in both lanes.  If yes,
46837              vpblendw with immediate can be used.  */
46838           for (i = 0; i < 16; i += 2)
46839             if (d->perm[i] + 16 != d->perm[i + 16])
46840               goto use_pblendvb;
46841
46842           /* Use vpblendw.  */
46843           for (i = 0; i < 16; ++i)
46844             mask |= (d->perm[i * 2] >= 32) << i;
46845           vmode = V16HImode;
46846           goto do_subreg;
46847         }
46848
46849       /* Use vpblendd.  */
46850       for (i = 0; i < 8; ++i)
46851         mask |= (d->perm[i * 4] >= 32) << i;
46852       vmode = V8SImode;
46853       goto do_subreg;
46854
46855     case V16HImode:
46856       /* See if words move in pairs.  If yes, vpblendd can be used.  */
46857       for (i = 0; i < 16; i += 2)
46858         if (d->perm[i] + 1 != d->perm[i + 1])
46859           break;
46860       if (i < 16)
46861         {
46862           /* See if words move the same in both lanes.  If not,
46863              vpblendvb must be used.  */
46864           for (i = 0; i < 8; i++)
46865             if (d->perm[i] + 8 != d->perm[i + 8])
46866               {
46867                 /* Use vpblendvb.  */
46868                 for (i = 0; i < 32; ++i)
46869                   rperm[i] = (d->perm[i / 2] < 16 ? const0_rtx : constm1_rtx);
46870
46871                 vmode = V32QImode;
46872                 nelt = 32;
46873                 target = gen_reg_rtx (vmode);
46874                 op0 = gen_lowpart (vmode, op0);
46875                 op1 = gen_lowpart (vmode, op1);
46876                 goto finish_pblendvb;
46877               }
46878
46879           /* Use vpblendw.  */
46880           for (i = 0; i < 16; ++i)
46881             mask |= (d->perm[i] >= 16) << i;
46882           break;
46883         }
46884
46885       /* Use vpblendd.  */
46886       for (i = 0; i < 8; ++i)
46887         mask |= (d->perm[i * 2] >= 16) << i;
46888       vmode = V8SImode;
46889       goto do_subreg;
46890
46891     case V4DImode:
46892       /* Use vpblendd.  */
46893       for (i = 0; i < 4; ++i)
46894         mask |= (d->perm[i] >= 4 ? 3 : 0) << (i * 2);
46895       vmode = V8SImode;
46896       goto do_subreg;
46897
46898     default:
46899       gcc_unreachable ();
46900     }
46901
46902   /* This matches five different patterns with the different modes.  */
46903   x = gen_rtx_VEC_MERGE (vmode, op1, op0, GEN_INT (mask));
46904   x = gen_rtx_SET (VOIDmode, target, x);
46905   emit_insn (x);
46906   if (target != d->target)
46907     emit_move_insn (d->target, gen_lowpart (d->vmode, target));
46908
46909   return true;
46910 }
46911
46912 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
46913    in terms of the variable form of vpermilps.
46914
46915    Note that we will have already failed the immediate input vpermilps,
46916    which requires that the high and low part shuffle be identical; the
46917    variable form doesn't require that.  */
46918
46919 static bool
46920 expand_vec_perm_vpermil (struct expand_vec_perm_d *d)
46921 {
46922   rtx rperm[8], vperm;
46923   unsigned i;
46924
46925   if (!TARGET_AVX || d->vmode != V8SFmode || !d->one_operand_p)
46926     return false;
46927
46928   /* We can only permute within the 128-bit lane.  */
46929   for (i = 0; i < 8; ++i)
46930     {
46931       unsigned e = d->perm[i];
46932       if (i < 4 ? e >= 4 : e < 4)
46933         return false;
46934     }
46935
46936   if (d->testing_p)
46937     return true;
46938
46939   for (i = 0; i < 8; ++i)
46940     {
46941       unsigned e = d->perm[i];
46942
46943       /* Within each 128-bit lane, the elements of op0 are numbered
46944          from 0 and the elements of op1 are numbered from 4.  */
46945       if (e >= 8 + 4)
46946         e -= 8;
46947       else if (e >= 4)
46948         e -= 4;
46949
46950       rperm[i] = GEN_INT (e);
46951     }
46952
46953   vperm = gen_rtx_CONST_VECTOR (V8SImode, gen_rtvec_v (8, rperm));
46954   vperm = force_reg (V8SImode, vperm);
46955   emit_insn (gen_avx_vpermilvarv8sf3 (d->target, d->op0, vperm));
46956
46957   return true;
46958 }
46959
46960 /* Return true if permutation D can be performed as VMODE permutation
46961    instead.  */
46962
46963 static bool
46964 valid_perm_using_mode_p (machine_mode vmode, struct expand_vec_perm_d *d)
46965 {
46966   unsigned int i, j, chunk;
46967
46968   if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT
46969       || GET_MODE_CLASS (d->vmode) != MODE_VECTOR_INT
46970       || GET_MODE_SIZE (vmode) != GET_MODE_SIZE (d->vmode))
46971     return false;
46972
46973   if (GET_MODE_NUNITS (vmode) >= d->nelt)
46974     return true;
46975
46976   chunk = d->nelt / GET_MODE_NUNITS (vmode);
46977   for (i = 0; i < d->nelt; i += chunk)
46978     if (d->perm[i] & (chunk - 1))
46979       return false;
46980     else
46981       for (j = 1; j < chunk; ++j)
46982         if (d->perm[i] + j != d->perm[i + j])
46983           return false;
46984
46985   return true;
46986 }
46987
46988 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
46989    in terms of pshufb, vpperm, vpermq, vpermd, vpermps or vperm2i128.  */
46990
46991 static bool
46992 expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
46993 {
46994   unsigned i, nelt, eltsz, mask;
46995   unsigned char perm[64];
46996   machine_mode vmode = V16QImode;
46997   rtx rperm[64], vperm, target, op0, op1;
46998
46999   nelt = d->nelt;
47000
47001   if (!d->one_operand_p)
47002     {
47003       if (!TARGET_XOP || GET_MODE_SIZE (d->vmode) != 16)
47004         {
47005           if (TARGET_AVX2
47006               && valid_perm_using_mode_p (V2TImode, d))
47007             {
47008               if (d->testing_p)
47009                 return true;
47010
47011               /* Use vperm2i128 insn.  The pattern uses
47012                  V4DImode instead of V2TImode.  */
47013               target = d->target;
47014               if (d->vmode != V4DImode)
47015                 target = gen_reg_rtx (V4DImode);
47016               op0 = gen_lowpart (V4DImode, d->op0);
47017               op1 = gen_lowpart (V4DImode, d->op1);
47018               rperm[0]
47019                 = GEN_INT ((d->perm[0] / (nelt / 2))
47020                            | ((d->perm[nelt / 2] / (nelt / 2)) * 16));
47021               emit_insn (gen_avx2_permv2ti (target, op0, op1, rperm[0]));
47022               if (target != d->target)
47023                 emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47024               return true;
47025             }
47026           return false;
47027         }
47028     }
47029   else
47030     {
47031       if (GET_MODE_SIZE (d->vmode) == 16)
47032         {
47033           if (!TARGET_SSSE3)
47034             return false;
47035         }
47036       else if (GET_MODE_SIZE (d->vmode) == 32)
47037         {
47038           if (!TARGET_AVX2)
47039             return false;
47040
47041           /* V4DImode should be already handled through
47042              expand_vselect by vpermq instruction.  */
47043           gcc_assert (d->vmode != V4DImode);
47044
47045           vmode = V32QImode;
47046           if (d->vmode == V8SImode
47047               || d->vmode == V16HImode
47048               || d->vmode == V32QImode)
47049             {
47050               /* First see if vpermq can be used for
47051                  V8SImode/V16HImode/V32QImode.  */
47052               if (valid_perm_using_mode_p (V4DImode, d))
47053                 {
47054                   for (i = 0; i < 4; i++)
47055                     perm[i] = (d->perm[i * nelt / 4] * 4 / nelt) & 3;
47056                   if (d->testing_p)
47057                     return true;
47058                   target = gen_reg_rtx (V4DImode);
47059                   if (expand_vselect (target, gen_lowpart (V4DImode, d->op0),
47060                                       perm, 4, false))
47061                     {
47062                       emit_move_insn (d->target,
47063                                       gen_lowpart (d->vmode, target));
47064                       return true;
47065                     }
47066                   return false;
47067                 }
47068
47069               /* Next see if vpermd can be used.  */
47070               if (valid_perm_using_mode_p (V8SImode, d))
47071                 vmode = V8SImode;
47072             }
47073           /* Or if vpermps can be used.  */
47074           else if (d->vmode == V8SFmode)
47075             vmode = V8SImode;
47076
47077           if (vmode == V32QImode)
47078             {
47079               /* vpshufb only works intra lanes, it is not
47080                  possible to shuffle bytes in between the lanes.  */
47081               for (i = 0; i < nelt; ++i)
47082                 if ((d->perm[i] ^ i) & (nelt / 2))
47083                   return false;
47084             }
47085         }
47086       else if (GET_MODE_SIZE (d->vmode) == 64)
47087         {
47088           if (!TARGET_AVX512BW)
47089             return false;
47090
47091           /* If vpermq didn't work, vpshufb won't work either.  */
47092           if (d->vmode == V8DFmode || d->vmode == V8DImode)
47093             return false;
47094
47095           vmode = V64QImode;
47096           if (d->vmode == V16SImode
47097               || d->vmode == V32HImode
47098               || d->vmode == V64QImode)
47099             {
47100               /* First see if vpermq can be used for
47101                  V16SImode/V32HImode/V64QImode.  */
47102               if (valid_perm_using_mode_p (V8DImode, d))
47103                 {
47104                   for (i = 0; i < 8; i++)
47105                     perm[i] = (d->perm[i * nelt / 8] * 8 / nelt) & 7;
47106                   if (d->testing_p)
47107                     return true;
47108                   target = gen_reg_rtx (V8DImode);
47109                   if (expand_vselect (target, gen_lowpart (V8DImode, d->op0),
47110                                       perm, 8, false))
47111                     {
47112                       emit_move_insn (d->target,
47113                                       gen_lowpart (d->vmode, target));
47114                       return true;
47115                     }
47116                   return false;
47117                 }
47118
47119               /* Next see if vpermd can be used.  */
47120               if (valid_perm_using_mode_p (V16SImode, d))
47121                 vmode = V16SImode;
47122             }
47123           /* Or if vpermps can be used.  */
47124           else if (d->vmode == V16SFmode)
47125             vmode = V16SImode;
47126           if (vmode == V64QImode)
47127             {
47128               /* vpshufb only works intra lanes, it is not
47129                  possible to shuffle bytes in between the lanes.  */
47130               for (i = 0; i < nelt; ++i)
47131                 if ((d->perm[i] ^ i) & (nelt / 4))
47132                   return false;
47133             }
47134         }
47135       else
47136         return false;
47137     }
47138
47139   if (d->testing_p)
47140     return true;
47141
47142   if (vmode == V8SImode)
47143     for (i = 0; i < 8; ++i)
47144       rperm[i] = GEN_INT ((d->perm[i * nelt / 8] * 8 / nelt) & 7);
47145   else if (vmode == V16SImode)
47146     for (i = 0; i < 16; ++i)
47147       rperm[i] = GEN_INT ((d->perm[i * nelt / 16] * 16 / nelt) & 15);
47148   else
47149     {
47150       eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
47151       if (!d->one_operand_p)
47152         mask = 2 * nelt - 1;
47153       else if (vmode == V16QImode)
47154         mask = nelt - 1;
47155       else if (vmode == V64QImode)
47156         mask = nelt / 4 - 1;
47157       else
47158         mask = nelt / 2 - 1;
47159
47160       for (i = 0; i < nelt; ++i)
47161         {
47162           unsigned j, e = d->perm[i] & mask;
47163           for (j = 0; j < eltsz; ++j)
47164             rperm[i * eltsz + j] = GEN_INT (e * eltsz + j);
47165         }
47166     }
47167
47168   vperm = gen_rtx_CONST_VECTOR (vmode,
47169                                 gen_rtvec_v (GET_MODE_NUNITS (vmode), rperm));
47170   vperm = force_reg (vmode, vperm);
47171
47172   target = d->target;
47173   if (d->vmode != vmode)
47174     target = gen_reg_rtx (vmode);
47175   op0 = gen_lowpart (vmode, d->op0);
47176   if (d->one_operand_p)
47177     {
47178       if (vmode == V16QImode)
47179         emit_insn (gen_ssse3_pshufbv16qi3 (target, op0, vperm));
47180       else if (vmode == V32QImode)
47181         emit_insn (gen_avx2_pshufbv32qi3 (target, op0, vperm));
47182       else if (vmode == V64QImode)
47183         emit_insn (gen_avx512bw_pshufbv64qi3 (target, op0, vperm));
47184       else if (vmode == V8SFmode)
47185         emit_insn (gen_avx2_permvarv8sf (target, op0, vperm));
47186       else if (vmode == V8SImode)
47187         emit_insn (gen_avx2_permvarv8si (target, op0, vperm));
47188       else if (vmode == V16SFmode)
47189         emit_insn (gen_avx512f_permvarv16sf (target, op0, vperm));
47190       else if (vmode == V16SImode)
47191         emit_insn (gen_avx512f_permvarv16si (target, op0, vperm));
47192       else
47193         gcc_unreachable ();
47194     }
47195   else
47196     {
47197       op1 = gen_lowpart (vmode, d->op1);
47198       emit_insn (gen_xop_pperm (target, op0, op1, vperm));
47199     }
47200   if (target != d->target)
47201     emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47202
47203   return true;
47204 }
47205
47206 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to instantiate D
47207    in a single instruction.  */
47208
47209 static bool
47210 expand_vec_perm_1 (struct expand_vec_perm_d *d)
47211 {
47212   unsigned i, nelt = d->nelt;
47213   unsigned char perm2[MAX_VECT_LEN];
47214
47215   /* Check plain VEC_SELECT first, because AVX has instructions that could
47216      match both SEL and SEL+CONCAT, but the plain SEL will allow a memory
47217      input where SEL+CONCAT may not.  */
47218   if (d->one_operand_p)
47219     {
47220       int mask = nelt - 1;
47221       bool identity_perm = true;
47222       bool broadcast_perm = true;
47223
47224       for (i = 0; i < nelt; i++)
47225         {
47226           perm2[i] = d->perm[i] & mask;
47227           if (perm2[i] != i)
47228             identity_perm = false;
47229           if (perm2[i])
47230             broadcast_perm = false;
47231         }
47232
47233       if (identity_perm)
47234         {
47235           if (!d->testing_p)
47236             emit_move_insn (d->target, d->op0);
47237           return true;
47238         }
47239       else if (broadcast_perm && TARGET_AVX2)
47240         {
47241           /* Use vpbroadcast{b,w,d}.  */
47242           rtx (*gen) (rtx, rtx) = NULL;
47243           switch (d->vmode)
47244             {
47245             case V64QImode:
47246               if (TARGET_AVX512BW)
47247                 gen = gen_avx512bw_vec_dupv64qi_1;
47248               break;
47249             case V32QImode:
47250               gen = gen_avx2_pbroadcastv32qi_1;
47251               break;
47252             case V32HImode:
47253               if (TARGET_AVX512BW)
47254                 gen = gen_avx512bw_vec_dupv32hi_1;
47255               break;
47256             case V16HImode:
47257               gen = gen_avx2_pbroadcastv16hi_1;
47258               break;
47259             case V16SImode:
47260               if (TARGET_AVX512F)
47261                 gen = gen_avx512f_vec_dupv16si_1;
47262               break;
47263             case V8SImode:
47264               gen = gen_avx2_pbroadcastv8si_1;
47265               break;
47266             case V16QImode:
47267               gen = gen_avx2_pbroadcastv16qi;
47268               break;
47269             case V8HImode:
47270               gen = gen_avx2_pbroadcastv8hi;
47271               break;
47272             case V16SFmode:
47273               if (TARGET_AVX512F)
47274                 gen = gen_avx512f_vec_dupv16sf_1;
47275               break;
47276             case V8SFmode:
47277               gen = gen_avx2_vec_dupv8sf_1;
47278               break;
47279             case V8DFmode:
47280               if (TARGET_AVX512F)
47281                 gen = gen_avx512f_vec_dupv8df_1;
47282               break;
47283             case V8DImode:
47284               if (TARGET_AVX512F)
47285                 gen = gen_avx512f_vec_dupv8di_1;
47286               break;
47287             /* For other modes prefer other shuffles this function creates.  */
47288             default: break;
47289             }
47290           if (gen != NULL)
47291             {
47292               if (!d->testing_p)
47293                 emit_insn (gen (d->target, d->op0));
47294               return true;
47295             }
47296         }
47297
47298       if (expand_vselect (d->target, d->op0, perm2, nelt, d->testing_p))
47299         return true;
47300
47301       /* There are plenty of patterns in sse.md that are written for
47302          SEL+CONCAT and are not replicated for a single op.  Perhaps
47303          that should be changed, to avoid the nastiness here.  */
47304
47305       /* Recognize interleave style patterns, which means incrementing
47306          every other permutation operand.  */
47307       for (i = 0; i < nelt; i += 2)
47308         {
47309           perm2[i] = d->perm[i] & mask;
47310           perm2[i + 1] = (d->perm[i + 1] & mask) + nelt;
47311         }
47312       if (expand_vselect_vconcat (d->target, d->op0, d->op0, perm2, nelt,
47313                                   d->testing_p))
47314         return true;
47315
47316       /* Recognize shufps, which means adding {0, 0, nelt, nelt}.  */
47317       if (nelt >= 4)
47318         {
47319           for (i = 0; i < nelt; i += 4)
47320             {
47321               perm2[i + 0] = d->perm[i + 0] & mask;
47322               perm2[i + 1] = d->perm[i + 1] & mask;
47323               perm2[i + 2] = (d->perm[i + 2] & mask) + nelt;
47324               perm2[i + 3] = (d->perm[i + 3] & mask) + nelt;
47325             }
47326
47327           if (expand_vselect_vconcat (d->target, d->op0, d->op0, perm2, nelt,
47328                                       d->testing_p))
47329             return true;
47330         }
47331     }
47332
47333   /* Finally, try the fully general two operand permute.  */
47334   if (expand_vselect_vconcat (d->target, d->op0, d->op1, d->perm, nelt,
47335                               d->testing_p))
47336     return true;
47337
47338   /* Recognize interleave style patterns with reversed operands.  */
47339   if (!d->one_operand_p)
47340     {
47341       for (i = 0; i < nelt; ++i)
47342         {
47343           unsigned e = d->perm[i];
47344           if (e >= nelt)
47345             e -= nelt;
47346           else
47347             e += nelt;
47348           perm2[i] = e;
47349         }
47350
47351       if (expand_vselect_vconcat (d->target, d->op1, d->op0, perm2, nelt,
47352                                   d->testing_p))
47353         return true;
47354     }
47355
47356   /* Try the SSE4.1 blend variable merge instructions.  */
47357   if (expand_vec_perm_blend (d))
47358     return true;
47359
47360   /* Try one of the AVX vpermil variable permutations.  */
47361   if (expand_vec_perm_vpermil (d))
47362     return true;
47363
47364   /* Try the SSSE3 pshufb or XOP vpperm or AVX2 vperm2i128,
47365      vpshufb, vpermd, vpermps or vpermq variable permutation.  */
47366   if (expand_vec_perm_pshufb (d))
47367     return true;
47368
47369   /* Try the AVX2 vpalignr instruction.  */
47370   if (expand_vec_perm_palignr (d, true))
47371     return true;
47372
47373   /* Try the AVX512F vpermi2 instructions.  */
47374   if (ix86_expand_vec_perm_vpermi2 (NULL_RTX, NULL_RTX, NULL_RTX, NULL_RTX, d))
47375     return true;
47376
47377   return false;
47378 }
47379
47380 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
47381    in terms of a pair of pshuflw + pshufhw instructions.  */
47382
47383 static bool
47384 expand_vec_perm_pshuflw_pshufhw (struct expand_vec_perm_d *d)
47385 {
47386   unsigned char perm2[MAX_VECT_LEN];
47387   unsigned i;
47388   bool ok;
47389
47390   if (d->vmode != V8HImode || !d->one_operand_p)
47391     return false;
47392
47393   /* The two permutations only operate in 64-bit lanes.  */
47394   for (i = 0; i < 4; ++i)
47395     if (d->perm[i] >= 4)
47396       return false;
47397   for (i = 4; i < 8; ++i)
47398     if (d->perm[i] < 4)
47399       return false;
47400
47401   if (d->testing_p)
47402     return true;
47403
47404   /* Emit the pshuflw.  */
47405   memcpy (perm2, d->perm, 4);
47406   for (i = 4; i < 8; ++i)
47407     perm2[i] = i;
47408   ok = expand_vselect (d->target, d->op0, perm2, 8, d->testing_p);
47409   gcc_assert (ok);
47410
47411   /* Emit the pshufhw.  */
47412   memcpy (perm2 + 4, d->perm + 4, 4);
47413   for (i = 0; i < 4; ++i)
47414     perm2[i] = i;
47415   ok = expand_vselect (d->target, d->target, perm2, 8, d->testing_p);
47416   gcc_assert (ok);
47417
47418   return true;
47419 }
47420
47421 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47422    the permutation using the SSSE3 palignr instruction.  This succeeds
47423    when all of the elements in PERM fit within one vector and we merely
47424    need to shift them down so that a single vector permutation has a
47425    chance to succeed.  If SINGLE_INSN_ONLY_P, succeed if only
47426    the vpalignr instruction itself can perform the requested permutation.  */
47427
47428 static bool
47429 expand_vec_perm_palignr (struct expand_vec_perm_d *d, bool single_insn_only_p)
47430 {
47431   unsigned i, nelt = d->nelt;
47432   unsigned min, max, minswap, maxswap;
47433   bool in_order, ok, swap = false;
47434   rtx shift, target;
47435   struct expand_vec_perm_d dcopy;
47436
47437   /* Even with AVX, palignr only operates on 128-bit vectors,
47438      in AVX2 palignr operates on both 128-bit lanes.  */
47439   if ((!TARGET_SSSE3 || GET_MODE_SIZE (d->vmode) != 16)
47440       && (!TARGET_AVX2 || GET_MODE_SIZE (d->vmode) != 32))
47441     return false;
47442
47443   min = 2 * nelt;
47444   max = 0;
47445   minswap = 2 * nelt;
47446   maxswap = 0;
47447   for (i = 0; i < nelt; ++i)
47448     {
47449       unsigned e = d->perm[i];
47450       unsigned eswap = d->perm[i] ^ nelt;
47451       if (GET_MODE_SIZE (d->vmode) == 32)
47452         {
47453           e = (e & ((nelt / 2) - 1)) | ((e & nelt) >> 1);
47454           eswap = e ^ (nelt / 2);
47455         }
47456       if (e < min)
47457         min = e;
47458       if (e > max)
47459         max = e;
47460       if (eswap < minswap)
47461         minswap = eswap;
47462       if (eswap > maxswap)
47463         maxswap = eswap;
47464     }
47465   if (min == 0
47466       || max - min >= (GET_MODE_SIZE (d->vmode) == 32 ? nelt / 2 : nelt))
47467     {
47468       if (d->one_operand_p
47469           || minswap == 0
47470           || maxswap - minswap >= (GET_MODE_SIZE (d->vmode) == 32
47471                                    ? nelt / 2 : nelt))
47472         return false;
47473       swap = true;
47474       min = minswap;
47475       max = maxswap;
47476     }
47477
47478   /* Given that we have SSSE3, we know we'll be able to implement the
47479      single operand permutation after the palignr with pshufb for
47480      128-bit vectors.  If SINGLE_INSN_ONLY_P, in_order has to be computed
47481      first.  */
47482   if (d->testing_p && GET_MODE_SIZE (d->vmode) == 16 && !single_insn_only_p)
47483     return true;
47484
47485   dcopy = *d;
47486   if (swap)
47487     {
47488       dcopy.op0 = d->op1;
47489       dcopy.op1 = d->op0;
47490       for (i = 0; i < nelt; ++i)
47491         dcopy.perm[i] ^= nelt;
47492     }
47493
47494   in_order = true;
47495   for (i = 0; i < nelt; ++i)
47496     {
47497       unsigned e = dcopy.perm[i];
47498       if (GET_MODE_SIZE (d->vmode) == 32
47499           && e >= nelt
47500           && (e & (nelt / 2 - 1)) < min)
47501         e = e - min - (nelt / 2);
47502       else
47503         e = e - min;
47504       if (e != i)
47505         in_order = false;
47506       dcopy.perm[i] = e;
47507     }
47508   dcopy.one_operand_p = true;
47509
47510   if (single_insn_only_p && !in_order)
47511     return false;
47512
47513   /* For AVX2, test whether we can permute the result in one instruction.  */
47514   if (d->testing_p)
47515     {
47516       if (in_order)
47517         return true;
47518       dcopy.op1 = dcopy.op0;
47519       return expand_vec_perm_1 (&dcopy);
47520     }
47521
47522   shift = GEN_INT (min * GET_MODE_BITSIZE (GET_MODE_INNER (d->vmode)));
47523   if (GET_MODE_SIZE (d->vmode) == 16)
47524     {
47525       target = gen_reg_rtx (TImode);
47526       emit_insn (gen_ssse3_palignrti (target, gen_lowpart (TImode, dcopy.op1),
47527                                       gen_lowpart (TImode, dcopy.op0), shift));
47528     }
47529   else
47530     {
47531       target = gen_reg_rtx (V2TImode);
47532       emit_insn (gen_avx2_palignrv2ti (target,
47533                                        gen_lowpart (V2TImode, dcopy.op1),
47534                                        gen_lowpart (V2TImode, dcopy.op0),
47535                                        shift));
47536     }
47537
47538   dcopy.op0 = dcopy.op1 = gen_lowpart (d->vmode, target);
47539
47540   /* Test for the degenerate case where the alignment by itself
47541      produces the desired permutation.  */
47542   if (in_order)
47543     {
47544       emit_move_insn (d->target, dcopy.op0);
47545       return true;
47546     }
47547
47548   ok = expand_vec_perm_1 (&dcopy);
47549   gcc_assert (ok || GET_MODE_SIZE (d->vmode) == 32);
47550
47551   return ok;
47552 }
47553
47554 /* A subroutine of ix86_expand_vec_perm_const_1.  Try to simplify
47555    the permutation using the SSE4_1 pblendv instruction.  Potentially
47556    reduces permutation from 2 pshufb and or to 1 pshufb and pblendv.  */
47557
47558 static bool
47559 expand_vec_perm_pblendv (struct expand_vec_perm_d *d)
47560 {
47561   unsigned i, which, nelt = d->nelt;
47562   struct expand_vec_perm_d dcopy, dcopy1;
47563   machine_mode vmode = d->vmode;
47564   bool ok;
47565
47566   /* Use the same checks as in expand_vec_perm_blend.  */
47567   if (d->one_operand_p)
47568     return false;
47569   if (TARGET_AVX2 && GET_MODE_SIZE (vmode) == 32)
47570     ;
47571   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
47572     ;
47573   else if (TARGET_SSE4_1 && GET_MODE_SIZE (vmode) == 16)
47574     ;
47575   else
47576     return false;
47577
47578   /* Figure out where permutation elements stay not in their
47579      respective lanes.  */
47580   for (i = 0, which = 0; i < nelt; ++i)
47581     {
47582       unsigned e = d->perm[i];
47583       if (e != i)
47584         which |= (e < nelt ? 1 : 2);
47585     }
47586   /* We can pblend the part where elements stay not in their
47587      respective lanes only when these elements are all in one
47588      half of a permutation.
47589      {0 1 8 3 4 5 9 7} is ok as 8, 9 are at not at their respective
47590      lanes, but both 8 and 9 >= 8
47591      {0 1 8 3 4 5 2 7} is not ok as 2 and 8 are not at their
47592      respective lanes and 8 >= 8, but 2 not.  */
47593   if (which != 1 && which != 2)
47594     return false;
47595   if (d->testing_p && GET_MODE_SIZE (vmode) == 16)
47596     return true;
47597
47598   /* First we apply one operand permutation to the part where
47599      elements stay not in their respective lanes.  */
47600   dcopy = *d;
47601   if (which == 2)
47602     dcopy.op0 = dcopy.op1 = d->op1;
47603   else
47604     dcopy.op0 = dcopy.op1 = d->op0;
47605   if (!d->testing_p)
47606     dcopy.target = gen_reg_rtx (vmode);
47607   dcopy.one_operand_p = true;
47608
47609   for (i = 0; i < nelt; ++i)
47610     dcopy.perm[i] = d->perm[i] & (nelt - 1);
47611
47612   ok = expand_vec_perm_1 (&dcopy);
47613   if (GET_MODE_SIZE (vmode) != 16 && !ok)
47614     return false;
47615   else
47616     gcc_assert (ok);
47617   if (d->testing_p)
47618     return true;
47619
47620   /* Next we put permuted elements into their positions.  */
47621   dcopy1 = *d;
47622   if (which == 2)
47623     dcopy1.op1 = dcopy.target;
47624   else
47625     dcopy1.op0 = dcopy.target;
47626
47627   for (i = 0; i < nelt; ++i)
47628     dcopy1.perm[i] = ((d->perm[i] >= nelt) ? (nelt + i) : i);
47629
47630   ok = expand_vec_perm_blend (&dcopy1);
47631   gcc_assert (ok);
47632
47633   return true;
47634 }
47635
47636 static bool expand_vec_perm_interleave3 (struct expand_vec_perm_d *d);
47637
47638 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47639    a two vector permutation into a single vector permutation by using
47640    an interleave operation to merge the vectors.  */
47641
47642 static bool
47643 expand_vec_perm_interleave2 (struct expand_vec_perm_d *d)
47644 {
47645   struct expand_vec_perm_d dremap, dfinal;
47646   unsigned i, nelt = d->nelt, nelt2 = nelt / 2;
47647   unsigned HOST_WIDE_INT contents;
47648   unsigned char remap[2 * MAX_VECT_LEN];
47649   rtx_insn *seq;
47650   bool ok, same_halves = false;
47651
47652   if (GET_MODE_SIZE (d->vmode) == 16)
47653     {
47654       if (d->one_operand_p)
47655         return false;
47656     }
47657   else if (GET_MODE_SIZE (d->vmode) == 32)
47658     {
47659       if (!TARGET_AVX)
47660         return false;
47661       /* For 32-byte modes allow even d->one_operand_p.
47662          The lack of cross-lane shuffling in some instructions
47663          might prevent a single insn shuffle.  */
47664       dfinal = *d;
47665       dfinal.testing_p = true;
47666       /* If expand_vec_perm_interleave3 can expand this into
47667          a 3 insn sequence, give up and let it be expanded as
47668          3 insn sequence.  While that is one insn longer,
47669          it doesn't need a memory operand and in the common
47670          case that both interleave low and high permutations
47671          with the same operands are adjacent needs 4 insns
47672          for both after CSE.  */
47673       if (expand_vec_perm_interleave3 (&dfinal))
47674         return false;
47675     }
47676   else
47677     return false;
47678
47679   /* Examine from whence the elements come.  */
47680   contents = 0;
47681   for (i = 0; i < nelt; ++i)
47682     contents |= ((unsigned HOST_WIDE_INT) 1) << d->perm[i];
47683
47684   memset (remap, 0xff, sizeof (remap));
47685   dremap = *d;
47686
47687   if (GET_MODE_SIZE (d->vmode) == 16)
47688     {
47689       unsigned HOST_WIDE_INT h1, h2, h3, h4;
47690
47691       /* Split the two input vectors into 4 halves.  */
47692       h1 = (((unsigned HOST_WIDE_INT) 1) << nelt2) - 1;
47693       h2 = h1 << nelt2;
47694       h3 = h2 << nelt2;
47695       h4 = h3 << nelt2;
47696
47697       /* If the elements from the low halves use interleave low, and similarly
47698          for interleave high.  If the elements are from mis-matched halves, we
47699          can use shufps for V4SF/V4SI or do a DImode shuffle.  */
47700       if ((contents & (h1 | h3)) == contents)
47701         {
47702           /* punpckl* */
47703           for (i = 0; i < nelt2; ++i)
47704             {
47705               remap[i] = i * 2;
47706               remap[i + nelt] = i * 2 + 1;
47707               dremap.perm[i * 2] = i;
47708               dremap.perm[i * 2 + 1] = i + nelt;
47709             }
47710           if (!TARGET_SSE2 && d->vmode == V4SImode)
47711             dremap.vmode = V4SFmode;
47712         }
47713       else if ((contents & (h2 | h4)) == contents)
47714         {
47715           /* punpckh* */
47716           for (i = 0; i < nelt2; ++i)
47717             {
47718               remap[i + nelt2] = i * 2;
47719               remap[i + nelt + nelt2] = i * 2 + 1;
47720               dremap.perm[i * 2] = i + nelt2;
47721               dremap.perm[i * 2 + 1] = i + nelt + nelt2;
47722             }
47723           if (!TARGET_SSE2 && d->vmode == V4SImode)
47724             dremap.vmode = V4SFmode;
47725         }
47726       else if ((contents & (h1 | h4)) == contents)
47727         {
47728           /* shufps */
47729           for (i = 0; i < nelt2; ++i)
47730             {
47731               remap[i] = i;
47732               remap[i + nelt + nelt2] = i + nelt2;
47733               dremap.perm[i] = i;
47734               dremap.perm[i + nelt2] = i + nelt + nelt2;
47735             }
47736           if (nelt != 4)
47737             {
47738               /* shufpd */
47739               dremap.vmode = V2DImode;
47740               dremap.nelt = 2;
47741               dremap.perm[0] = 0;
47742               dremap.perm[1] = 3;
47743             }
47744         }
47745       else if ((contents & (h2 | h3)) == contents)
47746         {
47747           /* shufps */
47748           for (i = 0; i < nelt2; ++i)
47749             {
47750               remap[i + nelt2] = i;
47751               remap[i + nelt] = i + nelt2;
47752               dremap.perm[i] = i + nelt2;
47753               dremap.perm[i + nelt2] = i + nelt;
47754             }
47755           if (nelt != 4)
47756             {
47757               /* shufpd */
47758               dremap.vmode = V2DImode;
47759               dremap.nelt = 2;
47760               dremap.perm[0] = 1;
47761               dremap.perm[1] = 2;
47762             }
47763         }
47764       else
47765         return false;
47766     }
47767   else
47768     {
47769       unsigned int nelt4 = nelt / 4, nzcnt = 0;
47770       unsigned HOST_WIDE_INT q[8];
47771       unsigned int nonzero_halves[4];
47772
47773       /* Split the two input vectors into 8 quarters.  */
47774       q[0] = (((unsigned HOST_WIDE_INT) 1) << nelt4) - 1;
47775       for (i = 1; i < 8; ++i)
47776         q[i] = q[0] << (nelt4 * i);
47777       for (i = 0; i < 4; ++i)
47778         if (((q[2 * i] | q[2 * i + 1]) & contents) != 0)
47779           {
47780             nonzero_halves[nzcnt] = i;
47781             ++nzcnt;
47782           }
47783
47784       if (nzcnt == 1)
47785         {
47786           gcc_assert (d->one_operand_p);
47787           nonzero_halves[1] = nonzero_halves[0];
47788           same_halves = true;
47789         }
47790       else if (d->one_operand_p)
47791         {
47792           gcc_assert (nonzero_halves[0] == 0);
47793           gcc_assert (nonzero_halves[1] == 1);
47794         }
47795
47796       if (nzcnt <= 2)
47797         {
47798           if (d->perm[0] / nelt2 == nonzero_halves[1])
47799             {
47800               /* Attempt to increase the likelihood that dfinal
47801                  shuffle will be intra-lane.  */
47802               char tmph = nonzero_halves[0];
47803               nonzero_halves[0] = nonzero_halves[1];
47804               nonzero_halves[1] = tmph;
47805             }
47806
47807           /* vperm2f128 or vperm2i128.  */
47808           for (i = 0; i < nelt2; ++i)
47809             {
47810               remap[i + nonzero_halves[1] * nelt2] = i + nelt2;
47811               remap[i + nonzero_halves[0] * nelt2] = i;
47812               dremap.perm[i + nelt2] = i + nonzero_halves[1] * nelt2;
47813               dremap.perm[i] = i + nonzero_halves[0] * nelt2;
47814             }
47815
47816           if (d->vmode != V8SFmode
47817               && d->vmode != V4DFmode
47818               && d->vmode != V8SImode)
47819             {
47820               dremap.vmode = V8SImode;
47821               dremap.nelt = 8;
47822               for (i = 0; i < 4; ++i)
47823                 {
47824                   dremap.perm[i] = i + nonzero_halves[0] * 4;
47825                   dremap.perm[i + 4] = i + nonzero_halves[1] * 4;
47826                 }
47827             }
47828         }
47829       else if (d->one_operand_p)
47830         return false;
47831       else if (TARGET_AVX2
47832                && (contents & (q[0] | q[2] | q[4] | q[6])) == contents)
47833         {
47834           /* vpunpckl* */
47835           for (i = 0; i < nelt4; ++i)
47836             {
47837               remap[i] = i * 2;
47838               remap[i + nelt] = i * 2 + 1;
47839               remap[i + nelt2] = i * 2 + nelt2;
47840               remap[i + nelt + nelt2] = i * 2 + nelt2 + 1;
47841               dremap.perm[i * 2] = i;
47842               dremap.perm[i * 2 + 1] = i + nelt;
47843               dremap.perm[i * 2 + nelt2] = i + nelt2;
47844               dremap.perm[i * 2 + nelt2 + 1] = i + nelt + nelt2;
47845             }
47846         }
47847       else if (TARGET_AVX2
47848                && (contents & (q[1] | q[3] | q[5] | q[7])) == contents)
47849         {
47850           /* vpunpckh* */
47851           for (i = 0; i < nelt4; ++i)
47852             {
47853               remap[i + nelt4] = i * 2;
47854               remap[i + nelt + nelt4] = i * 2 + 1;
47855               remap[i + nelt2 + nelt4] = i * 2 + nelt2;
47856               remap[i + nelt + nelt2 + nelt4] = i * 2 + nelt2 + 1;
47857               dremap.perm[i * 2] = i + nelt4;
47858               dremap.perm[i * 2 + 1] = i + nelt + nelt4;
47859               dremap.perm[i * 2 + nelt2] = i + nelt2 + nelt4;
47860               dremap.perm[i * 2 + nelt2 + 1] = i + nelt + nelt2 + nelt4;
47861             }
47862         }
47863       else
47864         return false;
47865     }
47866
47867   /* Use the remapping array set up above to move the elements from their
47868      swizzled locations into their final destinations.  */
47869   dfinal = *d;
47870   for (i = 0; i < nelt; ++i)
47871     {
47872       unsigned e = remap[d->perm[i]];
47873       gcc_assert (e < nelt);
47874       /* If same_halves is true, both halves of the remapped vector are the
47875          same.  Avoid cross-lane accesses if possible.  */
47876       if (same_halves && i >= nelt2)
47877         {
47878           gcc_assert (e < nelt2);
47879           dfinal.perm[i] = e + nelt2;
47880         }
47881       else
47882         dfinal.perm[i] = e;
47883     }
47884   if (!d->testing_p)
47885     {
47886       dremap.target = gen_reg_rtx (dremap.vmode);
47887       dfinal.op0 = gen_lowpart (dfinal.vmode, dremap.target);
47888     }
47889   dfinal.op1 = dfinal.op0;
47890   dfinal.one_operand_p = true;
47891
47892   /* Test if the final remap can be done with a single insn.  For V4SFmode or
47893      V4SImode this *will* succeed.  For V8HImode or V16QImode it may not.  */
47894   start_sequence ();
47895   ok = expand_vec_perm_1 (&dfinal);
47896   seq = get_insns ();
47897   end_sequence ();
47898
47899   if (!ok)
47900     return false;
47901
47902   if (d->testing_p)
47903     return true;
47904
47905   if (dremap.vmode != dfinal.vmode)
47906     {
47907       dremap.op0 = gen_lowpart (dremap.vmode, dremap.op0);
47908       dremap.op1 = gen_lowpart (dremap.vmode, dremap.op1);
47909     }
47910
47911   ok = expand_vec_perm_1 (&dremap);
47912   gcc_assert (ok);
47913
47914   emit_insn (seq);
47915   return true;
47916 }
47917
47918 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47919    a single vector cross-lane permutation into vpermq followed
47920    by any of the single insn permutations.  */
47921
47922 static bool
47923 expand_vec_perm_vpermq_perm_1 (struct expand_vec_perm_d *d)
47924 {
47925   struct expand_vec_perm_d dremap, dfinal;
47926   unsigned i, j, nelt = d->nelt, nelt2 = nelt / 2, nelt4 = nelt / 4;
47927   unsigned contents[2];
47928   bool ok;
47929
47930   if (!(TARGET_AVX2
47931         && (d->vmode == V32QImode || d->vmode == V16HImode)
47932         && d->one_operand_p))
47933     return false;
47934
47935   contents[0] = 0;
47936   contents[1] = 0;
47937   for (i = 0; i < nelt2; ++i)
47938     {
47939       contents[0] |= 1u << (d->perm[i] / nelt4);
47940       contents[1] |= 1u << (d->perm[i + nelt2] / nelt4);
47941     }
47942
47943   for (i = 0; i < 2; ++i)
47944     {
47945       unsigned int cnt = 0;
47946       for (j = 0; j < 4; ++j)
47947         if ((contents[i] & (1u << j)) != 0 && ++cnt > 2)
47948           return false;
47949     }
47950
47951   if (d->testing_p)
47952     return true;
47953
47954   dremap = *d;
47955   dremap.vmode = V4DImode;
47956   dremap.nelt = 4;
47957   dremap.target = gen_reg_rtx (V4DImode);
47958   dremap.op0 = gen_lowpart (V4DImode, d->op0);
47959   dremap.op1 = dremap.op0;
47960   dremap.one_operand_p = true;
47961   for (i = 0; i < 2; ++i)
47962     {
47963       unsigned int cnt = 0;
47964       for (j = 0; j < 4; ++j)
47965         if ((contents[i] & (1u << j)) != 0)
47966           dremap.perm[2 * i + cnt++] = j;
47967       for (; cnt < 2; ++cnt)
47968         dremap.perm[2 * i + cnt] = 0;
47969     }
47970
47971   dfinal = *d;
47972   dfinal.op0 = gen_lowpart (dfinal.vmode, dremap.target);
47973   dfinal.op1 = dfinal.op0;
47974   dfinal.one_operand_p = true;
47975   for (i = 0, j = 0; i < nelt; ++i)
47976     {
47977       if (i == nelt2)
47978         j = 2;
47979       dfinal.perm[i] = (d->perm[i] & (nelt4 - 1)) | (j ? nelt2 : 0);
47980       if ((d->perm[i] / nelt4) == dremap.perm[j])
47981         ;
47982       else if ((d->perm[i] / nelt4) == dremap.perm[j + 1])
47983         dfinal.perm[i] |= nelt4;
47984       else
47985         gcc_unreachable ();
47986     }
47987
47988   ok = expand_vec_perm_1 (&dremap);
47989   gcc_assert (ok);
47990
47991   ok = expand_vec_perm_1 (&dfinal);
47992   gcc_assert (ok);
47993
47994   return true;
47995 }
47996
47997 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to expand
47998    a vector permutation using two instructions, vperm2f128 resp.
47999    vperm2i128 followed by any single in-lane permutation.  */
48000
48001 static bool
48002 expand_vec_perm_vperm2f128 (struct expand_vec_perm_d *d)
48003 {
48004   struct expand_vec_perm_d dfirst, dsecond;
48005   unsigned i, j, nelt = d->nelt, nelt2 = nelt / 2, perm;
48006   bool ok;
48007
48008   if (!TARGET_AVX
48009       || GET_MODE_SIZE (d->vmode) != 32
48010       || (d->vmode != V8SFmode && d->vmode != V4DFmode && !TARGET_AVX2))
48011     return false;
48012
48013   dsecond = *d;
48014   dsecond.one_operand_p = false;
48015   dsecond.testing_p = true;
48016
48017   /* ((perm << 2)|perm) & 0x33 is the vperm2[fi]128
48018      immediate.  For perm < 16 the second permutation uses
48019      d->op0 as first operand, for perm >= 16 it uses d->op1
48020      as first operand.  The second operand is the result of
48021      vperm2[fi]128.  */
48022   for (perm = 0; perm < 32; perm++)
48023     {
48024       /* Ignore permutations which do not move anything cross-lane.  */
48025       if (perm < 16)
48026         {
48027           /* The second shuffle for e.g. V4DFmode has
48028              0123 and ABCD operands.
48029              Ignore AB23, as 23 is already in the second lane
48030              of the first operand.  */
48031           if ((perm & 0xc) == (1 << 2)) continue;
48032           /* And 01CD, as 01 is in the first lane of the first
48033              operand.  */
48034           if ((perm & 3) == 0) continue;
48035           /* And 4567, as then the vperm2[fi]128 doesn't change
48036              anything on the original 4567 second operand.  */
48037           if ((perm & 0xf) == ((3 << 2) | 2)) continue;
48038         }
48039       else
48040         {
48041           /* The second shuffle for e.g. V4DFmode has
48042              4567 and ABCD operands.
48043              Ignore AB67, as 67 is already in the second lane
48044              of the first operand.  */
48045           if ((perm & 0xc) == (3 << 2)) continue;
48046           /* And 45CD, as 45 is in the first lane of the first
48047              operand.  */
48048           if ((perm & 3) == 2) continue;
48049           /* And 0123, as then the vperm2[fi]128 doesn't change
48050              anything on the original 0123 first operand.  */
48051           if ((perm & 0xf) == (1 << 2)) continue;
48052         }
48053
48054       for (i = 0; i < nelt; i++)
48055         {
48056           j = d->perm[i] / nelt2;
48057           if (j == ((perm >> (2 * (i >= nelt2))) & 3))
48058             dsecond.perm[i] = nelt + (i & nelt2) + (d->perm[i] & (nelt2 - 1));
48059           else if (j == (unsigned) (i >= nelt2) + 2 * (perm >= 16))
48060             dsecond.perm[i] = d->perm[i] & (nelt - 1);
48061           else
48062             break;
48063         }
48064
48065       if (i == nelt)
48066         {
48067           start_sequence ();
48068           ok = expand_vec_perm_1 (&dsecond);
48069           end_sequence ();
48070         }
48071       else
48072         ok = false;
48073
48074       if (ok)
48075         {
48076           if (d->testing_p)
48077             return true;
48078
48079           /* Found a usable second shuffle.  dfirst will be
48080              vperm2f128 on d->op0 and d->op1.  */
48081           dsecond.testing_p = false;
48082           dfirst = *d;
48083           dfirst.target = gen_reg_rtx (d->vmode);
48084           for (i = 0; i < nelt; i++)
48085             dfirst.perm[i] = (i & (nelt2 - 1))
48086                              + ((perm >> (2 * (i >= nelt2))) & 3) * nelt2;
48087
48088           canonicalize_perm (&dfirst);
48089           ok = expand_vec_perm_1 (&dfirst);
48090           gcc_assert (ok);
48091
48092           /* And dsecond is some single insn shuffle, taking
48093              d->op0 and result of vperm2f128 (if perm < 16) or
48094              d->op1 and result of vperm2f128 (otherwise).  */
48095           if (perm >= 16)
48096             dsecond.op0 = dsecond.op1;
48097           dsecond.op1 = dfirst.target;
48098
48099           ok = expand_vec_perm_1 (&dsecond);
48100           gcc_assert (ok);
48101
48102           return true;
48103         }
48104
48105       /* For one operand, the only useful vperm2f128 permutation is 0x01
48106          aka lanes swap.  */
48107       if (d->one_operand_p)
48108         return false;
48109     }
48110
48111   return false;
48112 }
48113
48114 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
48115    a two vector permutation using 2 intra-lane interleave insns
48116    and cross-lane shuffle for 32-byte vectors.  */
48117
48118 static bool
48119 expand_vec_perm_interleave3 (struct expand_vec_perm_d *d)
48120 {
48121   unsigned i, nelt;
48122   rtx (*gen) (rtx, rtx, rtx);
48123
48124   if (d->one_operand_p)
48125     return false;
48126   if (TARGET_AVX2 && GET_MODE_SIZE (d->vmode) == 32)
48127     ;
48128   else if (TARGET_AVX && (d->vmode == V8SFmode || d->vmode == V4DFmode))
48129     ;
48130   else
48131     return false;
48132
48133   nelt = d->nelt;
48134   if (d->perm[0] != 0 && d->perm[0] != nelt / 2)
48135     return false;
48136   for (i = 0; i < nelt; i += 2)
48137     if (d->perm[i] != d->perm[0] + i / 2
48138         || d->perm[i + 1] != d->perm[0] + i / 2 + nelt)
48139       return false;
48140
48141   if (d->testing_p)
48142     return true;
48143
48144   switch (d->vmode)
48145     {
48146     case V32QImode:
48147       if (d->perm[0])
48148         gen = gen_vec_interleave_highv32qi;
48149       else
48150         gen = gen_vec_interleave_lowv32qi;
48151       break;
48152     case V16HImode:
48153       if (d->perm[0])
48154         gen = gen_vec_interleave_highv16hi;
48155       else
48156         gen = gen_vec_interleave_lowv16hi;
48157       break;
48158     case V8SImode:
48159       if (d->perm[0])
48160         gen = gen_vec_interleave_highv8si;
48161       else
48162         gen = gen_vec_interleave_lowv8si;
48163       break;
48164     case V4DImode:
48165       if (d->perm[0])
48166         gen = gen_vec_interleave_highv4di;
48167       else
48168         gen = gen_vec_interleave_lowv4di;
48169       break;
48170     case V8SFmode:
48171       if (d->perm[0])
48172         gen = gen_vec_interleave_highv8sf;
48173       else
48174         gen = gen_vec_interleave_lowv8sf;
48175       break;
48176     case V4DFmode:
48177       if (d->perm[0])
48178         gen = gen_vec_interleave_highv4df;
48179       else
48180         gen = gen_vec_interleave_lowv4df;
48181       break;
48182     default:
48183       gcc_unreachable ();
48184     }
48185
48186   emit_insn (gen (d->target, d->op0, d->op1));
48187   return true;
48188 }
48189
48190 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement
48191    a single vector permutation using a single intra-lane vector
48192    permutation, vperm2f128 swapping the lanes and vblend* insn blending
48193    the non-swapped and swapped vectors together.  */
48194
48195 static bool
48196 expand_vec_perm_vperm2f128_vblend (struct expand_vec_perm_d *d)
48197 {
48198   struct expand_vec_perm_d dfirst, dsecond;
48199   unsigned i, j, msk, nelt = d->nelt, nelt2 = nelt / 2;
48200   rtx_insn *seq;
48201   bool ok;
48202   rtx (*blend) (rtx, rtx, rtx, rtx) = NULL;
48203
48204   if (!TARGET_AVX
48205       || TARGET_AVX2
48206       || (d->vmode != V8SFmode && d->vmode != V4DFmode)
48207       || !d->one_operand_p)
48208     return false;
48209
48210   dfirst = *d;
48211   for (i = 0; i < nelt; i++)
48212     dfirst.perm[i] = 0xff;
48213   for (i = 0, msk = 0; i < nelt; i++)
48214     {
48215       j = (d->perm[i] & nelt2) ? i | nelt2 : i & ~nelt2;
48216       if (dfirst.perm[j] != 0xff && dfirst.perm[j] != d->perm[i])
48217         return false;
48218       dfirst.perm[j] = d->perm[i];
48219       if (j != i)
48220         msk |= (1 << i);
48221     }
48222   for (i = 0; i < nelt; i++)
48223     if (dfirst.perm[i] == 0xff)
48224       dfirst.perm[i] = i;
48225
48226   if (!d->testing_p)
48227     dfirst.target = gen_reg_rtx (dfirst.vmode);
48228
48229   start_sequence ();
48230   ok = expand_vec_perm_1 (&dfirst);
48231   seq = get_insns ();
48232   end_sequence ();
48233
48234   if (!ok)
48235     return false;
48236
48237   if (d->testing_p)
48238     return true;
48239
48240   emit_insn (seq);
48241
48242   dsecond = *d;
48243   dsecond.op0 = dfirst.target;
48244   dsecond.op1 = dfirst.target;
48245   dsecond.one_operand_p = true;
48246   dsecond.target = gen_reg_rtx (dsecond.vmode);
48247   for (i = 0; i < nelt; i++)
48248     dsecond.perm[i] = i ^ nelt2;
48249
48250   ok = expand_vec_perm_1 (&dsecond);
48251   gcc_assert (ok);
48252
48253   blend = d->vmode == V8SFmode ? gen_avx_blendps256 : gen_avx_blendpd256;
48254   emit_insn (blend (d->target, dfirst.target, dsecond.target, GEN_INT (msk)));
48255   return true;
48256 }
48257
48258 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement a V4DF
48259    permutation using two vperm2f128, followed by a vshufpd insn blending
48260    the two vectors together.  */
48261
48262 static bool
48263 expand_vec_perm_2vperm2f128_vshuf (struct expand_vec_perm_d *d)
48264 {
48265   struct expand_vec_perm_d dfirst, dsecond, dthird;
48266   bool ok;
48267
48268   if (!TARGET_AVX || (d->vmode != V4DFmode))
48269     return false;
48270
48271   if (d->testing_p)
48272     return true;
48273
48274   dfirst = *d;
48275   dsecond = *d;
48276   dthird = *d;
48277
48278   dfirst.perm[0] = (d->perm[0] & ~1);
48279   dfirst.perm[1] = (d->perm[0] & ~1) + 1;
48280   dfirst.perm[2] = (d->perm[2] & ~1);
48281   dfirst.perm[3] = (d->perm[2] & ~1) + 1;
48282   dsecond.perm[0] = (d->perm[1] & ~1);
48283   dsecond.perm[1] = (d->perm[1] & ~1) + 1;
48284   dsecond.perm[2] = (d->perm[3] & ~1);
48285   dsecond.perm[3] = (d->perm[3] & ~1) + 1;
48286   dthird.perm[0] = (d->perm[0] % 2);
48287   dthird.perm[1] = (d->perm[1] % 2) + 4;
48288   dthird.perm[2] = (d->perm[2] % 2) + 2;
48289   dthird.perm[3] = (d->perm[3] % 2) + 6;
48290
48291   dfirst.target = gen_reg_rtx (dfirst.vmode);
48292   dsecond.target = gen_reg_rtx (dsecond.vmode);
48293   dthird.op0 = dfirst.target;
48294   dthird.op1 = dsecond.target;
48295   dthird.one_operand_p = false;
48296
48297   canonicalize_perm (&dfirst);
48298   canonicalize_perm (&dsecond);
48299
48300   ok = expand_vec_perm_1 (&dfirst)
48301        && expand_vec_perm_1 (&dsecond)
48302        && expand_vec_perm_1 (&dthird);
48303
48304   gcc_assert (ok);
48305
48306   return true;
48307 }
48308
48309 /* A subroutine of expand_vec_perm_even_odd_1.  Implement the double-word
48310    permutation with two pshufb insns and an ior.  We should have already
48311    failed all two instruction sequences.  */
48312
48313 static bool
48314 expand_vec_perm_pshufb2 (struct expand_vec_perm_d *d)
48315 {
48316   rtx rperm[2][16], vperm, l, h, op, m128;
48317   unsigned int i, nelt, eltsz;
48318
48319   if (!TARGET_SSSE3 || GET_MODE_SIZE (d->vmode) != 16)
48320     return false;
48321   gcc_assert (!d->one_operand_p);
48322
48323   if (d->testing_p)
48324     return true;
48325
48326   nelt = d->nelt;
48327   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48328
48329   /* Generate two permutation masks.  If the required element is within
48330      the given vector it is shuffled into the proper lane.  If the required
48331      element is in the other vector, force a zero into the lane by setting
48332      bit 7 in the permutation mask.  */
48333   m128 = GEN_INT (-128);
48334   for (i = 0; i < nelt; ++i)
48335     {
48336       unsigned j, e = d->perm[i];
48337       unsigned which = (e >= nelt);
48338       if (e >= nelt)
48339         e -= nelt;
48340
48341       for (j = 0; j < eltsz; ++j)
48342         {
48343           rperm[which][i*eltsz + j] = GEN_INT (e*eltsz + j);
48344           rperm[1-which][i*eltsz + j] = m128;
48345         }
48346     }
48347
48348   vperm = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, rperm[0]));
48349   vperm = force_reg (V16QImode, vperm);
48350
48351   l = gen_reg_rtx (V16QImode);
48352   op = gen_lowpart (V16QImode, d->op0);
48353   emit_insn (gen_ssse3_pshufbv16qi3 (l, op, vperm));
48354
48355   vperm = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, rperm[1]));
48356   vperm = force_reg (V16QImode, vperm);
48357
48358   h = gen_reg_rtx (V16QImode);
48359   op = gen_lowpart (V16QImode, d->op1);
48360   emit_insn (gen_ssse3_pshufbv16qi3 (h, op, vperm));
48361
48362   op = d->target;
48363   if (d->vmode != V16QImode)
48364     op = gen_reg_rtx (V16QImode);
48365   emit_insn (gen_iorv16qi3 (op, l, h));
48366   if (op != d->target)
48367     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48368
48369   return true;
48370 }
48371
48372 /* Implement arbitrary permutation of one V32QImode and V16QImode operand
48373    with two vpshufb insns, vpermq and vpor.  We should have already failed
48374    all two or three instruction sequences.  */
48375
48376 static bool
48377 expand_vec_perm_vpshufb2_vpermq (struct expand_vec_perm_d *d)
48378 {
48379   rtx rperm[2][32], vperm, l, h, hp, op, m128;
48380   unsigned int i, nelt, eltsz;
48381
48382   if (!TARGET_AVX2
48383       || !d->one_operand_p
48384       || (d->vmode != V32QImode && d->vmode != V16HImode))
48385     return false;
48386
48387   if (d->testing_p)
48388     return true;
48389
48390   nelt = d->nelt;
48391   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48392
48393   /* Generate two permutation masks.  If the required element is within
48394      the same lane, it is shuffled in.  If the required element from the
48395      other lane, force a zero by setting bit 7 in the permutation mask.
48396      In the other mask the mask has non-negative elements if element
48397      is requested from the other lane, but also moved to the other lane,
48398      so that the result of vpshufb can have the two V2TImode halves
48399      swapped.  */
48400   m128 = GEN_INT (-128);
48401   for (i = 0; i < nelt; ++i)
48402     {
48403       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
48404       unsigned which = ((d->perm[i] ^ i) & (nelt / 2)) * eltsz;
48405
48406       for (j = 0; j < eltsz; ++j)
48407         {
48408           rperm[!!which][(i * eltsz + j) ^ which] = GEN_INT (e * eltsz + j);
48409           rperm[!which][(i * eltsz + j) ^ (which ^ 16)] = m128;
48410         }
48411     }
48412
48413   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[1]));
48414   vperm = force_reg (V32QImode, vperm);
48415
48416   h = gen_reg_rtx (V32QImode);
48417   op = gen_lowpart (V32QImode, d->op0);
48418   emit_insn (gen_avx2_pshufbv32qi3 (h, op, vperm));
48419
48420   /* Swap the 128-byte lanes of h into hp.  */
48421   hp = gen_reg_rtx (V4DImode);
48422   op = gen_lowpart (V4DImode, h);
48423   emit_insn (gen_avx2_permv4di_1 (hp, op, const2_rtx, GEN_INT (3), const0_rtx,
48424                                   const1_rtx));
48425
48426   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[0]));
48427   vperm = force_reg (V32QImode, vperm);
48428
48429   l = gen_reg_rtx (V32QImode);
48430   op = gen_lowpart (V32QImode, d->op0);
48431   emit_insn (gen_avx2_pshufbv32qi3 (l, op, vperm));
48432
48433   op = d->target;
48434   if (d->vmode != V32QImode)
48435     op = gen_reg_rtx (V32QImode);
48436   emit_insn (gen_iorv32qi3 (op, l, gen_lowpart (V32QImode, hp)));
48437   if (op != d->target)
48438     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48439
48440   return true;
48441 }
48442
48443 /* A subroutine of expand_vec_perm_even_odd_1.  Implement extract-even
48444    and extract-odd permutations of two V32QImode and V16QImode operand
48445    with two vpshufb insns, vpor and vpermq.  We should have already
48446    failed all two or three instruction sequences.  */
48447
48448 static bool
48449 expand_vec_perm_vpshufb2_vpermq_even_odd (struct expand_vec_perm_d *d)
48450 {
48451   rtx rperm[2][32], vperm, l, h, ior, op, m128;
48452   unsigned int i, nelt, eltsz;
48453
48454   if (!TARGET_AVX2
48455       || d->one_operand_p
48456       || (d->vmode != V32QImode && d->vmode != V16HImode))
48457     return false;
48458
48459   for (i = 0; i < d->nelt; ++i)
48460     if ((d->perm[i] ^ (i * 2)) & (3 * d->nelt / 2))
48461       return false;
48462
48463   if (d->testing_p)
48464     return true;
48465
48466   nelt = d->nelt;
48467   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48468
48469   /* Generate two permutation masks.  In the first permutation mask
48470      the first quarter will contain indexes for the first half
48471      of the op0, the second quarter will contain bit 7 set, third quarter
48472      will contain indexes for the second half of the op0 and the
48473      last quarter bit 7 set.  In the second permutation mask
48474      the first quarter will contain bit 7 set, the second quarter
48475      indexes for the first half of the op1, the third quarter bit 7 set
48476      and last quarter indexes for the second half of the op1.
48477      I.e. the first mask e.g. for V32QImode extract even will be:
48478      0, 2, ..., 0xe, -128, ..., -128, 0, 2, ..., 0xe, -128, ..., -128
48479      (all values masked with 0xf except for -128) and second mask
48480      for extract even will be
48481      -128, ..., -128, 0, 2, ..., 0xe, -128, ..., -128, 0, 2, ..., 0xe.  */
48482   m128 = GEN_INT (-128);
48483   for (i = 0; i < nelt; ++i)
48484     {
48485       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
48486       unsigned which = d->perm[i] >= nelt;
48487       unsigned xorv = (i >= nelt / 4 && i < 3 * nelt / 4) ? 24 : 0;
48488
48489       for (j = 0; j < eltsz; ++j)
48490         {
48491           rperm[which][(i * eltsz + j) ^ xorv] = GEN_INT (e * eltsz + j);
48492           rperm[1 - which][(i * eltsz + j) ^ xorv] = m128;
48493         }
48494     }
48495
48496   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[0]));
48497   vperm = force_reg (V32QImode, vperm);
48498
48499   l = gen_reg_rtx (V32QImode);
48500   op = gen_lowpart (V32QImode, d->op0);
48501   emit_insn (gen_avx2_pshufbv32qi3 (l, op, vperm));
48502
48503   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[1]));
48504   vperm = force_reg (V32QImode, vperm);
48505
48506   h = gen_reg_rtx (V32QImode);
48507   op = gen_lowpart (V32QImode, d->op1);
48508   emit_insn (gen_avx2_pshufbv32qi3 (h, op, vperm));
48509
48510   ior = gen_reg_rtx (V32QImode);
48511   emit_insn (gen_iorv32qi3 (ior, l, h));
48512
48513   /* Permute the V4DImode quarters using { 0, 2, 1, 3 } permutation.  */
48514   op = gen_reg_rtx (V4DImode);
48515   ior = gen_lowpart (V4DImode, ior);
48516   emit_insn (gen_avx2_permv4di_1 (op, ior, const0_rtx, const2_rtx,
48517                                   const1_rtx, GEN_INT (3)));
48518   emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48519
48520   return true;
48521 }
48522
48523 /* A subroutine of expand_vec_perm_even_odd_1.  Implement extract-even
48524    and extract-odd permutations of two V16QI, V8HI, V16HI or V32QI operands
48525    with two "and" and "pack" or two "shift" and "pack" insns.  We should
48526    have already failed all two instruction sequences.  */
48527
48528 static bool
48529 expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d)
48530 {
48531   rtx op, dop0, dop1, t, rperm[16];
48532   unsigned i, odd, c, s, nelt = d->nelt;
48533   bool end_perm = false;
48534   machine_mode half_mode;
48535   rtx (*gen_and) (rtx, rtx, rtx);
48536   rtx (*gen_pack) (rtx, rtx, rtx);
48537   rtx (*gen_shift) (rtx, rtx, rtx);
48538
48539   if (d->one_operand_p)
48540     return false;
48541
48542   switch (d->vmode)
48543     {
48544     case V8HImode:
48545       /* Required for "pack".  */
48546       if (!TARGET_SSE4_1)
48547         return false;
48548       c = 0xffff;
48549       s = 16;
48550       half_mode = V4SImode;
48551       gen_and = gen_andv4si3;
48552       gen_pack = gen_sse4_1_packusdw;
48553       gen_shift = gen_lshrv4si3;
48554       break;
48555     case V16QImode:
48556       /* No check as all instructions are SSE2.  */
48557       c = 0xff;
48558       s = 8;
48559       half_mode = V8HImode;
48560       gen_and = gen_andv8hi3;
48561       gen_pack = gen_sse2_packuswb;
48562       gen_shift = gen_lshrv8hi3;
48563       break;
48564     case V16HImode:
48565       if (!TARGET_AVX2)
48566         return false;
48567       c = 0xffff;
48568       s = 16;
48569       half_mode = V8SImode;
48570       gen_and = gen_andv8si3;
48571       gen_pack = gen_avx2_packusdw;
48572       gen_shift = gen_lshrv8si3;
48573       end_perm = true;
48574       break;
48575     case V32QImode:
48576       if (!TARGET_AVX2)
48577         return false;
48578       c = 0xff;
48579       s = 8;
48580       half_mode = V16HImode;
48581       gen_and = gen_andv16hi3;
48582       gen_pack = gen_avx2_packuswb;
48583       gen_shift = gen_lshrv16hi3;
48584       end_perm = true;
48585       break;
48586     default:
48587       /* Only V8HI, V16QI, V16HI and V32QI modes are more profitable than
48588          general shuffles.  */
48589       return false;
48590     }
48591
48592   /* Check that permutation is even or odd.  */
48593   odd = d->perm[0];
48594   if (odd > 1)
48595     return false;
48596
48597   for (i = 1; i < nelt; ++i)
48598     if (d->perm[i] != 2 * i + odd)
48599       return false;
48600
48601   if (d->testing_p)
48602     return true;
48603
48604   dop0 = gen_reg_rtx (half_mode);
48605   dop1 = gen_reg_rtx (half_mode);
48606   if (odd == 0)
48607     {
48608       for (i = 0; i < nelt / 2; i++)
48609         rperm[i] = GEN_INT (c);
48610       t = gen_rtx_CONST_VECTOR (half_mode, gen_rtvec_v (nelt / 2, rperm));
48611       t = force_reg (half_mode, t);
48612       emit_insn (gen_and (dop0, t, gen_lowpart (half_mode, d->op0)));
48613       emit_insn (gen_and (dop1, t, gen_lowpart (half_mode, d->op1)));
48614     }
48615   else
48616     {
48617       emit_insn (gen_shift (dop0,
48618                             gen_lowpart (half_mode, d->op0),
48619                             GEN_INT (s)));
48620       emit_insn (gen_shift (dop1,
48621                             gen_lowpart (half_mode, d->op1),
48622                             GEN_INT (s)));
48623     }
48624   /* In AVX2 for 256 bit case we need to permute pack result.  */
48625   if (TARGET_AVX2 && end_perm)
48626     {
48627       op = gen_reg_rtx (d->vmode);
48628       t = gen_reg_rtx (V4DImode);
48629       emit_insn (gen_pack (op, dop0, dop1));
48630       emit_insn (gen_avx2_permv4di_1 (t,
48631                                       gen_lowpart (V4DImode, op),
48632                                       const0_rtx,
48633                                       const2_rtx,
48634                                       const1_rtx,
48635                                       GEN_INT (3)));
48636       emit_move_insn (d->target, gen_lowpart (d->vmode, t));
48637     }
48638   else
48639     emit_insn (gen_pack (d->target, dop0, dop1));
48640
48641   return true;
48642 }
48643
48644 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement extract-even
48645    and extract-odd permutations.  */
48646
48647 static bool
48648 expand_vec_perm_even_odd_1 (struct expand_vec_perm_d *d, unsigned odd)
48649 {
48650   rtx t1, t2, t3, t4, t5;
48651
48652   switch (d->vmode)
48653     {
48654     case V4DFmode:
48655       if (d->testing_p)
48656         break;
48657       t1 = gen_reg_rtx (V4DFmode);
48658       t2 = gen_reg_rtx (V4DFmode);
48659
48660       /* Shuffle the lanes around into { 0 1 4 5 } and { 2 3 6 7 }.  */
48661       emit_insn (gen_avx_vperm2f128v4df3 (t1, d->op0, d->op1, GEN_INT (0x20)));
48662       emit_insn (gen_avx_vperm2f128v4df3 (t2, d->op0, d->op1, GEN_INT (0x31)));
48663
48664       /* Now an unpck[lh]pd will produce the result required.  */
48665       if (odd)
48666         t3 = gen_avx_unpckhpd256 (d->target, t1, t2);
48667       else
48668         t3 = gen_avx_unpcklpd256 (d->target, t1, t2);
48669       emit_insn (t3);
48670       break;
48671
48672     case V8SFmode:
48673       {
48674         int mask = odd ? 0xdd : 0x88;
48675
48676         if (d->testing_p)
48677           break;
48678         t1 = gen_reg_rtx (V8SFmode);
48679         t2 = gen_reg_rtx (V8SFmode);
48680         t3 = gen_reg_rtx (V8SFmode);
48681
48682         /* Shuffle within the 128-bit lanes to produce:
48683            { 0 2 8 a 4 6 c e } | { 1 3 9 b 5 7 d f }.  */
48684         emit_insn (gen_avx_shufps256 (t1, d->op0, d->op1,
48685                                       GEN_INT (mask)));
48686
48687         /* Shuffle the lanes around to produce:
48688            { 4 6 c e 0 2 8 a } and { 5 7 d f 1 3 9 b }.  */
48689         emit_insn (gen_avx_vperm2f128v8sf3 (t2, t1, t1,
48690                                             GEN_INT (0x3)));
48691
48692         /* Shuffle within the 128-bit lanes to produce:
48693            { 0 2 4 6 4 6 0 2 } | { 1 3 5 7 5 7 1 3 }.  */
48694         emit_insn (gen_avx_shufps256 (t3, t1, t2, GEN_INT (0x44)));
48695
48696         /* Shuffle within the 128-bit lanes to produce:
48697            { 8 a c e c e 8 a } | { 9 b d f d f 9 b }.  */
48698         emit_insn (gen_avx_shufps256 (t2, t1, t2, GEN_INT (0xee)));
48699
48700         /* Shuffle the lanes around to produce:
48701            { 0 2 4 6 8 a c e } | { 1 3 5 7 9 b d f }.  */
48702         emit_insn (gen_avx_vperm2f128v8sf3 (d->target, t3, t2,
48703                                             GEN_INT (0x20)));
48704       }
48705       break;
48706
48707     case V2DFmode:
48708     case V4SFmode:
48709     case V2DImode:
48710     case V4SImode:
48711       /* These are always directly implementable by expand_vec_perm_1.  */
48712       gcc_unreachable ();
48713
48714     case V8HImode:
48715       if (TARGET_SSE4_1)
48716         return expand_vec_perm_even_odd_pack (d);
48717       else if (TARGET_SSSE3 && !TARGET_SLOW_PSHUFB)
48718         return expand_vec_perm_pshufb2 (d);
48719       else
48720         {
48721           if (d->testing_p)
48722             break;
48723           /* We need 2*log2(N)-1 operations to achieve odd/even
48724              with interleave. */
48725           t1 = gen_reg_rtx (V8HImode);
48726           t2 = gen_reg_rtx (V8HImode);
48727           emit_insn (gen_vec_interleave_highv8hi (t1, d->op0, d->op1));
48728           emit_insn (gen_vec_interleave_lowv8hi (d->target, d->op0, d->op1));
48729           emit_insn (gen_vec_interleave_highv8hi (t2, d->target, t1));
48730           emit_insn (gen_vec_interleave_lowv8hi (d->target, d->target, t1));
48731           if (odd)
48732             t3 = gen_vec_interleave_highv8hi (d->target, d->target, t2);
48733           else
48734             t3 = gen_vec_interleave_lowv8hi (d->target, d->target, t2);
48735           emit_insn (t3);
48736         }
48737       break;
48738
48739     case V16QImode:
48740       return expand_vec_perm_even_odd_pack (d);
48741
48742     case V16HImode:
48743     case V32QImode:
48744       return expand_vec_perm_even_odd_pack (d);
48745
48746     case V4DImode:
48747       if (!TARGET_AVX2)
48748         {
48749           struct expand_vec_perm_d d_copy = *d;
48750           d_copy.vmode = V4DFmode;
48751           if (d->testing_p)
48752             d_copy.target = gen_lowpart (V4DFmode, d->target);
48753           else
48754             d_copy.target = gen_reg_rtx (V4DFmode);
48755           d_copy.op0 = gen_lowpart (V4DFmode, d->op0);
48756           d_copy.op1 = gen_lowpart (V4DFmode, d->op1);
48757           if (expand_vec_perm_even_odd_1 (&d_copy, odd))
48758             {
48759               if (!d->testing_p)
48760                 emit_move_insn (d->target,
48761                                 gen_lowpart (V4DImode, d_copy.target));
48762               return true;
48763             }
48764           return false;
48765         }
48766
48767       if (d->testing_p)
48768         break;
48769
48770       t1 = gen_reg_rtx (V4DImode);
48771       t2 = gen_reg_rtx (V4DImode);
48772
48773       /* Shuffle the lanes around into { 0 1 4 5 } and { 2 3 6 7 }.  */
48774       emit_insn (gen_avx2_permv2ti (t1, d->op0, d->op1, GEN_INT (0x20)));
48775       emit_insn (gen_avx2_permv2ti (t2, d->op0, d->op1, GEN_INT (0x31)));
48776
48777       /* Now an vpunpck[lh]qdq will produce the result required.  */
48778       if (odd)
48779         t3 = gen_avx2_interleave_highv4di (d->target, t1, t2);
48780       else
48781         t3 = gen_avx2_interleave_lowv4di (d->target, t1, t2);
48782       emit_insn (t3);
48783       break;
48784
48785     case V8SImode:
48786       if (!TARGET_AVX2)
48787         {
48788           struct expand_vec_perm_d d_copy = *d;
48789           d_copy.vmode = V8SFmode;
48790           if (d->testing_p)
48791             d_copy.target = gen_lowpart (V8SFmode, d->target);
48792           else
48793             d_copy.target = gen_reg_rtx (V8SFmode);
48794           d_copy.op0 = gen_lowpart (V8SFmode, d->op0);
48795           d_copy.op1 = gen_lowpart (V8SFmode, d->op1);
48796           if (expand_vec_perm_even_odd_1 (&d_copy, odd))
48797             {
48798               if (!d->testing_p)
48799                 emit_move_insn (d->target,
48800                                 gen_lowpart (V8SImode, d_copy.target));
48801               return true;
48802             }
48803           return false;
48804         }
48805
48806       if (d->testing_p)
48807         break;
48808
48809       t1 = gen_reg_rtx (V8SImode);
48810       t2 = gen_reg_rtx (V8SImode);
48811       t3 = gen_reg_rtx (V4DImode);
48812       t4 = gen_reg_rtx (V4DImode);
48813       t5 = gen_reg_rtx (V4DImode);
48814
48815       /* Shuffle the lanes around into
48816          { 0 1 2 3 8 9 a b } and { 4 5 6 7 c d e f }.  */
48817       emit_insn (gen_avx2_permv2ti (t3, gen_lowpart (V4DImode, d->op0),
48818                                     gen_lowpart (V4DImode, d->op1),
48819                                     GEN_INT (0x20)));
48820       emit_insn (gen_avx2_permv2ti (t4, gen_lowpart (V4DImode, d->op0),
48821                                     gen_lowpart (V4DImode, d->op1),
48822                                     GEN_INT (0x31)));
48823
48824       /* Swap the 2nd and 3rd position in each lane into
48825          { 0 2 1 3 8 a 9 b } and { 4 6 5 7 c e d f }.  */
48826       emit_insn (gen_avx2_pshufdv3 (t1, gen_lowpart (V8SImode, t3),
48827                                     GEN_INT (2 * 4 + 1 * 16 + 3 * 64)));
48828       emit_insn (gen_avx2_pshufdv3 (t2, gen_lowpart (V8SImode, t4),
48829                                     GEN_INT (2 * 4 + 1 * 16 + 3 * 64)));
48830
48831       /* Now an vpunpck[lh]qdq will produce
48832          { 0 2 4 6 8 a c e } resp. { 1 3 5 7 9 b d f }.  */
48833       if (odd)
48834         t3 = gen_avx2_interleave_highv4di (t5, gen_lowpart (V4DImode, t1),
48835                                            gen_lowpart (V4DImode, t2));
48836       else
48837         t3 = gen_avx2_interleave_lowv4di (t5, gen_lowpart (V4DImode, t1),
48838                                           gen_lowpart (V4DImode, t2));
48839       emit_insn (t3);
48840       emit_move_insn (d->target, gen_lowpart (V8SImode, t5));
48841       break;
48842
48843     default:
48844       gcc_unreachable ();
48845     }
48846
48847   return true;
48848 }
48849
48850 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Pattern match
48851    extract-even and extract-odd permutations.  */
48852
48853 static bool
48854 expand_vec_perm_even_odd (struct expand_vec_perm_d *d)
48855 {
48856   unsigned i, odd, nelt = d->nelt;
48857
48858   odd = d->perm[0];
48859   if (odd != 0 && odd != 1)
48860     return false;
48861
48862   for (i = 1; i < nelt; ++i)
48863     if (d->perm[i] != 2 * i + odd)
48864       return false;
48865
48866   return expand_vec_perm_even_odd_1 (d, odd);
48867 }
48868
48869 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement broadcast
48870    permutations.  We assume that expand_vec_perm_1 has already failed.  */
48871
48872 static bool
48873 expand_vec_perm_broadcast_1 (struct expand_vec_perm_d *d)
48874 {
48875   unsigned elt = d->perm[0], nelt2 = d->nelt / 2;
48876   machine_mode vmode = d->vmode;
48877   unsigned char perm2[4];
48878   rtx op0 = d->op0, dest;
48879   bool ok;
48880
48881   switch (vmode)
48882     {
48883     case V4DFmode:
48884     case V8SFmode:
48885       /* These are special-cased in sse.md so that we can optionally
48886          use the vbroadcast instruction.  They expand to two insns
48887          if the input happens to be in a register.  */
48888       gcc_unreachable ();
48889
48890     case V2DFmode:
48891     case V2DImode:
48892     case V4SFmode:
48893     case V4SImode:
48894       /* These are always implementable using standard shuffle patterns.  */
48895       gcc_unreachable ();
48896
48897     case V8HImode:
48898     case V16QImode:
48899       /* These can be implemented via interleave.  We save one insn by
48900          stopping once we have promoted to V4SImode and then use pshufd.  */
48901       if (d->testing_p)
48902         return true;
48903       do
48904         {
48905           rtx dest;
48906           rtx (*gen) (rtx, rtx, rtx)
48907             = vmode == V16QImode ? gen_vec_interleave_lowv16qi
48908                                  : gen_vec_interleave_lowv8hi;
48909
48910           if (elt >= nelt2)
48911             {
48912               gen = vmode == V16QImode ? gen_vec_interleave_highv16qi
48913                                        : gen_vec_interleave_highv8hi;
48914               elt -= nelt2;
48915             }
48916           nelt2 /= 2;
48917
48918           dest = gen_reg_rtx (vmode);
48919           emit_insn (gen (dest, op0, op0));
48920           vmode = get_mode_wider_vector (vmode);
48921           op0 = gen_lowpart (vmode, dest);
48922         }
48923       while (vmode != V4SImode);
48924
48925       memset (perm2, elt, 4);
48926       dest = gen_reg_rtx (V4SImode);
48927       ok = expand_vselect (dest, op0, perm2, 4, d->testing_p);
48928       gcc_assert (ok);
48929       if (!d->testing_p)
48930         emit_move_insn (d->target, gen_lowpart (d->vmode, dest));
48931       return true;
48932
48933     case V64QImode:
48934     case V32QImode:
48935     case V16HImode:
48936     case V8SImode:
48937     case V4DImode:
48938       /* For AVX2 broadcasts of the first element vpbroadcast* or
48939          vpermq should be used by expand_vec_perm_1.  */
48940       gcc_assert (!TARGET_AVX2 || d->perm[0]);
48941       return false;
48942
48943     default:
48944       gcc_unreachable ();
48945     }
48946 }
48947
48948 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Pattern match
48949    broadcast permutations.  */
48950
48951 static bool
48952 expand_vec_perm_broadcast (struct expand_vec_perm_d *d)
48953 {
48954   unsigned i, elt, nelt = d->nelt;
48955
48956   if (!d->one_operand_p)
48957     return false;
48958
48959   elt = d->perm[0];
48960   for (i = 1; i < nelt; ++i)
48961     if (d->perm[i] != elt)
48962       return false;
48963
48964   return expand_vec_perm_broadcast_1 (d);
48965 }
48966
48967 /* Implement arbitrary permutations of two V64QImode operands
48968    will 2 vpermi2w, 2 vpshufb and one vpor instruction.  */
48969 static bool
48970 expand_vec_perm_vpermi2_vpshub2 (struct expand_vec_perm_d *d)
48971 {
48972   if (!TARGET_AVX512BW || !(d->vmode == V64QImode))
48973     return false;
48974
48975   if (d->testing_p)
48976     return true;
48977
48978   struct expand_vec_perm_d ds[2];
48979   rtx rperm[128], vperm, target0, target1;
48980   unsigned int i, nelt;
48981   machine_mode vmode;
48982
48983   nelt = d->nelt;
48984   vmode = V64QImode;
48985
48986   for (i = 0; i < 2; i++)
48987     {
48988       ds[i] = *d;
48989       ds[i].vmode = V32HImode;
48990       ds[i].nelt = 32;
48991       ds[i].target = gen_reg_rtx (V32HImode);
48992       ds[i].op0 = gen_lowpart (V32HImode, d->op0);
48993       ds[i].op1 = gen_lowpart (V32HImode, d->op1);
48994     }
48995
48996   /* Prepare permutations such that the first one takes care of
48997      putting the even bytes into the right positions or one higher
48998      positions (ds[0]) and the second one takes care of
48999      putting the odd bytes into the right positions or one below
49000      (ds[1]).  */
49001
49002   for (i = 0; i < nelt; i++)
49003     {
49004       ds[i & 1].perm[i / 2] = d->perm[i] / 2;
49005       if (i & 1)
49006         {
49007           rperm[i] = constm1_rtx;
49008           rperm[i + 64] = GEN_INT ((i & 14) + (d->perm[i] & 1));
49009         }
49010       else
49011         {
49012           rperm[i] = GEN_INT ((i & 14) + (d->perm[i] & 1));
49013           rperm[i + 64] = constm1_rtx;
49014         }
49015     }
49016
49017   bool ok = expand_vec_perm_1 (&ds[0]);
49018   gcc_assert (ok);
49019   ds[0].target = gen_lowpart (V64QImode, ds[0].target);
49020
49021   ok = expand_vec_perm_1 (&ds[1]);
49022   gcc_assert (ok);
49023   ds[1].target = gen_lowpart (V64QImode, ds[1].target);
49024
49025   vperm = gen_rtx_CONST_VECTOR (V64QImode, gen_rtvec_v (64, rperm));
49026   vperm = force_reg (vmode, vperm);
49027   target0 = gen_reg_rtx (V64QImode);
49028   emit_insn (gen_avx512bw_pshufbv64qi3 (target0, ds[0].target, vperm));
49029
49030   vperm = gen_rtx_CONST_VECTOR (V64QImode, gen_rtvec_v (64, rperm + 64));
49031   vperm = force_reg (vmode, vperm);
49032   target1 = gen_reg_rtx (V64QImode);
49033   emit_insn (gen_avx512bw_pshufbv64qi3 (target1, ds[1].target, vperm));
49034
49035   emit_insn (gen_iorv64qi3 (d->target, target0, target1));
49036   return true;
49037 }
49038
49039 /* Implement arbitrary permutation of two V32QImode and V16QImode operands
49040    with 4 vpshufb insns, 2 vpermq and 3 vpor.  We should have already failed
49041    all the shorter instruction sequences.  */
49042
49043 static bool
49044 expand_vec_perm_vpshufb4_vpermq2 (struct expand_vec_perm_d *d)
49045 {
49046   rtx rperm[4][32], vperm, l[2], h[2], op, m128;
49047   unsigned int i, nelt, eltsz;
49048   bool used[4];
49049
49050   if (!TARGET_AVX2
49051       || d->one_operand_p
49052       || (d->vmode != V32QImode && d->vmode != V16HImode))
49053     return false;
49054
49055   if (d->testing_p)
49056     return true;
49057
49058   nelt = d->nelt;
49059   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
49060
49061   /* Generate 4 permutation masks.  If the required element is within
49062      the same lane, it is shuffled in.  If the required element from the
49063      other lane, force a zero by setting bit 7 in the permutation mask.
49064      In the other mask the mask has non-negative elements if element
49065      is requested from the other lane, but also moved to the other lane,
49066      so that the result of vpshufb can have the two V2TImode halves
49067      swapped.  */
49068   m128 = GEN_INT (-128);
49069   for (i = 0; i < 32; ++i)
49070     {
49071       rperm[0][i] = m128;
49072       rperm[1][i] = m128;
49073       rperm[2][i] = m128;
49074       rperm[3][i] = m128;
49075     }
49076   used[0] = false;
49077   used[1] = false;
49078   used[2] = false;
49079   used[3] = false;
49080   for (i = 0; i < nelt; ++i)
49081     {
49082       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
49083       unsigned xlane = ((d->perm[i] ^ i) & (nelt / 2)) * eltsz;
49084       unsigned int which = ((d->perm[i] & nelt) ? 2 : 0) + (xlane ? 1 : 0);
49085
49086       for (j = 0; j < eltsz; ++j)
49087         rperm[which][(i * eltsz + j) ^ xlane] = GEN_INT (e * eltsz + j);
49088       used[which] = true;
49089     }
49090
49091   for (i = 0; i < 2; ++i)
49092     {
49093       if (!used[2 * i + 1])
49094         {
49095           h[i] = NULL_RTX;
49096           continue;
49097         }
49098       vperm = gen_rtx_CONST_VECTOR (V32QImode,
49099                                     gen_rtvec_v (32, rperm[2 * i + 1]));
49100       vperm = force_reg (V32QImode, vperm);
49101       h[i] = gen_reg_rtx (V32QImode);
49102       op = gen_lowpart (V32QImode, i ? d->op1 : d->op0);
49103       emit_insn (gen_avx2_pshufbv32qi3 (h[i], op, vperm));
49104     }
49105
49106   /* Swap the 128-byte lanes of h[X].  */
49107   for (i = 0; i < 2; ++i)
49108    {
49109      if (h[i] == NULL_RTX)
49110        continue;
49111      op = gen_reg_rtx (V4DImode);
49112      emit_insn (gen_avx2_permv4di_1 (op, gen_lowpart (V4DImode, h[i]),
49113                                      const2_rtx, GEN_INT (3), const0_rtx,
49114                                      const1_rtx));
49115      h[i] = gen_lowpart (V32QImode, op);
49116    }
49117
49118   for (i = 0; i < 2; ++i)
49119     {
49120       if (!used[2 * i])
49121         {
49122           l[i] = NULL_RTX;
49123           continue;
49124         }
49125       vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[2 * i]));
49126       vperm = force_reg (V32QImode, vperm);
49127       l[i] = gen_reg_rtx (V32QImode);
49128       op = gen_lowpart (V32QImode, i ? d->op1 : d->op0);
49129       emit_insn (gen_avx2_pshufbv32qi3 (l[i], op, vperm));
49130     }
49131
49132   for (i = 0; i < 2; ++i)
49133     {
49134       if (h[i] && l[i])
49135         {
49136           op = gen_reg_rtx (V32QImode);
49137           emit_insn (gen_iorv32qi3 (op, l[i], h[i]));
49138           l[i] = op;
49139         }
49140       else if (h[i])
49141         l[i] = h[i];
49142     }
49143
49144   gcc_assert (l[0] && l[1]);
49145   op = d->target;
49146   if (d->vmode != V32QImode)
49147     op = gen_reg_rtx (V32QImode);
49148   emit_insn (gen_iorv32qi3 (op, l[0], l[1]));
49149   if (op != d->target)
49150     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
49151   return true;
49152 }
49153
49154 /* The guts of ix86_expand_vec_perm_const, also used by the ok hook.
49155    With all of the interface bits taken care of, perform the expansion
49156    in D and return true on success.  */
49157
49158 static bool
49159 ix86_expand_vec_perm_const_1 (struct expand_vec_perm_d *d)
49160 {
49161   /* Try a single instruction expansion.  */
49162   if (expand_vec_perm_1 (d))
49163     return true;
49164
49165   /* Try sequences of two instructions.  */
49166
49167   if (expand_vec_perm_pshuflw_pshufhw (d))
49168     return true;
49169
49170   if (expand_vec_perm_palignr (d, false))
49171     return true;
49172
49173   if (expand_vec_perm_interleave2 (d))
49174     return true;
49175
49176   if (expand_vec_perm_broadcast (d))
49177     return true;
49178
49179   if (expand_vec_perm_vpermq_perm_1 (d))
49180     return true;
49181
49182   if (expand_vec_perm_vperm2f128 (d))
49183     return true;
49184
49185   if (expand_vec_perm_pblendv (d))
49186     return true;
49187
49188   /* Try sequences of three instructions.  */
49189
49190   if (expand_vec_perm_even_odd_pack (d))
49191     return true;
49192
49193   if (expand_vec_perm_2vperm2f128_vshuf (d))
49194     return true;
49195
49196   if (expand_vec_perm_pshufb2 (d))
49197     return true;
49198
49199   if (expand_vec_perm_interleave3 (d))
49200     return true;
49201
49202   if (expand_vec_perm_vperm2f128_vblend (d))
49203     return true;
49204
49205   /* Try sequences of four instructions.  */
49206
49207   if (expand_vec_perm_vpshufb2_vpermq (d))
49208     return true;
49209
49210   if (expand_vec_perm_vpshufb2_vpermq_even_odd (d))
49211     return true;
49212
49213   if (expand_vec_perm_vpermi2_vpshub2 (d))
49214     return true;
49215
49216   /* ??? Look for narrow permutations whose element orderings would
49217      allow the promotion to a wider mode.  */
49218
49219   /* ??? Look for sequences of interleave or a wider permute that place
49220      the data into the correct lanes for a half-vector shuffle like
49221      pshuf[lh]w or vpermilps.  */
49222
49223   /* ??? Look for sequences of interleave that produce the desired results.
49224      The combinatorics of punpck[lh] get pretty ugly... */
49225
49226   if (expand_vec_perm_even_odd (d))
49227     return true;
49228
49229   /* Even longer sequences.  */
49230   if (expand_vec_perm_vpshufb4_vpermq2 (d))
49231     return true;
49232
49233   return false;
49234 }
49235
49236 /* If a permutation only uses one operand, make it clear. Returns true
49237    if the permutation references both operands.  */
49238
49239 static bool
49240 canonicalize_perm (struct expand_vec_perm_d *d)
49241 {
49242   int i, which, nelt = d->nelt;
49243
49244   for (i = which = 0; i < nelt; ++i)
49245       which |= (d->perm[i] < nelt ? 1 : 2);
49246
49247   d->one_operand_p = true;
49248   switch (which)
49249     {
49250     default:
49251       gcc_unreachable();
49252
49253     case 3:
49254       if (!rtx_equal_p (d->op0, d->op1))
49255         {
49256           d->one_operand_p = false;
49257           break;
49258         }
49259       /* The elements of PERM do not suggest that only the first operand
49260          is used, but both operands are identical.  Allow easier matching
49261          of the permutation by folding the permutation into the single
49262          input vector.  */
49263       /* FALLTHRU */
49264
49265     case 2:
49266       for (i = 0; i < nelt; ++i)
49267         d->perm[i] &= nelt - 1;
49268       d->op0 = d->op1;
49269       break;
49270
49271     case 1:
49272       d->op1 = d->op0;
49273       break;
49274     }
49275
49276   return (which == 3);
49277 }
49278
49279 bool
49280 ix86_expand_vec_perm_const (rtx operands[4])
49281 {
49282   struct expand_vec_perm_d d;
49283   unsigned char perm[MAX_VECT_LEN];
49284   int i, nelt;
49285   bool two_args;
49286   rtx sel;
49287
49288   d.target = operands[0];
49289   d.op0 = operands[1];
49290   d.op1 = operands[2];
49291   sel = operands[3];
49292
49293   d.vmode = GET_MODE (d.target);
49294   gcc_assert (VECTOR_MODE_P (d.vmode));
49295   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49296   d.testing_p = false;
49297
49298   gcc_assert (GET_CODE (sel) == CONST_VECTOR);
49299   gcc_assert (XVECLEN (sel, 0) == nelt);
49300   gcc_checking_assert (sizeof (d.perm) == sizeof (perm));
49301
49302   for (i = 0; i < nelt; ++i)
49303     {
49304       rtx e = XVECEXP (sel, 0, i);
49305       int ei = INTVAL (e) & (2 * nelt - 1);
49306       d.perm[i] = ei;
49307       perm[i] = ei;
49308     }
49309
49310   two_args = canonicalize_perm (&d);
49311
49312   if (ix86_expand_vec_perm_const_1 (&d))
49313     return true;
49314
49315   /* If the selector says both arguments are needed, but the operands are the
49316      same, the above tried to expand with one_operand_p and flattened selector.
49317      If that didn't work, retry without one_operand_p; we succeeded with that
49318      during testing.  */
49319   if (two_args && d.one_operand_p)
49320     {
49321       d.one_operand_p = false;
49322       memcpy (d.perm, perm, sizeof (perm));
49323       return ix86_expand_vec_perm_const_1 (&d);
49324     }
49325
49326   return false;
49327 }
49328
49329 /* Implement targetm.vectorize.vec_perm_const_ok.  */
49330
49331 static bool
49332 ix86_vectorize_vec_perm_const_ok (machine_mode vmode,
49333                                   const unsigned char *sel)
49334 {
49335   struct expand_vec_perm_d d;
49336   unsigned int i, nelt, which;
49337   bool ret;
49338
49339   d.vmode = vmode;
49340   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49341   d.testing_p = true;
49342
49343   /* Given sufficient ISA support we can just return true here
49344      for selected vector modes.  */
49345   switch (d.vmode)
49346     {
49347     case V16SFmode:
49348     case V16SImode:
49349     case V8DImode:
49350     case V8DFmode:
49351       if (TARGET_AVX512F)
49352         /* All implementable with a single vpermi2 insn.  */
49353         return true;
49354       break;
49355     case V32HImode:
49356       if (TARGET_AVX512BW)
49357         /* All implementable with a single vpermi2 insn.  */
49358         return true;
49359       break;
49360     case V64QImode:
49361       if (TARGET_AVX512BW)
49362         /* Implementable with 2 vpermi2, 2 vpshufb and 1 or insn.  */
49363         return true;
49364       break;
49365     case V8SImode:
49366     case V8SFmode:
49367     case V4DFmode:
49368     case V4DImode:
49369       if (TARGET_AVX512VL)
49370         /* All implementable with a single vpermi2 insn.  */
49371         return true;
49372       break;
49373     case V16HImode:
49374       if (TARGET_AVX2)
49375         /* Implementable with 4 vpshufb insns, 2 vpermq and 3 vpor insns.  */
49376         return true;
49377       break;
49378     case V32QImode:
49379       if (TARGET_AVX2)
49380         /* Implementable with 4 vpshufb insns, 2 vpermq and 3 vpor insns.  */
49381         return true;
49382       break;
49383     case V4SImode:
49384     case V4SFmode:
49385     case V8HImode:
49386     case V16QImode:
49387       /* All implementable with a single vpperm insn.  */
49388       if (TARGET_XOP)
49389         return true;
49390       /* All implementable with 2 pshufb + 1 ior.  */
49391       if (TARGET_SSSE3)
49392         return true;
49393       break;
49394     case V2DImode:
49395     case V2DFmode:
49396       /* All implementable with shufpd or unpck[lh]pd.  */
49397       return true;
49398     default:
49399       return false;
49400     }
49401
49402   /* Extract the values from the vector CST into the permutation
49403      array in D.  */
49404   memcpy (d.perm, sel, nelt);
49405   for (i = which = 0; i < nelt; ++i)
49406     {
49407       unsigned char e = d.perm[i];
49408       gcc_assert (e < 2 * nelt);
49409       which |= (e < nelt ? 1 : 2);
49410     }
49411
49412   /* For all elements from second vector, fold the elements to first.  */
49413   if (which == 2)
49414     for (i = 0; i < nelt; ++i)
49415       d.perm[i] -= nelt;
49416
49417   /* Check whether the mask can be applied to the vector type.  */
49418   d.one_operand_p = (which != 3);
49419
49420   /* Implementable with shufps or pshufd.  */
49421   if (d.one_operand_p && (d.vmode == V4SFmode || d.vmode == V4SImode))
49422     return true;
49423
49424   /* Otherwise we have to go through the motions and see if we can
49425      figure out how to generate the requested permutation.  */
49426   d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1);
49427   d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2);
49428   if (!d.one_operand_p)
49429     d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3);
49430
49431   start_sequence ();
49432   ret = ix86_expand_vec_perm_const_1 (&d);
49433   end_sequence ();
49434
49435   return ret;
49436 }
49437
49438 void
49439 ix86_expand_vec_extract_even_odd (rtx targ, rtx op0, rtx op1, unsigned odd)
49440 {
49441   struct expand_vec_perm_d d;
49442   unsigned i, nelt;
49443
49444   d.target = targ;
49445   d.op0 = op0;
49446   d.op1 = op1;
49447   d.vmode = GET_MODE (targ);
49448   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49449   d.one_operand_p = false;
49450   d.testing_p = false;
49451
49452   for (i = 0; i < nelt; ++i)
49453     d.perm[i] = i * 2 + odd;
49454
49455   /* We'll either be able to implement the permutation directly...  */
49456   if (expand_vec_perm_1 (&d))
49457     return;
49458
49459   /* ... or we use the special-case patterns.  */
49460   expand_vec_perm_even_odd_1 (&d, odd);
49461 }
49462
49463 static void
49464 ix86_expand_vec_interleave (rtx targ, rtx op0, rtx op1, bool high_p)
49465 {
49466   struct expand_vec_perm_d d;
49467   unsigned i, nelt, base;
49468   bool ok;
49469
49470   d.target = targ;
49471   d.op0 = op0;
49472   d.op1 = op1;
49473   d.vmode = GET_MODE (targ);
49474   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49475   d.one_operand_p = false;
49476   d.testing_p = false;
49477
49478   base = high_p ? nelt / 2 : 0;
49479   for (i = 0; i < nelt / 2; ++i)
49480     {
49481       d.perm[i * 2] = i + base;
49482       d.perm[i * 2 + 1] = i + base + nelt;
49483     }
49484
49485   /* Note that for AVX this isn't one instruction.  */
49486   ok = ix86_expand_vec_perm_const_1 (&d);
49487   gcc_assert (ok);
49488 }
49489
49490
49491 /* Expand a vector operation CODE for a V*QImode in terms of the
49492    same operation on V*HImode.  */
49493
49494 void
49495 ix86_expand_vecop_qihi (enum rtx_code code, rtx dest, rtx op1, rtx op2)
49496 {
49497   machine_mode qimode = GET_MODE (dest);
49498   machine_mode himode;
49499   rtx (*gen_il) (rtx, rtx, rtx);
49500   rtx (*gen_ih) (rtx, rtx, rtx);
49501   rtx op1_l, op1_h, op2_l, op2_h, res_l, res_h;
49502   struct expand_vec_perm_d d;
49503   bool ok, full_interleave;
49504   bool uns_p = false;
49505   int i;
49506
49507   switch (qimode)
49508     {
49509     case V16QImode:
49510       himode = V8HImode;
49511       gen_il = gen_vec_interleave_lowv16qi;
49512       gen_ih = gen_vec_interleave_highv16qi;
49513       break;
49514     case V32QImode:
49515       himode = V16HImode;
49516       gen_il = gen_avx2_interleave_lowv32qi;
49517       gen_ih = gen_avx2_interleave_highv32qi;
49518       break;
49519     case V64QImode:
49520       himode = V32HImode;
49521       gen_il = gen_avx512bw_interleave_lowv64qi;
49522       gen_ih = gen_avx512bw_interleave_highv64qi;
49523       break;
49524     default:
49525       gcc_unreachable ();
49526     }
49527
49528   op2_l = op2_h = op2;
49529   switch (code)
49530     {
49531     case MULT:
49532       /* Unpack data such that we've got a source byte in each low byte of
49533          each word.  We don't care what goes into the high byte of each word.
49534          Rather than trying to get zero in there, most convenient is to let
49535          it be a copy of the low byte.  */
49536       op2_l = gen_reg_rtx (qimode);
49537       op2_h = gen_reg_rtx (qimode);
49538       emit_insn (gen_il (op2_l, op2, op2));
49539       emit_insn (gen_ih (op2_h, op2, op2));
49540       /* FALLTHRU */
49541
49542       op1_l = gen_reg_rtx (qimode);
49543       op1_h = gen_reg_rtx (qimode);
49544       emit_insn (gen_il (op1_l, op1, op1));
49545       emit_insn (gen_ih (op1_h, op1, op1));
49546       full_interleave = qimode == V16QImode;
49547       break;
49548
49549     case ASHIFT:
49550     case LSHIFTRT:
49551       uns_p = true;
49552       /* FALLTHRU */
49553     case ASHIFTRT:
49554       op1_l = gen_reg_rtx (himode);
49555       op1_h = gen_reg_rtx (himode);
49556       ix86_expand_sse_unpack (op1_l, op1, uns_p, false);
49557       ix86_expand_sse_unpack (op1_h, op1, uns_p, true);
49558       full_interleave = true;
49559       break;
49560     default:
49561       gcc_unreachable ();
49562     }
49563
49564   /* Perform the operation.  */
49565   res_l = expand_simple_binop (himode, code, op1_l, op2_l, NULL_RTX,
49566                                1, OPTAB_DIRECT);
49567   res_h = expand_simple_binop (himode, code, op1_h, op2_h, NULL_RTX,
49568                                1, OPTAB_DIRECT);
49569   gcc_assert (res_l && res_h);
49570
49571   /* Merge the data back into the right place.  */
49572   d.target = dest;
49573   d.op0 = gen_lowpart (qimode, res_l);
49574   d.op1 = gen_lowpart (qimode, res_h);
49575   d.vmode = qimode;
49576   d.nelt = GET_MODE_NUNITS (qimode);
49577   d.one_operand_p = false;
49578   d.testing_p = false;
49579
49580   if (full_interleave)
49581     {
49582       /* For SSE2, we used an full interleave, so the desired
49583          results are in the even elements.  */
49584       for (i = 0; i < 64; ++i)
49585         d.perm[i] = i * 2;
49586     }
49587   else
49588     {
49589       /* For AVX, the interleave used above was not cross-lane.  So the
49590          extraction is evens but with the second and third quarter swapped.
49591          Happily, that is even one insn shorter than even extraction.  */
49592       for (i = 0; i < 64; ++i)
49593         d.perm[i] = i * 2 + ((i & 24) == 8 ? 16 : (i & 24) == 16 ? -16 : 0);
49594     }
49595
49596   ok = ix86_expand_vec_perm_const_1 (&d);
49597   gcc_assert (ok);
49598
49599   set_unique_reg_note (get_last_insn (), REG_EQUAL,
49600                        gen_rtx_fmt_ee (code, qimode, op1, op2));
49601 }
49602
49603 /* Helper function of ix86_expand_mul_widen_evenodd.  Return true
49604    if op is CONST_VECTOR with all odd elements equal to their
49605    preceding element.  */
49606
49607 static bool
49608 const_vector_equal_evenodd_p (rtx op)
49609 {
49610   machine_mode mode = GET_MODE (op);
49611   int i, nunits = GET_MODE_NUNITS (mode);
49612   if (GET_CODE (op) != CONST_VECTOR
49613       || nunits != CONST_VECTOR_NUNITS (op))
49614     return false;
49615   for (i = 0; i < nunits; i += 2)
49616     if (CONST_VECTOR_ELT (op, i) != CONST_VECTOR_ELT (op, i + 1))
49617       return false;
49618   return true;
49619 }
49620
49621 void
49622 ix86_expand_mul_widen_evenodd (rtx dest, rtx op1, rtx op2,
49623                                bool uns_p, bool odd_p)
49624 {
49625   machine_mode mode = GET_MODE (op1);
49626   machine_mode wmode = GET_MODE (dest);
49627   rtx x;
49628   rtx orig_op1 = op1, orig_op2 = op2;
49629
49630   if (!nonimmediate_operand (op1, mode))
49631     op1 = force_reg (mode, op1);
49632   if (!nonimmediate_operand (op2, mode))
49633     op2 = force_reg (mode, op2);
49634
49635   /* We only play even/odd games with vectors of SImode.  */
49636   gcc_assert (mode == V4SImode || mode == V8SImode || mode == V16SImode);
49637
49638   /* If we're looking for the odd results, shift those members down to
49639      the even slots.  For some cpus this is faster than a PSHUFD.  */
49640   if (odd_p)
49641     {
49642       /* For XOP use vpmacsdqh, but only for smult, as it is only
49643          signed.  */
49644       if (TARGET_XOP && mode == V4SImode && !uns_p)
49645         {
49646           x = force_reg (wmode, CONST0_RTX (wmode));
49647           emit_insn (gen_xop_pmacsdqh (dest, op1, op2, x));
49648           return;
49649         }
49650
49651       x = GEN_INT (GET_MODE_UNIT_BITSIZE (mode));
49652       if (!const_vector_equal_evenodd_p (orig_op1))
49653         op1 = expand_binop (wmode, lshr_optab, gen_lowpart (wmode, op1),
49654                             x, NULL, 1, OPTAB_DIRECT);
49655       if (!const_vector_equal_evenodd_p (orig_op2))
49656         op2 = expand_binop (wmode, lshr_optab, gen_lowpart (wmode, op2),
49657                             x, NULL, 1, OPTAB_DIRECT);
49658       op1 = gen_lowpart (mode, op1);
49659       op2 = gen_lowpart (mode, op2);
49660     }
49661
49662   if (mode == V16SImode)
49663     {
49664       if (uns_p)
49665         x = gen_vec_widen_umult_even_v16si (dest, op1, op2);
49666       else
49667         x = gen_vec_widen_smult_even_v16si (dest, op1, op2);
49668     }
49669   else if (mode == V8SImode)
49670     {
49671       if (uns_p)
49672         x = gen_vec_widen_umult_even_v8si (dest, op1, op2);
49673       else
49674         x = gen_vec_widen_smult_even_v8si (dest, op1, op2);
49675     }
49676   else if (uns_p)
49677     x = gen_vec_widen_umult_even_v4si (dest, op1, op2);
49678   else if (TARGET_SSE4_1)
49679     x = gen_sse4_1_mulv2siv2di3 (dest, op1, op2);
49680   else
49681     {
49682       rtx s1, s2, t0, t1, t2;
49683
49684       /* The easiest way to implement this without PMULDQ is to go through
49685          the motions as if we are performing a full 64-bit multiply.  With
49686          the exception that we need to do less shuffling of the elements.  */
49687
49688       /* Compute the sign-extension, aka highparts, of the two operands.  */
49689       s1 = ix86_expand_sse_cmp (gen_reg_rtx (mode), GT, CONST0_RTX (mode),
49690                                 op1, pc_rtx, pc_rtx);
49691       s2 = ix86_expand_sse_cmp (gen_reg_rtx (mode), GT, CONST0_RTX (mode),
49692                                 op2, pc_rtx, pc_rtx);
49693
49694       /* Multiply LO(A) * HI(B), and vice-versa.  */
49695       t1 = gen_reg_rtx (wmode);
49696       t2 = gen_reg_rtx (wmode);
49697       emit_insn (gen_vec_widen_umult_even_v4si (t1, s1, op2));
49698       emit_insn (gen_vec_widen_umult_even_v4si (t2, s2, op1));
49699
49700       /* Multiply LO(A) * LO(B).  */
49701       t0 = gen_reg_rtx (wmode);
49702       emit_insn (gen_vec_widen_umult_even_v4si (t0, op1, op2));
49703
49704       /* Combine and shift the highparts into place.  */
49705       t1 = expand_binop (wmode, add_optab, t1, t2, t1, 1, OPTAB_DIRECT);
49706       t1 = expand_binop (wmode, ashl_optab, t1, GEN_INT (32), t1,
49707                          1, OPTAB_DIRECT);
49708
49709       /* Combine high and low parts.  */
49710       force_expand_binop (wmode, add_optab, t0, t1, dest, 1, OPTAB_DIRECT);
49711       return;
49712     }
49713   emit_insn (x);
49714 }
49715
49716 void
49717 ix86_expand_mul_widen_hilo (rtx dest, rtx op1, rtx op2,
49718                             bool uns_p, bool high_p)
49719 {
49720   machine_mode wmode = GET_MODE (dest);
49721   machine_mode mode = GET_MODE (op1);
49722   rtx t1, t2, t3, t4, mask;
49723
49724   switch (mode)
49725     {
49726     case V4SImode:
49727       t1 = gen_reg_rtx (mode);
49728       t2 = gen_reg_rtx (mode);
49729       if (TARGET_XOP && !uns_p)
49730         {
49731           /* With XOP, we have pmacsdqh, aka mul_widen_odd.  In this case,
49732              shuffle the elements once so that all elements are in the right
49733              place for immediate use: { A C B D }.  */
49734           emit_insn (gen_sse2_pshufd_1 (t1, op1, const0_rtx, const2_rtx,
49735                                         const1_rtx, GEN_INT (3)));
49736           emit_insn (gen_sse2_pshufd_1 (t2, op2, const0_rtx, const2_rtx,
49737                                         const1_rtx, GEN_INT (3)));
49738         }
49739       else
49740         {
49741           /* Put the elements into place for the multiply.  */
49742           ix86_expand_vec_interleave (t1, op1, op1, high_p);
49743           ix86_expand_vec_interleave (t2, op2, op2, high_p);
49744           high_p = false;
49745         }
49746       ix86_expand_mul_widen_evenodd (dest, t1, t2, uns_p, high_p);
49747       break;
49748
49749     case V8SImode:
49750       /* Shuffle the elements between the lanes.  After this we
49751          have { A B E F | C D G H } for each operand.  */
49752       t1 = gen_reg_rtx (V4DImode);
49753       t2 = gen_reg_rtx (V4DImode);
49754       emit_insn (gen_avx2_permv4di_1 (t1, gen_lowpart (V4DImode, op1),
49755                                       const0_rtx, const2_rtx,
49756                                       const1_rtx, GEN_INT (3)));
49757       emit_insn (gen_avx2_permv4di_1 (t2, gen_lowpart (V4DImode, op2),
49758                                       const0_rtx, const2_rtx,
49759                                       const1_rtx, GEN_INT (3)));
49760
49761       /* Shuffle the elements within the lanes.  After this we
49762          have { A A B B | C C D D } or { E E F F | G G H H }.  */
49763       t3 = gen_reg_rtx (V8SImode);
49764       t4 = gen_reg_rtx (V8SImode);
49765       mask = GEN_INT (high_p
49766                       ? 2 + (2 << 2) + (3 << 4) + (3 << 6)
49767                       : 0 + (0 << 2) + (1 << 4) + (1 << 6));
49768       emit_insn (gen_avx2_pshufdv3 (t3, gen_lowpart (V8SImode, t1), mask));
49769       emit_insn (gen_avx2_pshufdv3 (t4, gen_lowpart (V8SImode, t2), mask));
49770
49771       ix86_expand_mul_widen_evenodd (dest, t3, t4, uns_p, false);
49772       break;
49773
49774     case V8HImode:
49775     case V16HImode:
49776       t1 = expand_binop (mode, smul_optab, op1, op2, NULL_RTX,
49777                          uns_p, OPTAB_DIRECT);
49778       t2 = expand_binop (mode,
49779                          uns_p ? umul_highpart_optab : smul_highpart_optab,
49780                          op1, op2, NULL_RTX, uns_p, OPTAB_DIRECT);
49781       gcc_assert (t1 && t2);
49782
49783       t3 = gen_reg_rtx (mode);
49784       ix86_expand_vec_interleave (t3, t1, t2, high_p);
49785       emit_move_insn (dest, gen_lowpart (wmode, t3));
49786       break;
49787
49788     case V16QImode:
49789     case V32QImode:
49790     case V32HImode:
49791     case V16SImode:
49792     case V64QImode:
49793       t1 = gen_reg_rtx (wmode);
49794       t2 = gen_reg_rtx (wmode);
49795       ix86_expand_sse_unpack (t1, op1, uns_p, high_p);
49796       ix86_expand_sse_unpack (t2, op2, uns_p, high_p);
49797
49798       emit_insn (gen_rtx_SET (VOIDmode, dest, gen_rtx_MULT (wmode, t1, t2)));
49799       break;
49800
49801     default:
49802       gcc_unreachable ();
49803     }
49804 }
49805
49806 void
49807 ix86_expand_sse2_mulv4si3 (rtx op0, rtx op1, rtx op2)
49808 {
49809   rtx res_1, res_2, res_3, res_4;
49810
49811   res_1 = gen_reg_rtx (V4SImode);
49812   res_2 = gen_reg_rtx (V4SImode);
49813   res_3 = gen_reg_rtx (V2DImode);
49814   res_4 = gen_reg_rtx (V2DImode);
49815   ix86_expand_mul_widen_evenodd (res_3, op1, op2, true, false);
49816   ix86_expand_mul_widen_evenodd (res_4, op1, op2, true, true);
49817
49818   /* Move the results in element 2 down to element 1; we don't care
49819      what goes in elements 2 and 3.  Then we can merge the parts
49820      back together with an interleave.
49821
49822      Note that two other sequences were tried:
49823      (1) Use interleaves at the start instead of psrldq, which allows
49824      us to use a single shufps to merge things back at the end.
49825      (2) Use shufps here to combine the two vectors, then pshufd to
49826      put the elements in the correct order.
49827      In both cases the cost of the reformatting stall was too high
49828      and the overall sequence slower.  */
49829
49830   emit_insn (gen_sse2_pshufd_1 (res_1, gen_lowpart (V4SImode, res_3),
49831                                 const0_rtx, const2_rtx,
49832                                 const0_rtx, const0_rtx));
49833   emit_insn (gen_sse2_pshufd_1 (res_2, gen_lowpart (V4SImode, res_4),
49834                                 const0_rtx, const2_rtx,
49835                                 const0_rtx, const0_rtx));
49836   res_1 = emit_insn (gen_vec_interleave_lowv4si (op0, res_1, res_2));
49837
49838   set_unique_reg_note (res_1, REG_EQUAL, gen_rtx_MULT (V4SImode, op1, op2));
49839 }
49840
49841 void
49842 ix86_expand_sse2_mulvxdi3 (rtx op0, rtx op1, rtx op2)
49843 {
49844   machine_mode mode = GET_MODE (op0);
49845   rtx t1, t2, t3, t4, t5, t6;
49846
49847   if (TARGET_AVX512DQ && mode == V8DImode)
49848     emit_insn (gen_avx512dq_mulv8di3 (op0, op1, op2));
49849   else if (TARGET_AVX512DQ && TARGET_AVX512VL && mode == V4DImode)
49850     emit_insn (gen_avx512dq_mulv4di3 (op0, op1, op2));
49851   else if (TARGET_AVX512DQ && TARGET_AVX512VL && mode == V2DImode)
49852     emit_insn (gen_avx512dq_mulv2di3 (op0, op1, op2));
49853   else if (TARGET_XOP && mode == V2DImode)
49854     {
49855       /* op1: A,B,C,D, op2: E,F,G,H */
49856       op1 = gen_lowpart (V4SImode, op1);
49857       op2 = gen_lowpart (V4SImode, op2);
49858
49859       t1 = gen_reg_rtx (V4SImode);
49860       t2 = gen_reg_rtx (V4SImode);
49861       t3 = gen_reg_rtx (V2DImode);
49862       t4 = gen_reg_rtx (V2DImode);
49863
49864       /* t1: B,A,D,C */
49865       emit_insn (gen_sse2_pshufd_1 (t1, op1,
49866                                     GEN_INT (1),
49867                                     GEN_INT (0),
49868                                     GEN_INT (3),
49869                                     GEN_INT (2)));
49870
49871       /* t2: (B*E),(A*F),(D*G),(C*H) */
49872       emit_insn (gen_mulv4si3 (t2, t1, op2));
49873
49874       /* t3: (B*E)+(A*F), (D*G)+(C*H) */
49875       emit_insn (gen_xop_phadddq (t3, t2));
49876
49877       /* t4: ((B*E)+(A*F))<<32, ((D*G)+(C*H))<<32 */
49878       emit_insn (gen_ashlv2di3 (t4, t3, GEN_INT (32)));
49879
49880       /* Multiply lower parts and add all */
49881       t5 = gen_reg_rtx (V2DImode);
49882       emit_insn (gen_vec_widen_umult_even_v4si (t5, 
49883                                         gen_lowpart (V4SImode, op1),
49884                                         gen_lowpart (V4SImode, op2)));
49885       op0 = expand_binop (mode, add_optab, t5, t4, op0, 1, OPTAB_DIRECT);
49886
49887     }
49888   else
49889     {
49890       machine_mode nmode;
49891       rtx (*umul) (rtx, rtx, rtx);
49892
49893       if (mode == V2DImode)
49894         {
49895           umul = gen_vec_widen_umult_even_v4si;
49896           nmode = V4SImode;
49897         }
49898       else if (mode == V4DImode)
49899         {
49900           umul = gen_vec_widen_umult_even_v8si;
49901           nmode = V8SImode;
49902         }
49903       else if (mode == V8DImode)
49904         {
49905           umul = gen_vec_widen_umult_even_v16si;
49906           nmode = V16SImode;
49907         }
49908       else
49909         gcc_unreachable ();
49910
49911
49912       /* Multiply low parts.  */
49913       t1 = gen_reg_rtx (mode);
49914       emit_insn (umul (t1, gen_lowpart (nmode, op1), gen_lowpart (nmode, op2)));
49915
49916       /* Shift input vectors right 32 bits so we can multiply high parts.  */
49917       t6 = GEN_INT (32);
49918       t2 = expand_binop (mode, lshr_optab, op1, t6, NULL, 1, OPTAB_DIRECT);
49919       t3 = expand_binop (mode, lshr_optab, op2, t6, NULL, 1, OPTAB_DIRECT);
49920
49921       /* Multiply high parts by low parts.  */
49922       t4 = gen_reg_rtx (mode);
49923       t5 = gen_reg_rtx (mode);
49924       emit_insn (umul (t4, gen_lowpart (nmode, t2), gen_lowpart (nmode, op2)));
49925       emit_insn (umul (t5, gen_lowpart (nmode, t3), gen_lowpart (nmode, op1)));
49926
49927       /* Combine and shift the highparts back.  */
49928       t4 = expand_binop (mode, add_optab, t4, t5, t4, 1, OPTAB_DIRECT);
49929       t4 = expand_binop (mode, ashl_optab, t4, t6, t4, 1, OPTAB_DIRECT);
49930
49931       /* Combine high and low parts.  */
49932       force_expand_binop (mode, add_optab, t1, t4, op0, 1, OPTAB_DIRECT);
49933     }
49934
49935   set_unique_reg_note (get_last_insn (), REG_EQUAL,
49936                        gen_rtx_MULT (mode, op1, op2));
49937 }
49938
49939 /* Return 1 if control tansfer instruction INSN
49940    should be encoded with bnd prefix.
49941    If insn is NULL then return 1 when control
49942    transfer instructions should be prefixed with
49943    bnd by default for current function.  */
49944
49945 bool
49946 ix86_bnd_prefixed_insn_p (rtx insn)
49947 {
49948   /* For call insns check special flag.  */
49949   if (insn && CALL_P (insn))
49950     {
49951       rtx call = get_call_rtx_from (insn);
49952       if (call)
49953         return CALL_EXPR_WITH_BOUNDS_P (call);
49954     }
49955
49956   /* All other insns are prefixed only if function is instrumented.  */
49957   return chkp_function_instrumented_p (current_function_decl);
49958 }
49959
49960 /* Calculate integer abs() using only SSE2 instructions.  */
49961
49962 void
49963 ix86_expand_sse2_abs (rtx target, rtx input)
49964 {
49965   machine_mode mode = GET_MODE (target);
49966   rtx tmp0, tmp1, x;
49967
49968   switch (mode)
49969     {
49970       /* For 32-bit signed integer X, the best way to calculate the absolute
49971          value of X is (((signed) X >> (W-1)) ^ X) - ((signed) X >> (W-1)).  */
49972       case V4SImode:
49973         tmp0 = expand_simple_binop (mode, ASHIFTRT, input,
49974                                     GEN_INT (GET_MODE_BITSIZE
49975                                              (GET_MODE_INNER (mode)) - 1),
49976                                     NULL, 0, OPTAB_DIRECT);
49977         tmp1 = expand_simple_binop (mode, XOR, tmp0, input,
49978                                     NULL, 0, OPTAB_DIRECT);
49979         x = expand_simple_binop (mode, MINUS, tmp1, tmp0,
49980                                  target, 0, OPTAB_DIRECT);
49981         break;
49982
49983       /* For 16-bit signed integer X, the best way to calculate the absolute
49984          value of X is max (X, -X), as SSE2 provides the PMAXSW insn.  */
49985       case V8HImode:
49986         tmp0 = expand_unop (mode, neg_optab, input, NULL_RTX, 0);
49987
49988         x = expand_simple_binop (mode, SMAX, tmp0, input,
49989                                  target, 0, OPTAB_DIRECT);
49990         break;
49991
49992       /* For 8-bit signed integer X, the best way to calculate the absolute
49993          value of X is min ((unsigned char) X, (unsigned char) (-X)),
49994          as SSE2 provides the PMINUB insn.  */
49995       case V16QImode:
49996         tmp0 = expand_unop (mode, neg_optab, input, NULL_RTX, 0);
49997
49998         x = expand_simple_binop (V16QImode, UMIN, tmp0, input,
49999                                  target, 0, OPTAB_DIRECT);
50000         break;
50001
50002       default:
50003         gcc_unreachable ();
50004     }
50005
50006   if (x != target)
50007     emit_move_insn (target, x);
50008 }
50009
50010 /* Expand an insert into a vector register through pinsr insn.
50011    Return true if successful.  */
50012
50013 bool
50014 ix86_expand_pinsr (rtx *operands)
50015 {
50016   rtx dst = operands[0];
50017   rtx src = operands[3];
50018
50019   unsigned int size = INTVAL (operands[1]);
50020   unsigned int pos = INTVAL (operands[2]);
50021
50022   if (GET_CODE (dst) == SUBREG)
50023     {
50024       pos += SUBREG_BYTE (dst) * BITS_PER_UNIT;
50025       dst = SUBREG_REG (dst);
50026     }
50027
50028   if (GET_CODE (src) == SUBREG)
50029     src = SUBREG_REG (src);
50030
50031   switch (GET_MODE (dst))
50032     {
50033     case V16QImode:
50034     case V8HImode:
50035     case V4SImode:
50036     case V2DImode:
50037       {
50038         machine_mode srcmode, dstmode;
50039         rtx (*pinsr)(rtx, rtx, rtx, rtx);
50040
50041         srcmode = mode_for_size (size, MODE_INT, 0);
50042
50043         switch (srcmode)
50044           {
50045           case QImode:
50046             if (!TARGET_SSE4_1)
50047               return false;
50048             dstmode = V16QImode;
50049             pinsr = gen_sse4_1_pinsrb;
50050             break;
50051
50052           case HImode:
50053             if (!TARGET_SSE2)
50054               return false;
50055             dstmode = V8HImode;
50056             pinsr = gen_sse2_pinsrw;
50057             break;
50058
50059           case SImode:
50060             if (!TARGET_SSE4_1)
50061               return false;
50062             dstmode = V4SImode;
50063             pinsr = gen_sse4_1_pinsrd;
50064             break;
50065
50066           case DImode:
50067             gcc_assert (TARGET_64BIT);
50068             if (!TARGET_SSE4_1)
50069               return false;
50070             dstmode = V2DImode;
50071             pinsr = gen_sse4_1_pinsrq;
50072             break;
50073
50074           default:
50075             return false;
50076           }
50077
50078         rtx d = dst;
50079         if (GET_MODE (dst) != dstmode)
50080           d = gen_reg_rtx (dstmode);
50081         src = gen_lowpart (srcmode, src);
50082
50083         pos /= size;
50084
50085         emit_insn (pinsr (d, gen_lowpart (dstmode, dst), src,
50086                           GEN_INT (1 << pos)));
50087         if (d != dst)
50088           emit_move_insn (dst, gen_lowpart (GET_MODE (dst), d));
50089         return true;
50090       }
50091
50092     default:
50093       return false;
50094     }
50095 }
50096 \f
50097 /* This function returns the calling abi specific va_list type node.
50098    It returns  the FNDECL specific va_list type.  */
50099
50100 static tree
50101 ix86_fn_abi_va_list (tree fndecl)
50102 {
50103   if (!TARGET_64BIT)
50104     return va_list_type_node;
50105   gcc_assert (fndecl != NULL_TREE);
50106
50107   if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
50108     return ms_va_list_type_node;
50109   else
50110     return sysv_va_list_type_node;
50111 }
50112
50113 /* Returns the canonical va_list type specified by TYPE. If there
50114    is no valid TYPE provided, it return NULL_TREE.  */
50115
50116 static tree
50117 ix86_canonical_va_list_type (tree type)
50118 {
50119   tree wtype, htype;
50120
50121   /* Resolve references and pointers to va_list type.  */
50122   if (TREE_CODE (type) == MEM_REF)
50123     type = TREE_TYPE (type);
50124   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
50125     type = TREE_TYPE (type);
50126   else if (POINTER_TYPE_P (type) && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
50127     type = TREE_TYPE (type);
50128
50129   if (TARGET_64BIT && va_list_type_node != NULL_TREE)
50130     {
50131       wtype = va_list_type_node;
50132           gcc_assert (wtype != NULL_TREE);
50133       htype = type;
50134       if (TREE_CODE (wtype) == ARRAY_TYPE)
50135         {
50136           /* If va_list is an array type, the argument may have decayed
50137              to a pointer type, e.g. by being passed to another function.
50138              In that case, unwrap both types so that we can compare the
50139              underlying records.  */
50140           if (TREE_CODE (htype) == ARRAY_TYPE
50141               || POINTER_TYPE_P (htype))
50142             {
50143               wtype = TREE_TYPE (wtype);
50144               htype = TREE_TYPE (htype);
50145             }
50146         }
50147       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50148         return va_list_type_node;
50149       wtype = sysv_va_list_type_node;
50150           gcc_assert (wtype != NULL_TREE);
50151       htype = type;
50152       if (TREE_CODE (wtype) == ARRAY_TYPE)
50153         {
50154           /* If va_list is an array type, the argument may have decayed
50155              to a pointer type, e.g. by being passed to another function.
50156              In that case, unwrap both types so that we can compare the
50157              underlying records.  */
50158           if (TREE_CODE (htype) == ARRAY_TYPE
50159               || POINTER_TYPE_P (htype))
50160             {
50161               wtype = TREE_TYPE (wtype);
50162               htype = TREE_TYPE (htype);
50163             }
50164         }
50165       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50166         return sysv_va_list_type_node;
50167       wtype = ms_va_list_type_node;
50168           gcc_assert (wtype != NULL_TREE);
50169       htype = type;
50170       if (TREE_CODE (wtype) == ARRAY_TYPE)
50171         {
50172           /* If va_list is an array type, the argument may have decayed
50173              to a pointer type, e.g. by being passed to another function.
50174              In that case, unwrap both types so that we can compare the
50175              underlying records.  */
50176           if (TREE_CODE (htype) == ARRAY_TYPE
50177               || POINTER_TYPE_P (htype))
50178             {
50179               wtype = TREE_TYPE (wtype);
50180               htype = TREE_TYPE (htype);
50181             }
50182         }
50183       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50184         return ms_va_list_type_node;
50185       return NULL_TREE;
50186     }
50187   return std_canonical_va_list_type (type);
50188 }
50189
50190 /* Iterate through the target-specific builtin types for va_list.
50191    IDX denotes the iterator, *PTREE is set to the result type of
50192    the va_list builtin, and *PNAME to its internal type.
50193    Returns zero if there is no element for this index, otherwise
50194    IDX should be increased upon the next call.
50195    Note, do not iterate a base builtin's name like __builtin_va_list.
50196    Used from c_common_nodes_and_builtins.  */
50197
50198 static int
50199 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
50200 {
50201   if (TARGET_64BIT)
50202     {
50203       switch (idx)
50204         {
50205         default:
50206           break;
50207
50208         case 0:
50209           *ptree = ms_va_list_type_node;
50210           *pname = "__builtin_ms_va_list";
50211           return 1;
50212
50213         case 1:
50214           *ptree = sysv_va_list_type_node;
50215           *pname = "__builtin_sysv_va_list";
50216           return 1;
50217         }
50218     }
50219
50220   return 0;
50221 }
50222
50223 #undef TARGET_SCHED_DISPATCH
50224 #define TARGET_SCHED_DISPATCH has_dispatch
50225 #undef TARGET_SCHED_DISPATCH_DO
50226 #define TARGET_SCHED_DISPATCH_DO do_dispatch
50227 #undef TARGET_SCHED_REASSOCIATION_WIDTH
50228 #define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width
50229 #undef TARGET_SCHED_REORDER
50230 #define TARGET_SCHED_REORDER ix86_sched_reorder
50231 #undef TARGET_SCHED_ADJUST_PRIORITY
50232 #define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority
50233 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
50234 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
50235   ix86_dependencies_evaluation_hook
50236
50237 /* The size of the dispatch window is the total number of bytes of
50238    object code allowed in a window.  */
50239 #define DISPATCH_WINDOW_SIZE 16
50240
50241 /* Number of dispatch windows considered for scheduling.  */
50242 #define MAX_DISPATCH_WINDOWS 3
50243
50244 /* Maximum number of instructions in a window.  */
50245 #define MAX_INSN 4
50246
50247 /* Maximum number of immediate operands in a window.  */
50248 #define MAX_IMM 4
50249
50250 /* Maximum number of immediate bits allowed in a window.  */
50251 #define MAX_IMM_SIZE 128
50252
50253 /* Maximum number of 32 bit immediates allowed in a window.  */
50254 #define MAX_IMM_32 4
50255
50256 /* Maximum number of 64 bit immediates allowed in a window.  */
50257 #define MAX_IMM_64 2
50258
50259 /* Maximum total of loads or prefetches allowed in a window.  */
50260 #define MAX_LOAD 2
50261
50262 /* Maximum total of stores allowed in a window.  */
50263 #define MAX_STORE 1
50264
50265 #undef BIG
50266 #define BIG 100
50267
50268
50269 /* Dispatch groups.  Istructions that affect the mix in a dispatch window.  */
50270 enum dispatch_group {
50271   disp_no_group = 0,
50272   disp_load,
50273   disp_store,
50274   disp_load_store,
50275   disp_prefetch,
50276   disp_imm,
50277   disp_imm_32,
50278   disp_imm_64,
50279   disp_branch,
50280   disp_cmp,
50281   disp_jcc,
50282   disp_last
50283 };
50284
50285 /* Number of allowable groups in a dispatch window.  It is an array
50286    indexed by dispatch_group enum.  100 is used as a big number,
50287    because the number of these kind of operations does not have any
50288    effect in dispatch window, but we need them for other reasons in
50289    the table.  */
50290 static unsigned int num_allowable_groups[disp_last] = {
50291   0, 2, 1, 1, 2, 4, 4, 2, 1, BIG, BIG
50292 };
50293
50294 char group_name[disp_last + 1][16] = {
50295   "disp_no_group", "disp_load", "disp_store", "disp_load_store",
50296   "disp_prefetch", "disp_imm", "disp_imm_32", "disp_imm_64",
50297   "disp_branch", "disp_cmp", "disp_jcc", "disp_last"
50298 };
50299
50300 /* Instruction path.  */
50301 enum insn_path {
50302   no_path = 0,
50303   path_single, /* Single micro op.  */
50304   path_double, /* Double micro op.  */
50305   path_multi,  /* Instructions with more than 2 micro op..  */
50306   last_path
50307 };
50308
50309 /* sched_insn_info defines a window to the instructions scheduled in
50310    the basic block.  It contains a pointer to the insn_info table and
50311    the instruction scheduled.
50312
50313    Windows are allocated for each basic block and are linked
50314    together.  */
50315 typedef struct sched_insn_info_s {
50316   rtx insn;
50317   enum dispatch_group group;
50318   enum insn_path path;
50319   int byte_len;
50320   int imm_bytes;
50321 } sched_insn_info;
50322
50323 /* Linked list of dispatch windows.  This is a two way list of
50324    dispatch windows of a basic block.  It contains information about
50325    the number of uops in the window and the total number of
50326    instructions and of bytes in the object code for this dispatch
50327    window.  */
50328 typedef struct dispatch_windows_s {
50329   int num_insn;            /* Number of insn in the window.  */
50330   int num_uops;            /* Number of uops in the window.  */
50331   int window_size;         /* Number of bytes in the window.  */
50332   int window_num;          /* Window number between 0 or 1.  */
50333   int num_imm;             /* Number of immediates in an insn.  */
50334   int num_imm_32;          /* Number of 32 bit immediates in an insn.  */
50335   int num_imm_64;          /* Number of 64 bit immediates in an insn.  */
50336   int imm_size;            /* Total immediates in the window.  */
50337   int num_loads;           /* Total memory loads in the window.  */
50338   int num_stores;          /* Total memory stores in the window.  */
50339   int violation;          /* Violation exists in window.  */
50340   sched_insn_info *window; /* Pointer to the window.  */
50341   struct dispatch_windows_s *next;
50342   struct dispatch_windows_s *prev;
50343 } dispatch_windows;
50344
50345 /* Immediate valuse used in an insn.  */
50346 typedef struct imm_info_s
50347   {
50348     int imm;
50349     int imm32;
50350     int imm64;
50351   } imm_info;
50352
50353 static dispatch_windows *dispatch_window_list;
50354 static dispatch_windows *dispatch_window_list1;
50355
50356 /* Get dispatch group of insn.  */
50357
50358 static enum dispatch_group
50359 get_mem_group (rtx_insn *insn)
50360 {
50361   enum attr_memory memory;
50362
50363   if (INSN_CODE (insn) < 0)
50364     return disp_no_group;
50365   memory = get_attr_memory (insn);
50366   if (memory == MEMORY_STORE)
50367     return disp_store;
50368
50369   if (memory == MEMORY_LOAD)
50370     return disp_load;
50371
50372   if (memory == MEMORY_BOTH)
50373     return disp_load_store;
50374
50375   return disp_no_group;
50376 }
50377
50378 /* Return true if insn is a compare instruction.  */
50379
50380 static bool
50381 is_cmp (rtx_insn *insn)
50382 {
50383   enum attr_type type;
50384
50385   type = get_attr_type (insn);
50386   return (type == TYPE_TEST
50387           || type == TYPE_ICMP
50388           || type == TYPE_FCMP
50389           || GET_CODE (PATTERN (insn)) == COMPARE);
50390 }
50391
50392 /* Return true if a dispatch violation encountered.  */
50393
50394 static bool
50395 dispatch_violation (void)
50396 {
50397   if (dispatch_window_list->next)
50398     return dispatch_window_list->next->violation;
50399   return dispatch_window_list->violation;
50400 }
50401
50402 /* Return true if insn is a branch instruction.  */
50403
50404 static bool
50405 is_branch (rtx insn)
50406 {
50407   return (CALL_P (insn) || JUMP_P (insn));
50408 }
50409
50410 /* Return true if insn is a prefetch instruction.  */
50411
50412 static bool
50413 is_prefetch (rtx insn)
50414 {
50415   return NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == PREFETCH;
50416 }
50417
50418 /* This function initializes a dispatch window and the list container holding a
50419    pointer to the window.  */
50420
50421 static void
50422 init_window (int window_num)
50423 {
50424   int i;
50425   dispatch_windows *new_list;
50426
50427   if (window_num == 0)
50428     new_list = dispatch_window_list;
50429   else
50430     new_list = dispatch_window_list1;
50431
50432   new_list->num_insn = 0;
50433   new_list->num_uops = 0;
50434   new_list->window_size = 0;
50435   new_list->next = NULL;
50436   new_list->prev = NULL;
50437   new_list->window_num = window_num;
50438   new_list->num_imm = 0;
50439   new_list->num_imm_32 = 0;
50440   new_list->num_imm_64 = 0;
50441   new_list->imm_size = 0;
50442   new_list->num_loads = 0;
50443   new_list->num_stores = 0;
50444   new_list->violation = false;
50445
50446   for (i = 0; i < MAX_INSN; i++)
50447     {
50448       new_list->window[i].insn = NULL;
50449       new_list->window[i].group = disp_no_group;
50450       new_list->window[i].path = no_path;
50451       new_list->window[i].byte_len = 0;
50452       new_list->window[i].imm_bytes = 0;
50453     }
50454   return;
50455 }
50456
50457 /* This function allocates and initializes a dispatch window and the
50458    list container holding a pointer to the window.  */
50459
50460 static dispatch_windows *
50461 allocate_window (void)
50462 {
50463   dispatch_windows *new_list = XNEW (struct dispatch_windows_s);
50464   new_list->window = XNEWVEC (struct sched_insn_info_s, MAX_INSN + 1);
50465
50466   return new_list;
50467 }
50468
50469 /* This routine initializes the dispatch scheduling information.  It
50470    initiates building dispatch scheduler tables and constructs the
50471    first dispatch window.  */
50472
50473 static void
50474 init_dispatch_sched (void)
50475 {
50476   /* Allocate a dispatch list and a window.  */
50477   dispatch_window_list = allocate_window ();
50478   dispatch_window_list1 = allocate_window ();
50479   init_window (0);
50480   init_window (1);
50481 }
50482
50483 /* This function returns true if a branch is detected.  End of a basic block
50484    does not have to be a branch, but here we assume only branches end a
50485    window.  */
50486
50487 static bool
50488 is_end_basic_block (enum dispatch_group group)
50489 {
50490   return group == disp_branch;
50491 }
50492
50493 /* This function is called when the end of a window processing is reached.  */
50494
50495 static void
50496 process_end_window (void)
50497 {
50498   gcc_assert (dispatch_window_list->num_insn <= MAX_INSN);
50499   if (dispatch_window_list->next)
50500     {
50501       gcc_assert (dispatch_window_list1->num_insn <= MAX_INSN);
50502       gcc_assert (dispatch_window_list->window_size
50503                   + dispatch_window_list1->window_size <= 48);
50504       init_window (1);
50505     }
50506   init_window (0);
50507 }
50508
50509 /* Allocates a new dispatch window and adds it to WINDOW_LIST.
50510    WINDOW_NUM is either 0 or 1.  A maximum of two windows are generated
50511    for 48 bytes of instructions.  Note that these windows are not dispatch
50512    windows that their sizes are DISPATCH_WINDOW_SIZE.  */
50513
50514 static dispatch_windows *
50515 allocate_next_window (int window_num)
50516 {
50517   if (window_num == 0)
50518     {
50519       if (dispatch_window_list->next)
50520           init_window (1);
50521       init_window (0);
50522       return dispatch_window_list;
50523     }
50524
50525   dispatch_window_list->next = dispatch_window_list1;
50526   dispatch_window_list1->prev = dispatch_window_list;
50527
50528   return dispatch_window_list1;
50529 }
50530
50531 /* Compute number of immediate operands of an instruction.  */
50532
50533 static void
50534 find_constant (rtx in_rtx, imm_info *imm_values)
50535 {
50536   if (INSN_P (in_rtx))
50537     in_rtx = PATTERN (in_rtx);
50538   subrtx_iterator::array_type array;
50539   FOR_EACH_SUBRTX (iter, array, in_rtx, ALL)
50540     if (const_rtx x = *iter)
50541       switch (GET_CODE (x))
50542         {
50543         case CONST:
50544         case SYMBOL_REF:
50545         case CONST_INT:
50546           (imm_values->imm)++;
50547           if (x86_64_immediate_operand (CONST_CAST_RTX (x), SImode))
50548             (imm_values->imm32)++;
50549           else
50550             (imm_values->imm64)++;
50551           break;
50552
50553         case CONST_DOUBLE:
50554           (imm_values->imm)++;
50555           (imm_values->imm64)++;
50556           break;
50557
50558         case CODE_LABEL:
50559           if (LABEL_KIND (x) == LABEL_NORMAL)
50560             {
50561               (imm_values->imm)++;
50562               (imm_values->imm32)++;
50563             }
50564           break;
50565
50566         default:
50567           break;
50568         }
50569 }
50570
50571 /* Return total size of immediate operands of an instruction along with number
50572    of corresponding immediate-operands.  It initializes its parameters to zero
50573    befor calling FIND_CONSTANT.
50574    INSN is the input instruction.  IMM is the total of immediates.
50575    IMM32 is the number of 32 bit immediates.  IMM64 is the number of 64
50576    bit immediates.  */
50577
50578 static int
50579 get_num_immediates (rtx insn, int *imm, int *imm32, int *imm64)
50580 {
50581   imm_info imm_values = {0, 0, 0};
50582
50583   find_constant (insn, &imm_values);
50584   *imm = imm_values.imm;
50585   *imm32 = imm_values.imm32;
50586   *imm64 = imm_values.imm64;
50587   return imm_values.imm32 * 4 + imm_values.imm64 * 8;
50588 }
50589
50590 /* This function indicates if an operand of an instruction is an
50591    immediate.  */
50592
50593 static bool
50594 has_immediate (rtx insn)
50595 {
50596   int num_imm_operand;
50597   int num_imm32_operand;
50598   int num_imm64_operand;
50599
50600   if (insn)
50601     return get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50602                                &num_imm64_operand);
50603   return false;
50604 }
50605
50606 /* Return single or double path for instructions.  */
50607
50608 static enum insn_path
50609 get_insn_path (rtx_insn *insn)
50610 {
50611   enum attr_amdfam10_decode path = get_attr_amdfam10_decode (insn);
50612
50613   if ((int)path == 0)
50614     return path_single;
50615
50616   if ((int)path == 1)
50617     return path_double;
50618
50619   return path_multi;
50620 }
50621
50622 /* Return insn dispatch group.  */
50623
50624 static enum dispatch_group
50625 get_insn_group (rtx_insn *insn)
50626 {
50627   enum dispatch_group group = get_mem_group (insn);
50628   if (group)
50629     return group;
50630
50631   if (is_branch (insn))
50632     return disp_branch;
50633
50634   if (is_cmp (insn))
50635     return disp_cmp;
50636
50637   if (has_immediate (insn))
50638     return disp_imm;
50639
50640   if (is_prefetch (insn))
50641     return disp_prefetch;
50642
50643   return disp_no_group;
50644 }
50645
50646 /* Count number of GROUP restricted instructions in a dispatch
50647    window WINDOW_LIST.  */
50648
50649 static int
50650 count_num_restricted (rtx_insn *insn, dispatch_windows *window_list)
50651 {
50652   enum dispatch_group group = get_insn_group (insn);
50653   int imm_size;
50654   int num_imm_operand;
50655   int num_imm32_operand;
50656   int num_imm64_operand;
50657
50658   if (group == disp_no_group)
50659     return 0;
50660
50661   if (group == disp_imm)
50662     {
50663       imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50664                               &num_imm64_operand);
50665       if (window_list->imm_size + imm_size > MAX_IMM_SIZE
50666           || num_imm_operand + window_list->num_imm > MAX_IMM
50667           || (num_imm32_operand > 0
50668               && (window_list->num_imm_32 + num_imm32_operand > MAX_IMM_32
50669                   || window_list->num_imm_64 * 2 + num_imm32_operand > MAX_IMM_32))
50670           || (num_imm64_operand > 0
50671               && (window_list->num_imm_64 + num_imm64_operand > MAX_IMM_64
50672                   || window_list->num_imm_32 + num_imm64_operand * 2 > MAX_IMM_32))
50673           || (window_list->imm_size + imm_size == MAX_IMM_SIZE
50674               && num_imm64_operand > 0
50675               && ((window_list->num_imm_64 > 0
50676                    && window_list->num_insn >= 2)
50677                   || window_list->num_insn >= 3)))
50678         return BIG;
50679
50680       return 1;
50681     }
50682
50683   if ((group == disp_load_store
50684        && (window_list->num_loads >= MAX_LOAD
50685            || window_list->num_stores >= MAX_STORE))
50686       || ((group == disp_load
50687            || group == disp_prefetch)
50688           && window_list->num_loads >= MAX_LOAD)
50689       || (group == disp_store
50690           && window_list->num_stores >= MAX_STORE))
50691     return BIG;
50692
50693   return 1;
50694 }
50695
50696 /* This function returns true if insn satisfies dispatch rules on the
50697    last window scheduled.  */
50698
50699 static bool
50700 fits_dispatch_window (rtx_insn *insn)
50701 {
50702   dispatch_windows *window_list = dispatch_window_list;
50703   dispatch_windows *window_list_next = dispatch_window_list->next;
50704   unsigned int num_restrict;
50705   enum dispatch_group group = get_insn_group (insn);
50706   enum insn_path path = get_insn_path (insn);
50707   int sum;
50708
50709   /* Make disp_cmp and disp_jcc get scheduled at the latest.  These
50710      instructions should be given the lowest priority in the
50711      scheduling process in Haifa scheduler to make sure they will be
50712      scheduled in the same dispatch window as the reference to them.  */
50713   if (group == disp_jcc || group == disp_cmp)
50714     return false;
50715
50716   /* Check nonrestricted.  */
50717   if (group == disp_no_group || group == disp_branch)
50718     return true;
50719
50720   /* Get last dispatch window.  */
50721   if (window_list_next)
50722     window_list = window_list_next;
50723
50724   if (window_list->window_num == 1)
50725     {
50726       sum = window_list->prev->window_size + window_list->window_size;
50727
50728       if (sum == 32
50729           || (min_insn_size (insn) + sum) >= 48)
50730         /* Window 1 is full.  Go for next window.  */
50731         return true;
50732     }
50733
50734   num_restrict = count_num_restricted (insn, window_list);
50735
50736   if (num_restrict > num_allowable_groups[group])
50737     return false;
50738
50739   /* See if it fits in the first window.  */
50740   if (window_list->window_num == 0)
50741     {
50742       /* The first widow should have only single and double path
50743          uops.  */
50744       if (path == path_double
50745           && (window_list->num_uops + 2) > MAX_INSN)
50746         return false;
50747       else if (path != path_single)
50748         return false;
50749     }
50750   return true;
50751 }
50752
50753 /* Add an instruction INSN with NUM_UOPS micro-operations to the
50754    dispatch window WINDOW_LIST.  */
50755
50756 static void
50757 add_insn_window (rtx_insn *insn, dispatch_windows *window_list, int num_uops)
50758 {
50759   int byte_len = min_insn_size (insn);
50760   int num_insn = window_list->num_insn;
50761   int imm_size;
50762   sched_insn_info *window = window_list->window;
50763   enum dispatch_group group = get_insn_group (insn);
50764   enum insn_path path = get_insn_path (insn);
50765   int num_imm_operand;
50766   int num_imm32_operand;
50767   int num_imm64_operand;
50768
50769   if (!window_list->violation && group != disp_cmp
50770       && !fits_dispatch_window (insn))
50771     window_list->violation = true;
50772
50773   imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50774                                  &num_imm64_operand);
50775
50776   /* Initialize window with new instruction.  */
50777   window[num_insn].insn = insn;
50778   window[num_insn].byte_len = byte_len;
50779   window[num_insn].group = group;
50780   window[num_insn].path = path;
50781   window[num_insn].imm_bytes = imm_size;
50782
50783   window_list->window_size += byte_len;
50784   window_list->num_insn = num_insn + 1;
50785   window_list->num_uops = window_list->num_uops + num_uops;
50786   window_list->imm_size += imm_size;
50787   window_list->num_imm += num_imm_operand;
50788   window_list->num_imm_32 += num_imm32_operand;
50789   window_list->num_imm_64 += num_imm64_operand;
50790
50791   if (group == disp_store)
50792     window_list->num_stores += 1;
50793   else if (group == disp_load
50794            || group == disp_prefetch)
50795     window_list->num_loads += 1;
50796   else if (group == disp_load_store)
50797     {
50798       window_list->num_stores += 1;
50799       window_list->num_loads += 1;
50800     }
50801 }
50802
50803 /* Adds a scheduled instruction, INSN, to the current dispatch window.
50804    If the total bytes of instructions or the number of instructions in
50805    the window exceed allowable, it allocates a new window.  */
50806
50807 static void
50808 add_to_dispatch_window (rtx_insn *insn)
50809 {
50810   int byte_len;
50811   dispatch_windows *window_list;
50812   dispatch_windows *next_list;
50813   dispatch_windows *window0_list;
50814   enum insn_path path;
50815   enum dispatch_group insn_group;
50816   bool insn_fits;
50817   int num_insn;
50818   int num_uops;
50819   int window_num;
50820   int insn_num_uops;
50821   int sum;
50822
50823   if (INSN_CODE (insn) < 0)
50824     return;
50825
50826   byte_len = min_insn_size (insn);
50827   window_list = dispatch_window_list;
50828   next_list = window_list->next;
50829   path = get_insn_path (insn);
50830   insn_group = get_insn_group (insn);
50831
50832   /* Get the last dispatch window.  */
50833   if (next_list)
50834       window_list = dispatch_window_list->next;
50835
50836   if (path == path_single)
50837     insn_num_uops = 1;
50838   else if (path == path_double)
50839     insn_num_uops = 2;
50840   else
50841     insn_num_uops = (int) path;
50842
50843   /* If current window is full, get a new window.
50844      Window number zero is full, if MAX_INSN uops are scheduled in it.
50845      Window number one is full, if window zero's bytes plus window
50846      one's bytes is 32, or if the bytes of the new instruction added
50847      to the total makes it greater than 48, or it has already MAX_INSN
50848      instructions in it.  */
50849   num_insn = window_list->num_insn;
50850   num_uops = window_list->num_uops;
50851   window_num = window_list->window_num;
50852   insn_fits = fits_dispatch_window (insn);
50853
50854   if (num_insn >= MAX_INSN
50855       || num_uops + insn_num_uops > MAX_INSN
50856       || !(insn_fits))
50857     {
50858       window_num = ~window_num & 1;
50859       window_list = allocate_next_window (window_num);
50860     }
50861
50862   if (window_num == 0)
50863     {
50864       add_insn_window (insn, window_list, insn_num_uops);
50865       if (window_list->num_insn >= MAX_INSN
50866           && insn_group == disp_branch)
50867         {
50868           process_end_window ();
50869           return;
50870         }
50871     }
50872   else if (window_num == 1)
50873     {
50874       window0_list = window_list->prev;
50875       sum = window0_list->window_size + window_list->window_size;
50876       if (sum == 32
50877           || (byte_len + sum) >= 48)
50878         {
50879           process_end_window ();
50880           window_list = dispatch_window_list;
50881         }
50882
50883       add_insn_window (insn, window_list, insn_num_uops);
50884     }
50885   else
50886     gcc_unreachable ();
50887
50888   if (is_end_basic_block (insn_group))
50889     {
50890       /* End of basic block is reached do end-basic-block process.  */
50891       process_end_window ();
50892       return;
50893     }
50894 }
50895
50896 /* Print the dispatch window, WINDOW_NUM, to FILE.  */
50897
50898 DEBUG_FUNCTION static void
50899 debug_dispatch_window_file (FILE *file, int window_num)
50900 {
50901   dispatch_windows *list;
50902   int i;
50903
50904   if (window_num == 0)
50905     list = dispatch_window_list;
50906   else
50907     list = dispatch_window_list1;
50908
50909   fprintf (file, "Window #%d:\n", list->window_num);
50910   fprintf (file, "  num_insn = %d, num_uops = %d, window_size = %d\n",
50911           list->num_insn, list->num_uops, list->window_size);
50912   fprintf (file, "  num_imm = %d, num_imm_32 = %d, num_imm_64 = %d, imm_size = %d\n",
50913            list->num_imm, list->num_imm_32, list->num_imm_64, list->imm_size);
50914
50915   fprintf (file, "  num_loads = %d, num_stores = %d\n", list->num_loads,
50916           list->num_stores);
50917   fprintf (file, " insn info:\n");
50918
50919   for (i = 0; i < MAX_INSN; i++)
50920     {
50921       if (!list->window[i].insn)
50922         break;
50923       fprintf (file, "    group[%d] = %s, insn[%d] = %p, path[%d] = %d byte_len[%d] = %d, imm_bytes[%d] = %d\n",
50924               i, group_name[list->window[i].group],
50925               i, (void *)list->window[i].insn,
50926               i, list->window[i].path,
50927               i, list->window[i].byte_len,
50928               i, list->window[i].imm_bytes);
50929     }
50930 }
50931
50932 /* Print to stdout a dispatch window.  */
50933
50934 DEBUG_FUNCTION void
50935 debug_dispatch_window (int window_num)
50936 {
50937   debug_dispatch_window_file (stdout, window_num);
50938 }
50939
50940 /* Print INSN dispatch information to FILE.  */
50941
50942 DEBUG_FUNCTION static void
50943 debug_insn_dispatch_info_file (FILE *file, rtx_insn *insn)
50944 {
50945   int byte_len;
50946   enum insn_path path;
50947   enum dispatch_group group;
50948   int imm_size;
50949   int num_imm_operand;
50950   int num_imm32_operand;
50951   int num_imm64_operand;
50952
50953   if (INSN_CODE (insn) < 0)
50954     return;
50955
50956   byte_len = min_insn_size (insn);
50957   path = get_insn_path (insn);
50958   group = get_insn_group (insn);
50959   imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50960                                  &num_imm64_operand);
50961
50962   fprintf (file, " insn info:\n");
50963   fprintf (file, "  group = %s, path = %d, byte_len = %d\n",
50964            group_name[group], path, byte_len);
50965   fprintf (file, "  num_imm = %d, num_imm_32 = %d, num_imm_64 = %d, imm_size = %d\n",
50966            num_imm_operand, num_imm32_operand, num_imm64_operand, imm_size);
50967 }
50968
50969 /* Print to STDERR the status of the ready list with respect to
50970    dispatch windows.  */
50971
50972 DEBUG_FUNCTION void
50973 debug_ready_dispatch (void)
50974 {
50975   int i;
50976   int no_ready = number_in_ready ();
50977
50978   fprintf (stdout, "Number of ready: %d\n", no_ready);
50979
50980   for (i = 0; i < no_ready; i++)
50981     debug_insn_dispatch_info_file (stdout, get_ready_element (i));
50982 }
50983
50984 /* This routine is the driver of the dispatch scheduler.  */
50985
50986 static void
50987 do_dispatch (rtx_insn *insn, int mode)
50988 {
50989   if (mode == DISPATCH_INIT)
50990     init_dispatch_sched ();
50991   else if (mode == ADD_TO_DISPATCH_WINDOW)
50992     add_to_dispatch_window (insn);
50993 }
50994
50995 /* Return TRUE if Dispatch Scheduling is supported.  */
50996
50997 static bool
50998 has_dispatch (rtx_insn *insn, int action)
50999 {
51000   if ((TARGET_BDVER1 || TARGET_BDVER2 || TARGET_BDVER3 || TARGET_BDVER4)
51001       && flag_dispatch_scheduler)
51002     switch (action)
51003       {
51004       default:
51005         return false;
51006
51007       case IS_DISPATCH_ON:
51008         return true;
51009         break;
51010
51011       case IS_CMP:
51012         return is_cmp (insn);
51013
51014       case DISPATCH_VIOLATION:
51015         return dispatch_violation ();
51016
51017       case FITS_DISPATCH_WINDOW:
51018         return fits_dispatch_window (insn);
51019       }
51020
51021   return false;
51022 }
51023
51024 /* Implementation of reassociation_width target hook used by
51025    reassoc phase to identify parallelism level in reassociated
51026    tree.  Statements tree_code is passed in OPC.  Arguments type
51027    is passed in MODE.
51028
51029    Currently parallel reassociation is enabled for Atom
51030    processors only and we set reassociation width to be 2
51031    because Atom may issue up to 2 instructions per cycle.
51032
51033    Return value should be fixed if parallel reassociation is
51034    enabled for other processors.  */
51035
51036 static int
51037 ix86_reassociation_width (unsigned int, machine_mode mode)
51038 {
51039   /* Vector part.  */
51040   if (VECTOR_MODE_P (mode))
51041     {
51042       if (TARGET_VECTOR_PARALLEL_EXECUTION)
51043         return 2;
51044       else
51045         return 1;
51046     }
51047
51048   /* Scalar part.  */
51049   if (INTEGRAL_MODE_P (mode) && TARGET_REASSOC_INT_TO_PARALLEL)
51050     return 2;
51051   else if (FLOAT_MODE_P (mode) && TARGET_REASSOC_FP_TO_PARALLEL)
51052     return 2;
51053   else
51054     return 1;
51055 }
51056
51057 /* ??? No autovectorization into MMX or 3DNOW until we can reliably
51058    place emms and femms instructions.  */
51059
51060 static machine_mode
51061 ix86_preferred_simd_mode (machine_mode mode)
51062 {
51063   if (!TARGET_SSE)
51064     return word_mode;
51065
51066   switch (mode)
51067     {
51068     case QImode:
51069       return TARGET_AVX512BW ? V64QImode :
51070        (TARGET_AVX && !TARGET_PREFER_AVX128) ? V32QImode : V16QImode;
51071     case HImode:
51072       return TARGET_AVX512BW ? V32HImode :
51073        (TARGET_AVX && !TARGET_PREFER_AVX128) ? V16HImode : V8HImode;
51074     case SImode:
51075       return TARGET_AVX512F ? V16SImode :
51076         (TARGET_AVX && !TARGET_PREFER_AVX128) ? V8SImode : V4SImode;
51077     case DImode:
51078       return TARGET_AVX512F ? V8DImode :
51079         (TARGET_AVX && !TARGET_PREFER_AVX128) ? V4DImode : V2DImode;
51080
51081     case SFmode:
51082       if (TARGET_AVX512F)
51083         return V16SFmode;
51084       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
51085         return V8SFmode;
51086       else
51087         return V4SFmode;
51088
51089     case DFmode:
51090       if (!TARGET_VECTORIZE_DOUBLE)
51091         return word_mode;
51092       else if (TARGET_AVX512F)
51093         return V8DFmode;
51094       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
51095         return V4DFmode;
51096       else if (TARGET_SSE2)
51097         return V2DFmode;
51098       /* FALLTHRU */
51099
51100     default:
51101       return word_mode;
51102     }
51103 }
51104
51105 /* If AVX is enabled then try vectorizing with both 256bit and 128bit
51106    vectors.  If AVX512F is enabled then try vectorizing with 512bit,
51107    256bit and 128bit vectors.  */
51108
51109 static unsigned int
51110 ix86_autovectorize_vector_sizes (void)
51111 {
51112   return TARGET_AVX512F ? 64 | 32 | 16 :
51113     (TARGET_AVX && !TARGET_PREFER_AVX128) ? 32 | 16 : 0;
51114 }
51115
51116 \f
51117
51118 /* Return class of registers which could be used for pseudo of MODE
51119    and of class RCLASS for spilling instead of memory.  Return NO_REGS
51120    if it is not possible or non-profitable.  */
51121 static reg_class_t
51122 ix86_spill_class (reg_class_t rclass, machine_mode mode)
51123 {
51124   if (TARGET_SSE && TARGET_GENERAL_REGS_SSE_SPILL && ! TARGET_MMX
51125       && (mode == SImode || (TARGET_64BIT && mode == DImode))
51126       && rclass != NO_REGS && INTEGER_CLASS_P (rclass))
51127     return ALL_SSE_REGS;
51128   return NO_REGS;
51129 }
51130
51131 /* Implement targetm.vectorize.init_cost.  */
51132
51133 static void *
51134 ix86_init_cost (struct loop *)
51135 {
51136   unsigned *cost = XNEWVEC (unsigned, 3);
51137   cost[vect_prologue] = cost[vect_body] = cost[vect_epilogue] = 0;
51138   return cost;
51139 }
51140
51141 /* Implement targetm.vectorize.add_stmt_cost.  */
51142
51143 static unsigned
51144 ix86_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
51145                     struct _stmt_vec_info *stmt_info, int misalign,
51146                     enum vect_cost_model_location where)
51147 {
51148   unsigned *cost = (unsigned *) data;
51149   unsigned retval = 0;
51150
51151   tree vectype = stmt_info ? stmt_vectype (stmt_info) : NULL_TREE;
51152   int stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
51153
51154   /* Statements in an inner loop relative to the loop being
51155      vectorized are weighted more heavily.  The value here is
51156       arbitrary and could potentially be improved with analysis.  */
51157   if (where == vect_body && stmt_info && stmt_in_inner_loop_p (stmt_info))
51158     count *= 50;  /* FIXME.  */
51159
51160   retval = (unsigned) (count * stmt_cost);
51161
51162   /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
51163      for Silvermont as it has out of order integer pipeline and can execute
51164      2 scalar instruction per tick, but has in order SIMD pipeline.  */
51165   if (TARGET_SILVERMONT || TARGET_INTEL)
51166     if (stmt_info && stmt_info->stmt)
51167       {
51168         tree lhs_op = gimple_get_lhs (stmt_info->stmt);
51169         if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE)
51170           retval = (retval * 17) / 10;
51171       }
51172
51173   cost[where] += retval;
51174
51175   return retval;
51176 }
51177
51178 /* Implement targetm.vectorize.finish_cost.  */
51179
51180 static void
51181 ix86_finish_cost (void *data, unsigned *prologue_cost,
51182                   unsigned *body_cost, unsigned *epilogue_cost)
51183 {
51184   unsigned *cost = (unsigned *) data;
51185   *prologue_cost = cost[vect_prologue];
51186   *body_cost     = cost[vect_body];
51187   *epilogue_cost = cost[vect_epilogue];
51188 }
51189
51190 /* Implement targetm.vectorize.destroy_cost_data.  */
51191
51192 static void
51193 ix86_destroy_cost_data (void *data)
51194 {
51195   free (data);
51196 }
51197
51198 /* Validate target specific memory model bits in VAL. */
51199
51200 static unsigned HOST_WIDE_INT
51201 ix86_memmodel_check (unsigned HOST_WIDE_INT val)
51202 {
51203   unsigned HOST_WIDE_INT model = val & MEMMODEL_MASK;
51204   bool strong;
51205
51206   if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE
51207                                       |MEMMODEL_MASK)
51208       || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE)))
51209     {
51210       warning (OPT_Winvalid_memory_model,
51211                "Unknown architecture specific memory model");
51212       return MEMMODEL_SEQ_CST;
51213     }
51214   strong = (model == MEMMODEL_ACQ_REL || model == MEMMODEL_SEQ_CST);
51215   if (val & IX86_HLE_ACQUIRE && !(model == MEMMODEL_ACQUIRE || strong))
51216     {
51217       warning (OPT_Winvalid_memory_model,
51218               "HLE_ACQUIRE not used with ACQUIRE or stronger memory model");
51219       return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE;
51220     }
51221    if (val & IX86_HLE_RELEASE && !(model == MEMMODEL_RELEASE || strong))
51222     {
51223       warning (OPT_Winvalid_memory_model,
51224               "HLE_RELEASE not used with RELEASE or stronger memory model");
51225       return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE;
51226     }
51227   return val;
51228 }
51229
51230 /* Set CLONEI->vecsize_mangle, CLONEI->vecsize_int,
51231    CLONEI->vecsize_float and if CLONEI->simdlen is 0, also
51232    CLONEI->simdlen.  Return 0 if SIMD clones shouldn't be emitted,
51233    or number of vecsize_mangle variants that should be emitted.  */
51234
51235 static int
51236 ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node,
51237                                              struct cgraph_simd_clone *clonei,
51238                                              tree base_type, int num)
51239 {
51240   int ret = 1;
51241
51242   if (clonei->simdlen
51243       && (clonei->simdlen < 2
51244           || clonei->simdlen > 16
51245           || (clonei->simdlen & (clonei->simdlen - 1)) != 0))
51246     {
51247       warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51248                   "unsupported simdlen %d", clonei->simdlen);
51249       return 0;
51250     }
51251
51252   tree ret_type = TREE_TYPE (TREE_TYPE (node->decl));
51253   if (TREE_CODE (ret_type) != VOID_TYPE)
51254     switch (TYPE_MODE (ret_type))
51255       {
51256       case QImode:
51257       case HImode:
51258       case SImode:
51259       case DImode:
51260       case SFmode:
51261       case DFmode:
51262       /* case SCmode: */
51263       /* case DCmode: */
51264         break;
51265       default:
51266         warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51267                     "unsupported return type %qT for simd\n", ret_type);
51268         return 0;
51269       }
51270
51271   tree t;
51272   int i;
51273
51274   for (t = DECL_ARGUMENTS (node->decl), i = 0; t; t = DECL_CHAIN (t), i++)
51275     /* FIXME: Shouldn't we allow such arguments if they are uniform?  */
51276     switch (TYPE_MODE (TREE_TYPE (t)))
51277       {
51278       case QImode:
51279       case HImode:
51280       case SImode:
51281       case DImode:
51282       case SFmode:
51283       case DFmode:
51284       /* case SCmode: */
51285       /* case DCmode: */
51286         break;
51287       default:
51288         warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51289                     "unsupported argument type %qT for simd\n", TREE_TYPE (t));
51290         return 0;
51291       }
51292
51293   if (clonei->cilk_elemental)
51294     {
51295       /* Parse here processor clause.  If not present, default to 'b'.  */
51296       clonei->vecsize_mangle = 'b';
51297     }
51298   else if (!TREE_PUBLIC (node->decl))
51299     {
51300       /* If the function isn't exported, we can pick up just one ISA
51301          for the clones.  */
51302       if (TARGET_AVX2)
51303         clonei->vecsize_mangle = 'd';
51304       else if (TARGET_AVX)
51305         clonei->vecsize_mangle = 'c';
51306       else
51307         clonei->vecsize_mangle = 'b';
51308       ret = 1;
51309     }
51310   else
51311     {
51312       clonei->vecsize_mangle = "bcd"[num];
51313       ret = 3;
51314     }
51315   switch (clonei->vecsize_mangle)
51316     {
51317     case 'b':
51318       clonei->vecsize_int = 128;
51319       clonei->vecsize_float = 128;
51320       break;
51321     case 'c':
51322       clonei->vecsize_int = 128;
51323       clonei->vecsize_float = 256;
51324       break;
51325     case 'd':
51326       clonei->vecsize_int = 256;
51327       clonei->vecsize_float = 256;
51328       break;
51329     }
51330   if (clonei->simdlen == 0)
51331     {
51332       if (SCALAR_INT_MODE_P (TYPE_MODE (base_type)))
51333         clonei->simdlen = clonei->vecsize_int;
51334       else
51335         clonei->simdlen = clonei->vecsize_float;
51336       clonei->simdlen /= GET_MODE_BITSIZE (TYPE_MODE (base_type));
51337       if (clonei->simdlen > 16)
51338         clonei->simdlen = 16;
51339     }
51340   return ret;
51341 }
51342
51343 /* Add target attribute to SIMD clone NODE if needed.  */
51344
51345 static void
51346 ix86_simd_clone_adjust (struct cgraph_node *node)
51347 {
51348   const char *str = NULL;
51349   gcc_assert (node->decl == cfun->decl);
51350   switch (node->simdclone->vecsize_mangle)
51351     {
51352     case 'b':
51353       if (!TARGET_SSE2)
51354         str = "sse2";
51355       break;
51356     case 'c':
51357       if (!TARGET_AVX)
51358         str = "avx";
51359       break;
51360     case 'd':
51361       if (!TARGET_AVX2)
51362         str = "avx2";
51363       break;
51364     default:
51365       gcc_unreachable ();
51366     }
51367   if (str == NULL)
51368     return;
51369   push_cfun (NULL);
51370   tree args = build_tree_list (NULL_TREE, build_string (strlen (str), str));
51371   bool ok = ix86_valid_target_attribute_p (node->decl, NULL, args, 0);
51372   gcc_assert (ok);
51373   pop_cfun ();
51374   ix86_reset_previous_fndecl ();
51375   ix86_set_current_function (node->decl);
51376 }
51377
51378 /* If SIMD clone NODE can't be used in a vectorized loop
51379    in current function, return -1, otherwise return a badness of using it
51380    (0 if it is most desirable from vecsize_mangle point of view, 1
51381    slightly less desirable, etc.).  */
51382
51383 static int
51384 ix86_simd_clone_usable (struct cgraph_node *node)
51385 {
51386   switch (node->simdclone->vecsize_mangle)
51387     {
51388     case 'b':
51389       if (!TARGET_SSE2)
51390         return -1;
51391       if (!TARGET_AVX)
51392         return 0;
51393       return TARGET_AVX2 ? 2 : 1;
51394     case 'c':
51395       if (!TARGET_AVX)
51396         return -1;
51397       return TARGET_AVX2 ? 1 : 0;
51398       break;
51399     case 'd':
51400       if (!TARGET_AVX2)
51401         return -1;
51402       return 0;
51403     default:
51404       gcc_unreachable ();
51405     }
51406 }
51407
51408 /* This function adjusts the unroll factor based on
51409    the hardware capabilities. For ex, bdver3 has
51410    a loop buffer which makes unrolling of smaller
51411    loops less important. This function decides the
51412    unroll factor using number of memory references
51413    (value 32 is used) as a heuristic. */
51414
51415 static unsigned
51416 ix86_loop_unroll_adjust (unsigned nunroll, struct loop *loop)
51417 {
51418   basic_block *bbs;
51419   rtx_insn *insn;
51420   unsigned i;
51421   unsigned mem_count = 0;
51422
51423   if (!TARGET_ADJUST_UNROLL)
51424      return nunroll;
51425
51426   /* Count the number of memory references within the loop body.
51427      This value determines the unrolling factor for bdver3 and bdver4
51428      architectures. */
51429   subrtx_iterator::array_type array;
51430   bbs = get_loop_body (loop);
51431   for (i = 0; i < loop->num_nodes; i++)
51432     FOR_BB_INSNS (bbs[i], insn)
51433       if (NONDEBUG_INSN_P (insn))
51434         FOR_EACH_SUBRTX (iter, array, insn, NONCONST)
51435           if (const_rtx x = *iter)
51436             if (MEM_P (x))
51437               {
51438                 machine_mode mode = GET_MODE (x);
51439                 unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
51440                 if (n_words > 4)
51441                   mem_count += 2;
51442                 else
51443                   mem_count += 1;
51444               }
51445   free (bbs);
51446
51447   if (mem_count && mem_count <=32)
51448     return 32/mem_count;
51449
51450   return nunroll;
51451 }
51452
51453
51454 /* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P.  */
51455
51456 static bool
51457 ix86_float_exceptions_rounding_supported_p (void)
51458 {
51459   /* For x87 floating point with standard excess precision handling,
51460      there is no adddf3 pattern (since x87 floating point only has
51461      XFmode operations) so the default hook implementation gets this
51462      wrong.  */
51463   return TARGET_80387 || TARGET_SSE_MATH;
51464 }
51465
51466 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV.  */
51467
51468 static void
51469 ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
51470 {
51471   if (!TARGET_80387 && !TARGET_SSE_MATH)
51472     return;
51473   tree exceptions_var = create_tmp_var (integer_type_node);
51474   if (TARGET_80387)
51475     {
51476       tree fenv_index_type = build_index_type (size_int (6));
51477       tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
51478       tree fenv_var = create_tmp_var (fenv_type);
51479       mark_addressable (fenv_var);
51480       tree fenv_ptr = build_pointer_type (fenv_type);
51481       tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
51482       fenv_addr = fold_convert (ptr_type_node, fenv_addr);
51483       tree fnstenv = ix86_builtins[IX86_BUILTIN_FNSTENV];
51484       tree fldenv = ix86_builtins[IX86_BUILTIN_FLDENV];
51485       tree fnstsw = ix86_builtins[IX86_BUILTIN_FNSTSW];
51486       tree fnclex = ix86_builtins[IX86_BUILTIN_FNCLEX];
51487       tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
51488       tree hold_fnclex = build_call_expr (fnclex, 0);
51489       *hold = build2 (COMPOUND_EXPR, void_type_node, hold_fnstenv,
51490                       hold_fnclex);
51491       *clear = build_call_expr (fnclex, 0);
51492       tree sw_var = create_tmp_var (short_unsigned_type_node);
51493       tree fnstsw_call = build_call_expr (fnstsw, 0);
51494       tree sw_mod = build2 (MODIFY_EXPR, short_unsigned_type_node,
51495                             sw_var, fnstsw_call);
51496       tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
51497       tree update_mod = build2 (MODIFY_EXPR, integer_type_node,
51498                                 exceptions_var, exceptions_x87);
51499       *update = build2 (COMPOUND_EXPR, integer_type_node,
51500                         sw_mod, update_mod);
51501       tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
51502       *update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv);
51503     }
51504   if (TARGET_SSE_MATH)
51505     {
51506       tree mxcsr_orig_var = create_tmp_var (unsigned_type_node);
51507       tree mxcsr_mod_var = create_tmp_var (unsigned_type_node);
51508       tree stmxcsr = ix86_builtins[IX86_BUILTIN_STMXCSR];
51509       tree ldmxcsr = ix86_builtins[IX86_BUILTIN_LDMXCSR];
51510       tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
51511       tree hold_assign_orig = build2 (MODIFY_EXPR, unsigned_type_node,
51512                                       mxcsr_orig_var, stmxcsr_hold_call);
51513       tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
51514                                   mxcsr_orig_var,
51515                                   build_int_cst (unsigned_type_node, 0x1f80));
51516       hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
51517                              build_int_cst (unsigned_type_node, 0xffffffc0));
51518       tree hold_assign_mod = build2 (MODIFY_EXPR, unsigned_type_node,
51519                                      mxcsr_mod_var, hold_mod_val);
51520       tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
51521       tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
51522                               hold_assign_orig, hold_assign_mod);
51523       hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all,
51524                          ldmxcsr_hold_call);
51525       if (*hold)
51526         *hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all);
51527       else
51528         *hold = hold_all;
51529       tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
51530       if (*clear)
51531         *clear = build2 (COMPOUND_EXPR, void_type_node, *clear,
51532                          ldmxcsr_clear_call);
51533       else
51534         *clear = ldmxcsr_clear_call;
51535       tree stxmcsr_update_call = build_call_expr (stmxcsr, 0);
51536       tree exceptions_sse = fold_convert (integer_type_node,
51537                                           stxmcsr_update_call);
51538       if (*update)
51539         {
51540           tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node,
51541                                         exceptions_var, exceptions_sse);
51542           tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node,
51543                                            exceptions_var, exceptions_mod);
51544           *update = build2 (COMPOUND_EXPR, integer_type_node, *update,
51545                             exceptions_assign);
51546         }
51547       else
51548         *update = build2 (MODIFY_EXPR, integer_type_node,
51549                           exceptions_var, exceptions_sse);
51550       tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
51551       *update = build2 (COMPOUND_EXPR, void_type_node, *update,
51552                         ldmxcsr_update_call);
51553     }
51554   tree atomic_feraiseexcept
51555     = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
51556   tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
51557                                                     1, exceptions_var);
51558   *update = build2 (COMPOUND_EXPR, void_type_node, *update,
51559                     atomic_feraiseexcept_call);
51560 }
51561
51562 /* Return mode to be used for bounds or VOIDmode
51563    if bounds are not supported.  */
51564
51565 static enum machine_mode
51566 ix86_mpx_bound_mode ()
51567 {
51568   /* Do not support pointer checker if MPX
51569      is not enabled.  */
51570   if (!TARGET_MPX)
51571     {
51572       if (flag_check_pointer_bounds)
51573         warning (0, "Pointer Checker requires MPX support on this target."
51574                  " Use -mmpx options to enable MPX.");
51575       return VOIDmode;
51576     }
51577
51578   return BNDmode;
51579 }
51580
51581 /*  Return constant used to statically initialize constant bounds.
51582
51583     This function is used to create special bound values.  For now
51584     only INIT bounds and NONE bounds are expected.  More special
51585     values may be added later.  */
51586
51587 static tree
51588 ix86_make_bounds_constant (HOST_WIDE_INT lb, HOST_WIDE_INT ub)
51589 {
51590   tree low = lb ? build_minus_one_cst (pointer_sized_int_node)
51591     : build_zero_cst (pointer_sized_int_node);
51592   tree high = ub ? build_zero_cst (pointer_sized_int_node)
51593     : build_minus_one_cst (pointer_sized_int_node);
51594
51595   /* This function is supposed to be used to create INIT and
51596      NONE bounds only.  */
51597   gcc_assert ((lb == 0 && ub == -1)
51598               || (lb == -1 && ub == 0));
51599
51600   return build_complex (NULL, low, high);
51601 }
51602
51603 /* Generate a list of statements STMTS to initialize pointer bounds
51604    variable VAR with bounds LB and UB.  Return the number of generated
51605    statements.  */
51606
51607 static int
51608 ix86_initialize_bounds (tree var, tree lb, tree ub, tree *stmts)
51609 {
51610   tree bnd_ptr = build_pointer_type (pointer_sized_int_node);
51611   tree lhs, modify, var_p;
51612
51613   ub = build1 (BIT_NOT_EXPR, pointer_sized_int_node, ub);
51614   var_p = fold_convert (bnd_ptr, build_fold_addr_expr (var));
51615
51616   lhs = build1 (INDIRECT_REF, pointer_sized_int_node, var_p);
51617   modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, lb);
51618   append_to_statement_list (modify, stmts);
51619
51620   lhs = build1 (INDIRECT_REF, pointer_sized_int_node,
51621                 build2 (POINTER_PLUS_EXPR, bnd_ptr, var_p,
51622                         TYPE_SIZE_UNIT (pointer_sized_int_node)));
51623   modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, ub);
51624   append_to_statement_list (modify, stmts);
51625
51626   return 2;
51627 }
51628
51629 /* Initialize the GCC target structure.  */
51630 #undef TARGET_RETURN_IN_MEMORY
51631 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
51632
51633 #undef TARGET_LEGITIMIZE_ADDRESS
51634 #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
51635
51636 #undef TARGET_ATTRIBUTE_TABLE
51637 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
51638 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
51639 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
51640 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
51641 #  undef TARGET_MERGE_DECL_ATTRIBUTES
51642 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
51643 #endif
51644
51645 #undef TARGET_COMP_TYPE_ATTRIBUTES
51646 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
51647
51648 #undef TARGET_INIT_BUILTINS
51649 #define TARGET_INIT_BUILTINS ix86_init_builtins
51650 #undef TARGET_BUILTIN_DECL
51651 #define TARGET_BUILTIN_DECL ix86_builtin_decl
51652 #undef TARGET_EXPAND_BUILTIN
51653 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
51654
51655 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
51656 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
51657   ix86_builtin_vectorized_function
51658
51659 #undef TARGET_VECTORIZE_BUILTIN_TM_LOAD
51660 #define TARGET_VECTORIZE_BUILTIN_TM_LOAD ix86_builtin_tm_load
51661
51662 #undef TARGET_VECTORIZE_BUILTIN_TM_STORE
51663 #define TARGET_VECTORIZE_BUILTIN_TM_STORE ix86_builtin_tm_store
51664
51665 #undef TARGET_VECTORIZE_BUILTIN_GATHER
51666 #define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather
51667
51668 #undef TARGET_BUILTIN_RECIPROCAL
51669 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
51670
51671 #undef TARGET_ASM_FUNCTION_EPILOGUE
51672 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
51673
51674 #undef TARGET_ENCODE_SECTION_INFO
51675 #ifndef SUBTARGET_ENCODE_SECTION_INFO
51676 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
51677 #else
51678 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
51679 #endif
51680
51681 #undef TARGET_ASM_OPEN_PAREN
51682 #define TARGET_ASM_OPEN_PAREN ""
51683 #undef TARGET_ASM_CLOSE_PAREN
51684 #define TARGET_ASM_CLOSE_PAREN ""
51685
51686 #undef TARGET_ASM_BYTE_OP
51687 #define TARGET_ASM_BYTE_OP ASM_BYTE
51688
51689 #undef TARGET_ASM_ALIGNED_HI_OP
51690 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
51691 #undef TARGET_ASM_ALIGNED_SI_OP
51692 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
51693 #ifdef ASM_QUAD
51694 #undef TARGET_ASM_ALIGNED_DI_OP
51695 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
51696 #endif
51697
51698 #undef TARGET_PROFILE_BEFORE_PROLOGUE
51699 #define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
51700
51701 #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
51702 #define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name
51703
51704 #undef TARGET_ASM_UNALIGNED_HI_OP
51705 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
51706 #undef TARGET_ASM_UNALIGNED_SI_OP
51707 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
51708 #undef TARGET_ASM_UNALIGNED_DI_OP
51709 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
51710
51711 #undef TARGET_PRINT_OPERAND
51712 #define TARGET_PRINT_OPERAND ix86_print_operand
51713 #undef TARGET_PRINT_OPERAND_ADDRESS
51714 #define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address
51715 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
51716 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p
51717 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
51718 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra
51719
51720 #undef TARGET_SCHED_INIT_GLOBAL
51721 #define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global
51722 #undef TARGET_SCHED_ADJUST_COST
51723 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
51724 #undef TARGET_SCHED_ISSUE_RATE
51725 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
51726 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
51727 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
51728   ia32_multipass_dfa_lookahead
51729 #undef TARGET_SCHED_MACRO_FUSION_P
51730 #define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p
51731 #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
51732 #define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p
51733
51734 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
51735 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
51736
51737 #undef TARGET_MEMMODEL_CHECK
51738 #define TARGET_MEMMODEL_CHECK ix86_memmodel_check
51739
51740 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
51741 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv
51742
51743 #ifdef HAVE_AS_TLS
51744 #undef TARGET_HAVE_TLS
51745 #define TARGET_HAVE_TLS true
51746 #endif
51747 #undef TARGET_CANNOT_FORCE_CONST_MEM
51748 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
51749 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
51750 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
51751
51752 #undef TARGET_DELEGITIMIZE_ADDRESS
51753 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
51754
51755 #undef TARGET_MS_BITFIELD_LAYOUT_P
51756 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
51757
51758 #if TARGET_MACHO
51759 #undef TARGET_BINDS_LOCAL_P
51760 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
51761 #endif
51762 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
51763 #undef TARGET_BINDS_LOCAL_P
51764 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
51765 #endif
51766
51767 #undef TARGET_ASM_OUTPUT_MI_THUNK
51768 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
51769 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
51770 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
51771
51772 #undef TARGET_ASM_FILE_START
51773 #define TARGET_ASM_FILE_START x86_file_start
51774
51775 #undef TARGET_OPTION_OVERRIDE
51776 #define TARGET_OPTION_OVERRIDE ix86_option_override
51777
51778 #undef TARGET_REGISTER_MOVE_COST
51779 #define TARGET_REGISTER_MOVE_COST ix86_register_move_cost
51780 #undef TARGET_MEMORY_MOVE_COST
51781 #define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost
51782 #undef TARGET_RTX_COSTS
51783 #define TARGET_RTX_COSTS ix86_rtx_costs
51784 #undef TARGET_ADDRESS_COST
51785 #define TARGET_ADDRESS_COST ix86_address_cost
51786
51787 #undef TARGET_FIXED_CONDITION_CODE_REGS
51788 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
51789 #undef TARGET_CC_MODES_COMPATIBLE
51790 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
51791
51792 #undef TARGET_MACHINE_DEPENDENT_REORG
51793 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
51794
51795 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
51796 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE ix86_builtin_setjmp_frame_value
51797
51798 #undef TARGET_BUILD_BUILTIN_VA_LIST
51799 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
51800
51801 #undef TARGET_FOLD_BUILTIN
51802 #define TARGET_FOLD_BUILTIN ix86_fold_builtin
51803
51804 #undef TARGET_COMPARE_VERSION_PRIORITY
51805 #define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority
51806
51807 #undef TARGET_GENERATE_VERSION_DISPATCHER_BODY
51808 #define TARGET_GENERATE_VERSION_DISPATCHER_BODY \
51809   ix86_generate_version_dispatcher_body
51810
51811 #undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
51812 #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
51813   ix86_get_function_versions_dispatcher
51814
51815 #undef TARGET_ENUM_VA_LIST_P
51816 #define TARGET_ENUM_VA_LIST_P ix86_enum_va_list
51817
51818 #undef TARGET_FN_ABI_VA_LIST
51819 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
51820
51821 #undef TARGET_CANONICAL_VA_LIST_TYPE
51822 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
51823
51824 #undef TARGET_EXPAND_BUILTIN_VA_START
51825 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
51826
51827 #undef TARGET_MD_ASM_CLOBBERS
51828 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
51829
51830 #undef TARGET_PROMOTE_PROTOTYPES
51831 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
51832 #undef TARGET_SETUP_INCOMING_VARARGS
51833 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
51834 #undef TARGET_MUST_PASS_IN_STACK
51835 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
51836 #undef TARGET_FUNCTION_ARG_ADVANCE
51837 #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance
51838 #undef TARGET_FUNCTION_ARG
51839 #define TARGET_FUNCTION_ARG ix86_function_arg
51840 #undef TARGET_INIT_PIC_REG
51841 #define TARGET_INIT_PIC_REG ix86_init_pic_reg
51842 #undef TARGET_USE_PSEUDO_PIC_REG
51843 #define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg
51844 #undef TARGET_FUNCTION_ARG_BOUNDARY
51845 #define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary
51846 #undef TARGET_PASS_BY_REFERENCE
51847 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
51848 #undef TARGET_INTERNAL_ARG_POINTER
51849 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
51850 #undef TARGET_UPDATE_STACK_BOUNDARY
51851 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
51852 #undef TARGET_GET_DRAP_RTX
51853 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
51854 #undef TARGET_STRICT_ARGUMENT_NAMING
51855 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
51856 #undef TARGET_STATIC_CHAIN
51857 #define TARGET_STATIC_CHAIN ix86_static_chain
51858 #undef TARGET_TRAMPOLINE_INIT
51859 #define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
51860 #undef TARGET_RETURN_POPS_ARGS
51861 #define TARGET_RETURN_POPS_ARGS ix86_return_pops_args
51862
51863 #undef TARGET_LEGITIMATE_COMBINED_INSN
51864 #define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn
51865
51866 #undef TARGET_ASAN_SHADOW_OFFSET
51867 #define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset
51868
51869 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
51870 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
51871
51872 #undef TARGET_SCALAR_MODE_SUPPORTED_P
51873 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
51874
51875 #undef TARGET_VECTOR_MODE_SUPPORTED_P
51876 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
51877
51878 #undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
51879 #define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \
51880   ix86_libgcc_floating_mode_supported_p
51881
51882 #undef TARGET_C_MODE_FOR_SUFFIX
51883 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
51884
51885 #ifdef HAVE_AS_TLS
51886 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
51887 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
51888 #endif
51889
51890 #ifdef SUBTARGET_INSERT_ATTRIBUTES
51891 #undef TARGET_INSERT_ATTRIBUTES
51892 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
51893 #endif
51894
51895 #undef TARGET_MANGLE_TYPE
51896 #define TARGET_MANGLE_TYPE ix86_mangle_type
51897
51898 #if !TARGET_MACHO
51899 #undef TARGET_STACK_PROTECT_FAIL
51900 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
51901 #endif
51902
51903 #undef TARGET_FUNCTION_VALUE
51904 #define TARGET_FUNCTION_VALUE ix86_function_value
51905
51906 #undef TARGET_FUNCTION_VALUE_REGNO_P
51907 #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
51908
51909 #undef TARGET_PROMOTE_FUNCTION_MODE
51910 #define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
51911
51912 #undef TARGET_MEMBER_TYPE_FORCES_BLK
51913 #define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk
51914
51915 #undef TARGET_INSTANTIATE_DECLS
51916 #define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls
51917
51918 #undef TARGET_SECONDARY_RELOAD
51919 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
51920
51921 #undef TARGET_CLASS_MAX_NREGS
51922 #define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs
51923
51924 #undef TARGET_PREFERRED_RELOAD_CLASS
51925 #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
51926 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
51927 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
51928 #undef TARGET_CLASS_LIKELY_SPILLED_P
51929 #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
51930
51931 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
51932 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
51933   ix86_builtin_vectorization_cost
51934 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
51935 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
51936   ix86_vectorize_vec_perm_const_ok
51937 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
51938 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
51939   ix86_preferred_simd_mode
51940 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
51941 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
51942   ix86_autovectorize_vector_sizes
51943 #undef TARGET_VECTORIZE_INIT_COST
51944 #define TARGET_VECTORIZE_INIT_COST ix86_init_cost
51945 #undef TARGET_VECTORIZE_ADD_STMT_COST
51946 #define TARGET_VECTORIZE_ADD_STMT_COST ix86_add_stmt_cost
51947 #undef TARGET_VECTORIZE_FINISH_COST
51948 #define TARGET_VECTORIZE_FINISH_COST ix86_finish_cost
51949 #undef TARGET_VECTORIZE_DESTROY_COST_DATA
51950 #define TARGET_VECTORIZE_DESTROY_COST_DATA ix86_destroy_cost_data
51951
51952 #undef TARGET_SET_CURRENT_FUNCTION
51953 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
51954
51955 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
51956 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
51957
51958 #undef TARGET_OPTION_SAVE
51959 #define TARGET_OPTION_SAVE ix86_function_specific_save
51960
51961 #undef TARGET_OPTION_RESTORE
51962 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
51963
51964 #undef TARGET_OPTION_PRINT
51965 #define TARGET_OPTION_PRINT ix86_function_specific_print
51966
51967 #undef TARGET_OPTION_FUNCTION_VERSIONS
51968 #define TARGET_OPTION_FUNCTION_VERSIONS ix86_function_versions
51969
51970 #undef TARGET_CAN_INLINE_P
51971 #define TARGET_CAN_INLINE_P ix86_can_inline_p
51972
51973 #undef TARGET_EXPAND_TO_RTL_HOOK
51974 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
51975
51976 #undef TARGET_LEGITIMATE_ADDRESS_P
51977 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
51978
51979 #undef TARGET_LRA_P
51980 #define TARGET_LRA_P hook_bool_void_true
51981
51982 #undef TARGET_REGISTER_PRIORITY
51983 #define TARGET_REGISTER_PRIORITY ix86_register_priority
51984
51985 #undef TARGET_REGISTER_USAGE_LEVELING_P
51986 #define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true
51987
51988 #undef TARGET_LEGITIMATE_CONSTANT_P
51989 #define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p
51990
51991 #undef TARGET_FRAME_POINTER_REQUIRED
51992 #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
51993
51994 #undef TARGET_CAN_ELIMINATE
51995 #define TARGET_CAN_ELIMINATE ix86_can_eliminate
51996
51997 #undef TARGET_EXTRA_LIVE_ON_ENTRY
51998 #define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry
51999
52000 #undef TARGET_ASM_CODE_END
52001 #define TARGET_ASM_CODE_END ix86_code_end
52002
52003 #undef TARGET_CONDITIONAL_REGISTER_USAGE
52004 #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
52005
52006 #if TARGET_MACHO
52007 #undef TARGET_INIT_LIBFUNCS
52008 #define TARGET_INIT_LIBFUNCS darwin_rename_builtins
52009 #endif
52010
52011 #undef TARGET_LOOP_UNROLL_ADJUST
52012 #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust
52013
52014 #undef TARGET_SPILL_CLASS
52015 #define TARGET_SPILL_CLASS ix86_spill_class
52016
52017 #undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
52018 #define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
52019   ix86_simd_clone_compute_vecsize_and_simdlen
52020
52021 #undef TARGET_SIMD_CLONE_ADJUST
52022 #define TARGET_SIMD_CLONE_ADJUST \
52023   ix86_simd_clone_adjust
52024
52025 #undef TARGET_SIMD_CLONE_USABLE
52026 #define TARGET_SIMD_CLONE_USABLE \
52027   ix86_simd_clone_usable
52028
52029 #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
52030 #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
52031   ix86_float_exceptions_rounding_supported_p
52032
52033 #undef TARGET_MODE_EMIT
52034 #define TARGET_MODE_EMIT ix86_emit_mode_set
52035
52036 #undef TARGET_MODE_NEEDED
52037 #define TARGET_MODE_NEEDED ix86_mode_needed
52038
52039 #undef TARGET_MODE_AFTER
52040 #define TARGET_MODE_AFTER ix86_mode_after
52041
52042 #undef TARGET_MODE_ENTRY
52043 #define TARGET_MODE_ENTRY ix86_mode_entry
52044
52045 #undef TARGET_MODE_EXIT
52046 #define TARGET_MODE_EXIT ix86_mode_exit
52047
52048 #undef TARGET_MODE_PRIORITY
52049 #define TARGET_MODE_PRIORITY ix86_mode_priority
52050
52051 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
52052 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
52053
52054 #undef TARGET_LOAD_BOUNDS_FOR_ARG
52055 #define TARGET_LOAD_BOUNDS_FOR_ARG ix86_load_bounds
52056
52057 #undef TARGET_STORE_BOUNDS_FOR_ARG
52058 #define TARGET_STORE_BOUNDS_FOR_ARG ix86_store_bounds
52059
52060 #undef TARGET_LOAD_RETURNED_BOUNDS
52061 #define TARGET_LOAD_RETURNED_BOUNDS ix86_load_returned_bounds
52062
52063 #undef TARGET_STORE_RETURNED_BOUNDS
52064 #define TARGET_STORE_RETURNED_BOUNDS ix86_store_returned_bounds
52065
52066 #undef TARGET_CHKP_BOUND_MODE
52067 #define TARGET_CHKP_BOUND_MODE ix86_mpx_bound_mode
52068
52069 #undef TARGET_BUILTIN_CHKP_FUNCTION
52070 #define TARGET_BUILTIN_CHKP_FUNCTION ix86_builtin_mpx_function
52071
52072 #undef TARGET_CHKP_FUNCTION_VALUE_BOUNDS
52073 #define TARGET_CHKP_FUNCTION_VALUE_BOUNDS ix86_function_value_bounds
52074
52075 #undef TARGET_CHKP_MAKE_BOUNDS_CONSTANT
52076 #define TARGET_CHKP_MAKE_BOUNDS_CONSTANT ix86_make_bounds_constant
52077
52078 #undef TARGET_CHKP_INITIALIZE_BOUNDS
52079 #define TARGET_CHKP_INITIALIZE_BOUNDS ix86_initialize_bounds
52080
52081 #undef TARGET_SETUP_INCOMING_VARARG_BOUNDS
52082 #define TARGET_SETUP_INCOMING_VARARG_BOUNDS ix86_setup_incoming_vararg_bounds
52083
52084 #undef TARGET_OFFLOAD_OPTIONS
52085 #define TARGET_OFFLOAD_OPTIONS \
52086   ix86_offload_options
52087
52088 struct gcc_target targetm = TARGET_INITIALIZER;
52089 \f
52090 #include "gt-i386.h"