Branch data Line data Source code
1 : : /* Subroutines used for code generation on IA-32.
2 : : Copyright (C) 1988-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify
7 : : it under the terms of the GNU General Public License as published by
8 : : the Free Software Foundation; either version 3, or (at your option)
9 : : any later version.
10 : :
11 : : GCC is distributed in the hope that it will be useful,
12 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : GNU General Public License for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : #define INCLUDE_STRING
21 : : #define IN_TARGET_CODE 1
22 : :
23 : : #include "config.h"
24 : : #include "system.h"
25 : : #include "coretypes.h"
26 : : #include "backend.h"
27 : : #include "rtl.h"
28 : : #include "tree.h"
29 : : #include "memmodel.h"
30 : : #include "gimple.h"
31 : : #include "cfghooks.h"
32 : : #include "cfgloop.h"
33 : : #include "df.h"
34 : : #include "tm_p.h"
35 : : #include "stringpool.h"
36 : : #include "expmed.h"
37 : : #include "optabs.h"
38 : : #include "regs.h"
39 : : #include "emit-rtl.h"
40 : : #include "recog.h"
41 : : #include "cgraph.h"
42 : : #include "diagnostic.h"
43 : : #include "cfgbuild.h"
44 : : #include "alias.h"
45 : : #include "fold-const.h"
46 : : #include "attribs.h"
47 : : #include "calls.h"
48 : : #include "stor-layout.h"
49 : : #include "varasm.h"
50 : : #include "output.h"
51 : : #include "insn-attr.h"
52 : : #include "flags.h"
53 : : #include "except.h"
54 : : #include "explow.h"
55 : : #include "expr.h"
56 : : #include "cfgrtl.h"
57 : : #include "common/common-target.h"
58 : : #include "langhooks.h"
59 : : #include "reload.h"
60 : : #include "gimplify.h"
61 : : #include "dwarf2.h"
62 : : #include "tm-constrs.h"
63 : : #include "cselib.h"
64 : : #include "sched-int.h"
65 : : #include "opts.h"
66 : : #include "tree-pass.h"
67 : : #include "context.h"
68 : : #include "pass_manager.h"
69 : : #include "target-globals.h"
70 : : #include "gimple-iterator.h"
71 : : #include "gimple-fold.h"
72 : : #include "tree-vectorizer.h"
73 : : #include "shrink-wrap.h"
74 : : #include "builtins.h"
75 : : #include "rtl-iter.h"
76 : : #include "tree-iterator.h"
77 : : #include "dbgcnt.h"
78 : : #include "case-cfn-macros.h"
79 : : #include "dojump.h"
80 : : #include "fold-const-call.h"
81 : : #include "tree-vrp.h"
82 : : #include "tree-ssanames.h"
83 : : #include "selftest.h"
84 : : #include "selftest-rtl.h"
85 : : #include "print-rtl.h"
86 : : #include "intl.h"
87 : : #include "ifcvt.h"
88 : : #include "symbol-summary.h"
89 : : #include "sreal.h"
90 : : #include "ipa-cp.h"
91 : : #include "ipa-prop.h"
92 : : #include "ipa-fnsummary.h"
93 : : #include "wide-int-bitmask.h"
94 : : #include "tree-vector-builder.h"
95 : : #include "debug.h"
96 : : #include "dwarf2out.h"
97 : : #include "i386-options.h"
98 : : #include "i386-builtins.h"
99 : : #include "i386-expand.h"
100 : : #include "i386-features.h"
101 : : #include "function-abi.h"
102 : : #include "rtl-error.h"
103 : : #include "gimple-pretty-print.h"
104 : :
105 : : /* This file should be included last. */
106 : : #include "target-def.h"
107 : :
108 : : static void ix86_print_operand_address_as (FILE *, rtx, addr_space_t, bool);
109 : : static void ix86_emit_restore_reg_using_pop (rtx, bool = false);
110 : :
111 : :
112 : : #ifndef CHECK_STACK_LIMIT
113 : : #define CHECK_STACK_LIMIT (-1)
114 : : #endif
115 : :
116 : : /* Return index of given mode in mult and division cost tables. */
117 : : #define MODE_INDEX(mode) \
118 : : ((mode) == QImode ? 0 \
119 : : : (mode) == HImode ? 1 \
120 : : : (mode) == SImode ? 2 \
121 : : : (mode) == DImode ? 3 \
122 : : : 4)
123 : :
124 : :
125 : : /* Set by -mtune. */
126 : : const struct processor_costs *ix86_tune_cost = NULL;
127 : :
128 : : /* Set by -mtune or -Os. */
129 : : const struct processor_costs *ix86_cost = NULL;
130 : :
131 : : /* In case the average insn count for single function invocation is
132 : : lower than this constant, emit fast (but longer) prologue and
133 : : epilogue code. */
134 : : #define FAST_PROLOGUE_INSN_COUNT 20
135 : :
136 : : /* Names for 8 (low), 8 (high), and 16-bit registers, respectively. */
137 : : static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
138 : : static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
139 : : static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
140 : :
141 : : /* Array of the smallest class containing reg number REGNO, indexed by
142 : : REGNO. Used by REGNO_REG_CLASS in i386.h. */
143 : :
144 : : enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
145 : : {
146 : : /* ax, dx, cx, bx */
147 : : AREG, DREG, CREG, BREG,
148 : : /* si, di, bp, sp */
149 : : SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
150 : : /* FP registers */
151 : : FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
152 : : FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
153 : : /* arg pointer, flags, fpsr, frame */
154 : : NON_Q_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
155 : : /* SSE registers */
156 : : SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS,
157 : : SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
158 : : /* MMX registers */
159 : : MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
160 : : MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
161 : : /* REX registers */
162 : : GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
163 : : GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
164 : : /* SSE REX registers */
165 : : SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
166 : : SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
167 : : /* AVX-512 SSE registers */
168 : : ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
169 : : ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
170 : : ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
171 : : ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
172 : : /* Mask registers. */
173 : : ALL_MASK_REGS, MASK_REGS, MASK_REGS, MASK_REGS,
174 : : MASK_REGS, MASK_REGS, MASK_REGS, MASK_REGS,
175 : : /* REX2 registers */
176 : : GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
177 : : GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
178 : : GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
179 : : GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
180 : : };
181 : :
182 : : /* The "default" register map used in 32bit mode. */
183 : :
184 : : unsigned int const debugger_register_map[FIRST_PSEUDO_REGISTER] =
185 : : {
186 : : /* general regs */
187 : : 0, 2, 1, 3, 6, 7, 4, 5,
188 : : /* fp regs */
189 : : 12, 13, 14, 15, 16, 17, 18, 19,
190 : : /* arg, flags, fpsr, frame */
191 : : IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
192 : : IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
193 : : /* SSE */
194 : : 21, 22, 23, 24, 25, 26, 27, 28,
195 : : /* MMX */
196 : : 29, 30, 31, 32, 33, 34, 35, 36,
197 : : /* extended integer registers */
198 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
199 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
200 : : /* extended sse registers */
201 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
202 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
203 : : /* AVX-512 registers 16-23 */
204 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
205 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
206 : : /* AVX-512 registers 24-31 */
207 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
208 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
209 : : /* Mask registers */
210 : : 93, 94, 95, 96, 97, 98, 99, 100
211 : : };
212 : :
213 : : /* The "default" register map used in 64bit mode. */
214 : :
215 : : unsigned int const debugger64_register_map[FIRST_PSEUDO_REGISTER] =
216 : : {
217 : : /* general regs */
218 : : 0, 1, 2, 3, 4, 5, 6, 7,
219 : : /* fp regs */
220 : : 33, 34, 35, 36, 37, 38, 39, 40,
221 : : /* arg, flags, fpsr, frame */
222 : : IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
223 : : IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
224 : : /* SSE */
225 : : 17, 18, 19, 20, 21, 22, 23, 24,
226 : : /* MMX */
227 : : 41, 42, 43, 44, 45, 46, 47, 48,
228 : : /* extended integer registers */
229 : : 8, 9, 10, 11, 12, 13, 14, 15,
230 : : /* extended SSE registers */
231 : : 25, 26, 27, 28, 29, 30, 31, 32,
232 : : /* AVX-512 registers 16-23 */
233 : : 67, 68, 69, 70, 71, 72, 73, 74,
234 : : /* AVX-512 registers 24-31 */
235 : : 75, 76, 77, 78, 79, 80, 81, 82,
236 : : /* Mask registers */
237 : : 118, 119, 120, 121, 122, 123, 124, 125,
238 : : /* rex2 extend interger registers */
239 : : 130, 131, 132, 133, 134, 135, 136, 137,
240 : : 138, 139, 140, 141, 142, 143, 144, 145
241 : : };
242 : :
243 : : /* Define the register numbers to be used in Dwarf debugging information.
244 : : The SVR4 reference port C compiler uses the following register numbers
245 : : in its Dwarf output code:
246 : : 0 for %eax (gcc regno = 0)
247 : : 1 for %ecx (gcc regno = 2)
248 : : 2 for %edx (gcc regno = 1)
249 : : 3 for %ebx (gcc regno = 3)
250 : : 4 for %esp (gcc regno = 7)
251 : : 5 for %ebp (gcc regno = 6)
252 : : 6 for %esi (gcc regno = 4)
253 : : 7 for %edi (gcc regno = 5)
254 : : The following three DWARF register numbers are never generated by
255 : : the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
256 : : believed these numbers have these meanings.
257 : : 8 for %eip (no gcc equivalent)
258 : : 9 for %eflags (gcc regno = 17)
259 : : 10 for %trapno (no gcc equivalent)
260 : : It is not at all clear how we should number the FP stack registers
261 : : for the x86 architecture. If the version of SDB on x86/svr4 were
262 : : a bit less brain dead with respect to floating-point then we would
263 : : have a precedent to follow with respect to DWARF register numbers
264 : : for x86 FP registers, but the SDB on x86/svr4 was so completely
265 : : broken with respect to FP registers that it is hardly worth thinking
266 : : of it as something to strive for compatibility with.
267 : : The version of x86/svr4 SDB I had does (partially)
268 : : seem to believe that DWARF register number 11 is associated with
269 : : the x86 register %st(0), but that's about all. Higher DWARF
270 : : register numbers don't seem to be associated with anything in
271 : : particular, and even for DWARF regno 11, SDB only seemed to under-
272 : : stand that it should say that a variable lives in %st(0) (when
273 : : asked via an `=' command) if we said it was in DWARF regno 11,
274 : : but SDB still printed garbage when asked for the value of the
275 : : variable in question (via a `/' command).
276 : : (Also note that the labels SDB printed for various FP stack regs
277 : : when doing an `x' command were all wrong.)
278 : : Note that these problems generally don't affect the native SVR4
279 : : C compiler because it doesn't allow the use of -O with -g and
280 : : because when it is *not* optimizing, it allocates a memory
281 : : location for each floating-point variable, and the memory
282 : : location is what gets described in the DWARF AT_location
283 : : attribute for the variable in question.
284 : : Regardless of the severe mental illness of the x86/svr4 SDB, we
285 : : do something sensible here and we use the following DWARF
286 : : register numbers. Note that these are all stack-top-relative
287 : : numbers.
288 : : 11 for %st(0) (gcc regno = 8)
289 : : 12 for %st(1) (gcc regno = 9)
290 : : 13 for %st(2) (gcc regno = 10)
291 : : 14 for %st(3) (gcc regno = 11)
292 : : 15 for %st(4) (gcc regno = 12)
293 : : 16 for %st(5) (gcc regno = 13)
294 : : 17 for %st(6) (gcc regno = 14)
295 : : 18 for %st(7) (gcc regno = 15)
296 : : */
297 : : unsigned int const svr4_debugger_register_map[FIRST_PSEUDO_REGISTER] =
298 : : {
299 : : /* general regs */
300 : : 0, 2, 1, 3, 6, 7, 5, 4,
301 : : /* fp regs */
302 : : 11, 12, 13, 14, 15, 16, 17, 18,
303 : : /* arg, flags, fpsr, frame */
304 : : IGNORED_DWARF_REGNUM, 9,
305 : : IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
306 : : /* SSE registers */
307 : : 21, 22, 23, 24, 25, 26, 27, 28,
308 : : /* MMX registers */
309 : : 29, 30, 31, 32, 33, 34, 35, 36,
310 : : /* extended integer registers */
311 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
312 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
313 : : /* extended sse registers */
314 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
315 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
316 : : /* AVX-512 registers 16-23 */
317 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
318 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
319 : : /* AVX-512 registers 24-31 */
320 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
321 : : INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
322 : : /* Mask registers */
323 : : 93, 94, 95, 96, 97, 98, 99, 100
324 : : };
325 : :
326 : : /* Define parameter passing and return registers. */
327 : :
328 : : static int const x86_64_int_parameter_registers[6] =
329 : : {
330 : : DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
331 : : };
332 : :
333 : : static int const x86_64_ms_abi_int_parameter_registers[4] =
334 : : {
335 : : CX_REG, DX_REG, R8_REG, R9_REG
336 : : };
337 : :
338 : : static int const x86_64_int_return_registers[4] =
339 : : {
340 : : AX_REG, DX_REG, DI_REG, SI_REG
341 : : };
342 : :
343 : : /* Define the structure for the machine field in struct function. */
344 : :
345 : : struct GTY(()) stack_local_entry {
346 : : unsigned short mode;
347 : : unsigned short n;
348 : : rtx rtl;
349 : : struct stack_local_entry *next;
350 : : };
351 : :
352 : : /* Which cpu are we scheduling for. */
353 : : enum attr_cpu ix86_schedule;
354 : :
355 : : /* Which cpu are we optimizing for. */
356 : : enum processor_type ix86_tune;
357 : :
358 : : /* Which instruction set architecture to use. */
359 : : enum processor_type ix86_arch;
360 : :
361 : : /* True if processor has SSE prefetch instruction. */
362 : : unsigned char ix86_prefetch_sse;
363 : :
364 : : /* Preferred alignment for stack boundary in bits. */
365 : : unsigned int ix86_preferred_stack_boundary;
366 : :
367 : : /* Alignment for incoming stack boundary in bits specified at
368 : : command line. */
369 : : unsigned int ix86_user_incoming_stack_boundary;
370 : :
371 : : /* Default alignment for incoming stack boundary in bits. */
372 : : unsigned int ix86_default_incoming_stack_boundary;
373 : :
374 : : /* Alignment for incoming stack boundary in bits. */
375 : : unsigned int ix86_incoming_stack_boundary;
376 : :
377 : : /* True if there is no direct access to extern symbols. */
378 : : bool ix86_has_no_direct_extern_access;
379 : :
380 : : /* Calling abi specific va_list type nodes. */
381 : : tree sysv_va_list_type_node;
382 : : tree ms_va_list_type_node;
383 : :
384 : : /* Prefix built by ASM_GENERATE_INTERNAL_LABEL. */
385 : : char internal_label_prefix[16];
386 : : int internal_label_prefix_len;
387 : :
388 : : /* Fence to use after loop using movnt. */
389 : : tree x86_mfence;
390 : :
391 : : /* Register class used for passing given 64bit part of the argument.
392 : : These represent classes as documented by the PS ABI, with the exception
393 : : of SSESF, SSEDF classes, that are basically SSE class, just gcc will
394 : : use SF or DFmode move instead of DImode to avoid reformatting penalties.
395 : :
396 : : Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
397 : : whenever possible (upper half does contain padding). */
398 : : enum x86_64_reg_class
399 : : {
400 : : X86_64_NO_CLASS,
401 : : X86_64_INTEGER_CLASS,
402 : : X86_64_INTEGERSI_CLASS,
403 : : X86_64_SSE_CLASS,
404 : : X86_64_SSEHF_CLASS,
405 : : X86_64_SSESF_CLASS,
406 : : X86_64_SSEDF_CLASS,
407 : : X86_64_SSEUP_CLASS,
408 : : X86_64_X87_CLASS,
409 : : X86_64_X87UP_CLASS,
410 : : X86_64_COMPLEX_X87_CLASS,
411 : : X86_64_MEMORY_CLASS
412 : : };
413 : :
414 : : #define MAX_CLASSES 8
415 : :
416 : : /* Table of constants used by fldpi, fldln2, etc.... */
417 : : static REAL_VALUE_TYPE ext_80387_constants_table [5];
418 : : static bool ext_80387_constants_init;
419 : :
420 : :
421 : : static rtx ix86_function_value (const_tree, const_tree, bool);
422 : : static bool ix86_function_value_regno_p (const unsigned int);
423 : : static unsigned int ix86_function_arg_boundary (machine_mode,
424 : : const_tree);
425 : : static rtx ix86_static_chain (const_tree, bool);
426 : : static int ix86_function_regparm (const_tree, const_tree);
427 : : static void ix86_compute_frame_layout (void);
428 : : static tree ix86_canonical_va_list_type (tree);
429 : : static unsigned int split_stack_prologue_scratch_regno (void);
430 : : static bool i386_asm_output_addr_const_extra (FILE *, rtx);
431 : :
432 : : static bool ix86_can_inline_p (tree, tree);
433 : : static unsigned int ix86_minimum_incoming_stack_boundary (bool);
434 : :
435 : : typedef enum ix86_flags_cc
436 : : {
437 : : X86_CCO = 0, X86_CCNO, X86_CCB, X86_CCNB,
438 : : X86_CCE, X86_CCNE, X86_CCBE, X86_CCNBE,
439 : : X86_CCS, X86_CCNS, X86_CCP, X86_CCNP,
440 : : X86_CCL, X86_CCNL, X86_CCLE, X86_CCNLE
441 : : } ix86_cc;
442 : :
443 : : static const char *ix86_ccmp_dfv_mapping[] =
444 : : {
445 : : "{dfv=of}", "{dfv=}", "{dfv=cf}", "{dfv=}",
446 : : "{dfv=zf}", "{dfv=}", "{dfv=cf, zf}", "{dfv=}",
447 : : "{dfv=sf}", "{dfv=}", "{dfv=cf}", "{dfv=}",
448 : : "{dfv=sf}", "{dfv=sf, of}", "{dfv=sf, of, zf}", "{dfv=sf, of}"
449 : : };
450 : :
451 : :
452 : : /* Whether -mtune= or -march= were specified */
453 : : int ix86_tune_defaulted;
454 : : int ix86_arch_specified;
455 : :
456 : : /* Return true if a red-zone is in use. We can't use red-zone when
457 : : there are local indirect jumps, like "indirect_jump" or "tablejump",
458 : : which jumps to another place in the function, since "call" in the
459 : : indirect thunk pushes the return address onto stack, destroying
460 : : red-zone.
461 : :
462 : : NB: Don't use red-zone for functions with no_caller_saved_registers
463 : : and 32 GPRs since 128-byte red-zone is too small for 31 GPRs.
464 : :
465 : : TODO: If we can reserve the first 2 WORDs, for PUSH and, another
466 : : for CALL, in red-zone, we can allow local indirect jumps with
467 : : indirect thunk. */
468 : :
469 : : bool
470 : 9551991 : ix86_using_red_zone (void)
471 : : {
472 : 9551991 : return (TARGET_RED_ZONE
473 : 8626987 : && !TARGET_64BIT_MS_ABI
474 : 8324605 : && (!TARGET_APX_EGPR
475 : 2714 : || (cfun->machine->call_saved_registers
476 : 2714 : != TYPE_NO_CALLER_SAVED_REGISTERS))
477 : 17876571 : && (!cfun->machine->has_local_indirect_jump
478 : 53517 : || cfun->machine->indirect_branch_type == indirect_branch_keep));
479 : : }
480 : :
481 : : /* Return true, if profiling code should be emitted before
482 : : prologue. Otherwise it returns false.
483 : : Note: For x86 with "hotfix" it is sorried. */
484 : : static bool
485 : 4329824 : ix86_profile_before_prologue (void)
486 : : {
487 : 4329824 : return flag_fentry != 0;
488 : : }
489 : :
490 : : /* Update register usage after having seen the compiler flags. */
491 : :
492 : : static void
493 : 862969 : ix86_conditional_register_usage (void)
494 : : {
495 : 862969 : int i, c_mask;
496 : :
497 : : /* If there are no caller-saved registers, preserve all registers.
498 : : except fixed_regs and registers used for function return value
499 : : since aggregate_value_p checks call_used_regs[regno] on return
500 : : value. */
501 : 862969 : if (cfun
502 : 61158 : && (cfun->machine->call_saved_registers
503 : 61158 : == TYPE_NO_CALLER_SAVED_REGISTERS))
504 : 378603 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
505 : 374532 : if (!fixed_regs[i] && !ix86_function_value_regno_p (i))
506 : 337883 : call_used_regs[i] = 0;
507 : :
508 : : /* For 32-bit targets, disable the REX registers. */
509 : 862969 : if (! TARGET_64BIT)
510 : : {
511 : 137034 : for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
512 : 121808 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
513 : 137034 : for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
514 : 121808 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
515 : 258842 : for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
516 : 243616 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
517 : : }
518 : :
519 : : /* See the definition of CALL_USED_REGISTERS in i386.h. */
520 : 862969 : c_mask = CALL_USED_REGISTERS_MASK (TARGET_64BIT_MS_ABI);
521 : :
522 : 862969 : CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
523 : :
524 : 80256117 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
525 : : {
526 : : /* Set/reset conditionally defined registers from
527 : : CALL_USED_REGISTERS initializer. */
528 : 79393148 : if (call_used_regs[i] > 1)
529 : 13750455 : call_used_regs[i] = !!(call_used_regs[i] & c_mask);
530 : :
531 : : /* Calculate registers of CLOBBERED_REGS register set
532 : : as call used registers from GENERAL_REGS register set. */
533 : 79393148 : if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
534 : 79393148 : && call_used_regs[i])
535 : 24070573 : SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
536 : : }
537 : :
538 : : /* If MMX is disabled, disable the registers. */
539 : 862969 : if (! TARGET_MMX)
540 : 387598 : accessible_reg_set &= ~reg_class_contents[MMX_REGS];
541 : :
542 : : /* If SSE is disabled, disable the registers. */
543 : 862969 : if (! TARGET_SSE)
544 : 382298 : accessible_reg_set &= ~reg_class_contents[ALL_SSE_REGS];
545 : :
546 : : /* If the FPU is disabled, disable the registers. */
547 : 862969 : if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
548 : 382754 : accessible_reg_set &= ~reg_class_contents[FLOAT_REGS];
549 : :
550 : : /* If AVX512F is disabled, disable the registers. */
551 : 862969 : if (! TARGET_AVX512F)
552 : : {
553 : 9789909 : for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
554 : 9214032 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
555 : :
556 : 1151754 : accessible_reg_set &= ~reg_class_contents[ALL_MASK_REGS];
557 : : }
558 : :
559 : : /* If APX is disabled, disable the registers. */
560 : 862969 : if (! (TARGET_APX_EGPR && TARGET_64BIT))
561 : : {
562 : 14663622 : for (i = FIRST_REX2_INT_REG; i <= LAST_REX2_INT_REG; i++)
563 : 13801056 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
564 : : }
565 : 862969 : }
566 : :
567 : : /* Canonicalize a comparison from one we don't have to one we do have. */
568 : :
569 : : static void
570 : 22104449 : ix86_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
571 : : bool op0_preserve_value)
572 : : {
573 : : /* The order of operands in x87 ficom compare is forced by combine in
574 : : simplify_comparison () function. Float operator is treated as RTX_OBJ
575 : : with a precedence over other operators and is always put in the first
576 : : place. Swap condition and operands to match ficom instruction. */
577 : 22104449 : if (!op0_preserve_value
578 : 21320316 : && GET_CODE (*op0) == FLOAT && MEM_P (XEXP (*op0, 0)) && REG_P (*op1))
579 : : {
580 : 6 : enum rtx_code scode = swap_condition ((enum rtx_code) *code);
581 : :
582 : : /* We are called only for compares that are split to SAHF instruction.
583 : : Ensure that we have setcc/jcc insn for the swapped condition. */
584 : 6 : if (ix86_fp_compare_code_to_integer (scode) != UNKNOWN)
585 : : {
586 : 6 : std::swap (*op0, *op1);
587 : 6 : *code = (int) scode;
588 : 6 : return;
589 : : }
590 : : }
591 : :
592 : : /* Swap operands of GTU comparison to canonicalize
593 : : addcarry/subborrow comparison. */
594 : 21320310 : if (!op0_preserve_value
595 : 21320310 : && *code == GTU
596 : 763933 : && GET_CODE (*op0) == PLUS
597 : 315963 : && ix86_carry_flag_operator (XEXP (*op0, 0), VOIDmode)
598 : 44993 : && GET_CODE (XEXP (*op0, 1)) == ZERO_EXTEND
599 : 40792 : && GET_CODE (*op1) == ZERO_EXTEND)
600 : : {
601 : 37796 : std::swap (*op0, *op1);
602 : 37796 : *code = (int) swap_condition ((enum rtx_code) *code);
603 : 37796 : return;
604 : : }
605 : : }
606 : :
607 : : /* Hook to determine if one function can safely inline another. */
608 : :
609 : : static bool
610 : 9371953 : ix86_can_inline_p (tree caller, tree callee)
611 : : {
612 : 9371953 : tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
613 : 9371953 : tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
614 : :
615 : : /* Changes of those flags can be tolerated for always inlines. Lets hope
616 : : user knows what he is doing. */
617 : 9371953 : unsigned HOST_WIDE_INT always_inline_safe_mask
618 : : = (MASK_USE_8BIT_IDIV | MASK_ACCUMULATE_OUTGOING_ARGS
619 : : | MASK_NO_ALIGN_STRINGOPS | MASK_AVX256_SPLIT_UNALIGNED_LOAD
620 : : | MASK_AVX256_SPLIT_UNALIGNED_STORE | MASK_CLD
621 : : | MASK_NO_FANCY_MATH_387 | MASK_IEEE_FP | MASK_INLINE_ALL_STRINGOPS
622 : : | MASK_INLINE_STRINGOPS_DYNAMICALLY | MASK_RECIP | MASK_STACK_PROBE
623 : : | MASK_STV | MASK_TLS_DIRECT_SEG_REFS | MASK_VZEROUPPER
624 : : | MASK_NO_PUSH_ARGS | MASK_OMIT_LEAF_FRAME_POINTER);
625 : :
626 : :
627 : 9371953 : if (!callee_tree)
628 : 8721222 : callee_tree = target_option_default_node;
629 : 9371953 : if (!caller_tree)
630 : 8729643 : caller_tree = target_option_default_node;
631 : 9371953 : if (callee_tree == caller_tree)
632 : : return true;
633 : :
634 : 17724 : struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
635 : 17724 : struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
636 : 17724 : bool ret = false;
637 : 17724 : bool always_inline
638 : 17724 : = (DECL_DISREGARD_INLINE_LIMITS (callee)
639 : 34852 : && lookup_attribute ("always_inline",
640 : 17128 : DECL_ATTRIBUTES (callee)));
641 : :
642 : : /* If callee only uses GPRs, ignore MASK_80387. */
643 : 17724 : if (TARGET_GENERAL_REGS_ONLY_P (callee_opts->x_ix86_target_flags))
644 : 1021 : always_inline_safe_mask |= MASK_80387;
645 : :
646 : 17724 : cgraph_node *callee_node = cgraph_node::get (callee);
647 : : /* Callee's isa options should be a subset of the caller's, i.e. a SSE4
648 : : function can inline a SSE2 function but a SSE2 function can't inline
649 : : a SSE4 function. */
650 : 17724 : if (((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags)
651 : : != callee_opts->x_ix86_isa_flags)
652 : 17509 : || ((caller_opts->x_ix86_isa_flags2 & callee_opts->x_ix86_isa_flags2)
653 : : != callee_opts->x_ix86_isa_flags2))
654 : : ret = false;
655 : :
656 : : /* See if we have the same non-isa options. */
657 : 17488 : else if ((!always_inline
658 : 376 : && caller_opts->x_target_flags != callee_opts->x_target_flags)
659 : 17444 : || (caller_opts->x_target_flags & ~always_inline_safe_mask)
660 : 17444 : != (callee_opts->x_target_flags & ~always_inline_safe_mask))
661 : : ret = false;
662 : :
663 : 17444 : else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath
664 : : /* If the calle doesn't use FP expressions differences in
665 : : ix86_fpmath can be ignored. We are called from FEs
666 : : for multi-versioning call optimization, so beware of
667 : : ipa_fn_summaries not available. */
668 : 1238 : && (! ipa_fn_summaries
669 : 1238 : || ipa_fn_summaries->get (callee_node) == NULL
670 : 1238 : || ipa_fn_summaries->get (callee_node)->fp_expressions))
671 : : ret = false;
672 : :
673 : : /* At this point we cannot identify whether arch or tune setting
674 : : comes from target attribute or not. So the most conservative way
675 : : is to allow the callee that uses default arch and tune string to
676 : : be inlined. */
677 : 17170 : else if (!strcmp (callee_opts->x_ix86_arch_string, "x86-64")
678 : 9413 : && !strcmp (callee_opts->x_ix86_tune_string, "generic"))
679 : : ret = true;
680 : :
681 : : /* See if arch, tune, etc. are the same. As previous ISA flags already
682 : : checks if callee's ISA is subset of caller's, do not block
683 : : always_inline attribute for callee even it has different arch. */
684 : 7765 : else if (!always_inline && caller_opts->arch != callee_opts->arch)
685 : : ret = false;
686 : :
687 : 3 : else if (!always_inline && caller_opts->tune != callee_opts->tune)
688 : : ret = false;
689 : :
690 : 7765 : else if (!always_inline
691 : 3 : && caller_opts->branch_cost != callee_opts->branch_cost)
692 : : ret = false;
693 : :
694 : : else
695 : 9371399 : ret = true;
696 : :
697 : : return ret;
698 : : }
699 : :
700 : : /* Return true if this goes in large data/bss. */
701 : :
702 : : static bool
703 : 77928467 : ix86_in_large_data_p (tree exp)
704 : : {
705 : 77928467 : if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC
706 : 77928229 : && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC)
707 : : return false;
708 : :
709 : 1040 : if (exp == NULL_TREE)
710 : : return false;
711 : :
712 : : /* Functions are never large data. */
713 : 1040 : if (TREE_CODE (exp) == FUNCTION_DECL)
714 : : return false;
715 : :
716 : : /* Automatic variables are never large data. */
717 : 256 : if (VAR_P (exp) && !is_global_var (exp))
718 : : return false;
719 : :
720 : 256 : if (VAR_P (exp) && DECL_SECTION_NAME (exp))
721 : : {
722 : 51 : const char *section = DECL_SECTION_NAME (exp);
723 : 51 : if (strcmp (section, ".ldata") == 0
724 : 51 : || strcmp (section, ".lbss") == 0)
725 : : return true;
726 : : return false;
727 : : }
728 : : else
729 : : {
730 : 205 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
731 : :
732 : : /* If this is an incomplete type with size 0, then we can't put it
733 : : in data because it might be too big when completed. Also,
734 : : int_size_in_bytes returns -1 if size can vary or is larger than
735 : : an integer in which case also it is safer to assume that it goes in
736 : : large data. */
737 : 205 : if (size <= 0 || size > ix86_section_threshold)
738 : : return true;
739 : : }
740 : :
741 : : return false;
742 : : }
743 : :
744 : : /* i386-specific section flag to mark large sections. */
745 : : #define SECTION_LARGE SECTION_MACH_DEP
746 : :
747 : : /* Switch to the appropriate section for output of DECL.
748 : : DECL is either a `VAR_DECL' node or a constant of some sort.
749 : : RELOC indicates whether forming the initial value of DECL requires
750 : : link-time relocations. */
751 : :
752 : : ATTRIBUTE_UNUSED static section *
753 : 1630921 : x86_64_elf_select_section (tree decl, int reloc,
754 : : unsigned HOST_WIDE_INT align)
755 : : {
756 : 1630921 : if (ix86_in_large_data_p (decl))
757 : : {
758 : 6 : const char *sname = NULL;
759 : 6 : unsigned int flags = SECTION_WRITE | SECTION_LARGE;
760 : 6 : switch (categorize_decl_for_section (decl, reloc))
761 : : {
762 : 1 : case SECCAT_DATA:
763 : 1 : sname = ".ldata";
764 : 1 : break;
765 : 0 : case SECCAT_DATA_REL:
766 : 0 : sname = ".ldata.rel";
767 : 0 : break;
768 : 0 : case SECCAT_DATA_REL_LOCAL:
769 : 0 : sname = ".ldata.rel.local";
770 : 0 : break;
771 : 0 : case SECCAT_DATA_REL_RO:
772 : 0 : sname = ".ldata.rel.ro";
773 : 0 : break;
774 : 0 : case SECCAT_DATA_REL_RO_LOCAL:
775 : 0 : sname = ".ldata.rel.ro.local";
776 : 0 : break;
777 : 0 : case SECCAT_BSS:
778 : 0 : sname = ".lbss";
779 : 0 : flags |= SECTION_BSS;
780 : 0 : break;
781 : : case SECCAT_RODATA:
782 : : case SECCAT_RODATA_MERGE_STR:
783 : : case SECCAT_RODATA_MERGE_STR_INIT:
784 : : case SECCAT_RODATA_MERGE_CONST:
785 : : sname = ".lrodata";
786 : : flags &= ~SECTION_WRITE;
787 : : break;
788 : 0 : case SECCAT_SRODATA:
789 : 0 : case SECCAT_SDATA:
790 : 0 : case SECCAT_SBSS:
791 : 0 : gcc_unreachable ();
792 : : case SECCAT_TEXT:
793 : : case SECCAT_TDATA:
794 : : case SECCAT_TBSS:
795 : : /* We don't split these for medium model. Place them into
796 : : default sections and hope for best. */
797 : : break;
798 : : }
799 : 1 : if (sname)
800 : : {
801 : : /* We might get called with string constants, but get_named_section
802 : : doesn't like them as they are not DECLs. Also, we need to set
803 : : flags in that case. */
804 : 6 : if (!DECL_P (decl))
805 : 3 : return get_section (sname, flags, NULL);
806 : 3 : return get_named_section (decl, sname, reloc);
807 : : }
808 : : }
809 : 1630915 : return default_elf_select_section (decl, reloc, align);
810 : : }
811 : :
812 : : /* Select a set of attributes for section NAME based on the properties
813 : : of DECL and whether or not RELOC indicates that DECL's initializer
814 : : might contain runtime relocations. */
815 : :
816 : : static unsigned int ATTRIBUTE_UNUSED
817 : 64815779 : x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
818 : : {
819 : 64815779 : unsigned int flags = default_section_type_flags (decl, name, reloc);
820 : :
821 : 64815779 : if (ix86_in_large_data_p (decl))
822 : 7 : flags |= SECTION_LARGE;
823 : :
824 : 64815779 : if (decl == NULL_TREE
825 : 370 : && (strcmp (name, ".ldata.rel.ro") == 0
826 : 370 : || strcmp (name, ".ldata.rel.ro.local") == 0))
827 : 0 : flags |= SECTION_RELRO;
828 : :
829 : 64815779 : if (strcmp (name, ".lbss") == 0
830 : 64815775 : || startswith (name, ".lbss.")
831 : 129631551 : || startswith (name, ".gnu.linkonce.lb."))
832 : 7 : flags |= SECTION_BSS;
833 : :
834 : 64815779 : return flags;
835 : : }
836 : :
837 : : /* Build up a unique section name, expressed as a
838 : : STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
839 : : RELOC indicates whether the initial value of EXP requires
840 : : link-time relocations. */
841 : :
842 : : static void ATTRIBUTE_UNUSED
843 : 1790278 : x86_64_elf_unique_section (tree decl, int reloc)
844 : : {
845 : 1790278 : if (ix86_in_large_data_p (decl))
846 : : {
847 : 3 : const char *prefix = NULL;
848 : : /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
849 : 3 : bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP;
850 : :
851 : 3 : switch (categorize_decl_for_section (decl, reloc))
852 : : {
853 : 0 : case SECCAT_DATA:
854 : 0 : case SECCAT_DATA_REL:
855 : 0 : case SECCAT_DATA_REL_LOCAL:
856 : 0 : case SECCAT_DATA_REL_RO:
857 : 0 : case SECCAT_DATA_REL_RO_LOCAL:
858 : 0 : prefix = one_only ? ".ld" : ".ldata";
859 : 0 : break;
860 : 3 : case SECCAT_BSS:
861 : 3 : prefix = one_only ? ".lb" : ".lbss";
862 : 3 : break;
863 : : case SECCAT_RODATA:
864 : : case SECCAT_RODATA_MERGE_STR:
865 : : case SECCAT_RODATA_MERGE_STR_INIT:
866 : : case SECCAT_RODATA_MERGE_CONST:
867 : : prefix = one_only ? ".lr" : ".lrodata";
868 : : break;
869 : 0 : case SECCAT_SRODATA:
870 : 0 : case SECCAT_SDATA:
871 : 0 : case SECCAT_SBSS:
872 : 0 : gcc_unreachable ();
873 : : case SECCAT_TEXT:
874 : : case SECCAT_TDATA:
875 : : case SECCAT_TBSS:
876 : : /* We don't split these for medium model. Place them into
877 : : default sections and hope for best. */
878 : : break;
879 : : }
880 : 3 : if (prefix)
881 : : {
882 : 3 : const char *name, *linkonce;
883 : 3 : char *string;
884 : :
885 : 3 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
886 : 3 : name = targetm.strip_name_encoding (name);
887 : :
888 : : /* If we're using one_only, then there needs to be a .gnu.linkonce
889 : : prefix to the section name. */
890 : 3 : linkonce = one_only ? ".gnu.linkonce" : "";
891 : :
892 : 3 : string = ACONCAT ((linkonce, prefix, ".", name, NULL));
893 : :
894 : 3 : set_decl_section_name (decl, string);
895 : 3 : return;
896 : : }
897 : : }
898 : 1790275 : default_unique_section (decl, reloc);
899 : : }
900 : :
901 : : #ifdef COMMON_ASM_OP
902 : :
903 : : #ifndef LARGECOMM_SECTION_ASM_OP
904 : : #define LARGECOMM_SECTION_ASM_OP "\t.largecomm\t"
905 : : #endif
906 : :
907 : : /* This says how to output assembler code to declare an
908 : : uninitialized external linkage data object.
909 : :
910 : : For medium model x86-64 we need to use LARGECOMM_SECTION_ASM_OP opcode for
911 : : large objects. */
912 : : void
913 : 166349 : x86_elf_aligned_decl_common (FILE *file, tree decl,
914 : : const char *name, unsigned HOST_WIDE_INT size,
915 : : unsigned align)
916 : : {
917 : 166349 : if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC
918 : 166343 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
919 : 6 : && size > (unsigned int)ix86_section_threshold)
920 : : {
921 : 1 : switch_to_section (get_named_section (decl, ".lbss", 0));
922 : 1 : fputs (LARGECOMM_SECTION_ASM_OP, file);
923 : : }
924 : : else
925 : 166348 : fputs (COMMON_ASM_OP, file);
926 : 166349 : assemble_name (file, name);
927 : 166349 : fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
928 : : size, align / BITS_PER_UNIT);
929 : 166349 : }
930 : : #endif
931 : :
932 : : /* Utility function for targets to use in implementing
933 : : ASM_OUTPUT_ALIGNED_BSS. */
934 : :
935 : : void
936 : 763067 : x86_output_aligned_bss (FILE *file, tree decl, const char *name,
937 : : unsigned HOST_WIDE_INT size, unsigned align)
938 : : {
939 : 763067 : if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC
940 : 763057 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
941 : 37 : && size > (unsigned int)ix86_section_threshold)
942 : 3 : switch_to_section (get_named_section (decl, ".lbss", 0));
943 : : else
944 : 763064 : switch_to_section (bss_section);
945 : 912853 : ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
946 : : #ifdef ASM_DECLARE_OBJECT_NAME
947 : 763067 : last_assemble_variable_decl = decl;
948 : 763067 : ASM_DECLARE_OBJECT_NAME (file, name, decl);
949 : : #else
950 : : /* Standard thing is just output label for the object. */
951 : : ASM_OUTPUT_LABEL (file, name);
952 : : #endif /* ASM_DECLARE_OBJECT_NAME */
953 : 763067 : ASM_OUTPUT_SKIP (file, size ? size : 1);
954 : 763067 : }
955 : :
956 : : /* Decide whether we must probe the stack before any space allocation
957 : : on this target. It's essentially TARGET_STACK_PROBE except when
958 : : -fstack-check causes the stack to be already probed differently. */
959 : :
960 : : bool
961 : 848847 : ix86_target_stack_probe (void)
962 : : {
963 : : /* Do not probe the stack twice if static stack checking is enabled. */
964 : 848847 : if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
965 : : return false;
966 : :
967 : 848847 : return TARGET_STACK_PROBE;
968 : : }
969 : :
970 : : /* Decide whether we can make a sibling call to a function. DECL is the
971 : : declaration of the function being targeted by the call and EXP is the
972 : : CALL_EXPR representing the call. */
973 : :
974 : : static bool
975 : 131016 : ix86_function_ok_for_sibcall (tree decl, tree exp)
976 : : {
977 : 131016 : tree type, decl_or_type;
978 : 131016 : rtx a, b;
979 : 131016 : bool bind_global = decl && !targetm.binds_local_p (decl);
980 : :
981 : 131016 : if (ix86_function_naked (current_function_decl))
982 : : return false;
983 : :
984 : : /* Sibling call isn't OK if there are no caller-saved registers
985 : : since all registers must be preserved before return. */
986 : 131014 : if (cfun->machine->call_saved_registers
987 : 131014 : == TYPE_NO_CALLER_SAVED_REGISTERS)
988 : : return false;
989 : :
990 : : /* If we are generating position-independent code, we cannot sibcall
991 : : optimize direct calls to global functions, as the PLT requires
992 : : %ebx be live. (Darwin does not have a PLT.) */
993 : 130990 : if (!TARGET_MACHO
994 : 130990 : && !TARGET_64BIT
995 : 10920 : && flag_pic
996 : 8089 : && flag_plt
997 : 8089 : && bind_global)
998 : : return false;
999 : :
1000 : : /* If we need to align the outgoing stack, then sibcalling would
1001 : : unalign the stack, which may break the called function. */
1002 : 126511 : if (ix86_minimum_incoming_stack_boundary (true)
1003 : 126511 : < PREFERRED_STACK_BOUNDARY)
1004 : : return false;
1005 : :
1006 : 125930 : if (decl)
1007 : : {
1008 : 115951 : decl_or_type = decl;
1009 : 115951 : type = TREE_TYPE (decl);
1010 : : }
1011 : : else
1012 : : {
1013 : : /* We're looking at the CALL_EXPR, we need the type of the function. */
1014 : 9979 : type = CALL_EXPR_FN (exp); /* pointer expression */
1015 : 9979 : type = TREE_TYPE (type); /* pointer type */
1016 : 9979 : type = TREE_TYPE (type); /* function type */
1017 : 9979 : decl_or_type = type;
1018 : : }
1019 : :
1020 : : /* Sibling call isn't OK if callee has no callee-saved registers
1021 : : and the calling function has callee-saved registers. */
1022 : 125930 : if (cfun->machine->call_saved_registers != TYPE_NO_CALLEE_SAVED_REGISTERS
1023 : 125925 : && (cfun->machine->call_saved_registers
1024 : : != TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP)
1025 : 251855 : && lookup_attribute ("no_callee_saved_registers",
1026 : 125925 : TYPE_ATTRIBUTES (type)))
1027 : : return false;
1028 : :
1029 : : /* If outgoing reg parm stack space changes, we cannot do sibcall. */
1030 : 125922 : if ((OUTGOING_REG_PARM_STACK_SPACE (type)
1031 : 125922 : != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
1032 : 251097 : || (REG_PARM_STACK_SPACE (decl_or_type)
1033 : 125175 : != REG_PARM_STACK_SPACE (current_function_decl)))
1034 : : {
1035 : 747 : maybe_complain_about_tail_call (exp,
1036 : : "inconsistent size of stack space"
1037 : : " allocated for arguments which are"
1038 : : " passed in registers");
1039 : 747 : return false;
1040 : : }
1041 : :
1042 : : /* Check that the return value locations are the same. Like
1043 : : if we are returning floats on the 80387 register stack, we cannot
1044 : : make a sibcall from a function that doesn't return a float to a
1045 : : function that does or, conversely, from a function that does return
1046 : : a float to a function that doesn't; the necessary stack adjustment
1047 : : would not be executed. This is also the place we notice
1048 : : differences in the return value ABI. Note that it is ok for one
1049 : : of the functions to have void return type as long as the return
1050 : : value of the other is passed in a register. */
1051 : 125175 : a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
1052 : 125175 : b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
1053 : 125175 : cfun->decl, false);
1054 : 125175 : if (STACK_REG_P (a) || STACK_REG_P (b))
1055 : : {
1056 : 693 : if (!rtx_equal_p (a, b))
1057 : : return false;
1058 : : }
1059 : 124482 : else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
1060 : : ;
1061 : 23840 : else if (!rtx_equal_p (a, b))
1062 : : return false;
1063 : :
1064 : 124785 : if (TARGET_64BIT)
1065 : : {
1066 : : /* The SYSV ABI has more call-clobbered registers;
1067 : : disallow sibcalls from MS to SYSV. */
1068 : 118344 : if (cfun->machine->call_abi == MS_ABI
1069 : 118344 : && ix86_function_type_abi (type) == SYSV_ABI)
1070 : : return false;
1071 : : }
1072 : : else
1073 : : {
1074 : : /* If this call is indirect, we'll need to be able to use a
1075 : : call-clobbered register for the address of the target function.
1076 : : Make sure that all such registers are not used for passing
1077 : : parameters. Note that DLLIMPORT functions and call to global
1078 : : function via GOT slot are indirect. */
1079 : 6441 : if (!decl
1080 : 4647 : || (bind_global && flag_pic && !flag_plt)
1081 : : || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl))
1082 : 4647 : || flag_force_indirect_call)
1083 : : {
1084 : : /* Check if regparm >= 3 since arg_reg_available is set to
1085 : : false if regparm == 0. If regparm is 1 or 2, there is
1086 : : always a call-clobbered register available.
1087 : :
1088 : : ??? The symbol indirect call doesn't need a call-clobbered
1089 : : register. But we don't know if this is a symbol indirect
1090 : : call or not here. */
1091 : 1794 : if (ix86_function_regparm (type, decl) >= 3
1092 : 1794 : && !cfun->machine->arg_reg_available)
1093 : : return false;
1094 : : }
1095 : : }
1096 : :
1097 : 124785 : if (decl && ix86_use_pseudo_pic_reg ())
1098 : : {
1099 : : /* When PIC register is used, it must be restored after ifunc
1100 : : function returns. */
1101 : 2017 : cgraph_node *node = cgraph_node::get (decl);
1102 : 2017 : if (node && node->ifunc_resolver)
1103 : : return false;
1104 : : }
1105 : :
1106 : : /* Disable sibcall if callee has indirect_return attribute and
1107 : : caller doesn't since callee will return to the caller's caller
1108 : : via an indirect jump. */
1109 : 124785 : if (((flag_cf_protection & (CF_RETURN | CF_BRANCH))
1110 : : == (CF_RETURN | CF_BRANCH))
1111 : 50005 : && lookup_attribute ("indirect_return", TYPE_ATTRIBUTES (type))
1112 : 124789 : && !lookup_attribute ("indirect_return",
1113 : 4 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))))
1114 : : return false;
1115 : :
1116 : : /* Otherwise okay. That also includes certain types of indirect calls. */
1117 : : return true;
1118 : : }
1119 : :
1120 : : /* This function determines from TYPE the calling-convention. */
1121 : :
1122 : : unsigned int
1123 : 6038246 : ix86_get_callcvt (const_tree type)
1124 : : {
1125 : 6038246 : unsigned int ret = 0;
1126 : 6038246 : bool is_stdarg;
1127 : 6038246 : tree attrs;
1128 : :
1129 : 6038246 : if (TARGET_64BIT)
1130 : : return IX86_CALLCVT_CDECL;
1131 : :
1132 : 3231080 : attrs = TYPE_ATTRIBUTES (type);
1133 : 3231080 : if (attrs != NULL_TREE)
1134 : : {
1135 : 61823 : if (lookup_attribute ("cdecl", attrs))
1136 : : ret |= IX86_CALLCVT_CDECL;
1137 : 61823 : else if (lookup_attribute ("stdcall", attrs))
1138 : : ret |= IX86_CALLCVT_STDCALL;
1139 : 61823 : else if (lookup_attribute ("fastcall", attrs))
1140 : : ret |= IX86_CALLCVT_FASTCALL;
1141 : 61814 : else if (lookup_attribute ("thiscall", attrs))
1142 : : ret |= IX86_CALLCVT_THISCALL;
1143 : :
1144 : : /* Regparam isn't allowed for thiscall and fastcall. */
1145 : : if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
1146 : : {
1147 : 61814 : if (lookup_attribute ("regparm", attrs))
1148 : 15683 : ret |= IX86_CALLCVT_REGPARM;
1149 : 61814 : if (lookup_attribute ("sseregparm", attrs))
1150 : 0 : ret |= IX86_CALLCVT_SSEREGPARM;
1151 : : }
1152 : :
1153 : 61823 : if (IX86_BASE_CALLCVT(ret) != 0)
1154 : 9 : return ret;
1155 : : }
1156 : :
1157 : 3231071 : is_stdarg = stdarg_p (type);
1158 : 3231071 : if (TARGET_RTD && !is_stdarg)
1159 : 0 : return IX86_CALLCVT_STDCALL | ret;
1160 : :
1161 : 3231071 : if (ret != 0
1162 : 3231071 : || is_stdarg
1163 : 3206574 : || TREE_CODE (type) != METHOD_TYPE
1164 : 3360624 : || ix86_function_type_abi (type) != MS_ABI)
1165 : 3231071 : return IX86_CALLCVT_CDECL | ret;
1166 : :
1167 : : return IX86_CALLCVT_THISCALL;
1168 : : }
1169 : :
1170 : : /* Return 0 if the attributes for two types are incompatible, 1 if they
1171 : : are compatible, and 2 if they are nearly compatible (which causes a
1172 : : warning to be generated). */
1173 : :
1174 : : static int
1175 : 1421121 : ix86_comp_type_attributes (const_tree type1, const_tree type2)
1176 : : {
1177 : 1421121 : unsigned int ccvt1, ccvt2;
1178 : :
1179 : 1421121 : if (TREE_CODE (type1) != FUNCTION_TYPE
1180 : 1421121 : && TREE_CODE (type1) != METHOD_TYPE)
1181 : : return 1;
1182 : :
1183 : 1414547 : ccvt1 = ix86_get_callcvt (type1);
1184 : 1414547 : ccvt2 = ix86_get_callcvt (type2);
1185 : 1414547 : if (ccvt1 != ccvt2)
1186 : : return 0;
1187 : 2807238 : if (ix86_function_regparm (type1, NULL)
1188 : 1403619 : != ix86_function_regparm (type2, NULL))
1189 : : return 0;
1190 : :
1191 : 682806 : if (lookup_attribute ("no_callee_saved_registers",
1192 : 682806 : TYPE_ATTRIBUTES (type1))
1193 : 682806 : != lookup_attribute ("no_callee_saved_registers",
1194 : 682806 : TYPE_ATTRIBUTES (type2)))
1195 : : return 0;
1196 : :
1197 : : return 1;
1198 : : }
1199 : :
1200 : : /* Return the regparm value for a function with the indicated TYPE and DECL.
1201 : : DECL may be NULL when calling function indirectly
1202 : : or considering a libcall. */
1203 : :
1204 : : static int
1205 : 4063951 : ix86_function_regparm (const_tree type, const_tree decl)
1206 : : {
1207 : 4063951 : tree attr;
1208 : 4063951 : int regparm;
1209 : 4063951 : unsigned int ccvt;
1210 : :
1211 : 4063951 : if (TARGET_64BIT)
1212 : 2807166 : return (ix86_function_type_abi (type) == SYSV_ABI
1213 : 2807166 : ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
1214 : 1256785 : ccvt = ix86_get_callcvt (type);
1215 : 1256785 : regparm = ix86_regparm;
1216 : :
1217 : 1256785 : if ((ccvt & IX86_CALLCVT_REGPARM) != 0)
1218 : : {
1219 : 2017 : attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
1220 : 2017 : if (attr)
1221 : : {
1222 : 2017 : regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
1223 : 2017 : return regparm;
1224 : : }
1225 : : }
1226 : 1254768 : else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
1227 : : return 2;
1228 : 1254768 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
1229 : : return 1;
1230 : :
1231 : : /* Use register calling convention for local functions when possible. */
1232 : 1254768 : if (decl
1233 : 1193014 : && TREE_CODE (decl) == FUNCTION_DECL)
1234 : : {
1235 : 1182931 : cgraph_node *target = cgraph_node::get (decl);
1236 : 1182931 : if (target)
1237 : 1176283 : target = target->function_symbol ();
1238 : :
1239 : : /* Caller and callee must agree on the calling convention, so
1240 : : checking here just optimize means that with
1241 : : __attribute__((optimize (...))) caller could use regparm convention
1242 : : and callee not, or vice versa. Instead look at whether the callee
1243 : : is optimized or not. */
1244 : 1176283 : if (target && opt_for_fn (target->decl, optimize)
1245 : 2351716 : && !(profile_flag && !flag_fentry))
1246 : : {
1247 : 1175433 : if (target->local && target->can_change_signature)
1248 : : {
1249 : 137096 : int local_regparm, globals = 0, regno;
1250 : :
1251 : : /* Make sure no regparm register is taken by a
1252 : : fixed register variable. */
1253 : 137096 : for (local_regparm = 0; local_regparm < REGPARM_MAX;
1254 : : local_regparm++)
1255 : 102822 : if (fixed_regs[local_regparm])
1256 : : break;
1257 : :
1258 : : /* We don't want to use regparm(3) for nested functions as
1259 : : these use a static chain pointer in the third argument. */
1260 : 34274 : if (local_regparm == 3 && DECL_STATIC_CHAIN (target->decl))
1261 : : local_regparm = 2;
1262 : :
1263 : : /* Save a register for the split stack. */
1264 : 34274 : if (flag_split_stack)
1265 : : {
1266 : 20833 : if (local_regparm == 3)
1267 : : local_regparm = 2;
1268 : 707 : else if (local_regparm == 2
1269 : 707 : && DECL_STATIC_CHAIN (target->decl))
1270 : : local_regparm = 1;
1271 : : }
1272 : :
1273 : : /* Each fixed register usage increases register pressure,
1274 : : so less registers should be used for argument passing.
1275 : : This functionality can be overriden by an explicit
1276 : : regparm value. */
1277 : 239918 : for (regno = AX_REG; regno <= DI_REG; regno++)
1278 : 205644 : if (fixed_regs[regno])
1279 : 0 : globals++;
1280 : :
1281 : 34274 : local_regparm
1282 : 34274 : = globals < local_regparm ? local_regparm - globals : 0;
1283 : :
1284 : 34274 : if (local_regparm > regparm)
1285 : 4063951 : regparm = local_regparm;
1286 : : }
1287 : : }
1288 : : }
1289 : :
1290 : : return regparm;
1291 : : }
1292 : :
1293 : : /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
1294 : : DFmode (2) arguments in SSE registers for a function with the
1295 : : indicated TYPE and DECL. DECL may be NULL when calling function
1296 : : indirectly or considering a libcall. Return -1 if any FP parameter
1297 : : should be rejected by error. This is used in siutation we imply SSE
1298 : : calling convetion but the function is called from another function with
1299 : : SSE disabled. Otherwise return 0. */
1300 : :
1301 : : static int
1302 : 1061499 : ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
1303 : : {
1304 : 1061499 : gcc_assert (!TARGET_64BIT);
1305 : :
1306 : : /* Use SSE registers to pass SFmode and DFmode arguments if requested
1307 : : by the sseregparm attribute. */
1308 : 1061499 : if (TARGET_SSEREGPARM
1309 : 1061499 : || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
1310 : : {
1311 : 0 : if (!TARGET_SSE)
1312 : : {
1313 : 0 : if (warn)
1314 : : {
1315 : 0 : if (decl)
1316 : 0 : error ("calling %qD with attribute sseregparm without "
1317 : : "SSE/SSE2 enabled", decl);
1318 : : else
1319 : 0 : error ("calling %qT with attribute sseregparm without "
1320 : : "SSE/SSE2 enabled", type);
1321 : : }
1322 : 0 : return 0;
1323 : : }
1324 : :
1325 : : return 2;
1326 : : }
1327 : :
1328 : 1061499 : if (!decl)
1329 : : return 0;
1330 : :
1331 : 967118 : cgraph_node *target = cgraph_node::get (decl);
1332 : 967118 : if (target)
1333 : 960477 : target = target->function_symbol ();
1334 : :
1335 : : /* For local functions, pass up to SSE_REGPARM_MAX SFmode
1336 : : (and DFmode for SSE2) arguments in SSE registers. */
1337 : 960477 : if (target
1338 : : /* TARGET_SSE_MATH */
1339 : 960477 : && (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE)
1340 : 1296 : && opt_for_fn (target->decl, optimize)
1341 : 961773 : && !(profile_flag && !flag_fentry))
1342 : : {
1343 : 1296 : if (target->local && target->can_change_signature)
1344 : : {
1345 : : /* Refuse to produce wrong code when local function with SSE enabled
1346 : : is called from SSE disabled function.
1347 : : FIXME: We need a way to detect these cases cross-ltrans partition
1348 : : and avoid using SSE calling conventions on local functions called
1349 : : from function with SSE disabled. For now at least delay the
1350 : : warning until we know we are going to produce wrong code.
1351 : : See PR66047 */
1352 : 0 : if (!TARGET_SSE && warn)
1353 : : return -1;
1354 : 0 : return TARGET_SSE2_P (target_opts_for_fn (target->decl)
1355 : 0 : ->x_ix86_isa_flags) ? 2 : 1;
1356 : : }
1357 : : }
1358 : :
1359 : : return 0;
1360 : : }
1361 : :
1362 : : /* Return true if EAX is live at the start of the function. Used by
1363 : : ix86_expand_prologue to determine if we need special help before
1364 : : calling allocate_stack_worker. */
1365 : :
1366 : : static bool
1367 : 7089 : ix86_eax_live_at_start_p (void)
1368 : : {
1369 : : /* Cheat. Don't bother working forward from ix86_function_regparm
1370 : : to the function type to whether an actual argument is located in
1371 : : eax. Instead just look at cfg info, which is still close enough
1372 : : to correct at this point. This gives false positives for broken
1373 : : functions that might use uninitialized data that happens to be
1374 : : allocated in eax, but who cares? */
1375 : 7089 : return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0);
1376 : : }
1377 : :
1378 : : static bool
1379 : 159086 : ix86_keep_aggregate_return_pointer (tree fntype)
1380 : : {
1381 : 159086 : tree attr;
1382 : :
1383 : 159086 : if (!TARGET_64BIT)
1384 : : {
1385 : 159086 : attr = lookup_attribute ("callee_pop_aggregate_return",
1386 : 159086 : TYPE_ATTRIBUTES (fntype));
1387 : 159086 : if (attr)
1388 : 0 : return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0);
1389 : :
1390 : : /* For 32-bit MS-ABI the default is to keep aggregate
1391 : : return pointer. */
1392 : 159086 : if (ix86_function_type_abi (fntype) == MS_ABI)
1393 : : return true;
1394 : : }
1395 : : return KEEP_AGGREGATE_RETURN_POINTER != 0;
1396 : : }
1397 : :
1398 : : /* Value is the number of bytes of arguments automatically
1399 : : popped when returning from a subroutine call.
1400 : : FUNDECL is the declaration node of the function (as a tree),
1401 : : FUNTYPE is the data type of the function (as a tree),
1402 : : or for a library call it is an identifier node for the subroutine name.
1403 : : SIZE is the number of bytes of arguments passed on the stack.
1404 : :
1405 : : On the 80386, the RTD insn may be used to pop them if the number
1406 : : of args is fixed, but if the number is variable then the caller
1407 : : must pop them all. RTD can't be used for library calls now
1408 : : because the library is compiled with the Unix compiler.
1409 : : Use of RTD is a selectable option, since it is incompatible with
1410 : : standard Unix calling sequences. If the option is not selected,
1411 : : the caller must always pop the args.
1412 : :
1413 : : The attribute stdcall is equivalent to RTD on a per module basis. */
1414 : :
1415 : : static poly_int64
1416 : 7435011 : ix86_return_pops_args (tree fundecl, tree funtype, poly_int64 size)
1417 : : {
1418 : 7435011 : unsigned int ccvt;
1419 : :
1420 : : /* None of the 64-bit ABIs pop arguments. */
1421 : 7435011 : if (TARGET_64BIT)
1422 : 6571433 : return 0;
1423 : :
1424 : 863578 : ccvt = ix86_get_callcvt (funtype);
1425 : :
1426 : 863578 : if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL
1427 : : | IX86_CALLCVT_THISCALL)) != 0
1428 : 863578 : && ! stdarg_p (funtype))
1429 : 3 : return size;
1430 : :
1431 : : /* Lose any fake structure return argument if it is passed on the stack. */
1432 : 863575 : if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
1433 : 863575 : && !ix86_keep_aggregate_return_pointer (funtype))
1434 : : {
1435 : 159086 : int nregs = ix86_function_regparm (funtype, fundecl);
1436 : 159086 : if (nregs == 0)
1437 : 304224 : return GET_MODE_SIZE (Pmode);
1438 : : }
1439 : :
1440 : 711463 : return 0;
1441 : : }
1442 : :
1443 : : /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook. */
1444 : :
1445 : : static bool
1446 : 9674413 : ix86_legitimate_combined_insn (rtx_insn *insn)
1447 : : {
1448 : 9674413 : int i;
1449 : :
1450 : : /* Check operand constraints in case hard registers were propagated
1451 : : into insn pattern. This check prevents combine pass from
1452 : : generating insn patterns with invalid hard register operands.
1453 : : These invalid insns can eventually confuse reload to error out
1454 : : with a spill failure. See also PRs 46829 and 46843. */
1455 : :
1456 : 9674413 : gcc_assert (INSN_CODE (insn) >= 0);
1457 : :
1458 : 9674413 : extract_insn (insn);
1459 : 9674413 : preprocess_constraints (insn);
1460 : :
1461 : 9674413 : int n_operands = recog_data.n_operands;
1462 : 9674413 : int n_alternatives = recog_data.n_alternatives;
1463 : 33202322 : for (i = 0; i < n_operands; i++)
1464 : : {
1465 : 23531379 : rtx op = recog_data.operand[i];
1466 : 23531379 : machine_mode mode = GET_MODE (op);
1467 : 23531379 : const operand_alternative *op_alt;
1468 : 23531379 : int offset = 0;
1469 : 23531379 : bool win;
1470 : 23531379 : int j;
1471 : :
1472 : : /* A unary operator may be accepted by the predicate, but it
1473 : : is irrelevant for matching constraints. */
1474 : 23531379 : if (UNARY_P (op))
1475 : 46179 : op = XEXP (op, 0);
1476 : :
1477 : 23531379 : if (SUBREG_P (op))
1478 : : {
1479 : 823773 : if (REG_P (SUBREG_REG (op))
1480 : 823773 : && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
1481 : 57 : offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
1482 : 57 : GET_MODE (SUBREG_REG (op)),
1483 : 57 : SUBREG_BYTE (op),
1484 : 57 : GET_MODE (op));
1485 : 823773 : op = SUBREG_REG (op);
1486 : : }
1487 : :
1488 : 23531379 : if (!(REG_P (op) && HARD_REGISTER_P (op)))
1489 : 23226541 : continue;
1490 : :
1491 : 304838 : op_alt = recog_op_alt;
1492 : :
1493 : : /* Operand has no constraints, anything is OK. */
1494 : 304838 : win = !n_alternatives;
1495 : :
1496 : 304838 : alternative_mask preferred = get_preferred_alternatives (insn);
1497 : 820274 : for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
1498 : : {
1499 : 511744 : if (!TEST_BIT (preferred, j))
1500 : 133523 : continue;
1501 : 378221 : if (op_alt[i].anything_ok
1502 : 197554 : || (op_alt[i].matches != -1
1503 : 35269 : && operands_match_p
1504 : 35269 : (recog_data.operand[i],
1505 : 35269 : recog_data.operand[op_alt[i].matches]))
1506 : 571426 : || reg_fits_class_p (op, op_alt[i].cl, offset, mode))
1507 : : {
1508 : : win = true;
1509 : : break;
1510 : : }
1511 : : }
1512 : :
1513 : 304838 : if (!win)
1514 : : return false;
1515 : : }
1516 : :
1517 : : return true;
1518 : : }
1519 : :
1520 : : /* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */
1521 : :
1522 : : static unsigned HOST_WIDE_INT
1523 : 4301 : ix86_asan_shadow_offset (void)
1524 : : {
1525 : 4301 : return SUBTARGET_SHADOW_OFFSET;
1526 : : }
1527 : :
1528 : : /* Argument support functions. */
1529 : :
1530 : : /* Return true when register may be used to pass function parameters. */
1531 : : bool
1532 : 1376336392 : ix86_function_arg_regno_p (int regno)
1533 : : {
1534 : 1376336392 : int i;
1535 : 1376336392 : enum calling_abi call_abi;
1536 : 1376336392 : const int *parm_regs;
1537 : :
1538 : 1373113333 : if (TARGET_SSE && SSE_REGNO_P (regno)
1539 : 2273705942 : && regno < FIRST_SSE_REG + SSE_REGPARM_MAX)
1540 : : return true;
1541 : :
1542 : 1265580486 : if (!TARGET_64BIT)
1543 : 125989023 : return (regno < REGPARM_MAX
1544 : 125989023 : || (TARGET_MMX && MMX_REGNO_P (regno)
1545 : 11323504 : && regno < FIRST_MMX_REG + MMX_REGPARM_MAX));
1546 : :
1547 : : /* TODO: The function should depend on current function ABI but
1548 : : builtins.cc would need updating then. Therefore we use the
1549 : : default ABI. */
1550 : 1139591463 : call_abi = ix86_cfun_abi ();
1551 : :
1552 : : /* RAX is used as hidden argument to va_arg functions. */
1553 : 1139591463 : if (call_abi == SYSV_ABI && regno == AX_REG)
1554 : : return true;
1555 : :
1556 : 1126436184 : if (call_abi == MS_ABI)
1557 : : parm_regs = x86_64_ms_abi_int_parameter_registers;
1558 : : else
1559 : 1092056840 : parm_regs = x86_64_int_parameter_registers;
1560 : :
1561 : 15071742324 : for (i = 0; i < (call_abi == MS_ABI
1562 : 7535871162 : ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
1563 : 6489979678 : if (regno == parm_regs[i])
1564 : : return true;
1565 : : return false;
1566 : : }
1567 : :
1568 : : /* Return if we do not know how to pass ARG solely in registers. */
1569 : :
1570 : : static bool
1571 : 370392489 : ix86_must_pass_in_stack (const function_arg_info &arg)
1572 : : {
1573 : 370392489 : if (must_pass_in_stack_var_size_or_pad (arg))
1574 : : return true;
1575 : :
1576 : : /* For 32-bit, we want TImode aggregates to go on the stack. But watch out!
1577 : : The layout_type routine is crafty and tries to trick us into passing
1578 : : currently unsupported vector types on the stack by using TImode. */
1579 : 1748368 : return (!TARGET_64BIT && arg.mode == TImode
1580 : 370392452 : && arg.type && TREE_CODE (arg.type) != VECTOR_TYPE);
1581 : : }
1582 : :
1583 : : /* It returns the size, in bytes, of the area reserved for arguments passed
1584 : : in registers for the function represented by fndecl dependent to the used
1585 : : abi format. */
1586 : : int
1587 : 10471774 : ix86_reg_parm_stack_space (const_tree fndecl)
1588 : : {
1589 : 10471774 : enum calling_abi call_abi = SYSV_ABI;
1590 : 10471774 : if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
1591 : 10158515 : call_abi = ix86_function_abi (fndecl);
1592 : : else
1593 : 313259 : call_abi = ix86_function_type_abi (fndecl);
1594 : 10471774 : if (TARGET_64BIT && call_abi == MS_ABI)
1595 : 119228 : return 32;
1596 : : return 0;
1597 : : }
1598 : :
1599 : : /* We add this as a workaround in order to use libc_has_function
1600 : : hook in i386.md. */
1601 : : bool
1602 : 0 : ix86_libc_has_function (enum function_class fn_class)
1603 : : {
1604 : 0 : return targetm.libc_has_function (fn_class, NULL_TREE);
1605 : : }
1606 : :
1607 : : /* Returns value SYSV_ABI, MS_ABI dependent on fntype,
1608 : : specifying the call abi used. */
1609 : : enum calling_abi
1610 : 398333187 : ix86_function_type_abi (const_tree fntype)
1611 : : {
1612 : 398333187 : enum calling_abi abi = ix86_abi;
1613 : :
1614 : 398333187 : if (fntype == NULL_TREE || TYPE_ATTRIBUTES (fntype) == NULL_TREE)
1615 : : return abi;
1616 : :
1617 : 16910218 : if (abi == SYSV_ABI
1618 : 16910218 : && lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
1619 : : {
1620 : 2567514 : static int warned;
1621 : 2567514 : if (TARGET_X32 && !warned)
1622 : : {
1623 : 1 : error ("X32 does not support %<ms_abi%> attribute");
1624 : 1 : warned = 1;
1625 : : }
1626 : :
1627 : : abi = MS_ABI;
1628 : : }
1629 : 14342704 : else if (abi == MS_ABI
1630 : 14342704 : && lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
1631 : : abi = SYSV_ABI;
1632 : :
1633 : : return abi;
1634 : : }
1635 : :
1636 : : enum calling_abi
1637 : 193416879 : ix86_function_abi (const_tree fndecl)
1638 : : {
1639 : 193416879 : return fndecl ? ix86_function_type_abi (TREE_TYPE (fndecl)) : ix86_abi;
1640 : : }
1641 : :
1642 : : /* Returns value SYSV_ABI, MS_ABI dependent on cfun,
1643 : : specifying the call abi used. */
1644 : : enum calling_abi
1645 : 1966291310 : ix86_cfun_abi (void)
1646 : : {
1647 : 1966291310 : return cfun ? cfun->machine->call_abi : ix86_abi;
1648 : : }
1649 : :
1650 : : bool
1651 : 4950005 : ix86_function_ms_hook_prologue (const_tree fn)
1652 : : {
1653 : 4950005 : if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn)))
1654 : : {
1655 : 15 : if (decl_function_context (fn) != NULL_TREE)
1656 : 0 : error_at (DECL_SOURCE_LOCATION (fn),
1657 : : "%<ms_hook_prologue%> attribute is not compatible "
1658 : : "with nested function");
1659 : : else
1660 : : return true;
1661 : : }
1662 : : return false;
1663 : : }
1664 : :
1665 : : bool
1666 : 108625828 : ix86_function_naked (const_tree fn)
1667 : : {
1668 : 108625828 : if (fn && lookup_attribute ("naked", DECL_ATTRIBUTES (fn)))
1669 : : return true;
1670 : :
1671 : : return false;
1672 : : }
1673 : :
1674 : : /* Write the extra assembler code needed to declare a function properly. */
1675 : :
1676 : : void
1677 : 1507992 : ix86_asm_output_function_label (FILE *out_file, const char *fname,
1678 : : tree decl)
1679 : : {
1680 : 1507992 : bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
1681 : :
1682 : 1507992 : if (cfun)
1683 : 1504425 : cfun->machine->function_label_emitted = true;
1684 : :
1685 : 1507992 : if (is_ms_hook)
1686 : : {
1687 : 2 : int i, filler_count = (TARGET_64BIT ? 32 : 16);
1688 : 2 : unsigned int filler_cc = 0xcccccccc;
1689 : :
1690 : 18 : for (i = 0; i < filler_count; i += 4)
1691 : 16 : fprintf (out_file, ASM_LONG " %#x\n", filler_cc);
1692 : : }
1693 : :
1694 : : #ifdef SUBTARGET_ASM_UNWIND_INIT
1695 : : SUBTARGET_ASM_UNWIND_INIT (out_file);
1696 : : #endif
1697 : :
1698 : 1507992 : assemble_function_label_raw (out_file, fname);
1699 : :
1700 : : /* Output magic byte marker, if hot-patch attribute is set. */
1701 : 1507992 : if (is_ms_hook)
1702 : : {
1703 : 2 : if (TARGET_64BIT)
1704 : : {
1705 : : /* leaq [%rsp + 0], %rsp */
1706 : 2 : fputs (ASM_BYTE "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n",
1707 : : out_file);
1708 : : }
1709 : : else
1710 : : {
1711 : : /* movl.s %edi, %edi
1712 : : push %ebp
1713 : : movl.s %esp, %ebp */
1714 : 0 : fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", out_file);
1715 : : }
1716 : : }
1717 : 1507992 : }
1718 : :
1719 : : /* Implementation of call abi switching target hook. Specific to FNDECL
1720 : : the specific call register sets are set. See also
1721 : : ix86_conditional_register_usage for more details. */
1722 : : void
1723 : 173339703 : ix86_call_abi_override (const_tree fndecl)
1724 : : {
1725 : 173339703 : cfun->machine->call_abi = ix86_function_abi (fndecl);
1726 : 173339703 : }
1727 : :
1728 : : /* Return 1 if pseudo register should be created and used to hold
1729 : : GOT address for PIC code. */
1730 : : bool
1731 : 166763844 : ix86_use_pseudo_pic_reg (void)
1732 : : {
1733 : 166763844 : if ((TARGET_64BIT
1734 : 155842089 : && (ix86_cmodel == CM_SMALL_PIC
1735 : : || TARGET_PECOFF))
1736 : 161481455 : || !flag_pic)
1737 : 162125723 : return false;
1738 : : return true;
1739 : : }
1740 : :
1741 : : /* Initialize large model PIC register. */
1742 : :
1743 : : static void
1744 : 47 : ix86_init_large_pic_reg (unsigned int tmp_regno)
1745 : : {
1746 : 47 : rtx_code_label *label;
1747 : 47 : rtx tmp_reg;
1748 : :
1749 : 47 : gcc_assert (Pmode == DImode);
1750 : 47 : label = gen_label_rtx ();
1751 : 47 : emit_label (label);
1752 : 47 : LABEL_PRESERVE_P (label) = 1;
1753 : 47 : tmp_reg = gen_rtx_REG (Pmode, tmp_regno);
1754 : 47 : gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno);
1755 : 47 : emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx,
1756 : : label));
1757 : 47 : emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
1758 : 47 : emit_insn (gen_add2_insn (pic_offset_table_rtx, tmp_reg));
1759 : 47 : const char *name = LABEL_NAME (label);
1760 : 47 : PUT_CODE (label, NOTE);
1761 : 47 : NOTE_KIND (label) = NOTE_INSN_DELETED_LABEL;
1762 : 47 : NOTE_DELETED_LABEL_NAME (label) = name;
1763 : 47 : }
1764 : :
1765 : : /* Create and initialize PIC register if required. */
1766 : : static void
1767 : 1440897 : ix86_init_pic_reg (void)
1768 : : {
1769 : 1440897 : edge entry_edge;
1770 : 1440897 : rtx_insn *seq;
1771 : :
1772 : 1440897 : if (!ix86_use_pseudo_pic_reg ())
1773 : : return;
1774 : :
1775 : 39730 : start_sequence ();
1776 : :
1777 : 39730 : if (TARGET_64BIT)
1778 : : {
1779 : 60 : if (ix86_cmodel == CM_LARGE_PIC)
1780 : 44 : ix86_init_large_pic_reg (R11_REG);
1781 : : else
1782 : 16 : emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
1783 : : }
1784 : : else
1785 : : {
1786 : : /* If there is future mcount call in the function it is more profitable
1787 : : to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM. */
1788 : 39670 : rtx reg = crtl->profile
1789 : 39670 : ? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM)
1790 : 39670 : : pic_offset_table_rtx;
1791 : 39670 : rtx_insn *insn = emit_insn (gen_set_got (reg));
1792 : 39670 : RTX_FRAME_RELATED_P (insn) = 1;
1793 : 39670 : if (crtl->profile)
1794 : 0 : emit_move_insn (pic_offset_table_rtx, reg);
1795 : 39670 : add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
1796 : : }
1797 : :
1798 : 39730 : seq = get_insns ();
1799 : 39730 : end_sequence ();
1800 : :
1801 : 39730 : entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
1802 : 39730 : insert_insn_on_edge (seq, entry_edge);
1803 : 39730 : commit_one_edge_insertion (entry_edge);
1804 : : }
1805 : :
1806 : : /* Initialize a variable CUM of type CUMULATIVE_ARGS
1807 : : for a call to a function whose data type is FNTYPE.
1808 : : For a library call, FNTYPE is 0. */
1809 : :
1810 : : void
1811 : 10201530 : init_cumulative_args (CUMULATIVE_ARGS *cum, /* Argument info to initialize */
1812 : : tree fntype, /* tree ptr for function decl */
1813 : : rtx libname, /* SYMBOL_REF of library name or 0 */
1814 : : tree fndecl,
1815 : : int caller)
1816 : : {
1817 : 10201530 : struct cgraph_node *local_info_node = NULL;
1818 : 10201530 : struct cgraph_node *target = NULL;
1819 : :
1820 : : /* Set silent_p to false to raise an error for invalid calls when
1821 : : expanding function body. */
1822 : 10201530 : cfun->machine->silent_p = false;
1823 : :
1824 : 10201530 : memset (cum, 0, sizeof (*cum));
1825 : :
1826 : 10201530 : if (fndecl)
1827 : : {
1828 : 9872111 : target = cgraph_node::get (fndecl);
1829 : 9872111 : if (target)
1830 : : {
1831 : 9752654 : target = target->function_symbol ();
1832 : 9752654 : local_info_node = cgraph_node::local_info_node (target->decl);
1833 : 9752654 : cum->call_abi = ix86_function_abi (target->decl);
1834 : : }
1835 : : else
1836 : 119457 : cum->call_abi = ix86_function_abi (fndecl);
1837 : : }
1838 : : else
1839 : 329419 : cum->call_abi = ix86_function_type_abi (fntype);
1840 : :
1841 : 10201530 : cum->caller = caller;
1842 : :
1843 : : /* Set up the number of registers to use for passing arguments. */
1844 : 10201530 : cum->nregs = ix86_regparm;
1845 : 10201530 : if (TARGET_64BIT)
1846 : : {
1847 : 9179420 : cum->nregs = (cum->call_abi == SYSV_ABI
1848 : 9179420 : ? X86_64_REGPARM_MAX
1849 : : : X86_64_MS_REGPARM_MAX);
1850 : : }
1851 : 10201530 : if (TARGET_SSE)
1852 : : {
1853 : 10192493 : cum->sse_nregs = SSE_REGPARM_MAX;
1854 : 10192493 : if (TARGET_64BIT)
1855 : : {
1856 : 9170503 : cum->sse_nregs = (cum->call_abi == SYSV_ABI
1857 : 9170503 : ? X86_64_SSE_REGPARM_MAX
1858 : : : X86_64_MS_SSE_REGPARM_MAX);
1859 : : }
1860 : : }
1861 : 10201530 : if (TARGET_MMX)
1862 : 11016693 : cum->mmx_nregs = MMX_REGPARM_MAX;
1863 : 10201530 : cum->warn_avx512f = true;
1864 : 10201530 : cum->warn_avx = true;
1865 : 10201530 : cum->warn_sse = true;
1866 : 10201530 : cum->warn_mmx = true;
1867 : :
1868 : : /* Because type might mismatch in between caller and callee, we need to
1869 : : use actual type of function for local calls.
1870 : : FIXME: cgraph_analyze can be told to actually record if function uses
1871 : : va_start so for local functions maybe_vaarg can be made aggressive
1872 : : helping K&R code.
1873 : : FIXME: once typesytem is fixed, we won't need this code anymore. */
1874 : 10201530 : if (local_info_node && local_info_node->local
1875 : 9752654 : && local_info_node->can_change_signature)
1876 : 377701 : fntype = TREE_TYPE (target->decl);
1877 : 10201530 : cum->stdarg = stdarg_p (fntype);
1878 : 20403060 : cum->maybe_vaarg = (fntype
1879 : 10662285 : ? (!prototype_p (fntype) || stdarg_p (fntype))
1880 : 119119 : : !libname);
1881 : :
1882 : 10201530 : cum->decl = fndecl;
1883 : :
1884 : 10201530 : cum->warn_empty = !warn_abi || cum->stdarg;
1885 : 10201530 : if (!cum->warn_empty && fntype)
1886 : : {
1887 : 107722 : function_args_iterator iter;
1888 : 107722 : tree argtype;
1889 : 107722 : bool seen_empty_type = false;
1890 : 308891 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
1891 : : {
1892 : 308891 : if (argtype == error_mark_node || VOID_TYPE_P (argtype))
1893 : : break;
1894 : 201579 : if (TYPE_EMPTY_P (argtype))
1895 : : seen_empty_type = true;
1896 : 200743 : else if (seen_empty_type)
1897 : : {
1898 : 410 : cum->warn_empty = true;
1899 : 410 : break;
1900 : : }
1901 : : }
1902 : : }
1903 : :
1904 : 10201530 : if (!TARGET_64BIT)
1905 : : {
1906 : : /* If there are variable arguments, then we won't pass anything
1907 : : in registers in 32-bit mode. */
1908 : 1022110 : if (stdarg_p (fntype))
1909 : : {
1910 : 8863 : cum->nregs = 0;
1911 : : /* Since in 32-bit, variable arguments are always passed on
1912 : : stack, there is scratch register available for indirect
1913 : : sibcall. */
1914 : 8863 : cfun->machine->arg_reg_available = true;
1915 : 8863 : cum->sse_nregs = 0;
1916 : 8863 : cum->mmx_nregs = 0;
1917 : 8863 : cum->warn_avx512f = false;
1918 : 8863 : cum->warn_avx = false;
1919 : 8863 : cum->warn_sse = false;
1920 : 8863 : cum->warn_mmx = false;
1921 : 8863 : return;
1922 : : }
1923 : :
1924 : : /* Use ecx and edx registers if function has fastcall attribute,
1925 : : else look for regparm information. */
1926 : 1013247 : if (fntype)
1927 : : {
1928 : 1000107 : unsigned int ccvt = ix86_get_callcvt (fntype);
1929 : 1000107 : if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
1930 : : {
1931 : 0 : cum->nregs = 1;
1932 : 0 : cum->fastcall = 1; /* Same first register as in fastcall. */
1933 : : }
1934 : 1000107 : else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
1935 : : {
1936 : 4 : cum->nregs = 2;
1937 : 4 : cum->fastcall = 1;
1938 : : }
1939 : : else
1940 : 1000103 : cum->nregs = ix86_function_regparm (fntype, fndecl);
1941 : : }
1942 : :
1943 : : /* Set up the number of SSE registers used for passing SFmode
1944 : : and DFmode arguments. Warn for mismatching ABI. */
1945 : 1013247 : cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
1946 : : }
1947 : :
1948 : 10192667 : cfun->machine->arg_reg_available = (cum->nregs > 0);
1949 : : }
1950 : :
1951 : : /* Return the "natural" mode for TYPE. In most cases, this is just TYPE_MODE.
1952 : : But in the case of vector types, it is some vector mode.
1953 : :
1954 : : When we have only some of our vector isa extensions enabled, then there
1955 : : are some modes for which vector_mode_supported_p is false. For these
1956 : : modes, the generic vector support in gcc will choose some non-vector mode
1957 : : in order to implement the type. By computing the natural mode, we'll
1958 : : select the proper ABI location for the operand and not depend on whatever
1959 : : the middle-end decides to do with these vector types.
1960 : :
1961 : : The midde-end can't deal with the vector types > 16 bytes. In this
1962 : : case, we return the original mode and warn ABI change if CUM isn't
1963 : : NULL.
1964 : :
1965 : : If INT_RETURN is true, warn ABI change if the vector mode isn't
1966 : : available for function return value. */
1967 : :
1968 : : static machine_mode
1969 : 211728552 : type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum,
1970 : : bool in_return)
1971 : : {
1972 : 211728552 : machine_mode mode = TYPE_MODE (type);
1973 : :
1974 : 211728552 : if (VECTOR_TYPE_P (type) && !VECTOR_MODE_P (mode))
1975 : : {
1976 : 439874 : HOST_WIDE_INT size = int_size_in_bytes (type);
1977 : 439874 : if ((size == 8 || size == 16 || size == 32 || size == 64)
1978 : : /* ??? Generic code allows us to create width 1 vectors. Ignore. */
1979 : 439874 : && TYPE_VECTOR_SUBPARTS (type) > 1)
1980 : : {
1981 : 405073 : machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
1982 : :
1983 : : /* There are no XFmode vector modes ... */
1984 : 405073 : if (innermode == XFmode)
1985 : : return mode;
1986 : :
1987 : : /* ... and no decimal float vector modes. */
1988 : 404528 : if (DECIMAL_FLOAT_MODE_P (innermode))
1989 : : return mode;
1990 : :
1991 : 404238 : if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type)))
1992 : : mode = MIN_MODE_VECTOR_FLOAT;
1993 : : else
1994 : 339116 : mode = MIN_MODE_VECTOR_INT;
1995 : :
1996 : : /* Get the mode which has this inner mode and number of units. */
1997 : 8560193 : FOR_EACH_MODE_FROM (mode, mode)
1998 : 17794932 : if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
1999 : 9638977 : && GET_MODE_INNER (mode) == innermode)
2000 : : {
2001 : 404238 : if (size == 64 && (!TARGET_AVX512F || !TARGET_EVEX512)
2002 : 281713 : && !TARGET_IAMCU)
2003 : : {
2004 : 281713 : static bool warnedavx512f;
2005 : 281713 : static bool warnedavx512f_ret;
2006 : :
2007 : 281713 : if (cum && cum->warn_avx512f && !warnedavx512f)
2008 : : {
2009 : 1194 : if (warning (OPT_Wpsabi, "AVX512F vector argument "
2010 : : "without AVX512F enabled changes the ABI"))
2011 : 2 : warnedavx512f = true;
2012 : : }
2013 : 280519 : else if (in_return && !warnedavx512f_ret)
2014 : : {
2015 : 277813 : if (warning (OPT_Wpsabi, "AVX512F vector return "
2016 : : "without AVX512F enabled changes the ABI"))
2017 : 2 : warnedavx512f_ret = true;
2018 : : }
2019 : :
2020 : 281713 : return TYPE_MODE (type);
2021 : : }
2022 : 122525 : else if (size == 32 && !TARGET_AVX && !TARGET_IAMCU)
2023 : : {
2024 : 121976 : static bool warnedavx;
2025 : 121976 : static bool warnedavx_ret;
2026 : :
2027 : 121976 : if (cum && cum->warn_avx && !warnedavx)
2028 : : {
2029 : 601 : if (warning (OPT_Wpsabi, "AVX vector argument "
2030 : : "without AVX enabled changes the ABI"))
2031 : 5 : warnedavx = true;
2032 : : }
2033 : 121375 : else if (in_return && !warnedavx_ret)
2034 : : {
2035 : 119404 : if (warning (OPT_Wpsabi, "AVX vector return "
2036 : : "without AVX enabled changes the ABI"))
2037 : 7 : warnedavx_ret = true;
2038 : : }
2039 : :
2040 : 121976 : return TYPE_MODE (type);
2041 : : }
2042 : 549 : else if (((size == 8 && TARGET_64BIT) || size == 16)
2043 : 546 : && !TARGET_SSE
2044 : 140 : && !TARGET_IAMCU)
2045 : : {
2046 : 140 : static bool warnedsse;
2047 : 140 : static bool warnedsse_ret;
2048 : :
2049 : 140 : if (cum && cum->warn_sse && !warnedsse)
2050 : : {
2051 : 19 : if (warning (OPT_Wpsabi, "SSE vector argument "
2052 : : "without SSE enabled changes the ABI"))
2053 : 6 : warnedsse = true;
2054 : : }
2055 : 121 : else if (!TARGET_64BIT && in_return && !warnedsse_ret)
2056 : : {
2057 : 0 : if (warning (OPT_Wpsabi, "SSE vector return "
2058 : : "without SSE enabled changes the ABI"))
2059 : 0 : warnedsse_ret = true;
2060 : : }
2061 : : }
2062 : 409 : else if ((size == 8 && !TARGET_64BIT)
2063 : 0 : && (!cfun
2064 : 0 : || cfun->machine->func_type == TYPE_NORMAL)
2065 : 0 : && !TARGET_MMX
2066 : 0 : && !TARGET_IAMCU)
2067 : : {
2068 : 0 : static bool warnedmmx;
2069 : 0 : static bool warnedmmx_ret;
2070 : :
2071 : 0 : if (cum && cum->warn_mmx && !warnedmmx)
2072 : : {
2073 : 0 : if (warning (OPT_Wpsabi, "MMX vector argument "
2074 : : "without MMX enabled changes the ABI"))
2075 : 0 : warnedmmx = true;
2076 : : }
2077 : 0 : else if (in_return && !warnedmmx_ret)
2078 : : {
2079 : 0 : if (warning (OPT_Wpsabi, "MMX vector return "
2080 : : "without MMX enabled changes the ABI"))
2081 : 0 : warnedmmx_ret = true;
2082 : : }
2083 : : }
2084 : 549 : return mode;
2085 : : }
2086 : :
2087 : 0 : gcc_unreachable ();
2088 : : }
2089 : : }
2090 : :
2091 : : return mode;
2092 : : }
2093 : :
2094 : : /* We want to pass a value in REGNO whose "natural" mode is MODE. However,
2095 : : this may not agree with the mode that the type system has chosen for the
2096 : : register, which is ORIG_MODE. If ORIG_MODE is not BLKmode, then we can
2097 : : go ahead and use it. Otherwise we have to build a PARALLEL instead. */
2098 : :
2099 : : static rtx
2100 : 35563446 : gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode,
2101 : : unsigned int regno)
2102 : : {
2103 : 35563446 : rtx tmp;
2104 : :
2105 : 35563446 : if (orig_mode != BLKmode)
2106 : 35563418 : tmp = gen_rtx_REG (orig_mode, regno);
2107 : : else
2108 : : {
2109 : 28 : tmp = gen_rtx_REG (mode, regno);
2110 : 28 : tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
2111 : 28 : tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
2112 : : }
2113 : :
2114 : 35563446 : return tmp;
2115 : : }
2116 : :
2117 : : /* x86-64 register passing implementation. See x86-64 ABI for details. Goal
2118 : : of this code is to classify each 8bytes of incoming argument by the register
2119 : : class and assign registers accordingly. */
2120 : :
2121 : : /* Return the union class of CLASS1 and CLASS2.
2122 : : See the x86-64 PS ABI for details. */
2123 : :
2124 : : static enum x86_64_reg_class
2125 : 44651062 : merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
2126 : : {
2127 : : /* Rule #1: If both classes are equal, this is the resulting class. */
2128 : 44207055 : if (class1 == class2)
2129 : : return class1;
2130 : :
2131 : : /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
2132 : : the other class. */
2133 : 38240013 : if (class1 == X86_64_NO_CLASS)
2134 : : return class2;
2135 : 38428146 : if (class2 == X86_64_NO_CLASS)
2136 : : return class1;
2137 : :
2138 : : /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
2139 : 1794760 : if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
2140 : : return X86_64_MEMORY_CLASS;
2141 : :
2142 : : /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
2143 : 1768556 : if ((class1 == X86_64_INTEGERSI_CLASS
2144 : 192017 : && (class2 == X86_64_SSESF_CLASS || class2 == X86_64_SSEHF_CLASS))
2145 : 1767350 : || (class2 == X86_64_INTEGERSI_CLASS
2146 : 723203 : && (class1 == X86_64_SSESF_CLASS || class1 == X86_64_SSEHF_CLASS)))
2147 : : return X86_64_INTEGERSI_CLASS;
2148 : 1763486 : if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
2149 : 714687 : || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
2150 : : return X86_64_INTEGER_CLASS;
2151 : :
2152 : : /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
2153 : : MEMORY is used. */
2154 : 60221 : if (class1 == X86_64_X87_CLASS
2155 : : || class1 == X86_64_X87UP_CLASS
2156 : 60221 : || class1 == X86_64_COMPLEX_X87_CLASS
2157 : : || class2 == X86_64_X87_CLASS
2158 : 59316 : || class2 == X86_64_X87UP_CLASS
2159 : 59006 : || class2 == X86_64_COMPLEX_X87_CLASS)
2160 : 1215 : return X86_64_MEMORY_CLASS;
2161 : :
2162 : : /* Rule #6: Otherwise class SSE is used. */
2163 : : return X86_64_SSE_CLASS;
2164 : : }
2165 : :
2166 : : /* Classify the argument of type TYPE and mode MODE.
2167 : : CLASSES will be filled by the register class used to pass each word
2168 : : of the operand. The number of words is returned. In case the parameter
2169 : : should be passed in memory, 0 is returned. As a special case for zero
2170 : : sized containers, classes[0] will be NO_CLASS and 1 is returned.
2171 : :
2172 : : BIT_OFFSET is used internally for handling records and specifies offset
2173 : : of the offset in bits modulo 512 to avoid overflow cases.
2174 : :
2175 : : See the x86-64 PS ABI for details.
2176 : : */
2177 : :
2178 : : static int
2179 : 356219541 : classify_argument (machine_mode mode, const_tree type,
2180 : : enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset,
2181 : : int &zero_width_bitfields)
2182 : : {
2183 : 356219541 : HOST_WIDE_INT bytes
2184 : 707253376 : = mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
2185 : 356219541 : int words = CEIL (bytes + (bit_offset % 64) / 8, UNITS_PER_WORD);
2186 : :
2187 : : /* Variable sized entities are always passed/returned in memory. */
2188 : 356219541 : if (bytes < 0)
2189 : : return 0;
2190 : :
2191 : 356218384 : if (mode != VOIDmode)
2192 : : {
2193 : : /* The value of "named" doesn't matter. */
2194 : 355307459 : function_arg_info arg (const_cast<tree> (type), mode, /*named=*/true);
2195 : 355307459 : if (targetm.calls.must_pass_in_stack (arg))
2196 : 37 : return 0;
2197 : : }
2198 : :
2199 : 356218347 : if (type && (AGGREGATE_TYPE_P (type)
2200 : 329849236 : || (TREE_CODE (type) == BITINT_TYPE && words > 1)))
2201 : : {
2202 : 27528776 : int i;
2203 : 27528776 : tree field;
2204 : 27528776 : enum x86_64_reg_class subclasses[MAX_CLASSES];
2205 : :
2206 : : /* On x86-64 we pass structures larger than 64 bytes on the stack. */
2207 : 27528776 : if (bytes > 64)
2208 : : return 0;
2209 : :
2210 : 71238847 : for (i = 0; i < words; i++)
2211 : 44505112 : classes[i] = X86_64_NO_CLASS;
2212 : :
2213 : : /* Zero sized arrays or structures are NO_CLASS. We return 0 to
2214 : : signalize memory class, so handle it as special case. */
2215 : 26733735 : if (!words)
2216 : : {
2217 : 74323 : classes[0] = X86_64_NO_CLASS;
2218 : 74323 : return 1;
2219 : : }
2220 : :
2221 : : /* Classify each field of record and merge classes. */
2222 : 26659412 : switch (TREE_CODE (type))
2223 : : {
2224 : 24576702 : case RECORD_TYPE:
2225 : : /* And now merge the fields of structure. */
2226 : 643467301 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2227 : : {
2228 : 619084798 : if (TREE_CODE (field) == FIELD_DECL)
2229 : : {
2230 : 37618786 : int num;
2231 : :
2232 : 37618786 : if (TREE_TYPE (field) == error_mark_node)
2233 : 4 : continue;
2234 : :
2235 : : /* Bitfields are always classified as integer. Handle them
2236 : : early, since later code would consider them to be
2237 : : misaligned integers. */
2238 : 37618782 : if (DECL_BIT_FIELD (field))
2239 : : {
2240 : 453268 : if (integer_zerop (DECL_SIZE (field)))
2241 : : {
2242 : 12902 : if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field))
2243 : 8048 : continue;
2244 : 4854 : if (zero_width_bitfields != 2)
2245 : : {
2246 : 4320 : zero_width_bitfields = 1;
2247 : 4320 : continue;
2248 : : }
2249 : : }
2250 : 440900 : for (i = (int_bit_position (field)
2251 : 440900 : + (bit_offset % 64)) / 8 / 8;
2252 : 884907 : i < ((int_bit_position (field) + (bit_offset % 64))
2253 : 884907 : + tree_to_shwi (DECL_SIZE (field))
2254 : 884907 : + 63) / 8 / 8; i++)
2255 : 444007 : classes[i]
2256 : 888014 : = merge_classes (X86_64_INTEGER_CLASS, classes[i]);
2257 : : }
2258 : : else
2259 : : {
2260 : 37165514 : int pos;
2261 : :
2262 : 37165514 : type = TREE_TYPE (field);
2263 : :
2264 : : /* Flexible array member is ignored. */
2265 : 37165514 : if (TYPE_MODE (type) == BLKmode
2266 : 498740 : && TREE_CODE (type) == ARRAY_TYPE
2267 : 193181 : && TYPE_SIZE (type) == NULL_TREE
2268 : 2004 : && TYPE_DOMAIN (type) != NULL_TREE
2269 : 37166759 : && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
2270 : : == NULL_TREE))
2271 : : {
2272 : 1245 : static bool warned;
2273 : :
2274 : 1245 : if (!warned && warn_psabi)
2275 : : {
2276 : 2 : warned = true;
2277 : 2 : inform (input_location,
2278 : : "the ABI of passing struct with"
2279 : : " a flexible array member has"
2280 : : " changed in GCC 4.4");
2281 : : }
2282 : 1245 : continue;
2283 : 1245 : }
2284 : 37164269 : num = classify_argument (TYPE_MODE (type), type,
2285 : : subclasses,
2286 : 37164269 : (int_bit_position (field)
2287 : 37164269 : + bit_offset) % 512,
2288 : : zero_width_bitfields);
2289 : 37164269 : if (!num)
2290 : : return 0;
2291 : 36970070 : pos = (int_bit_position (field)
2292 : 36970070 : + (bit_offset % 64)) / 8 / 8;
2293 : 77269042 : for (i = 0; i < num && (i + pos) < words; i++)
2294 : 40298972 : classes[i + pos]
2295 : 40298972 : = merge_classes (subclasses[i], classes[i + pos]);
2296 : : }
2297 : : }
2298 : : }
2299 : : break;
2300 : :
2301 : 447569 : case ARRAY_TYPE:
2302 : : /* Arrays are handled as small records. */
2303 : 447569 : {
2304 : 447569 : int num;
2305 : 447569 : num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
2306 : 447569 : TREE_TYPE (type), subclasses, bit_offset,
2307 : : zero_width_bitfields);
2308 : 447569 : if (!num)
2309 : : return 0;
2310 : :
2311 : : /* The partial classes are now full classes. */
2312 : 444418 : if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
2313 : 13575 : subclasses[0] = X86_64_SSE_CLASS;
2314 : 444418 : if (subclasses[0] == X86_64_SSEHF_CLASS && bytes != 2)
2315 : 4734 : subclasses[0] = X86_64_SSE_CLASS;
2316 : 444418 : if (subclasses[0] == X86_64_INTEGERSI_CLASS
2317 : 222492 : && !((bit_offset % 64) == 0 && bytes == 4))
2318 : 121119 : subclasses[0] = X86_64_INTEGER_CLASS;
2319 : :
2320 : 1373927 : for (i = 0; i < words; i++)
2321 : 929509 : classes[i] = subclasses[i % num];
2322 : :
2323 : : break;
2324 : : }
2325 : 360506 : case UNION_TYPE:
2326 : 360506 : case QUAL_UNION_TYPE:
2327 : : /* Unions are similar to RECORD_TYPE but offset is always 0.
2328 : : */
2329 : 4638678 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2330 : : {
2331 : 4311798 : if (TREE_CODE (field) == FIELD_DECL)
2332 : : {
2333 : 2647908 : int num;
2334 : :
2335 : 2647908 : if (TREE_TYPE (field) == error_mark_node)
2336 : 10 : continue;
2337 : :
2338 : 2647898 : num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
2339 : 2647898 : TREE_TYPE (field), subclasses,
2340 : : bit_offset, zero_width_bitfields);
2341 : 2647898 : if (!num)
2342 : : return 0;
2343 : 6522355 : for (i = 0; i < num && i < words; i++)
2344 : 3908083 : classes[i] = merge_classes (subclasses[i], classes[i]);
2345 : : }
2346 : : }
2347 : : break;
2348 : :
2349 : 1274635 : case BITINT_TYPE:
2350 : : /* _BitInt(N) for N > 64 is passed as structure containing
2351 : : (N + 63) / 64 64-bit elements. */
2352 : 1274635 : if (words > 2)
2353 : : return 0;
2354 : 74969 : classes[0] = classes[1] = X86_64_INTEGER_CLASS;
2355 : 74969 : return 2;
2356 : :
2357 : 0 : default:
2358 : 0 : gcc_unreachable ();
2359 : : }
2360 : :
2361 : 25153801 : if (words > 2)
2362 : : {
2363 : : /* When size > 16 bytes, if the first one isn't
2364 : : X86_64_SSE_CLASS or any other ones aren't
2365 : : X86_64_SSEUP_CLASS, everything should be passed in
2366 : : memory. */
2367 : 1135670 : if (classes[0] != X86_64_SSE_CLASS)
2368 : : return 0;
2369 : :
2370 : 190315 : for (i = 1; i < words; i++)
2371 : 172435 : if (classes[i] != X86_64_SSEUP_CLASS)
2372 : : return 0;
2373 : : }
2374 : :
2375 : : /* Final merger cleanup. */
2376 : 59128877 : for (i = 0; i < words; i++)
2377 : : {
2378 : : /* If one class is MEMORY, everything should be passed in
2379 : : memory. */
2380 : 35095738 : if (classes[i] == X86_64_MEMORY_CLASS)
2381 : : return 0;
2382 : :
2383 : : /* The X86_64_SSEUP_CLASS should be always preceded by
2384 : : X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. */
2385 : 35095236 : if (classes[i] == X86_64_SSEUP_CLASS
2386 : 146284 : && classes[i - 1] != X86_64_SSE_CLASS
2387 : 74696 : && classes[i - 1] != X86_64_SSEUP_CLASS)
2388 : : {
2389 : : /* The first one should never be X86_64_SSEUP_CLASS. */
2390 : 1916 : gcc_assert (i != 0);
2391 : 1916 : classes[i] = X86_64_SSE_CLASS;
2392 : : }
2393 : :
2394 : : /* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
2395 : : everything should be passed in memory. */
2396 : 35095236 : if (classes[i] == X86_64_X87UP_CLASS
2397 : 191532 : && (classes[i - 1] != X86_64_X87_CLASS))
2398 : : {
2399 : 2370 : static bool warned;
2400 : :
2401 : : /* The first one should never be X86_64_X87UP_CLASS. */
2402 : 2370 : gcc_assert (i != 0);
2403 : 2370 : if (!warned && warn_psabi)
2404 : : {
2405 : 1 : warned = true;
2406 : 1 : inform (input_location,
2407 : : "the ABI of passing union with %<long double%>"
2408 : : " has changed in GCC 4.4");
2409 : : }
2410 : 2370 : return 0;
2411 : : }
2412 : : }
2413 : : return words;
2414 : : }
2415 : :
2416 : : /* Compute alignment needed. We align all types to natural boundaries with
2417 : : exception of XFmode that is aligned to 64bits. */
2418 : 328689571 : if (mode != VOIDmode && mode != BLKmode)
2419 : : {
2420 : 327341929 : int mode_alignment = GET_MODE_BITSIZE (mode);
2421 : :
2422 : 327341929 : if (mode == XFmode)
2423 : : mode_alignment = 128;
2424 : 320216665 : else if (mode == XCmode)
2425 : 555315 : mode_alignment = 256;
2426 : 327341929 : if (COMPLEX_MODE_P (mode))
2427 : 2455137 : mode_alignment /= 2;
2428 : : /* Misaligned fields are always returned in memory. */
2429 : 327341929 : if (bit_offset % mode_alignment)
2430 : : return 0;
2431 : : }
2432 : :
2433 : : /* for V1xx modes, just use the base mode */
2434 : 328681938 : if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode
2435 : 419320085 : && GET_MODE_UNIT_SIZE (mode) == bytes)
2436 : 5360 : mode = GET_MODE_INNER (mode);
2437 : :
2438 : : /* Classification of atomic types. */
2439 : 328681938 : switch (mode)
2440 : : {
2441 : 207688 : case E_SDmode:
2442 : 207688 : case E_DDmode:
2443 : 207688 : classes[0] = X86_64_SSE_CLASS;
2444 : 207688 : return 1;
2445 : 99145 : case E_TDmode:
2446 : 99145 : classes[0] = X86_64_SSE_CLASS;
2447 : 99145 : classes[1] = X86_64_SSEUP_CLASS;
2448 : 99145 : return 2;
2449 : 208572082 : case E_DImode:
2450 : 208572082 : case E_SImode:
2451 : 208572082 : case E_HImode:
2452 : 208572082 : case E_QImode:
2453 : 208572082 : case E_CSImode:
2454 : 208572082 : case E_CHImode:
2455 : 208572082 : case E_CQImode:
2456 : 208572082 : {
2457 : 208572082 : int size = bit_offset + (int) GET_MODE_BITSIZE (mode);
2458 : :
2459 : : /* Analyze last 128 bits only. */
2460 : 208572082 : size = (size - 1) & 0x7f;
2461 : :
2462 : 208572082 : if (size < 32)
2463 : : {
2464 : 89848221 : classes[0] = X86_64_INTEGERSI_CLASS;
2465 : 89848221 : return 1;
2466 : : }
2467 : 118723861 : else if (size < 64)
2468 : : {
2469 : 108589394 : classes[0] = X86_64_INTEGER_CLASS;
2470 : 108589394 : return 1;
2471 : : }
2472 : 10134467 : else if (size < 64+32)
2473 : : {
2474 : 4253266 : classes[0] = X86_64_INTEGER_CLASS;
2475 : 4253266 : classes[1] = X86_64_INTEGERSI_CLASS;
2476 : 4253266 : return 2;
2477 : : }
2478 : 5881201 : else if (size < 64+64)
2479 : : {
2480 : 5881201 : classes[0] = classes[1] = X86_64_INTEGER_CLASS;
2481 : 5881201 : return 2;
2482 : : }
2483 : : else
2484 : : gcc_unreachable ();
2485 : : }
2486 : 1951589 : case E_CDImode:
2487 : 1951589 : case E_TImode:
2488 : 1951589 : classes[0] = classes[1] = X86_64_INTEGER_CLASS;
2489 : 1951589 : return 2;
2490 : 0 : case E_COImode:
2491 : 0 : case E_OImode:
2492 : : /* OImode shouldn't be used directly. */
2493 : 0 : gcc_unreachable ();
2494 : : case E_CTImode:
2495 : : return 0;
2496 : 960952 : case E_HFmode:
2497 : 960952 : case E_BFmode:
2498 : 960952 : if (!(bit_offset % 64))
2499 : 958692 : classes[0] = X86_64_SSEHF_CLASS;
2500 : : else
2501 : 2260 : classes[0] = X86_64_SSE_CLASS;
2502 : : return 1;
2503 : 9907470 : case E_SFmode:
2504 : 9907470 : if (!(bit_offset % 64))
2505 : 9854511 : classes[0] = X86_64_SSESF_CLASS;
2506 : : else
2507 : 52959 : classes[0] = X86_64_SSE_CLASS;
2508 : : return 1;
2509 : 4266132 : case E_DFmode:
2510 : 4266132 : classes[0] = X86_64_SSEDF_CLASS;
2511 : 4266132 : return 1;
2512 : 7124548 : case E_XFmode:
2513 : 7124548 : classes[0] = X86_64_X87_CLASS;
2514 : 7124548 : classes[1] = X86_64_X87UP_CLASS;
2515 : 7124548 : return 2;
2516 : 1344159 : case E_TFmode:
2517 : 1344159 : classes[0] = X86_64_SSE_CLASS;
2518 : 1344159 : classes[1] = X86_64_SSEUP_CLASS;
2519 : 1344159 : return 2;
2520 : 137608 : case E_HCmode:
2521 : 137608 : case E_BCmode:
2522 : 137608 : classes[0] = X86_64_SSE_CLASS;
2523 : 137608 : if (!(bit_offset % 64))
2524 : : return 1;
2525 : : else
2526 : : {
2527 : 98 : classes[1] = X86_64_SSEHF_CLASS;
2528 : 98 : return 2;
2529 : : }
2530 : 724247 : case E_SCmode:
2531 : 724247 : classes[0] = X86_64_SSE_CLASS;
2532 : 724247 : if (!(bit_offset % 64))
2533 : : return 1;
2534 : : else
2535 : : {
2536 : 1041 : static bool warned;
2537 : :
2538 : 1041 : if (!warned && warn_psabi)
2539 : : {
2540 : 1 : warned = true;
2541 : 1 : inform (input_location,
2542 : : "the ABI of passing structure with %<complex float%>"
2543 : : " member has changed in GCC 4.4");
2544 : : }
2545 : 1041 : classes[1] = X86_64_SSESF_CLASS;
2546 : 1041 : return 2;
2547 : : }
2548 : 735466 : case E_DCmode:
2549 : 735466 : classes[0] = X86_64_SSEDF_CLASS;
2550 : 735466 : classes[1] = X86_64_SSEDF_CLASS;
2551 : 735466 : return 2;
2552 : 555315 : case E_XCmode:
2553 : 555315 : classes[0] = X86_64_COMPLEX_X87_CLASS;
2554 : 555315 : return 1;
2555 : : case E_TCmode:
2556 : : /* This modes is larger than 16 bytes. */
2557 : : return 0;
2558 : 24565422 : case E_V8SFmode:
2559 : 24565422 : case E_V8SImode:
2560 : 24565422 : case E_V32QImode:
2561 : 24565422 : case E_V16HFmode:
2562 : 24565422 : case E_V16BFmode:
2563 : 24565422 : case E_V16HImode:
2564 : 24565422 : case E_V4DFmode:
2565 : 24565422 : case E_V4DImode:
2566 : 24565422 : classes[0] = X86_64_SSE_CLASS;
2567 : 24565422 : classes[1] = X86_64_SSEUP_CLASS;
2568 : 24565422 : classes[2] = X86_64_SSEUP_CLASS;
2569 : 24565422 : classes[3] = X86_64_SSEUP_CLASS;
2570 : 24565422 : return 4;
2571 : 26664690 : case E_V8DFmode:
2572 : 26664690 : case E_V16SFmode:
2573 : 26664690 : case E_V32HFmode:
2574 : 26664690 : case E_V32BFmode:
2575 : 26664690 : case E_V8DImode:
2576 : 26664690 : case E_V16SImode:
2577 : 26664690 : case E_V32HImode:
2578 : 26664690 : case E_V64QImode:
2579 : 26664690 : classes[0] = X86_64_SSE_CLASS;
2580 : 26664690 : classes[1] = X86_64_SSEUP_CLASS;
2581 : 26664690 : classes[2] = X86_64_SSEUP_CLASS;
2582 : 26664690 : classes[3] = X86_64_SSEUP_CLASS;
2583 : 26664690 : classes[4] = X86_64_SSEUP_CLASS;
2584 : 26664690 : classes[5] = X86_64_SSEUP_CLASS;
2585 : 26664690 : classes[6] = X86_64_SSEUP_CLASS;
2586 : 26664690 : classes[7] = X86_64_SSEUP_CLASS;
2587 : 26664690 : return 8;
2588 : 36203280 : case E_V4SFmode:
2589 : 36203280 : case E_V4SImode:
2590 : 36203280 : case E_V16QImode:
2591 : 36203280 : case E_V8HImode:
2592 : 36203280 : case E_V8HFmode:
2593 : 36203280 : case E_V8BFmode:
2594 : 36203280 : case E_V2DFmode:
2595 : 36203280 : case E_V2DImode:
2596 : 36203280 : classes[0] = X86_64_SSE_CLASS;
2597 : 36203280 : classes[1] = X86_64_SSEUP_CLASS;
2598 : 36203280 : return 2;
2599 : 3181936 : case E_V1TImode:
2600 : 3181936 : case E_V1DImode:
2601 : 3181936 : case E_V2SFmode:
2602 : 3181936 : case E_V2SImode:
2603 : 3181936 : case E_V4HImode:
2604 : 3181936 : case E_V4HFmode:
2605 : 3181936 : case E_V4BFmode:
2606 : 3181936 : case E_V2HFmode:
2607 : 3181936 : case E_V2BFmode:
2608 : 3181936 : case E_V8QImode:
2609 : 3181936 : classes[0] = X86_64_SSE_CLASS;
2610 : 3181936 : return 1;
2611 : : case E_BLKmode:
2612 : : case E_VOIDmode:
2613 : : return 0;
2614 : 37178 : default:
2615 : 37178 : gcc_assert (VECTOR_MODE_P (mode));
2616 : :
2617 : 37178 : if (bytes > 16)
2618 : : return 0;
2619 : :
2620 : 45432 : gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
2621 : :
2622 : 45432 : if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
2623 : 22276 : classes[0] = X86_64_INTEGERSI_CLASS;
2624 : : else
2625 : 440 : classes[0] = X86_64_INTEGER_CLASS;
2626 : 22716 : classes[1] = X86_64_INTEGER_CLASS;
2627 : 22716 : return 1 + (bytes > 8);
2628 : : }
2629 : : }
2630 : :
2631 : : /* Wrapper around classify_argument with the extra zero_width_bitfields
2632 : : argument, to diagnose GCC 12.1 ABI differences for C. */
2633 : :
2634 : : static int
2635 : 315959271 : classify_argument (machine_mode mode, const_tree type,
2636 : : enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
2637 : : {
2638 : 315959271 : int zero_width_bitfields = 0;
2639 : 315959271 : static bool warned = false;
2640 : 315959271 : int n = classify_argument (mode, type, classes, bit_offset,
2641 : : zero_width_bitfields);
2642 : 315959271 : if (!zero_width_bitfields || warned || !warn_psabi)
2643 : : return n;
2644 : 534 : enum x86_64_reg_class alt_classes[MAX_CLASSES];
2645 : 534 : zero_width_bitfields = 2;
2646 : 534 : if (classify_argument (mode, type, alt_classes, bit_offset,
2647 : : zero_width_bitfields) != n)
2648 : 0 : zero_width_bitfields = 3;
2649 : : else
2650 : 1286 : for (int i = 0; i < n; i++)
2651 : 760 : if (classes[i] != alt_classes[i])
2652 : : {
2653 : 8 : zero_width_bitfields = 3;
2654 : 8 : break;
2655 : : }
2656 : 534 : if (zero_width_bitfields == 3)
2657 : : {
2658 : 8 : warned = true;
2659 : 8 : const char *url
2660 : : = CHANGES_ROOT_URL "gcc-12/changes.html#zero_width_bitfields";
2661 : :
2662 : 8 : inform (input_location,
2663 : : "the ABI of passing C structures with zero-width bit-fields"
2664 : : " has changed in GCC %{12.1%}", url);
2665 : : }
2666 : : return n;
2667 : : }
2668 : :
2669 : : /* Examine the argument and return set number of register required in each
2670 : : class. Return true iff parameter should be passed in memory. */
2671 : :
2672 : : static bool
2673 : 212503103 : examine_argument (machine_mode mode, const_tree type, int in_return,
2674 : : int *int_nregs, int *sse_nregs)
2675 : : {
2676 : 212503103 : enum x86_64_reg_class regclass[MAX_CLASSES];
2677 : 212503103 : int n = classify_argument (mode, type, regclass, 0);
2678 : :
2679 : 212503103 : *int_nregs = 0;
2680 : 212503103 : *sse_nregs = 0;
2681 : :
2682 : 212503103 : if (!n)
2683 : : return true;
2684 : 626766791 : for (n--; n >= 0; n--)
2685 : 418495655 : switch (regclass[n])
2686 : : {
2687 : 137773507 : case X86_64_INTEGER_CLASS:
2688 : 137773507 : case X86_64_INTEGERSI_CLASS:
2689 : 137773507 : (*int_nregs)++;
2690 : 137773507 : break;
2691 : 72716848 : case X86_64_SSE_CLASS:
2692 : 72716848 : case X86_64_SSEHF_CLASS:
2693 : 72716848 : case X86_64_SSESF_CLASS:
2694 : 72716848 : case X86_64_SSEDF_CLASS:
2695 : 72716848 : (*sse_nregs)++;
2696 : 72716848 : break;
2697 : : case X86_64_NO_CLASS:
2698 : : case X86_64_SSEUP_CLASS:
2699 : : break;
2700 : 9543956 : case X86_64_X87_CLASS:
2701 : 9543956 : case X86_64_X87UP_CLASS:
2702 : 9543956 : case X86_64_COMPLEX_X87_CLASS:
2703 : 9543956 : if (!in_return)
2704 : : return true;
2705 : : break;
2706 : 0 : case X86_64_MEMORY_CLASS:
2707 : 0 : gcc_unreachable ();
2708 : : }
2709 : :
2710 : : return false;
2711 : : }
2712 : :
2713 : : /* Construct container for the argument used by GCC interface. See
2714 : : FUNCTION_ARG for the detailed description. */
2715 : :
2716 : : static rtx
2717 : 103456168 : construct_container (machine_mode mode, machine_mode orig_mode,
2718 : : const_tree type, int in_return, int nintregs, int nsseregs,
2719 : : const int *intreg, int sse_regno)
2720 : : {
2721 : : /* The following variables hold the static issued_error state. */
2722 : 103456168 : static bool issued_sse_arg_error;
2723 : 103456168 : static bool issued_sse_ret_error;
2724 : 103456168 : static bool issued_x87_ret_error;
2725 : :
2726 : 103456168 : machine_mode tmpmode;
2727 : 103456168 : int bytes
2728 : 206299515 : = mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
2729 : 103456168 : enum x86_64_reg_class regclass[MAX_CLASSES];
2730 : 103456168 : int n;
2731 : 103456168 : int i;
2732 : 103456168 : int nexps = 0;
2733 : 103456168 : int needed_sseregs, needed_intregs;
2734 : 103456168 : rtx exp[MAX_CLASSES];
2735 : 103456168 : rtx ret;
2736 : :
2737 : 103456168 : n = classify_argument (mode, type, regclass, 0);
2738 : 103456168 : if (!n)
2739 : : return NULL;
2740 : 103009502 : if (examine_argument (mode, type, in_return, &needed_intregs,
2741 : : &needed_sseregs))
2742 : : return NULL;
2743 : 102961414 : if (needed_intregs > nintregs || needed_sseregs > nsseregs)
2744 : : return NULL;
2745 : :
2746 : : /* We allowed the user to turn off SSE for kernel mode. Don't crash if
2747 : : some less clueful developer tries to use floating-point anyway. */
2748 : 101868034 : if (needed_sseregs
2749 : 35914063 : && (!TARGET_SSE || (VALID_SSE2_TYPE_MODE (mode) && !TARGET_SSE2)))
2750 : : {
2751 : : /* Return early if we shouldn't raise an error for invalid
2752 : : calls. */
2753 : 71 : if (cfun != NULL && cfun->machine->silent_p)
2754 : : return NULL;
2755 : 39 : if (in_return)
2756 : : {
2757 : 34 : if (!issued_sse_ret_error)
2758 : : {
2759 : 16 : if (VALID_SSE2_TYPE_MODE (mode))
2760 : 5 : error ("SSE register return with SSE2 disabled");
2761 : : else
2762 : 11 : error ("SSE register return with SSE disabled");
2763 : 16 : issued_sse_ret_error = true;
2764 : : }
2765 : : }
2766 : 5 : else if (!issued_sse_arg_error)
2767 : : {
2768 : 5 : if (VALID_SSE2_TYPE_MODE (mode))
2769 : 0 : error ("SSE register argument with SSE2 disabled");
2770 : : else
2771 : 5 : error ("SSE register argument with SSE disabled");
2772 : 5 : issued_sse_arg_error = true;
2773 : : }
2774 : 39 : return NULL;
2775 : : }
2776 : :
2777 : : /* Likewise, error if the ABI requires us to return values in the
2778 : : x87 registers and the user specified -mno-80387. */
2779 : 101867963 : if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return)
2780 : 1389093 : for (i = 0; i < n; i++)
2781 : 734051 : if (regclass[i] == X86_64_X87_CLASS
2782 : : || regclass[i] == X86_64_X87UP_CLASS
2783 : 734051 : || regclass[i] == X86_64_COMPLEX_X87_CLASS)
2784 : : {
2785 : : /* Return early if we shouldn't raise an error for invalid
2786 : : calls. */
2787 : 14 : if (cfun != NULL && cfun->machine->silent_p)
2788 : : return NULL;
2789 : 11 : if (!issued_x87_ret_error)
2790 : : {
2791 : 6 : error ("x87 register return with x87 disabled");
2792 : 6 : issued_x87_ret_error = true;
2793 : : }
2794 : 11 : return NULL;
2795 : : }
2796 : :
2797 : : /* First construct simple cases. Avoid SCmode, since we want to use
2798 : : single register to pass this type. */
2799 : 101867949 : if (n == 1 && mode != SCmode && mode != HCmode)
2800 : 66161975 : switch (regclass[0])
2801 : : {
2802 : 60088463 : case X86_64_INTEGER_CLASS:
2803 : 60088463 : case X86_64_INTEGERSI_CLASS:
2804 : 60088463 : return gen_rtx_REG (mode, intreg[0]);
2805 : 5874526 : case X86_64_SSE_CLASS:
2806 : 5874526 : case X86_64_SSEHF_CLASS:
2807 : 5874526 : case X86_64_SSESF_CLASS:
2808 : 5874526 : case X86_64_SSEDF_CLASS:
2809 : 5874526 : if (mode != BLKmode)
2810 : 11748244 : return gen_reg_or_parallel (mode, orig_mode,
2811 : 11748244 : GET_SSE_REGNO (sse_regno));
2812 : : break;
2813 : 171735 : case X86_64_X87_CLASS:
2814 : 171735 : case X86_64_COMPLEX_X87_CLASS:
2815 : 171735 : return gen_rtx_REG (mode, FIRST_STACK_REG);
2816 : : case X86_64_NO_CLASS:
2817 : : /* Zero sized array, struct or class. */
2818 : : return NULL;
2819 : 0 : default:
2820 : 0 : gcc_unreachable ();
2821 : : }
2822 : 35706378 : if (n == 2
2823 : 18417188 : && regclass[0] == X86_64_SSE_CLASS
2824 : 12491001 : && regclass[1] == X86_64_SSEUP_CLASS
2825 : 12486265 : && mode != BLKmode)
2826 : 24972530 : return gen_reg_or_parallel (mode, orig_mode,
2827 : 24972530 : GET_SSE_REGNO (sse_regno));
2828 : 23220113 : if (n == 4
2829 : 8172452 : && regclass[0] == X86_64_SSE_CLASS
2830 : 8172452 : && regclass[1] == X86_64_SSEUP_CLASS
2831 : 8172452 : && regclass[2] == X86_64_SSEUP_CLASS
2832 : 8172452 : && regclass[3] == X86_64_SSEUP_CLASS
2833 : 8172452 : && mode != BLKmode)
2834 : 16341526 : return gen_reg_or_parallel (mode, orig_mode,
2835 : 16341526 : GET_SSE_REGNO (sse_regno));
2836 : 15049350 : if (n == 8
2837 : 8858125 : && regclass[0] == X86_64_SSE_CLASS
2838 : 8858125 : && regclass[1] == X86_64_SSEUP_CLASS
2839 : 8858125 : && regclass[2] == X86_64_SSEUP_CLASS
2840 : 8858125 : && regclass[3] == X86_64_SSEUP_CLASS
2841 : 8858125 : && regclass[4] == X86_64_SSEUP_CLASS
2842 : 8858125 : && regclass[5] == X86_64_SSEUP_CLASS
2843 : 8858125 : && regclass[6] == X86_64_SSEUP_CLASS
2844 : 8858125 : && regclass[7] == X86_64_SSEUP_CLASS
2845 : 8858125 : && mode != BLKmode)
2846 : 17711978 : return gen_reg_or_parallel (mode, orig_mode,
2847 : 17711978 : GET_SSE_REGNO (sse_regno));
2848 : 6193361 : if (n == 2
2849 : 5930923 : && regclass[0] == X86_64_X87_CLASS
2850 : 2280611 : && regclass[1] == X86_64_X87UP_CLASS)
2851 : 2280611 : return gen_rtx_REG (XFmode, FIRST_STACK_REG);
2852 : :
2853 : 3912750 : if (n == 2
2854 : 3650312 : && regclass[0] == X86_64_INTEGER_CLASS
2855 : 3268927 : && regclass[1] == X86_64_INTEGER_CLASS
2856 : 3260693 : && (mode == CDImode || mode == TImode || mode == BLKmode)
2857 : 3260693 : && intreg[0] + 1 == intreg[1])
2858 : : {
2859 : 2937151 : if (mode == BLKmode)
2860 : : {
2861 : : /* Use TImode for BLKmode values in 2 integer registers. */
2862 : 560284 : exp[0] = gen_rtx_EXPR_LIST (VOIDmode,
2863 : 280142 : gen_rtx_REG (TImode, intreg[0]),
2864 : : GEN_INT (0));
2865 : 280142 : ret = gen_rtx_PARALLEL (mode, rtvec_alloc (1));
2866 : 280142 : XVECEXP (ret, 0, 0) = exp[0];
2867 : 280142 : return ret;
2868 : : }
2869 : : else
2870 : 2657009 : return gen_rtx_REG (mode, intreg[0]);
2871 : : }
2872 : :
2873 : : /* Otherwise figure out the entries of the PARALLEL. */
2874 : 2664359 : for (i = 0; i < n; i++)
2875 : : {
2876 : 1688760 : int pos;
2877 : :
2878 : 1688760 : switch (regclass[i])
2879 : : {
2880 : : case X86_64_NO_CLASS:
2881 : : break;
2882 : 900971 : case X86_64_INTEGER_CLASS:
2883 : 900971 : case X86_64_INTEGERSI_CLASS:
2884 : : /* Merge TImodes on aligned occasions here too. */
2885 : 900971 : if (i * 8 + 8 > bytes)
2886 : : {
2887 : 3217 : unsigned int tmpbits = (bytes - i * 8) * BITS_PER_UNIT;
2888 : 3217 : if (!int_mode_for_size (tmpbits, 0).exists (&tmpmode))
2889 : : /* We've requested 24 bytes we
2890 : : don't have mode for. Use DImode. */
2891 : 358 : tmpmode = DImode;
2892 : : }
2893 : 897754 : else if (regclass[i] == X86_64_INTEGERSI_CLASS)
2894 : : tmpmode = SImode;
2895 : : else
2896 : 776323 : tmpmode = DImode;
2897 : 1801942 : exp [nexps++]
2898 : 900971 : = gen_rtx_EXPR_LIST (VOIDmode,
2899 : 900971 : gen_rtx_REG (tmpmode, *intreg),
2900 : 900971 : GEN_INT (i*8));
2901 : 900971 : intreg++;
2902 : 900971 : break;
2903 : 592 : case X86_64_SSEHF_CLASS:
2904 : 592 : tmpmode = (mode == BFmode ? BFmode : HFmode);
2905 : 1184 : exp [nexps++]
2906 : 1184 : = gen_rtx_EXPR_LIST (VOIDmode,
2907 : : gen_rtx_REG (tmpmode,
2908 : 592 : GET_SSE_REGNO (sse_regno)),
2909 : 592 : GEN_INT (i*8));
2910 : 592 : sse_regno++;
2911 : 592 : break;
2912 : 2937 : case X86_64_SSESF_CLASS:
2913 : 5874 : exp [nexps++]
2914 : 5874 : = gen_rtx_EXPR_LIST (VOIDmode,
2915 : : gen_rtx_REG (SFmode,
2916 : 2937 : GET_SSE_REGNO (sse_regno)),
2917 : 2937 : GEN_INT (i*8));
2918 : 2937 : sse_regno++;
2919 : 2937 : break;
2920 : 504642 : case X86_64_SSEDF_CLASS:
2921 : 1009284 : exp [nexps++]
2922 : 1009284 : = gen_rtx_EXPR_LIST (VOIDmode,
2923 : : gen_rtx_REG (DFmode,
2924 : 504642 : GET_SSE_REGNO (sse_regno)),
2925 : 504642 : GEN_INT (i*8));
2926 : 504642 : sse_regno++;
2927 : 504642 : break;
2928 : 271538 : case X86_64_SSE_CLASS:
2929 : 271538 : pos = i;
2930 : 271538 : switch (n)
2931 : : {
2932 : : case 1:
2933 : : tmpmode = DImode;
2934 : : break;
2935 : 9314 : case 2:
2936 : 9314 : if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
2937 : : {
2938 : 0 : tmpmode = TImode;
2939 : 0 : i++;
2940 : : }
2941 : : else
2942 : : tmpmode = DImode;
2943 : : break;
2944 : 1689 : case 4:
2945 : 1689 : gcc_assert (i == 0
2946 : : && regclass[1] == X86_64_SSEUP_CLASS
2947 : : && regclass[2] == X86_64_SSEUP_CLASS
2948 : : && regclass[3] == X86_64_SSEUP_CLASS);
2949 : : tmpmode = OImode;
2950 : : i += 3;
2951 : : break;
2952 : 2136 : case 8:
2953 : 2136 : gcc_assert (i == 0
2954 : : && regclass[1] == X86_64_SSEUP_CLASS
2955 : : && regclass[2] == X86_64_SSEUP_CLASS
2956 : : && regclass[3] == X86_64_SSEUP_CLASS
2957 : : && regclass[4] == X86_64_SSEUP_CLASS
2958 : : && regclass[5] == X86_64_SSEUP_CLASS
2959 : : && regclass[6] == X86_64_SSEUP_CLASS
2960 : : && regclass[7] == X86_64_SSEUP_CLASS);
2961 : : tmpmode = XImode;
2962 : : i += 7;
2963 : : break;
2964 : 0 : default:
2965 : 0 : gcc_unreachable ();
2966 : : }
2967 : 543076 : exp [nexps++]
2968 : 543076 : = gen_rtx_EXPR_LIST (VOIDmode,
2969 : : gen_rtx_REG (tmpmode,
2970 : 271538 : GET_SSE_REGNO (sse_regno)),
2971 : 271538 : GEN_INT (pos*8));
2972 : 271538 : sse_regno++;
2973 : 271538 : break;
2974 : 0 : default:
2975 : 0 : gcc_unreachable ();
2976 : : }
2977 : : }
2978 : :
2979 : : /* Empty aligned struct, union or class. */
2980 : 975599 : if (nexps == 0)
2981 : : return NULL;
2982 : :
2983 : 975344 : ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
2984 : 2656024 : for (i = 0; i < nexps; i++)
2985 : 1680680 : XVECEXP (ret, 0, i) = exp [i];
2986 : : return ret;
2987 : : }
2988 : :
2989 : : /* Update the data in CUM to advance over an argument of mode MODE
2990 : : and data type TYPE. (TYPE is null for libcalls where that information
2991 : : may not be available.)
2992 : :
2993 : : Return a number of integer regsiters advanced over. */
2994 : :
2995 : : static int
2996 : 2098087 : function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
2997 : : const_tree type, HOST_WIDE_INT bytes,
2998 : : HOST_WIDE_INT words)
2999 : : {
3000 : 2098087 : int res = 0;
3001 : 2098087 : bool error_p = false;
3002 : :
3003 : 2098087 : if (TARGET_IAMCU)
3004 : : {
3005 : : /* Intel MCU psABI passes scalars and aggregates no larger than 8
3006 : : bytes in registers. */
3007 : 0 : if (!VECTOR_MODE_P (mode) && bytes <= 8)
3008 : 0 : goto pass_in_reg;
3009 : : return res;
3010 : : }
3011 : :
3012 : 2098087 : switch (mode)
3013 : : {
3014 : : default:
3015 : : break;
3016 : :
3017 : 93650 : case E_BLKmode:
3018 : 93650 : if (bytes < 0)
3019 : : break;
3020 : : /* FALLTHRU */
3021 : :
3022 : 2061551 : case E_DImode:
3023 : 2061551 : case E_SImode:
3024 : 2061551 : case E_HImode:
3025 : 2061551 : case E_QImode:
3026 : 93650 : pass_in_reg:
3027 : 2061551 : cum->words += words;
3028 : 2061551 : cum->nregs -= words;
3029 : 2061551 : cum->regno += words;
3030 : 2061551 : if (cum->nregs >= 0)
3031 : 45659 : res = words;
3032 : 2061551 : if (cum->nregs <= 0)
3033 : : {
3034 : 2028774 : cum->nregs = 0;
3035 : 2028774 : cfun->machine->arg_reg_available = false;
3036 : 2028774 : cum->regno = 0;
3037 : : }
3038 : : break;
3039 : :
3040 : 0 : case E_OImode:
3041 : : /* OImode shouldn't be used directly. */
3042 : 0 : gcc_unreachable ();
3043 : :
3044 : 4679 : case E_DFmode:
3045 : 4679 : if (cum->float_in_sse == -1)
3046 : 0 : error_p = true;
3047 : 4679 : if (cum->float_in_sse < 2)
3048 : : break;
3049 : : /* FALLTHRU */
3050 : 1349 : case E_SFmode:
3051 : 1349 : if (cum->float_in_sse == -1)
3052 : 0 : error_p = true;
3053 : 1349 : if (cum->float_in_sse < 1)
3054 : : break;
3055 : : /* FALLTHRU */
3056 : :
3057 : 52 : case E_V16HFmode:
3058 : 52 : case E_V16BFmode:
3059 : 52 : case E_V8SFmode:
3060 : 52 : case E_V8SImode:
3061 : 52 : case E_V64QImode:
3062 : 52 : case E_V32HImode:
3063 : 52 : case E_V16SImode:
3064 : 52 : case E_V8DImode:
3065 : 52 : case E_V32HFmode:
3066 : 52 : case E_V32BFmode:
3067 : 52 : case E_V16SFmode:
3068 : 52 : case E_V8DFmode:
3069 : 52 : case E_V32QImode:
3070 : 52 : case E_V16HImode:
3071 : 52 : case E_V4DFmode:
3072 : 52 : case E_V4DImode:
3073 : 52 : case E_TImode:
3074 : 52 : case E_V16QImode:
3075 : 52 : case E_V8HImode:
3076 : 52 : case E_V4SImode:
3077 : 52 : case E_V2DImode:
3078 : 52 : case E_V8HFmode:
3079 : 52 : case E_V8BFmode:
3080 : 52 : case E_V4SFmode:
3081 : 52 : case E_V2DFmode:
3082 : 52 : if (!type || !AGGREGATE_TYPE_P (type))
3083 : : {
3084 : 52 : cum->sse_words += words;
3085 : 52 : cum->sse_nregs -= 1;
3086 : 52 : cum->sse_regno += 1;
3087 : 52 : if (cum->sse_nregs <= 0)
3088 : : {
3089 : 4 : cum->sse_nregs = 0;
3090 : 4 : cum->sse_regno = 0;
3091 : : }
3092 : : }
3093 : : break;
3094 : :
3095 : 12 : case E_V8QImode:
3096 : 12 : case E_V4HImode:
3097 : 12 : case E_V4HFmode:
3098 : 12 : case E_V4BFmode:
3099 : 12 : case E_V2SImode:
3100 : 12 : case E_V2SFmode:
3101 : 12 : case E_V1TImode:
3102 : 12 : case E_V1DImode:
3103 : 12 : if (!type || !AGGREGATE_TYPE_P (type))
3104 : : {
3105 : 12 : cum->mmx_words += words;
3106 : 12 : cum->mmx_nregs -= 1;
3107 : 12 : cum->mmx_regno += 1;
3108 : 12 : if (cum->mmx_nregs <= 0)
3109 : : {
3110 : 0 : cum->mmx_nregs = 0;
3111 : 0 : cum->mmx_regno = 0;
3112 : : }
3113 : : }
3114 : : break;
3115 : : }
3116 : 2034854 : if (error_p)
3117 : : {
3118 : 0 : cum->float_in_sse = 0;
3119 : 0 : error ("calling %qD with SSE calling convention without "
3120 : : "SSE/SSE2 enabled", cum->decl);
3121 : 0 : sorry ("this is a GCC bug that can be worked around by adding "
3122 : : "attribute used to function called");
3123 : : }
3124 : :
3125 : : return res;
3126 : : }
3127 : :
3128 : : static int
3129 : 18787690 : function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode,
3130 : : const_tree type, HOST_WIDE_INT words, bool named)
3131 : : {
3132 : 18787690 : int int_nregs, sse_nregs;
3133 : :
3134 : : /* Unnamed 512 and 256bit vector mode parameters are passed on stack. */
3135 : 18787690 : if (!named && (VALID_AVX512F_REG_MODE (mode)
3136 : : || VALID_AVX256_REG_MODE (mode)))
3137 : : return 0;
3138 : :
3139 : 18787326 : if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
3140 : 18787326 : && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
3141 : : {
3142 : 16532164 : cum->nregs -= int_nregs;
3143 : 16532164 : cum->sse_nregs -= sse_nregs;
3144 : 16532164 : cum->regno += int_nregs;
3145 : 16532164 : cum->sse_regno += sse_nregs;
3146 : 16532164 : return int_nregs;
3147 : : }
3148 : : else
3149 : : {
3150 : 2255162 : int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
3151 : 2255162 : cum->words = ROUND_UP (cum->words, align);
3152 : 2255162 : cum->words += words;
3153 : 2255162 : return 0;
3154 : : }
3155 : : }
3156 : :
3157 : : static int
3158 : 446969 : function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
3159 : : HOST_WIDE_INT words)
3160 : : {
3161 : : /* Otherwise, this should be passed indirect. */
3162 : 446969 : gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
3163 : :
3164 : 446969 : cum->words += words;
3165 : 446969 : if (cum->nregs > 0)
3166 : : {
3167 : 289335 : cum->nregs -= 1;
3168 : 289335 : cum->regno += 1;
3169 : 289335 : return 1;
3170 : : }
3171 : : return 0;
3172 : : }
3173 : :
3174 : : /* Update the data in CUM to advance over argument ARG. */
3175 : :
3176 : : static void
3177 : 21333100 : ix86_function_arg_advance (cumulative_args_t cum_v,
3178 : : const function_arg_info &arg)
3179 : : {
3180 : 21333100 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
3181 : 21333100 : machine_mode mode = arg.mode;
3182 : 21333100 : HOST_WIDE_INT bytes, words;
3183 : 21333100 : int nregs;
3184 : :
3185 : : /* The argument of interrupt handler is a special case and is
3186 : : handled in ix86_function_arg. */
3187 : 21333100 : if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL)
3188 : : return;
3189 : :
3190 : 21332746 : bytes = arg.promoted_size_in_bytes ();
3191 : 21332746 : words = CEIL (bytes, UNITS_PER_WORD);
3192 : :
3193 : 21332746 : if (arg.type)
3194 : 21053950 : mode = type_natural_mode (arg.type, NULL, false);
3195 : :
3196 : 21332746 : if (TARGET_64BIT)
3197 : : {
3198 : 19234659 : enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
3199 : :
3200 : 19234659 : if (call_abi == MS_ABI)
3201 : 446969 : nregs = function_arg_advance_ms_64 (cum, bytes, words);
3202 : : else
3203 : 18787690 : nregs = function_arg_advance_64 (cum, mode, arg.type, words,
3204 : 18787690 : arg.named);
3205 : : }
3206 : : else
3207 : 2098087 : nregs = function_arg_advance_32 (cum, mode, arg.type, bytes, words);
3208 : :
3209 : 21332746 : if (!nregs)
3210 : : {
3211 : : /* Track if there are outgoing arguments on stack. */
3212 : 5637784 : if (cum->caller)
3213 : 2687645 : cfun->machine->outgoing_args_on_stack = true;
3214 : : }
3215 : : }
3216 : :
3217 : : /* Define where to put the arguments to a function.
3218 : : Value is zero to push the argument on the stack,
3219 : : or a hard register in which to store the argument.
3220 : :
3221 : : MODE is the argument's machine mode.
3222 : : TYPE is the data type of the argument (as a tree).
3223 : : This is null for libcalls where that information may
3224 : : not be available.
3225 : : CUM is a variable of type CUMULATIVE_ARGS which gives info about
3226 : : the preceding args and about the function being called.
3227 : : NAMED is nonzero if this argument is a named parameter
3228 : : (otherwise it is an extra parameter matching an ellipsis). */
3229 : :
3230 : : static rtx
3231 : 2522021 : function_arg_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
3232 : : machine_mode orig_mode, const_tree type,
3233 : : HOST_WIDE_INT bytes, HOST_WIDE_INT words)
3234 : : {
3235 : 2522021 : bool error_p = false;
3236 : :
3237 : : /* Avoid the AL settings for the Unix64 ABI. */
3238 : 2522021 : if (mode == VOIDmode)
3239 : 733470 : return constm1_rtx;
3240 : :
3241 : 1788551 : if (TARGET_IAMCU)
3242 : : {
3243 : : /* Intel MCU psABI passes scalars and aggregates no larger than 8
3244 : : bytes in registers. */
3245 : 0 : if (!VECTOR_MODE_P (mode) && bytes <= 8)
3246 : 0 : goto pass_in_reg;
3247 : : return NULL_RTX;
3248 : : }
3249 : :
3250 : 1788551 : switch (mode)
3251 : : {
3252 : : default:
3253 : : break;
3254 : :
3255 : 77680 : case E_BLKmode:
3256 : 77680 : if (bytes < 0)
3257 : : break;
3258 : : /* FALLTHRU */
3259 : 1755266 : case E_DImode:
3260 : 1755266 : case E_SImode:
3261 : 1755266 : case E_HImode:
3262 : 1755266 : case E_QImode:
3263 : 77680 : pass_in_reg:
3264 : 1755266 : if (words <= cum->nregs)
3265 : : {
3266 : 43827 : int regno = cum->regno;
3267 : :
3268 : : /* Fastcall allocates the first two DWORD (SImode) or
3269 : : smaller arguments to ECX and EDX if it isn't an
3270 : : aggregate type . */
3271 : 43827 : if (cum->fastcall)
3272 : : {
3273 : 6 : if (mode == BLKmode
3274 : 6 : || mode == DImode
3275 : 6 : || (type && AGGREGATE_TYPE_P (type)))
3276 : : break;
3277 : :
3278 : : /* ECX not EAX is the first allocated register. */
3279 : 6 : if (regno == AX_REG)
3280 : 43827 : regno = CX_REG;
3281 : : }
3282 : 43827 : return gen_rtx_REG (mode, regno);
3283 : : }
3284 : : break;
3285 : :
3286 : 3298 : case E_DFmode:
3287 : 3298 : if (cum->float_in_sse == -1)
3288 : 0 : error_p = true;
3289 : 3298 : if (cum->float_in_sse < 2)
3290 : : break;
3291 : : /* FALLTHRU */
3292 : 958 : case E_SFmode:
3293 : 958 : if (cum->float_in_sse == -1)
3294 : 0 : error_p = true;
3295 : 958 : if (cum->float_in_sse < 1)
3296 : : break;
3297 : : /* FALLTHRU */
3298 : 12 : case E_TImode:
3299 : : /* In 32bit, we pass TImode in xmm registers. */
3300 : 12 : case E_V16QImode:
3301 : 12 : case E_V8HImode:
3302 : 12 : case E_V4SImode:
3303 : 12 : case E_V2DImode:
3304 : 12 : case E_V8HFmode:
3305 : 12 : case E_V8BFmode:
3306 : 12 : case E_V4SFmode:
3307 : 12 : case E_V2DFmode:
3308 : 12 : if (!type || !AGGREGATE_TYPE_P (type))
3309 : : {
3310 : 12 : if (cum->sse_nregs)
3311 : 12 : return gen_reg_or_parallel (mode, orig_mode,
3312 : 12 : cum->sse_regno + FIRST_SSE_REG);
3313 : : }
3314 : : break;
3315 : :
3316 : 0 : case E_OImode:
3317 : 0 : case E_XImode:
3318 : : /* OImode and XImode shouldn't be used directly. */
3319 : 0 : gcc_unreachable ();
3320 : :
3321 : 9 : case E_V64QImode:
3322 : 9 : case E_V32HImode:
3323 : 9 : case E_V16SImode:
3324 : 9 : case E_V8DImode:
3325 : 9 : case E_V32HFmode:
3326 : 9 : case E_V32BFmode:
3327 : 9 : case E_V16SFmode:
3328 : 9 : case E_V8DFmode:
3329 : 9 : case E_V16HFmode:
3330 : 9 : case E_V16BFmode:
3331 : 9 : case E_V8SFmode:
3332 : 9 : case E_V8SImode:
3333 : 9 : case E_V32QImode:
3334 : 9 : case E_V16HImode:
3335 : 9 : case E_V4DFmode:
3336 : 9 : case E_V4DImode:
3337 : 9 : if (!type || !AGGREGATE_TYPE_P (type))
3338 : : {
3339 : 9 : if (cum->sse_nregs)
3340 : 9 : return gen_reg_or_parallel (mode, orig_mode,
3341 : 9 : cum->sse_regno + FIRST_SSE_REG);
3342 : : }
3343 : : break;
3344 : :
3345 : 6 : case E_V8QImode:
3346 : 6 : case E_V4HImode:
3347 : 6 : case E_V4HFmode:
3348 : 6 : case E_V4BFmode:
3349 : 6 : case E_V2SImode:
3350 : 6 : case E_V2SFmode:
3351 : 6 : case E_V1TImode:
3352 : 6 : case E_V1DImode:
3353 : 6 : if (!type || !AGGREGATE_TYPE_P (type))
3354 : : {
3355 : 6 : if (cum->mmx_nregs)
3356 : 6 : return gen_reg_or_parallel (mode, orig_mode,
3357 : 6 : cum->mmx_regno + FIRST_MMX_REG);
3358 : : }
3359 : : break;
3360 : : }
3361 : 4256 : if (error_p)
3362 : : {
3363 : 0 : cum->float_in_sse = 0;
3364 : 0 : error ("calling %qD with SSE calling convention without "
3365 : : "SSE/SSE2 enabled", cum->decl);
3366 : 0 : sorry ("this is a GCC bug that can be worked around by adding "
3367 : : "attribute used to function called");
3368 : : }
3369 : :
3370 : : return NULL_RTX;
3371 : : }
3372 : :
3373 : : static rtx
3374 : 18509724 : function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
3375 : : machine_mode orig_mode, const_tree type, bool named)
3376 : : {
3377 : : /* Handle a hidden AL argument containing number of registers
3378 : : for varargs x86-64 functions. */
3379 : 18509724 : if (mode == VOIDmode)
3380 : 5102212 : return GEN_INT (cum->maybe_vaarg
3381 : : ? (cum->sse_nregs < 0
3382 : : ? X86_64_SSE_REGPARM_MAX
3383 : : : cum->sse_regno)
3384 : : : -1);
3385 : :
3386 : 13407512 : switch (mode)
3387 : : {
3388 : : default:
3389 : : break;
3390 : :
3391 : 89677 : case E_V16HFmode:
3392 : 89677 : case E_V16BFmode:
3393 : 89677 : case E_V8SFmode:
3394 : 89677 : case E_V8SImode:
3395 : 89677 : case E_V32QImode:
3396 : 89677 : case E_V16HImode:
3397 : 89677 : case E_V4DFmode:
3398 : 89677 : case E_V4DImode:
3399 : 89677 : case E_V32HFmode:
3400 : 89677 : case E_V32BFmode:
3401 : 89677 : case E_V16SFmode:
3402 : 89677 : case E_V16SImode:
3403 : 89677 : case E_V64QImode:
3404 : 89677 : case E_V32HImode:
3405 : 89677 : case E_V8DFmode:
3406 : 89677 : case E_V8DImode:
3407 : : /* Unnamed 256 and 512bit vector mode parameters are passed on stack. */
3408 : 89677 : if (!named)
3409 : : return NULL;
3410 : : break;
3411 : : }
3412 : :
3413 : 13407148 : return construct_container (mode, orig_mode, type, 0, cum->nregs,
3414 : 13407148 : cum->sse_nregs,
3415 : 13407148 : &x86_64_int_parameter_registers [cum->regno],
3416 : 13407148 : cum->sse_regno);
3417 : : }
3418 : :
3419 : : static rtx
3420 : 296328 : function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
3421 : : machine_mode orig_mode, bool named, const_tree type,
3422 : : HOST_WIDE_INT bytes)
3423 : : {
3424 : 296328 : unsigned int regno;
3425 : :
3426 : : /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
3427 : : We use value of -2 to specify that current function call is MSABI. */
3428 : 296328 : if (mode == VOIDmode)
3429 : 36293 : return GEN_INT (-2);
3430 : :
3431 : : /* If we've run out of registers, it goes on the stack. */
3432 : 260035 : if (cum->nregs == 0)
3433 : : return NULL_RTX;
3434 : :
3435 : 176280 : regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
3436 : :
3437 : : /* Only floating point modes are passed in anything but integer regs. */
3438 : 176280 : if (TARGET_SSE && (mode == SFmode || mode == DFmode))
3439 : : {
3440 : 38254 : if (named)
3441 : : {
3442 : 38254 : if (type == NULL_TREE || !AGGREGATE_TYPE_P (type))
3443 : 37260 : regno = cum->regno + FIRST_SSE_REG;
3444 : : }
3445 : : else
3446 : : {
3447 : 0 : rtx t1, t2;
3448 : :
3449 : : /* Unnamed floating parameters are passed in both the
3450 : : SSE and integer registers. */
3451 : 0 : t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
3452 : 0 : t2 = gen_rtx_REG (mode, regno);
3453 : 0 : t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
3454 : 0 : t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
3455 : 0 : return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
3456 : : }
3457 : : }
3458 : : /* Handle aggregated types passed in register. */
3459 : 176280 : if (orig_mode == BLKmode)
3460 : : {
3461 : 0 : if (bytes > 0 && bytes <= 8)
3462 : 0 : mode = (bytes > 4 ? DImode : SImode);
3463 : 0 : if (mode == BLKmode)
3464 : 0 : mode = DImode;
3465 : : }
3466 : :
3467 : 176280 : return gen_reg_or_parallel (mode, orig_mode, regno);
3468 : : }
3469 : :
3470 : : /* Return where to put the arguments to a function.
3471 : : Return zero to push the argument on the stack, or a hard register in which to store the argument.
3472 : :
3473 : : ARG describes the argument while CUM gives information about the
3474 : : preceding args and about the function being called. */
3475 : :
3476 : : static rtx
3477 : 21328254 : ix86_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
3478 : : {
3479 : 21328254 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
3480 : 21328254 : machine_mode mode = arg.mode;
3481 : 21328254 : HOST_WIDE_INT bytes, words;
3482 : 21328254 : rtx reg;
3483 : :
3484 : 21328254 : if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL)
3485 : : {
3486 : 181 : gcc_assert (arg.type != NULL_TREE);
3487 : 181 : if (POINTER_TYPE_P (arg.type))
3488 : : {
3489 : : /* This is the pointer argument. */
3490 : 118 : gcc_assert (TYPE_MODE (arg.type) == ptr_mode);
3491 : : /* It is at -WORD(AP) in the current frame in interrupt and
3492 : : exception handlers. */
3493 : 118 : reg = plus_constant (Pmode, arg_pointer_rtx, -UNITS_PER_WORD);
3494 : : }
3495 : : else
3496 : : {
3497 : 63 : gcc_assert (cfun->machine->func_type == TYPE_EXCEPTION
3498 : : && TREE_CODE (arg.type) == INTEGER_TYPE
3499 : : && TYPE_MODE (arg.type) == word_mode);
3500 : : /* The error code is the word-mode integer argument at
3501 : : -2 * WORD(AP) in the current frame of the exception
3502 : : handler. */
3503 : 63 : reg = gen_rtx_MEM (word_mode,
3504 : 63 : plus_constant (Pmode,
3505 : : arg_pointer_rtx,
3506 : 63 : -2 * UNITS_PER_WORD));
3507 : : }
3508 : 181 : return reg;
3509 : : }
3510 : :
3511 : 21328073 : bytes = arg.promoted_size_in_bytes ();
3512 : 21328073 : words = CEIL (bytes, UNITS_PER_WORD);
3513 : :
3514 : : /* To simplify the code below, represent vector types with a vector mode
3515 : : even if MMX/SSE are not active. */
3516 : 21328073 : if (arg.type && VECTOR_TYPE_P (arg.type))
3517 : 169356 : mode = type_natural_mode (arg.type, cum, false);
3518 : :
3519 : 21328073 : if (TARGET_64BIT)
3520 : : {
3521 : 18806052 : enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
3522 : :
3523 : 18806052 : if (call_abi == MS_ABI)
3524 : 296328 : reg = function_arg_ms_64 (cum, mode, arg.mode, arg.named,
3525 : 296328 : arg.type, bytes);
3526 : : else
3527 : 18509724 : reg = function_arg_64 (cum, mode, arg.mode, arg.type, arg.named);
3528 : : }
3529 : : else
3530 : 2522021 : reg = function_arg_32 (cum, mode, arg.mode, arg.type, bytes, words);
3531 : :
3532 : : /* Track if there are outgoing arguments on stack. */
3533 : 21328073 : if (reg == NULL_RTX && cum->caller)
3534 : 2166496 : cfun->machine->outgoing_args_on_stack = true;
3535 : :
3536 : : return reg;
3537 : : }
3538 : :
3539 : : /* A C expression that indicates when an argument must be passed by
3540 : : reference. If nonzero for an argument, a copy of that argument is
3541 : : made in memory and a pointer to the argument is passed instead of
3542 : : the argument itself. The pointer is passed in whatever way is
3543 : : appropriate for passing a pointer to that type. */
3544 : :
3545 : : static bool
3546 : 21289860 : ix86_pass_by_reference (cumulative_args_t cum_v, const function_arg_info &arg)
3547 : : {
3548 : 21289860 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
3549 : :
3550 : 21289860 : if (TARGET_64BIT)
3551 : : {
3552 : 19202014 : enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
3553 : :
3554 : : /* See Windows x64 Software Convention. */
3555 : 19202014 : if (call_abi == MS_ABI)
3556 : : {
3557 : 441370 : HOST_WIDE_INT msize = GET_MODE_SIZE (arg.mode);
3558 : :
3559 : 441370 : if (tree type = arg.type)
3560 : : {
3561 : : /* Arrays are passed by reference. */
3562 : 441370 : if (TREE_CODE (type) == ARRAY_TYPE)
3563 : : return true;
3564 : :
3565 : 441370 : if (RECORD_OR_UNION_TYPE_P (type))
3566 : : {
3567 : : /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
3568 : : are passed by reference. */
3569 : 15022 : msize = int_size_in_bytes (type);
3570 : : }
3571 : : }
3572 : :
3573 : : /* __m128 is passed by reference. */
3574 : 872811 : return msize != 1 && msize != 2 && msize != 4 && msize != 8;
3575 : : }
3576 : 18760644 : else if (arg.type && int_size_in_bytes (arg.type) == -1)
3577 : : return true;
3578 : : }
3579 : :
3580 : : return false;
3581 : : }
3582 : :
3583 : : /* Return true when TYPE should be 128bit aligned for 32bit argument
3584 : : passing ABI. XXX: This function is obsolete and is only used for
3585 : : checking psABI compatibility with previous versions of GCC. */
3586 : :
3587 : : static bool
3588 : 1950440 : ix86_compat_aligned_value_p (const_tree type)
3589 : : {
3590 : 1950440 : machine_mode mode = TYPE_MODE (type);
3591 : 1950440 : if (((TARGET_SSE && SSE_REG_MODE_P (mode))
3592 : 1950398 : || mode == TDmode
3593 : 1950398 : || mode == TFmode
3594 : : || mode == TCmode)
3595 : 1950652 : && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
3596 : : return true;
3597 : 1950228 : if (TYPE_ALIGN (type) < 128)
3598 : : return false;
3599 : :
3600 : 0 : if (AGGREGATE_TYPE_P (type))
3601 : : {
3602 : : /* Walk the aggregates recursively. */
3603 : 0 : switch (TREE_CODE (type))
3604 : : {
3605 : 0 : case RECORD_TYPE:
3606 : 0 : case UNION_TYPE:
3607 : 0 : case QUAL_UNION_TYPE:
3608 : 0 : {
3609 : 0 : tree field;
3610 : :
3611 : : /* Walk all the structure fields. */
3612 : 0 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
3613 : : {
3614 : 0 : if (TREE_CODE (field) == FIELD_DECL
3615 : 0 : && ix86_compat_aligned_value_p (TREE_TYPE (field)))
3616 : : return true;
3617 : : }
3618 : : break;
3619 : : }
3620 : :
3621 : 0 : case ARRAY_TYPE:
3622 : : /* Just for use if some languages passes arrays by value. */
3623 : 0 : if (ix86_compat_aligned_value_p (TREE_TYPE (type)))
3624 : : return true;
3625 : : break;
3626 : :
3627 : : default:
3628 : : gcc_unreachable ();
3629 : : }
3630 : : }
3631 : : return false;
3632 : : }
3633 : :
3634 : : /* Return the alignment boundary for MODE and TYPE with alignment ALIGN.
3635 : : XXX: This function is obsolete and is only used for checking psABI
3636 : : compatibility with previous versions of GCC. */
3637 : :
3638 : : static unsigned int
3639 : 5459394 : ix86_compat_function_arg_boundary (machine_mode mode,
3640 : : const_tree type, unsigned int align)
3641 : : {
3642 : : /* In 32bit, only _Decimal128 and __float128 are aligned to their
3643 : : natural boundaries. */
3644 : 5459394 : if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
3645 : : {
3646 : : /* i386 ABI defines all arguments to be 4 byte aligned. We have to
3647 : : make an exception for SSE modes since these require 128bit
3648 : : alignment.
3649 : :
3650 : : The handling here differs from field_alignment. ICC aligns MMX
3651 : : arguments to 4 byte boundaries, while structure fields are aligned
3652 : : to 8 byte boundaries. */
3653 : 1962307 : if (!type)
3654 : : {
3655 : 11867 : if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
3656 : 1962095 : align = PARM_BOUNDARY;
3657 : : }
3658 : : else
3659 : : {
3660 : 1950440 : if (!ix86_compat_aligned_value_p (type))
3661 : 1950228 : align = PARM_BOUNDARY;
3662 : : }
3663 : : }
3664 : 10526519 : if (align > BIGGEST_ALIGNMENT)
3665 : 83 : align = BIGGEST_ALIGNMENT;
3666 : 5459394 : return align;
3667 : : }
3668 : :
3669 : : /* Return true when TYPE should be 128bit aligned for 32bit argument
3670 : : passing ABI. */
3671 : :
3672 : : static bool
3673 : 1953076 : ix86_contains_aligned_value_p (const_tree type)
3674 : : {
3675 : 1953076 : machine_mode mode = TYPE_MODE (type);
3676 : :
3677 : 1953076 : if (mode == XFmode || mode == XCmode)
3678 : : return false;
3679 : :
3680 : 1950984 : if (TYPE_ALIGN (type) < 128)
3681 : : return false;
3682 : :
3683 : 2848 : if (AGGREGATE_TYPE_P (type))
3684 : : {
3685 : : /* Walk the aggregates recursively. */
3686 : 0 : switch (TREE_CODE (type))
3687 : : {
3688 : 0 : case RECORD_TYPE:
3689 : 0 : case UNION_TYPE:
3690 : 0 : case QUAL_UNION_TYPE:
3691 : 0 : {
3692 : 0 : tree field;
3693 : :
3694 : : /* Walk all the structure fields. */
3695 : 0 : for (field = TYPE_FIELDS (type);
3696 : 0 : field;
3697 : 0 : field = DECL_CHAIN (field))
3698 : : {
3699 : 0 : if (TREE_CODE (field) == FIELD_DECL
3700 : 0 : && ix86_contains_aligned_value_p (TREE_TYPE (field)))
3701 : : return true;
3702 : : }
3703 : : break;
3704 : : }
3705 : :
3706 : 0 : case ARRAY_TYPE:
3707 : : /* Just for use if some languages passes arrays by value. */
3708 : 0 : if (ix86_contains_aligned_value_p (TREE_TYPE (type)))
3709 : : return true;
3710 : : break;
3711 : :
3712 : : default:
3713 : : gcc_unreachable ();
3714 : : }
3715 : : }
3716 : : else
3717 : 2848 : return TYPE_ALIGN (type) >= 128;
3718 : :
3719 : : return false;
3720 : : }
3721 : :
3722 : : /* Gives the alignment boundary, in bits, of an argument with the
3723 : : specified mode and type. */
3724 : :
3725 : : static unsigned int
3726 : 10811258 : ix86_function_arg_boundary (machine_mode mode, const_tree type)
3727 : : {
3728 : 10811258 : unsigned int align;
3729 : 10811258 : if (type)
3730 : : {
3731 : : /* Since the main variant type is used for call, we convert it to
3732 : : the main variant type. */
3733 : 10771738 : type = TYPE_MAIN_VARIANT (type);
3734 : 10771738 : align = TYPE_ALIGN (type);
3735 : 10771738 : if (TYPE_EMPTY_P (type))
3736 : 23910 : return PARM_BOUNDARY;
3737 : : }
3738 : : else
3739 : 39520 : align = GET_MODE_ALIGNMENT (mode);
3740 : 12787132 : if (align < PARM_BOUNDARY)
3741 : : align = PARM_BOUNDARY;
3742 : : else
3743 : : {
3744 : 6715989 : static bool warned;
3745 : 6715989 : unsigned int saved_align = align;
3746 : :
3747 : 6715989 : if (!TARGET_64BIT)
3748 : : {
3749 : : /* i386 ABI defines XFmode arguments to be 4 byte aligned. */
3750 : 1988695 : if (!type)
3751 : : {
3752 : 35619 : if (mode == XFmode || mode == XCmode)
3753 : : align = PARM_BOUNDARY;
3754 : : }
3755 : 1953076 : else if (!ix86_contains_aligned_value_p (type))
3756 : : align = PARM_BOUNDARY;
3757 : :
3758 : 38467 : if (align < 128)
3759 : 1962095 : align = PARM_BOUNDARY;
3760 : : }
3761 : :
3762 : 6715989 : if (warn_psabi
3763 : 5462079 : && !warned
3764 : 12175383 : && align != ix86_compat_function_arg_boundary (mode, type,
3765 : : saved_align))
3766 : : {
3767 : 83 : warned = true;
3768 : 83 : inform (input_location,
3769 : : "the ABI for passing parameters with %d-byte"
3770 : : " alignment has changed in GCC 4.6",
3771 : : align / BITS_PER_UNIT);
3772 : : }
3773 : : }
3774 : :
3775 : : return align;
3776 : : }
3777 : :
3778 : : /* Return true if N is a possible register number of function value. */
3779 : :
3780 : : static bool
3781 : 4642981 : ix86_function_value_regno_p (const unsigned int regno)
3782 : : {
3783 : 4642981 : switch (regno)
3784 : : {
3785 : : case AX_REG:
3786 : : return true;
3787 : 104899 : case DX_REG:
3788 : 104899 : return (!TARGET_64BIT || ix86_cfun_abi () != MS_ABI);
3789 : 101400 : case DI_REG:
3790 : 101400 : case SI_REG:
3791 : 101400 : return TARGET_64BIT && ix86_cfun_abi () != MS_ABI;
3792 : :
3793 : : /* Complex values are returned in %st(0)/%st(1) pair. */
3794 : 21225 : case ST0_REG:
3795 : 21225 : case ST1_REG:
3796 : : /* TODO: The function should depend on current function ABI but
3797 : : builtins.cc would need updating then. Therefore we use the
3798 : : default ABI. */
3799 : 21225 : if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
3800 : : return false;
3801 : 21225 : return TARGET_FLOAT_RETURNS_IN_80387;
3802 : :
3803 : : /* Complex values are returned in %xmm0/%xmm1 pair. */
3804 : 1297802 : case XMM0_REG:
3805 : 1297802 : case XMM1_REG:
3806 : 1297802 : return TARGET_SSE;
3807 : :
3808 : 11395 : case MM0_REG:
3809 : 11395 : if (TARGET_MACHO || TARGET_64BIT)
3810 : : return false;
3811 : 5425 : return TARGET_MMX;
3812 : : }
3813 : :
3814 : : return false;
3815 : : }
3816 : :
3817 : : /* Check whether the register REGNO should be zeroed on X86.
3818 : : When ALL_SSE_ZEROED is true, all SSE registers have been zeroed
3819 : : together, no need to zero it again.
3820 : : When NEED_ZERO_MMX is true, MMX registers should be cleared. */
3821 : :
3822 : : static bool
3823 : 1296 : zero_call_used_regno_p (const unsigned int regno,
3824 : : bool all_sse_zeroed,
3825 : : bool need_zero_mmx)
3826 : : {
3827 : 763 : return GENERAL_REGNO_P (regno)
3828 : 763 : || (!all_sse_zeroed && SSE_REGNO_P (regno))
3829 : 383 : || MASK_REGNO_P (regno)
3830 : 1671 : || (need_zero_mmx && MMX_REGNO_P (regno));
3831 : : }
3832 : :
3833 : : /* Return the machine_mode that is used to zero register REGNO. */
3834 : :
3835 : : static machine_mode
3836 : 921 : zero_call_used_regno_mode (const unsigned int regno)
3837 : : {
3838 : : /* NB: We only need to zero the lower 32 bits for integer registers
3839 : : and the lower 128 bits for vector registers since destination are
3840 : : zero-extended to the full register width. */
3841 : 921 : if (GENERAL_REGNO_P (regno))
3842 : : return SImode;
3843 : : else if (SSE_REGNO_P (regno))
3844 : 380 : return V4SFmode;
3845 : : else if (MASK_REGNO_P (regno))
3846 : : return HImode;
3847 : : else if (MMX_REGNO_P (regno))
3848 : 0 : return V2SImode;
3849 : : else
3850 : 0 : gcc_unreachable ();
3851 : : }
3852 : :
3853 : : /* Generate a rtx to zero all vector registers together if possible,
3854 : : otherwise, return NULL. */
3855 : :
3856 : : static rtx
3857 : 130 : zero_all_vector_registers (HARD_REG_SET need_zeroed_hardregs)
3858 : : {
3859 : 130 : if (!TARGET_AVX)
3860 : : return NULL;
3861 : :
3862 : 279 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
3863 : 276 : if ((LEGACY_SSE_REGNO_P (regno)
3864 : 252 : || (TARGET_64BIT
3865 : 252 : && (REX_SSE_REGNO_P (regno)
3866 : 228 : || (TARGET_AVX512F && EXT_REX_SSE_REGNO_P (regno)))))
3867 : 316 : && !TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
3868 : : return NULL;
3869 : :
3870 : 3 : return gen_avx_vzeroall ();
3871 : : }
3872 : :
3873 : : /* Generate insns to zero all st registers together.
3874 : : Return true when zeroing instructions are generated.
3875 : : Assume the number of st registers that are zeroed is num_of_st,
3876 : : we will emit the following sequence to zero them together:
3877 : : fldz; \
3878 : : fldz; \
3879 : : ...
3880 : : fldz; \
3881 : : fstp %%st(0); \
3882 : : fstp %%st(0); \
3883 : : ...
3884 : : fstp %%st(0);
3885 : : i.e., num_of_st fldz followed by num_of_st fstp to clear the stack
3886 : : mark stack slots empty.
3887 : :
3888 : : How to compute the num_of_st:
3889 : : There is no direct mapping from stack registers to hard register
3890 : : numbers. If one stack register needs to be cleared, we don't know
3891 : : where in the stack the value remains. So, if any stack register
3892 : : needs to be cleared, the whole stack should be cleared. However,
3893 : : x87 stack registers that hold the return value should be excluded.
3894 : : x87 returns in the top (two for complex values) register, so
3895 : : num_of_st should be 7/6 when x87 returns, otherwise it will be 8.
3896 : : return the value of num_of_st. */
3897 : :
3898 : :
3899 : : static int
3900 : 130 : zero_all_st_registers (HARD_REG_SET need_zeroed_hardregs)
3901 : : {
3902 : :
3903 : : /* If the FPU is disabled, no need to zero all st registers. */
3904 : 130 : if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
3905 : : return 0;
3906 : :
3907 : 10320 : unsigned int num_of_st = 0;
3908 : 10320 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
3909 : 10211 : if ((STACK_REGNO_P (regno) || MMX_REGNO_P (regno))
3910 : 10211 : && TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
3911 : : {
3912 : : num_of_st++;
3913 : : break;
3914 : : }
3915 : :
3916 : 129 : if (num_of_st == 0)
3917 : : return 0;
3918 : :
3919 : 20 : bool return_with_x87 = false;
3920 : 40 : return_with_x87 = (crtl->return_rtx
3921 : 20 : && (STACK_REG_P (crtl->return_rtx)));
3922 : :
3923 : 20 : bool complex_return = false;
3924 : 40 : complex_return = (crtl->return_rtx
3925 : 20 : && COMPLEX_MODE_P (GET_MODE (crtl->return_rtx)));
3926 : :
3927 : 20 : if (return_with_x87)
3928 : 2 : if (complex_return)
3929 : : num_of_st = 6;
3930 : : else
3931 : 1 : num_of_st = 7;
3932 : : else
3933 : : num_of_st = 8;
3934 : :
3935 : 20 : rtx st_reg = gen_rtx_REG (XFmode, FIRST_STACK_REG);
3936 : 177 : for (unsigned int i = 0; i < num_of_st; i++)
3937 : 157 : emit_insn (gen_rtx_SET (st_reg, CONST0_RTX (XFmode)));
3938 : :
3939 : 177 : for (unsigned int i = 0; i < num_of_st; i++)
3940 : : {
3941 : 157 : rtx insn;
3942 : 157 : insn = emit_insn (gen_rtx_SET (st_reg, st_reg));
3943 : 157 : add_reg_note (insn, REG_DEAD, st_reg);
3944 : : }
3945 : 20 : return num_of_st;
3946 : : }
3947 : :
3948 : :
3949 : : /* When the routine exit in MMX mode, if any ST register needs
3950 : : to be zeroed, we should clear all MMX registers except the
3951 : : RET_MMX_REGNO that holds the return value. */
3952 : : static bool
3953 : 0 : zero_all_mm_registers (HARD_REG_SET need_zeroed_hardregs,
3954 : : unsigned int ret_mmx_regno)
3955 : : {
3956 : 0 : bool need_zero_all_mm = false;
3957 : 0 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
3958 : 0 : if (STACK_REGNO_P (regno)
3959 : 0 : && TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
3960 : : {
3961 : : need_zero_all_mm = true;
3962 : : break;
3963 : : }
3964 : :
3965 : 0 : if (!need_zero_all_mm)
3966 : : return false;
3967 : :
3968 : : machine_mode mode = V2SImode;
3969 : 0 : for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++)
3970 : 0 : if (regno != ret_mmx_regno)
3971 : : {
3972 : 0 : rtx reg = gen_rtx_REG (mode, regno);
3973 : 0 : emit_insn (gen_rtx_SET (reg, CONST0_RTX (mode)));
3974 : : }
3975 : : return true;
3976 : : }
3977 : :
3978 : : /* TARGET_ZERO_CALL_USED_REGS. */
3979 : : /* Generate a sequence of instructions that zero registers specified by
3980 : : NEED_ZEROED_HARDREGS. Return the ZEROED_HARDREGS that are actually
3981 : : zeroed. */
3982 : : static HARD_REG_SET
3983 : 130 : ix86_zero_call_used_regs (HARD_REG_SET need_zeroed_hardregs)
3984 : : {
3985 : 130 : HARD_REG_SET zeroed_hardregs;
3986 : 130 : bool all_sse_zeroed = false;
3987 : 130 : int all_st_zeroed_num = 0;
3988 : 130 : bool all_mm_zeroed = false;
3989 : :
3990 : 130 : CLEAR_HARD_REG_SET (zeroed_hardregs);
3991 : :
3992 : : /* first, let's see whether we can zero all vector registers together. */
3993 : 130 : rtx zero_all_vec_insn = zero_all_vector_registers (need_zeroed_hardregs);
3994 : 130 : if (zero_all_vec_insn)
3995 : : {
3996 : 3 : emit_insn (zero_all_vec_insn);
3997 : 3 : all_sse_zeroed = true;
3998 : : }
3999 : :
4000 : : /* mm/st registers are shared registers set, we should follow the following
4001 : : rules to clear them:
4002 : : MMX exit mode x87 exit mode
4003 : : -------------|----------------------|---------------
4004 : : uses x87 reg | clear all MMX | clear all x87
4005 : : uses MMX reg | clear individual MMX | clear all x87
4006 : : x87 + MMX | clear all MMX | clear all x87
4007 : :
4008 : : first, we should decide which mode (MMX mode or x87 mode) the function
4009 : : exit with. */
4010 : :
4011 : 130 : bool exit_with_mmx_mode = (crtl->return_rtx
4012 : 130 : && (MMX_REG_P (crtl->return_rtx)));
4013 : :
4014 : 130 : if (!exit_with_mmx_mode)
4015 : : /* x87 exit mode, we should zero all st registers together. */
4016 : : {
4017 : 130 : all_st_zeroed_num = zero_all_st_registers (need_zeroed_hardregs);
4018 : :
4019 : 130 : if (all_st_zeroed_num > 0)
4020 : 180 : for (unsigned int regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
4021 : : /* x87 stack registers that hold the return value should be excluded.
4022 : : x87 returns in the top (two for complex values) register. */
4023 : 160 : if (all_st_zeroed_num == 8
4024 : 160 : || !((all_st_zeroed_num >= 6 && regno == REGNO (crtl->return_rtx))
4025 : : || (all_st_zeroed_num == 6
4026 : 7 : && (regno == (REGNO (crtl->return_rtx) + 1)))))
4027 : 157 : SET_HARD_REG_BIT (zeroed_hardregs, regno);
4028 : : }
4029 : : else
4030 : : /* MMX exit mode, check whether we can zero all mm registers. */
4031 : : {
4032 : 0 : unsigned int exit_mmx_regno = REGNO (crtl->return_rtx);
4033 : 0 : all_mm_zeroed = zero_all_mm_registers (need_zeroed_hardregs,
4034 : : exit_mmx_regno);
4035 : 0 : if (all_mm_zeroed)
4036 : 0 : for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++)
4037 : 0 : if (regno != exit_mmx_regno)
4038 : 0 : SET_HARD_REG_BIT (zeroed_hardregs, regno);
4039 : : }
4040 : :
4041 : : /* Now, generate instructions to zero all the other registers. */
4042 : :
4043 : 12090 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
4044 : : {
4045 : 11960 : if (!TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
4046 : 10664 : continue;
4047 : 1671 : if (!zero_call_used_regno_p (regno, all_sse_zeroed,
4048 : 1296 : exit_with_mmx_mode && !all_mm_zeroed))
4049 : 375 : continue;
4050 : :
4051 : 921 : SET_HARD_REG_BIT (zeroed_hardregs, regno);
4052 : :
4053 : 921 : machine_mode mode = zero_call_used_regno_mode (regno);
4054 : :
4055 : 921 : rtx reg = gen_rtx_REG (mode, regno);
4056 : 921 : rtx tmp = gen_rtx_SET (reg, CONST0_RTX (mode));
4057 : :
4058 : 921 : switch (mode)
4059 : : {
4060 : 533 : case E_SImode:
4061 : 533 : if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ())
4062 : : {
4063 : 533 : rtx clob = gen_rtx_CLOBBER (VOIDmode,
4064 : : gen_rtx_REG (CCmode,
4065 : : FLAGS_REG));
4066 : 533 : tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2,
4067 : : tmp,
4068 : : clob));
4069 : : }
4070 : : /* FALLTHRU. */
4071 : :
4072 : 921 : case E_V4SFmode:
4073 : 921 : case E_HImode:
4074 : 921 : case E_V2SImode:
4075 : 921 : emit_insn (tmp);
4076 : 921 : break;
4077 : :
4078 : 0 : default:
4079 : 0 : gcc_unreachable ();
4080 : : }
4081 : : }
4082 : 130 : return zeroed_hardregs;
4083 : : }
4084 : :
4085 : : /* Define how to find the value returned by a function.
4086 : : VALTYPE is the data type of the value (as a tree).
4087 : : If the precise function being called is known, FUNC is its FUNCTION_DECL;
4088 : : otherwise, FUNC is 0. */
4089 : :
4090 : : static rtx
4091 : 3864879 : function_value_32 (machine_mode orig_mode, machine_mode mode,
4092 : : const_tree fntype, const_tree fn)
4093 : : {
4094 : 3864879 : unsigned int regno;
4095 : :
4096 : : /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
4097 : : we normally prevent this case when mmx is not available. However
4098 : : some ABIs may require the result to be returned like DImode. */
4099 : 4132356 : if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
4100 : : regno = FIRST_MMX_REG;
4101 : :
4102 : : /* 16-byte vector modes in %xmm0. See ix86_return_in_memory for where
4103 : : we prevent this case when sse is not available. However some ABIs
4104 : : may require the result to be returned like integer TImode. */
4105 : 3855639 : else if (mode == TImode
4106 : 4113876 : || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
4107 : : regno = FIRST_SSE_REG;
4108 : :
4109 : : /* 32-byte vector modes in %ymm0. */
4110 : 3896242 : else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
4111 : : regno = FIRST_SSE_REG;
4112 : :
4113 : : /* 64-byte vector modes in %zmm0. */
4114 : 3752484 : else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
4115 : : regno = FIRST_SSE_REG;
4116 : :
4117 : : /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387). */
4118 : 3597402 : else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
4119 : : regno = FIRST_FLOAT_REG;
4120 : : else
4121 : : /* Most things go in %eax. */
4122 : 3535557 : regno = AX_REG;
4123 : :
4124 : : /* Return __bf16/ _Float16/_Complex _Foat16 by sse register. */
4125 : 3864879 : if (mode == HFmode || mode == BFmode)
4126 : : {
4127 : 1613 : if (!TARGET_SSE2)
4128 : : {
4129 : 0 : error ("SSE register return with SSE2 disabled");
4130 : 0 : regno = AX_REG;
4131 : : }
4132 : : else
4133 : : regno = FIRST_SSE_REG;
4134 : : }
4135 : :
4136 : 3864879 : if (mode == HCmode)
4137 : : {
4138 : 80 : if (!TARGET_SSE2)
4139 : 0 : error ("SSE register return with SSE2 disabled");
4140 : :
4141 : 80 : rtx ret = gen_rtx_PARALLEL (mode, rtvec_alloc(1));
4142 : 160 : XVECEXP (ret, 0, 0)
4143 : 160 : = gen_rtx_EXPR_LIST (VOIDmode,
4144 : : gen_rtx_REG (SImode,
4145 : 80 : TARGET_SSE2 ? FIRST_SSE_REG : AX_REG),
4146 : : GEN_INT (0));
4147 : 80 : return ret;
4148 : : }
4149 : :
4150 : : /* Override FP return register with %xmm0 for local functions when
4151 : : SSE math is enabled or for functions with sseregparm attribute. */
4152 : 3864799 : if ((fn || fntype) && (mode == SFmode || mode == DFmode))
4153 : : {
4154 : 48252 : int sse_level = ix86_function_sseregparm (fntype, fn, false);
4155 : 48252 : if (sse_level == -1)
4156 : : {
4157 : 0 : error ("calling %qD with SSE calling convention without "
4158 : : "SSE/SSE2 enabled", fn);
4159 : 0 : sorry ("this is a GCC bug that can be worked around by adding "
4160 : : "attribute used to function called");
4161 : : }
4162 : 48252 : else if ((sse_level >= 1 && mode == SFmode)
4163 : 48252 : || (sse_level == 2 && mode == DFmode))
4164 : : regno = FIRST_SSE_REG;
4165 : : }
4166 : :
4167 : : /* OImode shouldn't be used directly. */
4168 : 3864799 : gcc_assert (mode != OImode);
4169 : :
4170 : 3864799 : return gen_rtx_REG (orig_mode, regno);
4171 : : }
4172 : :
4173 : : static rtx
4174 : 90101758 : function_value_64 (machine_mode orig_mode, machine_mode mode,
4175 : : const_tree valtype)
4176 : : {
4177 : 90101758 : rtx ret;
4178 : :
4179 : : /* Handle libcalls, which don't provide a type node. */
4180 : 90101758 : if (valtype == NULL)
4181 : : {
4182 : 104366 : unsigned int regno;
4183 : :
4184 : 104366 : switch (mode)
4185 : : {
4186 : : case E_BFmode:
4187 : : case E_HFmode:
4188 : : case E_HCmode:
4189 : : case E_SFmode:
4190 : : case E_SCmode:
4191 : : case E_DFmode:
4192 : : case E_DCmode:
4193 : : case E_TFmode:
4194 : : case E_SDmode:
4195 : : case E_DDmode:
4196 : : case E_TDmode:
4197 : : regno = FIRST_SSE_REG;
4198 : : break;
4199 : 1035 : case E_XFmode:
4200 : 1035 : case E_XCmode:
4201 : 1035 : regno = FIRST_FLOAT_REG;
4202 : 1035 : break;
4203 : : case E_TCmode:
4204 : : return NULL;
4205 : 56540 : default:
4206 : 56540 : regno = AX_REG;
4207 : : }
4208 : :
4209 : 104366 : return gen_rtx_REG (mode, regno);
4210 : : }
4211 : 89997392 : else if (POINTER_TYPE_P (valtype))
4212 : : {
4213 : : /* Pointers are always returned in word_mode. */
4214 : 13924546 : mode = word_mode;
4215 : : }
4216 : :
4217 : 89997392 : ret = construct_container (mode, orig_mode, valtype, 1,
4218 : : X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
4219 : : x86_64_int_return_registers, 0);
4220 : :
4221 : : /* For zero sized structures, construct_container returns NULL, but we
4222 : : need to keep rest of compiler happy by returning meaningful value. */
4223 : 89997392 : if (!ret)
4224 : 191462 : ret = gen_rtx_REG (orig_mode, AX_REG);
4225 : :
4226 : : return ret;
4227 : : }
4228 : :
4229 : : static rtx
4230 : 0 : function_value_ms_32 (machine_mode orig_mode, machine_mode mode,
4231 : : const_tree fntype, const_tree fn, const_tree valtype)
4232 : : {
4233 : 0 : unsigned int regno;
4234 : :
4235 : : /* Floating point return values in %st(0)
4236 : : (unless -mno-fp-ret-in-387 or aggregate type of up to 8 bytes). */
4237 : 0 : if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387
4238 : 0 : && (GET_MODE_SIZE (mode) > 8
4239 : 0 : || valtype == NULL_TREE || !AGGREGATE_TYPE_P (valtype)))
4240 : : {
4241 : 0 : regno = FIRST_FLOAT_REG;
4242 : 0 : return gen_rtx_REG (orig_mode, regno);
4243 : : }
4244 : : else
4245 : 0 : return function_value_32(orig_mode, mode, fntype,fn);
4246 : : }
4247 : :
4248 : : static rtx
4249 : 762440 : function_value_ms_64 (machine_mode orig_mode, machine_mode mode,
4250 : : const_tree valtype)
4251 : : {
4252 : 762440 : unsigned int regno = AX_REG;
4253 : :
4254 : 762440 : if (TARGET_SSE)
4255 : : {
4256 : 1523426 : switch (GET_MODE_SIZE (mode))
4257 : : {
4258 : 13985 : case 16:
4259 : 13985 : if (valtype != NULL_TREE
4260 : 13985 : && !VECTOR_INTEGER_TYPE_P (valtype)
4261 : 7146 : && !VECTOR_INTEGER_TYPE_P (valtype)
4262 : 7146 : && !INTEGRAL_TYPE_P (valtype)
4263 : 21131 : && !VECTOR_FLOAT_TYPE_P (valtype))
4264 : : break;
4265 : 13985 : if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
4266 : : && !COMPLEX_MODE_P (mode))
4267 : 197510 : regno = FIRST_SSE_REG;
4268 : : break;
4269 : 728054 : case 8:
4270 : 728054 : case 4:
4271 : 728054 : if (valtype != NULL_TREE && AGGREGATE_TYPE_P (valtype))
4272 : : break;
4273 : 713302 : if (mode == SFmode || mode == DFmode)
4274 : 197510 : regno = FIRST_SSE_REG;
4275 : : break;
4276 : : default:
4277 : : break;
4278 : : }
4279 : : }
4280 : 762440 : return gen_rtx_REG (orig_mode, regno);
4281 : : }
4282 : :
4283 : : static rtx
4284 : 94729077 : ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
4285 : : machine_mode orig_mode, machine_mode mode)
4286 : : {
4287 : 94729077 : const_tree fn, fntype;
4288 : :
4289 : 94729077 : fn = NULL_TREE;
4290 : 94729077 : if (fntype_or_decl && DECL_P (fntype_or_decl))
4291 : 3484671 : fn = fntype_or_decl;
4292 : 3484671 : fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
4293 : :
4294 : 94729077 : if (ix86_function_type_abi (fntype) == MS_ABI)
4295 : : {
4296 : 762440 : if (TARGET_64BIT)
4297 : 762440 : return function_value_ms_64 (orig_mode, mode, valtype);
4298 : : else
4299 : 0 : return function_value_ms_32 (orig_mode, mode, fntype, fn, valtype);
4300 : : }
4301 : 93966637 : else if (TARGET_64BIT)
4302 : 90101758 : return function_value_64 (orig_mode, mode, valtype);
4303 : : else
4304 : 3864879 : return function_value_32 (orig_mode, mode, fntype, fn);
4305 : : }
4306 : :
4307 : : static rtx
4308 : 94621619 : ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool)
4309 : : {
4310 : 94621619 : machine_mode mode, orig_mode;
4311 : :
4312 : 94621619 : orig_mode = TYPE_MODE (valtype);
4313 : 94621619 : mode = type_natural_mode (valtype, NULL, true);
4314 : 94621619 : return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
4315 : : }
4316 : :
4317 : : /* Pointer function arguments and return values are promoted to
4318 : : word_mode for normal functions. */
4319 : :
4320 : : static machine_mode
4321 : 31554179 : ix86_promote_function_mode (const_tree type, machine_mode mode,
4322 : : int *punsignedp, const_tree fntype,
4323 : : int for_return)
4324 : : {
4325 : 31554179 : if (cfun->machine->func_type == TYPE_NORMAL
4326 : 31553187 : && type != NULL_TREE
4327 : 31519838 : && POINTER_TYPE_P (type))
4328 : : {
4329 : 15800247 : *punsignedp = POINTERS_EXTEND_UNSIGNED;
4330 : 15800247 : return word_mode;
4331 : : }
4332 : 15753932 : return default_promote_function_mode (type, mode, punsignedp, fntype,
4333 : 15753932 : for_return);
4334 : : }
4335 : :
4336 : : /* Return true if a structure, union or array with MODE containing FIELD
4337 : : should be accessed using BLKmode. */
4338 : :
4339 : : static bool
4340 : 121191528 : ix86_member_type_forces_blk (const_tree field, machine_mode mode)
4341 : : {
4342 : : /* Union with XFmode must be in BLKmode. */
4343 : 121191528 : return (mode == XFmode
4344 : 121325226 : && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE
4345 : 121038 : || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE));
4346 : : }
4347 : :
4348 : : rtx
4349 : 107458 : ix86_libcall_value (machine_mode mode)
4350 : : {
4351 : 107458 : return ix86_function_value_1 (NULL, NULL, mode, mode);
4352 : : }
4353 : :
4354 : : /* Return true iff type is returned in memory. */
4355 : :
4356 : : static bool
4357 : 95831971 : ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
4358 : : {
4359 : 95831971 : const machine_mode mode = type_natural_mode (type, NULL, true);
4360 : 95831971 : HOST_WIDE_INT size;
4361 : :
4362 : 95831971 : if (TARGET_64BIT)
4363 : : {
4364 : 91379832 : if (ix86_function_type_abi (fntype) == MS_ABI)
4365 : : {
4366 : 702118 : size = int_size_in_bytes (type);
4367 : :
4368 : : /* __m128 is returned in xmm0. */
4369 : 702118 : if ((!type || VECTOR_INTEGER_TYPE_P (type)
4370 : 682625 : || INTEGRAL_TYPE_P (type)
4371 : 216893 : || VECTOR_FLOAT_TYPE_P (type))
4372 : 501053 : && (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
4373 : : && !COMPLEX_MODE_P (mode)
4374 : 1203171 : && (GET_MODE_SIZE (mode) == 16 || size == 16))
4375 : : return false;
4376 : :
4377 : : /* Otherwise, the size must be exactly in [1248]. */
4378 : 1339975 : return size != 1 && size != 2 && size != 4 && size != 8;
4379 : : }
4380 : : else
4381 : : {
4382 : 90677714 : int needed_intregs, needed_sseregs;
4383 : :
4384 : 90677714 : return examine_argument (mode, type, 1,
4385 : : &needed_intregs, &needed_sseregs);
4386 : : }
4387 : : }
4388 : : else
4389 : : {
4390 : 4452139 : size = int_size_in_bytes (type);
4391 : :
4392 : : /* Intel MCU psABI returns scalars and aggregates no larger than 8
4393 : : bytes in registers. */
4394 : 4452139 : if (TARGET_IAMCU)
4395 : 0 : return VECTOR_MODE_P (mode) || size < 0 || size > 8;
4396 : :
4397 : 4452139 : if (mode == BLKmode)
4398 : : return true;
4399 : :
4400 : 4452139 : if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
4401 : : return false;
4402 : :
4403 : 4452139 : if (VECTOR_MODE_P (mode) || mode == TImode)
4404 : : {
4405 : : /* User-created vectors small enough to fit in EAX. */
4406 : 267449 : if (size < 8)
4407 : : return false;
4408 : :
4409 : : /* Unless ABI prescibes otherwise,
4410 : : MMX/3dNow values are returned in MM0 if available. */
4411 : :
4412 : 267449 : if (size == 8)
4413 : 9232 : return TARGET_VECT8_RETURNS || !TARGET_MMX;
4414 : :
4415 : : /* SSE values are returned in XMM0 if available. */
4416 : 258217 : if (size == 16)
4417 : 108807 : return !TARGET_SSE;
4418 : :
4419 : : /* AVX values are returned in YMM0 if available. */
4420 : 149410 : if (size == 32)
4421 : 71870 : return !TARGET_AVX;
4422 : :
4423 : : /* AVX512F values are returned in ZMM0 if available. */
4424 : 77540 : if (size == 64)
4425 : 77540 : return !TARGET_AVX512F || !TARGET_EVEX512;
4426 : : }
4427 : :
4428 : 4184690 : if (mode == XFmode)
4429 : : return false;
4430 : :
4431 : 4173563 : if (size > 12)
4432 : : return true;
4433 : :
4434 : : /* OImode shouldn't be used directly. */
4435 : 3218589 : gcc_assert (mode != OImode);
4436 : :
4437 : : return false;
4438 : : }
4439 : : }
4440 : :
4441 : : /* Implement TARGET_PUSH_ARGUMENT. */
4442 : :
4443 : : static bool
4444 : 9146297 : ix86_push_argument (unsigned int npush)
4445 : : {
4446 : : /* If SSE2 is available, use vector move to put large argument onto
4447 : : stack. NB: In 32-bit mode, use 8-byte vector move. */
4448 : 11539851 : return ((!TARGET_SSE2 || npush < (TARGET_64BIT ? 16 : 8))
4449 : 8883599 : && TARGET_PUSH_ARGS
4450 : 18029798 : && !ACCUMULATE_OUTGOING_ARGS);
4451 : : }
4452 : :
4453 : :
4454 : : /* Create the va_list data type. */
4455 : :
4456 : : static tree
4457 : 269870 : ix86_build_builtin_va_list_64 (void)
4458 : : {
4459 : 269870 : tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4460 : :
4461 : 269870 : record = lang_hooks.types.make_type (RECORD_TYPE);
4462 : 269870 : type_decl = build_decl (BUILTINS_LOCATION,
4463 : : TYPE_DECL, get_identifier ("__va_list_tag"), record);
4464 : :
4465 : 269870 : f_gpr = build_decl (BUILTINS_LOCATION,
4466 : : FIELD_DECL, get_identifier ("gp_offset"),
4467 : : unsigned_type_node);
4468 : 269870 : f_fpr = build_decl (BUILTINS_LOCATION,
4469 : : FIELD_DECL, get_identifier ("fp_offset"),
4470 : : unsigned_type_node);
4471 : 269870 : f_ovf = build_decl (BUILTINS_LOCATION,
4472 : : FIELD_DECL, get_identifier ("overflow_arg_area"),
4473 : : ptr_type_node);
4474 : 269870 : f_sav = build_decl (BUILTINS_LOCATION,
4475 : : FIELD_DECL, get_identifier ("reg_save_area"),
4476 : : ptr_type_node);
4477 : :
4478 : 269870 : va_list_gpr_counter_field = f_gpr;
4479 : 269870 : va_list_fpr_counter_field = f_fpr;
4480 : :
4481 : 269870 : DECL_FIELD_CONTEXT (f_gpr) = record;
4482 : 269870 : DECL_FIELD_CONTEXT (f_fpr) = record;
4483 : 269870 : DECL_FIELD_CONTEXT (f_ovf) = record;
4484 : 269870 : DECL_FIELD_CONTEXT (f_sav) = record;
4485 : :
4486 : 269870 : TYPE_STUB_DECL (record) = type_decl;
4487 : 269870 : TYPE_NAME (record) = type_decl;
4488 : 269870 : TYPE_FIELDS (record) = f_gpr;
4489 : 269870 : DECL_CHAIN (f_gpr) = f_fpr;
4490 : 269870 : DECL_CHAIN (f_fpr) = f_ovf;
4491 : 269870 : DECL_CHAIN (f_ovf) = f_sav;
4492 : :
4493 : 269870 : layout_type (record);
4494 : :
4495 : 269870 : TYPE_ATTRIBUTES (record) = tree_cons (get_identifier ("sysv_abi va_list"),
4496 : 269870 : NULL_TREE, TYPE_ATTRIBUTES (record));
4497 : :
4498 : : /* The correct type is an array type of one element. */
4499 : 269870 : return build_array_type (record, build_index_type (size_zero_node));
4500 : : }
4501 : :
4502 : : /* Setup the builtin va_list data type and for 64-bit the additional
4503 : : calling convention specific va_list data types. */
4504 : :
4505 : : static tree
4506 : 276943 : ix86_build_builtin_va_list (void)
4507 : : {
4508 : 276943 : if (TARGET_64BIT)
4509 : : {
4510 : : /* Initialize ABI specific va_list builtin types.
4511 : :
4512 : : In lto1, we can encounter two va_list types:
4513 : : - one as a result of the type-merge across TUs, and
4514 : : - the one constructed here.
4515 : : These two types will not have the same TYPE_MAIN_VARIANT, and therefore
4516 : : a type identity check in canonical_va_list_type based on
4517 : : TYPE_MAIN_VARIANT (which we used to have) will not work.
4518 : : Instead, we tag each va_list_type_node with its unique attribute, and
4519 : : look for the attribute in the type identity check in
4520 : : canonical_va_list_type.
4521 : :
4522 : : Tagging sysv_va_list_type_node directly with the attribute is
4523 : : problematic since it's a array of one record, which will degrade into a
4524 : : pointer to record when used as parameter (see build_va_arg comments for
4525 : : an example), dropping the attribute in the process. So we tag the
4526 : : record instead. */
4527 : :
4528 : : /* For SYSV_ABI we use an array of one record. */
4529 : 269870 : sysv_va_list_type_node = ix86_build_builtin_va_list_64 ();
4530 : :
4531 : : /* For MS_ABI we use plain pointer to argument area. */
4532 : 269870 : tree char_ptr_type = build_pointer_type (char_type_node);
4533 : 269870 : tree attr = tree_cons (get_identifier ("ms_abi va_list"), NULL_TREE,
4534 : 269870 : TYPE_ATTRIBUTES (char_ptr_type));
4535 : 269870 : ms_va_list_type_node = build_type_attribute_variant (char_ptr_type, attr);
4536 : :
4537 : 269870 : return ((ix86_abi == MS_ABI)
4538 : 269870 : ? ms_va_list_type_node
4539 : 269870 : : sysv_va_list_type_node);
4540 : : }
4541 : : else
4542 : : {
4543 : : /* For i386 we use plain pointer to argument area. */
4544 : 7073 : return build_pointer_type (char_type_node);
4545 : : }
4546 : : }
4547 : :
4548 : : /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
4549 : :
4550 : : static void
4551 : 15540 : setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
4552 : : {
4553 : 15540 : rtx save_area, mem;
4554 : 15540 : alias_set_type set;
4555 : 15540 : int i, max;
4556 : :
4557 : : /* GPR size of varargs save area. */
4558 : 15540 : if (cfun->va_list_gpr_size)
4559 : 15112 : ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
4560 : : else
4561 : 428 : ix86_varargs_gpr_size = 0;
4562 : :
4563 : : /* FPR size of varargs save area. We don't need it if we don't pass
4564 : : anything in SSE registers. */
4565 : 15540 : if (TARGET_SSE && cfun->va_list_fpr_size)
4566 : 14513 : ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
4567 : : else
4568 : 1027 : ix86_varargs_fpr_size = 0;
4569 : :
4570 : 15540 : if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
4571 : : return;
4572 : :
4573 : 15281 : save_area = frame_pointer_rtx;
4574 : 15281 : set = get_varargs_alias_set ();
4575 : :
4576 : 15281 : max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
4577 : 15281 : if (max > X86_64_REGPARM_MAX)
4578 : : max = X86_64_REGPARM_MAX;
4579 : :
4580 : 84774 : for (i = cum->regno; i < max; i++)
4581 : : {
4582 : 69493 : mem = gen_rtx_MEM (word_mode,
4583 : 69493 : plus_constant (Pmode, save_area, i * UNITS_PER_WORD));
4584 : 69493 : MEM_NOTRAP_P (mem) = 1;
4585 : 69493 : set_mem_alias_set (mem, set);
4586 : 69493 : emit_move_insn (mem,
4587 : : gen_rtx_REG (word_mode,
4588 : 69493 : x86_64_int_parameter_registers[i]));
4589 : : }
4590 : :
4591 : 15281 : if (ix86_varargs_fpr_size)
4592 : : {
4593 : 14513 : machine_mode smode;
4594 : 14513 : rtx_code_label *label;
4595 : 14513 : rtx test;
4596 : :
4597 : : /* Now emit code to save SSE registers. The AX parameter contains number
4598 : : of SSE parameter registers used to call this function, though all we
4599 : : actually check here is the zero/non-zero status. */
4600 : :
4601 : 14513 : label = gen_label_rtx ();
4602 : 14513 : test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx);
4603 : 14513 : emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1),
4604 : : label));
4605 : :
4606 : : /* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if
4607 : : we used movdqa (i.e. TImode) instead? Perhaps even better would
4608 : : be if we could determine the real mode of the data, via a hook
4609 : : into pass_stdarg. Ignore all that for now. */
4610 : 14513 : smode = V4SFmode;
4611 : 14513 : if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode))
4612 : 4024 : crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode);
4613 : :
4614 : 14513 : max = cum->sse_regno + cfun->va_list_fpr_size / 16;
4615 : 14513 : if (max > X86_64_SSE_REGPARM_MAX)
4616 : : max = X86_64_SSE_REGPARM_MAX;
4617 : :
4618 : 129014 : for (i = cum->sse_regno; i < max; ++i)
4619 : : {
4620 : 114501 : mem = plus_constant (Pmode, save_area,
4621 : 114501 : i * 16 + ix86_varargs_gpr_size);
4622 : 114501 : mem = gen_rtx_MEM (smode, mem);
4623 : 114501 : MEM_NOTRAP_P (mem) = 1;
4624 : 114501 : set_mem_alias_set (mem, set);
4625 : 114501 : set_mem_align (mem, GET_MODE_ALIGNMENT (smode));
4626 : :
4627 : 114501 : emit_move_insn (mem, gen_rtx_REG (smode, GET_SSE_REGNO (i)));
4628 : : }
4629 : :
4630 : 14513 : emit_label (label);
4631 : : }
4632 : : }
4633 : :
4634 : : static void
4635 : 5652 : setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
4636 : : {
4637 : 5652 : alias_set_type set = get_varargs_alias_set ();
4638 : 5652 : int i;
4639 : :
4640 : : /* Reset to zero, as there might be a sysv vaarg used
4641 : : before. */
4642 : 5652 : ix86_varargs_gpr_size = 0;
4643 : 5652 : ix86_varargs_fpr_size = 0;
4644 : :
4645 : 14154 : for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
4646 : : {
4647 : 8502 : rtx reg, mem;
4648 : :
4649 : 8502 : mem = gen_rtx_MEM (Pmode,
4650 : 8502 : plus_constant (Pmode, virtual_incoming_args_rtx,
4651 : 8502 : i * UNITS_PER_WORD));
4652 : 8502 : MEM_NOTRAP_P (mem) = 1;
4653 : 8502 : set_mem_alias_set (mem, set);
4654 : :
4655 : 8502 : reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
4656 : 8502 : emit_move_insn (mem, reg);
4657 : : }
4658 : 5652 : }
4659 : :
4660 : : static void
4661 : 21338 : ix86_setup_incoming_varargs (cumulative_args_t cum_v,
4662 : : const function_arg_info &arg,
4663 : : int *, int no_rtl)
4664 : : {
4665 : 21338 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
4666 : 21338 : CUMULATIVE_ARGS next_cum;
4667 : 21338 : tree fntype;
4668 : :
4669 : : /* This argument doesn't appear to be used anymore. Which is good,
4670 : : because the old code here didn't suppress rtl generation. */
4671 : 21338 : gcc_assert (!no_rtl);
4672 : :
4673 : 21338 : if (!TARGET_64BIT)
4674 : 146 : return;
4675 : :
4676 : 21192 : fntype = TREE_TYPE (current_function_decl);
4677 : :
4678 : : /* For varargs, we do not want to skip the dummy va_dcl argument.
4679 : : For stdargs, we do want to skip the last named argument. */
4680 : 21192 : next_cum = *cum;
4681 : 21192 : if ((!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl))
4682 : 77 : || arg.type != NULL_TREE)
4683 : 21204 : && stdarg_p (fntype))
4684 : 21127 : ix86_function_arg_advance (pack_cumulative_args (&next_cum), arg);
4685 : :
4686 : 21192 : if (cum->call_abi == MS_ABI)
4687 : 5652 : setup_incoming_varargs_ms_64 (&next_cum);
4688 : : else
4689 : 15540 : setup_incoming_varargs_64 (&next_cum);
4690 : : }
4691 : :
4692 : : /* Checks if TYPE is of kind va_list char *. */
4693 : :
4694 : : static bool
4695 : 72779 : is_va_list_char_pointer (tree type)
4696 : : {
4697 : 72779 : tree canonic;
4698 : :
4699 : : /* For 32-bit it is always true. */
4700 : 72779 : if (!TARGET_64BIT)
4701 : : return true;
4702 : 72617 : canonic = ix86_canonical_va_list_type (type);
4703 : 72617 : return (canonic == ms_va_list_type_node
4704 : 72617 : || (ix86_abi == MS_ABI && canonic == va_list_type_node));
4705 : : }
4706 : :
4707 : : /* Implement va_start. */
4708 : :
4709 : : static void
4710 : 20863 : ix86_va_start (tree valist, rtx nextarg)
4711 : : {
4712 : 20863 : HOST_WIDE_INT words, n_gpr, n_fpr;
4713 : 20863 : tree f_gpr, f_fpr, f_ovf, f_sav;
4714 : 20863 : tree gpr, fpr, ovf, sav, t;
4715 : 20863 : tree type;
4716 : 20863 : rtx ovf_rtx;
4717 : :
4718 : 20863 : if (flag_split_stack
4719 : 12 : && cfun->machine->split_stack_varargs_pointer == NULL_RTX)
4720 : : {
4721 : 12 : unsigned int scratch_regno;
4722 : :
4723 : : /* When we are splitting the stack, we can't refer to the stack
4724 : : arguments using internal_arg_pointer, because they may be on
4725 : : the old stack. The split stack prologue will arrange to
4726 : : leave a pointer to the old stack arguments in a scratch
4727 : : register, which we here copy to a pseudo-register. The split
4728 : : stack prologue can't set the pseudo-register directly because
4729 : : it (the prologue) runs before any registers have been saved. */
4730 : :
4731 : 12 : scratch_regno = split_stack_prologue_scratch_regno ();
4732 : 12 : if (scratch_regno != INVALID_REGNUM)
4733 : : {
4734 : 12 : rtx reg;
4735 : 12 : rtx_insn *seq;
4736 : :
4737 : 12 : reg = gen_reg_rtx (Pmode);
4738 : 12 : cfun->machine->split_stack_varargs_pointer = reg;
4739 : :
4740 : 12 : start_sequence ();
4741 : 12 : emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno));
4742 : 12 : seq = get_insns ();
4743 : 12 : end_sequence ();
4744 : :
4745 : 12 : push_topmost_sequence ();
4746 : 12 : emit_insn_after (seq, entry_of_function ());
4747 : 12 : pop_topmost_sequence ();
4748 : : }
4749 : : }
4750 : :
4751 : : /* Only 64bit target needs something special. */
4752 : 20863 : if (is_va_list_char_pointer (TREE_TYPE (valist)))
4753 : : {
4754 : 5656 : if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
4755 : 5652 : std_expand_builtin_va_start (valist, nextarg);
4756 : : else
4757 : : {
4758 : 4 : rtx va_r, next;
4759 : :
4760 : 4 : va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
4761 : 8 : next = expand_binop (ptr_mode, add_optab,
4762 : 4 : cfun->machine->split_stack_varargs_pointer,
4763 : : crtl->args.arg_offset_rtx,
4764 : : NULL_RTX, 0, OPTAB_LIB_WIDEN);
4765 : 4 : convert_move (va_r, next, 0);
4766 : : }
4767 : 5656 : return;
4768 : : }
4769 : :
4770 : 15207 : f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
4771 : 15207 : f_fpr = DECL_CHAIN (f_gpr);
4772 : 15207 : f_ovf = DECL_CHAIN (f_fpr);
4773 : 15207 : f_sav = DECL_CHAIN (f_ovf);
4774 : :
4775 : 15207 : valist = build_simple_mem_ref (valist);
4776 : 15207 : TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node);
4777 : : /* The following should be folded into the MEM_REF offset. */
4778 : 15207 : gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist),
4779 : : f_gpr, NULL_TREE);
4780 : 15207 : fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
4781 : : f_fpr, NULL_TREE);
4782 : 15207 : ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
4783 : : f_ovf, NULL_TREE);
4784 : 15207 : sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
4785 : : f_sav, NULL_TREE);
4786 : :
4787 : : /* Count number of gp and fp argument registers used. */
4788 : 15207 : words = crtl->args.info.words;
4789 : 15207 : n_gpr = crtl->args.info.regno;
4790 : 15207 : n_fpr = crtl->args.info.sse_regno;
4791 : :
4792 : 15207 : if (cfun->va_list_gpr_size)
4793 : : {
4794 : 14985 : type = TREE_TYPE (gpr);
4795 : 14985 : t = build2 (MODIFY_EXPR, type,
4796 : 14985 : gpr, build_int_cst (type, n_gpr * 8));
4797 : 14985 : TREE_SIDE_EFFECTS (t) = 1;
4798 : 14985 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4799 : : }
4800 : :
4801 : 15207 : if (TARGET_SSE && cfun->va_list_fpr_size)
4802 : : {
4803 : 14374 : type = TREE_TYPE (fpr);
4804 : 14374 : t = build2 (MODIFY_EXPR, type, fpr,
4805 : 14374 : build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
4806 : 14374 : TREE_SIDE_EFFECTS (t) = 1;
4807 : 14374 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4808 : : }
4809 : :
4810 : : /* Find the overflow area. */
4811 : 15207 : type = TREE_TYPE (ovf);
4812 : 15207 : if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
4813 : 15199 : ovf_rtx = crtl->args.internal_arg_pointer;
4814 : : else
4815 : : ovf_rtx = cfun->machine->split_stack_varargs_pointer;
4816 : 15207 : t = make_tree (type, ovf_rtx);
4817 : 15207 : if (words != 0)
4818 : 486 : t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD);
4819 : :
4820 : 15207 : t = build2 (MODIFY_EXPR, type, ovf, t);
4821 : 15207 : TREE_SIDE_EFFECTS (t) = 1;
4822 : 15207 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4823 : :
4824 : 15207 : if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
4825 : : {
4826 : : /* Find the register save area.
4827 : : Prologue of the function save it right above stack frame. */
4828 : 15154 : type = TREE_TYPE (sav);
4829 : 15154 : t = make_tree (type, frame_pointer_rtx);
4830 : 15154 : if (!ix86_varargs_gpr_size)
4831 : 169 : t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX);
4832 : :
4833 : 15154 : t = build2 (MODIFY_EXPR, type, sav, t);
4834 : 15154 : TREE_SIDE_EFFECTS (t) = 1;
4835 : 15154 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4836 : : }
4837 : : }
4838 : :
4839 : : /* Implement va_arg. */
4840 : :
4841 : : static tree
4842 : 51916 : ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
4843 : : gimple_seq *post_p)
4844 : : {
4845 : 51916 : static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
4846 : 51916 : tree f_gpr, f_fpr, f_ovf, f_sav;
4847 : 51916 : tree gpr, fpr, ovf, sav, t;
4848 : 51916 : int size, rsize;
4849 : 51916 : tree lab_false, lab_over = NULL_TREE;
4850 : 51916 : tree addr, t2;
4851 : 51916 : rtx container;
4852 : 51916 : int indirect_p = 0;
4853 : 51916 : tree ptrtype;
4854 : 51916 : machine_mode nat_mode;
4855 : 51916 : unsigned int arg_boundary;
4856 : 51916 : unsigned int type_align;
4857 : :
4858 : : /* Only 64bit target needs something special. */
4859 : 51916 : if (is_va_list_char_pointer (TREE_TYPE (valist)))
4860 : 260 : return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
4861 : :
4862 : 51656 : f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
4863 : 51656 : f_fpr = DECL_CHAIN (f_gpr);
4864 : 51656 : f_ovf = DECL_CHAIN (f_fpr);
4865 : 51656 : f_sav = DECL_CHAIN (f_ovf);
4866 : :
4867 : 51656 : gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
4868 : : valist, f_gpr, NULL_TREE);
4869 : :
4870 : 51656 : fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
4871 : 51656 : ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
4872 : 51656 : sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
4873 : :
4874 : 51656 : indirect_p = pass_va_arg_by_reference (type);
4875 : 51656 : if (indirect_p)
4876 : 103 : type = build_pointer_type (type);
4877 : 51656 : size = arg_int_size_in_bytes (type);
4878 : 51656 : rsize = CEIL (size, UNITS_PER_WORD);
4879 : :
4880 : 51656 : nat_mode = type_natural_mode (type, NULL, false);
4881 : 51656 : switch (nat_mode)
4882 : : {
4883 : 28 : case E_V16HFmode:
4884 : 28 : case E_V16BFmode:
4885 : 28 : case E_V8SFmode:
4886 : 28 : case E_V8SImode:
4887 : 28 : case E_V32QImode:
4888 : 28 : case E_V16HImode:
4889 : 28 : case E_V4DFmode:
4890 : 28 : case E_V4DImode:
4891 : 28 : case E_V32HFmode:
4892 : 28 : case E_V32BFmode:
4893 : 28 : case E_V16SFmode:
4894 : 28 : case E_V16SImode:
4895 : 28 : case E_V64QImode:
4896 : 28 : case E_V32HImode:
4897 : 28 : case E_V8DFmode:
4898 : 28 : case E_V8DImode:
4899 : : /* Unnamed 256 and 512bit vector mode parameters are passed on stack. */
4900 : 28 : if (!TARGET_64BIT_MS_ABI)
4901 : : {
4902 : : container = NULL;
4903 : : break;
4904 : : }
4905 : : /* FALLTHRU */
4906 : :
4907 : 51628 : default:
4908 : 51628 : container = construct_container (nat_mode, TYPE_MODE (type),
4909 : : type, 0, X86_64_REGPARM_MAX,
4910 : : X86_64_SSE_REGPARM_MAX, intreg,
4911 : : 0);
4912 : 51628 : break;
4913 : : }
4914 : :
4915 : : /* Pull the value out of the saved registers. */
4916 : :
4917 : 51656 : addr = create_tmp_var (ptr_type_node, "addr");
4918 : 51656 : type_align = TYPE_ALIGN (type);
4919 : :
4920 : 51656 : if (container)
4921 : : {
4922 : 28561 : int needed_intregs, needed_sseregs;
4923 : 28561 : bool need_temp;
4924 : 28561 : tree int_addr, sse_addr;
4925 : :
4926 : 28561 : lab_false = create_artificial_label (UNKNOWN_LOCATION);
4927 : 28561 : lab_over = create_artificial_label (UNKNOWN_LOCATION);
4928 : :
4929 : 28561 : examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
4930 : :
4931 : 28561 : bool container_in_reg = false;
4932 : 28561 : if (REG_P (container))
4933 : : container_in_reg = true;
4934 : 1641 : else if (GET_CODE (container) == PARALLEL
4935 : 1641 : && GET_MODE (container) == BLKmode
4936 : 580 : && XVECLEN (container, 0) == 1)
4937 : : {
4938 : : /* Check if it is a PARALLEL BLKmode container of an EXPR_LIST
4939 : : expression in a TImode register. In this case, temp isn't
4940 : : needed. Otherwise, the TImode variable will be put in the
4941 : : GPR save area which guarantees only 8-byte alignment. */
4942 : 509 : rtx x = XVECEXP (container, 0, 0);
4943 : 509 : if (GET_CODE (x) == EXPR_LIST
4944 : 509 : && REG_P (XEXP (x, 0))
4945 : 509 : && XEXP (x, 1) == const0_rtx)
4946 : : container_in_reg = true;
4947 : : }
4948 : :
4949 : 680 : need_temp = (!container_in_reg
4950 : 1150 : && ((needed_intregs && TYPE_ALIGN (type) > 64)
4951 : 680 : || TYPE_ALIGN (type) > 128));
4952 : :
4953 : : /* In case we are passing structure, verify that it is consecutive block
4954 : : on the register save area. If not we need to do moves. */
4955 : 680 : if (!need_temp && !container_in_reg)
4956 : : {
4957 : : /* Verify that all registers are strictly consecutive */
4958 : 966 : if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
4959 : : {
4960 : : int i;
4961 : :
4962 : 815 : for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
4963 : : {
4964 : 529 : rtx slot = XVECEXP (container, 0, i);
4965 : 529 : if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
4966 : 529 : || INTVAL (XEXP (slot, 1)) != i * 16)
4967 : : need_temp = true;
4968 : : }
4969 : : }
4970 : : else
4971 : : {
4972 : : int i;
4973 : :
4974 : 1120 : for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
4975 : : {
4976 : 726 : rtx slot = XVECEXP (container, 0, i);
4977 : 726 : if (REGNO (XEXP (slot, 0)) != (unsigned int) i
4978 : 726 : || INTVAL (XEXP (slot, 1)) != i * 8)
4979 : : need_temp = true;
4980 : : }
4981 : : }
4982 : : }
4983 : 28561 : if (!need_temp)
4984 : : {
4985 : : int_addr = addr;
4986 : : sse_addr = addr;
4987 : : }
4988 : : else
4989 : : {
4990 : 877 : int_addr = create_tmp_var (ptr_type_node, "int_addr");
4991 : 877 : sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
4992 : : }
4993 : :
4994 : : /* First ensure that we fit completely in registers. */
4995 : 28561 : if (needed_intregs)
4996 : : {
4997 : 17897 : t = build_int_cst (TREE_TYPE (gpr),
4998 : 17897 : (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
4999 : 17897 : t = build2 (GE_EXPR, boolean_type_node, gpr, t);
5000 : 17897 : t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
5001 : 17897 : t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
5002 : 17897 : gimplify_and_add (t, pre_p);
5003 : : }
5004 : 28561 : if (needed_sseregs)
5005 : : {
5006 : 11056 : t = build_int_cst (TREE_TYPE (fpr),
5007 : : (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
5008 : 11056 : + X86_64_REGPARM_MAX * 8);
5009 : 11056 : t = build2 (GE_EXPR, boolean_type_node, fpr, t);
5010 : 11056 : t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
5011 : 11056 : t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
5012 : 11056 : gimplify_and_add (t, pre_p);
5013 : : }
5014 : :
5015 : : /* Compute index to start of area used for integer regs. */
5016 : 28561 : if (needed_intregs)
5017 : : {
5018 : : /* int_addr = gpr + sav; */
5019 : 17897 : t = fold_build_pointer_plus (sav, gpr);
5020 : 17897 : gimplify_assign (int_addr, t, pre_p);
5021 : : }
5022 : 28561 : if (needed_sseregs)
5023 : : {
5024 : : /* sse_addr = fpr + sav; */
5025 : 11056 : t = fold_build_pointer_plus (sav, fpr);
5026 : 11056 : gimplify_assign (sse_addr, t, pre_p);
5027 : : }
5028 : 28561 : if (need_temp)
5029 : : {
5030 : 877 : int i, prev_size = 0;
5031 : 877 : tree temp = create_tmp_var (type, "va_arg_tmp");
5032 : 877 : TREE_ADDRESSABLE (temp) = 1;
5033 : :
5034 : : /* addr = &temp; */
5035 : 877 : t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
5036 : 877 : gimplify_assign (addr, t, pre_p);
5037 : :
5038 : 2241 : for (i = 0; i < XVECLEN (container, 0); i++)
5039 : : {
5040 : 1364 : rtx slot = XVECEXP (container, 0, i);
5041 : 1364 : rtx reg = XEXP (slot, 0);
5042 : 1364 : machine_mode mode = GET_MODE (reg);
5043 : 1364 : tree piece_type;
5044 : 1364 : tree addr_type;
5045 : 1364 : tree daddr_type;
5046 : 1364 : tree src_addr, src;
5047 : 1364 : int src_offset;
5048 : 1364 : tree dest_addr, dest;
5049 : 1364 : int cur_size = GET_MODE_SIZE (mode);
5050 : :
5051 : 1364 : gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
5052 : 1364 : prev_size = INTVAL (XEXP (slot, 1));
5053 : 1364 : if (prev_size + cur_size > size)
5054 : : {
5055 : 30 : cur_size = size - prev_size;
5056 : 30 : unsigned int nbits = cur_size * BITS_PER_UNIT;
5057 : 30 : if (!int_mode_for_size (nbits, 1).exists (&mode))
5058 : 10 : mode = QImode;
5059 : : }
5060 : 1364 : piece_type = lang_hooks.types.type_for_mode (mode, 1);
5061 : 1364 : if (mode == GET_MODE (reg))
5062 : 1334 : addr_type = build_pointer_type (piece_type);
5063 : : else
5064 : 30 : addr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
5065 : : true);
5066 : 1364 : daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
5067 : : true);
5068 : :
5069 : 1364 : if (SSE_REGNO_P (REGNO (reg)))
5070 : : {
5071 : 534 : src_addr = sse_addr;
5072 : 534 : src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
5073 : : }
5074 : : else
5075 : : {
5076 : 830 : src_addr = int_addr;
5077 : 830 : src_offset = REGNO (reg) * 8;
5078 : : }
5079 : 1364 : src_addr = fold_convert (addr_type, src_addr);
5080 : 1364 : src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset);
5081 : :
5082 : 1364 : dest_addr = fold_convert (daddr_type, addr);
5083 : 1364 : dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size);
5084 : 2728 : if (cur_size == GET_MODE_SIZE (mode))
5085 : : {
5086 : 1354 : src = build_va_arg_indirect_ref (src_addr);
5087 : 1354 : dest = build_va_arg_indirect_ref (dest_addr);
5088 : :
5089 : 1354 : gimplify_assign (dest, src, pre_p);
5090 : : }
5091 : : else
5092 : : {
5093 : 10 : tree copy
5094 : 20 : = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
5095 : : 3, dest_addr, src_addr,
5096 : 10 : size_int (cur_size));
5097 : 10 : gimplify_and_add (copy, pre_p);
5098 : : }
5099 : 1364 : prev_size += cur_size;
5100 : : }
5101 : : }
5102 : :
5103 : 28561 : if (needed_intregs)
5104 : : {
5105 : 17897 : t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
5106 : 17897 : build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
5107 : 17897 : gimplify_assign (gpr, t, pre_p);
5108 : : /* The GPR save area guarantees only 8-byte alignment. */
5109 : 17897 : if (!need_temp)
5110 : 17093 : type_align = MIN (type_align, 64);
5111 : : }
5112 : :
5113 : 28561 : if (needed_sseregs)
5114 : : {
5115 : 11056 : t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
5116 : 11056 : build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
5117 : 11056 : gimplify_assign (unshare_expr (fpr), t, pre_p);
5118 : : }
5119 : :
5120 : 28561 : gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
5121 : :
5122 : 28561 : gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
5123 : : }
5124 : :
5125 : : /* ... otherwise out of the overflow area. */
5126 : :
5127 : : /* When we align parameter on stack for caller, if the parameter
5128 : : alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
5129 : : aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee
5130 : : here with caller. */
5131 : 51656 : arg_boundary = ix86_function_arg_boundary (VOIDmode, type);
5132 : 51656 : if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
5133 : : arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
5134 : :
5135 : : /* Care for on-stack alignment if needed. */
5136 : 51656 : if (arg_boundary <= 64 || size == 0)
5137 : 34615 : t = ovf;
5138 : : else
5139 : : {
5140 : 17041 : HOST_WIDE_INT align = arg_boundary / 8;
5141 : 17041 : t = fold_build_pointer_plus_hwi (ovf, align - 1);
5142 : 17041 : t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
5143 : 17041 : build_int_cst (TREE_TYPE (t), -align));
5144 : : }
5145 : :
5146 : 51656 : gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
5147 : 51656 : gimplify_assign (addr, t, pre_p);
5148 : :
5149 : 51656 : t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD);
5150 : 51656 : gimplify_assign (unshare_expr (ovf), t, pre_p);
5151 : :
5152 : 51656 : if (container)
5153 : 28561 : gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
5154 : :
5155 : 51656 : type = build_aligned_type (type, type_align);
5156 : 51656 : ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
5157 : 51656 : addr = fold_convert (ptrtype, addr);
5158 : :
5159 : 51656 : if (indirect_p)
5160 : 103 : addr = build_va_arg_indirect_ref (addr);
5161 : 51656 : return build_va_arg_indirect_ref (addr);
5162 : : }
5163 : :
5164 : : /* Return true if OPNUM's MEM should be matched
5165 : : in movabs* patterns. */
5166 : :
5167 : : bool
5168 : 18093 : ix86_check_movabs (rtx insn, int opnum)
5169 : : {
5170 : 18093 : rtx set, mem;
5171 : :
5172 : 18093 : set = PATTERN (insn);
5173 : 18093 : if (GET_CODE (set) == PARALLEL)
5174 : 0 : set = XVECEXP (set, 0, 0);
5175 : 18093 : gcc_assert (GET_CODE (set) == SET);
5176 : 18093 : mem = XEXP (set, opnum);
5177 : 18093 : while (SUBREG_P (mem))
5178 : 0 : mem = SUBREG_REG (mem);
5179 : 18093 : gcc_assert (MEM_P (mem));
5180 : 18093 : return volatile_ok || !MEM_VOLATILE_P (mem);
5181 : : }
5182 : :
5183 : : /* Return true if XVECEXP idx of INSN satisfies MOVS arguments. */
5184 : : bool
5185 : 363101 : ix86_check_movs (rtx insn, int idx)
5186 : : {
5187 : 363101 : rtx pat = PATTERN (insn);
5188 : 363101 : gcc_assert (GET_CODE (pat) == PARALLEL);
5189 : :
5190 : 363101 : rtx set = XVECEXP (pat, 0, idx);
5191 : 363101 : gcc_assert (GET_CODE (set) == SET);
5192 : :
5193 : 363101 : rtx dst = SET_DEST (set);
5194 : 363101 : gcc_assert (MEM_P (dst));
5195 : :
5196 : 363101 : rtx src = SET_SRC (set);
5197 : 363101 : gcc_assert (MEM_P (src));
5198 : :
5199 : 363101 : return (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (dst))
5200 : 726202 : && (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (src))
5201 : 30 : || Pmode == word_mode));
5202 : : }
5203 : :
5204 : : /* Return false if INSN contains a MEM with a non-default address space. */
5205 : : bool
5206 : 66582 : ix86_check_no_addr_space (rtx insn)
5207 : : {
5208 : 66582 : subrtx_var_iterator::array_type array;
5209 : 1465246 : FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), ALL)
5210 : : {
5211 : 1398664 : rtx x = *iter;
5212 : 1531828 : if (MEM_P (x) && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x)))
5213 : 0 : return false;
5214 : : }
5215 : 66582 : return true;
5216 : 66582 : }
5217 : :
5218 : : /* Initialize the table of extra 80387 mathematical constants. */
5219 : :
5220 : : static void
5221 : 2418 : init_ext_80387_constants (void)
5222 : : {
5223 : 2418 : static const char * cst[5] =
5224 : : {
5225 : : "0.3010299956639811952256464283594894482", /* 0: fldlg2 */
5226 : : "0.6931471805599453094286904741849753009", /* 1: fldln2 */
5227 : : "1.4426950408889634073876517827983434472", /* 2: fldl2e */
5228 : : "3.3219280948873623478083405569094566090", /* 3: fldl2t */
5229 : : "3.1415926535897932385128089594061862044", /* 4: fldpi */
5230 : : };
5231 : 2418 : int i;
5232 : :
5233 : 14508 : for (i = 0; i < 5; i++)
5234 : : {
5235 : 12090 : real_from_string (&ext_80387_constants_table[i], cst[i]);
5236 : : /* Ensure each constant is rounded to XFmode precision. */
5237 : 12090 : real_convert (&ext_80387_constants_table[i],
5238 : 24180 : XFmode, &ext_80387_constants_table[i]);
5239 : : }
5240 : :
5241 : 2418 : ext_80387_constants_init = 1;
5242 : 2418 : }
5243 : :
5244 : : /* Return non-zero if the constant is something that
5245 : : can be loaded with a special instruction. */
5246 : :
5247 : : int
5248 : 5082875 : standard_80387_constant_p (rtx x)
5249 : : {
5250 : 5082875 : machine_mode mode = GET_MODE (x);
5251 : :
5252 : 5082875 : const REAL_VALUE_TYPE *r;
5253 : :
5254 : 5082875 : if (!(CONST_DOUBLE_P (x) && X87_FLOAT_MODE_P (mode)))
5255 : : return -1;
5256 : :
5257 : 4613673 : if (x == CONST0_RTX (mode))
5258 : : return 1;
5259 : 2089186 : if (x == CONST1_RTX (mode))
5260 : : return 2;
5261 : :
5262 : 1227630 : r = CONST_DOUBLE_REAL_VALUE (x);
5263 : :
5264 : : /* For XFmode constants, try to find a special 80387 instruction when
5265 : : optimizing for size or on those CPUs that benefit from them. */
5266 : 1227630 : if (mode == XFmode
5267 : 802964 : && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS)
5268 : 2030594 : && !flag_rounding_math)
5269 : : {
5270 : 795365 : int i;
5271 : :
5272 : 795365 : if (! ext_80387_constants_init)
5273 : 2411 : init_ext_80387_constants ();
5274 : :
5275 : 4761630 : for (i = 0; i < 5; i++)
5276 : 3975144 : if (real_identical (r, &ext_80387_constants_table[i]))
5277 : 8879 : return i + 3;
5278 : : }
5279 : :
5280 : : /* Load of the constant -0.0 or -1.0 will be split as
5281 : : fldz;fchs or fld1;fchs sequence. */
5282 : 1218751 : if (real_isnegzero (r))
5283 : : return 8;
5284 : 1202762 : if (real_identical (r, &dconstm1))
5285 : 301008 : return 9;
5286 : :
5287 : : return 0;
5288 : : }
5289 : :
5290 : : /* Return the opcode of the special instruction to be used to load
5291 : : the constant X. */
5292 : :
5293 : : const char *
5294 : 54385 : standard_80387_constant_opcode (rtx x)
5295 : : {
5296 : 54385 : switch (standard_80387_constant_p (x))
5297 : : {
5298 : : case 1:
5299 : : return "fldz";
5300 : 33614 : case 2:
5301 : 33614 : return "fld1";
5302 : 1 : case 3:
5303 : 1 : return "fldlg2";
5304 : 10 : case 4:
5305 : 10 : return "fldln2";
5306 : 12 : case 5:
5307 : 12 : return "fldl2e";
5308 : 2 : case 6:
5309 : 2 : return "fldl2t";
5310 : 190 : case 7:
5311 : 190 : return "fldpi";
5312 : 0 : case 8:
5313 : 0 : case 9:
5314 : 0 : return "#";
5315 : 0 : default:
5316 : 0 : gcc_unreachable ();
5317 : : }
5318 : : }
5319 : :
5320 : : /* Return the CONST_DOUBLE representing the 80387 constant that is
5321 : : loaded by the specified special instruction. The argument IDX
5322 : : matches the return value from standard_80387_constant_p. */
5323 : :
5324 : : rtx
5325 : 24 : standard_80387_constant_rtx (int idx)
5326 : : {
5327 : 24 : int i;
5328 : :
5329 : 24 : if (! ext_80387_constants_init)
5330 : 7 : init_ext_80387_constants ();
5331 : :
5332 : 24 : switch (idx)
5333 : : {
5334 : 24 : case 3:
5335 : 24 : case 4:
5336 : 24 : case 5:
5337 : 24 : case 6:
5338 : 24 : case 7:
5339 : 24 : i = idx - 3;
5340 : 24 : break;
5341 : :
5342 : 0 : default:
5343 : 0 : gcc_unreachable ();
5344 : : }
5345 : :
5346 : 24 : return const_double_from_real_value (ext_80387_constants_table[i],
5347 : 24 : XFmode);
5348 : : }
5349 : :
5350 : : /* Return 1 if X is all bits 0, 2 if X is all bits 1
5351 : : and 3 if X is all bits 1 with zero extend
5352 : : in supported SSE/AVX vector mode. */
5353 : :
5354 : : int
5355 : 50556581 : standard_sse_constant_p (rtx x, machine_mode pred_mode)
5356 : : {
5357 : 50556581 : machine_mode mode;
5358 : :
5359 : 50556581 : if (!TARGET_SSE)
5360 : : return 0;
5361 : :
5362 : 50394517 : mode = GET_MODE (x);
5363 : :
5364 : 50394517 : if (x == const0_rtx || const0_operand (x, mode))
5365 : 11400910 : return 1;
5366 : :
5367 : 38993607 : if (x == constm1_rtx
5368 : 38845235 : || vector_all_ones_operand (x, mode)
5369 : 77370968 : || ((GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
5370 : 32353543 : || GET_MODE_CLASS (pred_mode) == MODE_VECTOR_FLOAT)
5371 : 6023818 : && float_vector_all_ones_operand (x, mode)))
5372 : : {
5373 : : /* VOIDmode integer constant, get mode from the predicate. */
5374 : 618292 : if (mode == VOIDmode)
5375 : 148372 : mode = pred_mode;
5376 : :
5377 : 1236584 : switch (GET_MODE_SIZE (mode))
5378 : : {
5379 : 29636 : case 64:
5380 : 29636 : if (TARGET_AVX512F && TARGET_EVEX512)
5381 : : return 2;
5382 : : break;
5383 : 39758 : case 32:
5384 : 39758 : if (TARGET_AVX2)
5385 : : return 2;
5386 : : break;
5387 : 537944 : case 16:
5388 : 537944 : if (TARGET_SSE2)
5389 : : return 2;
5390 : : break;
5391 : 0 : case 0:
5392 : : /* VOIDmode */
5393 : 0 : gcc_unreachable ();
5394 : : default:
5395 : : break;
5396 : : }
5397 : : }
5398 : :
5399 : 38386982 : if (vector_all_ones_zero_extend_half_operand (x, mode)
5400 : 38386982 : || vector_all_ones_zero_extend_quarter_operand (x, mode))
5401 : 686 : return 3;
5402 : :
5403 : : return 0;
5404 : : }
5405 : :
5406 : : /* Return the opcode of the special instruction to be used to load
5407 : : the constant operands[1] into operands[0]. */
5408 : :
5409 : : const char *
5410 : 449324 : standard_sse_constant_opcode (rtx_insn *insn, rtx *operands)
5411 : : {
5412 : 449324 : machine_mode mode;
5413 : 449324 : rtx x = operands[1];
5414 : :
5415 : 449324 : gcc_assert (TARGET_SSE);
5416 : :
5417 : 449324 : mode = GET_MODE (x);
5418 : :
5419 : 449324 : if (x == const0_rtx || const0_operand (x, mode))
5420 : : {
5421 : 439018 : switch (get_attr_mode (insn))
5422 : : {
5423 : 422441 : case MODE_TI:
5424 : 422441 : if (!EXT_REX_SSE_REG_P (operands[0]))
5425 : : return "%vpxor\t%0, %d0";
5426 : : /* FALLTHRU */
5427 : 5523 : case MODE_XI:
5428 : 5523 : case MODE_OI:
5429 : 5523 : if (EXT_REX_SSE_REG_P (operands[0]))
5430 : : {
5431 : 70 : if (TARGET_AVX512VL)
5432 : : return "vpxord\t%x0, %x0, %x0";
5433 : 22 : else if (TARGET_EVEX512)
5434 : : return "vpxord\t%g0, %g0, %g0";
5435 : : else
5436 : 0 : gcc_unreachable ();
5437 : : }
5438 : : return "vpxor\t%x0, %x0, %x0";
5439 : :
5440 : 1986 : case MODE_V2DF:
5441 : 1986 : if (!EXT_REX_SSE_REG_P (operands[0]))
5442 : : return "%vxorpd\t%0, %d0";
5443 : : /* FALLTHRU */
5444 : 805 : case MODE_V8DF:
5445 : 805 : case MODE_V4DF:
5446 : 805 : if (EXT_REX_SSE_REG_P (operands[0]))
5447 : : {
5448 : 4 : if (TARGET_AVX512DQ)
5449 : : {
5450 : 0 : if (TARGET_AVX512VL)
5451 : : return "vxorpd\t%x0, %x0, %x0";
5452 : 0 : else if (TARGET_EVEX512)
5453 : : return "vxorpd\t%g0, %g0, %g0";
5454 : : else
5455 : 0 : gcc_unreachable ();
5456 : : }
5457 : : else
5458 : : {
5459 : 4 : if (TARGET_AVX512VL)
5460 : : return "vpxorq\t%x0, %x0, %x0";
5461 : 4 : else if (TARGET_EVEX512)
5462 : : return "vpxorq\t%g0, %g0, %g0";
5463 : : else
5464 : 0 : gcc_unreachable ();
5465 : : }
5466 : : }
5467 : : return "vxorpd\t%x0, %x0, %x0";
5468 : :
5469 : 6425 : case MODE_V4SF:
5470 : 6425 : if (!EXT_REX_SSE_REG_P (operands[0]))
5471 : : return "%vxorps\t%0, %d0";
5472 : : /* FALLTHRU */
5473 : 1865 : case MODE_V16SF:
5474 : 1865 : case MODE_V8SF:
5475 : 1865 : if (EXT_REX_SSE_REG_P (operands[0]))
5476 : : {
5477 : 26 : if (TARGET_AVX512DQ)
5478 : : {
5479 : 21 : if (TARGET_AVX512VL)
5480 : : return "vxorps\t%x0, %x0, %x0";
5481 : 0 : else if (TARGET_EVEX512)
5482 : : return "vxorps\t%g0, %g0, %g0";
5483 : : else
5484 : 0 : gcc_unreachable ();
5485 : : }
5486 : : else
5487 : : {
5488 : 5 : if (TARGET_AVX512VL)
5489 : : return "vpxord\t%x0, %x0, %x0";
5490 : 2 : else if (TARGET_EVEX512)
5491 : : return "vpxord\t%g0, %g0, %g0";
5492 : : else
5493 : 0 : gcc_unreachable ();
5494 : : }
5495 : : }
5496 : : return "vxorps\t%x0, %x0, %x0";
5497 : :
5498 : 0 : default:
5499 : 0 : gcc_unreachable ();
5500 : : }
5501 : : }
5502 : 10306 : else if (x == constm1_rtx
5503 : 10295 : || vector_all_ones_operand (x, mode)
5504 : 10379 : || (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
5505 : 51 : && float_vector_all_ones_operand (x, mode)))
5506 : : {
5507 : 10284 : enum attr_mode insn_mode = get_attr_mode (insn);
5508 : :
5509 : 10284 : switch (insn_mode)
5510 : : {
5511 : 2 : case MODE_XI:
5512 : 2 : case MODE_V8DF:
5513 : 2 : case MODE_V16SF:
5514 : 2 : gcc_assert (TARGET_AVX512F && TARGET_EVEX512);
5515 : : return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
5516 : :
5517 : 964 : case MODE_OI:
5518 : 964 : case MODE_V4DF:
5519 : 964 : case MODE_V8SF:
5520 : 964 : gcc_assert (TARGET_AVX2);
5521 : : /* FALLTHRU */
5522 : 10282 : case MODE_TI:
5523 : 10282 : case MODE_V2DF:
5524 : 10282 : case MODE_V4SF:
5525 : 10282 : gcc_assert (TARGET_SSE2);
5526 : 10282 : if (EXT_REX_SSE_REG_P (operands[0]))
5527 : : {
5528 : 2 : if (TARGET_AVX512VL)
5529 : : return "vpternlogd\t{$0xFF, %0, %0, %0|%0, %0, %0, 0xFF}";
5530 : 0 : else if (TARGET_EVEX512)
5531 : : return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
5532 : : else
5533 : 0 : gcc_unreachable ();
5534 : : }
5535 : 10280 : return (TARGET_AVX
5536 : 10280 : ? "vpcmpeqd\t%0, %0, %0"
5537 : 10280 : : "pcmpeqd\t%0, %0");
5538 : :
5539 : 0 : default:
5540 : 0 : gcc_unreachable ();
5541 : : }
5542 : : }
5543 : 22 : else if (vector_all_ones_zero_extend_half_operand (x, mode))
5544 : : {
5545 : 40 : if (GET_MODE_SIZE (mode) == 64)
5546 : : {
5547 : 5 : gcc_assert (TARGET_AVX512F && TARGET_EVEX512);
5548 : : return "vpcmpeqd\t%t0, %t0, %t0";
5549 : : }
5550 : 30 : else if (GET_MODE_SIZE (mode) == 32)
5551 : : {
5552 : 15 : gcc_assert (TARGET_AVX);
5553 : : return "vpcmpeqd\t%x0, %x0, %x0";
5554 : : }
5555 : 0 : gcc_unreachable ();
5556 : : }
5557 : 2 : else if (vector_all_ones_zero_extend_quarter_operand (x, mode))
5558 : : {
5559 : 2 : gcc_assert (TARGET_AVX512F && TARGET_EVEX512);
5560 : : return "vpcmpeqd\t%x0, %x0, %x0";
5561 : : }
5562 : :
5563 : 0 : gcc_unreachable ();
5564 : : }
5565 : :
5566 : : /* Returns true if INSN can be transformed from a memory load
5567 : : to a supported FP constant load. */
5568 : :
5569 : : bool
5570 : 2208960 : ix86_standard_x87sse_constant_load_p (const rtx_insn *insn, rtx dst)
5571 : : {
5572 : 2208960 : rtx src = find_constant_src (insn);
5573 : :
5574 : 2208960 : gcc_assert (REG_P (dst));
5575 : :
5576 : 2208960 : if (src == NULL
5577 : 620428 : || (SSE_REGNO_P (REGNO (dst))
5578 : 489054 : && standard_sse_constant_p (src, GET_MODE (dst)) != 1)
5579 : 164611 : || (!TARGET_AVX512VL
5580 : 164550 : && EXT_REX_SSE_REGNO_P (REGNO (dst))
5581 : 0 : && standard_sse_constant_p (src, GET_MODE (dst)) == 1)
5582 : 2373571 : || (STACK_REGNO_P (REGNO (dst))
5583 : 131374 : && standard_80387_constant_p (src) < 1))
5584 : 2133753 : return false;
5585 : :
5586 : : return true;
5587 : : }
5588 : :
5589 : : /* Predicate for pre-reload splitters with associated instructions,
5590 : : which can match any time before the split1 pass (usually combine),
5591 : : then are unconditionally split in that pass and should not be
5592 : : matched again afterwards. */
5593 : :
5594 : : bool
5595 : 16599272 : ix86_pre_reload_split (void)
5596 : : {
5597 : 16599272 : return (can_create_pseudo_p ()
5598 : 25050033 : && !(cfun->curr_properties & PROP_rtl_split_insns));
5599 : : }
5600 : :
5601 : : /* Return the opcode of the TYPE_SSEMOV instruction. To move from
5602 : : or to xmm16-xmm31/ymm16-ymm31 registers, we either require
5603 : : TARGET_AVX512VL or it is a register to register move which can
5604 : : be done with zmm register move. */
5605 : :
5606 : : static const char *
5607 : 3779594 : ix86_get_ssemov (rtx *operands, unsigned size,
5608 : : enum attr_mode insn_mode, machine_mode mode)
5609 : : {
5610 : 3779594 : char buf[128];
5611 : 3779594 : bool misaligned_p = (misaligned_operand (operands[0], mode)
5612 : 3779594 : || misaligned_operand (operands[1], mode));
5613 : 3779594 : bool evex_reg_p = (size == 64
5614 : 3700613 : || EXT_REX_SSE_REG_P (operands[0])
5615 : 7479581 : || EXT_REX_SSE_REG_P (operands[1]));
5616 : :
5617 : 3779594 : bool egpr_p = (TARGET_APX_EGPR
5618 : 3779594 : && (x86_extended_rex2reg_mentioned_p (operands[0])
5619 : 115 : || x86_extended_rex2reg_mentioned_p (operands[1])));
5620 : 193 : bool egpr_vl = egpr_p && TARGET_AVX512VL;
5621 : :
5622 : 3779594 : machine_mode scalar_mode;
5623 : :
5624 : 3779594 : const char *opcode = NULL;
5625 : 3779594 : enum
5626 : : {
5627 : : opcode_int,
5628 : : opcode_float,
5629 : : opcode_double
5630 : 3779594 : } type = opcode_int;
5631 : :
5632 : 3779594 : switch (insn_mode)
5633 : : {
5634 : : case MODE_V16SF:
5635 : : case MODE_V8SF:
5636 : : case MODE_V4SF:
5637 : : scalar_mode = E_SFmode;
5638 : : type = opcode_float;
5639 : : break;
5640 : 207223 : case MODE_V8DF:
5641 : 207223 : case MODE_V4DF:
5642 : 207223 : case MODE_V2DF:
5643 : 207223 : scalar_mode = E_DFmode;
5644 : 207223 : type = opcode_double;
5645 : 207223 : break;
5646 : 1327010 : case MODE_XI:
5647 : 1327010 : case MODE_OI:
5648 : 1327010 : case MODE_TI:
5649 : 1327010 : scalar_mode = GET_MODE_INNER (mode);
5650 : : break;
5651 : 0 : default:
5652 : 0 : gcc_unreachable ();
5653 : : }
5654 : :
5655 : : /* NB: To move xmm16-xmm31/ymm16-ymm31 registers without AVX512VL,
5656 : : we can only use zmm register move without memory operand. */
5657 : 3779594 : if (evex_reg_p
5658 : 80285 : && !TARGET_AVX512VL
5659 : 3825035 : && GET_MODE_SIZE (mode) < 64)
5660 : : {
5661 : : /* NB: Even though ix86_hard_regno_mode_ok doesn't allow
5662 : : xmm16-xmm31 nor ymm16-ymm31 in 128/256 bit modes when
5663 : : AVX512VL is disabled, LRA can still generate reg to
5664 : : reg moves with xmm16-xmm31 and ymm16-ymm31 in 128/256 bit
5665 : : modes. */
5666 : 0 : if (memory_operand (operands[0], mode)
5667 : 0 : || memory_operand (operands[1], mode))
5668 : 0 : gcc_unreachable ();
5669 : 0 : size = 64;
5670 : : /* We need TARGET_EVEX512 to move into zmm register. */
5671 : 0 : gcc_assert (TARGET_EVEX512);
5672 : 0 : switch (type)
5673 : : {
5674 : 0 : case opcode_int:
5675 : 0 : if (scalar_mode == E_HFmode || scalar_mode == E_BFmode)
5676 : 0 : opcode = (misaligned_p
5677 : 0 : ? (TARGET_AVX512BW ? "vmovdqu16" : "vmovdqu64")
5678 : : : "vmovdqa64");
5679 : : else
5680 : 0 : opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32";
5681 : : break;
5682 : 0 : case opcode_float:
5683 : 0 : opcode = misaligned_p ? "vmovups" : "vmovaps";
5684 : : break;
5685 : 0 : case opcode_double:
5686 : 0 : opcode = misaligned_p ? "vmovupd" : "vmovapd";
5687 : : break;
5688 : : }
5689 : : }
5690 : 3779594 : else if (SCALAR_FLOAT_MODE_P (scalar_mode))
5691 : : {
5692 : 2630370 : switch (scalar_mode)
5693 : : {
5694 : 35745 : case E_HFmode:
5695 : 35745 : case E_BFmode:
5696 : 35745 : if (evex_reg_p || egpr_vl)
5697 : 11056 : opcode = (misaligned_p
5698 : 164 : ? (TARGET_AVX512BW
5699 : : ? "vmovdqu16"
5700 : : : "vmovdqu64")
5701 : : : "vmovdqa64");
5702 : 24689 : else if (egpr_p)
5703 : 0 : opcode = (misaligned_p
5704 : 0 : ? (TARGET_AVX512BW
5705 : 0 : ? "vmovdqu16"
5706 : : : "%vmovups")
5707 : : : "%vmovaps");
5708 : : else
5709 : 24689 : opcode = (misaligned_p
5710 : 24689 : ? (TARGET_AVX512BW
5711 : 471 : ? "vmovdqu16"
5712 : : : "%vmovdqu")
5713 : : : "%vmovdqa");
5714 : : break;
5715 : 2245361 : case E_SFmode:
5716 : 2245361 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5717 : : break;
5718 : 207223 : case E_DFmode:
5719 : 207223 : opcode = misaligned_p ? "%vmovupd" : "%vmovapd";
5720 : : break;
5721 : 142041 : case E_TFmode:
5722 : 142041 : if (evex_reg_p || egpr_vl)
5723 : 14 : opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
5724 : 142027 : else if (egpr_p)
5725 : 0 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5726 : : else
5727 : 142027 : opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
5728 : : break;
5729 : 0 : default:
5730 : 0 : gcc_unreachable ();
5731 : : }
5732 : : }
5733 : 1149224 : else if (SCALAR_INT_MODE_P (scalar_mode))
5734 : : {
5735 : 1149224 : switch (scalar_mode)
5736 : : {
5737 : 46304 : case E_QImode:
5738 : 46304 : if (evex_reg_p || egpr_vl)
5739 : 5788 : opcode = (misaligned_p
5740 : 5788 : ? (TARGET_AVX512BW
5741 : 2390 : ? "vmovdqu8"
5742 : : : "vmovdqu64")
5743 : : : "vmovdqa64");
5744 : 40516 : else if (egpr_p)
5745 : 30 : opcode = (misaligned_p
5746 : 0 : ? (TARGET_AVX512BW
5747 : : ? "vmovdqu8"
5748 : : : "%vmovups")
5749 : : : "%vmovaps");
5750 : : else
5751 : 40486 : opcode = (misaligned_p
5752 : 8923 : ? (TARGET_AVX512BW
5753 : : ? "vmovdqu8"
5754 : : : "%vmovdqu")
5755 : : : "%vmovdqa");
5756 : : break;
5757 : 39685 : case E_HImode:
5758 : 39685 : if (evex_reg_p || egpr_vl)
5759 : 3185 : opcode = (misaligned_p
5760 : 158 : ? (TARGET_AVX512BW
5761 : : ? "vmovdqu16"
5762 : : : "vmovdqu64")
5763 : : : "vmovdqa64");
5764 : 36500 : else if (egpr_p)
5765 : 27 : opcode = (misaligned_p
5766 : 27 : ? (TARGET_AVX512BW
5767 : 0 : ? "vmovdqu16"
5768 : : : "%vmovups")
5769 : : : "%vmovaps");
5770 : : else
5771 : 36473 : opcode = (misaligned_p
5772 : 36473 : ? (TARGET_AVX512BW
5773 : 3209 : ? "vmovdqu16"
5774 : : : "%vmovdqu")
5775 : : : "%vmovdqa");
5776 : : break;
5777 : 159933 : case E_SImode:
5778 : 159933 : if (evex_reg_p || egpr_vl)
5779 : 7405 : opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32";
5780 : 152528 : else if (egpr_p)
5781 : 14 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5782 : : else
5783 : 152514 : opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
5784 : : break;
5785 : 892349 : case E_DImode:
5786 : 892349 : case E_TImode:
5787 : 892349 : case E_OImode:
5788 : 892349 : if (evex_reg_p || egpr_vl)
5789 : 17930 : opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
5790 : 874419 : else if (egpr_p)
5791 : 26 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5792 : : else
5793 : 874393 : opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
5794 : : break;
5795 : 10953 : case E_XImode:
5796 : 10953 : opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
5797 : : break;
5798 : 0 : default:
5799 : 0 : gcc_unreachable ();
5800 : : }
5801 : : }
5802 : : else
5803 : 0 : gcc_unreachable ();
5804 : :
5805 : 3779594 : switch (size)
5806 : : {
5807 : 78981 : case 64:
5808 : 78981 : snprintf (buf, sizeof (buf), "%s\t{%%g1, %%g0|%%g0, %%g1}",
5809 : : opcode);
5810 : 78981 : break;
5811 : 85823 : case 32:
5812 : 85823 : snprintf (buf, sizeof (buf), "%s\t{%%t1, %%t0|%%t0, %%t1}",
5813 : : opcode);
5814 : 85823 : break;
5815 : 3614790 : case 16:
5816 : 3614790 : snprintf (buf, sizeof (buf), "%s\t{%%x1, %%x0|%%x0, %%x1}",
5817 : : opcode);
5818 : 3614790 : break;
5819 : 0 : default:
5820 : 0 : gcc_unreachable ();
5821 : : }
5822 : 3779594 : output_asm_insn (buf, operands);
5823 : 3779594 : return "";
5824 : : }
5825 : :
5826 : : /* Return the template of the TYPE_SSEMOV instruction to move
5827 : : operands[1] into operands[0]. */
5828 : :
5829 : : const char *
5830 : 6292476 : ix86_output_ssemov (rtx_insn *insn, rtx *operands)
5831 : : {
5832 : 6292476 : machine_mode mode = GET_MODE (operands[0]);
5833 : 6292476 : if (get_attr_type (insn) != TYPE_SSEMOV
5834 : 6292476 : || mode != GET_MODE (operands[1]))
5835 : 0 : gcc_unreachable ();
5836 : :
5837 : 6292476 : enum attr_mode insn_mode = get_attr_mode (insn);
5838 : :
5839 : 6292476 : switch (insn_mode)
5840 : : {
5841 : 78981 : case MODE_XI:
5842 : 78981 : case MODE_V8DF:
5843 : 78981 : case MODE_V16SF:
5844 : 78981 : return ix86_get_ssemov (operands, 64, insn_mode, mode);
5845 : :
5846 : 85823 : case MODE_OI:
5847 : 85823 : case MODE_V4DF:
5848 : 85823 : case MODE_V8SF:
5849 : 85823 : return ix86_get_ssemov (operands, 32, insn_mode, mode);
5850 : :
5851 : 3614790 : case MODE_TI:
5852 : 3614790 : case MODE_V2DF:
5853 : 3614790 : case MODE_V4SF:
5854 : 3614790 : return ix86_get_ssemov (operands, 16, insn_mode, mode);
5855 : :
5856 : 732855 : case MODE_DI:
5857 : : /* Handle broken assemblers that require movd instead of movq. */
5858 : 732855 : if (GENERAL_REG_P (operands[0]))
5859 : : {
5860 : : if (HAVE_AS_IX86_INTERUNIT_MOVQ)
5861 : : return "%vmovq\t{%1, %q0|%q0, %1}";
5862 : : else
5863 : : return "%vmovd\t{%1, %q0|%q0, %1}";
5864 : : }
5865 : 658267 : else if (GENERAL_REG_P (operands[1]))
5866 : : {
5867 : : if (HAVE_AS_IX86_INTERUNIT_MOVQ)
5868 : : return "%vmovq\t{%q1, %0|%0, %q1}";
5869 : : else
5870 : : return "%vmovd\t{%q1, %0|%0, %q1}";
5871 : : }
5872 : : else
5873 : 446551 : return "%vmovq\t{%1, %0|%0, %1}";
5874 : :
5875 : 239882 : case MODE_SI:
5876 : 239882 : if (GENERAL_REG_P (operands[0]))
5877 : : return "%vmovd\t{%1, %k0|%k0, %1}";
5878 : 182190 : else if (GENERAL_REG_P (operands[1]))
5879 : : return "%vmovd\t{%k1, %0|%0, %k1}";
5880 : : else
5881 : 78296 : return "%vmovd\t{%1, %0|%0, %1}";
5882 : :
5883 : 53391 : case MODE_HI:
5884 : 53391 : if (GENERAL_REG_P (operands[0]))
5885 : : return "vmovw\t{%1, %k0|%k0, %1}";
5886 : 53357 : else if (GENERAL_REG_P (operands[1]))
5887 : : return "vmovw\t{%k1, %0|%0, %k1}";
5888 : : else
5889 : 53270 : return "vmovw\t{%1, %0|%0, %1}";
5890 : :
5891 : 786671 : case MODE_DF:
5892 : 786671 : if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
5893 : : return "vmovsd\t{%d1, %0|%0, %d1}";
5894 : : else
5895 : 785667 : return "%vmovsd\t{%1, %0|%0, %1}";
5896 : :
5897 : 696306 : case MODE_SF:
5898 : 696306 : if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
5899 : : return "vmovss\t{%d1, %0|%0, %d1}";
5900 : : else
5901 : 695512 : return "%vmovss\t{%1, %0|%0, %1}";
5902 : :
5903 : 98 : case MODE_HF:
5904 : 98 : case MODE_BF:
5905 : 98 : if (REG_P (operands[0]) && REG_P (operands[1]))
5906 : : return "vmovsh\t{%d1, %0|%0, %d1}";
5907 : : else
5908 : 0 : return "vmovsh\t{%1, %0|%0, %1}";
5909 : :
5910 : 36 : case MODE_V1DF:
5911 : 36 : gcc_assert (!TARGET_AVX);
5912 : : return "movlpd\t{%1, %0|%0, %1}";
5913 : :
5914 : 3643 : case MODE_V2SF:
5915 : 3643 : if (TARGET_AVX && REG_P (operands[0]))
5916 : : return "vmovlps\t{%1, %d0|%d0, %1}";
5917 : : else
5918 : 3563 : return "%vmovlps\t{%1, %0|%0, %1}";
5919 : :
5920 : 0 : default:
5921 : 0 : gcc_unreachable ();
5922 : : }
5923 : : }
5924 : :
5925 : : /* Returns true if OP contains a symbol reference */
5926 : :
5927 : : bool
5928 : 548103443 : symbolic_reference_mentioned_p (rtx op)
5929 : : {
5930 : 548103443 : const char *fmt;
5931 : 548103443 : int i;
5932 : :
5933 : 548103443 : if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
5934 : : return true;
5935 : :
5936 : 414486343 : fmt = GET_RTX_FORMAT (GET_CODE (op));
5937 : 703970475 : for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
5938 : : {
5939 : 561496051 : if (fmt[i] == 'E')
5940 : : {
5941 : 1955889 : int j;
5942 : :
5943 : 3901355 : for (j = XVECLEN (op, i) - 1; j >= 0; j--)
5944 : 3224937 : if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
5945 : : return true;
5946 : : }
5947 : :
5948 : 559540162 : else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
5949 : : return true;
5950 : : }
5951 : :
5952 : : return false;
5953 : : }
5954 : :
5955 : : /* Return true if it is appropriate to emit `ret' instructions in the
5956 : : body of a function. Do this only if the epilogue is simple, needing a
5957 : : couple of insns. Prior to reloading, we can't tell how many registers
5958 : : must be saved, so return false then. Return false if there is no frame
5959 : : marker to de-allocate. */
5960 : :
5961 : : bool
5962 : 0 : ix86_can_use_return_insn_p (void)
5963 : : {
5964 : 0 : if (ix86_function_ms_hook_prologue (current_function_decl))
5965 : : return false;
5966 : :
5967 : 0 : if (ix86_function_naked (current_function_decl))
5968 : : return false;
5969 : :
5970 : : /* Don't use `ret' instruction in interrupt handler. */
5971 : 0 : if (! reload_completed
5972 : 0 : || frame_pointer_needed
5973 : 0 : || cfun->machine->func_type != TYPE_NORMAL)
5974 : : return 0;
5975 : :
5976 : : /* Don't allow more than 32k pop, since that's all we can do
5977 : : with one instruction. */
5978 : 0 : if (crtl->args.pops_args && crtl->args.size >= 32768)
5979 : : return 0;
5980 : :
5981 : 0 : struct ix86_frame &frame = cfun->machine->frame;
5982 : 0 : return (frame.stack_pointer_offset == UNITS_PER_WORD
5983 : 0 : && (frame.nregs + frame.nsseregs) == 0);
5984 : : }
5985 : :
5986 : : /* Return stack frame size. get_frame_size () returns used stack slots
5987 : : during compilation, which may be optimized out later. If stack frame
5988 : : is needed, stack_frame_required should be true. */
5989 : :
5990 : : static HOST_WIDE_INT
5991 : 8032131 : ix86_get_frame_size (void)
5992 : : {
5993 : 8032131 : if (cfun->machine->stack_frame_required)
5994 : 7965596 : return get_frame_size ();
5995 : : else
5996 : : return 0;
5997 : : }
5998 : :
5999 : : /* Value should be nonzero if functions must have frame pointers.
6000 : : Zero means the frame pointer need not be set up (and parms may
6001 : : be accessed via the stack pointer) in functions that seem suitable. */
6002 : :
6003 : : static bool
6004 : 1198199 : ix86_frame_pointer_required (void)
6005 : : {
6006 : : /* If we accessed previous frames, then the generated code expects
6007 : : to be able to access the saved ebp value in our frame. */
6008 : 1198199 : if (cfun->machine->accesses_prev_frame)
6009 : : return true;
6010 : :
6011 : : /* Several x86 os'es need a frame pointer for other reasons,
6012 : : usually pertaining to setjmp. */
6013 : 1198166 : if (SUBTARGET_FRAME_POINTER_REQUIRED)
6014 : : return true;
6015 : :
6016 : : /* For older 32-bit runtimes setjmp requires valid frame-pointer. */
6017 : 1198166 : if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
6018 : : return true;
6019 : :
6020 : : /* Win64 SEH, very large frames need a frame-pointer as maximum stack
6021 : : allocation is 4GB. */
6022 : 1198166 : if (TARGET_64BIT_MS_ABI && ix86_get_frame_size () > SEH_MAX_FRAME_SIZE)
6023 : : return true;
6024 : :
6025 : : /* SSE saves require frame-pointer when stack is misaligned. */
6026 : 1198166 : if (TARGET_64BIT_MS_ABI && ix86_incoming_stack_boundary < 128)
6027 : : return true;
6028 : :
6029 : : /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
6030 : : turns off the frame pointer by default. Turn it back on now if
6031 : : we've not got a leaf function. */
6032 : 1198165 : if (TARGET_OMIT_LEAF_FRAME_POINTER
6033 : 1198165 : && (!crtl->is_leaf
6034 : 0 : || ix86_current_function_calls_tls_descriptor))
6035 : 0 : return true;
6036 : :
6037 : : /* Several versions of mcount for the x86 assumes that there is a
6038 : : frame, so we cannot allow profiling without a frame pointer. */
6039 : 1198165 : if (crtl->profile && !flag_fentry)
6040 : : return true;
6041 : :
6042 : : return false;
6043 : : }
6044 : :
6045 : : /* Record that the current function accesses previous call frames. */
6046 : :
6047 : : void
6048 : 966 : ix86_setup_frame_addresses (void)
6049 : : {
6050 : 966 : cfun->machine->accesses_prev_frame = 1;
6051 : 966 : }
6052 : :
6053 : : #if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)
6054 : : # define USE_HIDDEN_LINKONCE 1
6055 : : #else
6056 : : # define USE_HIDDEN_LINKONCE 0
6057 : : #endif
6058 : :
6059 : : /* Label count for call and return thunks. It is used to make unique
6060 : : labels in call and return thunks. */
6061 : : static int indirectlabelno;
6062 : :
6063 : : /* True if call thunk function is needed. */
6064 : : static bool indirect_thunk_needed = false;
6065 : :
6066 : : /* Bit masks of integer registers, which contain branch target, used
6067 : : by call thunk functions. */
6068 : : static HARD_REG_SET indirect_thunks_used;
6069 : :
6070 : : /* True if return thunk function is needed. */
6071 : : static bool indirect_return_needed = false;
6072 : :
6073 : : /* True if return thunk function via CX is needed. */
6074 : : static bool indirect_return_via_cx;
6075 : :
6076 : : #ifndef INDIRECT_LABEL
6077 : : # define INDIRECT_LABEL "LIND"
6078 : : #endif
6079 : :
6080 : : /* Indicate what prefix is needed for an indirect branch. */
6081 : : enum indirect_thunk_prefix
6082 : : {
6083 : : indirect_thunk_prefix_none,
6084 : : indirect_thunk_prefix_nt
6085 : : };
6086 : :
6087 : : /* Return the prefix needed for an indirect branch INSN. */
6088 : :
6089 : : enum indirect_thunk_prefix
6090 : 67 : indirect_thunk_need_prefix (rtx_insn *insn)
6091 : : {
6092 : 67 : enum indirect_thunk_prefix need_prefix;
6093 : 67 : if ((cfun->machine->indirect_branch_type
6094 : 67 : == indirect_branch_thunk_extern)
6095 : 67 : && ix86_notrack_prefixed_insn_p (insn))
6096 : : {
6097 : : /* NOTRACK prefix is only used with external thunk so that it
6098 : : can be properly updated to support CET at run-time. */
6099 : : need_prefix = indirect_thunk_prefix_nt;
6100 : : }
6101 : : else
6102 : : need_prefix = indirect_thunk_prefix_none;
6103 : 67 : return need_prefix;
6104 : : }
6105 : :
6106 : : /* Fills in the label name that should be used for the indirect thunk. */
6107 : :
6108 : : static void
6109 : 73 : indirect_thunk_name (char name[32], unsigned int regno,
6110 : : enum indirect_thunk_prefix need_prefix,
6111 : : bool ret_p)
6112 : : {
6113 : 73 : if (regno != INVALID_REGNUM && regno != CX_REG && ret_p)
6114 : 0 : gcc_unreachable ();
6115 : :
6116 : 73 : if (USE_HIDDEN_LINKONCE)
6117 : : {
6118 : 73 : const char *prefix;
6119 : :
6120 : 73 : if (need_prefix == indirect_thunk_prefix_nt
6121 : 73 : && regno != INVALID_REGNUM)
6122 : : {
6123 : : /* NOTRACK prefix is only used with external thunk via
6124 : : register so that NOTRACK prefix can be added to indirect
6125 : : branch via register to support CET at run-time. */
6126 : : prefix = "_nt";
6127 : : }
6128 : : else
6129 : 71 : prefix = "";
6130 : :
6131 : 73 : const char *ret = ret_p ? "return" : "indirect";
6132 : :
6133 : 73 : if (regno != INVALID_REGNUM)
6134 : : {
6135 : 55 : const char *reg_prefix;
6136 : 55 : if (LEGACY_INT_REGNO_P (regno))
6137 : 53 : reg_prefix = TARGET_64BIT ? "r" : "e";
6138 : : else
6139 : : reg_prefix = "";
6140 : 55 : sprintf (name, "__x86_%s_thunk%s_%s%s",
6141 : : ret, prefix, reg_prefix, reg_names[regno]);
6142 : : }
6143 : : else
6144 : 18 : sprintf (name, "__x86_%s_thunk%s", ret, prefix);
6145 : : }
6146 : : else
6147 : : {
6148 : : if (regno != INVALID_REGNUM)
6149 : : ASM_GENERATE_INTERNAL_LABEL (name, "LITR", regno);
6150 : : else
6151 : : {
6152 : : if (ret_p)
6153 : : ASM_GENERATE_INTERNAL_LABEL (name, "LRT", 0);
6154 : : else
6155 : 73 : ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0);
6156 : : }
6157 : : }
6158 : 73 : }
6159 : :
6160 : : /* Output a call and return thunk for indirect branch. If REGNO != -1,
6161 : : the function address is in REGNO and the call and return thunk looks like:
6162 : :
6163 : : call L2
6164 : : L1:
6165 : : pause
6166 : : lfence
6167 : : jmp L1
6168 : : L2:
6169 : : mov %REG, (%sp)
6170 : : ret
6171 : :
6172 : : Otherwise, the function address is on the top of stack and the
6173 : : call and return thunk looks like:
6174 : :
6175 : : call L2
6176 : : L1:
6177 : : pause
6178 : : lfence
6179 : : jmp L1
6180 : : L2:
6181 : : lea WORD_SIZE(%sp), %sp
6182 : : ret
6183 : : */
6184 : :
6185 : : static void
6186 : 38 : output_indirect_thunk (unsigned int regno)
6187 : : {
6188 : 38 : char indirectlabel1[32];
6189 : 38 : char indirectlabel2[32];
6190 : :
6191 : 38 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel1, INDIRECT_LABEL,
6192 : : indirectlabelno++);
6193 : 38 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel2, INDIRECT_LABEL,
6194 : : indirectlabelno++);
6195 : :
6196 : : /* Call */
6197 : 38 : fputs ("\tcall\t", asm_out_file);
6198 : 38 : assemble_name_raw (asm_out_file, indirectlabel2);
6199 : 38 : fputc ('\n', asm_out_file);
6200 : :
6201 : 38 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
6202 : :
6203 : : /* AMD and Intel CPUs prefer each a different instruction as loop filler.
6204 : : Usage of both pause + lfence is compromise solution. */
6205 : 38 : fprintf (asm_out_file, "\tpause\n\tlfence\n");
6206 : :
6207 : : /* Jump. */
6208 : 38 : fputs ("\tjmp\t", asm_out_file);
6209 : 38 : assemble_name_raw (asm_out_file, indirectlabel1);
6210 : 38 : fputc ('\n', asm_out_file);
6211 : :
6212 : 38 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
6213 : :
6214 : : /* The above call insn pushed a word to stack. Adjust CFI info. */
6215 : 38 : if (flag_asynchronous_unwind_tables && dwarf2out_do_frame ())
6216 : : {
6217 : 38 : if (! dwarf2out_do_cfi_asm ())
6218 : : {
6219 : 0 : dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> ();
6220 : 0 : xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
6221 : 0 : xcfi->dw_cfi_oprnd1.dw_cfi_addr = ggc_strdup (indirectlabel2);
6222 : 0 : vec_safe_push (cfun->fde->dw_fde_cfi, xcfi);
6223 : : }
6224 : 38 : dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> ();
6225 : 38 : xcfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
6226 : 38 : xcfi->dw_cfi_oprnd1.dw_cfi_offset = 2 * UNITS_PER_WORD;
6227 : 38 : vec_safe_push (cfun->fde->dw_fde_cfi, xcfi);
6228 : 38 : dwarf2out_emit_cfi (xcfi);
6229 : : }
6230 : :
6231 : 38 : if (regno != INVALID_REGNUM)
6232 : : {
6233 : : /* MOV. */
6234 : 27 : rtx xops[2];
6235 : 27 : xops[0] = gen_rtx_MEM (word_mode, stack_pointer_rtx);
6236 : 27 : xops[1] = gen_rtx_REG (word_mode, regno);
6237 : 27 : output_asm_insn ("mov\t{%1, %0|%0, %1}", xops);
6238 : : }
6239 : : else
6240 : : {
6241 : : /* LEA. */
6242 : 11 : rtx xops[2];
6243 : 11 : xops[0] = stack_pointer_rtx;
6244 : 11 : xops[1] = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
6245 : 11 : output_asm_insn ("lea\t{%E1, %0|%0, %E1}", xops);
6246 : : }
6247 : :
6248 : 38 : fputs ("\tret\n", asm_out_file);
6249 : 38 : if ((ix86_harden_sls & harden_sls_return))
6250 : 1 : fputs ("\tint3\n", asm_out_file);
6251 : 38 : }
6252 : :
6253 : : /* Output a funtion with a call and return thunk for indirect branch.
6254 : : If REGNO != INVALID_REGNUM, the function address is in REGNO.
6255 : : Otherwise, the function address is on the top of stack. Thunk is
6256 : : used for function return if RET_P is true. */
6257 : :
6258 : : static void
6259 : 22 : output_indirect_thunk_function (enum indirect_thunk_prefix need_prefix,
6260 : : unsigned int regno, bool ret_p)
6261 : : {
6262 : 22 : char name[32];
6263 : 22 : tree decl;
6264 : :
6265 : : /* Create __x86_indirect_thunk. */
6266 : 22 : indirect_thunk_name (name, regno, need_prefix, ret_p);
6267 : 22 : decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
6268 : : get_identifier (name),
6269 : : build_function_type_list (void_type_node, NULL_TREE));
6270 : 22 : DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
6271 : : NULL_TREE, void_type_node);
6272 : 22 : TREE_PUBLIC (decl) = 1;
6273 : 22 : TREE_STATIC (decl) = 1;
6274 : 22 : DECL_IGNORED_P (decl) = 1;
6275 : :
6276 : : #if TARGET_MACHO
6277 : : if (TARGET_MACHO)
6278 : : {
6279 : : switch_to_section (darwin_sections[picbase_thunk_section]);
6280 : : fputs ("\t.weak_definition\t", asm_out_file);
6281 : : assemble_name (asm_out_file, name);
6282 : : fputs ("\n\t.private_extern\t", asm_out_file);
6283 : : assemble_name (asm_out_file, name);
6284 : : putc ('\n', asm_out_file);
6285 : : ASM_OUTPUT_LABEL (asm_out_file, name);
6286 : : DECL_WEAK (decl) = 1;
6287 : : }
6288 : : else
6289 : : #endif
6290 : 22 : if (USE_HIDDEN_LINKONCE)
6291 : : {
6292 : 22 : cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
6293 : :
6294 : 22 : targetm.asm_out.unique_section (decl, 0);
6295 : 22 : switch_to_section (get_named_section (decl, NULL, 0));
6296 : :
6297 : 22 : targetm.asm_out.globalize_label (asm_out_file, name);
6298 : 22 : fputs ("\t.hidden\t", asm_out_file);
6299 : 22 : assemble_name (asm_out_file, name);
6300 : 22 : putc ('\n', asm_out_file);
6301 : 22 : ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
6302 : : }
6303 : : else
6304 : : {
6305 : : switch_to_section (text_section);
6306 : 22 : ASM_OUTPUT_LABEL (asm_out_file, name);
6307 : : }
6308 : :
6309 : 22 : DECL_INITIAL (decl) = make_node (BLOCK);
6310 : 22 : current_function_decl = decl;
6311 : 22 : allocate_struct_function (decl, false);
6312 : 22 : init_function_start (decl);
6313 : : /* We're about to hide the function body from callees of final_* by
6314 : : emitting it directly; tell them we're a thunk, if they care. */
6315 : 22 : cfun->is_thunk = true;
6316 : 22 : first_function_block_is_cold = false;
6317 : : /* Make sure unwind info is emitted for the thunk if needed. */
6318 : 22 : final_start_function (emit_barrier (), asm_out_file, 1);
6319 : :
6320 : 22 : output_indirect_thunk (regno);
6321 : :
6322 : 22 : final_end_function ();
6323 : 22 : init_insn_lengths ();
6324 : 22 : free_after_compilation (cfun);
6325 : 22 : set_cfun (NULL);
6326 : 22 : current_function_decl = NULL;
6327 : 22 : }
6328 : :
6329 : : static int pic_labels_used;
6330 : :
6331 : : /* Fills in the label name that should be used for a pc thunk for
6332 : : the given register. */
6333 : :
6334 : : static void
6335 : 36682 : get_pc_thunk_name (char name[32], unsigned int regno)
6336 : : {
6337 : 36682 : gcc_assert (!TARGET_64BIT);
6338 : :
6339 : 36682 : if (USE_HIDDEN_LINKONCE)
6340 : 36682 : sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]);
6341 : : else
6342 : 36682 : ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
6343 : 36682 : }
6344 : :
6345 : :
6346 : : /* This function generates code for -fpic that loads %ebx with
6347 : : the return address of the caller and then returns. */
6348 : :
6349 : : static void
6350 : 224135 : ix86_code_end (void)
6351 : : {
6352 : 224135 : rtx xops[2];
6353 : 224135 : unsigned int regno;
6354 : :
6355 : 224135 : if (indirect_return_needed)
6356 : 6 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6357 : : INVALID_REGNUM, true);
6358 : 224135 : if (indirect_return_via_cx)
6359 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6360 : : CX_REG, true);
6361 : 224135 : if (indirect_thunk_needed)
6362 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6363 : : INVALID_REGNUM, false);
6364 : :
6365 : 2017215 : for (regno = FIRST_REX_INT_REG; regno <= LAST_REX_INT_REG; regno++)
6366 : : {
6367 : 1793080 : if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
6368 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6369 : : regno, false);
6370 : : }
6371 : :
6372 : 3810295 : for (regno = FIRST_REX2_INT_REG; regno <= LAST_REX2_INT_REG; regno++)
6373 : : {
6374 : 3586160 : if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
6375 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6376 : : regno, false);
6377 : : }
6378 : :
6379 : 2017215 : for (regno = FIRST_INT_REG; regno <= LAST_INT_REG; regno++)
6380 : : {
6381 : 1793080 : char name[32];
6382 : 1793080 : tree decl;
6383 : :
6384 : 1793080 : if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
6385 : 16 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6386 : : regno, false);
6387 : :
6388 : 1793080 : if (!(pic_labels_used & (1 << regno)))
6389 : 1789535 : continue;
6390 : :
6391 : 3545 : get_pc_thunk_name (name, regno);
6392 : :
6393 : 3545 : decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
6394 : : get_identifier (name),
6395 : : build_function_type_list (void_type_node, NULL_TREE));
6396 : 3545 : DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
6397 : : NULL_TREE, void_type_node);
6398 : 3545 : TREE_PUBLIC (decl) = 1;
6399 : 3545 : TREE_STATIC (decl) = 1;
6400 : 3545 : DECL_IGNORED_P (decl) = 1;
6401 : :
6402 : : #if TARGET_MACHO
6403 : : if (TARGET_MACHO)
6404 : : {
6405 : : switch_to_section (darwin_sections[picbase_thunk_section]);
6406 : : fputs ("\t.weak_definition\t", asm_out_file);
6407 : : assemble_name (asm_out_file, name);
6408 : : fputs ("\n\t.private_extern\t", asm_out_file);
6409 : : assemble_name (asm_out_file, name);
6410 : : putc ('\n', asm_out_file);
6411 : : ASM_OUTPUT_LABEL (asm_out_file, name);
6412 : : DECL_WEAK (decl) = 1;
6413 : : }
6414 : : else
6415 : : #endif
6416 : 3545 : if (USE_HIDDEN_LINKONCE)
6417 : : {
6418 : 3545 : cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
6419 : :
6420 : 3545 : targetm.asm_out.unique_section (decl, 0);
6421 : 3545 : switch_to_section (get_named_section (decl, NULL, 0));
6422 : :
6423 : 3545 : targetm.asm_out.globalize_label (asm_out_file, name);
6424 : 3545 : fputs ("\t.hidden\t", asm_out_file);
6425 : 3545 : assemble_name (asm_out_file, name);
6426 : 3545 : putc ('\n', asm_out_file);
6427 : 3545 : ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
6428 : : }
6429 : : else
6430 : : {
6431 : : switch_to_section (text_section);
6432 : 3545 : ASM_OUTPUT_LABEL (asm_out_file, name);
6433 : : }
6434 : :
6435 : 3545 : DECL_INITIAL (decl) = make_node (BLOCK);
6436 : 3545 : current_function_decl = decl;
6437 : 3545 : allocate_struct_function (decl, false);
6438 : 3545 : init_function_start (decl);
6439 : : /* We're about to hide the function body from callees of final_* by
6440 : : emitting it directly; tell them we're a thunk, if they care. */
6441 : 3545 : cfun->is_thunk = true;
6442 : 3545 : first_function_block_is_cold = false;
6443 : : /* Make sure unwind info is emitted for the thunk if needed. */
6444 : 3545 : final_start_function (emit_barrier (), asm_out_file, 1);
6445 : :
6446 : : /* Pad stack IP move with 4 instructions (two NOPs count
6447 : : as one instruction). */
6448 : 3545 : if (TARGET_PAD_SHORT_FUNCTION)
6449 : : {
6450 : : int i = 8;
6451 : :
6452 : 0 : while (i--)
6453 : 0 : fputs ("\tnop\n", asm_out_file);
6454 : : }
6455 : :
6456 : 3545 : xops[0] = gen_rtx_REG (Pmode, regno);
6457 : 3545 : xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
6458 : 3545 : output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
6459 : 3545 : fputs ("\tret\n", asm_out_file);
6460 : 3545 : final_end_function ();
6461 : 3545 : init_insn_lengths ();
6462 : 3545 : free_after_compilation (cfun);
6463 : 3545 : set_cfun (NULL);
6464 : 3545 : current_function_decl = NULL;
6465 : : }
6466 : :
6467 : 224135 : if (flag_split_stack)
6468 : 4711 : file_end_indicate_split_stack ();
6469 : 224135 : }
6470 : :
6471 : : /* Emit code for the SET_GOT patterns. */
6472 : :
6473 : : const char *
6474 : 33137 : output_set_got (rtx dest, rtx label)
6475 : : {
6476 : 33137 : rtx xops[3];
6477 : :
6478 : 33137 : xops[0] = dest;
6479 : :
6480 : 33137 : if (TARGET_VXWORKS_RTP && flag_pic)
6481 : : {
6482 : : /* Load (*VXWORKS_GOTT_BASE) into the PIC register. */
6483 : : xops[2] = gen_rtx_MEM (Pmode,
6484 : : gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
6485 : : output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
6486 : :
6487 : : /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
6488 : : Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
6489 : : an unadorned address. */
6490 : : xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
6491 : : SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
6492 : : output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
6493 : : return "";
6494 : : }
6495 : :
6496 : 33137 : xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
6497 : :
6498 : 33137 : if (flag_pic)
6499 : : {
6500 : 33137 : char name[32];
6501 : 33137 : get_pc_thunk_name (name, REGNO (dest));
6502 : 33137 : pic_labels_used |= 1 << REGNO (dest);
6503 : :
6504 : 33137 : xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
6505 : 33137 : xops[2] = gen_rtx_MEM (QImode, xops[2]);
6506 : 33137 : output_asm_insn ("%!call\t%X2", xops);
6507 : :
6508 : : #if TARGET_MACHO
6509 : : /* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here.
6510 : : This is what will be referenced by the Mach-O PIC subsystem. */
6511 : : if (machopic_should_output_picbase_label () || !label)
6512 : : ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
6513 : :
6514 : : /* When we are restoring the pic base at the site of a nonlocal label,
6515 : : and we decided to emit the pic base above, we will still output a
6516 : : local label used for calculating the correction offset (even though
6517 : : the offset will be 0 in that case). */
6518 : : if (label)
6519 : : targetm.asm_out.internal_label (asm_out_file, "L",
6520 : : CODE_LABEL_NUMBER (label));
6521 : : #endif
6522 : : }
6523 : : else
6524 : : {
6525 : 0 : if (TARGET_MACHO)
6526 : : /* We don't need a pic base, we're not producing pic. */
6527 : : gcc_unreachable ();
6528 : :
6529 : 0 : xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
6530 : 0 : output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
6531 : 0 : targetm.asm_out.internal_label (asm_out_file, "L",
6532 : 0 : CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
6533 : : }
6534 : :
6535 : 33137 : if (!TARGET_MACHO)
6536 : 33137 : output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
6537 : :
6538 : 33137 : return "";
6539 : : }
6540 : :
6541 : : /* Generate an "push" pattern for input ARG. */
6542 : :
6543 : : rtx
6544 : 1866011 : gen_push (rtx arg, bool ppx_p)
6545 : : {
6546 : 1866011 : struct machine_function *m = cfun->machine;
6547 : :
6548 : 1866011 : if (m->fs.cfa_reg == stack_pointer_rtx)
6549 : 1604084 : m->fs.cfa_offset += UNITS_PER_WORD;
6550 : 1866011 : m->fs.sp_offset += UNITS_PER_WORD;
6551 : :
6552 : 1866011 : if (REG_P (arg) && GET_MODE (arg) != word_mode)
6553 : 25 : arg = gen_rtx_REG (word_mode, REGNO (arg));
6554 : :
6555 : 1866011 : rtx stack = gen_rtx_MEM (word_mode,
6556 : 1866011 : gen_rtx_PRE_DEC (Pmode,
6557 : : stack_pointer_rtx));
6558 : 3732008 : return ppx_p ? gen_pushp_di (stack, arg) : gen_rtx_SET (stack, arg);
6559 : : }
6560 : :
6561 : : rtx
6562 : 23 : gen_pushfl (void)
6563 : : {
6564 : 23 : struct machine_function *m = cfun->machine;
6565 : 23 : rtx flags, mem;
6566 : :
6567 : 23 : if (m->fs.cfa_reg == stack_pointer_rtx)
6568 : 0 : m->fs.cfa_offset += UNITS_PER_WORD;
6569 : 23 : m->fs.sp_offset += UNITS_PER_WORD;
6570 : :
6571 : 23 : flags = gen_rtx_REG (CCmode, FLAGS_REG);
6572 : :
6573 : 23 : mem = gen_rtx_MEM (word_mode,
6574 : 23 : gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
6575 : :
6576 : 23 : return gen_pushfl2 (word_mode, mem, flags);
6577 : : }
6578 : :
6579 : : /* Generate an "pop" pattern for input ARG. */
6580 : :
6581 : : rtx
6582 : 1487736 : gen_pop (rtx arg, bool ppx_p)
6583 : : {
6584 : 1487736 : if (REG_P (arg) && GET_MODE (arg) != word_mode)
6585 : 21 : arg = gen_rtx_REG (word_mode, REGNO (arg));
6586 : :
6587 : 1487736 : rtx stack = gen_rtx_MEM (word_mode,
6588 : 1487736 : gen_rtx_POST_INC (Pmode,
6589 : : stack_pointer_rtx));
6590 : :
6591 : 2975458 : return ppx_p ? gen_popp_di (arg, stack) : gen_rtx_SET (arg, stack);
6592 : : }
6593 : :
6594 : : rtx
6595 : 21 : gen_popfl (void)
6596 : : {
6597 : 21 : rtx flags, mem;
6598 : :
6599 : 21 : flags = gen_rtx_REG (CCmode, FLAGS_REG);
6600 : :
6601 : 21 : mem = gen_rtx_MEM (word_mode,
6602 : 21 : gen_rtx_POST_INC (Pmode, stack_pointer_rtx));
6603 : :
6604 : 21 : return gen_popfl1 (word_mode, flags, mem);
6605 : : }
6606 : :
6607 : : /* Generate a "push2" pattern for input ARG. */
6608 : : rtx
6609 : 17 : gen_push2 (rtx mem, rtx reg1, rtx reg2, bool ppx_p = false)
6610 : : {
6611 : 17 : struct machine_function *m = cfun->machine;
6612 : 17 : const int offset = UNITS_PER_WORD * 2;
6613 : :
6614 : 17 : if (m->fs.cfa_reg == stack_pointer_rtx)
6615 : 12 : m->fs.cfa_offset += offset;
6616 : 17 : m->fs.sp_offset += offset;
6617 : :
6618 : 17 : if (REG_P (reg1) && GET_MODE (reg1) != word_mode)
6619 : 0 : reg1 = gen_rtx_REG (word_mode, REGNO (reg1));
6620 : :
6621 : 17 : if (REG_P (reg2) && GET_MODE (reg2) != word_mode)
6622 : 0 : reg2 = gen_rtx_REG (word_mode, REGNO (reg2));
6623 : :
6624 : 17 : return ppx_p ? gen_push2p_di (mem, reg1, reg2)
6625 : 4 : : gen_push2_di (mem, reg1, reg2);
6626 : : }
6627 : :
6628 : : /* Return >= 0 if there is an unused call-clobbered register available
6629 : : for the entire function. */
6630 : :
6631 : : static unsigned int
6632 : 0 : ix86_select_alt_pic_regnum (void)
6633 : : {
6634 : 0 : if (ix86_use_pseudo_pic_reg ())
6635 : : return INVALID_REGNUM;
6636 : :
6637 : 0 : if (crtl->is_leaf
6638 : 0 : && !crtl->profile
6639 : 0 : && !ix86_current_function_calls_tls_descriptor)
6640 : : {
6641 : 0 : int i, drap;
6642 : : /* Can't use the same register for both PIC and DRAP. */
6643 : 0 : if (crtl->drap_reg)
6644 : 0 : drap = REGNO (crtl->drap_reg);
6645 : : else
6646 : : drap = -1;
6647 : 0 : for (i = 2; i >= 0; --i)
6648 : 0 : if (i != drap && !df_regs_ever_live_p (i))
6649 : : return i;
6650 : : }
6651 : :
6652 : : return INVALID_REGNUM;
6653 : : }
6654 : :
6655 : : /* Return true if REGNO is used by the epilogue. */
6656 : :
6657 : : bool
6658 : 1555325710 : ix86_epilogue_uses (int regno)
6659 : : {
6660 : : /* If there are no caller-saved registers, we preserve all registers,
6661 : : except for MMX and x87 registers which aren't supported when saving
6662 : : and restoring registers. Don't explicitly save SP register since
6663 : : it is always preserved. */
6664 : 1555325710 : return (epilogue_completed
6665 : 256675982 : && (cfun->machine->call_saved_registers
6666 : 256675982 : == TYPE_NO_CALLER_SAVED_REGISTERS)
6667 : 25116 : && !fixed_regs[regno]
6668 : 4207 : && !STACK_REGNO_P (regno)
6669 : 1555329917 : && !MMX_REGNO_P (regno));
6670 : : }
6671 : :
6672 : : /* Return nonzero if register REGNO can be used as a scratch register
6673 : : in peephole2. */
6674 : :
6675 : : static bool
6676 : 1179535 : ix86_hard_regno_scratch_ok (unsigned int regno)
6677 : : {
6678 : : /* If there are no caller-saved registers, we can't use any register
6679 : : as a scratch register after epilogue and use REGNO as scratch
6680 : : register only if it has been used before to avoid saving and
6681 : : restoring it. */
6682 : 1179535 : return ((cfun->machine->call_saved_registers
6683 : 1179535 : != TYPE_NO_CALLER_SAVED_REGISTERS)
6684 : 1179535 : || (!epilogue_completed
6685 : 0 : && df_regs_ever_live_p (regno)));
6686 : : }
6687 : :
6688 : : /* Return TRUE if we need to save REGNO. */
6689 : :
6690 : : bool
6691 : 321286696 : ix86_save_reg (unsigned int regno, bool maybe_eh_return, bool ignore_outlined)
6692 : : {
6693 : 321286696 : rtx reg;
6694 : :
6695 : 321286696 : switch (cfun->machine->call_saved_registers)
6696 : : {
6697 : : case TYPE_DEFAULT_CALL_SAVED_REGISTERS:
6698 : : break;
6699 : :
6700 : 30656 : case TYPE_NO_CALLER_SAVED_REGISTERS:
6701 : : /* If there are no caller-saved registers, we preserve all
6702 : : registers, except for MMX and x87 registers which aren't
6703 : : supported when saving and restoring registers. Don't
6704 : : explicitly save SP register since it is always preserved.
6705 : :
6706 : : Don't preserve registers used for function return value. */
6707 : 30656 : reg = crtl->return_rtx;
6708 : 30656 : if (reg)
6709 : : {
6710 : 448 : unsigned int i = REGNO (reg);
6711 : 448 : unsigned int nregs = REG_NREGS (reg);
6712 : 882 : while (nregs-- > 0)
6713 : 448 : if ((i + nregs) == regno)
6714 : : return false;
6715 : : }
6716 : :
6717 : 30642 : return (df_regs_ever_live_p (regno)
6718 : 5079 : && !fixed_regs[regno]
6719 : 4190 : && !STACK_REGNO_P (regno)
6720 : 4190 : && !MMX_REGNO_P (regno)
6721 : 34832 : && (regno != HARD_FRAME_POINTER_REGNUM
6722 : 239 : || !frame_pointer_needed));
6723 : :
6724 : : case TYPE_NO_CALLEE_SAVED_REGISTERS:
6725 : : return false;
6726 : :
6727 : 1664 : case TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP:
6728 : 1664 : if (regno != HARD_FRAME_POINTER_REGNUM)
6729 : : return false;
6730 : : break;
6731 : : }
6732 : :
6733 : 353170972 : if (regno == REAL_PIC_OFFSET_TABLE_REGNUM
6734 : 9746522 : && pic_offset_table_rtx)
6735 : : {
6736 : 335057 : if (ix86_use_pseudo_pic_reg ())
6737 : : {
6738 : : /* REAL_PIC_OFFSET_TABLE_REGNUM used by call to
6739 : : _mcount in prologue. */
6740 : 335057 : if (!TARGET_64BIT && flag_pic && crtl->profile)
6741 : : return true;
6742 : : }
6743 : 0 : else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
6744 : 0 : || crtl->profile
6745 : 0 : || crtl->calls_eh_return
6746 : 0 : || crtl->uses_const_pool
6747 : 0 : || cfun->has_nonlocal_label)
6748 : 0 : return ix86_select_alt_pic_regnum () == INVALID_REGNUM;
6749 : : }
6750 : :
6751 : 321248860 : if (crtl->calls_eh_return && maybe_eh_return)
6752 : : {
6753 : : unsigned i;
6754 : 14335 : for (i = 0; ; i++)
6755 : : {
6756 : 21855 : unsigned test = EH_RETURN_DATA_REGNO (i);
6757 : 14805 : if (test == INVALID_REGNUM)
6758 : : break;
6759 : 14805 : if (test == regno)
6760 : : return true;
6761 : 14335 : }
6762 : : }
6763 : :
6764 : 321248390 : if (ignore_outlined && cfun->machine->call_ms2sysv)
6765 : : {
6766 : 2650688 : unsigned count = cfun->machine->call_ms2sysv_extra_regs
6767 : : + xlogue_layout::MIN_REGS;
6768 : 2650688 : if (xlogue_layout::is_stub_managed_reg (regno, count))
6769 : : return false;
6770 : : }
6771 : :
6772 : 320748521 : if (crtl->drap_reg
6773 : 2130778 : && regno == REGNO (crtl->drap_reg)
6774 : 320802217 : && !cfun->machine->no_drap_save_restore)
6775 : : return true;
6776 : :
6777 : 320694825 : return (df_regs_ever_live_p (regno)
6778 : 337502423 : && !call_used_or_fixed_reg_p (regno)
6779 : 336910552 : && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
6780 : : }
6781 : :
6782 : : /* Return number of saved general prupose registers. */
6783 : :
6784 : : static int
6785 : 7958200 : ix86_nsaved_regs (void)
6786 : : {
6787 : 7958200 : int nregs = 0;
6788 : 7958200 : int regno;
6789 : :
6790 : 740112600 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6791 : 732154400 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
6792 : 8211661 : nregs ++;
6793 : 7958200 : return nregs;
6794 : : }
6795 : :
6796 : : /* Return number of saved SSE registers. */
6797 : :
6798 : : static int
6799 : 7991683 : ix86_nsaved_sseregs (void)
6800 : : {
6801 : 7991683 : int nregs = 0;
6802 : 7991683 : int regno;
6803 : :
6804 : 7991683 : if (!TARGET_64BIT_MS_ABI)
6805 : 7765980 : return 0;
6806 : 20990379 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6807 : 20764676 : if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
6808 : 1899215 : nregs ++;
6809 : : return nregs;
6810 : : }
6811 : :
6812 : : /* Given FROM and TO register numbers, say whether this elimination is
6813 : : allowed. If stack alignment is needed, we can only replace argument
6814 : : pointer with hard frame pointer, or replace frame pointer with stack
6815 : : pointer. Otherwise, frame pointer elimination is automatically
6816 : : handled and all other eliminations are valid. */
6817 : :
6818 : : static bool
6819 : 47105076 : ix86_can_eliminate (const int from, const int to)
6820 : : {
6821 : 47105076 : if (stack_realign_fp)
6822 : 1651900 : return ((from == ARG_POINTER_REGNUM
6823 : 1651900 : && to == HARD_FRAME_POINTER_REGNUM)
6824 : 1651900 : || (from == FRAME_POINTER_REGNUM
6825 : 1651900 : && to == STACK_POINTER_REGNUM));
6826 : : else
6827 : 84590498 : return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true;
6828 : : }
6829 : :
6830 : : /* Return the offset between two registers, one to be eliminated, and the other
6831 : : its replacement, at the start of a routine. */
6832 : :
6833 : : HOST_WIDE_INT
6834 : 138916973 : ix86_initial_elimination_offset (int from, int to)
6835 : : {
6836 : 138916973 : struct ix86_frame &frame = cfun->machine->frame;
6837 : :
6838 : 138916973 : if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
6839 : 10149213 : return frame.hard_frame_pointer_offset;
6840 : 128767760 : else if (from == FRAME_POINTER_REGNUM
6841 : 128767760 : && to == HARD_FRAME_POINTER_REGNUM)
6842 : 7924423 : return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
6843 : : else
6844 : : {
6845 : 120843337 : gcc_assert (to == STACK_POINTER_REGNUM);
6846 : :
6847 : 120843337 : if (from == ARG_POINTER_REGNUM)
6848 : 112918914 : return frame.stack_pointer_offset;
6849 : :
6850 : 7924423 : gcc_assert (from == FRAME_POINTER_REGNUM);
6851 : 7924423 : return frame.stack_pointer_offset - frame.frame_pointer_offset;
6852 : : }
6853 : : }
6854 : :
6855 : : /* Emits a warning for unsupported msabi to sysv pro/epilogues. */
6856 : : void
6857 : 0 : warn_once_call_ms2sysv_xlogues (const char *feature)
6858 : : {
6859 : 0 : static bool warned_once = false;
6860 : 0 : if (!warned_once)
6861 : : {
6862 : 0 : warning (0, "%<-mcall-ms2sysv-xlogues%> is not compatible with %s",
6863 : : feature);
6864 : 0 : warned_once = true;
6865 : : }
6866 : 0 : }
6867 : :
6868 : : /* Return the probing interval for -fstack-clash-protection. */
6869 : :
6870 : : static HOST_WIDE_INT
6871 : 452 : get_probe_interval (void)
6872 : : {
6873 : 298 : if (flag_stack_clash_protection)
6874 : 368 : return (HOST_WIDE_INT_1U
6875 : 368 : << param_stack_clash_protection_probe_interval);
6876 : : else
6877 : : return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
6878 : : }
6879 : :
6880 : : /* When using -fsplit-stack, the allocation routines set a field in
6881 : : the TCB to the bottom of the stack plus this much space, measured
6882 : : in bytes. */
6883 : :
6884 : : #define SPLIT_STACK_AVAILABLE 256
6885 : :
6886 : : /* Return true if push2/pop2 can be generated. */
6887 : :
6888 : : static bool
6889 : 7958660 : ix86_can_use_push2pop2 (void)
6890 : : {
6891 : : /* Use push2/pop2 only if the incoming stack is 16-byte aligned. */
6892 : 7958660 : unsigned int incoming_stack_boundary
6893 : 7958660 : = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
6894 : 7958660 : ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
6895 : 7958660 : return incoming_stack_boundary % 128 == 0;
6896 : : }
6897 : :
6898 : : /* Helper function to determine whether push2/pop2 can be used in prologue or
6899 : : epilogue for register save/restore. */
6900 : : static bool
6901 : 7958200 : ix86_pro_and_epilogue_can_use_push2pop2 (int nregs)
6902 : : {
6903 : 7958200 : if (!ix86_can_use_push2pop2 ())
6904 : : return false;
6905 : 7922319 : int aligned = cfun->machine->fs.sp_offset % 16 == 0;
6906 : 7922319 : return TARGET_APX_PUSH2POP2
6907 : 2270 : && !cfun->machine->frame.save_regs_using_mov
6908 : 2266 : && cfun->machine->func_type == TYPE_NORMAL
6909 : 7924577 : && (nregs + aligned) >= 3;
6910 : : }
6911 : :
6912 : : /* Fill structure ix86_frame about frame of currently computed function. */
6913 : :
6914 : : static void
6915 : 7958200 : ix86_compute_frame_layout (void)
6916 : : {
6917 : 7958200 : struct ix86_frame *frame = &cfun->machine->frame;
6918 : 7958200 : struct machine_function *m = cfun->machine;
6919 : 7958200 : unsigned HOST_WIDE_INT stack_alignment_needed;
6920 : 7958200 : HOST_WIDE_INT offset;
6921 : 7958200 : unsigned HOST_WIDE_INT preferred_alignment;
6922 : 7958200 : HOST_WIDE_INT size = ix86_get_frame_size ();
6923 : 7958200 : HOST_WIDE_INT to_allocate;
6924 : :
6925 : : /* m->call_ms2sysv is initially enabled in ix86_expand_call for all 64-bit
6926 : : * ms_abi functions that call a sysv function. We now need to prune away
6927 : : * cases where it should be disabled. */
6928 : 7958200 : if (TARGET_64BIT && m->call_ms2sysv)
6929 : : {
6930 : 35225 : gcc_assert (TARGET_64BIT_MS_ABI);
6931 : 35225 : gcc_assert (TARGET_CALL_MS2SYSV_XLOGUES);
6932 : 35225 : gcc_assert (!TARGET_SEH);
6933 : 35225 : gcc_assert (TARGET_SSE);
6934 : 35225 : gcc_assert (!ix86_using_red_zone ());
6935 : :
6936 : 35225 : if (crtl->calls_eh_return)
6937 : : {
6938 : 0 : gcc_assert (!reload_completed);
6939 : 0 : m->call_ms2sysv = false;
6940 : 0 : warn_once_call_ms2sysv_xlogues ("__builtin_eh_return");
6941 : : }
6942 : :
6943 : 35225 : else if (ix86_static_chain_on_stack)
6944 : : {
6945 : 0 : gcc_assert (!reload_completed);
6946 : 0 : m->call_ms2sysv = false;
6947 : 0 : warn_once_call_ms2sysv_xlogues ("static call chains");
6948 : : }
6949 : :
6950 : : /* Finally, compute which registers the stub will manage. */
6951 : : else
6952 : : {
6953 : 35225 : unsigned count = xlogue_layout::count_stub_managed_regs ();
6954 : 35225 : m->call_ms2sysv_extra_regs = count - xlogue_layout::MIN_REGS;
6955 : 35225 : m->call_ms2sysv_pad_in = 0;
6956 : : }
6957 : : }
6958 : :
6959 : 7958200 : frame->nregs = ix86_nsaved_regs ();
6960 : 7958200 : frame->nsseregs = ix86_nsaved_sseregs ();
6961 : :
6962 : : /* 64-bit MS ABI seem to require stack alignment to be always 16,
6963 : : except for function prologues, leaf functions and when the defult
6964 : : incoming stack boundary is overriden at command line or via
6965 : : force_align_arg_pointer attribute.
6966 : :
6967 : : Darwin's ABI specifies 128b alignment for both 32 and 64 bit variants
6968 : : at call sites, including profile function calls.
6969 : :
6970 : : For APX push2/pop2, the stack also requires 128b alignment. */
6971 : 7958200 : if ((ix86_pro_and_epilogue_can_use_push2pop2 (frame->nregs)
6972 : 61 : && crtl->preferred_stack_boundary < 128)
6973 : 7958260 : || (((TARGET_64BIT_MS_ABI || TARGET_MACHO)
6974 : 225701 : && crtl->preferred_stack_boundary < 128)
6975 : 0 : && (!crtl->is_leaf || cfun->calls_alloca != 0
6976 : 0 : || ix86_current_function_calls_tls_descriptor
6977 : 0 : || (TARGET_MACHO && crtl->profile)
6978 : 0 : || ix86_incoming_stack_boundary < 128)))
6979 : : {
6980 : 1 : crtl->preferred_stack_boundary = 128;
6981 : 1 : if (crtl->stack_alignment_needed < 128)
6982 : 0 : crtl->stack_alignment_needed = 128;
6983 : : }
6984 : :
6985 : 7958200 : stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
6986 : 7958200 : preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
6987 : :
6988 : 7958200 : gcc_assert (!size || stack_alignment_needed);
6989 : 8752959 : gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
6990 : 7958200 : gcc_assert (preferred_alignment <= stack_alignment_needed);
6991 : :
6992 : : /* The only ABI saving SSE regs should be 64-bit ms_abi. */
6993 : 7958200 : gcc_assert (TARGET_64BIT || !frame->nsseregs);
6994 : 7958200 : if (TARGET_64BIT && m->call_ms2sysv)
6995 : : {
6996 : 35225 : gcc_assert (stack_alignment_needed >= 16);
6997 : 35225 : gcc_assert (!frame->nsseregs);
6998 : : }
6999 : :
7000 : : /* For SEH we have to limit the amount of code movement into the prologue.
7001 : : At present we do this via a BLOCKAGE, at which point there's very little
7002 : : scheduling that can be done, which means that there's very little point
7003 : : in doing anything except PUSHs. */
7004 : 7958200 : if (TARGET_SEH)
7005 : : m->use_fast_prologue_epilogue = false;
7006 : 7958200 : else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
7007 : : {
7008 : 7637664 : int count = frame->nregs;
7009 : 7637664 : struct cgraph_node *node = cgraph_node::get (current_function_decl);
7010 : :
7011 : : /* The fast prologue uses move instead of push to save registers. This
7012 : : is significantly longer, but also executes faster as modern hardware
7013 : : can execute the moves in parallel, but can't do that for push/pop.
7014 : :
7015 : : Be careful about choosing what prologue to emit: When function takes
7016 : : many instructions to execute we may use slow version as well as in
7017 : : case function is known to be outside hot spot (this is known with
7018 : : feedback only). Weight the size of function by number of registers
7019 : : to save as it is cheap to use one or two push instructions but very
7020 : : slow to use many of them.
7021 : :
7022 : : Calling this hook multiple times with the same frame requirements
7023 : : must produce the same layout, since the RA might otherwise be
7024 : : unable to reach a fixed point or might fail its final sanity checks.
7025 : : This means that once we've assumed that a function does or doesn't
7026 : : have a particular size, we have to stick to that assumption
7027 : : regardless of how the function has changed since. */
7028 : 7637664 : if (count)
7029 : 2587413 : count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7030 : 7637664 : if (node->frequency < NODE_FREQUENCY_NORMAL
7031 : 6974688 : || (flag_branch_probabilities
7032 : 961 : && node->frequency < NODE_FREQUENCY_HOT))
7033 : 663276 : m->use_fast_prologue_epilogue = false;
7034 : : else
7035 : : {
7036 : 6974388 : if (count != frame->expensive_count)
7037 : : {
7038 : 287771 : frame->expensive_count = count;
7039 : 287771 : frame->expensive_p = expensive_function_p (count);
7040 : : }
7041 : 6974388 : m->use_fast_prologue_epilogue = !frame->expensive_p;
7042 : : }
7043 : : }
7044 : :
7045 : 7958200 : frame->save_regs_using_mov
7046 : 7958200 : = TARGET_PROLOGUE_USING_MOVE && m->use_fast_prologue_epilogue;
7047 : :
7048 : : /* Skip return address and error code in exception handler. */
7049 : 7958200 : offset = INCOMING_FRAME_SP_OFFSET;
7050 : :
7051 : : /* Skip pushed static chain. */
7052 : 7958200 : if (ix86_static_chain_on_stack)
7053 : 0 : offset += UNITS_PER_WORD;
7054 : :
7055 : : /* Skip saved base pointer. */
7056 : 7958200 : if (frame_pointer_needed)
7057 : 2686692 : offset += UNITS_PER_WORD;
7058 : 7958200 : frame->hfp_save_offset = offset;
7059 : :
7060 : : /* The traditional frame pointer location is at the top of the frame. */
7061 : 7958200 : frame->hard_frame_pointer_offset = offset;
7062 : :
7063 : : /* Register save area */
7064 : 7958200 : offset += frame->nregs * UNITS_PER_WORD;
7065 : 7958200 : frame->reg_save_offset = offset;
7066 : :
7067 : : /* Calculate the size of the va-arg area (not including padding, if any). */
7068 : 7958200 : frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7069 : :
7070 : : /* Also adjust stack_realign_offset for the largest alignment of
7071 : : stack slot actually used. */
7072 : 7958200 : if (stack_realign_fp
7073 : 7661220 : || (cfun->machine->max_used_stack_alignment != 0
7074 : 119 : && (offset % cfun->machine->max_used_stack_alignment) != 0))
7075 : : {
7076 : : /* We may need a 16-byte aligned stack for the remainder of the
7077 : : register save area, but the stack frame for the local function
7078 : : may require a greater alignment if using AVX/2/512. In order
7079 : : to avoid wasting space, we first calculate the space needed for
7080 : : the rest of the register saves, add that to the stack pointer,
7081 : : and then realign the stack to the boundary of the start of the
7082 : : frame for the local function. */
7083 : 297042 : HOST_WIDE_INT space_needed = 0;
7084 : 297042 : HOST_WIDE_INT sse_reg_space_needed = 0;
7085 : :
7086 : 297042 : if (TARGET_64BIT)
7087 : : {
7088 : 295252 : if (m->call_ms2sysv)
7089 : : {
7090 : 6415 : m->call_ms2sysv_pad_in = 0;
7091 : 6415 : space_needed = xlogue_layout::get_instance ().get_stack_space_used ();
7092 : : }
7093 : :
7094 : 288837 : else if (frame->nsseregs)
7095 : : /* The only ABI that has saved SSE registers (Win64) also has a
7096 : : 16-byte aligned default stack. However, many programs violate
7097 : : the ABI, and Wine64 forces stack realignment to compensate. */
7098 : 6447 : space_needed = frame->nsseregs * 16;
7099 : :
7100 : 295252 : sse_reg_space_needed = space_needed = ROUND_UP (space_needed, 16);
7101 : :
7102 : : /* 64-bit frame->va_arg_size should always be a multiple of 16, but
7103 : : rounding to be pedantic. */
7104 : 295252 : space_needed = ROUND_UP (space_needed + frame->va_arg_size, 16);
7105 : : }
7106 : : else
7107 : 1790 : space_needed = frame->va_arg_size;
7108 : :
7109 : : /* Record the allocation size required prior to the realignment AND. */
7110 : 297042 : frame->stack_realign_allocate = space_needed;
7111 : :
7112 : : /* The re-aligned stack starts at frame->stack_realign_offset. Values
7113 : : before this point are not directly comparable with values below
7114 : : this point. Use sp_valid_at to determine if the stack pointer is
7115 : : valid for a given offset, fp_valid_at for the frame pointer, or
7116 : : choose_baseaddr to have a base register chosen for you.
7117 : :
7118 : : Note that the result of (frame->stack_realign_offset
7119 : : & (stack_alignment_needed - 1)) may not equal zero. */
7120 : 297042 : offset = ROUND_UP (offset + space_needed, stack_alignment_needed);
7121 : 297042 : frame->stack_realign_offset = offset - space_needed;
7122 : 297042 : frame->sse_reg_save_offset = frame->stack_realign_offset
7123 : 297042 : + sse_reg_space_needed;
7124 : 297042 : }
7125 : : else
7126 : : {
7127 : 7661158 : frame->stack_realign_offset = offset;
7128 : :
7129 : 7661158 : if (TARGET_64BIT && m->call_ms2sysv)
7130 : : {
7131 : 28810 : m->call_ms2sysv_pad_in = !!(offset & UNITS_PER_WORD);
7132 : 28810 : offset += xlogue_layout::get_instance ().get_stack_space_used ();
7133 : : }
7134 : :
7135 : : /* Align and set SSE register save area. */
7136 : 7632348 : else if (frame->nsseregs)
7137 : : {
7138 : : /* If the incoming stack boundary is at least 16 bytes, or DRAP is
7139 : : required and the DRAP re-alignment boundary is at least 16 bytes,
7140 : : then we want the SSE register save area properly aligned. */
7141 : 183479 : if (ix86_incoming_stack_boundary >= 128
7142 : 6400 : || (stack_realign_drap && stack_alignment_needed >= 16))
7143 : 183479 : offset = ROUND_UP (offset, 16);
7144 : 183479 : offset += frame->nsseregs * 16;
7145 : : }
7146 : 7661158 : frame->sse_reg_save_offset = offset;
7147 : 7661158 : offset += frame->va_arg_size;
7148 : : }
7149 : :
7150 : : /* Align start of frame for local function. When a function call
7151 : : is removed, it may become a leaf function. But if argument may
7152 : : be passed on stack, we need to align the stack when there is no
7153 : : tail call. */
7154 : 7958200 : if (m->call_ms2sysv
7155 : 7922975 : || frame->va_arg_size != 0
7156 : 7844562 : || size != 0
7157 : 4216819 : || !crtl->is_leaf
7158 : 1953433 : || (!crtl->tail_call_emit
7159 : 1652099 : && cfun->machine->outgoing_args_on_stack)
7160 : 1953383 : || cfun->calls_alloca
7161 : 9909951 : || ix86_current_function_calls_tls_descriptor)
7162 : 6006856 : offset = ROUND_UP (offset, stack_alignment_needed);
7163 : :
7164 : : /* Frame pointer points here. */
7165 : 7958200 : frame->frame_pointer_offset = offset;
7166 : :
7167 : 7958200 : offset += size;
7168 : :
7169 : : /* Add outgoing arguments area. Can be skipped if we eliminated
7170 : : all the function calls as dead code.
7171 : : Skipping is however impossible when function calls alloca. Alloca
7172 : : expander assumes that last crtl->outgoing_args_size
7173 : : of stack frame are unused. */
7174 : 7958200 : if (ACCUMULATE_OUTGOING_ARGS
7175 : 8575587 : && (!crtl->is_leaf || cfun->calls_alloca
7176 : 390915 : || ix86_current_function_calls_tls_descriptor))
7177 : : {
7178 : 226472 : offset += crtl->outgoing_args_size;
7179 : 226472 : frame->outgoing_arguments_size = crtl->outgoing_args_size;
7180 : : }
7181 : : else
7182 : 7731728 : frame->outgoing_arguments_size = 0;
7183 : :
7184 : : /* Align stack boundary. Only needed if we're calling another function
7185 : : or using alloca. */
7186 : 2650839 : if (!crtl->is_leaf || cfun->calls_alloca
7187 : 10605580 : || ix86_current_function_calls_tls_descriptor)
7188 : 5312605 : offset = ROUND_UP (offset, preferred_alignment);
7189 : :
7190 : : /* We've reached end of stack frame. */
7191 : 7958200 : frame->stack_pointer_offset = offset;
7192 : :
7193 : : /* Size prologue needs to allocate. */
7194 : 7958200 : to_allocate = offset - frame->sse_reg_save_offset;
7195 : :
7196 : 2680906 : if ((!to_allocate && frame->nregs <= 1)
7197 : 5500726 : || (TARGET_64BIT && to_allocate >= HOST_WIDE_INT_C (0x80000000))
7198 : : /* If static stack checking is enabled and done with probes,
7199 : : the registers need to be saved before allocating the frame. */
7200 : 5500096 : || flag_stack_check == STATIC_BUILTIN_STACK_CHECK
7201 : : /* If stack clash probing needs a loop, then it needs a
7202 : : scratch register. But the returned register is only guaranteed
7203 : : to be safe to use after register saves are complete. So if
7204 : : stack clash protections are enabled and the allocated frame is
7205 : : larger than the probe interval, then use pushes to save
7206 : : callee saved registers. */
7207 : 13458226 : || (flag_stack_clash_protection
7208 : 298 : && !ix86_target_stack_probe ()
7209 : 298 : && to_allocate > get_probe_interval ()))
7210 : 2458298 : frame->save_regs_using_mov = false;
7211 : :
7212 : 7958200 : if (ix86_using_red_zone ()
7213 : 6937574 : && crtl->sp_is_unchanging
7214 : 6306882 : && crtl->is_leaf
7215 : 2553046 : && !cfun->machine->asm_redzone_clobber_seen
7216 : 2553046 : && !ix86_pc_thunk_call_expanded
7217 : 10511233 : && !ix86_current_function_calls_tls_descriptor)
7218 : : {
7219 : 2553033 : frame->red_zone_size = to_allocate;
7220 : 2553033 : if (frame->save_regs_using_mov)
7221 : 139705 : frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7222 : 2553033 : if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7223 : 104499 : frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7224 : : }
7225 : : else
7226 : 5405167 : frame->red_zone_size = 0;
7227 : 7958200 : frame->stack_pointer_offset -= frame->red_zone_size;
7228 : :
7229 : : /* The SEH frame pointer location is near the bottom of the frame.
7230 : : This is enforced by the fact that the difference between the
7231 : : stack pointer and the frame pointer is limited to 240 bytes in
7232 : : the unwind data structure. */
7233 : 7958200 : if (TARGET_SEH)
7234 : : {
7235 : : /* Force the frame pointer to point at or below the lowest register save
7236 : : area, see the SEH code in config/i386/winnt.cc for the rationale. */
7237 : : frame->hard_frame_pointer_offset = frame->sse_reg_save_offset;
7238 : :
7239 : : /* If we can leave the frame pointer where it is, do so; however return
7240 : : the establisher frame for __builtin_frame_address (0) or else if the
7241 : : frame overflows the SEH maximum frame size.
7242 : :
7243 : : Note that the value returned by __builtin_frame_address (0) is quite
7244 : : constrained, because setjmp is piggybacked on the SEH machinery with
7245 : : recent versions of MinGW:
7246 : :
7247 : : # elif defined(__SEH__)
7248 : : # if defined(__aarch64__) || defined(_ARM64_)
7249 : : # define setjmp(BUF) _setjmp((BUF), __builtin_sponentry())
7250 : : # elif (__MINGW_GCC_VERSION < 40702)
7251 : : # define setjmp(BUF) _setjmp((BUF), mingw_getsp())
7252 : : # else
7253 : : # define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))
7254 : : # endif
7255 : :
7256 : : and the second argument passed to _setjmp, if not null, is forwarded
7257 : : to the TargetFrame parameter of RtlUnwindEx by longjmp (after it has
7258 : : built an ExceptionRecord on the fly describing the setjmp buffer). */
7259 : : const HOST_WIDE_INT diff
7260 : : = frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
7261 : : if (diff <= 255 && !crtl->accesses_prior_frames)
7262 : : {
7263 : : /* The resulting diff will be a multiple of 16 lower than 255,
7264 : : i.e. at most 240 as required by the unwind data structure. */
7265 : : frame->hard_frame_pointer_offset += (diff & 15);
7266 : : }
7267 : : else if (diff <= SEH_MAX_FRAME_SIZE && !crtl->accesses_prior_frames)
7268 : : {
7269 : : /* Ideally we'd determine what portion of the local stack frame
7270 : : (within the constraint of the lowest 240) is most heavily used.
7271 : : But without that complication, simply bias the frame pointer
7272 : : by 128 bytes so as to maximize the amount of the local stack
7273 : : frame that is addressable with 8-bit offsets. */
7274 : : frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128;
7275 : : }
7276 : : else
7277 : : frame->hard_frame_pointer_offset = frame->hfp_save_offset;
7278 : : }
7279 : 7958200 : }
7280 : :
7281 : : /* This is semi-inlined memory_address_length, but simplified
7282 : : since we know that we're always dealing with reg+offset, and
7283 : : to avoid having to create and discard all that rtl. */
7284 : :
7285 : : static inline int
7286 : 692459 : choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
7287 : : {
7288 : 692459 : int len = 4;
7289 : :
7290 : 0 : if (offset == 0)
7291 : : {
7292 : : /* EBP and R13 cannot be encoded without an offset. */
7293 : 0 : len = (regno == BP_REG || regno == R13_REG);
7294 : : }
7295 : 688439 : else if (IN_RANGE (offset, -128, 127))
7296 : 424992 : len = 1;
7297 : :
7298 : : /* ESP and R12 must be encoded with a SIB byte. */
7299 : 0 : if (regno == SP_REG || regno == R12_REG)
7300 : 0 : len++;
7301 : :
7302 : 692459 : return len;
7303 : : }
7304 : :
7305 : : /* Determine if the stack pointer is valid for accessing the CFA_OFFSET in
7306 : : the frame save area. The register is saved at CFA - CFA_OFFSET. */
7307 : :
7308 : : static bool
7309 : 2749338 : sp_valid_at (HOST_WIDE_INT cfa_offset)
7310 : : {
7311 : 2749338 : const struct machine_frame_state &fs = cfun->machine->fs;
7312 : 2749338 : if (fs.sp_realigned && cfa_offset <= fs.sp_realigned_offset)
7313 : : {
7314 : : /* Validate that the cfa_offset isn't in a "no-man's land". */
7315 : 45869 : gcc_assert (cfa_offset <= fs.sp_realigned_fp_last);
7316 : : return false;
7317 : : }
7318 : 2703469 : return fs.sp_valid;
7319 : : }
7320 : :
7321 : : /* Determine if the frame pointer is valid for accessing the CFA_OFFSET in
7322 : : the frame save area. The register is saved at CFA - CFA_OFFSET. */
7323 : :
7324 : : static inline bool
7325 : 725471 : fp_valid_at (HOST_WIDE_INT cfa_offset)
7326 : : {
7327 : 725471 : const struct machine_frame_state &fs = cfun->machine->fs;
7328 : 725471 : if (fs.sp_realigned && cfa_offset > fs.sp_realigned_fp_last)
7329 : : {
7330 : : /* Validate that the cfa_offset isn't in a "no-man's land". */
7331 : 28328 : gcc_assert (cfa_offset >= fs.sp_realigned_offset);
7332 : : return false;
7333 : : }
7334 : 697143 : return fs.fp_valid;
7335 : : }
7336 : :
7337 : : /* Choose a base register based upon alignment requested, speed and/or
7338 : : size. */
7339 : :
7340 : : static void
7341 : 725471 : choose_basereg (HOST_WIDE_INT cfa_offset, rtx &base_reg,
7342 : : HOST_WIDE_INT &base_offset,
7343 : : unsigned int align_reqested, unsigned int *align)
7344 : : {
7345 : 725471 : const struct machine_function *m = cfun->machine;
7346 : 725471 : unsigned int hfp_align;
7347 : 725471 : unsigned int drap_align;
7348 : 725471 : unsigned int sp_align;
7349 : 725471 : bool hfp_ok = fp_valid_at (cfa_offset);
7350 : 725471 : bool drap_ok = m->fs.drap_valid;
7351 : 725471 : bool sp_ok = sp_valid_at (cfa_offset);
7352 : :
7353 : 725471 : hfp_align = drap_align = sp_align = INCOMING_STACK_BOUNDARY;
7354 : :
7355 : : /* Filter out any registers that don't meet the requested alignment
7356 : : criteria. */
7357 : 725471 : if (align_reqested)
7358 : : {
7359 : 683570 : if (m->fs.realigned)
7360 : 28160 : hfp_align = drap_align = sp_align = crtl->stack_alignment_needed;
7361 : : /* SEH unwind code does do not currently support REG_CFA_EXPRESSION
7362 : : notes (which we would need to use a realigned stack pointer),
7363 : : so disable on SEH targets. */
7364 : 655410 : else if (m->fs.sp_realigned)
7365 : 28328 : sp_align = crtl->stack_alignment_needed;
7366 : :
7367 : 683570 : hfp_ok = hfp_ok && hfp_align >= align_reqested;
7368 : 683570 : drap_ok = drap_ok && drap_align >= align_reqested;
7369 : 683570 : sp_ok = sp_ok && sp_align >= align_reqested;
7370 : : }
7371 : :
7372 : 725471 : if (m->use_fast_prologue_epilogue)
7373 : : {
7374 : : /* Choose the base register most likely to allow the most scheduling
7375 : : opportunities. Generally FP is valid throughout the function,
7376 : : while DRAP must be reloaded within the epilogue. But choose either
7377 : : over the SP due to increased encoding size. */
7378 : :
7379 : 321772 : if (hfp_ok)
7380 : : {
7381 : 97618 : base_reg = hard_frame_pointer_rtx;
7382 : 97618 : base_offset = m->fs.fp_offset - cfa_offset;
7383 : : }
7384 : 224154 : else if (drap_ok)
7385 : : {
7386 : 0 : base_reg = crtl->drap_reg;
7387 : 0 : base_offset = 0 - cfa_offset;
7388 : : }
7389 : 224154 : else if (sp_ok)
7390 : : {
7391 : 224154 : base_reg = stack_pointer_rtx;
7392 : 224154 : base_offset = m->fs.sp_offset - cfa_offset;
7393 : : }
7394 : : }
7395 : : else
7396 : : {
7397 : 403699 : HOST_WIDE_INT toffset;
7398 : 403699 : int len = 16, tlen;
7399 : :
7400 : : /* Choose the base register with the smallest address encoding.
7401 : : With a tie, choose FP > DRAP > SP. */
7402 : 403699 : if (sp_ok)
7403 : : {
7404 : 386506 : base_reg = stack_pointer_rtx;
7405 : 386506 : base_offset = m->fs.sp_offset - cfa_offset;
7406 : 768992 : len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset);
7407 : : }
7408 : 403699 : if (drap_ok)
7409 : : {
7410 : 0 : toffset = 0 - cfa_offset;
7411 : 0 : tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset);
7412 : 0 : if (tlen <= len)
7413 : : {
7414 : 0 : base_reg = crtl->drap_reg;
7415 : 0 : base_offset = toffset;
7416 : 0 : len = tlen;
7417 : : }
7418 : : }
7419 : 403699 : if (hfp_ok)
7420 : : {
7421 : 305953 : toffset = m->fs.fp_offset - cfa_offset;
7422 : 305953 : tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset);
7423 : 305953 : if (tlen <= len)
7424 : : {
7425 : 215309 : base_reg = hard_frame_pointer_rtx;
7426 : 215309 : base_offset = toffset;
7427 : : }
7428 : : }
7429 : : }
7430 : :
7431 : : /* Set the align return value. */
7432 : 725471 : if (align)
7433 : : {
7434 : 683570 : if (base_reg == stack_pointer_rtx)
7435 : 412480 : *align = sp_align;
7436 : 271090 : else if (base_reg == crtl->drap_reg)
7437 : 0 : *align = drap_align;
7438 : 271090 : else if (base_reg == hard_frame_pointer_rtx)
7439 : 271090 : *align = hfp_align;
7440 : : }
7441 : 725471 : }
7442 : :
7443 : : /* Return an RTX that points to CFA_OFFSET within the stack frame and
7444 : : the alignment of address. If ALIGN is non-null, it should point to
7445 : : an alignment value (in bits) that is preferred or zero and will
7446 : : recieve the alignment of the base register that was selected,
7447 : : irrespective of rather or not CFA_OFFSET is a multiple of that
7448 : : alignment value. If it is possible for the base register offset to be
7449 : : non-immediate then SCRATCH_REGNO should specify a scratch register to
7450 : : use.
7451 : :
7452 : : The valid base registers are taken from CFUN->MACHINE->FS. */
7453 : :
7454 : : static rtx
7455 : 725471 : choose_baseaddr (HOST_WIDE_INT cfa_offset, unsigned int *align,
7456 : : unsigned int scratch_regno = INVALID_REGNUM)
7457 : : {
7458 : 725471 : rtx base_reg = NULL;
7459 : 725471 : HOST_WIDE_INT base_offset = 0;
7460 : :
7461 : : /* If a specific alignment is requested, try to get a base register
7462 : : with that alignment first. */
7463 : 725471 : if (align && *align)
7464 : 683570 : choose_basereg (cfa_offset, base_reg, base_offset, *align, align);
7465 : :
7466 : 725471 : if (!base_reg)
7467 : 41901 : choose_basereg (cfa_offset, base_reg, base_offset, 0, align);
7468 : :
7469 : 725471 : gcc_assert (base_reg != NULL);
7470 : :
7471 : 725471 : rtx base_offset_rtx = GEN_INT (base_offset);
7472 : :
7473 : 725471 : if (!x86_64_immediate_operand (base_offset_rtx, Pmode))
7474 : : {
7475 : 1 : gcc_assert (scratch_regno != INVALID_REGNUM);
7476 : :
7477 : 1 : rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
7478 : 1 : emit_move_insn (scratch_reg, base_offset_rtx);
7479 : :
7480 : 1 : return gen_rtx_PLUS (Pmode, base_reg, scratch_reg);
7481 : : }
7482 : :
7483 : 725470 : return plus_constant (Pmode, base_reg, base_offset);
7484 : : }
7485 : :
7486 : : /* Emit code to save registers in the prologue. */
7487 : :
7488 : : static void
7489 : 423491 : ix86_emit_save_regs (void)
7490 : : {
7491 : 423491 : int regno;
7492 : 423491 : rtx_insn *insn;
7493 : 423491 : bool use_ppx = TARGET_APX_PPX && !crtl->calls_eh_return;
7494 : :
7495 : 423491 : if (!TARGET_APX_PUSH2POP2
7496 : 13 : || !ix86_can_use_push2pop2 ()
7497 : 423502 : || cfun->machine->func_type != TYPE_NORMAL)
7498 : : {
7499 : 39383733 : for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7500 : 38960252 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7501 : : {
7502 : 1197993 : insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno),
7503 : : use_ppx));
7504 : 1197993 : RTX_FRAME_RELATED_P (insn) = 1;
7505 : : }
7506 : : }
7507 : : else
7508 : : {
7509 : 10 : int regno_list[2];
7510 : 10 : regno_list[0] = regno_list[1] = -1;
7511 : 10 : int loaded_regnum = 0;
7512 : 10 : bool aligned = cfun->machine->fs.sp_offset % 16 == 0;
7513 : :
7514 : 930 : for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7515 : 920 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7516 : : {
7517 : 49 : if (aligned)
7518 : : {
7519 : 43 : regno_list[loaded_regnum++] = regno;
7520 : 43 : if (loaded_regnum == 2)
7521 : : {
7522 : 17 : gcc_assert (regno_list[0] != -1
7523 : : && regno_list[1] != -1
7524 : : && regno_list[0] != regno_list[1]);
7525 : 17 : const int offset = UNITS_PER_WORD * 2;
7526 : 17 : rtx mem = gen_rtx_MEM (TImode,
7527 : 17 : gen_rtx_PRE_DEC (Pmode,
7528 : : stack_pointer_rtx));
7529 : 17 : insn = emit_insn (gen_push2 (mem,
7530 : : gen_rtx_REG (word_mode,
7531 : : regno_list[0]),
7532 : : gen_rtx_REG (word_mode,
7533 : : regno_list[1]),
7534 : : use_ppx));
7535 : 17 : RTX_FRAME_RELATED_P (insn) = 1;
7536 : 17 : rtx dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (3));
7537 : :
7538 : 51 : for (int i = 0; i < 2; i++)
7539 : : {
7540 : 68 : rtx dwarf_reg = gen_rtx_REG (word_mode,
7541 : 34 : regno_list[i]);
7542 : 34 : rtx sp_offset = plus_constant (Pmode,
7543 : : stack_pointer_rtx,
7544 : 34 : + UNITS_PER_WORD
7545 : 34 : * (1 - i));
7546 : 34 : rtx tmp = gen_rtx_SET (gen_frame_mem (DImode,
7547 : : sp_offset),
7548 : : dwarf_reg);
7549 : 34 : RTX_FRAME_RELATED_P (tmp) = 1;
7550 : 34 : XVECEXP (dwarf, 0, i + 1) = tmp;
7551 : : }
7552 : 17 : rtx sp_tmp = gen_rtx_SET (stack_pointer_rtx,
7553 : : plus_constant (Pmode,
7554 : : stack_pointer_rtx,
7555 : : -offset));
7556 : 17 : RTX_FRAME_RELATED_P (sp_tmp) = 1;
7557 : 17 : XVECEXP (dwarf, 0, 0) = sp_tmp;
7558 : 17 : add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf);
7559 : :
7560 : 17 : loaded_regnum = 0;
7561 : 17 : regno_list[0] = regno_list[1] = -1;
7562 : : }
7563 : : }
7564 : : else
7565 : : {
7566 : 6 : insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno),
7567 : : use_ppx));
7568 : 6 : RTX_FRAME_RELATED_P (insn) = 1;
7569 : 6 : aligned = true;
7570 : : }
7571 : : }
7572 : 10 : if (loaded_regnum == 1)
7573 : : {
7574 : 9 : insn = emit_insn (gen_push (gen_rtx_REG (word_mode,
7575 : 9 : regno_list[0]),
7576 : : use_ppx));
7577 : 9 : RTX_FRAME_RELATED_P (insn) = 1;
7578 : : }
7579 : : }
7580 : 423491 : }
7581 : :
7582 : : /* Emit a single register save at CFA - CFA_OFFSET. */
7583 : :
7584 : : static void
7585 : 331623 : ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
7586 : : HOST_WIDE_INT cfa_offset)
7587 : : {
7588 : 331623 : struct machine_function *m = cfun->machine;
7589 : 331623 : rtx reg = gen_rtx_REG (mode, regno);
7590 : 331623 : rtx mem, addr, base, insn;
7591 : 331623 : unsigned int align = GET_MODE_ALIGNMENT (mode);
7592 : :
7593 : 331623 : addr = choose_baseaddr (cfa_offset, &align);
7594 : 331623 : mem = gen_frame_mem (mode, addr);
7595 : :
7596 : : /* The location aligment depends upon the base register. */
7597 : 331623 : align = MIN (GET_MODE_ALIGNMENT (mode), align);
7598 : 331623 : gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1)));
7599 : 331623 : set_mem_align (mem, align);
7600 : :
7601 : 331623 : insn = emit_insn (gen_rtx_SET (mem, reg));
7602 : 331623 : RTX_FRAME_RELATED_P (insn) = 1;
7603 : :
7604 : 331623 : base = addr;
7605 : 331623 : if (GET_CODE (base) == PLUS)
7606 : 324945 : base = XEXP (base, 0);
7607 : 331623 : gcc_checking_assert (REG_P (base));
7608 : :
7609 : : /* When saving registers into a re-aligned local stack frame, avoid
7610 : : any tricky guessing by dwarf2out. */
7611 : 331623 : if (m->fs.realigned)
7612 : : {
7613 : 12800 : gcc_checking_assert (stack_realign_drap);
7614 : :
7615 : 12800 : if (regno == REGNO (crtl->drap_reg))
7616 : : {
7617 : : /* A bit of a hack. We force the DRAP register to be saved in
7618 : : the re-aligned stack frame, which provides us with a copy
7619 : : of the CFA that will last past the prologue. Install it. */
7620 : 0 : gcc_checking_assert (cfun->machine->fs.fp_valid);
7621 : 0 : addr = plus_constant (Pmode, hard_frame_pointer_rtx,
7622 : 0 : cfun->machine->fs.fp_offset - cfa_offset);
7623 : 0 : mem = gen_rtx_MEM (mode, addr);
7624 : 0 : add_reg_note (insn, REG_CFA_DEF_CFA, mem);
7625 : : }
7626 : : else
7627 : : {
7628 : : /* The frame pointer is a stable reference within the
7629 : : aligned frame. Use it. */
7630 : 12800 : gcc_checking_assert (cfun->machine->fs.fp_valid);
7631 : 12800 : addr = plus_constant (Pmode, hard_frame_pointer_rtx,
7632 : 12800 : cfun->machine->fs.fp_offset - cfa_offset);
7633 : 12800 : mem = gen_rtx_MEM (mode, addr);
7634 : 12800 : add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
7635 : : }
7636 : : }
7637 : :
7638 : 318823 : else if (base == stack_pointer_rtx && m->fs.sp_realigned
7639 : 12881 : && cfa_offset >= m->fs.sp_realigned_offset)
7640 : : {
7641 : 12881 : gcc_checking_assert (stack_realign_fp);
7642 : 12881 : add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
7643 : : }
7644 : :
7645 : : /* The memory may not be relative to the current CFA register,
7646 : : which means that we may need to generate a new pattern for
7647 : : use by the unwind info. */
7648 : 305942 : else if (base != m->fs.cfa_reg)
7649 : : {
7650 : 45084 : addr = plus_constant (Pmode, m->fs.cfa_reg,
7651 : 45084 : m->fs.cfa_offset - cfa_offset);
7652 : 45084 : mem = gen_rtx_MEM (mode, addr);
7653 : 45084 : add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (mem, reg));
7654 : : }
7655 : 331623 : }
7656 : :
7657 : : /* Emit code to save registers using MOV insns.
7658 : : First register is stored at CFA - CFA_OFFSET. */
7659 : : static void
7660 : 53 : ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
7661 : : {
7662 : 53 : unsigned int regno;
7663 : :
7664 : 4929 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7665 : 4876 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7666 : : {
7667 : 102 : ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
7668 : 102 : cfa_offset -= UNITS_PER_WORD;
7669 : : }
7670 : 53 : }
7671 : :
7672 : : /* Emit code to save SSE registers using MOV insns.
7673 : : First register is stored at CFA - CFA_OFFSET. */
7674 : : static void
7675 : 33153 : ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
7676 : : {
7677 : 33153 : unsigned int regno;
7678 : :
7679 : 3083229 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7680 : 3050076 : if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7681 : : {
7682 : 331521 : ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
7683 : 331521 : cfa_offset -= GET_MODE_SIZE (V4SFmode);
7684 : : }
7685 : 33153 : }
7686 : :
7687 : : static GTY(()) rtx queued_cfa_restores;
7688 : :
7689 : : /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
7690 : : manipulation insn. The value is on the stack at CFA - CFA_OFFSET.
7691 : : Don't add the note if the previously saved value will be left untouched
7692 : : within stack red-zone till return, as unwinders can find the same value
7693 : : in the register and on the stack. */
7694 : :
7695 : : static void
7696 : 2200178 : ix86_add_cfa_restore_note (rtx_insn *insn, rtx reg, HOST_WIDE_INT cfa_offset)
7697 : : {
7698 : 2200178 : if (!crtl->shrink_wrapped
7699 : 2187284 : && cfa_offset <= cfun->machine->fs.red_zone_offset)
7700 : : return;
7701 : :
7702 : 761226 : if (insn)
7703 : : {
7704 : 368700 : add_reg_note (insn, REG_CFA_RESTORE, reg);
7705 : 368700 : RTX_FRAME_RELATED_P (insn) = 1;
7706 : : }
7707 : : else
7708 : 392526 : queued_cfa_restores
7709 : 392526 : = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
7710 : : }
7711 : :
7712 : : /* Add queued REG_CFA_RESTORE notes if any to INSN. */
7713 : :
7714 : : static void
7715 : 2444769 : ix86_add_queued_cfa_restore_notes (rtx insn)
7716 : : {
7717 : 2444769 : rtx last;
7718 : 2444769 : if (!queued_cfa_restores)
7719 : : return;
7720 : 392526 : for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
7721 : : ;
7722 : 44525 : XEXP (last, 1) = REG_NOTES (insn);
7723 : 44525 : REG_NOTES (insn) = queued_cfa_restores;
7724 : 44525 : queued_cfa_restores = NULL_RTX;
7725 : 44525 : RTX_FRAME_RELATED_P (insn) = 1;
7726 : : }
7727 : :
7728 : : /* Expand prologue or epilogue stack adjustment.
7729 : : The pattern exist to put a dependency on all ebp-based memory accesses.
7730 : : STYLE should be negative if instructions should be marked as frame related,
7731 : : zero if %r11 register is live and cannot be freely used and positive
7732 : : otherwise. */
7733 : :
7734 : : static rtx
7735 : 1468011 : pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
7736 : : int style, bool set_cfa)
7737 : : {
7738 : 1468011 : struct machine_function *m = cfun->machine;
7739 : 1468011 : rtx addend = offset;
7740 : 1468011 : rtx insn;
7741 : 1468011 : bool add_frame_related_expr = false;
7742 : :
7743 : 1468011 : if (!x86_64_immediate_operand (offset, Pmode))
7744 : : {
7745 : : /* r11 is used by indirect sibcall return as well, set before the
7746 : : epilogue and used after the epilogue. */
7747 : 204 : if (style)
7748 : 179 : addend = gen_rtx_REG (Pmode, R11_REG);
7749 : : else
7750 : : {
7751 : 25 : gcc_assert (src != hard_frame_pointer_rtx
7752 : : && dest != hard_frame_pointer_rtx);
7753 : : addend = hard_frame_pointer_rtx;
7754 : : }
7755 : 204 : emit_insn (gen_rtx_SET (addend, offset));
7756 : 204 : if (style < 0)
7757 : 92 : add_frame_related_expr = true;
7758 : : }
7759 : :
7760 : 1468011 : insn = emit_insn (gen_pro_epilogue_adjust_stack_add
7761 : 1468011 : (Pmode, dest, src, addend));
7762 : 1468011 : if (style >= 0)
7763 : 642535 : ix86_add_queued_cfa_restore_notes (insn);
7764 : :
7765 : 1468011 : if (set_cfa)
7766 : : {
7767 : 1116241 : rtx r;
7768 : :
7769 : 1116241 : gcc_assert (m->fs.cfa_reg == src);
7770 : 1116241 : m->fs.cfa_offset += INTVAL (offset);
7771 : 1116241 : m->fs.cfa_reg = dest;
7772 : :
7773 : 1116241 : r = gen_rtx_PLUS (Pmode, src, offset);
7774 : 1116241 : r = gen_rtx_SET (dest, r);
7775 : 1116241 : add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
7776 : 1116241 : RTX_FRAME_RELATED_P (insn) = 1;
7777 : : }
7778 : 351770 : else if (style < 0)
7779 : : {
7780 : 286459 : RTX_FRAME_RELATED_P (insn) = 1;
7781 : 286459 : if (add_frame_related_expr)
7782 : : {
7783 : 23 : rtx r = gen_rtx_PLUS (Pmode, src, offset);
7784 : 23 : r = gen_rtx_SET (dest, r);
7785 : 23 : add_reg_note (insn, REG_FRAME_RELATED_EXPR, r);
7786 : : }
7787 : : }
7788 : :
7789 : 1468011 : if (dest == stack_pointer_rtx)
7790 : : {
7791 : 1468011 : HOST_WIDE_INT ooffset = m->fs.sp_offset;
7792 : 1468011 : bool valid = m->fs.sp_valid;
7793 : 1468011 : bool realigned = m->fs.sp_realigned;
7794 : :
7795 : 1468011 : if (src == hard_frame_pointer_rtx)
7796 : : {
7797 : 28817 : valid = m->fs.fp_valid;
7798 : 28817 : realigned = false;
7799 : 28817 : ooffset = m->fs.fp_offset;
7800 : : }
7801 : 1439194 : else if (src == crtl->drap_reg)
7802 : : {
7803 : 0 : valid = m->fs.drap_valid;
7804 : 0 : realigned = false;
7805 : 0 : ooffset = 0;
7806 : : }
7807 : : else
7808 : : {
7809 : : /* Else there are two possibilities: SP itself, which we set
7810 : : up as the default above. Or EH_RETURN_STACKADJ_RTX, which is
7811 : : taken care of this by hand along the eh_return path. */
7812 : 1439194 : gcc_checking_assert (src == stack_pointer_rtx
7813 : : || offset == const0_rtx);
7814 : : }
7815 : :
7816 : 1468011 : m->fs.sp_offset = ooffset - INTVAL (offset);
7817 : 1468011 : m->fs.sp_valid = valid;
7818 : 1468011 : m->fs.sp_realigned = realigned;
7819 : : }
7820 : 1468011 : return insn;
7821 : : }
7822 : :
7823 : : /* Find an available register to be used as dynamic realign argument
7824 : : pointer regsiter. Such a register will be written in prologue and
7825 : : used in begin of body, so it must not be
7826 : : 1. parameter passing register.
7827 : : 2. GOT pointer.
7828 : : We reuse static-chain register if it is available. Otherwise, we
7829 : : use DI for i386 and R13 for x86-64. We chose R13 since it has
7830 : : shorter encoding.
7831 : :
7832 : : Return: the regno of chosen register. */
7833 : :
7834 : : static unsigned int
7835 : 7122 : find_drap_reg (void)
7836 : : {
7837 : 7122 : tree decl = cfun->decl;
7838 : :
7839 : : /* Always use callee-saved register if there are no caller-saved
7840 : : registers. */
7841 : 7122 : if (TARGET_64BIT)
7842 : : {
7843 : : /* Use R13 for nested function or function need static chain.
7844 : : Since function with tail call may use any caller-saved
7845 : : registers in epilogue, DRAP must not use caller-saved
7846 : : register in such case. */
7847 : 6840 : if (DECL_STATIC_CHAIN (decl)
7848 : 6798 : || (cfun->machine->call_saved_registers
7849 : 6798 : == TYPE_NO_CALLER_SAVED_REGISTERS)
7850 : 13638 : || crtl->tail_call_emit)
7851 : 181 : return R13_REG;
7852 : :
7853 : : return R10_REG;
7854 : : }
7855 : : else
7856 : : {
7857 : : /* Use DI for nested function or function need static chain.
7858 : : Since function with tail call may use any caller-saved
7859 : : registers in epilogue, DRAP must not use caller-saved
7860 : : register in such case. */
7861 : 282 : if (DECL_STATIC_CHAIN (decl)
7862 : 282 : || (cfun->machine->call_saved_registers
7863 : 282 : == TYPE_NO_CALLER_SAVED_REGISTERS)
7864 : 282 : || crtl->tail_call_emit
7865 : 544 : || crtl->calls_eh_return)
7866 : : return DI_REG;
7867 : :
7868 : : /* Reuse static chain register if it isn't used for parameter
7869 : : passing. */
7870 : 262 : if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2)
7871 : : {
7872 : 262 : unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl));
7873 : 262 : if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0)
7874 : : return CX_REG;
7875 : : }
7876 : 0 : return DI_REG;
7877 : : }
7878 : : }
7879 : :
7880 : : /* Return minimum incoming stack alignment. */
7881 : :
7882 : : static unsigned int
7883 : 1568182 : ix86_minimum_incoming_stack_boundary (bool sibcall)
7884 : : {
7885 : 1568182 : unsigned int incoming_stack_boundary;
7886 : :
7887 : : /* Stack of interrupt handler is aligned to 128 bits in 64bit mode. */
7888 : 1568182 : if (cfun->machine->func_type != TYPE_NORMAL)
7889 : 118 : incoming_stack_boundary = TARGET_64BIT ? 128 : MIN_STACK_BOUNDARY;
7890 : : /* Prefer the one specified at command line. */
7891 : 1568064 : else if (ix86_user_incoming_stack_boundary)
7892 : : incoming_stack_boundary = ix86_user_incoming_stack_boundary;
7893 : : /* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary
7894 : : if -mstackrealign is used, it isn't used for sibcall check and
7895 : : estimated stack alignment is 128bit. */
7896 : 1568042 : else if (!sibcall
7897 : 1441536 : && ix86_force_align_arg_pointer
7898 : 4572 : && crtl->stack_alignment_estimated == 128)
7899 : 596 : incoming_stack_boundary = MIN_STACK_BOUNDARY;
7900 : : else
7901 : 1567446 : incoming_stack_boundary = ix86_default_incoming_stack_boundary;
7902 : :
7903 : : /* Incoming stack alignment can be changed on individual functions
7904 : : via force_align_arg_pointer attribute. We use the smallest
7905 : : incoming stack boundary. */
7906 : 1568182 : if (incoming_stack_boundary > MIN_STACK_BOUNDARY
7907 : 3135758 : && lookup_attribute ("force_align_arg_pointer",
7908 : 1567576 : TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7909 : 5708 : incoming_stack_boundary = MIN_STACK_BOUNDARY;
7910 : :
7911 : : /* The incoming stack frame has to be aligned at least at
7912 : : parm_stack_boundary. */
7913 : 1568182 : if (incoming_stack_boundary < crtl->parm_stack_boundary)
7914 : : incoming_stack_boundary = crtl->parm_stack_boundary;
7915 : :
7916 : : /* Stack at entrance of main is aligned by runtime. We use the
7917 : : smallest incoming stack boundary. */
7918 : 1568182 : if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
7919 : 139185 : && DECL_NAME (current_function_decl)
7920 : 139185 : && MAIN_NAME_P (DECL_NAME (current_function_decl))
7921 : 1570652 : && DECL_FILE_SCOPE_P (current_function_decl))
7922 : : incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7923 : :
7924 : 1568182 : return incoming_stack_boundary;
7925 : : }
7926 : :
7927 : : /* Update incoming stack boundary and estimated stack alignment. */
7928 : :
7929 : : static void
7930 : 1441671 : ix86_update_stack_boundary (void)
7931 : : {
7932 : 1441671 : ix86_incoming_stack_boundary
7933 : 1441671 : = ix86_minimum_incoming_stack_boundary (false);
7934 : :
7935 : : /* x86_64 vararg needs 16byte stack alignment for register save area. */
7936 : 1441671 : if (TARGET_64BIT
7937 : 1316262 : && cfun->stdarg
7938 : 21193 : && crtl->stack_alignment_estimated < 128)
7939 : 10142 : crtl->stack_alignment_estimated = 128;
7940 : :
7941 : : /* __tls_get_addr needs to be called with 16-byte aligned stack. */
7942 : 1441671 : if (ix86_tls_descriptor_calls_expanded_in_cfun
7943 : 1247 : && crtl->preferred_stack_boundary < 128)
7944 : 899 : crtl->preferred_stack_boundary = 128;
7945 : 1441671 : }
7946 : :
7947 : : /* Handle the TARGET_GET_DRAP_RTX hook. Return NULL if no DRAP is
7948 : : needed or an rtx for DRAP otherwise. */
7949 : :
7950 : : static rtx
7951 : 1544517 : ix86_get_drap_rtx (void)
7952 : : {
7953 : : /* We must use DRAP if there are outgoing arguments on stack or
7954 : : the stack pointer register is clobbered by asm statment and
7955 : : ACCUMULATE_OUTGOING_ARGS is false. */
7956 : 1544517 : if (ix86_force_drap
7957 : 1544517 : || ((cfun->machine->outgoing_args_on_stack
7958 : 1218082 : || crtl->sp_is_clobbered_by_asm)
7959 : 324490 : && !ACCUMULATE_OUTGOING_ARGS))
7960 : 304296 : crtl->need_drap = true;
7961 : :
7962 : 1544517 : if (stack_realign_drap)
7963 : : {
7964 : : /* Assign DRAP to vDRAP and returns vDRAP */
7965 : 7122 : unsigned int regno = find_drap_reg ();
7966 : 7122 : rtx drap_vreg;
7967 : 7122 : rtx arg_ptr;
7968 : 7122 : rtx_insn *seq, *insn;
7969 : :
7970 : 7122 : arg_ptr = gen_rtx_REG (Pmode, regno);
7971 : 7122 : crtl->drap_reg = arg_ptr;
7972 : :
7973 : 7122 : start_sequence ();
7974 : 7122 : drap_vreg = copy_to_reg (arg_ptr);
7975 : 7122 : seq = get_insns ();
7976 : 7122 : end_sequence ();
7977 : :
7978 : 7122 : insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
7979 : 7122 : if (!optimize)
7980 : : {
7981 : 1882 : add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg);
7982 : 1882 : RTX_FRAME_RELATED_P (insn) = 1;
7983 : : }
7984 : 7122 : return drap_vreg;
7985 : : }
7986 : : else
7987 : : return NULL;
7988 : : }
7989 : :
7990 : : /* Handle the TARGET_INTERNAL_ARG_POINTER hook. */
7991 : :
7992 : : static rtx
7993 : 1441671 : ix86_internal_arg_pointer (void)
7994 : : {
7995 : 1441671 : return virtual_incoming_args_rtx;
7996 : : }
7997 : :
7998 : : struct scratch_reg {
7999 : : rtx reg;
8000 : : bool saved;
8001 : : };
8002 : :
8003 : : /* Return a short-lived scratch register for use on function entry.
8004 : : In 32-bit mode, it is valid only after the registers are saved
8005 : : in the prologue. This register must be released by means of
8006 : : release_scratch_register_on_entry once it is dead. */
8007 : :
8008 : : static void
8009 : 25 : get_scratch_register_on_entry (struct scratch_reg *sr)
8010 : : {
8011 : 25 : int regno;
8012 : :
8013 : 25 : sr->saved = false;
8014 : :
8015 : 25 : if (TARGET_64BIT)
8016 : : {
8017 : : /* We always use R11 in 64-bit mode. */
8018 : : regno = R11_REG;
8019 : : }
8020 : : else
8021 : : {
8022 : 0 : tree decl = current_function_decl, fntype = TREE_TYPE (decl);
8023 : 0 : bool fastcall_p
8024 : 0 : = lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
8025 : 0 : bool thiscall_p
8026 : 0 : = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
8027 : 0 : bool static_chain_p = DECL_STATIC_CHAIN (decl);
8028 : 0 : int regparm = ix86_function_regparm (fntype, decl);
8029 : 0 : int drap_regno
8030 : 0 : = crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM;
8031 : :
8032 : : /* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax
8033 : : for the static chain register. */
8034 : 0 : if ((regparm < 1 || (fastcall_p && !static_chain_p))
8035 : 0 : && drap_regno != AX_REG)
8036 : : regno = AX_REG;
8037 : : /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
8038 : : for the static chain register. */
8039 : 0 : else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
8040 : : regno = AX_REG;
8041 : 0 : else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
8042 : : regno = DX_REG;
8043 : : /* ecx is the static chain register. */
8044 : 0 : else if (regparm < 3 && !fastcall_p && !thiscall_p
8045 : 0 : && !static_chain_p
8046 : 0 : && drap_regno != CX_REG)
8047 : : regno = CX_REG;
8048 : 0 : else if (ix86_save_reg (BX_REG, true, false))
8049 : : regno = BX_REG;
8050 : : /* esi is the static chain register. */
8051 : 0 : else if (!(regparm == 3 && static_chain_p)
8052 : 0 : && ix86_save_reg (SI_REG, true, false))
8053 : : regno = SI_REG;
8054 : 0 : else if (ix86_save_reg (DI_REG, true, false))
8055 : : regno = DI_REG;
8056 : : else
8057 : : {
8058 : 0 : regno = (drap_regno == AX_REG ? DX_REG : AX_REG);
8059 : 0 : sr->saved = true;
8060 : : }
8061 : : }
8062 : :
8063 : 25 : sr->reg = gen_rtx_REG (Pmode, regno);
8064 : 25 : if (sr->saved)
8065 : : {
8066 : 0 : rtx_insn *insn = emit_insn (gen_push (sr->reg));
8067 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
8068 : : }
8069 : 25 : }
8070 : :
8071 : : /* Release a scratch register obtained from the preceding function.
8072 : :
8073 : : If RELEASE_VIA_POP is true, we just pop the register off the stack
8074 : : to release it. This is what non-Linux systems use with -fstack-check.
8075 : :
8076 : : Otherwise we use OFFSET to locate the saved register and the
8077 : : allocated stack space becomes part of the local frame and is
8078 : : deallocated by the epilogue. */
8079 : :
8080 : : static void
8081 : 25 : release_scratch_register_on_entry (struct scratch_reg *sr, HOST_WIDE_INT offset,
8082 : : bool release_via_pop)
8083 : : {
8084 : 25 : if (sr->saved)
8085 : : {
8086 : 0 : if (release_via_pop)
8087 : : {
8088 : 0 : struct machine_function *m = cfun->machine;
8089 : 0 : rtx x, insn = emit_insn (gen_pop (sr->reg));
8090 : :
8091 : : /* The RX FRAME_RELATED_P mechanism doesn't know about pop. */
8092 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
8093 : 0 : x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
8094 : 0 : x = gen_rtx_SET (stack_pointer_rtx, x);
8095 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
8096 : 0 : m->fs.sp_offset -= UNITS_PER_WORD;
8097 : : }
8098 : : else
8099 : : {
8100 : 0 : rtx x = plus_constant (Pmode, stack_pointer_rtx, offset);
8101 : 0 : x = gen_rtx_SET (sr->reg, gen_rtx_MEM (word_mode, x));
8102 : 0 : emit_insn (x);
8103 : : }
8104 : : }
8105 : 25 : }
8106 : :
8107 : : /* Emit code to adjust the stack pointer by SIZE bytes while probing it.
8108 : :
8109 : : If INT_REGISTERS_SAVED is true, then integer registers have already been
8110 : : pushed on the stack.
8111 : :
8112 : : If PROTECTION AREA is true, then probe PROBE_INTERVAL plus a small dope
8113 : : beyond SIZE bytes.
8114 : :
8115 : : This assumes no knowledge of the current probing state, i.e. it is never
8116 : : allowed to allocate more than PROBE_INTERVAL bytes of stack space without
8117 : : a suitable probe. */
8118 : :
8119 : : static void
8120 : 125 : ix86_adjust_stack_and_probe (HOST_WIDE_INT size,
8121 : : const bool int_registers_saved,
8122 : : const bool protection_area)
8123 : : {
8124 : 125 : struct machine_function *m = cfun->machine;
8125 : :
8126 : : /* If this function does not statically allocate stack space, then
8127 : : no probes are needed. */
8128 : 125 : if (!size)
8129 : : {
8130 : : /* However, the allocation of space via pushes for register
8131 : : saves could be viewed as allocating space, but without the
8132 : : need to probe. */
8133 : 42 : if (m->frame.nregs || m->frame.nsseregs || frame_pointer_needed)
8134 : 22 : dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
8135 : : else
8136 : 20 : dump_stack_clash_frame_info (NO_PROBE_NO_FRAME, false);
8137 : 42 : return;
8138 : : }
8139 : :
8140 : : /* If we are a noreturn function, then we have to consider the
8141 : : possibility that we're called via a jump rather than a call.
8142 : :
8143 : : Thus we don't have the implicit probe generated by saving the
8144 : : return address into the stack at the call. Thus, the stack
8145 : : pointer could be anywhere in the guard page. The safe thing
8146 : : to do is emit a probe now.
8147 : :
8148 : : The probe can be avoided if we have already emitted any callee
8149 : : register saves into the stack or have a frame pointer (which will
8150 : : have been saved as well). Those saves will function as implicit
8151 : : probes.
8152 : :
8153 : : ?!? This should be revamped to work like aarch64 and s390 where
8154 : : we track the offset from the most recent probe. Normally that
8155 : : offset would be zero. For a noreturn function we would reset
8156 : : it to PROBE_INTERVAL - (STACK_BOUNDARY / BITS_PER_UNIT). Then
8157 : : we just probe when we cross PROBE_INTERVAL. */
8158 : 83 : if (TREE_THIS_VOLATILE (cfun->decl)
8159 : 15 : && !(m->frame.nregs || m->frame.nsseregs || frame_pointer_needed))
8160 : : {
8161 : : /* We can safely use any register here since we're just going to push
8162 : : its value and immediately pop it back. But we do try and avoid
8163 : : argument passing registers so as not to introduce dependencies in
8164 : : the pipeline. For 32 bit we use %esi and for 64 bit we use %rax. */
8165 : 15 : rtx dummy_reg = gen_rtx_REG (word_mode, TARGET_64BIT ? AX_REG : SI_REG);
8166 : 15 : rtx_insn *insn_push = emit_insn (gen_push (dummy_reg));
8167 : 15 : rtx_insn *insn_pop = emit_insn (gen_pop (dummy_reg));
8168 : 15 : m->fs.sp_offset -= UNITS_PER_WORD;
8169 : 15 : if (m->fs.cfa_reg == stack_pointer_rtx)
8170 : : {
8171 : 15 : m->fs.cfa_offset -= UNITS_PER_WORD;
8172 : 15 : rtx x = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
8173 : 15 : x = gen_rtx_SET (stack_pointer_rtx, x);
8174 : 15 : add_reg_note (insn_push, REG_CFA_ADJUST_CFA, x);
8175 : 15 : RTX_FRAME_RELATED_P (insn_push) = 1;
8176 : 15 : x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
8177 : 15 : x = gen_rtx_SET (stack_pointer_rtx, x);
8178 : 15 : add_reg_note (insn_pop, REG_CFA_ADJUST_CFA, x);
8179 : 15 : RTX_FRAME_RELATED_P (insn_pop) = 1;
8180 : : }
8181 : 15 : emit_insn (gen_blockage ());
8182 : : }
8183 : :
8184 : 83 : const HOST_WIDE_INT probe_interval = get_probe_interval ();
8185 : 83 : const int dope = 4 * UNITS_PER_WORD;
8186 : :
8187 : : /* If there is protection area, take it into account in the size. */
8188 : 83 : if (protection_area)
8189 : 25 : size += probe_interval + dope;
8190 : :
8191 : : /* If we allocate less than the size of the guard statically,
8192 : : then no probing is necessary, but we do need to allocate
8193 : : the stack. */
8194 : 58 : else if (size < (1 << param_stack_clash_protection_guard_size))
8195 : : {
8196 : 37 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8197 : : GEN_INT (-size), -1,
8198 : 37 : m->fs.cfa_reg == stack_pointer_rtx);
8199 : 37 : dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
8200 : 37 : return;
8201 : : }
8202 : :
8203 : : /* We're allocating a large enough stack frame that we need to
8204 : : emit probes. Either emit them inline or in a loop depending
8205 : : on the size. */
8206 : 46 : if (size <= 4 * probe_interval)
8207 : : {
8208 : : HOST_WIDE_INT i;
8209 : 49 : for (i = probe_interval; i <= size; i += probe_interval)
8210 : : {
8211 : : /* Allocate PROBE_INTERVAL bytes. */
8212 : 28 : rtx insn
8213 : 28 : = pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8214 : : GEN_INT (-probe_interval), -1,
8215 : 28 : m->fs.cfa_reg == stack_pointer_rtx);
8216 : 28 : add_reg_note (insn, REG_STACK_CHECK, const0_rtx);
8217 : :
8218 : : /* And probe at *sp. */
8219 : 28 : emit_stack_probe (stack_pointer_rtx);
8220 : 28 : emit_insn (gen_blockage ());
8221 : : }
8222 : :
8223 : : /* We need to allocate space for the residual, but we do not need
8224 : : to probe the residual... */
8225 : 21 : HOST_WIDE_INT residual = (i - probe_interval - size);
8226 : 21 : if (residual)
8227 : : {
8228 : 21 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8229 : : GEN_INT (residual), -1,
8230 : 21 : m->fs.cfa_reg == stack_pointer_rtx);
8231 : :
8232 : : /* ...except if there is a protection area to maintain. */
8233 : 21 : if (protection_area)
8234 : 12 : emit_stack_probe (stack_pointer_rtx);
8235 : : }
8236 : :
8237 : 21 : dump_stack_clash_frame_info (PROBE_INLINE, residual != 0);
8238 : : }
8239 : : else
8240 : : {
8241 : : /* We expect the GP registers to be saved when probes are used
8242 : : as the probing sequences might need a scratch register and
8243 : : the routine to allocate one assumes the integer registers
8244 : : have already been saved. */
8245 : 25 : gcc_assert (int_registers_saved);
8246 : :
8247 : 25 : struct scratch_reg sr;
8248 : 25 : get_scratch_register_on_entry (&sr);
8249 : :
8250 : : /* If we needed to save a register, then account for any space
8251 : : that was pushed (we are not going to pop the register when
8252 : : we do the restore). */
8253 : 25 : if (sr.saved)
8254 : 0 : size -= UNITS_PER_WORD;
8255 : :
8256 : : /* Step 1: round SIZE down to a multiple of the interval. */
8257 : 25 : HOST_WIDE_INT rounded_size = size & -probe_interval;
8258 : :
8259 : : /* Step 2: compute final value of the loop counter. Use lea if
8260 : : possible. */
8261 : 25 : rtx addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size);
8262 : 25 : rtx insn;
8263 : 25 : if (address_no_seg_operand (addr, Pmode))
8264 : 13 : insn = emit_insn (gen_rtx_SET (sr.reg, addr));
8265 : : else
8266 : : {
8267 : 12 : emit_move_insn (sr.reg, GEN_INT (-rounded_size));
8268 : 12 : insn = emit_insn (gen_rtx_SET (sr.reg,
8269 : : gen_rtx_PLUS (Pmode, sr.reg,
8270 : : stack_pointer_rtx)));
8271 : : }
8272 : 25 : if (m->fs.cfa_reg == stack_pointer_rtx)
8273 : : {
8274 : 22 : add_reg_note (insn, REG_CFA_DEF_CFA,
8275 : 22 : plus_constant (Pmode, sr.reg,
8276 : 22 : m->fs.cfa_offset + rounded_size));
8277 : 22 : RTX_FRAME_RELATED_P (insn) = 1;
8278 : : }
8279 : :
8280 : : /* Step 3: the loop. */
8281 : 25 : rtx size_rtx = GEN_INT (rounded_size);
8282 : 25 : insn = emit_insn (gen_adjust_stack_and_probe (Pmode, sr.reg, sr.reg,
8283 : : size_rtx));
8284 : 25 : if (m->fs.cfa_reg == stack_pointer_rtx)
8285 : : {
8286 : 22 : m->fs.cfa_offset += rounded_size;
8287 : 22 : add_reg_note (insn, REG_CFA_DEF_CFA,
8288 : 22 : plus_constant (Pmode, stack_pointer_rtx,
8289 : 22 : m->fs.cfa_offset));
8290 : 22 : RTX_FRAME_RELATED_P (insn) = 1;
8291 : : }
8292 : 25 : m->fs.sp_offset += rounded_size;
8293 : 25 : emit_insn (gen_blockage ());
8294 : :
8295 : : /* Step 4: adjust SP if we cannot assert at compile-time that SIZE
8296 : : is equal to ROUNDED_SIZE. */
8297 : :
8298 : 25 : if (size != rounded_size)
8299 : : {
8300 : 25 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8301 : : GEN_INT (rounded_size - size), -1,
8302 : 25 : m->fs.cfa_reg == stack_pointer_rtx);
8303 : :
8304 : 25 : if (protection_area)
8305 : 13 : emit_stack_probe (stack_pointer_rtx);
8306 : : }
8307 : :
8308 : 25 : dump_stack_clash_frame_info (PROBE_LOOP, size != rounded_size);
8309 : :
8310 : : /* This does not deallocate the space reserved for the scratch
8311 : : register. That will be deallocated in the epilogue. */
8312 : 25 : release_scratch_register_on_entry (&sr, size, false);
8313 : : }
8314 : :
8315 : : /* Adjust back to account for the protection area. */
8316 : 46 : if (protection_area)
8317 : 25 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8318 : 25 : GEN_INT (probe_interval + dope), -1,
8319 : 25 : m->fs.cfa_reg == stack_pointer_rtx);
8320 : :
8321 : : /* Make sure nothing is scheduled before we are done. */
8322 : 46 : emit_insn (gen_blockage ());
8323 : : }
8324 : :
8325 : : /* Adjust the stack pointer up to REG while probing it. */
8326 : :
8327 : : const char *
8328 : 25 : output_adjust_stack_and_probe (rtx reg)
8329 : : {
8330 : 25 : static int labelno = 0;
8331 : 25 : char loop_lab[32];
8332 : 25 : rtx xops[2];
8333 : :
8334 : 25 : ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
8335 : :
8336 : : /* Loop. */
8337 : 25 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
8338 : :
8339 : : /* SP = SP + PROBE_INTERVAL. */
8340 : 25 : xops[0] = stack_pointer_rtx;
8341 : 37 : xops[1] = GEN_INT (get_probe_interval ());
8342 : 25 : output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
8343 : :
8344 : : /* Probe at SP. */
8345 : 25 : xops[1] = const0_rtx;
8346 : 25 : output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops);
8347 : :
8348 : : /* Test if SP == LAST_ADDR. */
8349 : 25 : xops[0] = stack_pointer_rtx;
8350 : 25 : xops[1] = reg;
8351 : 25 : output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
8352 : :
8353 : : /* Branch. */
8354 : 25 : fputs ("\tjne\t", asm_out_file);
8355 : 25 : assemble_name_raw (asm_out_file, loop_lab);
8356 : 25 : fputc ('\n', asm_out_file);
8357 : :
8358 : 25 : return "";
8359 : : }
8360 : :
8361 : : /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
8362 : : inclusive. These are offsets from the current stack pointer.
8363 : :
8364 : : INT_REGISTERS_SAVED is true if integer registers have already been
8365 : : pushed on the stack. */
8366 : :
8367 : : static void
8368 : 0 : ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
8369 : : const bool int_registers_saved)
8370 : : {
8371 : 0 : const HOST_WIDE_INT probe_interval = get_probe_interval ();
8372 : :
8373 : : /* See if we have a constant small number of probes to generate. If so,
8374 : : that's the easy case. The run-time loop is made up of 6 insns in the
8375 : : generic case while the compile-time loop is made up of n insns for n #
8376 : : of intervals. */
8377 : 0 : if (size <= 6 * probe_interval)
8378 : : {
8379 : : HOST_WIDE_INT i;
8380 : :
8381 : : /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
8382 : : it exceeds SIZE. If only one probe is needed, this will not
8383 : : generate any code. Then probe at FIRST + SIZE. */
8384 : 0 : for (i = probe_interval; i < size; i += probe_interval)
8385 : 0 : emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
8386 : 0 : -(first + i)));
8387 : :
8388 : 0 : emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
8389 : 0 : -(first + size)));
8390 : : }
8391 : :
8392 : : /* Otherwise, do the same as above, but in a loop. Note that we must be
8393 : : extra careful with variables wrapping around because we might be at
8394 : : the very top (or the very bottom) of the address space and we have
8395 : : to be able to handle this case properly; in particular, we use an
8396 : : equality test for the loop condition. */
8397 : : else
8398 : : {
8399 : : /* We expect the GP registers to be saved when probes are used
8400 : : as the probing sequences might need a scratch register and
8401 : : the routine to allocate one assumes the integer registers
8402 : : have already been saved. */
8403 : 0 : gcc_assert (int_registers_saved);
8404 : :
8405 : 0 : HOST_WIDE_INT rounded_size, last;
8406 : 0 : struct scratch_reg sr;
8407 : :
8408 : 0 : get_scratch_register_on_entry (&sr);
8409 : :
8410 : :
8411 : : /* Step 1: round SIZE to the previous multiple of the interval. */
8412 : :
8413 : 0 : rounded_size = ROUND_DOWN (size, probe_interval);
8414 : :
8415 : :
8416 : : /* Step 2: compute initial and final value of the loop counter. */
8417 : :
8418 : : /* TEST_OFFSET = FIRST. */
8419 : 0 : emit_move_insn (sr.reg, GEN_INT (-first));
8420 : :
8421 : : /* LAST_OFFSET = FIRST + ROUNDED_SIZE. */
8422 : 0 : last = first + rounded_size;
8423 : :
8424 : :
8425 : : /* Step 3: the loop
8426 : :
8427 : : do
8428 : : {
8429 : : TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
8430 : : probe at TEST_ADDR
8431 : : }
8432 : : while (TEST_ADDR != LAST_ADDR)
8433 : :
8434 : : probes at FIRST + N * PROBE_INTERVAL for values of N from 1
8435 : : until it is equal to ROUNDED_SIZE. */
8436 : :
8437 : 0 : emit_insn
8438 : 0 : (gen_probe_stack_range (Pmode, sr.reg, sr.reg, GEN_INT (-last)));
8439 : :
8440 : :
8441 : : /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
8442 : : that SIZE is equal to ROUNDED_SIZE. */
8443 : :
8444 : 0 : if (size != rounded_size)
8445 : 0 : emit_stack_probe (plus_constant (Pmode,
8446 : 0 : gen_rtx_PLUS (Pmode,
8447 : : stack_pointer_rtx,
8448 : : sr.reg),
8449 : 0 : rounded_size - size));
8450 : :
8451 : 0 : release_scratch_register_on_entry (&sr, size, true);
8452 : : }
8453 : :
8454 : : /* Make sure nothing is scheduled before we are done. */
8455 : 0 : emit_insn (gen_blockage ());
8456 : 0 : }
8457 : :
8458 : : /* Probe a range of stack addresses from REG to END, inclusive. These are
8459 : : offsets from the current stack pointer. */
8460 : :
8461 : : const char *
8462 : 0 : output_probe_stack_range (rtx reg, rtx end)
8463 : : {
8464 : 0 : static int labelno = 0;
8465 : 0 : char loop_lab[32];
8466 : 0 : rtx xops[3];
8467 : :
8468 : 0 : ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
8469 : :
8470 : : /* Loop. */
8471 : 0 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
8472 : :
8473 : : /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
8474 : 0 : xops[0] = reg;
8475 : 0 : xops[1] = GEN_INT (get_probe_interval ());
8476 : 0 : output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
8477 : :
8478 : : /* Probe at TEST_ADDR. */
8479 : 0 : xops[0] = stack_pointer_rtx;
8480 : 0 : xops[1] = reg;
8481 : 0 : xops[2] = const0_rtx;
8482 : 0 : output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops);
8483 : :
8484 : : /* Test if TEST_ADDR == LAST_ADDR. */
8485 : 0 : xops[0] = reg;
8486 : 0 : xops[1] = end;
8487 : 0 : output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
8488 : :
8489 : : /* Branch. */
8490 : 0 : fputs ("\tjne\t", asm_out_file);
8491 : 0 : assemble_name_raw (asm_out_file, loop_lab);
8492 : 0 : fputc ('\n', asm_out_file);
8493 : :
8494 : 0 : return "";
8495 : : }
8496 : :
8497 : : /* Data passed to ix86_update_stack_alignment. */
8498 : : struct stack_access_data
8499 : : {
8500 : : /* The stack access register. */
8501 : : const_rtx reg;
8502 : : /* Pointer to stack alignment. */
8503 : : unsigned int *stack_alignment;
8504 : : };
8505 : :
8506 : : /* Update the maximum stack slot alignment from memory alignment in PAT. */
8507 : :
8508 : : static void
8509 : 53364652 : ix86_update_stack_alignment (rtx, const_rtx pat, void *data)
8510 : : {
8511 : : /* This insn may reference stack slot. Update the maximum stack slot
8512 : : alignment if the memory is referenced by the stack access register. */
8513 : 53364652 : stack_access_data *p = (stack_access_data *) data;
8514 : :
8515 : 53364652 : subrtx_iterator::array_type array;
8516 : 207867257 : FOR_EACH_SUBRTX (iter, array, pat, ALL)
8517 : : {
8518 : 176128554 : auto op = *iter;
8519 : 176128554 : if (MEM_P (op))
8520 : : {
8521 : 27315002 : if (reg_mentioned_p (p->reg, XEXP (op, 0)))
8522 : : {
8523 : 21625949 : unsigned int alignment = MEM_ALIGN (op);
8524 : :
8525 : 21625949 : if (alignment > *p->stack_alignment)
8526 : 57052 : *p->stack_alignment = alignment;
8527 : : break;
8528 : : }
8529 : : else
8530 : 5689053 : iter.skip_subrtxes ();
8531 : : }
8532 : : }
8533 : 53364652 : }
8534 : :
8535 : : /* Helper function for ix86_find_all_reg_uses. */
8536 : :
8537 : : static void
8538 : 44861047 : ix86_find_all_reg_uses_1 (HARD_REG_SET ®set,
8539 : : rtx set, unsigned int regno,
8540 : : auto_bitmap &worklist)
8541 : : {
8542 : 44861047 : rtx dest = SET_DEST (set);
8543 : :
8544 : 44861047 : if (!REG_P (dest))
8545 : 40562971 : return;
8546 : :
8547 : : /* Reject non-Pmode modes. */
8548 : 28125700 : if (GET_MODE (dest) != Pmode)
8549 : : return;
8550 : :
8551 : 18330660 : unsigned int dst_regno = REGNO (dest);
8552 : :
8553 : 18330660 : if (TEST_HARD_REG_BIT (regset, dst_regno))
8554 : : return;
8555 : :
8556 : 4298076 : const_rtx src = SET_SRC (set);
8557 : :
8558 : 4298076 : subrtx_iterator::array_type array;
8559 : 8531256 : FOR_EACH_SUBRTX (iter, array, src, ALL)
8560 : : {
8561 : 5553713 : auto op = *iter;
8562 : :
8563 : 5553713 : if (MEM_P (op))
8564 : 2927827 : iter.skip_subrtxes ();
8565 : :
8566 : 5553713 : if (REG_P (op) && REGNO (op) == regno)
8567 : : {
8568 : : /* Add this register to register set. */
8569 : 1320533 : add_to_hard_reg_set (®set, Pmode, dst_regno);
8570 : 1320533 : bitmap_set_bit (worklist, dst_regno);
8571 : 1320533 : break;
8572 : : }
8573 : : }
8574 : 4298076 : }
8575 : :
8576 : : /* Find all registers defined with register REGNO. */
8577 : :
8578 : : static void
8579 : 2322436 : ix86_find_all_reg_uses (HARD_REG_SET ®set,
8580 : : unsigned int regno, auto_bitmap &worklist)
8581 : : {
8582 : 2322436 : for (df_ref ref = DF_REG_USE_CHAIN (regno);
8583 : 79213346 : ref != NULL;
8584 : 76890910 : ref = DF_REF_NEXT_REG (ref))
8585 : : {
8586 : 76890910 : if (DF_REF_IS_ARTIFICIAL (ref))
8587 : 16250801 : continue;
8588 : :
8589 : 60640109 : rtx_insn *insn = DF_REF_INSN (ref);
8590 : :
8591 : 60640109 : if (!NONJUMP_INSN_P (insn))
8592 : 16744035 : continue;
8593 : :
8594 : 43896074 : unsigned int ref_regno = DF_REF_REGNO (ref);
8595 : :
8596 : 43896074 : rtx set = single_set (insn);
8597 : 43896074 : if (set)
8598 : : {
8599 : 43020340 : ix86_find_all_reg_uses_1 (regset, set,
8600 : : ref_regno, worklist);
8601 : 43020340 : continue;
8602 : : }
8603 : :
8604 : 875734 : rtx pat = PATTERN (insn);
8605 : 875734 : if (GET_CODE (pat) != PARALLEL)
8606 : 129225 : continue;
8607 : :
8608 : 3162221 : for (int i = 0; i < XVECLEN (pat, 0); i++)
8609 : : {
8610 : 2415712 : rtx exp = XVECEXP (pat, 0, i);
8611 : :
8612 : 2415712 : if (GET_CODE (exp) == SET)
8613 : 1840707 : ix86_find_all_reg_uses_1 (regset, exp,
8614 : : ref_regno, worklist);
8615 : : }
8616 : : }
8617 : 2322436 : }
8618 : :
8619 : : /* Set stack_frame_required to false if stack frame isn't required.
8620 : : Update STACK_ALIGNMENT to the largest alignment, in bits, of stack
8621 : : slot used if stack frame is required and CHECK_STACK_SLOT is true. */
8622 : :
8623 : : static void
8624 : 1440824 : ix86_find_max_used_stack_alignment (unsigned int &stack_alignment,
8625 : : bool check_stack_slot)
8626 : : {
8627 : 1440824 : HARD_REG_SET set_up_by_prologue, prologue_used;
8628 : 1440824 : basic_block bb;
8629 : :
8630 : 5763296 : CLEAR_HARD_REG_SET (prologue_used);
8631 : 1440824 : CLEAR_HARD_REG_SET (set_up_by_prologue);
8632 : 1440824 : add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM);
8633 : 1440824 : add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM);
8634 : 1440824 : add_to_hard_reg_set (&set_up_by_prologue, Pmode,
8635 : : HARD_FRAME_POINTER_REGNUM);
8636 : :
8637 : 1440824 : bool require_stack_frame = false;
8638 : :
8639 : 15502771 : FOR_EACH_BB_FN (bb, cfun)
8640 : : {
8641 : 14061947 : rtx_insn *insn;
8642 : 86225373 : FOR_BB_INSNS (bb, insn)
8643 : 79937090 : if (NONDEBUG_INSN_P (insn)
8644 : 79937090 : && requires_stack_frame_p (insn, prologue_used,
8645 : : set_up_by_prologue))
8646 : : {
8647 : : require_stack_frame = true;
8648 : : break;
8649 : : }
8650 : : }
8651 : :
8652 : 1440824 : cfun->machine->stack_frame_required = require_stack_frame;
8653 : :
8654 : : /* Stop if we don't need to check stack slot. */
8655 : 1440824 : if (!check_stack_slot)
8656 : 756759 : return;
8657 : :
8658 : : /* The preferred stack alignment is the minimum stack alignment. */
8659 : 684065 : if (stack_alignment > crtl->preferred_stack_boundary)
8660 : 140357 : stack_alignment = crtl->preferred_stack_boundary;
8661 : :
8662 : : HARD_REG_SET stack_slot_access;
8663 : 684065 : CLEAR_HARD_REG_SET (stack_slot_access);
8664 : :
8665 : : /* Stack slot can be accessed by stack pointer, frame pointer or
8666 : : registers defined by stack pointer or frame pointer. */
8667 : 684065 : auto_bitmap worklist;
8668 : :
8669 : 684065 : add_to_hard_reg_set (&stack_slot_access, Pmode, STACK_POINTER_REGNUM);
8670 : 684065 : bitmap_set_bit (worklist, STACK_POINTER_REGNUM);
8671 : :
8672 : 684065 : if (frame_pointer_needed)
8673 : : {
8674 : 317838 : add_to_hard_reg_set (&stack_slot_access, Pmode,
8675 : : HARD_FRAME_POINTER_REGNUM);
8676 : 317838 : bitmap_set_bit (worklist, HARD_FRAME_POINTER_REGNUM);
8677 : : }
8678 : :
8679 : 2322436 : unsigned int regno;
8680 : :
8681 : 2322436 : do
8682 : : {
8683 : 2322436 : regno = bitmap_clear_first_set_bit (worklist);
8684 : 2322436 : ix86_find_all_reg_uses (stack_slot_access, regno, worklist);
8685 : : }
8686 : 2322436 : while (!bitmap_empty_p (worklist));
8687 : :
8688 : 684065 : hard_reg_set_iterator hrsi;
8689 : 684065 : stack_access_data data;
8690 : :
8691 : 684065 : data.stack_alignment = &stack_alignment;
8692 : :
8693 : 3006501 : EXECUTE_IF_SET_IN_HARD_REG_SET (stack_slot_access, 0, regno, hrsi)
8694 : 2322436 : for (df_ref ref = DF_REG_USE_CHAIN (regno);
8695 : 79213346 : ref != NULL;
8696 : 76890910 : ref = DF_REF_NEXT_REG (ref))
8697 : : {
8698 : 76890910 : if (DF_REF_IS_ARTIFICIAL (ref))
8699 : 16250801 : continue;
8700 : :
8701 : 60640109 : rtx_insn *insn = DF_REF_INSN (ref);
8702 : :
8703 : 60640109 : if (!NONJUMP_INSN_P (insn))
8704 : 16744035 : continue;
8705 : :
8706 : 43896074 : data.reg = DF_REF_REG (ref);
8707 : 43896074 : note_stores (insn, ix86_update_stack_alignment, &data);
8708 : : }
8709 : 684065 : }
8710 : :
8711 : : /* Finalize stack_realign_needed and frame_pointer_needed flags, which
8712 : : will guide prologue/epilogue to be generated in correct form. */
8713 : :
8714 : : static void
8715 : 3259130 : ix86_finalize_stack_frame_flags (void)
8716 : : {
8717 : : /* Check if stack realign is really needed after reload, and
8718 : : stores result in cfun */
8719 : 3259130 : unsigned int incoming_stack_boundary
8720 : 3259130 : = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
8721 : 3259130 : ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
8722 : 3259130 : unsigned int stack_alignment
8723 : 1129177 : = (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
8724 : 4388307 : ? crtl->max_used_stack_slot_alignment
8725 : 3259130 : : crtl->stack_alignment_needed);
8726 : 3259130 : unsigned int stack_realign
8727 : 3259130 : = (incoming_stack_boundary < stack_alignment);
8728 : 3259130 : bool recompute_frame_layout_p = false;
8729 : :
8730 : 3259130 : if (crtl->stack_realign_finalized)
8731 : : {
8732 : : /* After stack_realign_needed is finalized, we can't no longer
8733 : : change it. */
8734 : 1818306 : gcc_assert (crtl->stack_realign_needed == stack_realign);
8735 : 1818306 : return;
8736 : : }
8737 : :
8738 : : /* It is always safe to compute max_used_stack_alignment. We
8739 : : compute it only if 128-bit aligned load/store may be generated
8740 : : on misaligned stack slot which will lead to segfault. */
8741 : 2881648 : bool check_stack_slot
8742 : 1440824 : = (stack_realign || crtl->max_used_stack_slot_alignment >= 128);
8743 : 1440824 : ix86_find_max_used_stack_alignment (stack_alignment,
8744 : : check_stack_slot);
8745 : :
8746 : : /* If the only reason for frame_pointer_needed is that we conservatively
8747 : : assumed stack realignment might be needed or -fno-omit-frame-pointer
8748 : : is used, but in the end nothing that needed the stack alignment had
8749 : : been spilled nor stack access, clear frame_pointer_needed and say we
8750 : : don't need stack realignment.
8751 : :
8752 : : When vector register is used for piecewise move and store, we don't
8753 : : increase stack_alignment_needed as there is no register spill for
8754 : : piecewise move and store. Since stack_realign_needed is set to true
8755 : : by checking stack_alignment_estimated which is updated by pseudo
8756 : : vector register usage, we also need to check stack_realign_needed to
8757 : : eliminate frame pointer. */
8758 : 1440824 : if ((stack_realign
8759 : 1376461 : || (!flag_omit_frame_pointer && optimize)
8760 : 1366228 : || crtl->stack_realign_needed)
8761 : 75169 : && frame_pointer_needed
8762 : 75169 : && crtl->is_leaf
8763 : 50895 : && crtl->sp_is_unchanging
8764 : 50843 : && !ix86_current_function_calls_tls_descriptor
8765 : 50843 : && !crtl->accesses_prior_frames
8766 : 50843 : && !cfun->calls_alloca
8767 : 50843 : && !crtl->calls_eh_return
8768 : : /* See ira_setup_eliminable_regset for the rationale. */
8769 : 50843 : && !(STACK_CHECK_MOVING_SP
8770 : 50843 : && flag_stack_check
8771 : 0 : && flag_exceptions
8772 : 0 : && cfun->can_throw_non_call_exceptions)
8773 : 50843 : && !ix86_frame_pointer_required ()
8774 : 50842 : && ix86_get_frame_size () == 0
8775 : 33483 : && ix86_nsaved_sseregs () == 0
8776 : 1474307 : && ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0)
8777 : : {
8778 : 33483 : if (cfun->machine->stack_frame_required)
8779 : : {
8780 : : /* Stack frame is required. If stack alignment needed is less
8781 : : than incoming stack boundary, don't realign stack. */
8782 : 217 : stack_realign = incoming_stack_boundary < stack_alignment;
8783 : 217 : if (!stack_realign)
8784 : : {
8785 : 217 : crtl->max_used_stack_slot_alignment
8786 : 217 : = incoming_stack_boundary;
8787 : 217 : crtl->stack_alignment_needed
8788 : 217 : = incoming_stack_boundary;
8789 : : /* Also update preferred_stack_boundary for leaf
8790 : : functions. */
8791 : 217 : crtl->preferred_stack_boundary
8792 : 217 : = incoming_stack_boundary;
8793 : : }
8794 : : }
8795 : : else
8796 : : {
8797 : : /* If drap has been set, but it actually isn't live at the
8798 : : start of the function, there is no reason to set it up. */
8799 : 33266 : if (crtl->drap_reg)
8800 : : {
8801 : 32 : basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
8802 : 64 : if (! REGNO_REG_SET_P (DF_LR_IN (bb),
8803 : : REGNO (crtl->drap_reg)))
8804 : : {
8805 : 32 : crtl->drap_reg = NULL_RTX;
8806 : 32 : crtl->need_drap = false;
8807 : : }
8808 : : }
8809 : : else
8810 : 33234 : cfun->machine->no_drap_save_restore = true;
8811 : :
8812 : 33266 : frame_pointer_needed = false;
8813 : 33266 : stack_realign = false;
8814 : 33266 : crtl->max_used_stack_slot_alignment = incoming_stack_boundary;
8815 : 33266 : crtl->stack_alignment_needed = incoming_stack_boundary;
8816 : 33266 : crtl->stack_alignment_estimated = incoming_stack_boundary;
8817 : 33266 : if (crtl->preferred_stack_boundary > incoming_stack_boundary)
8818 : 0 : crtl->preferred_stack_boundary = incoming_stack_boundary;
8819 : 33266 : df_finish_pass (true);
8820 : 33266 : df_scan_alloc (NULL);
8821 : 33266 : df_scan_blocks ();
8822 : 33266 : df_compute_regs_ever_live (true);
8823 : 33266 : df_analyze ();
8824 : :
8825 : 33266 : if (flag_var_tracking)
8826 : : {
8827 : : /* Since frame pointer is no longer available, replace it with
8828 : : stack pointer - UNITS_PER_WORD in debug insns. */
8829 : 131 : df_ref ref, next;
8830 : 131 : for (ref = DF_REG_USE_CHAIN (HARD_FRAME_POINTER_REGNUM);
8831 : 131 : ref; ref = next)
8832 : : {
8833 : 0 : next = DF_REF_NEXT_REG (ref);
8834 : 0 : if (!DF_REF_INSN_INFO (ref))
8835 : 0 : continue;
8836 : :
8837 : : /* Make sure the next ref is for a different instruction,
8838 : : so that we're not affected by the rescan. */
8839 : 0 : rtx_insn *insn = DF_REF_INSN (ref);
8840 : 0 : while (next && DF_REF_INSN (next) == insn)
8841 : 0 : next = DF_REF_NEXT_REG (next);
8842 : :
8843 : 0 : if (DEBUG_INSN_P (insn))
8844 : : {
8845 : : bool changed = false;
8846 : 0 : for (; ref != next; ref = DF_REF_NEXT_REG (ref))
8847 : : {
8848 : 0 : rtx *loc = DF_REF_LOC (ref);
8849 : 0 : if (*loc == hard_frame_pointer_rtx)
8850 : : {
8851 : 0 : *loc = plus_constant (Pmode,
8852 : : stack_pointer_rtx,
8853 : 0 : -UNITS_PER_WORD);
8854 : 0 : changed = true;
8855 : : }
8856 : : }
8857 : 0 : if (changed)
8858 : 0 : df_insn_rescan (insn);
8859 : : }
8860 : : }
8861 : : }
8862 : :
8863 : : recompute_frame_layout_p = true;
8864 : : }
8865 : : }
8866 : 1407341 : else if (crtl->max_used_stack_slot_alignment >= 128
8867 : 649499 : && cfun->machine->stack_frame_required)
8868 : : {
8869 : : /* We don't need to realign stack. max_used_stack_alignment is
8870 : : used to decide how stack frame should be aligned. This is
8871 : : independent of any psABIs nor 32-bit vs 64-bit. */
8872 : 605861 : cfun->machine->max_used_stack_alignment
8873 : 605861 : = stack_alignment / BITS_PER_UNIT;
8874 : : }
8875 : :
8876 : 1440824 : if (crtl->stack_realign_needed != stack_realign)
8877 : 33699 : recompute_frame_layout_p = true;
8878 : 1440824 : crtl->stack_realign_needed = stack_realign;
8879 : 1440824 : crtl->stack_realign_finalized = true;
8880 : 1440824 : if (recompute_frame_layout_p)
8881 : 33777 : ix86_compute_frame_layout ();
8882 : : }
8883 : :
8884 : : /* Delete SET_GOT right after entry block if it is allocated to reg. */
8885 : :
8886 : : static void
8887 : 0 : ix86_elim_entry_set_got (rtx reg)
8888 : : {
8889 : 0 : basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
8890 : 0 : rtx_insn *c_insn = BB_HEAD (bb);
8891 : 0 : if (!NONDEBUG_INSN_P (c_insn))
8892 : 0 : c_insn = next_nonnote_nondebug_insn (c_insn);
8893 : 0 : if (c_insn && NONJUMP_INSN_P (c_insn))
8894 : : {
8895 : 0 : rtx pat = PATTERN (c_insn);
8896 : 0 : if (GET_CODE (pat) == PARALLEL)
8897 : : {
8898 : 0 : rtx set = XVECEXP (pat, 0, 0);
8899 : 0 : if (GET_CODE (set) == SET
8900 : 0 : && GET_CODE (SET_SRC (set)) == UNSPEC
8901 : 0 : && XINT (SET_SRC (set), 1) == UNSPEC_SET_GOT
8902 : 0 : && REGNO (SET_DEST (set)) == REGNO (reg))
8903 : 0 : delete_insn (c_insn);
8904 : : }
8905 : : }
8906 : 0 : }
8907 : :
8908 : : static rtx
8909 : 193166 : gen_frame_set (rtx reg, rtx frame_reg, int offset, bool store)
8910 : : {
8911 : 193166 : rtx addr, mem;
8912 : :
8913 : 193166 : if (offset)
8914 : 184480 : addr = plus_constant (Pmode, frame_reg, offset);
8915 : 193166 : mem = gen_frame_mem (GET_MODE (reg), offset ? addr : frame_reg);
8916 : 193166 : return gen_rtx_SET (store ? mem : reg, store ? reg : mem);
8917 : : }
8918 : :
8919 : : static inline rtx
8920 : 100333 : gen_frame_load (rtx reg, rtx frame_reg, int offset)
8921 : : {
8922 : 100333 : return gen_frame_set (reg, frame_reg, offset, false);
8923 : : }
8924 : :
8925 : : static inline rtx
8926 : 92833 : gen_frame_store (rtx reg, rtx frame_reg, int offset)
8927 : : {
8928 : 92833 : return gen_frame_set (reg, frame_reg, offset, true);
8929 : : }
8930 : :
8931 : : static void
8932 : 7045 : ix86_emit_outlined_ms2sysv_save (const struct ix86_frame &frame)
8933 : : {
8934 : 7045 : struct machine_function *m = cfun->machine;
8935 : 7045 : const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS
8936 : 7045 : + m->call_ms2sysv_extra_regs;
8937 : 7045 : rtvec v = rtvec_alloc (ncregs + 1);
8938 : 7045 : unsigned int align, i, vi = 0;
8939 : 7045 : rtx_insn *insn;
8940 : 7045 : rtx sym, addr;
8941 : 7045 : rtx rax = gen_rtx_REG (word_mode, AX_REG);
8942 : 7045 : const class xlogue_layout &xlogue = xlogue_layout::get_instance ();
8943 : :
8944 : : /* AL should only be live with sysv_abi. */
8945 : 7045 : gcc_assert (!ix86_eax_live_at_start_p ());
8946 : 7045 : gcc_assert (m->fs.sp_offset >= frame.sse_reg_save_offset);
8947 : :
8948 : : /* Setup RAX as the stub's base pointer. We use stack_realign_offset rather
8949 : : we've actually realigned the stack or not. */
8950 : 7045 : align = GET_MODE_ALIGNMENT (V4SFmode);
8951 : 7045 : addr = choose_baseaddr (frame.stack_realign_offset
8952 : 7045 : + xlogue.get_stub_ptr_offset (), &align, AX_REG);
8953 : 7045 : gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode));
8954 : :
8955 : 7045 : emit_insn (gen_rtx_SET (rax, addr));
8956 : :
8957 : : /* Get the stub symbol. */
8958 : 8327 : sym = xlogue.get_stub_rtx (frame_pointer_needed ? XLOGUE_STUB_SAVE_HFP
8959 : : : XLOGUE_STUB_SAVE);
8960 : 7045 : RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
8961 : :
8962 : 99878 : for (i = 0; i < ncregs; ++i)
8963 : : {
8964 : 92833 : const xlogue_layout::reginfo &r = xlogue.get_reginfo (i);
8965 : 92833 : rtx reg = gen_rtx_REG ((SSE_REGNO_P (r.regno) ? V4SFmode : word_mode),
8966 : 92833 : r.regno);
8967 : 92833 : RTVEC_ELT (v, vi++) = gen_frame_store (reg, rax, -r.offset);
8968 : : }
8969 : :
8970 : 7045 : gcc_assert (vi == (unsigned)GET_NUM_ELEM (v));
8971 : :
8972 : 7045 : insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, v));
8973 : 7045 : RTX_FRAME_RELATED_P (insn) = true;
8974 : 7045 : }
8975 : :
8976 : : /* Generate and return an insn body to AND X with Y. */
8977 : :
8978 : : static rtx_insn *
8979 : 31237 : gen_and2_insn (rtx x, rtx y)
8980 : : {
8981 : 31237 : enum insn_code icode = optab_handler (and_optab, GET_MODE (x));
8982 : :
8983 : 31237 : gcc_assert (insn_operand_matches (icode, 0, x));
8984 : 31237 : gcc_assert (insn_operand_matches (icode, 1, x));
8985 : 31237 : gcc_assert (insn_operand_matches (icode, 2, y));
8986 : :
8987 : 31237 : return GEN_FCN (icode) (x, x, y);
8988 : : }
8989 : :
8990 : : /* Expand the prologue into a bunch of separate insns. */
8991 : :
8992 : : void
8993 : 1440898 : ix86_expand_prologue (void)
8994 : : {
8995 : 1440898 : struct machine_function *m = cfun->machine;
8996 : 1440898 : rtx insn, t;
8997 : 1440898 : HOST_WIDE_INT allocate;
8998 : 1440898 : bool int_registers_saved;
8999 : 1440898 : bool sse_registers_saved;
9000 : 1440898 : bool save_stub_call_needed;
9001 : 1440898 : rtx static_chain = NULL_RTX;
9002 : :
9003 : 1440898 : ix86_last_zero_store_uid = 0;
9004 : 1440898 : if (ix86_function_naked (current_function_decl))
9005 : : {
9006 : 74 : if (flag_stack_usage_info)
9007 : 0 : current_function_static_stack_size = 0;
9008 : 74 : return;
9009 : : }
9010 : :
9011 : 1440824 : ix86_finalize_stack_frame_flags ();
9012 : :
9013 : : /* DRAP should not coexist with stack_realign_fp */
9014 : 1440824 : gcc_assert (!(crtl->drap_reg && stack_realign_fp));
9015 : :
9016 : 1440824 : memset (&m->fs, 0, sizeof (m->fs));
9017 : :
9018 : : /* Initialize CFA state for before the prologue. */
9019 : 1440824 : m->fs.cfa_reg = stack_pointer_rtx;
9020 : 1440824 : m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET;
9021 : :
9022 : : /* Track SP offset to the CFA. We continue tracking this after we've
9023 : : swapped the CFA register away from SP. In the case of re-alignment
9024 : : this is fudged; we're interested to offsets within the local frame. */
9025 : 1440824 : m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
9026 : 1440824 : m->fs.sp_valid = true;
9027 : 1440824 : m->fs.sp_realigned = false;
9028 : :
9029 : 1440824 : const struct ix86_frame &frame = cfun->machine->frame;
9030 : :
9031 : 1440824 : if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
9032 : : {
9033 : : /* We should have already generated an error for any use of
9034 : : ms_hook on a nested function. */
9035 : 0 : gcc_checking_assert (!ix86_static_chain_on_stack);
9036 : :
9037 : : /* Check if profiling is active and we shall use profiling before
9038 : : prologue variant. If so sorry. */
9039 : 0 : if (crtl->profile && flag_fentry != 0)
9040 : 0 : sorry ("%<ms_hook_prologue%> attribute is not compatible "
9041 : : "with %<-mfentry%> for 32-bit");
9042 : :
9043 : : /* In ix86_asm_output_function_label we emitted:
9044 : : 8b ff movl.s %edi,%edi
9045 : : 55 push %ebp
9046 : : 8b ec movl.s %esp,%ebp
9047 : :
9048 : : This matches the hookable function prologue in Win32 API
9049 : : functions in Microsoft Windows XP Service Pack 2 and newer.
9050 : : Wine uses this to enable Windows apps to hook the Win32 API
9051 : : functions provided by Wine.
9052 : :
9053 : : What that means is that we've already set up the frame pointer. */
9054 : :
9055 : 0 : if (frame_pointer_needed
9056 : 0 : && !(crtl->drap_reg && crtl->stack_realign_needed))
9057 : : {
9058 : 0 : rtx push, mov;
9059 : :
9060 : : /* We've decided to use the frame pointer already set up.
9061 : : Describe this to the unwinder by pretending that both
9062 : : push and mov insns happen right here.
9063 : :
9064 : : Putting the unwind info here at the end of the ms_hook
9065 : : is done so that we can make absolutely certain we get
9066 : : the required byte sequence at the start of the function,
9067 : : rather than relying on an assembler that can produce
9068 : : the exact encoding required.
9069 : :
9070 : : However it does mean (in the unpatched case) that we have
9071 : : a 1 insn window where the asynchronous unwind info is
9072 : : incorrect. However, if we placed the unwind info at
9073 : : its correct location we would have incorrect unwind info
9074 : : in the patched case. Which is probably all moot since
9075 : : I don't expect Wine generates dwarf2 unwind info for the
9076 : : system libraries that use this feature. */
9077 : :
9078 : 0 : insn = emit_insn (gen_blockage ());
9079 : :
9080 : 0 : push = gen_push (hard_frame_pointer_rtx);
9081 : 0 : mov = gen_rtx_SET (hard_frame_pointer_rtx,
9082 : : stack_pointer_rtx);
9083 : 0 : RTX_FRAME_RELATED_P (push) = 1;
9084 : 0 : RTX_FRAME_RELATED_P (mov) = 1;
9085 : :
9086 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9087 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9088 : : gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov)));
9089 : :
9090 : : /* Note that gen_push incremented m->fs.cfa_offset, even
9091 : : though we didn't emit the push insn here. */
9092 : 0 : m->fs.cfa_reg = hard_frame_pointer_rtx;
9093 : 0 : m->fs.fp_offset = m->fs.cfa_offset;
9094 : 0 : m->fs.fp_valid = true;
9095 : 0 : }
9096 : : else
9097 : : {
9098 : : /* The frame pointer is not needed so pop %ebp again.
9099 : : This leaves us with a pristine state. */
9100 : 0 : emit_insn (gen_pop (hard_frame_pointer_rtx));
9101 : : }
9102 : : }
9103 : :
9104 : : /* The first insn of a function that accepts its static chain on the
9105 : : stack is to push the register that would be filled in by a direct
9106 : : call. This insn will be skipped by the trampoline. */
9107 : 1440824 : else if (ix86_static_chain_on_stack)
9108 : : {
9109 : 0 : static_chain = ix86_static_chain (cfun->decl, false);
9110 : 0 : insn = emit_insn (gen_push (static_chain));
9111 : 0 : emit_insn (gen_blockage ());
9112 : :
9113 : : /* We don't want to interpret this push insn as a register save,
9114 : : only as a stack adjustment. The real copy of the register as
9115 : : a save will be done later, if needed. */
9116 : 0 : t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
9117 : 0 : t = gen_rtx_SET (stack_pointer_rtx, t);
9118 : 0 : add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
9119 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9120 : : }
9121 : :
9122 : : /* Emit prologue code to adjust stack alignment and setup DRAP, in case
9123 : : of DRAP is needed and stack realignment is really needed after reload */
9124 : 1440824 : if (stack_realign_drap)
9125 : : {
9126 : 6907 : int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
9127 : :
9128 : : /* Can't use DRAP in interrupt function. */
9129 : 6907 : if (cfun->machine->func_type != TYPE_NORMAL)
9130 : 0 : sorry ("Dynamic Realign Argument Pointer (DRAP) not supported "
9131 : : "in interrupt service routine. This may be worked "
9132 : : "around by avoiding functions with aggregate return.");
9133 : :
9134 : : /* Only need to push parameter pointer reg if it is caller saved. */
9135 : 6907 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
9136 : : {
9137 : : /* Push arg pointer reg */
9138 : 130 : insn = emit_insn (gen_push (crtl->drap_reg));
9139 : 130 : RTX_FRAME_RELATED_P (insn) = 1;
9140 : : }
9141 : :
9142 : : /* Grab the argument pointer. */
9143 : 6907 : t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
9144 : 6907 : insn = emit_insn (gen_rtx_SET (crtl->drap_reg, t));
9145 : 6907 : RTX_FRAME_RELATED_P (insn) = 1;
9146 : 6907 : m->fs.cfa_reg = crtl->drap_reg;
9147 : 6907 : m->fs.cfa_offset = 0;
9148 : :
9149 : : /* Align the stack. */
9150 : 6907 : insn = emit_insn (gen_and2_insn (stack_pointer_rtx,
9151 : 6907 : GEN_INT (-align_bytes)));
9152 : 6907 : RTX_FRAME_RELATED_P (insn) = 1;
9153 : :
9154 : : /* Replicate the return address on the stack so that return
9155 : : address can be reached via (argp - 1) slot. This is needed
9156 : : to implement macro RETURN_ADDR_RTX and intrinsic function
9157 : : expand_builtin_return_addr etc. */
9158 : 7189 : t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
9159 : 6907 : t = gen_frame_mem (word_mode, t);
9160 : 6907 : insn = emit_insn (gen_push (t));
9161 : 6907 : RTX_FRAME_RELATED_P (insn) = 1;
9162 : :
9163 : : /* For the purposes of frame and register save area addressing,
9164 : : we've started over with a new frame. */
9165 : 6907 : m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
9166 : 6907 : m->fs.realigned = true;
9167 : :
9168 : 6907 : if (static_chain)
9169 : : {
9170 : : /* Replicate static chain on the stack so that static chain
9171 : : can be reached via (argp - 2) slot. This is needed for
9172 : : nested function with stack realignment. */
9173 : 0 : insn = emit_insn (gen_push (static_chain));
9174 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9175 : : }
9176 : : }
9177 : :
9178 : 1440824 : int_registers_saved = (frame.nregs == 0);
9179 : 1440824 : sse_registers_saved = (frame.nsseregs == 0);
9180 : 1440824 : save_stub_call_needed = (m->call_ms2sysv);
9181 : 1440824 : gcc_assert (sse_registers_saved || !save_stub_call_needed);
9182 : :
9183 : 1440824 : if (frame_pointer_needed && !m->fs.fp_valid)
9184 : : {
9185 : : /* Note: AT&T enter does NOT have reversed args. Enter is probably
9186 : : slower on all targets. Also sdb didn't like it. */
9187 : 465126 : insn = emit_insn (gen_push (hard_frame_pointer_rtx));
9188 : 465126 : RTX_FRAME_RELATED_P (insn) = 1;
9189 : :
9190 : 465126 : if (m->fs.sp_offset == frame.hard_frame_pointer_offset)
9191 : : {
9192 : 465126 : insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
9193 : 465126 : RTX_FRAME_RELATED_P (insn) = 1;
9194 : :
9195 : 465126 : if (m->fs.cfa_reg == stack_pointer_rtx)
9196 : 458219 : m->fs.cfa_reg = hard_frame_pointer_rtx;
9197 : 465126 : m->fs.fp_offset = m->fs.sp_offset;
9198 : 465126 : m->fs.fp_valid = true;
9199 : : }
9200 : : }
9201 : :
9202 : 1440824 : if (!int_registers_saved)
9203 : : {
9204 : : /* If saving registers via PUSH, do so now. */
9205 : 423544 : if (!frame.save_regs_using_mov)
9206 : : {
9207 : 423491 : ix86_emit_save_regs ();
9208 : 423491 : m->fs.apx_ppx_used = TARGET_APX_PPX && !crtl->calls_eh_return;
9209 : 423491 : int_registers_saved = true;
9210 : 423491 : gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
9211 : : }
9212 : :
9213 : : /* When using red zone we may start register saving before allocating
9214 : : the stack frame saving one cycle of the prologue. However, avoid
9215 : : doing this if we have to probe the stack; at least on x86_64 the
9216 : : stack probe can turn into a call that clobbers a red zone location. */
9217 : 53 : else if (ix86_using_red_zone ()
9218 : 53 : && (! TARGET_STACK_PROBE
9219 : 0 : || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
9220 : : {
9221 : 52 : ix86_emit_save_regs_using_mov (frame.reg_save_offset);
9222 : 52 : cfun->machine->red_zone_used = true;
9223 : 52 : int_registers_saved = true;
9224 : : }
9225 : : }
9226 : :
9227 : 1440824 : if (frame.red_zone_size != 0)
9228 : 136974 : cfun->machine->red_zone_used = true;
9229 : :
9230 : 1440824 : if (stack_realign_fp)
9231 : : {
9232 : 24330 : int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
9233 : 24680 : gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
9234 : :
9235 : : /* Record last valid frame pointer offset. */
9236 : 24330 : m->fs.sp_realigned_fp_last = frame.reg_save_offset;
9237 : :
9238 : : /* The computation of the size of the re-aligned stack frame means
9239 : : that we must allocate the size of the register save area before
9240 : : performing the actual alignment. Otherwise we cannot guarantee
9241 : : that there's enough storage above the realignment point. */
9242 : 24330 : allocate = frame.reg_save_offset - m->fs.sp_offset
9243 : 24330 : + frame.stack_realign_allocate;
9244 : 24330 : if (allocate)
9245 : 2691 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9246 : : GEN_INT (-allocate), -1, false);
9247 : :
9248 : : /* Align the stack. */
9249 : 24330 : emit_insn (gen_and2_insn (stack_pointer_rtx, GEN_INT (-align_bytes)));
9250 : 24330 : m->fs.sp_offset = ROUND_UP (m->fs.sp_offset, align_bytes);
9251 : 24330 : m->fs.sp_realigned_offset = m->fs.sp_offset
9252 : 24330 : - frame.stack_realign_allocate;
9253 : : /* The stack pointer may no longer be equal to CFA - m->fs.sp_offset.
9254 : : Beyond this point, stack access should be done via choose_baseaddr or
9255 : : by using sp_valid_at and fp_valid_at to determine the correct base
9256 : : register. Henceforth, any CFA offset should be thought of as logical
9257 : : and not physical. */
9258 : 24330 : gcc_assert (m->fs.sp_realigned_offset >= m->fs.sp_realigned_fp_last);
9259 : 24330 : gcc_assert (m->fs.sp_realigned_offset == frame.stack_realign_offset);
9260 : 24330 : m->fs.sp_realigned = true;
9261 : :
9262 : : /* SEH unwind emit doesn't currently support REG_CFA_EXPRESSION, which
9263 : : is needed to describe where a register is saved using a realigned
9264 : : stack pointer, so we need to invalidate the stack pointer for that
9265 : : target. */
9266 : 24330 : if (TARGET_SEH)
9267 : : m->fs.sp_valid = false;
9268 : :
9269 : : /* If SP offset is non-immediate after allocation of the stack frame,
9270 : : then emit SSE saves or stub call prior to allocating the rest of the
9271 : : stack frame. This is less efficient for the out-of-line stub because
9272 : : we can't combine allocations across the call barrier, but it's better
9273 : : than using a scratch register. */
9274 : 24330 : else if (!x86_64_immediate_operand (GEN_INT (frame.stack_pointer_offset
9275 : : - m->fs.sp_realigned_offset),
9276 : 24330 : Pmode))
9277 : : {
9278 : 3 : if (!sse_registers_saved)
9279 : : {
9280 : 1 : ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
9281 : 1 : sse_registers_saved = true;
9282 : : }
9283 : 2 : else if (save_stub_call_needed)
9284 : : {
9285 : 1 : ix86_emit_outlined_ms2sysv_save (frame);
9286 : 1 : save_stub_call_needed = false;
9287 : : }
9288 : : }
9289 : : }
9290 : :
9291 : 1440824 : allocate = frame.stack_pointer_offset - m->fs.sp_offset;
9292 : :
9293 : 1440824 : if (flag_stack_usage_info)
9294 : : {
9295 : : /* We start to count from ARG_POINTER. */
9296 : 355 : HOST_WIDE_INT stack_size = frame.stack_pointer_offset;
9297 : :
9298 : : /* If it was realigned, take into account the fake frame. */
9299 : 355 : if (stack_realign_drap)
9300 : : {
9301 : 1 : if (ix86_static_chain_on_stack)
9302 : 0 : stack_size += UNITS_PER_WORD;
9303 : :
9304 : 1 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
9305 : 0 : stack_size += UNITS_PER_WORD;
9306 : :
9307 : : /* This over-estimates by 1 minimal-stack-alignment-unit but
9308 : : mitigates that by counting in the new return address slot. */
9309 : 1 : current_function_dynamic_stack_size
9310 : 1 : += crtl->stack_alignment_needed / BITS_PER_UNIT;
9311 : : }
9312 : :
9313 : 355 : current_function_static_stack_size = stack_size;
9314 : : }
9315 : :
9316 : : /* On SEH target with very large frame size, allocate an area to save
9317 : : SSE registers (as the very large allocation won't be described). */
9318 : 1440824 : if (TARGET_SEH
9319 : : && frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE
9320 : : && !sse_registers_saved)
9321 : : {
9322 : : HOST_WIDE_INT sse_size
9323 : : = frame.sse_reg_save_offset - frame.reg_save_offset;
9324 : :
9325 : : gcc_assert (int_registers_saved);
9326 : :
9327 : : /* No need to do stack checking as the area will be immediately
9328 : : written. */
9329 : : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9330 : : GEN_INT (-sse_size), -1,
9331 : : m->fs.cfa_reg == stack_pointer_rtx);
9332 : : allocate -= sse_size;
9333 : : ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
9334 : : sse_registers_saved = true;
9335 : : }
9336 : :
9337 : : /* If stack clash protection is requested, then probe the stack, unless it
9338 : : is already probed on the target. */
9339 : 1440824 : if (allocate >= 0
9340 : 1440820 : && flag_stack_clash_protection
9341 : 1440920 : && !ix86_target_stack_probe ())
9342 : : {
9343 : 96 : ix86_adjust_stack_and_probe (allocate, int_registers_saved, false);
9344 : 96 : allocate = 0;
9345 : : }
9346 : :
9347 : : /* The stack has already been decremented by the instruction calling us
9348 : : so probe if the size is non-negative to preserve the protection area. */
9349 : 1440728 : else if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
9350 : : {
9351 : 46 : const HOST_WIDE_INT probe_interval = get_probe_interval ();
9352 : :
9353 : 46 : if (STACK_CHECK_MOVING_SP)
9354 : : {
9355 : 46 : if (crtl->is_leaf
9356 : 18 : && !cfun->calls_alloca
9357 : 18 : && allocate <= probe_interval)
9358 : : ;
9359 : :
9360 : : else
9361 : : {
9362 : 29 : ix86_adjust_stack_and_probe (allocate, int_registers_saved, true);
9363 : 29 : allocate = 0;
9364 : : }
9365 : : }
9366 : :
9367 : : else
9368 : : {
9369 : : HOST_WIDE_INT size = allocate;
9370 : :
9371 : : if (TARGET_64BIT && size >= HOST_WIDE_INT_C (0x80000000))
9372 : : size = 0x80000000 - get_stack_check_protect () - 1;
9373 : :
9374 : : if (TARGET_STACK_PROBE)
9375 : : {
9376 : : if (crtl->is_leaf && !cfun->calls_alloca)
9377 : : {
9378 : : if (size > probe_interval)
9379 : : ix86_emit_probe_stack_range (0, size, int_registers_saved);
9380 : : }
9381 : : else
9382 : : ix86_emit_probe_stack_range (0,
9383 : : size + get_stack_check_protect (),
9384 : : int_registers_saved);
9385 : : }
9386 : : else
9387 : : {
9388 : : if (crtl->is_leaf && !cfun->calls_alloca)
9389 : : {
9390 : : if (size > probe_interval
9391 : : && size > get_stack_check_protect ())
9392 : : ix86_emit_probe_stack_range (get_stack_check_protect (),
9393 : : (size
9394 : : - get_stack_check_protect ()),
9395 : : int_registers_saved);
9396 : : }
9397 : : else
9398 : : ix86_emit_probe_stack_range (get_stack_check_protect (), size,
9399 : : int_registers_saved);
9400 : : }
9401 : : }
9402 : : }
9403 : :
9404 : 1440820 : if (allocate == 0)
9405 : : ;
9406 : 822693 : else if (!ix86_target_stack_probe ()
9407 : 822693 : || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
9408 : : {
9409 : 822649 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9410 : : GEN_INT (-allocate), -1,
9411 : 822649 : m->fs.cfa_reg == stack_pointer_rtx);
9412 : : }
9413 : : else
9414 : : {
9415 : 44 : rtx eax = gen_rtx_REG (Pmode, AX_REG);
9416 : 44 : rtx r10 = NULL;
9417 : 44 : const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx);
9418 : 44 : bool eax_live = ix86_eax_live_at_start_p ();
9419 : 44 : bool r10_live = false;
9420 : :
9421 : 44 : if (TARGET_64BIT)
9422 : 44 : r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0);
9423 : :
9424 : 44 : if (eax_live)
9425 : : {
9426 : 0 : insn = emit_insn (gen_push (eax));
9427 : 0 : allocate -= UNITS_PER_WORD;
9428 : : /* Note that SEH directives need to continue tracking the stack
9429 : : pointer even after the frame pointer has been set up. */
9430 : 0 : if (sp_is_cfa_reg || TARGET_SEH)
9431 : : {
9432 : 0 : if (sp_is_cfa_reg)
9433 : 0 : m->fs.cfa_offset += UNITS_PER_WORD;
9434 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9435 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9436 : 0 : gen_rtx_SET (stack_pointer_rtx,
9437 : : plus_constant (Pmode,
9438 : : stack_pointer_rtx,
9439 : : -UNITS_PER_WORD)));
9440 : : }
9441 : : }
9442 : :
9443 : 44 : if (r10_live)
9444 : : {
9445 : 0 : r10 = gen_rtx_REG (Pmode, R10_REG);
9446 : 0 : insn = emit_insn (gen_push (r10));
9447 : 0 : allocate -= UNITS_PER_WORD;
9448 : 0 : if (sp_is_cfa_reg || TARGET_SEH)
9449 : : {
9450 : 0 : if (sp_is_cfa_reg)
9451 : 0 : m->fs.cfa_offset += UNITS_PER_WORD;
9452 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9453 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9454 : 0 : gen_rtx_SET (stack_pointer_rtx,
9455 : : plus_constant (Pmode,
9456 : : stack_pointer_rtx,
9457 : : -UNITS_PER_WORD)));
9458 : : }
9459 : : }
9460 : :
9461 : 44 : emit_move_insn (eax, GEN_INT (allocate));
9462 : 44 : emit_insn (gen_allocate_stack_worker_probe (Pmode, eax, eax));
9463 : :
9464 : : /* Use the fact that AX still contains ALLOCATE. */
9465 : 44 : insn = emit_insn (gen_pro_epilogue_adjust_stack_sub
9466 : 44 : (Pmode, stack_pointer_rtx, stack_pointer_rtx, eax));
9467 : :
9468 : 44 : if (sp_is_cfa_reg || TARGET_SEH)
9469 : : {
9470 : 36 : if (sp_is_cfa_reg)
9471 : 36 : m->fs.cfa_offset += allocate;
9472 : 36 : RTX_FRAME_RELATED_P (insn) = 1;
9473 : 36 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9474 : 36 : gen_rtx_SET (stack_pointer_rtx,
9475 : : plus_constant (Pmode, stack_pointer_rtx,
9476 : : -allocate)));
9477 : : }
9478 : 44 : m->fs.sp_offset += allocate;
9479 : :
9480 : : /* Use stack_pointer_rtx for relative addressing so that code works for
9481 : : realigned stack. But this means that we need a blockage to prevent
9482 : : stores based on the frame pointer from being scheduled before. */
9483 : 44 : if (r10_live && eax_live)
9484 : : {
9485 : 0 : t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
9486 : 0 : emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
9487 : : gen_frame_mem (word_mode, t));
9488 : 0 : t = plus_constant (Pmode, t, UNITS_PER_WORD);
9489 : 0 : emit_move_insn (gen_rtx_REG (word_mode, AX_REG),
9490 : : gen_frame_mem (word_mode, t));
9491 : 0 : emit_insn (gen_memory_blockage ());
9492 : : }
9493 : 44 : else if (eax_live || r10_live)
9494 : : {
9495 : 0 : t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
9496 : 0 : emit_move_insn (gen_rtx_REG (word_mode,
9497 : : (eax_live ? AX_REG : R10_REG)),
9498 : : gen_frame_mem (word_mode, t));
9499 : 0 : emit_insn (gen_memory_blockage ());
9500 : : }
9501 : : }
9502 : 1440824 : gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset);
9503 : :
9504 : : /* If we havn't already set up the frame pointer, do so now. */
9505 : 1440824 : if (frame_pointer_needed && !m->fs.fp_valid)
9506 : : {
9507 : 0 : insn = gen_add3_insn (hard_frame_pointer_rtx, stack_pointer_rtx,
9508 : 0 : GEN_INT (frame.stack_pointer_offset
9509 : : - frame.hard_frame_pointer_offset));
9510 : 0 : insn = emit_insn (insn);
9511 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9512 : 0 : add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL);
9513 : :
9514 : 0 : if (m->fs.cfa_reg == stack_pointer_rtx)
9515 : 0 : m->fs.cfa_reg = hard_frame_pointer_rtx;
9516 : 0 : m->fs.fp_offset = frame.hard_frame_pointer_offset;
9517 : 0 : m->fs.fp_valid = true;
9518 : : }
9519 : :
9520 : 1440824 : if (!int_registers_saved)
9521 : 1 : ix86_emit_save_regs_using_mov (frame.reg_save_offset);
9522 : 1440824 : if (!sse_registers_saved)
9523 : 33152 : ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
9524 : 1407672 : else if (save_stub_call_needed)
9525 : 7044 : ix86_emit_outlined_ms2sysv_save (frame);
9526 : :
9527 : : /* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT
9528 : : in PROLOGUE. */
9529 : 1440824 : if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry)
9530 : : {
9531 : 0 : rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM);
9532 : 0 : insn = emit_insn (gen_set_got (pic));
9533 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9534 : 0 : add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
9535 : 0 : emit_insn (gen_prologue_use (pic));
9536 : : /* Deleting already emmitted SET_GOT if exist and allocated to
9537 : : REAL_PIC_OFFSET_TABLE_REGNUM. */
9538 : 0 : ix86_elim_entry_set_got (pic);
9539 : : }
9540 : :
9541 : 1440824 : if (crtl->drap_reg && !crtl->stack_realign_needed)
9542 : : {
9543 : : /* vDRAP is setup but after reload it turns out stack realign
9544 : : isn't necessary, here we will emit prologue to setup DRAP
9545 : : without stack realign adjustment */
9546 : 177 : t = choose_baseaddr (0, NULL);
9547 : 177 : emit_insn (gen_rtx_SET (crtl->drap_reg, t));
9548 : : }
9549 : :
9550 : : /* Prevent instructions from being scheduled into register save push
9551 : : sequence when access to the redzone area is done through frame pointer.
9552 : : The offset between the frame pointer and the stack pointer is calculated
9553 : : relative to the value of the stack pointer at the end of the function
9554 : : prologue, and moving instructions that access redzone area via frame
9555 : : pointer inside push sequence violates this assumption. */
9556 : 1440824 : if (frame_pointer_needed && frame.red_zone_size)
9557 : 126455 : emit_insn (gen_memory_blockage ());
9558 : :
9559 : : /* SEH requires that the prologue end within 256 bytes of the start of
9560 : : the function. Prevent instruction schedules that would extend that.
9561 : : Further, prevent alloca modifications to the stack pointer from being
9562 : : combined with prologue modifications. */
9563 : : if (TARGET_SEH)
9564 : : emit_insn (gen_prologue_use (stack_pointer_rtx));
9565 : : }
9566 : :
9567 : : /* Emit code to restore REG using a POP or POPP insn. */
9568 : :
9569 : : static void
9570 : 1487681 : ix86_emit_restore_reg_using_pop (rtx reg, bool ppx_p)
9571 : : {
9572 : 1487681 : struct machine_function *m = cfun->machine;
9573 : 1487681 : rtx_insn *insn = emit_insn (gen_pop (reg, ppx_p));
9574 : :
9575 : 1487681 : ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset);
9576 : 1487681 : m->fs.sp_offset -= UNITS_PER_WORD;
9577 : :
9578 : 1487681 : if (m->fs.cfa_reg == crtl->drap_reg
9579 : 1487681 : && REGNO (reg) == REGNO (crtl->drap_reg))
9580 : : {
9581 : : /* Previously we'd represented the CFA as an expression
9582 : : like *(%ebp - 8). We've just popped that value from
9583 : : the stack, which means we need to reset the CFA to
9584 : : the drap register. This will remain until we restore
9585 : : the stack pointer. */
9586 : 3985 : add_reg_note (insn, REG_CFA_DEF_CFA, reg);
9587 : 3985 : RTX_FRAME_RELATED_P (insn) = 1;
9588 : :
9589 : : /* This means that the DRAP register is valid for addressing too. */
9590 : 3985 : m->fs.drap_valid = true;
9591 : 3985 : return;
9592 : : }
9593 : :
9594 : 1483696 : if (m->fs.cfa_reg == stack_pointer_rtx)
9595 : : {
9596 : 1240858 : rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
9597 : 1049247 : x = gen_rtx_SET (stack_pointer_rtx, x);
9598 : 1049247 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
9599 : 1049247 : RTX_FRAME_RELATED_P (insn) = 1;
9600 : :
9601 : 1240858 : m->fs.cfa_offset -= UNITS_PER_WORD;
9602 : : }
9603 : :
9604 : : /* When the frame pointer is the CFA, and we pop it, we are
9605 : : swapping back to the stack pointer as the CFA. This happens
9606 : : for stack frames that don't allocate other data, so we assume
9607 : : the stack pointer is now pointing at the return address, i.e.
9608 : : the function entry state, which makes the offset be 1 word. */
9609 : 1483696 : if (reg == hard_frame_pointer_rtx)
9610 : : {
9611 : 230201 : m->fs.fp_valid = false;
9612 : 230201 : if (m->fs.cfa_reg == hard_frame_pointer_rtx)
9613 : : {
9614 : 226203 : m->fs.cfa_reg = stack_pointer_rtx;
9615 : 226203 : m->fs.cfa_offset -= UNITS_PER_WORD;
9616 : :
9617 : 226203 : add_reg_note (insn, REG_CFA_DEF_CFA,
9618 : 226203 : plus_constant (Pmode, stack_pointer_rtx,
9619 : 226203 : m->fs.cfa_offset));
9620 : 226203 : RTX_FRAME_RELATED_P (insn) = 1;
9621 : : }
9622 : : }
9623 : : }
9624 : :
9625 : : /* Emit code to restore REG using a POP2 insn. */
9626 : : static void
9627 : 17 : ix86_emit_restore_reg_using_pop2 (rtx reg1, rtx reg2, bool ppx_p = false)
9628 : : {
9629 : 17 : struct machine_function *m = cfun->machine;
9630 : 17 : const int offset = UNITS_PER_WORD * 2;
9631 : 17 : rtx_insn *insn;
9632 : :
9633 : 17 : rtx mem = gen_rtx_MEM (TImode, gen_rtx_POST_INC (Pmode,
9634 : : stack_pointer_rtx));
9635 : :
9636 : 17 : if (ppx_p)
9637 : 13 : insn = emit_insn (gen_pop2p_di (reg1, mem, reg2));
9638 : : else
9639 : 4 : insn = emit_insn (gen_pop2_di (reg1, mem, reg2));
9640 : :
9641 : 17 : RTX_FRAME_RELATED_P (insn) = 1;
9642 : :
9643 : 17 : rtx dwarf = NULL_RTX;
9644 : 17 : dwarf = alloc_reg_note (REG_CFA_RESTORE, reg1, dwarf);
9645 : 17 : dwarf = alloc_reg_note (REG_CFA_RESTORE, reg2, dwarf);
9646 : 17 : REG_NOTES (insn) = dwarf;
9647 : 17 : m->fs.sp_offset -= offset;
9648 : :
9649 : 17 : if (m->fs.cfa_reg == crtl->drap_reg
9650 : 17 : && (REGNO (reg1) == REGNO (crtl->drap_reg)
9651 : 3 : || REGNO (reg2) == REGNO (crtl->drap_reg)))
9652 : : {
9653 : : /* Previously we'd represented the CFA as an expression
9654 : : like *(%ebp - 8). We've just popped that value from
9655 : : the stack, which means we need to reset the CFA to
9656 : : the drap register. This will remain until we restore
9657 : : the stack pointer. */
9658 : 1 : add_reg_note (insn, REG_CFA_DEF_CFA,
9659 : 1 : REGNO (reg1) == REGNO (crtl->drap_reg) ? reg1 : reg2);
9660 : 1 : RTX_FRAME_RELATED_P (insn) = 1;
9661 : :
9662 : : /* This means that the DRAP register is valid for addressing too. */
9663 : 1 : m->fs.drap_valid = true;
9664 : 1 : return;
9665 : : }
9666 : :
9667 : 16 : if (m->fs.cfa_reg == stack_pointer_rtx)
9668 : : {
9669 : 12 : rtx x = plus_constant (Pmode, stack_pointer_rtx, offset);
9670 : 12 : x = gen_rtx_SET (stack_pointer_rtx, x);
9671 : 12 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
9672 : 12 : RTX_FRAME_RELATED_P (insn) = 1;
9673 : :
9674 : 12 : m->fs.cfa_offset -= offset;
9675 : : }
9676 : :
9677 : : /* When the frame pointer is the CFA, and we pop it, we are
9678 : : swapping back to the stack pointer as the CFA. This happens
9679 : : for stack frames that don't allocate other data, so we assume
9680 : : the stack pointer is now pointing at the return address, i.e.
9681 : : the function entry state, which makes the offset be 1 word. */
9682 : 16 : if (reg1 == hard_frame_pointer_rtx || reg2 == hard_frame_pointer_rtx)
9683 : : {
9684 : 0 : m->fs.fp_valid = false;
9685 : 0 : if (m->fs.cfa_reg == hard_frame_pointer_rtx)
9686 : : {
9687 : 0 : m->fs.cfa_reg = stack_pointer_rtx;
9688 : 0 : m->fs.cfa_offset -= offset;
9689 : :
9690 : 0 : add_reg_note (insn, REG_CFA_DEF_CFA,
9691 : 0 : plus_constant (Pmode, stack_pointer_rtx,
9692 : 0 : m->fs.cfa_offset));
9693 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9694 : : }
9695 : : }
9696 : : }
9697 : :
9698 : : /* Emit code to restore saved registers using POP insns. */
9699 : :
9700 : : static void
9701 : 1321596 : ix86_emit_restore_regs_using_pop (bool ppx_p)
9702 : : {
9703 : 1321596 : unsigned int regno;
9704 : :
9705 : 122908428 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9706 : 121586832 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true))
9707 : 1257247 : ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno), ppx_p);
9708 : 1321596 : }
9709 : :
9710 : : /* Emit code to restore saved registers using POP2 insns. */
9711 : :
9712 : : static void
9713 : 444 : ix86_emit_restore_regs_using_pop2 (void)
9714 : : {
9715 : 444 : int regno;
9716 : 444 : int regno_list[2];
9717 : 444 : regno_list[0] = regno_list[1] = -1;
9718 : 444 : int loaded_regnum = 0;
9719 : 444 : bool aligned = cfun->machine->fs.sp_offset % 16 == 0;
9720 : :
9721 : 41292 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9722 : 40848 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true))
9723 : : {
9724 : 49 : if (aligned)
9725 : : {
9726 : 40 : regno_list[loaded_regnum++] = regno;
9727 : 40 : if (loaded_regnum == 2)
9728 : : {
9729 : 17 : gcc_assert (regno_list[0] != -1
9730 : : && regno_list[1] != -1
9731 : : && regno_list[0] != regno_list[1]);
9732 : :
9733 : 17 : ix86_emit_restore_reg_using_pop2 (gen_rtx_REG (word_mode,
9734 : : regno_list[0]),
9735 : : gen_rtx_REG (word_mode,
9736 : : regno_list[1]),
9737 : 17 : TARGET_APX_PPX);
9738 : 17 : loaded_regnum = 0;
9739 : 17 : regno_list[0] = regno_list[1] = -1;
9740 : : }
9741 : : }
9742 : : else
9743 : : {
9744 : 18 : ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno),
9745 : 9 : TARGET_APX_PPX);
9746 : 9 : aligned = true;
9747 : : }
9748 : : }
9749 : :
9750 : 444 : if (loaded_regnum == 1)
9751 : 6 : ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno_list[0]),
9752 : 6 : TARGET_APX_PPX);
9753 : 444 : }
9754 : :
9755 : : /* Emit code and notes for the LEAVE instruction. If insn is non-null,
9756 : : omits the emit and only attaches the notes. */
9757 : :
9758 : : static void
9759 : 236168 : ix86_emit_leave (rtx_insn *insn)
9760 : : {
9761 : 236168 : struct machine_function *m = cfun->machine;
9762 : :
9763 : 236168 : if (!insn)
9764 : 235197 : insn = emit_insn (gen_leave (word_mode));
9765 : :
9766 : 236168 : ix86_add_queued_cfa_restore_notes (insn);
9767 : :
9768 : 236168 : gcc_assert (m->fs.fp_valid);
9769 : 236168 : m->fs.sp_valid = true;
9770 : 236168 : m->fs.sp_realigned = false;
9771 : 236168 : m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD;
9772 : 236168 : m->fs.fp_valid = false;
9773 : :
9774 : 236168 : if (m->fs.cfa_reg == hard_frame_pointer_rtx)
9775 : : {
9776 : 233159 : m->fs.cfa_reg = stack_pointer_rtx;
9777 : 233159 : m->fs.cfa_offset = m->fs.sp_offset;
9778 : :
9779 : 233159 : add_reg_note (insn, REG_CFA_DEF_CFA,
9780 : 233159 : plus_constant (Pmode, stack_pointer_rtx,
9781 : 233159 : m->fs.sp_offset));
9782 : 233159 : RTX_FRAME_RELATED_P (insn) = 1;
9783 : : }
9784 : 236168 : ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx,
9785 : : m->fs.fp_offset);
9786 : 236168 : }
9787 : :
9788 : : /* Emit code to restore saved registers using MOV insns.
9789 : : First register is restored from CFA - CFA_OFFSET. */
9790 : : static void
9791 : 41481 : ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
9792 : : bool maybe_eh_return)
9793 : : {
9794 : 41481 : struct machine_function *m = cfun->machine;
9795 : 41481 : unsigned int regno;
9796 : :
9797 : 3857733 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9798 : 3816252 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
9799 : : {
9800 : 41724 : rtx reg = gen_rtx_REG (word_mode, regno);
9801 : 41724 : rtx mem;
9802 : 41724 : rtx_insn *insn;
9803 : :
9804 : 41724 : mem = choose_baseaddr (cfa_offset, NULL);
9805 : 41724 : mem = gen_frame_mem (word_mode, mem);
9806 : 41724 : insn = emit_move_insn (reg, mem);
9807 : :
9808 : 41724 : if (m->fs.cfa_reg == crtl->drap_reg && regno == REGNO (crtl->drap_reg))
9809 : : {
9810 : : /* Previously we'd represented the CFA as an expression
9811 : : like *(%ebp - 8). We've just popped that value from
9812 : : the stack, which means we need to reset the CFA to
9813 : : the drap register. This will remain until we restore
9814 : : the stack pointer. */
9815 : 3009 : add_reg_note (insn, REG_CFA_DEF_CFA, reg);
9816 : 3009 : RTX_FRAME_RELATED_P (insn) = 1;
9817 : :
9818 : : /* This means that the DRAP register is valid for addressing. */
9819 : 3009 : m->fs.drap_valid = true;
9820 : : }
9821 : : else
9822 : 38715 : ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
9823 : :
9824 : 43579 : cfa_offset -= UNITS_PER_WORD;
9825 : : }
9826 : 41481 : }
9827 : :
9828 : : /* Emit code to restore saved registers using MOV insns.
9829 : : First register is restored from CFA - CFA_OFFSET. */
9830 : : static void
9831 : 33729 : ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
9832 : : bool maybe_eh_return)
9833 : : {
9834 : 33729 : unsigned int regno;
9835 : :
9836 : 3136797 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9837 : 3103068 : if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
9838 : : {
9839 : 337281 : rtx reg = gen_rtx_REG (V4SFmode, regno);
9840 : 337281 : rtx mem;
9841 : 337281 : unsigned int align = GET_MODE_ALIGNMENT (V4SFmode);
9842 : :
9843 : 337281 : mem = choose_baseaddr (cfa_offset, &align);
9844 : 337281 : mem = gen_rtx_MEM (V4SFmode, mem);
9845 : :
9846 : : /* The location aligment depends upon the base register. */
9847 : 337281 : align = MIN (GET_MODE_ALIGNMENT (V4SFmode), align);
9848 : 337281 : gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1)));
9849 : 337281 : set_mem_align (mem, align);
9850 : 337281 : emit_insn (gen_rtx_SET (reg, mem));
9851 : :
9852 : 337281 : ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
9853 : :
9854 : 337281 : cfa_offset -= GET_MODE_SIZE (V4SFmode);
9855 : : }
9856 : 33729 : }
9857 : :
9858 : : static void
9859 : 7621 : ix86_emit_outlined_ms2sysv_restore (const struct ix86_frame &frame,
9860 : : bool use_call, int style)
9861 : : {
9862 : 7621 : struct machine_function *m = cfun->machine;
9863 : 7621 : const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS
9864 : 7621 : + m->call_ms2sysv_extra_regs;
9865 : 7621 : rtvec v;
9866 : 7621 : unsigned int elems_needed, align, i, vi = 0;
9867 : 7621 : rtx_insn *insn;
9868 : 7621 : rtx sym, tmp;
9869 : 7621 : rtx rsi = gen_rtx_REG (word_mode, SI_REG);
9870 : 7621 : rtx r10 = NULL_RTX;
9871 : 7621 : const class xlogue_layout &xlogue = xlogue_layout::get_instance ();
9872 : 7621 : HOST_WIDE_INT stub_ptr_offset = xlogue.get_stub_ptr_offset ();
9873 : 7621 : HOST_WIDE_INT rsi_offset = frame.stack_realign_offset + stub_ptr_offset;
9874 : 7621 : rtx rsi_frame_load = NULL_RTX;
9875 : 7621 : HOST_WIDE_INT rsi_restore_offset = (HOST_WIDE_INT)-1;
9876 : 7621 : enum xlogue_stub stub;
9877 : :
9878 : 7621 : gcc_assert (!m->fs.fp_valid || frame_pointer_needed);
9879 : :
9880 : : /* If using a realigned stack, we should never start with padding. */
9881 : 7621 : gcc_assert (!stack_realign_fp || !xlogue.get_stack_align_off_in ());
9882 : :
9883 : : /* Setup RSI as the stub's base pointer. */
9884 : 7621 : align = GET_MODE_ALIGNMENT (V4SFmode);
9885 : 7621 : tmp = choose_baseaddr (rsi_offset, &align, SI_REG);
9886 : 7621 : gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode));
9887 : :
9888 : 7621 : emit_insn (gen_rtx_SET (rsi, tmp));
9889 : :
9890 : : /* Get a symbol for the stub. */
9891 : 7621 : if (frame_pointer_needed)
9892 : 5955 : stub = use_call ? XLOGUE_STUB_RESTORE_HFP
9893 : : : XLOGUE_STUB_RESTORE_HFP_TAIL;
9894 : : else
9895 : 1666 : stub = use_call ? XLOGUE_STUB_RESTORE
9896 : : : XLOGUE_STUB_RESTORE_TAIL;
9897 : 7621 : sym = xlogue.get_stub_rtx (stub);
9898 : :
9899 : 7621 : elems_needed = ncregs;
9900 : 7621 : if (use_call)
9901 : 6498 : elems_needed += 1;
9902 : : else
9903 : 1275 : elems_needed += frame_pointer_needed ? 5 : 3;
9904 : 7621 : v = rtvec_alloc (elems_needed);
9905 : :
9906 : : /* We call the epilogue stub when we need to pop incoming args or we are
9907 : : doing a sibling call as the tail. Otherwise, we will emit a jmp to the
9908 : : epilogue stub and it is the tail-call. */
9909 : 7621 : if (use_call)
9910 : 6498 : RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
9911 : : else
9912 : : {
9913 : 1123 : RTVEC_ELT (v, vi++) = ret_rtx;
9914 : 1123 : RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
9915 : 1123 : if (frame_pointer_needed)
9916 : : {
9917 : 971 : rtx rbp = gen_rtx_REG (DImode, BP_REG);
9918 : 971 : gcc_assert (m->fs.fp_valid);
9919 : 971 : gcc_assert (m->fs.cfa_reg == hard_frame_pointer_rtx);
9920 : :
9921 : 971 : tmp = plus_constant (DImode, rbp, 8);
9922 : 971 : RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, tmp);
9923 : 971 : RTVEC_ELT (v, vi++) = gen_rtx_SET (rbp, gen_rtx_MEM (DImode, rbp));
9924 : 971 : tmp = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
9925 : 971 : RTVEC_ELT (v, vi++) = gen_rtx_CLOBBER (VOIDmode, tmp);
9926 : : }
9927 : : else
9928 : : {
9929 : : /* If no hard frame pointer, we set R10 to the SP restore value. */
9930 : 152 : gcc_assert (!m->fs.fp_valid);
9931 : 152 : gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
9932 : 152 : gcc_assert (m->fs.sp_valid);
9933 : :
9934 : 152 : r10 = gen_rtx_REG (DImode, R10_REG);
9935 : 152 : tmp = plus_constant (Pmode, rsi, stub_ptr_offset);
9936 : 152 : emit_insn (gen_rtx_SET (r10, tmp));
9937 : :
9938 : 152 : RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, r10);
9939 : : }
9940 : : }
9941 : :
9942 : : /* Generate frame load insns and restore notes. */
9943 : 107954 : for (i = 0; i < ncregs; ++i)
9944 : : {
9945 : 100333 : const xlogue_layout::reginfo &r = xlogue.get_reginfo (i);
9946 : 100333 : machine_mode mode = SSE_REGNO_P (r.regno) ? V4SFmode : word_mode;
9947 : 100333 : rtx reg, frame_load;
9948 : :
9949 : 100333 : reg = gen_rtx_REG (mode, r.regno);
9950 : 100333 : frame_load = gen_frame_load (reg, rsi, r.offset);
9951 : :
9952 : : /* Save RSI frame load insn & note to add last. */
9953 : 100333 : if (r.regno == SI_REG)
9954 : : {
9955 : 7621 : gcc_assert (!rsi_frame_load);
9956 : 7621 : rsi_frame_load = frame_load;
9957 : 7621 : rsi_restore_offset = r.offset;
9958 : : }
9959 : : else
9960 : : {
9961 : 92712 : RTVEC_ELT (v, vi++) = frame_load;
9962 : 92712 : ix86_add_cfa_restore_note (NULL, reg, r.offset);
9963 : : }
9964 : : }
9965 : :
9966 : : /* Add RSI frame load & restore note at the end. */
9967 : 7621 : gcc_assert (rsi_frame_load);
9968 : 7621 : gcc_assert (rsi_restore_offset != (HOST_WIDE_INT)-1);
9969 : 7621 : RTVEC_ELT (v, vi++) = rsi_frame_load;
9970 : 7621 : ix86_add_cfa_restore_note (NULL, gen_rtx_REG (DImode, SI_REG),
9971 : : rsi_restore_offset);
9972 : :
9973 : : /* Finally, for tail-call w/o a hard frame pointer, set SP to R10. */
9974 : 7621 : if (!use_call && !frame_pointer_needed)
9975 : : {
9976 : 152 : gcc_assert (m->fs.sp_valid);
9977 : 152 : gcc_assert (!m->fs.sp_realigned);
9978 : :
9979 : : /* At this point, R10 should point to frame.stack_realign_offset. */
9980 : 152 : if (m->fs.cfa_reg == stack_pointer_rtx)
9981 : 152 : m->fs.cfa_offset += m->fs.sp_offset - frame.stack_realign_offset;
9982 : 152 : m->fs.sp_offset = frame.stack_realign_offset;
9983 : : }
9984 : :
9985 : 7621 : gcc_assert (vi == (unsigned int)GET_NUM_ELEM (v));
9986 : 7621 : tmp = gen_rtx_PARALLEL (VOIDmode, v);
9987 : 7621 : if (use_call)
9988 : 6498 : insn = emit_insn (tmp);
9989 : : else
9990 : : {
9991 : 1123 : insn = emit_jump_insn (tmp);
9992 : 1123 : JUMP_LABEL (insn) = ret_rtx;
9993 : :
9994 : 1123 : if (frame_pointer_needed)
9995 : 971 : ix86_emit_leave (insn);
9996 : : else
9997 : : {
9998 : : /* Need CFA adjust note. */
9999 : 152 : tmp = gen_rtx_SET (stack_pointer_rtx, r10);
10000 : 152 : add_reg_note (insn, REG_CFA_ADJUST_CFA, tmp);
10001 : : }
10002 : : }
10003 : :
10004 : 7621 : RTX_FRAME_RELATED_P (insn) = true;
10005 : 7621 : ix86_add_queued_cfa_restore_notes (insn);
10006 : :
10007 : : /* If we're not doing a tail-call, we need to adjust the stack. */
10008 : 7621 : if (use_call && m->fs.sp_valid)
10009 : : {
10010 : 3706 : HOST_WIDE_INT dealloc = m->fs.sp_offset - frame.stack_realign_offset;
10011 : 3706 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10012 : : GEN_INT (dealloc), style,
10013 : 3706 : m->fs.cfa_reg == stack_pointer_rtx);
10014 : : }
10015 : 7621 : }
10016 : :
10017 : : /* Restore function stack, frame, and registers. */
10018 : :
10019 : : void
10020 : 1558585 : ix86_expand_epilogue (int style)
10021 : : {
10022 : 1558585 : struct machine_function *m = cfun->machine;
10023 : 1558585 : struct machine_frame_state frame_state_save = m->fs;
10024 : 1558585 : bool restore_regs_via_mov;
10025 : 1558585 : bool using_drap;
10026 : 1558585 : bool restore_stub_is_tail = false;
10027 : :
10028 : 1558585 : if (ix86_function_naked (current_function_decl))
10029 : : {
10030 : : /* The program should not reach this point. */
10031 : 74 : emit_insn (gen_ud2 ());
10032 : 117806 : return;
10033 : : }
10034 : :
10035 : 1558511 : ix86_finalize_stack_frame_flags ();
10036 : 1558511 : const struct ix86_frame &frame = cfun->machine->frame;
10037 : :
10038 : 1558511 : m->fs.sp_realigned = stack_realign_fp;
10039 : 31375 : m->fs.sp_valid = stack_realign_fp
10040 : 1534131 : || !frame_pointer_needed
10041 : 2000527 : || crtl->sp_is_unchanging;
10042 : 1558511 : gcc_assert (!m->fs.sp_valid
10043 : : || m->fs.sp_offset == frame.stack_pointer_offset);
10044 : :
10045 : : /* The FP must be valid if the frame pointer is present. */
10046 : 1558511 : gcc_assert (frame_pointer_needed == m->fs.fp_valid);
10047 : 1558511 : gcc_assert (!m->fs.fp_valid
10048 : : || m->fs.fp_offset == frame.hard_frame_pointer_offset);
10049 : :
10050 : : /* We must have *some* valid pointer to the stack frame. */
10051 : 1558511 : gcc_assert (m->fs.sp_valid || m->fs.fp_valid);
10052 : :
10053 : : /* The DRAP is never valid at this point. */
10054 : 1558511 : gcc_assert (!m->fs.drap_valid);
10055 : :
10056 : : /* See the comment about red zone and frame
10057 : : pointer usage in ix86_expand_prologue. */
10058 : 1558511 : if (frame_pointer_needed && frame.red_zone_size)
10059 : 126488 : emit_insn (gen_memory_blockage ());
10060 : :
10061 : 1558511 : using_drap = crtl->drap_reg && crtl->stack_realign_needed;
10062 : 6995 : gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg);
10063 : :
10064 : : /* Determine the CFA offset of the end of the red-zone. */
10065 : 1558511 : m->fs.red_zone_offset = 0;
10066 : 1558511 : if (ix86_using_red_zone () && crtl->args.pops_args < 65536)
10067 : : {
10068 : : /* The red-zone begins below return address and error code in
10069 : : exception handler. */
10070 : 1386904 : m->fs.red_zone_offset = RED_ZONE_SIZE + INCOMING_FRAME_SP_OFFSET;
10071 : :
10072 : : /* When the register save area is in the aligned portion of
10073 : : the stack, determine the maximum runtime displacement that
10074 : : matches up with the aligned frame. */
10075 : 1386904 : if (stack_realign_drap)
10076 : 8266 : m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT
10077 : 4133 : + UNITS_PER_WORD);
10078 : : }
10079 : :
10080 : 1558511 : HOST_WIDE_INT reg_save_offset = frame.reg_save_offset;
10081 : :
10082 : : /* Special care must be taken for the normal return case of a function
10083 : : using eh_return: the eax and edx registers are marked as saved, but
10084 : : not restored along this path. Adjust the save location to match. */
10085 : 1558511 : if (crtl->calls_eh_return && style != 2)
10086 : 37 : reg_save_offset -= 2 * UNITS_PER_WORD;
10087 : :
10088 : : /* EH_RETURN requires the use of moves to function properly. */
10089 : 1558511 : if (crtl->calls_eh_return)
10090 : : restore_regs_via_mov = true;
10091 : : /* SEH requires the use of pops to identify the epilogue. */
10092 : 1558453 : else if (TARGET_SEH)
10093 : : restore_regs_via_mov = false;
10094 : : /* If we already save reg with pushp, don't use move at epilogue. */
10095 : 1558453 : else if (m->fs.apx_ppx_used)
10096 : : restore_regs_via_mov = false;
10097 : : /* If we're only restoring one register and sp cannot be used then
10098 : : using a move instruction to restore the register since it's
10099 : : less work than reloading sp and popping the register. */
10100 : 1558443 : else if (!sp_valid_at (frame.hfp_save_offset) && frame.nregs <= 1)
10101 : : restore_regs_via_mov = true;
10102 : 1498672 : else if (TARGET_EPILOGUE_USING_MOVE
10103 : 56579 : && cfun->machine->use_fast_prologue_epilogue
10104 : 56529 : && (frame.nregs > 1
10105 : 56524 : || m->fs.sp_offset != reg_save_offset))
10106 : : restore_regs_via_mov = true;
10107 : 1498454 : else if (frame_pointer_needed
10108 : 406378 : && !frame.nregs
10109 : 314144 : && m->fs.sp_offset != reg_save_offset)
10110 : : restore_regs_via_mov = true;
10111 : 1350178 : else if (frame_pointer_needed
10112 : 258102 : && TARGET_USE_LEAVE
10113 : 258073 : && cfun->machine->use_fast_prologue_epilogue
10114 : 202407 : && frame.nregs == 1)
10115 : : restore_regs_via_mov = true;
10116 : : else
10117 : : restore_regs_via_mov = false;
10118 : :
10119 : 1322192 : if (restore_regs_via_mov || frame.nsseregs)
10120 : : {
10121 : : /* Ensure that the entire register save area is addressable via
10122 : : the stack pointer, if we will restore SSE regs via sp. */
10123 : 270045 : if (TARGET_64BIT
10124 : 262788 : && m->fs.sp_offset > 0x7fffffff
10125 : 26 : && sp_valid_at (frame.stack_realign_offset + 1)
10126 : 270070 : && (frame.nsseregs + frame.nregs) != 0)
10127 : : {
10128 : 6 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10129 : 6 : GEN_INT (m->fs.sp_offset
10130 : : - frame.sse_reg_save_offset),
10131 : : style,
10132 : 6 : m->fs.cfa_reg == stack_pointer_rtx);
10133 : : }
10134 : : }
10135 : :
10136 : : /* If there are any SSE registers to restore, then we have to do it
10137 : : via moves, since there's obviously no pop for SSE regs. */
10138 : 1558511 : if (frame.nsseregs)
10139 : 33729 : ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset,
10140 : : style == 2);
10141 : :
10142 : 1558511 : if (m->call_ms2sysv)
10143 : : {
10144 : 7621 : int pop_incoming_args = crtl->args.pops_args && crtl->args.size;
10145 : :
10146 : : /* We cannot use a tail-call for the stub if:
10147 : : 1. We have to pop incoming args,
10148 : : 2. We have additional int regs to restore, or
10149 : : 3. A sibling call will be the tail-call, or
10150 : : 4. We are emitting an eh_return_internal epilogue.
10151 : :
10152 : : TODO: Item 4 has not yet tested!
10153 : :
10154 : : If any of the above are true, we will call the stub rather than
10155 : : jump to it. */
10156 : 7621 : restore_stub_is_tail = !(pop_incoming_args || frame.nregs || style != 1);
10157 : 7621 : ix86_emit_outlined_ms2sysv_restore (frame, !restore_stub_is_tail, style);
10158 : : }
10159 : :
10160 : : /* If using out-of-line stub that is a tail-call, then...*/
10161 : 1558511 : if (m->call_ms2sysv && restore_stub_is_tail)
10162 : : {
10163 : : /* TODO: parinoid tests. (remove eventually) */
10164 : 1123 : gcc_assert (m->fs.sp_valid);
10165 : 1123 : gcc_assert (!m->fs.sp_realigned);
10166 : 1123 : gcc_assert (!m->fs.fp_valid);
10167 : 1123 : gcc_assert (!m->fs.realigned);
10168 : 1123 : gcc_assert (m->fs.sp_offset == UNITS_PER_WORD);
10169 : 1123 : gcc_assert (!crtl->drap_reg);
10170 : 1123 : gcc_assert (!frame.nregs);
10171 : : }
10172 : 1557388 : else if (restore_regs_via_mov)
10173 : : {
10174 : 235348 : rtx t;
10175 : :
10176 : 235348 : if (frame.nregs)
10177 : 41481 : ix86_emit_restore_regs_using_mov (reg_save_offset, style == 2);
10178 : :
10179 : : /* eh_return epilogues need %ecx added to the stack pointer. */
10180 : 235348 : if (style == 2)
10181 : : {
10182 : 29 : rtx sa = EH_RETURN_STACKADJ_RTX;
10183 : 29 : rtx_insn *insn;
10184 : :
10185 : : /* Stack realignment doesn't work with eh_return. */
10186 : 29 : if (crtl->stack_realign_needed)
10187 : 0 : sorry ("Stack realignment not supported with "
10188 : : "%<__builtin_eh_return%>");
10189 : :
10190 : : /* regparm nested functions don't work with eh_return. */
10191 : 29 : if (ix86_static_chain_on_stack)
10192 : 0 : sorry ("regparm nested function not supported with "
10193 : : "%<__builtin_eh_return%>");
10194 : :
10195 : 29 : if (frame_pointer_needed)
10196 : : {
10197 : 27 : t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
10198 : 35 : t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
10199 : 27 : emit_insn (gen_rtx_SET (sa, t));
10200 : :
10201 : : /* NB: eh_return epilogues must restore the frame pointer
10202 : : in word_mode since the upper 32 bits of RBP register
10203 : : can have any values. */
10204 : 27 : t = gen_frame_mem (word_mode, hard_frame_pointer_rtx);
10205 : 27 : rtx frame_reg = gen_rtx_REG (word_mode,
10206 : : HARD_FRAME_POINTER_REGNUM);
10207 : 27 : insn = emit_move_insn (frame_reg, t);
10208 : :
10209 : : /* Note that we use SA as a temporary CFA, as the return
10210 : : address is at the proper place relative to it. We
10211 : : pretend this happens at the FP restore insn because
10212 : : prior to this insn the FP would be stored at the wrong
10213 : : offset relative to SA, and after this insn we have no
10214 : : other reasonable register to use for the CFA. We don't
10215 : : bother resetting the CFA to the SP for the duration of
10216 : : the return insn, unless the control flow instrumentation
10217 : : is done. In this case the SP is used later and we have
10218 : : to reset CFA to SP. */
10219 : 27 : add_reg_note (insn, REG_CFA_DEF_CFA,
10220 : 35 : plus_constant (Pmode, sa, UNITS_PER_WORD));
10221 : 27 : ix86_add_queued_cfa_restore_notes (insn);
10222 : 27 : add_reg_note (insn, REG_CFA_RESTORE, frame_reg);
10223 : 27 : RTX_FRAME_RELATED_P (insn) = 1;
10224 : :
10225 : 27 : m->fs.cfa_reg = sa;
10226 : 27 : m->fs.cfa_offset = UNITS_PER_WORD;
10227 : 27 : m->fs.fp_valid = false;
10228 : :
10229 : 27 : pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
10230 : : const0_rtx, style,
10231 : 27 : flag_cf_protection);
10232 : : }
10233 : : else
10234 : : {
10235 : 2 : t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
10236 : 2 : t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD);
10237 : 2 : insn = emit_insn (gen_rtx_SET (stack_pointer_rtx, t));
10238 : 2 : ix86_add_queued_cfa_restore_notes (insn);
10239 : :
10240 : 2 : gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
10241 : 2 : if (m->fs.cfa_offset != UNITS_PER_WORD)
10242 : : {
10243 : 2 : m->fs.cfa_offset = UNITS_PER_WORD;
10244 : 2 : add_reg_note (insn, REG_CFA_DEF_CFA,
10245 : 2 : plus_constant (Pmode, stack_pointer_rtx,
10246 : 2 : UNITS_PER_WORD));
10247 : 2 : RTX_FRAME_RELATED_P (insn) = 1;
10248 : : }
10249 : : }
10250 : 29 : m->fs.sp_offset = UNITS_PER_WORD;
10251 : 29 : m->fs.sp_valid = true;
10252 : 29 : m->fs.sp_realigned = false;
10253 : : }
10254 : : }
10255 : : else
10256 : : {
10257 : : /* SEH requires that the function end with (1) a stack adjustment
10258 : : if necessary, (2) a sequence of pops, and (3) a return or
10259 : : jump instruction. Prevent insns from the function body from
10260 : : being scheduled into this sequence. */
10261 : 1322040 : if (TARGET_SEH)
10262 : : {
10263 : : /* Prevent a catch region from being adjacent to the standard
10264 : : epilogue sequence. Unfortunately neither crtl->uses_eh_lsda
10265 : : nor several other flags that would be interesting to test are
10266 : : set up yet. */
10267 : : if (flag_non_call_exceptions)
10268 : : emit_insn (gen_nops (const1_rtx));
10269 : : else
10270 : : emit_insn (gen_blockage ());
10271 : : }
10272 : :
10273 : : /* First step is to deallocate the stack frame so that we can
10274 : : pop the registers. If the stack pointer was realigned, it needs
10275 : : to be restored now. Also do it on SEH target for very large
10276 : : frame as the emitted instructions aren't allowed by the ABI
10277 : : in epilogues. */
10278 : 1322040 : if (!m->fs.sp_valid || m->fs.sp_realigned
10279 : : || (TARGET_SEH
10280 : : && (m->fs.sp_offset - reg_save_offset
10281 : : >= SEH_MAX_FRAME_SIZE)))
10282 : : {
10283 : 28805 : pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx,
10284 : 28805 : GEN_INT (m->fs.fp_offset
10285 : : - reg_save_offset),
10286 : : style, false);
10287 : : }
10288 : 1293235 : else if (m->fs.sp_offset != reg_save_offset)
10289 : : {
10290 : 609884 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10291 : : GEN_INT (m->fs.sp_offset
10292 : : - reg_save_offset),
10293 : : style,
10294 : 609884 : m->fs.cfa_reg == stack_pointer_rtx);
10295 : : }
10296 : :
10297 : 1322040 : if (TARGET_APX_PUSH2POP2
10298 : 447 : && ix86_can_use_push2pop2 ()
10299 : 1322485 : && m->func_type == TYPE_NORMAL)
10300 : 444 : ix86_emit_restore_regs_using_pop2 ();
10301 : : else
10302 : 1321596 : ix86_emit_restore_regs_using_pop (TARGET_APX_PPX);
10303 : : }
10304 : :
10305 : : /* If we used a stack pointer and haven't already got rid of it,
10306 : : then do so now. */
10307 : 1558511 : if (m->fs.fp_valid)
10308 : : {
10309 : : /* If the stack pointer is valid and pointing at the frame
10310 : : pointer store address, then we only need a pop. */
10311 : 465398 : if (sp_valid_at (frame.hfp_save_offset)
10312 : 465398 : && m->fs.sp_offset == frame.hfp_save_offset)
10313 : 230189 : ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
10314 : : /* Leave results in shorter dependency chains on CPUs that are
10315 : : able to grok it fast. */
10316 : 235209 : else if (TARGET_USE_LEAVE
10317 : 12 : || optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun))
10318 : 235221 : || !cfun->machine->use_fast_prologue_epilogue)
10319 : 235197 : ix86_emit_leave (NULL);
10320 : : else
10321 : : {
10322 : 12 : pro_epilogue_adjust_stack (stack_pointer_rtx,
10323 : : hard_frame_pointer_rtx,
10324 : 12 : const0_rtx, style, !using_drap);
10325 : 12 : ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
10326 : : }
10327 : : }
10328 : :
10329 : 1558511 : if (using_drap)
10330 : : {
10331 : 6995 : int param_ptr_offset = UNITS_PER_WORD;
10332 : 6995 : rtx_insn *insn;
10333 : :
10334 : 6995 : gcc_assert (stack_realign_drap);
10335 : :
10336 : 6995 : if (ix86_static_chain_on_stack)
10337 : 0 : param_ptr_offset += UNITS_PER_WORD;
10338 : 6995 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
10339 : 218 : param_ptr_offset += UNITS_PER_WORD;
10340 : :
10341 : 6995 : insn = emit_insn (gen_rtx_SET
10342 : : (stack_pointer_rtx,
10343 : : plus_constant (Pmode, crtl->drap_reg,
10344 : : -param_ptr_offset)));
10345 : 6995 : m->fs.cfa_reg = stack_pointer_rtx;
10346 : 6995 : m->fs.cfa_offset = param_ptr_offset;
10347 : 6995 : m->fs.sp_offset = param_ptr_offset;
10348 : 6995 : m->fs.realigned = false;
10349 : :
10350 : 7297 : add_reg_note (insn, REG_CFA_DEF_CFA,
10351 : 6995 : plus_constant (Pmode, stack_pointer_rtx,
10352 : : param_ptr_offset));
10353 : 6995 : RTX_FRAME_RELATED_P (insn) = 1;
10354 : :
10355 : 6995 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
10356 : 218 : ix86_emit_restore_reg_using_pop (crtl->drap_reg);
10357 : : }
10358 : :
10359 : : /* At this point the stack pointer must be valid, and we must have
10360 : : restored all of the registers. We may not have deallocated the
10361 : : entire stack frame. We've delayed this until now because it may
10362 : : be possible to merge the local stack deallocation with the
10363 : : deallocation forced by ix86_static_chain_on_stack. */
10364 : 1558511 : gcc_assert (m->fs.sp_valid);
10365 : 1558511 : gcc_assert (!m->fs.sp_realigned);
10366 : 1558511 : gcc_assert (!m->fs.fp_valid);
10367 : 1558511 : gcc_assert (!m->fs.realigned);
10368 : 1688607 : if (m->fs.sp_offset != UNITS_PER_WORD)
10369 : : {
10370 : 95 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10371 : : GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
10372 : : style, true);
10373 : : }
10374 : : else
10375 : 1558416 : ix86_add_queued_cfa_restore_notes (get_last_insn ());
10376 : :
10377 : : /* Sibcall epilogues don't want a return instruction. */
10378 : 1558511 : if (style == 0)
10379 : : {
10380 : 117658 : m->fs = frame_state_save;
10381 : 117658 : return;
10382 : : }
10383 : :
10384 : 1440853 : if (cfun->machine->func_type != TYPE_NORMAL)
10385 : 118 : emit_jump_insn (gen_interrupt_return ());
10386 : 1440735 : else if (crtl->args.pops_args && crtl->args.size)
10387 : : {
10388 : 25615 : rtx popc = GEN_INT (crtl->args.pops_args);
10389 : :
10390 : : /* i386 can only pop 64K bytes. If asked to pop more, pop return
10391 : : address, do explicit add, and jump indirectly to the caller. */
10392 : :
10393 : 25615 : if (crtl->args.pops_args >= 65536)
10394 : : {
10395 : 0 : rtx ecx = gen_rtx_REG (SImode, CX_REG);
10396 : 0 : rtx_insn *insn;
10397 : :
10398 : : /* There is no "pascal" calling convention in any 64bit ABI. */
10399 : 0 : gcc_assert (!TARGET_64BIT);
10400 : :
10401 : 0 : insn = emit_insn (gen_pop (ecx));
10402 : 0 : m->fs.cfa_offset -= UNITS_PER_WORD;
10403 : 0 : m->fs.sp_offset -= UNITS_PER_WORD;
10404 : :
10405 : 0 : rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
10406 : 0 : x = gen_rtx_SET (stack_pointer_rtx, x);
10407 : 0 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
10408 : 0 : add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
10409 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
10410 : :
10411 : 0 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10412 : : popc, -1, true);
10413 : 0 : emit_jump_insn (gen_simple_return_indirect_internal (ecx));
10414 : : }
10415 : : else
10416 : 25615 : emit_jump_insn (gen_simple_return_pop_internal (popc));
10417 : : }
10418 : 1415120 : else if (!m->call_ms2sysv || !restore_stub_is_tail)
10419 : : {
10420 : : /* In case of return from EH a simple return cannot be used
10421 : : as a return address will be compared with a shadow stack
10422 : : return address. Use indirect jump instead. */
10423 : 1413997 : if (style == 2 && flag_cf_protection)
10424 : : {
10425 : : /* Register used in indirect jump must be in word_mode. But
10426 : : Pmode may not be the same as word_mode for x32. */
10427 : 17 : rtx ecx = gen_rtx_REG (word_mode, CX_REG);
10428 : 17 : rtx_insn *insn;
10429 : :
10430 : 17 : insn = emit_insn (gen_pop (ecx));
10431 : 17 : m->fs.cfa_offset -= UNITS_PER_WORD;
10432 : 17 : m->fs.sp_offset -= UNITS_PER_WORD;
10433 : :
10434 : 25 : rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
10435 : 17 : x = gen_rtx_SET (stack_pointer_rtx, x);
10436 : 17 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
10437 : 17 : add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
10438 : 17 : RTX_FRAME_RELATED_P (insn) = 1;
10439 : :
10440 : 17 : emit_jump_insn (gen_simple_return_indirect_internal (ecx));
10441 : 17 : }
10442 : : else
10443 : 1413980 : emit_jump_insn (gen_simple_return_internal ());
10444 : : }
10445 : :
10446 : : /* Restore the state back to the state from the prologue,
10447 : : so that it's correct for the next epilogue. */
10448 : 1440853 : m->fs = frame_state_save;
10449 : : }
10450 : :
10451 : : /* Reset from the function's potential modifications. */
10452 : :
10453 : : static void
10454 : 1446221 : ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED)
10455 : : {
10456 : 1446221 : if (pic_offset_table_rtx
10457 : 1446221 : && !ix86_use_pseudo_pic_reg ())
10458 : 0 : SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
10459 : :
10460 : 1446221 : if (TARGET_MACHO)
10461 : : {
10462 : : rtx_insn *insn = get_last_insn ();
10463 : : rtx_insn *deleted_debug_label = NULL;
10464 : :
10465 : : /* Mach-O doesn't support labels at the end of objects, so if
10466 : : it looks like we might want one, take special action.
10467 : : First, collect any sequence of deleted debug labels. */
10468 : : while (insn
10469 : : && NOTE_P (insn)
10470 : : && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
10471 : : {
10472 : : /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
10473 : : notes only, instead set their CODE_LABEL_NUMBER to -1,
10474 : : otherwise there would be code generation differences
10475 : : in between -g and -g0. */
10476 : : if (NOTE_P (insn) && NOTE_KIND (insn)
10477 : : == NOTE_INSN_DELETED_DEBUG_LABEL)
10478 : : deleted_debug_label = insn;
10479 : : insn = PREV_INSN (insn);
10480 : : }
10481 : :
10482 : : /* If we have:
10483 : : label:
10484 : : barrier
10485 : : then this needs to be detected, so skip past the barrier. */
10486 : :
10487 : : if (insn && BARRIER_P (insn))
10488 : : insn = PREV_INSN (insn);
10489 : :
10490 : : /* Up to now we've only seen notes or barriers. */
10491 : : if (insn)
10492 : : {
10493 : : if (LABEL_P (insn)
10494 : : || (NOTE_P (insn)
10495 : : && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
10496 : : /* Trailing label. */
10497 : : fputs ("\tnop\n", file);
10498 : : else if (cfun && ! cfun->is_thunk)
10499 : : {
10500 : : /* See if we have a completely empty function body, skipping
10501 : : the special case of the picbase thunk emitted as asm. */
10502 : : while (insn && ! INSN_P (insn))
10503 : : insn = PREV_INSN (insn);
10504 : : /* If we don't find any insns, we've got an empty function body;
10505 : : I.e. completely empty - without a return or branch. This is
10506 : : taken as the case where a function body has been removed
10507 : : because it contains an inline __builtin_unreachable(). GCC
10508 : : declares that reaching __builtin_unreachable() means UB so
10509 : : we're not obliged to do anything special; however, we want
10510 : : non-zero-sized function bodies. To meet this, and help the
10511 : : user out, let's trap the case. */
10512 : : if (insn == NULL)
10513 : : fputs ("\tud2\n", file);
10514 : : }
10515 : : }
10516 : : else if (deleted_debug_label)
10517 : : for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
10518 : : if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
10519 : : CODE_LABEL_NUMBER (insn) = -1;
10520 : : }
10521 : 1446221 : }
10522 : :
10523 : : /* Implement TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY. */
10524 : :
10525 : : void
10526 : 59 : ix86_print_patchable_function_entry (FILE *file,
10527 : : unsigned HOST_WIDE_INT patch_area_size,
10528 : : bool record_p)
10529 : : {
10530 : 59 : if (cfun->machine->function_label_emitted)
10531 : : {
10532 : : /* NB: When ix86_print_patchable_function_entry is called after
10533 : : function table has been emitted, we have inserted or queued
10534 : : a pseudo UNSPECV_PATCHABLE_AREA instruction at the proper
10535 : : place. There is nothing to do here. */
10536 : : return;
10537 : : }
10538 : :
10539 : 8 : default_print_patchable_function_entry (file, patch_area_size,
10540 : : record_p);
10541 : : }
10542 : :
10543 : : /* Output patchable area. NB: default_print_patchable_function_entry
10544 : : isn't available in i386.md. */
10545 : :
10546 : : void
10547 : 51 : ix86_output_patchable_area (unsigned int patch_area_size,
10548 : : bool record_p)
10549 : : {
10550 : 51 : default_print_patchable_function_entry (asm_out_file,
10551 : : patch_area_size,
10552 : : record_p);
10553 : 51 : }
10554 : :
10555 : : /* Return a scratch register to use in the split stack prologue. The
10556 : : split stack prologue is used for -fsplit-stack. It is the first
10557 : : instructions in the function, even before the regular prologue.
10558 : : The scratch register can be any caller-saved register which is not
10559 : : used for parameters or for the static chain. */
10560 : :
10561 : : static unsigned int
10562 : 24663 : split_stack_prologue_scratch_regno (void)
10563 : : {
10564 : 24663 : if (TARGET_64BIT)
10565 : : return R11_REG;
10566 : : else
10567 : : {
10568 : 6972 : bool is_fastcall, is_thiscall;
10569 : 6972 : int regparm;
10570 : :
10571 : 6972 : is_fastcall = (lookup_attribute ("fastcall",
10572 : 6972 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
10573 : : != NULL);
10574 : 6972 : is_thiscall = (lookup_attribute ("thiscall",
10575 : 6972 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
10576 : : != NULL);
10577 : 6972 : regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
10578 : :
10579 : 6972 : if (is_fastcall)
10580 : : {
10581 : 0 : if (DECL_STATIC_CHAIN (cfun->decl))
10582 : : {
10583 : 0 : sorry ("%<-fsplit-stack%> does not support fastcall with "
10584 : : "nested function");
10585 : 0 : return INVALID_REGNUM;
10586 : : }
10587 : : return AX_REG;
10588 : : }
10589 : 6972 : else if (is_thiscall)
10590 : : {
10591 : 0 : if (!DECL_STATIC_CHAIN (cfun->decl))
10592 : : return DX_REG;
10593 : 0 : return AX_REG;
10594 : : }
10595 : 6972 : else if (regparm < 3)
10596 : : {
10597 : 6972 : if (!DECL_STATIC_CHAIN (cfun->decl))
10598 : : return CX_REG;
10599 : : else
10600 : : {
10601 : 448 : if (regparm >= 2)
10602 : : {
10603 : 0 : sorry ("%<-fsplit-stack%> does not support 2 register "
10604 : : "parameters for a nested function");
10605 : 0 : return INVALID_REGNUM;
10606 : : }
10607 : : return DX_REG;
10608 : : }
10609 : : }
10610 : : else
10611 : : {
10612 : : /* FIXME: We could make this work by pushing a register
10613 : : around the addition and comparison. */
10614 : 0 : sorry ("%<-fsplit-stack%> does not support 3 register parameters");
10615 : 0 : return INVALID_REGNUM;
10616 : : }
10617 : : }
10618 : : }
10619 : :
10620 : : /* A SYMBOL_REF for the function which allocates new stackspace for
10621 : : -fsplit-stack. */
10622 : :
10623 : : static GTY(()) rtx split_stack_fn;
10624 : :
10625 : : /* A SYMBOL_REF for the more stack function when using the large
10626 : : model. */
10627 : :
10628 : : static GTY(()) rtx split_stack_fn_large;
10629 : :
10630 : : /* Return location of the stack guard value in the TLS block. */
10631 : :
10632 : : rtx
10633 : 259805 : ix86_split_stack_guard (void)
10634 : : {
10635 : 259805 : int offset;
10636 : 259805 : addr_space_t as = DEFAULT_TLS_SEG_REG;
10637 : 259805 : rtx r;
10638 : :
10639 : 259805 : gcc_assert (flag_split_stack);
10640 : :
10641 : : #ifdef TARGET_THREAD_SPLIT_STACK_OFFSET
10642 : 259805 : offset = TARGET_THREAD_SPLIT_STACK_OFFSET;
10643 : : #else
10644 : : gcc_unreachable ();
10645 : : #endif
10646 : :
10647 : 259805 : r = GEN_INT (offset);
10648 : 259805 : r = gen_const_mem (Pmode, r);
10649 : 259805 : set_mem_addr_space (r, as);
10650 : :
10651 : 259805 : return r;
10652 : : }
10653 : :
10654 : : /* Handle -fsplit-stack. These are the first instructions in the
10655 : : function, even before the regular prologue. */
10656 : :
10657 : : void
10658 : 259795 : ix86_expand_split_stack_prologue (void)
10659 : : {
10660 : 259795 : HOST_WIDE_INT allocate;
10661 : 259795 : unsigned HOST_WIDE_INT args_size;
10662 : 259795 : rtx_code_label *label;
10663 : 259795 : rtx limit, current, allocate_rtx, call_fusage;
10664 : 259795 : rtx_insn *call_insn;
10665 : 259795 : unsigned int scratch_regno = INVALID_REGNUM;
10666 : 259795 : rtx scratch_reg = NULL_RTX;
10667 : 259795 : rtx_code_label *varargs_label = NULL;
10668 : 259795 : rtx fn;
10669 : :
10670 : 259795 : gcc_assert (flag_split_stack && reload_completed);
10671 : :
10672 : 259795 : ix86_finalize_stack_frame_flags ();
10673 : 259795 : struct ix86_frame &frame = cfun->machine->frame;
10674 : 259795 : allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
10675 : :
10676 : : /* This is the label we will branch to if we have enough stack
10677 : : space. We expect the basic block reordering pass to reverse this
10678 : : branch if optimizing, so that we branch in the unlikely case. */
10679 : 259795 : label = gen_label_rtx ();
10680 : :
10681 : : /* We need to compare the stack pointer minus the frame size with
10682 : : the stack boundary in the TCB. The stack boundary always gives
10683 : : us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we
10684 : : can compare directly. Otherwise we need to do an addition. */
10685 : :
10686 : 259795 : limit = ix86_split_stack_guard ();
10687 : :
10688 : 259795 : if (allocate >= SPLIT_STACK_AVAILABLE
10689 : 235295 : || flag_force_indirect_call)
10690 : : {
10691 : 24515 : scratch_regno = split_stack_prologue_scratch_regno ();
10692 : 24515 : if (scratch_regno == INVALID_REGNUM)
10693 : 0 : return;
10694 : : }
10695 : :
10696 : 259795 : if (allocate >= SPLIT_STACK_AVAILABLE)
10697 : : {
10698 : 24500 : rtx offset;
10699 : :
10700 : : /* We need a scratch register to hold the stack pointer minus
10701 : : the required frame size. Since this is the very start of the
10702 : : function, the scratch register can be any caller-saved
10703 : : register which is not used for parameters. */
10704 : 24500 : offset = GEN_INT (- allocate);
10705 : :
10706 : 24500 : scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
10707 : 24500 : if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode))
10708 : : {
10709 : : /* We don't use gen_add in this case because it will
10710 : : want to split to lea, but when not optimizing the insn
10711 : : will not be split after this point. */
10712 : 24500 : emit_insn (gen_rtx_SET (scratch_reg,
10713 : : gen_rtx_PLUS (Pmode, stack_pointer_rtx,
10714 : : offset)));
10715 : : }
10716 : : else
10717 : : {
10718 : 0 : emit_move_insn (scratch_reg, offset);
10719 : 0 : emit_insn (gen_add2_insn (scratch_reg, stack_pointer_rtx));
10720 : : }
10721 : : current = scratch_reg;
10722 : : }
10723 : : else
10724 : 235295 : current = stack_pointer_rtx;
10725 : :
10726 : 259795 : ix86_expand_branch (GEU, current, limit, label);
10727 : 259795 : rtx_insn *jump_insn = get_last_insn ();
10728 : 259795 : JUMP_LABEL (jump_insn) = label;
10729 : :
10730 : : /* Mark the jump as very likely to be taken. */
10731 : 259795 : add_reg_br_prob_note (jump_insn, profile_probability::very_likely ());
10732 : :
10733 : 259795 : if (split_stack_fn == NULL_RTX)
10734 : : {
10735 : 4348 : split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack");
10736 : 4348 : SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL;
10737 : : }
10738 : 259795 : fn = split_stack_fn;
10739 : :
10740 : : /* Get more stack space. We pass in the desired stack space and the
10741 : : size of the arguments to copy to the new stack. In 32-bit mode
10742 : : we push the parameters; __morestack will return on a new stack
10743 : : anyhow. In 64-bit mode we pass the parameters in r10 and
10744 : : r11. */
10745 : 259795 : allocate_rtx = GEN_INT (allocate);
10746 : 259795 : args_size = crtl->args.size >= 0 ? (HOST_WIDE_INT) crtl->args.size : 0;
10747 : 259795 : call_fusage = NULL_RTX;
10748 : 259795 : rtx pop = NULL_RTX;
10749 : 259795 : if (TARGET_64BIT)
10750 : : {
10751 : 161893 : rtx reg10, reg11;
10752 : :
10753 : 161893 : reg10 = gen_rtx_REG (DImode, R10_REG);
10754 : 161893 : reg11 = gen_rtx_REG (DImode, R11_REG);
10755 : :
10756 : : /* If this function uses a static chain, it will be in %r10.
10757 : : Preserve it across the call to __morestack. */
10758 : 161893 : if (DECL_STATIC_CHAIN (cfun->decl))
10759 : : {
10760 : 7505 : rtx rax;
10761 : :
10762 : 7505 : rax = gen_rtx_REG (word_mode, AX_REG);
10763 : 7505 : emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG));
10764 : 7505 : use_reg (&call_fusage, rax);
10765 : : }
10766 : :
10767 : 161893 : if (flag_force_indirect_call
10768 : 161878 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
10769 : : {
10770 : 16 : HOST_WIDE_INT argval;
10771 : :
10772 : 16 : if (split_stack_fn_large == NULL_RTX)
10773 : : {
10774 : 7 : split_stack_fn_large
10775 : 7 : = gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model");
10776 : 7 : SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL;
10777 : : }
10778 : :
10779 : 16 : fn = split_stack_fn_large;
10780 : :
10781 : 16 : if (ix86_cmodel == CM_LARGE_PIC)
10782 : : {
10783 : 3 : rtx_code_label *label;
10784 : 3 : rtx x;
10785 : :
10786 : 3 : gcc_assert (Pmode == DImode);
10787 : :
10788 : 3 : label = gen_label_rtx ();
10789 : 3 : emit_label (label);
10790 : 3 : LABEL_PRESERVE_P (label) = 1;
10791 : 3 : emit_insn (gen_set_rip_rex64 (reg10, label));
10792 : 3 : emit_insn (gen_set_got_offset_rex64 (reg11, label));
10793 : 3 : emit_insn (gen_add2_insn (reg10, reg11));
10794 : 3 : x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fn), UNSPEC_GOT);
10795 : 3 : x = gen_rtx_CONST (Pmode, x);
10796 : 3 : emit_move_insn (reg11, x);
10797 : 3 : x = gen_rtx_PLUS (Pmode, reg10, reg11);
10798 : 3 : x = gen_const_mem (Pmode, x);
10799 : 3 : fn = copy_to_suggested_reg (x, reg11, Pmode);
10800 : : }
10801 : 13 : else if (ix86_cmodel == CM_LARGE)
10802 : 1 : fn = copy_to_suggested_reg (fn, reg11, Pmode);
10803 : :
10804 : : /* When using the large model we need to load the address
10805 : : into a register, and we've run out of registers. So we
10806 : : switch to a different calling convention, and we call a
10807 : : different function: __morestack_large. We pass the
10808 : : argument size in the upper 32 bits of r10 and pass the
10809 : : frame size in the lower 32 bits. */
10810 : 16 : gcc_assert ((allocate & HOST_WIDE_INT_C (0xffffffff)) == allocate);
10811 : 16 : gcc_assert ((args_size & 0xffffffff) == args_size);
10812 : :
10813 : 16 : argval = ((args_size << 16) << 16) + allocate;
10814 : 16 : emit_move_insn (reg10, GEN_INT (argval));
10815 : 16 : }
10816 : : else
10817 : : {
10818 : 161877 : emit_move_insn (reg10, allocate_rtx);
10819 : 161877 : emit_move_insn (reg11, GEN_INT (args_size));
10820 : 161877 : use_reg (&call_fusage, reg11);
10821 : : }
10822 : :
10823 : 161893 : use_reg (&call_fusage, reg10);
10824 : : }
10825 : : else
10826 : : {
10827 : 97902 : if (flag_force_indirect_call && flag_pic)
10828 : : {
10829 : 0 : rtx x;
10830 : :
10831 : 0 : gcc_assert (Pmode == SImode);
10832 : :
10833 : 0 : scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
10834 : :
10835 : 0 : emit_insn (gen_set_got (scratch_reg));
10836 : 0 : x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn),
10837 : : UNSPEC_GOT);
10838 : 0 : x = gen_rtx_CONST (Pmode, x);
10839 : 0 : x = gen_rtx_PLUS (Pmode, scratch_reg, x);
10840 : 0 : x = gen_const_mem (Pmode, x);
10841 : 0 : fn = copy_to_suggested_reg (x, scratch_reg, Pmode);
10842 : : }
10843 : :
10844 : 97902 : rtx_insn *insn = emit_insn (gen_push (GEN_INT (args_size)));
10845 : 195804 : add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (UNITS_PER_WORD));
10846 : 97902 : insn = emit_insn (gen_push (allocate_rtx));
10847 : 195804 : add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (2 * UNITS_PER_WORD));
10848 : 195804 : pop = GEN_INT (2 * UNITS_PER_WORD);
10849 : : }
10850 : :
10851 : 259795 : if (flag_force_indirect_call && !register_operand (fn, VOIDmode))
10852 : : {
10853 : 12 : scratch_reg = gen_rtx_REG (word_mode, scratch_regno);
10854 : :
10855 : 12 : if (GET_MODE (fn) != word_mode)
10856 : 0 : fn = gen_rtx_ZERO_EXTEND (word_mode, fn);
10857 : :
10858 : 12 : fn = copy_to_suggested_reg (fn, scratch_reg, word_mode);
10859 : : }
10860 : :
10861 : 259795 : call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn),
10862 : 259795 : GEN_INT (UNITS_PER_WORD), constm1_rtx,
10863 : : pop, false);
10864 : 259795 : add_function_usage_to (call_insn, call_fusage);
10865 : 259795 : if (!TARGET_64BIT)
10866 : 97902 : add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (0));
10867 : : /* Indicate that this function can't jump to non-local gotos. */
10868 : 259795 : make_reg_eh_region_note_nothrow_nononlocal (call_insn);
10869 : :
10870 : : /* In order to make call/return prediction work right, we now need
10871 : : to execute a return instruction. See
10872 : : libgcc/config/i386/morestack.S for the details on how this works.
10873 : :
10874 : : For flow purposes gcc must not see this as a return
10875 : : instruction--we need control flow to continue at the subsequent
10876 : : label. Therefore, we use an unspec. */
10877 : 259795 : gcc_assert (crtl->args.pops_args < 65536);
10878 : 259795 : rtx_insn *ret_insn
10879 : 259795 : = emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args)));
10880 : :
10881 : 259795 : if ((flag_cf_protection & CF_BRANCH))
10882 : : {
10883 : : /* Insert ENDBR since __morestack will jump back here via indirect
10884 : : call. */
10885 : 21 : rtx cet_eb = gen_nop_endbr ();
10886 : 21 : emit_insn_after (cet_eb, ret_insn);
10887 : : }
10888 : :
10889 : : /* If we are in 64-bit mode and this function uses a static chain,
10890 : : we saved %r10 in %rax before calling _morestack. */
10891 : 259795 : if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl))
10892 : 7505 : emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
10893 : : gen_rtx_REG (word_mode, AX_REG));
10894 : :
10895 : : /* If this function calls va_start, we need to store a pointer to
10896 : : the arguments on the old stack, because they may not have been
10897 : : all copied to the new stack. At this point the old stack can be
10898 : : found at the frame pointer value used by __morestack, because
10899 : : __morestack has set that up before calling back to us. Here we
10900 : : store that pointer in a scratch register, and in
10901 : : ix86_expand_prologue we store the scratch register in a stack
10902 : : slot. */
10903 : 259795 : if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
10904 : : {
10905 : 12 : rtx frame_reg;
10906 : 12 : int words;
10907 : :
10908 : 12 : scratch_regno = split_stack_prologue_scratch_regno ();
10909 : 12 : scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
10910 : 12 : frame_reg = gen_rtx_REG (Pmode, BP_REG);
10911 : :
10912 : : /* 64-bit:
10913 : : fp -> old fp value
10914 : : return address within this function
10915 : : return address of caller of this function
10916 : : stack arguments
10917 : : So we add three words to get to the stack arguments.
10918 : :
10919 : : 32-bit:
10920 : : fp -> old fp value
10921 : : return address within this function
10922 : : first argument to __morestack
10923 : : second argument to __morestack
10924 : : return address of caller of this function
10925 : : stack arguments
10926 : : So we add five words to get to the stack arguments.
10927 : : */
10928 : 12 : words = TARGET_64BIT ? 3 : 5;
10929 : 16 : emit_insn (gen_rtx_SET (scratch_reg,
10930 : : plus_constant (Pmode, frame_reg,
10931 : : words * UNITS_PER_WORD)));
10932 : :
10933 : 12 : varargs_label = gen_label_rtx ();
10934 : 12 : emit_jump_insn (gen_jump (varargs_label));
10935 : 12 : JUMP_LABEL (get_last_insn ()) = varargs_label;
10936 : :
10937 : 12 : emit_barrier ();
10938 : : }
10939 : :
10940 : 259795 : emit_label (label);
10941 : 259795 : LABEL_NUSES (label) = 1;
10942 : :
10943 : : /* If this function calls va_start, we now have to set the scratch
10944 : : register for the case where we do not call __morestack. In this
10945 : : case we need to set it based on the stack pointer. */
10946 : 259795 : if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
10947 : : {
10948 : 16 : emit_insn (gen_rtx_SET (scratch_reg,
10949 : : plus_constant (Pmode, stack_pointer_rtx,
10950 : : UNITS_PER_WORD)));
10951 : :
10952 : 12 : emit_label (varargs_label);
10953 : 12 : LABEL_NUSES (varargs_label) = 1;
10954 : : }
10955 : : }
10956 : :
10957 : : /* We may have to tell the dataflow pass that the split stack prologue
10958 : : is initializing a scratch register. */
10959 : :
10960 : : static void
10961 : 14729671 : ix86_live_on_entry (bitmap regs)
10962 : : {
10963 : 14729671 : if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
10964 : : {
10965 : 124 : gcc_assert (flag_split_stack);
10966 : 124 : bitmap_set_bit (regs, split_stack_prologue_scratch_regno ());
10967 : : }
10968 : 14729671 : }
10969 : :
10970 : : /* Extract the parts of an RTL expression that is a valid memory address
10971 : : for an instruction. Return false if the structure of the address is
10972 : : grossly off. */
10973 : :
10974 : : bool
10975 : 4177855593 : ix86_decompose_address (rtx addr, struct ix86_address *out)
10976 : : {
10977 : 4177855593 : rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
10978 : 4177855593 : rtx base_reg, index_reg;
10979 : 4177855593 : HOST_WIDE_INT scale = 1;
10980 : 4177855593 : rtx scale_rtx = NULL_RTX;
10981 : 4177855593 : rtx tmp;
10982 : 4177855593 : addr_space_t seg = ADDR_SPACE_GENERIC;
10983 : :
10984 : : /* Allow zero-extended SImode addresses,
10985 : : they will be emitted with addr32 prefix. */
10986 : 4177855593 : if (TARGET_64BIT && GET_MODE (addr) == DImode)
10987 : : {
10988 : 2157338205 : if (GET_CODE (addr) == ZERO_EXTEND
10989 : 1826718 : && GET_MODE (XEXP (addr, 0)) == SImode)
10990 : : {
10991 : 1722798 : addr = XEXP (addr, 0);
10992 : 1722798 : if (CONST_INT_P (addr))
10993 : : return false;
10994 : : }
10995 : 2155615407 : else if (GET_CODE (addr) == AND)
10996 : : {
10997 : 2776947 : rtx mask = XEXP (addr, 1);
10998 : 2776947 : rtx shift_val;
10999 : :
11000 : 2776947 : if (const_32bit_mask (mask, DImode)
11001 : : /* For ASHIFT inside AND, combine will not generate
11002 : : canonical zero-extend. Merge mask for AND and shift_count
11003 : : to check if it is canonical zero-extend. */
11004 : 2776947 : || (CONST_INT_P (mask)
11005 : 1901578 : && GET_CODE (XEXP (addr, 0)) == ASHIFT
11006 : 144790 : && CONST_INT_P (shift_val = XEXP (XEXP (addr, 0), 1))
11007 : 137257 : && ((UINTVAL (mask)
11008 : 137257 : | ((HOST_WIDE_INT_1U << INTVAL (shift_val)) - 1))
11009 : : == HOST_WIDE_INT_UC (0xffffffff))))
11010 : : {
11011 : 61602 : addr = lowpart_subreg (SImode, XEXP (addr, 0), DImode);
11012 : 61602 : if (addr == NULL_RTX)
11013 : : return false;
11014 : :
11015 : 61602 : if (CONST_INT_P (addr))
11016 : : return false;
11017 : : }
11018 : : }
11019 : : }
11020 : :
11021 : : /* Allow SImode subregs of DImode addresses,
11022 : : they will be emitted with addr32 prefix. */
11023 : 4177855593 : if (TARGET_64BIT && GET_MODE (addr) == SImode)
11024 : : {
11025 : 16667501 : if (SUBREG_P (addr)
11026 : 205053 : && GET_MODE (SUBREG_REG (addr)) == DImode)
11027 : : {
11028 : 183750 : addr = SUBREG_REG (addr);
11029 : 183750 : if (CONST_INT_P (addr))
11030 : : return false;
11031 : : }
11032 : : }
11033 : :
11034 : 4177855593 : if (REG_P (addr))
11035 : : base = addr;
11036 : : else if (SUBREG_P (addr))
11037 : : {
11038 : 496938 : if (REG_P (SUBREG_REG (addr)))
11039 : : base = addr;
11040 : : else
11041 : : return false;
11042 : : }
11043 : : else if (GET_CODE (addr) == PLUS)
11044 : : {
11045 : : rtx addends[4], op;
11046 : : int n = 0, i;
11047 : :
11048 : : op = addr;
11049 : 3037698565 : do
11050 : : {
11051 : 3037698565 : if (n >= 4)
11052 : 635689653 : return false;
11053 : 3037694377 : addends[n++] = XEXP (op, 1);
11054 : 3037694377 : op = XEXP (op, 0);
11055 : : }
11056 : 3037694377 : while (GET_CODE (op) == PLUS);
11057 : 2989359989 : if (n >= 4)
11058 : : return false;
11059 : 2989353275 : addends[n] = op;
11060 : :
11061 : 7748551347 : for (i = n; i >= 0; --i)
11062 : : {
11063 : 5394876823 : op = addends[i];
11064 : 5394876823 : switch (GET_CODE (op))
11065 : : {
11066 : 58356038 : case MULT:
11067 : 58356038 : if (index)
11068 : : return false;
11069 : 58317177 : index = XEXP (op, 0);
11070 : 58317177 : scale_rtx = XEXP (op, 1);
11071 : 58317177 : break;
11072 : :
11073 : 12669013 : case ASHIFT:
11074 : 12669013 : if (index)
11075 : : return false;
11076 : 12595995 : index = XEXP (op, 0);
11077 : 12595995 : tmp = XEXP (op, 1);
11078 : 12595995 : if (!CONST_INT_P (tmp))
11079 : : return false;
11080 : 12581748 : scale = INTVAL (tmp);
11081 : 12581748 : if ((unsigned HOST_WIDE_INT) scale > 3)
11082 : : return false;
11083 : 12165877 : scale = 1 << scale;
11084 : 12165877 : break;
11085 : :
11086 : 764132 : case ZERO_EXTEND:
11087 : 764132 : op = XEXP (op, 0);
11088 : 764132 : if (GET_CODE (op) != UNSPEC)
11089 : : return false;
11090 : : /* FALLTHRU */
11091 : :
11092 : 620216 : case UNSPEC:
11093 : 620216 : if (XINT (op, 1) == UNSPEC_TP
11094 : 612925 : && TARGET_TLS_DIRECT_SEG_REFS
11095 : 612925 : && seg == ADDR_SPACE_GENERIC)
11096 : 612925 : seg = DEFAULT_TLS_SEG_REG;
11097 : : else
11098 : : return false;
11099 : : break;
11100 : :
11101 : 510388 : case SUBREG:
11102 : 510388 : if (!REG_P (SUBREG_REG (op)))
11103 : : return false;
11104 : : /* FALLTHRU */
11105 : :
11106 : 2406054518 : case REG:
11107 : 2406054518 : if (!base)
11108 : : base = op;
11109 : 64079330 : else if (!index)
11110 : : index = op;
11111 : : else
11112 : : return false;
11113 : : break;
11114 : :
11115 : 2282811705 : case CONST:
11116 : 2282811705 : case CONST_INT:
11117 : 2282811705 : case SYMBOL_REF:
11118 : 2282811705 : case LABEL_REF:
11119 : 2282811705 : if (disp)
11120 : : return false;
11121 : : disp = op;
11122 : : break;
11123 : :
11124 : : default:
11125 : : return false;
11126 : : }
11127 : : }
11128 : : }
11129 : : else if (GET_CODE (addr) == MULT)
11130 : : {
11131 : 3395417 : index = XEXP (addr, 0); /* index*scale */
11132 : 3395417 : scale_rtx = XEXP (addr, 1);
11133 : : }
11134 : : else if (GET_CODE (addr) == ASHIFT)
11135 : : {
11136 : : /* We're called for lea too, which implements ashift on occasion. */
11137 : 3041108 : index = XEXP (addr, 0);
11138 : 3041108 : tmp = XEXP (addr, 1);
11139 : 3041108 : if (!CONST_INT_P (tmp))
11140 : : return false;
11141 : 2646968 : scale = INTVAL (tmp);
11142 : 2646968 : if ((unsigned HOST_WIDE_INT) scale > 3)
11143 : : return false;
11144 : 1904473 : scale = 1 << scale;
11145 : : }
11146 : : else
11147 : : disp = addr; /* displacement */
11148 : :
11149 : 2358974414 : if (index)
11150 : : {
11151 : 130860902 : if (REG_P (index))
11152 : : ;
11153 : 3837049 : else if (SUBREG_P (index)
11154 : 307676 : && REG_P (SUBREG_REG (index)))
11155 : : ;
11156 : : else
11157 : : return false;
11158 : : }
11159 : :
11160 : : /* Extract the integral value of scale. */
11161 : 3537424445 : if (scale_rtx)
11162 : : {
11163 : 54003837 : if (!CONST_INT_P (scale_rtx))
11164 : : return false;
11165 : 53444419 : scale = INTVAL (scale_rtx);
11166 : : }
11167 : :
11168 : 3536865027 : base_reg = base && SUBREG_P (base) ? SUBREG_REG (base) : base;
11169 : 3536865027 : index_reg = index && SUBREG_P (index) ? SUBREG_REG (index) : index;
11170 : :
11171 : : /* Avoid useless 0 displacement. */
11172 : 3536865027 : if (disp == const0_rtx && (base || index))
11173 : 3536865027 : disp = NULL_RTX;
11174 : :
11175 : : /* Allow arg pointer and stack pointer as index if there is not scaling. */
11176 : 2570605821 : if (base_reg && index_reg && scale == 1
11177 : 3599529534 : && (REGNO (index_reg) == ARG_POINTER_REGNUM
11178 : : || REGNO (index_reg) == FRAME_POINTER_REGNUM
11179 : : || REGNO (index_reg) == SP_REG))
11180 : : {
11181 : : std::swap (base, index);
11182 : : std::swap (base_reg, index_reg);
11183 : : }
11184 : :
11185 : : /* Special case: %ebp cannot be encoded as a base without a displacement.
11186 : : Similarly %r13. */
11187 : 305397494 : if (!disp && base_reg
11188 : 3838459410 : && (REGNO (base_reg) == ARG_POINTER_REGNUM
11189 : : || REGNO (base_reg) == FRAME_POINTER_REGNUM
11190 : : || REGNO (base_reg) == BP_REG
11191 : : || REGNO (base_reg) == R13_REG))
11192 : : disp = const0_rtx;
11193 : :
11194 : : /* Special case: on K6, [%esi] makes the instruction vector decoded.
11195 : : Avoid this by transforming to [%esi+0].
11196 : : Reload calls address legitimization without cfun defined, so we need
11197 : : to test cfun for being non-NULL. */
11198 : 0 : if (TARGET_CPU_P (K6) && cfun && optimize_function_for_speed_p (cfun)
11199 : 0 : && base_reg && !index_reg && !disp
11200 : 3536865027 : && REGNO (base_reg) == SI_REG)
11201 : 0 : disp = const0_rtx;
11202 : :
11203 : : /* Special case: encode reg+reg instead of reg*2. */
11204 : 3536865027 : if (!base && index && scale == 2)
11205 : 966259206 : base = index, base_reg = index_reg, scale = 1;
11206 : :
11207 : : /* Special case: scaling cannot be encoded without base or displacement. */
11208 : 966259206 : if (!base && !disp && index && scale != 1)
11209 : 2979163 : disp = const0_rtx;
11210 : :
11211 : 3536865027 : out->base = base;
11212 : 3536865027 : out->index = index;
11213 : 3536865027 : out->disp = disp;
11214 : 3536865027 : out->scale = scale;
11215 : 3536865027 : out->seg = seg;
11216 : :
11217 : 3536865027 : return true;
11218 : : }
11219 : :
11220 : : /* Return cost of the memory address x.
11221 : : For i386, it is better to use a complex address than let gcc copy
11222 : : the address into a reg and make a new pseudo. But not if the address
11223 : : requires to two regs - that would mean more pseudos with longer
11224 : : lifetimes. */
11225 : : static int
11226 : 9793034 : ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
11227 : : {
11228 : 9793034 : struct ix86_address parts;
11229 : 9793034 : int cost = 1;
11230 : 9793034 : int ok = ix86_decompose_address (x, &parts);
11231 : :
11232 : 9793034 : gcc_assert (ok);
11233 : :
11234 : 9793034 : if (parts.base && SUBREG_P (parts.base))
11235 : 276 : parts.base = SUBREG_REG (parts.base);
11236 : 9793034 : if (parts.index && SUBREG_P (parts.index))
11237 : 20 : parts.index = SUBREG_REG (parts.index);
11238 : :
11239 : : /* Attempt to minimize number of registers in the address by increasing
11240 : : address cost for each used register. We don't increase address cost
11241 : : for "pic_offset_table_rtx". When a memopt with "pic_offset_table_rtx"
11242 : : is not invariant itself it most likely means that base or index is not
11243 : : invariant. Therefore only "pic_offset_table_rtx" could be hoisted out,
11244 : : which is not profitable for x86. */
11245 : 9793034 : if (parts.base
11246 : 8482470 : && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
11247 : 18015609 : && (current_pass->type == GIMPLE_PASS
11248 : 2296645 : || !pic_offset_table_rtx
11249 : 119398 : || !REG_P (parts.base)
11250 : 119398 : || REGNO (pic_offset_table_rtx) != REGNO (parts.base)))
11251 : : cost++;
11252 : :
11253 : 9793034 : if (parts.index
11254 : 4836424 : && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
11255 : 14615947 : && (current_pass->type == GIMPLE_PASS
11256 : 539755 : || !pic_offset_table_rtx
11257 : 45383 : || !REG_P (parts.index)
11258 : 45383 : || REGNO (pic_offset_table_rtx) != REGNO (parts.index)))
11259 : 4821666 : cost++;
11260 : :
11261 : : /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
11262 : : since it's predecode logic can't detect the length of instructions
11263 : : and it degenerates to vector decoded. Increase cost of such
11264 : : addresses here. The penalty is minimally 2 cycles. It may be worthwhile
11265 : : to split such addresses or even refuse such addresses at all.
11266 : :
11267 : : Following addressing modes are affected:
11268 : : [base+scale*index]
11269 : : [scale*index+disp]
11270 : : [base+index]
11271 : :
11272 : : The first and last case may be avoidable by explicitly coding the zero in
11273 : : memory address, but I don't have AMD-K6 machine handy to check this
11274 : : theory. */
11275 : :
11276 : 9793034 : if (TARGET_CPU_P (K6)
11277 : 0 : && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
11278 : 0 : || (parts.disp && !parts.base && parts.index && parts.scale != 1)
11279 : 0 : || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
11280 : 0 : cost += 10;
11281 : :
11282 : 9793034 : return cost;
11283 : : }
11284 : :
11285 : : /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
11286 : : this is used for to form addresses to local data when -fPIC is in
11287 : : use. */
11288 : :
11289 : : static bool
11290 : 0 : darwin_local_data_pic (rtx disp)
11291 : : {
11292 : 0 : return (GET_CODE (disp) == UNSPEC
11293 : 0 : && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
11294 : : }
11295 : :
11296 : : /* True if the function symbol operand X should be loaded from GOT.
11297 : : If CALL_P is true, X is a call operand.
11298 : :
11299 : : NB: -mno-direct-extern-access doesn't force load from GOT for
11300 : : call.
11301 : :
11302 : : NB: In 32-bit mode, only non-PIC is allowed in inline assembly
11303 : : statements, since a PIC register could not be available at the
11304 : : call site. */
11305 : :
11306 : : bool
11307 : 1785872032 : ix86_force_load_from_GOT_p (rtx x, bool call_p)
11308 : : {
11309 : 94411193 : return ((TARGET_64BIT || (!flag_pic && HAVE_AS_IX86_GOT32X))
11310 : : && !TARGET_PECOFF && !TARGET_MACHO
11311 : 1783018189 : && (!flag_pic || this_is_asm_operands)
11312 : 1763407181 : && ix86_cmodel != CM_LARGE
11313 : 1763401383 : && ix86_cmodel != CM_LARGE_PIC
11314 : 1763401382 : && GET_CODE (x) == SYMBOL_REF
11315 : 1763401380 : && ((!call_p
11316 : 1758054397 : && (!ix86_direct_extern_access
11317 : 1758053033 : || (SYMBOL_REF_DECL (x)
11318 : 1572694991 : && lookup_attribute ("nodirect_extern_access",
11319 : 1572694991 : DECL_ATTRIBUTES (SYMBOL_REF_DECL (x))))))
11320 : 1763399571 : || (SYMBOL_REF_FUNCTION_P (x)
11321 : 664164597 : && (!flag_plt
11322 : 664160278 : || (SYMBOL_REF_DECL (x)
11323 : 664160278 : && lookup_attribute ("noplt",
11324 : 664160278 : DECL_ATTRIBUTES (SYMBOL_REF_DECL (x)))))))
11325 : 1785878551 : && !SYMBOL_REF_LOCAL_P (x));
11326 : : }
11327 : :
11328 : : /* Determine if a given RTX is a valid constant. We already know this
11329 : : satisfies CONSTANT_P. */
11330 : :
11331 : : static bool
11332 : 1516683658 : ix86_legitimate_constant_p (machine_mode mode, rtx x)
11333 : : {
11334 : 1516683658 : switch (GET_CODE (x))
11335 : : {
11336 : 129850505 : case CONST:
11337 : 129850505 : x = XEXP (x, 0);
11338 : :
11339 : 129850505 : if (GET_CODE (x) == PLUS)
11340 : : {
11341 : 129737849 : if (!CONST_INT_P (XEXP (x, 1)))
11342 : : return false;
11343 : 129737849 : x = XEXP (x, 0);
11344 : : }
11345 : :
11346 : 129850505 : if (TARGET_MACHO && darwin_local_data_pic (x))
11347 : : return true;
11348 : :
11349 : : /* Only some unspecs are valid as "constants". */
11350 : 129850505 : if (GET_CODE (x) == UNSPEC)
11351 : 474062 : switch (XINT (x, 1))
11352 : : {
11353 : 20558 : case UNSPEC_GOT:
11354 : 20558 : case UNSPEC_GOTOFF:
11355 : 20558 : case UNSPEC_PLTOFF:
11356 : 20558 : return TARGET_64BIT;
11357 : 452670 : case UNSPEC_TPOFF:
11358 : 452670 : case UNSPEC_NTPOFF:
11359 : 452670 : x = XVECEXP (x, 0, 0);
11360 : 452670 : return (GET_CODE (x) == SYMBOL_REF
11361 : 452670 : && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
11362 : 748 : case UNSPEC_DTPOFF:
11363 : 748 : x = XVECEXP (x, 0, 0);
11364 : 748 : return (GET_CODE (x) == SYMBOL_REF
11365 : 748 : && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
11366 : 0 : case UNSPEC_SECREL32:
11367 : 0 : x = XVECEXP (x, 0, 0);
11368 : 0 : return GET_CODE (x) == SYMBOL_REF;
11369 : : default:
11370 : : return false;
11371 : : }
11372 : :
11373 : : /* We must have drilled down to a symbol. */
11374 : 129376443 : if (GET_CODE (x) == LABEL_REF)
11375 : : return true;
11376 : 129372619 : if (GET_CODE (x) != SYMBOL_REF)
11377 : : return false;
11378 : : /* FALLTHRU */
11379 : :
11380 : 895235068 : case SYMBOL_REF:
11381 : : /* TLS symbols are never valid. */
11382 : 895235068 : if (SYMBOL_REF_TLS_MODEL (x))
11383 : : return false;
11384 : :
11385 : : /* DLLIMPORT symbols are never valid. */
11386 : 895141748 : if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11387 : : && SYMBOL_REF_DLLIMPORT_P (x))
11388 : : return false;
11389 : :
11390 : : #if TARGET_MACHO
11391 : : /* mdynamic-no-pic */
11392 : : if (MACHO_DYNAMIC_NO_PIC_P)
11393 : : return machopic_symbol_defined_p (x);
11394 : : #endif
11395 : :
11396 : : /* External function address should be loaded
11397 : : via the GOT slot to avoid PLT. */
11398 : 895141748 : if (ix86_force_load_from_GOT_p (x))
11399 : : return false;
11400 : :
11401 : : break;
11402 : :
11403 : 600973470 : CASE_CONST_SCALAR_INT:
11404 : 600973470 : if (ix86_endbr_immediate_operand (x, VOIDmode))
11405 : : return false;
11406 : :
11407 : 600973267 : switch (mode)
11408 : : {
11409 : 1535851 : case E_TImode:
11410 : 1535851 : if (TARGET_64BIT)
11411 : : return true;
11412 : : /* FALLTHRU */
11413 : 22644 : case E_OImode:
11414 : 22644 : case E_XImode:
11415 : 22644 : if (!standard_sse_constant_p (x, mode)
11416 : 35753 : && GET_MODE_SIZE (TARGET_AVX512F && TARGET_EVEX512
11417 : : ? XImode
11418 : : : (TARGET_AVX
11419 : : ? OImode
11420 : : : (TARGET_SSE2
11421 : 13109 : ? TImode : DImode))) < GET_MODE_SIZE (mode))
11422 : : return false;
11423 : : default:
11424 : : break;
11425 : : }
11426 : : break;
11427 : :
11428 : 7907347 : case CONST_VECTOR:
11429 : 7907347 : if (!standard_sse_constant_p (x, mode))
11430 : : return false;
11431 : : break;
11432 : :
11433 : 7656276 : case CONST_DOUBLE:
11434 : 7656276 : if (mode == E_BFmode)
11435 : : return false;
11436 : :
11437 : : default:
11438 : : break;
11439 : : }
11440 : :
11441 : : /* Otherwise we handle everything else in the move patterns. */
11442 : : return true;
11443 : : }
11444 : :
11445 : : /* Determine if it's legal to put X into the constant pool. This
11446 : : is not possible for the address of thread-local symbols, which
11447 : : is checked above. */
11448 : :
11449 : : static bool
11450 : 61142314 : ix86_cannot_force_const_mem (machine_mode mode, rtx x)
11451 : : {
11452 : : /* We can put any immediate constant in memory. */
11453 : 61142314 : switch (GET_CODE (x))
11454 : : {
11455 : : CASE_CONST_ANY:
11456 : : return false;
11457 : :
11458 : 1786650 : default:
11459 : 1786650 : break;
11460 : : }
11461 : :
11462 : 1786650 : return !ix86_legitimate_constant_p (mode, x);
11463 : : }
11464 : :
11465 : : /* Return a unique alias set for the GOT. */
11466 : :
11467 : : alias_set_type
11468 : 183805 : ix86_GOT_alias_set (void)
11469 : : {
11470 : 183805 : static alias_set_type set = -1;
11471 : 183805 : if (set == -1)
11472 : 2798 : set = new_alias_set ();
11473 : 183805 : return set;
11474 : : }
11475 : :
11476 : : /* Nonzero if the constant value X is a legitimate general operand
11477 : : when generating PIC code. It is given that flag_pic is on and
11478 : : that X satisfies CONSTANT_P. */
11479 : :
11480 : : bool
11481 : 122493722 : legitimate_pic_operand_p (rtx x)
11482 : : {
11483 : 122493722 : rtx inner;
11484 : :
11485 : 122493722 : switch (GET_CODE (x))
11486 : : {
11487 : 2458858 : case CONST:
11488 : 2458858 : inner = XEXP (x, 0);
11489 : 2458858 : if (GET_CODE (inner) == PLUS
11490 : 346249 : && CONST_INT_P (XEXP (inner, 1)))
11491 : 346249 : inner = XEXP (inner, 0);
11492 : :
11493 : : /* Only some unspecs are valid as "constants". */
11494 : 2458858 : if (GET_CODE (inner) == UNSPEC)
11495 : 2216734 : switch (XINT (inner, 1))
11496 : : {
11497 : 2156818 : case UNSPEC_GOT:
11498 : 2156818 : case UNSPEC_GOTOFF:
11499 : 2156818 : case UNSPEC_PLTOFF:
11500 : 2156818 : return TARGET_64BIT;
11501 : 0 : case UNSPEC_TPOFF:
11502 : 0 : x = XVECEXP (inner, 0, 0);
11503 : 0 : return (GET_CODE (x) == SYMBOL_REF
11504 : 0 : && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
11505 : 0 : case UNSPEC_SECREL32:
11506 : 0 : x = XVECEXP (inner, 0, 0);
11507 : 0 : return GET_CODE (x) == SYMBOL_REF;
11508 : 0 : case UNSPEC_MACHOPIC_OFFSET:
11509 : 0 : return legitimate_pic_address_disp_p (x);
11510 : : default:
11511 : : return false;
11512 : : }
11513 : : /* FALLTHRU */
11514 : :
11515 : 6673240 : case SYMBOL_REF:
11516 : 6673240 : case LABEL_REF:
11517 : 6673240 : return legitimate_pic_address_disp_p (x);
11518 : :
11519 : : default:
11520 : : return true;
11521 : : }
11522 : : }
11523 : :
11524 : : /* Determine if a given CONST RTX is a valid memory displacement
11525 : : in PIC mode. */
11526 : :
11527 : : bool
11528 : 61831317 : legitimate_pic_address_disp_p (rtx disp)
11529 : : {
11530 : 61831317 : bool saw_plus;
11531 : :
11532 : : /* In 64bit mode we can allow direct addresses of symbols and labels
11533 : : when they are not dynamic symbols. */
11534 : 61831317 : if (TARGET_64BIT)
11535 : : {
11536 : 37666062 : rtx op0 = disp, op1;
11537 : :
11538 : 37666062 : switch (GET_CODE (disp))
11539 : : {
11540 : : case LABEL_REF:
11541 : : return true;
11542 : :
11543 : 10479118 : case CONST:
11544 : 10479118 : if (GET_CODE (XEXP (disp, 0)) != PLUS)
11545 : : break;
11546 : 1108053 : op0 = XEXP (XEXP (disp, 0), 0);
11547 : 1108053 : op1 = XEXP (XEXP (disp, 0), 1);
11548 : 1108053 : if (!CONST_INT_P (op1))
11549 : : break;
11550 : 1108053 : if (GET_CODE (op0) == UNSPEC
11551 : 293 : && (XINT (op0, 1) == UNSPEC_DTPOFF
11552 : 293 : || XINT (op0, 1) == UNSPEC_NTPOFF)
11553 : 1108346 : && trunc_int_for_mode (INTVAL (op1), SImode) == INTVAL (op1))
11554 : : return true;
11555 : 1107760 : if (INTVAL (op1) >= 16*1024*1024
11556 : 1107760 : || INTVAL (op1) < -16*1024*1024)
11557 : : break;
11558 : 1107672 : if (GET_CODE (op0) == LABEL_REF)
11559 : : return true;
11560 : 1107672 : if (GET_CODE (op0) == CONST
11561 : 0 : && GET_CODE (XEXP (op0, 0)) == UNSPEC
11562 : 0 : && XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL)
11563 : : return true;
11564 : 1107672 : if (GET_CODE (op0) == UNSPEC
11565 : 0 : && XINT (op0, 1) == UNSPEC_PCREL)
11566 : : return true;
11567 : 1107672 : if (GET_CODE (op0) != SYMBOL_REF)
11568 : : break;
11569 : : /* FALLTHRU */
11570 : :
11571 : 28081528 : case SYMBOL_REF:
11572 : : /* TLS references should always be enclosed in UNSPEC.
11573 : : The dllimported symbol needs always to be resolved. */
11574 : 28081528 : if (SYMBOL_REF_TLS_MODEL (op0)
11575 : : || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0)))
11576 : : return false;
11577 : :
11578 : 27931066 : if (TARGET_PECOFF)
11579 : : {
11580 : : #if TARGET_PECOFF
11581 : : if (is_imported_p (op0))
11582 : : return true;
11583 : : #endif
11584 : :
11585 : : if (SYMBOL_REF_FAR_ADDR_P (op0) || !SYMBOL_REF_LOCAL_P (op0))
11586 : : break;
11587 : :
11588 : : /* Non-external-weak function symbols need to be resolved only
11589 : : for the large model. Non-external symbols don't need to be
11590 : : resolved for large and medium models. For the small model,
11591 : : we don't need to resolve anything here. */
11592 : : if ((ix86_cmodel != CM_LARGE_PIC
11593 : : && SYMBOL_REF_FUNCTION_P (op0)
11594 : : && !(SYMBOL_REF_EXTERNAL_P (op0) && SYMBOL_REF_WEAK (op0)))
11595 : : || !SYMBOL_REF_EXTERNAL_P (op0)
11596 : : || ix86_cmodel == CM_SMALL_PIC)
11597 : : return true;
11598 : : }
11599 : 27931066 : else if (!SYMBOL_REF_FAR_ADDR_P (op0)
11600 : 27931062 : && (SYMBOL_REF_LOCAL_P (op0)
11601 : 16882329 : || ((ix86_direct_extern_access
11602 : 33553008 : && !(SYMBOL_REF_DECL (op0)
11603 : 16670838 : && lookup_attribute ("nodirect_extern_access",
11604 : 16670838 : DECL_ATTRIBUTES (SYMBOL_REF_DECL (op0)))))
11605 : : && HAVE_LD_PIE_COPYRELOC
11606 : 16882011 : && flag_pie
11607 : 36752 : && !SYMBOL_REF_WEAK (op0)
11608 : 36364 : && !SYMBOL_REF_FUNCTION_P (op0)))
11609 : 38987513 : && ix86_cmodel != CM_LARGE_PIC)
11610 : : return true;
11611 : : break;
11612 : :
11613 : : default:
11614 : : break;
11615 : : }
11616 : : }
11617 : 50414742 : if (GET_CODE (disp) != CONST)
11618 : : return false;
11619 : 14542181 : disp = XEXP (disp, 0);
11620 : :
11621 : 14542181 : if (TARGET_64BIT)
11622 : : {
11623 : : /* We are unsafe to allow PLUS expressions. This limit allowed distance
11624 : : of GOT tables. We should not need these anyway. */
11625 : 9419861 : if (GET_CODE (disp) != UNSPEC
11626 : 9371065 : || (XINT (disp, 1) != UNSPEC_GOTPCREL
11627 : 9371065 : && XINT (disp, 1) != UNSPEC_GOTOFF
11628 : : && XINT (disp, 1) != UNSPEC_PCREL
11629 : : && XINT (disp, 1) != UNSPEC_PLTOFF))
11630 : : return false;
11631 : :
11632 : 9371065 : if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
11633 : 9371065 : && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
11634 : : return false;
11635 : : return true;
11636 : : }
11637 : :
11638 : 5122320 : saw_plus = false;
11639 : 5122320 : if (GET_CODE (disp) == PLUS)
11640 : : {
11641 : 572621 : if (!CONST_INT_P (XEXP (disp, 1)))
11642 : : return false;
11643 : 572621 : disp = XEXP (disp, 0);
11644 : 572621 : saw_plus = true;
11645 : : }
11646 : :
11647 : 5122320 : if (TARGET_MACHO && darwin_local_data_pic (disp))
11648 : : return true;
11649 : :
11650 : 5122320 : if (GET_CODE (disp) != UNSPEC)
11651 : : return false;
11652 : :
11653 : 4960354 : switch (XINT (disp, 1))
11654 : : {
11655 : 2267914 : case UNSPEC_GOT:
11656 : 2267914 : if (saw_plus)
11657 : : return false;
11658 : : /* We need to check for both symbols and labels because VxWorks loads
11659 : : text labels with @GOT rather than @GOTOFF. See gotoff_operand for
11660 : : details. */
11661 : 2267914 : return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
11662 : 2267914 : || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
11663 : 2692440 : case UNSPEC_GOTOFF:
11664 : : /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
11665 : : While ABI specify also 32bit relocation but we don't produce it in
11666 : : small PIC model at all. */
11667 : 2692440 : if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
11668 : 2692440 : || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
11669 : : && !TARGET_64BIT)
11670 : 2692440 : return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
11671 : : return false;
11672 : 0 : case UNSPEC_GOTTPOFF:
11673 : 0 : case UNSPEC_GOTNTPOFF:
11674 : 0 : case UNSPEC_INDNTPOFF:
11675 : 0 : if (saw_plus)
11676 : : return false;
11677 : 0 : disp = XVECEXP (disp, 0, 0);
11678 : 0 : return (GET_CODE (disp) == SYMBOL_REF
11679 : 0 : && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
11680 : 0 : case UNSPEC_NTPOFF:
11681 : 0 : disp = XVECEXP (disp, 0, 0);
11682 : 0 : return (GET_CODE (disp) == SYMBOL_REF
11683 : 0 : && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
11684 : 0 : case UNSPEC_DTPOFF:
11685 : 0 : disp = XVECEXP (disp, 0, 0);
11686 : 0 : return (GET_CODE (disp) == SYMBOL_REF
11687 : 0 : && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
11688 : 0 : case UNSPEC_SECREL32:
11689 : 0 : disp = XVECEXP (disp, 0, 0);
11690 : 0 : return GET_CODE (disp) == SYMBOL_REF;
11691 : : }
11692 : :
11693 : : return false;
11694 : : }
11695 : :
11696 : : /* Determine if op is suitable RTX for an address register.
11697 : : Return naked register if a register or a register subreg is
11698 : : found, otherwise return NULL_RTX. */
11699 : :
11700 : : static rtx
11701 : 1291251535 : ix86_validate_address_register (rtx op)
11702 : : {
11703 : 1291251535 : machine_mode mode = GET_MODE (op);
11704 : :
11705 : : /* Only SImode or DImode registers can form the address. */
11706 : 1291251535 : if (mode != SImode && mode != DImode)
11707 : : return NULL_RTX;
11708 : :
11709 : 1291244185 : if (REG_P (op))
11710 : : return op;
11711 : 750487 : else if (SUBREG_P (op))
11712 : : {
11713 : 750487 : rtx reg = SUBREG_REG (op);
11714 : :
11715 : 750487 : if (!REG_P (reg))
11716 : : return NULL_RTX;
11717 : :
11718 : 750487 : mode = GET_MODE (reg);
11719 : :
11720 : : /* Don't allow SUBREGs that span more than a word. It can
11721 : : lead to spill failures when the register is one word out
11722 : : of a two word structure. */
11723 : 1545804 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
11724 : : return NULL_RTX;
11725 : :
11726 : : /* Allow only SUBREGs of non-eliminable hard registers. */
11727 : 229551 : if (register_no_elim_operand (reg, mode))
11728 : : return reg;
11729 : : }
11730 : :
11731 : : /* Op is not a register. */
11732 : : return NULL_RTX;
11733 : : }
11734 : :
11735 : : /* Determine which memory address register set insn can use. */
11736 : :
11737 : : static enum attr_addr
11738 : 244325267 : ix86_memory_address_reg_class (rtx_insn* insn)
11739 : : {
11740 : : /* LRA can do some initialization with NULL insn,
11741 : : return maximum register class in this case. */
11742 : 244325267 : enum attr_addr addr_rclass = ADDR_GPR32;
11743 : :
11744 : 244325267 : if (!insn)
11745 : : return addr_rclass;
11746 : :
11747 : 70202927 : if (asm_noperands (PATTERN (insn)) >= 0
11748 : 70202927 : || GET_CODE (PATTERN (insn)) == ASM_INPUT)
11749 : 59678 : return ix86_apx_inline_asm_use_gpr32 ? ADDR_GPR32 : ADDR_GPR16;
11750 : :
11751 : : /* Return maximum register class for unrecognized instructions. */
11752 : 70173088 : if (INSN_CODE (insn) < 0)
11753 : : return addr_rclass;
11754 : :
11755 : : /* Try to recognize the insn before calling get_attr_addr.
11756 : : Save current recog_data and current alternative. */
11757 : 70173088 : struct recog_data_d saved_recog_data = recog_data;
11758 : 70173088 : int saved_alternative = which_alternative;
11759 : :
11760 : : /* Update recog_data for processing of alternatives. */
11761 : 70173088 : extract_insn_cached (insn);
11762 : :
11763 : : /* If current alternative is not set, loop throught enabled
11764 : : alternatives and get the most limited register class. */
11765 : 70173088 : if (saved_alternative == -1)
11766 : : {
11767 : 70173088 : alternative_mask enabled = get_enabled_alternatives (insn);
11768 : :
11769 : 1213696593 : for (int i = 0; i < recog_data.n_alternatives; i++)
11770 : : {
11771 : 1143523505 : if (!TEST_BIT (enabled, i))
11772 : 338299658 : continue;
11773 : :
11774 : 805223847 : which_alternative = i;
11775 : 805223847 : addr_rclass = MIN (addr_rclass, get_attr_addr (insn));
11776 : : }
11777 : : }
11778 : : else
11779 : : {
11780 : 0 : which_alternative = saved_alternative;
11781 : 0 : addr_rclass = get_attr_addr (insn);
11782 : : }
11783 : :
11784 : 70173088 : recog_data = saved_recog_data;
11785 : 70173088 : which_alternative = saved_alternative;
11786 : :
11787 : 70173088 : return addr_rclass;
11788 : : }
11789 : :
11790 : : /* Return memory address register class insn can use. */
11791 : :
11792 : : enum reg_class
11793 : 205196616 : ix86_insn_base_reg_class (rtx_insn* insn)
11794 : : {
11795 : 205196616 : switch (ix86_memory_address_reg_class (insn))
11796 : : {
11797 : : case ADDR_GPR8:
11798 : : return LEGACY_GENERAL_REGS;
11799 : : case ADDR_GPR16:
11800 : : return GENERAL_GPR16;
11801 : : case ADDR_GPR32:
11802 : : break;
11803 : 0 : default:
11804 : 0 : gcc_unreachable ();
11805 : : }
11806 : :
11807 : : return BASE_REG_CLASS;
11808 : : }
11809 : :
11810 : : bool
11811 : 1007629 : ix86_regno_ok_for_insn_base_p (int regno, rtx_insn* insn)
11812 : : {
11813 : 1007629 : switch (ix86_memory_address_reg_class (insn))
11814 : : {
11815 : 0 : case ADDR_GPR8:
11816 : 0 : return LEGACY_INT_REGNO_P (regno);
11817 : 0 : case ADDR_GPR16:
11818 : 0 : return GENERAL_GPR16_REGNO_P (regno);
11819 : 1007629 : case ADDR_GPR32:
11820 : 1007629 : break;
11821 : 0 : default:
11822 : 0 : gcc_unreachable ();
11823 : : }
11824 : :
11825 : 1007629 : return GENERAL_REGNO_P (regno);
11826 : : }
11827 : :
11828 : : enum reg_class
11829 : 38121022 : ix86_insn_index_reg_class (rtx_insn* insn)
11830 : : {
11831 : 38121022 : switch (ix86_memory_address_reg_class (insn))
11832 : : {
11833 : : case ADDR_GPR8:
11834 : : return LEGACY_INDEX_REGS;
11835 : : case ADDR_GPR16:
11836 : : return INDEX_GPR16;
11837 : : case ADDR_GPR32:
11838 : : break;
11839 : 0 : default:
11840 : 0 : gcc_unreachable ();
11841 : : }
11842 : :
11843 : : return INDEX_REG_CLASS;
11844 : : }
11845 : :
11846 : : /* Recognizes RTL expressions that are valid memory addresses for an
11847 : : instruction. The MODE argument is the machine mode for the MEM
11848 : : expression that wants to use this address.
11849 : :
11850 : : It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should
11851 : : convert common non-canonical forms to canonical form so that they will
11852 : : be recognized. */
11853 : :
11854 : : static bool
11855 : 2144720285 : ix86_legitimate_address_p (machine_mode, rtx addr, bool strict,
11856 : : code_helper = ERROR_MARK)
11857 : : {
11858 : 2144720285 : struct ix86_address parts;
11859 : 2144720285 : rtx base, index, disp;
11860 : 2144720285 : HOST_WIDE_INT scale;
11861 : 2144720285 : addr_space_t seg;
11862 : :
11863 : 2144720285 : if (ix86_decompose_address (addr, &parts) == 0)
11864 : : /* Decomposition failed. */
11865 : : return false;
11866 : :
11867 : 2133501180 : base = parts.base;
11868 : 2133501180 : index = parts.index;
11869 : 2133501180 : disp = parts.disp;
11870 : 2133501180 : scale = parts.scale;
11871 : 2133501180 : seg = parts.seg;
11872 : :
11873 : : /* Validate base register. */
11874 : 2133501180 : if (base)
11875 : : {
11876 : 1215029737 : rtx reg = ix86_validate_address_register (base);
11877 : :
11878 : 1215029737 : if (reg == NULL_RTX)
11879 : : return false;
11880 : :
11881 : 1214553230 : unsigned int regno = REGNO (reg);
11882 : 1214553230 : if ((strict && !REGNO_OK_FOR_BASE_P (regno))
11883 : 1210219941 : || (!strict && !REGNO_OK_FOR_BASE_NONSTRICT_P (regno)))
11884 : : /* Base is not valid. */
11885 : : return false;
11886 : : }
11887 : :
11888 : : /* Validate index register. */
11889 : 2131702356 : if (index)
11890 : : {
11891 : 76221798 : rtx reg = ix86_validate_address_register (index);
11892 : :
11893 : 76221798 : if (reg == NULL_RTX)
11894 : : return false;
11895 : :
11896 : 76169839 : unsigned int regno = REGNO (reg);
11897 : 76169839 : if ((strict && !REGNO_OK_FOR_INDEX_P (regno))
11898 : 76162874 : || (!strict && !REGNO_OK_FOR_INDEX_NONSTRICT_P (regno)))
11899 : : /* Index is not valid. */
11900 : : return false;
11901 : : }
11902 : :
11903 : : /* Index and base should have the same mode. */
11904 : 2131649282 : if (base && index
11905 : 66833445 : && GET_MODE (base) != GET_MODE (index))
11906 : : return false;
11907 : :
11908 : : /* Address override works only on the (%reg) part of %fs:(%reg). */
11909 : 2131554087 : if (seg != ADDR_SPACE_GENERIC
11910 : 2131554087 : && ((base && GET_MODE (base) != word_mode)
11911 : 302657 : || (index && GET_MODE (index) != word_mode)))
11912 : : return false;
11913 : :
11914 : : /* Validate scale factor. */
11915 : 2131554058 : if (scale != 1)
11916 : : {
11917 : 38426446 : if (!index)
11918 : : /* Scale without index. */
11919 : : return false;
11920 : :
11921 : 38426446 : if (scale != 2 && scale != 4 && scale != 8)
11922 : : /* Scale is not a valid multiplier. */
11923 : : return false;
11924 : : }
11925 : :
11926 : : /* Validate displacement. */
11927 : 2128624028 : if (disp)
11928 : : {
11929 : 1912835591 : if (ix86_endbr_immediate_operand (disp, VOIDmode))
11930 : : return false;
11931 : :
11932 : 1912835548 : if (GET_CODE (disp) == CONST
11933 : 139749045 : && GET_CODE (XEXP (disp, 0)) == UNSPEC
11934 : 14852234 : && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
11935 : 14852234 : switch (XINT (XEXP (disp, 0), 1))
11936 : : {
11937 : : /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit
11938 : : when used. While ABI specify also 32bit relocations, we
11939 : : don't produce them at all and use IP relative instead.
11940 : : Allow GOT in 32bit mode for both PIC and non-PIC if symbol
11941 : : should be loaded via GOT. */
11942 : 2267965 : case UNSPEC_GOT:
11943 : 2267965 : if (!TARGET_64BIT
11944 : 2267965 : && ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
11945 : 0 : goto is_legitimate_pic;
11946 : : /* FALLTHRU */
11947 : 4549801 : case UNSPEC_GOTOFF:
11948 : 4549801 : gcc_assert (flag_pic);
11949 : 4549801 : if (!TARGET_64BIT)
11950 : 4549699 : goto is_legitimate_pic;
11951 : :
11952 : : /* 64bit address unspec. */
11953 : : return false;
11954 : :
11955 : 9371037 : case UNSPEC_GOTPCREL:
11956 : 9371037 : if (ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
11957 : 2484 : goto is_legitimate_pic;
11958 : : /* FALLTHRU */
11959 : 9368553 : case UNSPEC_PCREL:
11960 : 9368553 : gcc_assert (flag_pic);
11961 : 9368553 : goto is_legitimate_pic;
11962 : :
11963 : : case UNSPEC_GOTTPOFF:
11964 : : case UNSPEC_GOTNTPOFF:
11965 : : case UNSPEC_INDNTPOFF:
11966 : : case UNSPEC_NTPOFF:
11967 : : case UNSPEC_DTPOFF:
11968 : : case UNSPEC_SECREL32:
11969 : : break;
11970 : :
11971 : : default:
11972 : : /* Invalid address unspec. */
11973 : : return false;
11974 : : }
11975 : :
11976 : 1196070434 : else if (SYMBOLIC_CONST (disp)
11977 : 2022880125 : && (flag_pic
11978 : : #if TARGET_MACHO
11979 : : || (MACHOPIC_INDIRECT
11980 : : && !machopic_operand_p (disp))
11981 : : #endif
11982 : : ))
11983 : : {
11984 : :
11985 : 55000065 : is_legitimate_pic:
11986 : 55000065 : if (TARGET_64BIT && (index || base))
11987 : : {
11988 : : /* foo@dtpoff(%rX) is ok. */
11989 : 35659 : if (GET_CODE (disp) != CONST
11990 : 6754 : || GET_CODE (XEXP (disp, 0)) != PLUS
11991 : 6754 : || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
11992 : 4439 : || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
11993 : 4439 : || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
11994 : 4439 : && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF
11995 : 0 : && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_SECREL32))
11996 : : /* Non-constant pic memory reference. */
11997 : : return false;
11998 : : }
11999 : 54964406 : else if ((!TARGET_MACHO || flag_pic)
12000 : 54964406 : && ! legitimate_pic_address_disp_p (disp))
12001 : : /* Displacement is an invalid pic construct. */
12002 : : return false;
12003 : : #if TARGET_MACHO
12004 : : else if (MACHO_DYNAMIC_NO_PIC_P
12005 : : && !ix86_legitimate_constant_p (Pmode, disp))
12006 : : /* displacment must be referenced via non_lazy_pointer */
12007 : : return false;
12008 : : #endif
12009 : :
12010 : : /* This code used to verify that a symbolic pic displacement
12011 : : includes the pic_offset_table_rtx register.
12012 : :
12013 : : While this is good idea, unfortunately these constructs may
12014 : : be created by "adds using lea" optimization for incorrect
12015 : : code like:
12016 : :
12017 : : int a;
12018 : : int foo(int i)
12019 : : {
12020 : : return *(&a+i);
12021 : : }
12022 : :
12023 : : This code is nonsensical, but results in addressing
12024 : : GOT table with pic_offset_table_rtx base. We can't
12025 : : just refuse it easily, since it gets matched by
12026 : : "addsi3" pattern, that later gets split to lea in the
12027 : : case output register differs from input. While this
12028 : : can be handled by separate addsi pattern for this case
12029 : : that never results in lea, this seems to be easier and
12030 : : correct fix for crash to disable this test. */
12031 : : }
12032 : 1856903985 : else if (GET_CODE (disp) != LABEL_REF
12033 : 1856714822 : && !CONST_INT_P (disp)
12034 : 843555879 : && (GET_CODE (disp) != CONST
12035 : 123459433 : || !ix86_legitimate_constant_p (Pmode, disp))
12036 : 2577010931 : && (GET_CODE (disp) != SYMBOL_REF
12037 : 662081766 : || !ix86_legitimate_constant_p (Pmode, disp)))
12038 : : /* Displacement is not constant. */
12039 : 58083337 : return false;
12040 : 1798820648 : else if (TARGET_64BIT
12041 : 1798820648 : && !x86_64_immediate_operand (disp, VOIDmode))
12042 : : /* Displacement is out of range. */
12043 : : return false;
12044 : : /* In x32 mode, constant addresses are sign extended to 64bit, so
12045 : : we have to prevent addresses from 0x80000000 to 0xffffffff. */
12046 : 28897 : else if (TARGET_X32 && !(index || base)
12047 : 15519 : && CONST_INT_P (disp)
12048 : 1798354046 : && val_signbit_known_set_p (SImode, INTVAL (disp)))
12049 : : return false;
12050 : : }
12051 : :
12052 : : /* Everything looks valid. */
12053 : : return true;
12054 : : }
12055 : :
12056 : : /* Determine if a given RTX is a valid constant address. */
12057 : :
12058 : : bool
12059 : 2589272486 : constant_address_p (rtx x)
12060 : : {
12061 : 2589272486 : return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
12062 : : }
12063 : :
12064 : :
12065 : : /* Return a legitimate reference for ORIG (an address) using the
12066 : : register REG. If REG is 0, a new pseudo is generated.
12067 : :
12068 : : There are two types of references that must be handled:
12069 : :
12070 : : 1. Global data references must load the address from the GOT, via
12071 : : the PIC reg. An insn is emitted to do this load, and the reg is
12072 : : returned.
12073 : :
12074 : : 2. Static data references, constant pool addresses, and code labels
12075 : : compute the address as an offset from the GOT, whose base is in
12076 : : the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
12077 : : differentiate them from global data objects. The returned
12078 : : address is the PIC reg + an unspec constant.
12079 : :
12080 : : TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
12081 : : reg also appears in the address. */
12082 : :
12083 : : rtx
12084 : 392185 : legitimize_pic_address (rtx orig, rtx reg)
12085 : : {
12086 : 392185 : rtx addr = orig;
12087 : 392185 : rtx new_rtx = orig;
12088 : :
12089 : : #if TARGET_MACHO
12090 : : if (TARGET_MACHO && !TARGET_64BIT)
12091 : : {
12092 : : if (reg == 0)
12093 : : reg = gen_reg_rtx (Pmode);
12094 : : /* Use the generic Mach-O PIC machinery. */
12095 : : return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
12096 : : }
12097 : : #endif
12098 : :
12099 : 392185 : if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES)
12100 : : {
12101 : : #if TARGET_PECOFF
12102 : : rtx tmp = legitimize_pe_coff_symbol (addr, true);
12103 : : if (tmp)
12104 : : return tmp;
12105 : : #endif
12106 : : }
12107 : :
12108 : 392185 : if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
12109 : : new_rtx = addr;
12110 : 297935 : else if ((!TARGET_64BIT
12111 : 99421 : || /* TARGET_64BIT && */ ix86_cmodel != CM_SMALL_PIC)
12112 : : && !TARGET_PECOFF
12113 : 298014 : && gotoff_operand (addr, Pmode))
12114 : : {
12115 : : /* This symbol may be referenced via a displacement
12116 : : from the PIC base address (@GOTOFF). */
12117 : 96813 : if (GET_CODE (addr) == CONST)
12118 : 2973 : addr = XEXP (addr, 0);
12119 : :
12120 : 96813 : if (GET_CODE (addr) == PLUS)
12121 : : {
12122 : 2973 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
12123 : : UNSPEC_GOTOFF);
12124 : 2973 : new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
12125 : : }
12126 : : else
12127 : 93840 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
12128 : :
12129 : 96813 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12130 : :
12131 : 96813 : if (TARGET_64BIT)
12132 : 12 : new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
12133 : :
12134 : 96813 : if (reg != 0)
12135 : : {
12136 : 3 : gcc_assert (REG_P (reg));
12137 : 3 : new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx,
12138 : : new_rtx, reg, 1, OPTAB_DIRECT);
12139 : : }
12140 : : else
12141 : 96810 : new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
12142 : : }
12143 : 375358 : else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
12144 : : /* We can't always use @GOTOFF for text labels
12145 : : on VxWorks, see gotoff_operand. */
12146 : 201122 : || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
12147 : : {
12148 : : #if TARGET_PECOFF
12149 : : rtx tmp = legitimize_pe_coff_symbol (addr, true);
12150 : : if (tmp)
12151 : : return tmp;
12152 : : #endif
12153 : :
12154 : : /* For x64 PE-COFF there is no GOT table,
12155 : : so we use address directly. */
12156 : 174233 : if (TARGET_64BIT && TARGET_PECOFF)
12157 : : {
12158 : : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
12159 : : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12160 : : }
12161 : 174233 : else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
12162 : : {
12163 : 92248 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
12164 : : UNSPEC_GOTPCREL);
12165 : 92248 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12166 : 92248 : new_rtx = gen_const_mem (Pmode, new_rtx);
12167 : 92248 : set_mem_alias_set (new_rtx, GOT_ALIAS_SET);
12168 : : }
12169 : : else
12170 : : {
12171 : : /* This symbol must be referenced via a load
12172 : : from the Global Offset Table (@GOT). */
12173 : 81985 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
12174 : 81985 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12175 : :
12176 : 81985 : if (TARGET_64BIT)
12177 : 22 : new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
12178 : :
12179 : 81985 : if (reg != 0)
12180 : : {
12181 : 0 : gcc_assert (REG_P (reg));
12182 : 0 : new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx,
12183 : : new_rtx, reg, 1, OPTAB_DIRECT);
12184 : : }
12185 : : else
12186 : 81985 : new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
12187 : :
12188 : 81985 : new_rtx = gen_const_mem (Pmode, new_rtx);
12189 : 81985 : set_mem_alias_set (new_rtx, GOT_ALIAS_SET);
12190 : : }
12191 : :
12192 : 174233 : new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
12193 : : }
12194 : : else
12195 : : {
12196 : 26889 : if (CONST_INT_P (addr)
12197 : 26889 : && !x86_64_immediate_operand (addr, VOIDmode))
12198 : 8 : new_rtx = copy_to_suggested_reg (addr, reg, Pmode);
12199 : 26881 : else if (GET_CODE (addr) == CONST)
12200 : : {
12201 : 16589 : addr = XEXP (addr, 0);
12202 : :
12203 : : /* We must match stuff we generate before. Assume the only
12204 : : unspecs that can get here are ours. Not that we could do
12205 : : anything with them anyway.... */
12206 : 16589 : if (GET_CODE (addr) == UNSPEC
12207 : 8890 : || (GET_CODE (addr) == PLUS
12208 : 8890 : && GET_CODE (XEXP (addr, 0)) == UNSPEC))
12209 : : return orig;
12210 : 6765 : gcc_assert (GET_CODE (addr) == PLUS);
12211 : : }
12212 : :
12213 : 17065 : if (GET_CODE (addr) == PLUS)
12214 : : {
12215 : 8533 : rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
12216 : :
12217 : : /* Check first to see if this is a constant
12218 : : offset from a @GOTOFF symbol reference. */
12219 : 8533 : if (!TARGET_PECOFF
12220 : 8533 : && gotoff_operand (op0, Pmode)
12221 : 8533 : && CONST_INT_P (op1))
12222 : : {
12223 : 4 : if (!TARGET_64BIT)
12224 : : {
12225 : 0 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
12226 : : UNSPEC_GOTOFF);
12227 : 0 : new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
12228 : 0 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12229 : :
12230 : 0 : if (reg != 0)
12231 : : {
12232 : 0 : gcc_assert (REG_P (reg));
12233 : 0 : new_rtx = expand_simple_binop (Pmode, PLUS,
12234 : : pic_offset_table_rtx,
12235 : : new_rtx, reg, 1,
12236 : : OPTAB_DIRECT);
12237 : : }
12238 : : else
12239 : 0 : new_rtx
12240 : 0 : = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
12241 : : }
12242 : : else
12243 : : {
12244 : 4 : if (INTVAL (op1) < -16*1024*1024
12245 : 4 : || INTVAL (op1) >= 16*1024*1024)
12246 : : {
12247 : 4 : if (!x86_64_immediate_operand (op1, Pmode))
12248 : 4 : op1 = force_reg (Pmode, op1);
12249 : :
12250 : 4 : new_rtx
12251 : 4 : = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
12252 : : }
12253 : : }
12254 : : }
12255 : : else
12256 : : {
12257 : 8529 : rtx base = legitimize_pic_address (op0, reg);
12258 : 8529 : machine_mode mode = GET_MODE (base);
12259 : 8529 : new_rtx
12260 : 8529 : = legitimize_pic_address (op1, base == reg ? NULL_RTX : reg);
12261 : :
12262 : 8529 : if (CONST_INT_P (new_rtx))
12263 : : {
12264 : 6753 : if (INTVAL (new_rtx) < -16*1024*1024
12265 : 6753 : || INTVAL (new_rtx) >= 16*1024*1024)
12266 : : {
12267 : 0 : if (!x86_64_immediate_operand (new_rtx, mode))
12268 : 0 : new_rtx = force_reg (mode, new_rtx);
12269 : :
12270 : 0 : new_rtx
12271 : 0 : = gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx);
12272 : : }
12273 : : else
12274 : 6753 : new_rtx = plus_constant (mode, base, INTVAL (new_rtx));
12275 : : }
12276 : : else
12277 : : {
12278 : : /* For %rip addressing, we have to use
12279 : : just disp32, not base nor index. */
12280 : 1776 : if (TARGET_64BIT
12281 : 99 : && (GET_CODE (base) == SYMBOL_REF
12282 : 99 : || GET_CODE (base) == LABEL_REF))
12283 : 7 : base = force_reg (mode, base);
12284 : 1776 : if (GET_CODE (new_rtx) == PLUS
12285 : 1655 : && CONSTANT_P (XEXP (new_rtx, 1)))
12286 : : {
12287 : 1651 : base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0));
12288 : 1651 : new_rtx = XEXP (new_rtx, 1);
12289 : : }
12290 : 1776 : new_rtx = gen_rtx_PLUS (mode, base, new_rtx);
12291 : : }
12292 : : }
12293 : : }
12294 : : }
12295 : : return new_rtx;
12296 : : }
12297 : :
12298 : : /* Load the thread pointer. If TO_REG is true, force it into a register. */
12299 : :
12300 : : static rtx
12301 : 22309 : get_thread_pointer (machine_mode tp_mode, bool to_reg)
12302 : : {
12303 : 22309 : rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
12304 : :
12305 : 22309 : if (GET_MODE (tp) != tp_mode)
12306 : : {
12307 : 11 : gcc_assert (GET_MODE (tp) == SImode);
12308 : 11 : gcc_assert (tp_mode == DImode);
12309 : :
12310 : 11 : tp = gen_rtx_ZERO_EXTEND (tp_mode, tp);
12311 : : }
12312 : :
12313 : 22309 : if (to_reg)
12314 : 7723 : tp = copy_to_mode_reg (tp_mode, tp);
12315 : :
12316 : 22309 : return tp;
12317 : : }
12318 : :
12319 : : /* Construct the SYMBOL_REF for the _tls_index symbol. */
12320 : :
12321 : : static GTY(()) rtx ix86_tls_index_symbol;
12322 : :
12323 : : #if TARGET_WIN32_TLS
12324 : : static rtx
12325 : : ix86_tls_index (void)
12326 : : {
12327 : : if (!ix86_tls_index_symbol)
12328 : : ix86_tls_index_symbol = gen_rtx_SYMBOL_REF (SImode, "_tls_index");
12329 : :
12330 : : if (flag_pic)
12331 : : return gen_rtx_CONST (Pmode, gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_index_symbol), UNSPEC_PCREL));
12332 : : else
12333 : : return ix86_tls_index_symbol;
12334 : : }
12335 : : #endif
12336 : :
12337 : : /* Construct the SYMBOL_REF for the tls_get_addr function. */
12338 : :
12339 : : static GTY(()) rtx ix86_tls_symbol;
12340 : :
12341 : : static rtx
12342 : 6679 : ix86_tls_get_addr (void)
12343 : : {
12344 : 6679 : if (!ix86_tls_symbol)
12345 : : {
12346 : 674 : const char *sym
12347 : 337 : = ((TARGET_ANY_GNU_TLS && !TARGET_64BIT)
12348 : 337 : ? "___tls_get_addr" : "__tls_get_addr");
12349 : :
12350 : 337 : ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym);
12351 : : }
12352 : :
12353 : 6679 : if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF)
12354 : : {
12355 : 0 : rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol),
12356 : : UNSPEC_PLTOFF);
12357 : 0 : return gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
12358 : : gen_rtx_CONST (Pmode, unspec));
12359 : : }
12360 : :
12361 : 6679 : return ix86_tls_symbol;
12362 : : }
12363 : :
12364 : : /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol. */
12365 : :
12366 : : static GTY(()) rtx ix86_tls_module_base_symbol;
12367 : :
12368 : : rtx
12369 : 18 : ix86_tls_module_base (void)
12370 : : {
12371 : 18 : if (!ix86_tls_module_base_symbol)
12372 : : {
12373 : 3 : ix86_tls_module_base_symbol
12374 : 3 : = gen_rtx_SYMBOL_REF (ptr_mode, "_TLS_MODULE_BASE_");
12375 : :
12376 : 3 : SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
12377 : 3 : |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
12378 : : }
12379 : :
12380 : 18 : return ix86_tls_module_base_symbol;
12381 : : }
12382 : :
12383 : : /* A subroutine of ix86_legitimize_address and ix86_expand_move. FOR_MOV is
12384 : : false if we expect this to be used for a memory address and true if
12385 : : we expect to load the address into a register. */
12386 : :
12387 : : rtx
12388 : 28988 : legitimize_tls_address (rtx x, enum tls_model model, bool for_mov)
12389 : : {
12390 : 28988 : rtx dest, base, off;
12391 : 28988 : rtx pic = NULL_RTX, tp = NULL_RTX;
12392 : 28988 : machine_mode tp_mode = Pmode;
12393 : 28988 : int type;
12394 : :
12395 : : #if TARGET_WIN32_TLS
12396 : : off = gen_const_mem (SImode, ix86_tls_index ());
12397 : : set_mem_alias_set (off, GOT_ALIAS_SET);
12398 : :
12399 : : tp = gen_const_mem (Pmode, GEN_INT (TARGET_64BIT ? 88 : 44));
12400 : : set_mem_addr_space (tp, DEFAULT_TLS_SEG_REG);
12401 : :
12402 : : if (TARGET_64BIT)
12403 : : off = convert_to_mode (Pmode, off, 1);
12404 : :
12405 : : base = force_reg (Pmode, off);
12406 : : tp = copy_to_mode_reg (Pmode, tp);
12407 : :
12408 : : tp = gen_const_mem (Pmode, gen_rtx_PLUS (Pmode, tp, gen_rtx_MULT (Pmode, base, GEN_INT (UNITS_PER_WORD))));
12409 : : set_mem_alias_set (tp, GOT_ALIAS_SET);
12410 : :
12411 : : base = force_reg (Pmode, tp);
12412 : :
12413 : : return gen_rtx_PLUS (Pmode, base, gen_rtx_CONST (Pmode, gen_rtx_UNSPEC (SImode, gen_rtvec (1, x), UNSPEC_SECREL32)));
12414 : : #else
12415 : : /* Fall back to global dynamic model if tool chain cannot support local
12416 : : dynamic. */
12417 : 28988 : if (TARGET_SUN_TLS && !TARGET_64BIT
12418 : : && !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM
12419 : : && model == TLS_MODEL_LOCAL_DYNAMIC)
12420 : : model = TLS_MODEL_GLOBAL_DYNAMIC;
12421 : :
12422 : 28988 : switch (model)
12423 : : {
12424 : 6261 : case TLS_MODEL_GLOBAL_DYNAMIC:
12425 : 6261 : if (!TARGET_64BIT)
12426 : : {
12427 : 1976 : if (flag_pic && !TARGET_PECOFF)
12428 : 1976 : pic = pic_offset_table_rtx;
12429 : : else
12430 : : {
12431 : 0 : pic = gen_reg_rtx (Pmode);
12432 : 0 : emit_insn (gen_set_got (pic));
12433 : : }
12434 : : }
12435 : :
12436 : 6261 : if (TARGET_GNU2_TLS)
12437 : : {
12438 : 14 : dest = gen_reg_rtx (ptr_mode);
12439 : 14 : if (TARGET_64BIT)
12440 : 14 : emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, dest, x));
12441 : : else
12442 : 0 : emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic));
12443 : :
12444 : 14 : tp = get_thread_pointer (ptr_mode, true);
12445 : 14 : dest = gen_rtx_PLUS (ptr_mode, tp, dest);
12446 : 14 : if (GET_MODE (dest) != Pmode)
12447 : 6 : dest = gen_rtx_ZERO_EXTEND (Pmode, dest);
12448 : 14 : dest = force_reg (Pmode, dest);
12449 : :
12450 : 14 : if (GET_MODE (x) != Pmode)
12451 : 3 : x = gen_rtx_ZERO_EXTEND (Pmode, x);
12452 : :
12453 : 14 : set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
12454 : : }
12455 : : else
12456 : : {
12457 : 6247 : rtx caddr = ix86_tls_get_addr ();
12458 : :
12459 : 6247 : dest = gen_reg_rtx (Pmode);
12460 : 6247 : if (TARGET_64BIT)
12461 : : {
12462 : 4271 : rtx rax = gen_rtx_REG (Pmode, AX_REG);
12463 : 4271 : rtx_insn *insns;
12464 : :
12465 : 4271 : start_sequence ();
12466 : 4271 : emit_call_insn
12467 : 4271 : (gen_tls_global_dynamic_64 (Pmode, rax, x, caddr));
12468 : 4271 : insns = get_insns ();
12469 : 4271 : end_sequence ();
12470 : :
12471 : 4271 : if (GET_MODE (x) != Pmode)
12472 : 1 : x = gen_rtx_ZERO_EXTEND (Pmode, x);
12473 : :
12474 : 4271 : RTL_CONST_CALL_P (insns) = 1;
12475 : 4271 : emit_libcall_block (insns, dest, rax, x);
12476 : : }
12477 : : else
12478 : 1976 : emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr));
12479 : : }
12480 : : break;
12481 : :
12482 : 440 : case TLS_MODEL_LOCAL_DYNAMIC:
12483 : 440 : if (!TARGET_64BIT)
12484 : : {
12485 : 110 : if (flag_pic)
12486 : 110 : pic = pic_offset_table_rtx;
12487 : : else
12488 : : {
12489 : 0 : pic = gen_reg_rtx (Pmode);
12490 : 0 : emit_insn (gen_set_got (pic));
12491 : : }
12492 : : }
12493 : :
12494 : 440 : if (TARGET_GNU2_TLS)
12495 : : {
12496 : 8 : rtx tmp = ix86_tls_module_base ();
12497 : :
12498 : 8 : base = gen_reg_rtx (ptr_mode);
12499 : 8 : if (TARGET_64BIT)
12500 : 8 : emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, base, tmp));
12501 : : else
12502 : 0 : emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic));
12503 : :
12504 : 8 : tp = get_thread_pointer (ptr_mode, true);
12505 : 8 : if (GET_MODE (base) != Pmode)
12506 : 2 : base = gen_rtx_ZERO_EXTEND (Pmode, base);
12507 : 8 : base = force_reg (Pmode, base);
12508 : : }
12509 : : else
12510 : : {
12511 : 432 : rtx caddr = ix86_tls_get_addr ();
12512 : :
12513 : 432 : base = gen_reg_rtx (Pmode);
12514 : 432 : if (TARGET_64BIT)
12515 : : {
12516 : 322 : rtx rax = gen_rtx_REG (Pmode, AX_REG);
12517 : 322 : rtx_insn *insns;
12518 : 322 : rtx eqv;
12519 : :
12520 : 322 : start_sequence ();
12521 : 322 : emit_call_insn
12522 : 322 : (gen_tls_local_dynamic_base_64 (Pmode, rax, caddr));
12523 : 322 : insns = get_insns ();
12524 : 322 : end_sequence ();
12525 : :
12526 : : /* Attach a unique REG_EQUAL, to allow the RTL optimizers to
12527 : : share the LD_BASE result with other LD model accesses. */
12528 : 322 : eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12529 : : UNSPEC_TLS_LD_BASE);
12530 : :
12531 : 322 : RTL_CONST_CALL_P (insns) = 1;
12532 : 322 : emit_libcall_block (insns, base, rax, eqv);
12533 : : }
12534 : : else
12535 : 110 : emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr));
12536 : : }
12537 : :
12538 : 440 : off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
12539 : 440 : off = gen_rtx_CONST (Pmode, off);
12540 : :
12541 : 440 : dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
12542 : :
12543 : 440 : if (TARGET_GNU2_TLS)
12544 : : {
12545 : 8 : if (GET_MODE (tp) != Pmode)
12546 : : {
12547 : 2 : dest = lowpart_subreg (ptr_mode, dest, Pmode);
12548 : 2 : dest = gen_rtx_PLUS (ptr_mode, tp, dest);
12549 : 2 : dest = gen_rtx_ZERO_EXTEND (Pmode, dest);
12550 : : }
12551 : : else
12552 : 6 : dest = gen_rtx_PLUS (Pmode, tp, dest);
12553 : 8 : dest = force_reg (Pmode, dest);
12554 : :
12555 : 8 : if (GET_MODE (x) != Pmode)
12556 : 1 : x = gen_rtx_ZERO_EXTEND (Pmode, x);
12557 : :
12558 : 8 : set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
12559 : : }
12560 : : break;
12561 : :
12562 : 9552 : case TLS_MODEL_INITIAL_EXEC:
12563 : 9552 : if (TARGET_64BIT)
12564 : : {
12565 : : /* Generate DImode references to avoid %fs:(%reg32)
12566 : : problems and linker IE->LE relaxation bug. */
12567 : : tp_mode = DImode;
12568 : : pic = NULL;
12569 : : type = UNSPEC_GOTNTPOFF;
12570 : : }
12571 : 731 : else if (flag_pic)
12572 : : {
12573 : 730 : pic = pic_offset_table_rtx;
12574 : 730 : type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
12575 : : }
12576 : 1 : else if (!TARGET_ANY_GNU_TLS)
12577 : : {
12578 : 0 : pic = gen_reg_rtx (Pmode);
12579 : 0 : emit_insn (gen_set_got (pic));
12580 : 0 : type = UNSPEC_GOTTPOFF;
12581 : : }
12582 : : else
12583 : : {
12584 : : pic = NULL;
12585 : : type = UNSPEC_INDNTPOFF;
12586 : : }
12587 : :
12588 : 9552 : off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type);
12589 : 9552 : off = gen_rtx_CONST (tp_mode, off);
12590 : 9552 : if (pic)
12591 : 730 : off = gen_rtx_PLUS (tp_mode, pic, off);
12592 : 9552 : off = gen_const_mem (tp_mode, off);
12593 : 9552 : set_mem_alias_set (off, GOT_ALIAS_SET);
12594 : :
12595 : 9552 : if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
12596 : : {
12597 : 9552 : base = get_thread_pointer (tp_mode,
12598 : 9552 : for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
12599 : 9552 : off = force_reg (tp_mode, off);
12600 : 9552 : dest = gen_rtx_PLUS (tp_mode, base, off);
12601 : 9552 : if (tp_mode != Pmode)
12602 : 4 : dest = convert_to_mode (Pmode, dest, 1);
12603 : : }
12604 : : else
12605 : : {
12606 : 0 : base = get_thread_pointer (Pmode, true);
12607 : 0 : dest = gen_reg_rtx (Pmode);
12608 : 0 : emit_insn (gen_sub3_insn (dest, base, off));
12609 : : }
12610 : : break;
12611 : :
12612 : 12735 : case TLS_MODEL_LOCAL_EXEC:
12613 : 25470 : off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
12614 : : (TARGET_64BIT || TARGET_ANY_GNU_TLS)
12615 : : ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
12616 : 12735 : off = gen_rtx_CONST (Pmode, off);
12617 : :
12618 : 12735 : if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
12619 : : {
12620 : 12735 : base = get_thread_pointer (Pmode,
12621 : 12735 : for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
12622 : 12735 : return gen_rtx_PLUS (Pmode, base, off);
12623 : : }
12624 : : else
12625 : : {
12626 : 0 : base = get_thread_pointer (Pmode, true);
12627 : 0 : dest = gen_reg_rtx (Pmode);
12628 : 0 : emit_insn (gen_sub3_insn (dest, base, off));
12629 : : }
12630 : 0 : break;
12631 : :
12632 : 0 : default:
12633 : 0 : gcc_unreachable ();
12634 : : }
12635 : :
12636 : : return dest;
12637 : : #endif
12638 : : }
12639 : :
12640 : : /* Return true if the TLS address requires insn using integer registers.
12641 : : It's used to prevent KMOV/VMOV in TLS code sequences which require integer
12642 : : MOV instructions, refer to PR103275. */
12643 : : bool
12644 : 16064092 : ix86_gpr_tls_address_pattern_p (rtx mem)
12645 : : {
12646 : 16064092 : gcc_assert (MEM_P (mem));
12647 : :
12648 : 16064092 : rtx addr = XEXP (mem, 0);
12649 : 16064092 : subrtx_var_iterator::array_type array;
12650 : 55965906 : FOR_EACH_SUBRTX_VAR (iter, array, addr, ALL)
12651 : : {
12652 : 39908682 : rtx op = *iter;
12653 : 39908682 : if (GET_CODE (op) == UNSPEC)
12654 : 203277 : switch (XINT (op, 1))
12655 : : {
12656 : : case UNSPEC_GOTNTPOFF:
12657 : 6868 : return true;
12658 : 0 : case UNSPEC_TPOFF:
12659 : 0 : if (!TARGET_64BIT)
12660 : : return true;
12661 : : break;
12662 : : default:
12663 : : break;
12664 : : }
12665 : : }
12666 : :
12667 : 16057224 : return false;
12668 : 16064092 : }
12669 : :
12670 : : /* Return true if OP refers to a TLS address. */
12671 : : bool
12672 : 228468650 : ix86_tls_address_pattern_p (rtx op)
12673 : : {
12674 : 228468650 : subrtx_var_iterator::array_type array;
12675 : 1358405765 : FOR_EACH_SUBRTX_VAR (iter, array, op, ALL)
12676 : : {
12677 : 1129953267 : rtx op = *iter;
12678 : 1129953267 : if (MEM_P (op))
12679 : : {
12680 : 101544359 : rtx *x = &XEXP (op, 0);
12681 : 159570060 : while (GET_CODE (*x) == PLUS)
12682 : : {
12683 : : int i;
12684 : 174093278 : for (i = 0; i < 2; i++)
12685 : : {
12686 : 116067577 : rtx u = XEXP (*x, i);
12687 : 116067577 : if (GET_CODE (u) == ZERO_EXTEND)
12688 : 102047 : u = XEXP (u, 0);
12689 : 116067577 : if (GET_CODE (u) == UNSPEC
12690 : 16174 : && XINT (u, 1) == UNSPEC_TP)
12691 : 16152 : return true;
12692 : : }
12693 : 58025701 : x = &XEXP (*x, 0);
12694 : : }
12695 : :
12696 : 101528207 : iter.skip_subrtxes ();
12697 : : }
12698 : : }
12699 : :
12700 : 228452498 : return false;
12701 : 228468650 : }
12702 : :
12703 : : /* Rewrite *LOC so that it refers to a default TLS address space. */
12704 : : static void
12705 : 16152 : ix86_rewrite_tls_address_1 (rtx *loc)
12706 : : {
12707 : 16152 : subrtx_ptr_iterator::array_type array;
12708 : 48684 : FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
12709 : : {
12710 : 48684 : rtx *loc = *iter;
12711 : 48684 : if (MEM_P (*loc))
12712 : : {
12713 : 16339 : rtx addr = XEXP (*loc, 0);
12714 : 16339 : rtx *x = &addr;
12715 : 21071 : while (GET_CODE (*x) == PLUS)
12716 : : {
12717 : : int i;
12718 : 30371 : for (i = 0; i < 2; i++)
12719 : : {
12720 : 25639 : rtx u = XEXP (*x, i);
12721 : 25639 : if (GET_CODE (u) == ZERO_EXTEND)
12722 : 19 : u = XEXP (u, 0);
12723 : 25639 : if (GET_CODE (u) == UNSPEC
12724 : 16152 : && XINT (u, 1) == UNSPEC_TP)
12725 : : {
12726 : : /* NB: Since address override only applies to the
12727 : : (reg32) part in fs:(reg32), return if address
12728 : : override is used. */
12729 : 16152 : if (Pmode != word_mode
12730 : 16152 : && REG_P (XEXP (*x, 1 - i)))
12731 : 16152 : return;
12732 : :
12733 : 16150 : addr_space_t as = DEFAULT_TLS_SEG_REG;
12734 : :
12735 : 16150 : *x = XEXP (*x, 1 - i);
12736 : :
12737 : 16150 : *loc = replace_equiv_address_nv (*loc, addr, true);
12738 : 16150 : set_mem_addr_space (*loc, as);
12739 : 16150 : return;
12740 : : }
12741 : : }
12742 : 4732 : x = &XEXP (*x, 0);
12743 : : }
12744 : :
12745 : 187 : iter.skip_subrtxes ();
12746 : : }
12747 : : }
12748 : 16152 : }
12749 : :
12750 : : /* Rewrite instruction pattern involvning TLS address
12751 : : so that it refers to a default TLS address space. */
12752 : : rtx
12753 : 16152 : ix86_rewrite_tls_address (rtx pattern)
12754 : : {
12755 : 16152 : pattern = copy_insn (pattern);
12756 : 16152 : ix86_rewrite_tls_address_1 (&pattern);
12757 : 16152 : return pattern;
12758 : : }
12759 : :
12760 : : /* Try machine-dependent ways of modifying an illegitimate address
12761 : : to be legitimate. If we find one, return the new, valid address.
12762 : : This macro is used in only one place: `memory_address' in explow.cc.
12763 : :
12764 : : OLDX is the address as it was before break_out_memory_refs was called.
12765 : : In some cases it is useful to look at this to decide what needs to be done.
12766 : :
12767 : : It is always safe for this macro to do nothing. It exists to recognize
12768 : : opportunities to optimize the output.
12769 : :
12770 : : For the 80386, we handle X+REG by loading X into a register R and
12771 : : using R+REG. R will go in a general reg and indexing will be used.
12772 : : However, if REG is a broken-out memory address or multiplication,
12773 : : nothing needs to be done because REG can certainly go in a general reg.
12774 : :
12775 : : When -fpic is used, special handling is needed for symbolic references.
12776 : : See comments by legitimize_pic_address in i386.cc for details. */
12777 : :
12778 : : static rtx
12779 : 590413 : ix86_legitimize_address (rtx x, rtx, machine_mode mode)
12780 : : {
12781 : 590413 : bool changed = false;
12782 : 590413 : unsigned log;
12783 : :
12784 : 590413 : log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
12785 : 150374 : if (log)
12786 : 19208 : return legitimize_tls_address (x, (enum tls_model) log, false);
12787 : 571205 : if (GET_CODE (x) == CONST
12788 : 515 : && GET_CODE (XEXP (x, 0)) == PLUS
12789 : 515 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
12790 : 571720 : && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
12791 : : {
12792 : 4 : rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
12793 : : (enum tls_model) log, false);
12794 : 4 : return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
12795 : : }
12796 : :
12797 : 571201 : if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
12798 : : {
12799 : : #if TARGET_PECOFF
12800 : : rtx tmp = legitimize_pe_coff_symbol (x, true);
12801 : : if (tmp)
12802 : : return tmp;
12803 : : #endif
12804 : : }
12805 : :
12806 : 571201 : if (flag_pic && SYMBOLIC_CONST (x))
12807 : 131550 : return legitimize_pic_address (x, 0);
12808 : :
12809 : : #if TARGET_MACHO
12810 : : if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x))
12811 : : return machopic_indirect_data_reference (x, 0);
12812 : : #endif
12813 : :
12814 : : /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
12815 : 439651 : if (GET_CODE (x) == ASHIFT
12816 : 0 : && CONST_INT_P (XEXP (x, 1))
12817 : 0 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
12818 : : {
12819 : 0 : changed = true;
12820 : 0 : log = INTVAL (XEXP (x, 1));
12821 : 0 : x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
12822 : : GEN_INT (1 << log));
12823 : : }
12824 : :
12825 : 439651 : if (GET_CODE (x) == PLUS)
12826 : : {
12827 : : /* Canonicalize shifts by 0, 1, 2, 3 into multiply. */
12828 : :
12829 : 116650 : if (GET_CODE (XEXP (x, 0)) == ASHIFT
12830 : 531 : && CONST_INT_P (XEXP (XEXP (x, 0), 1))
12831 : 531 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
12832 : : {
12833 : 531 : changed = true;
12834 : 531 : log = INTVAL (XEXP (XEXP (x, 0), 1));
12835 : 531 : XEXP (x, 0) = gen_rtx_MULT (Pmode,
12836 : : force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
12837 : : GEN_INT (1 << log));
12838 : : }
12839 : :
12840 : 116650 : if (GET_CODE (XEXP (x, 1)) == ASHIFT
12841 : 0 : && CONST_INT_P (XEXP (XEXP (x, 1), 1))
12842 : 0 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
12843 : : {
12844 : 0 : changed = true;
12845 : 0 : log = INTVAL (XEXP (XEXP (x, 1), 1));
12846 : 0 : XEXP (x, 1) = gen_rtx_MULT (Pmode,
12847 : : force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
12848 : : GEN_INT (1 << log));
12849 : : }
12850 : :
12851 : : /* Put multiply first if it isn't already. */
12852 : 116650 : if (GET_CODE (XEXP (x, 1)) == MULT)
12853 : : {
12854 : 0 : std::swap (XEXP (x, 0), XEXP (x, 1));
12855 : 0 : changed = true;
12856 : : }
12857 : :
12858 : : /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
12859 : : into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be
12860 : : created by virtual register instantiation, register elimination, and
12861 : : similar optimizations. */
12862 : 116650 : if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
12863 : : {
12864 : 9191 : changed = true;
12865 : 9191 : x = gen_rtx_PLUS (Pmode,
12866 : : gen_rtx_PLUS (Pmode, XEXP (x, 0),
12867 : : XEXP (XEXP (x, 1), 0)),
12868 : : XEXP (XEXP (x, 1), 1));
12869 : : }
12870 : :
12871 : : /* Canonicalize
12872 : : (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
12873 : : into (plus (plus (mult (reg) (const)) (reg)) (const)). */
12874 : 107459 : else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
12875 : 70899 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
12876 : 44230 : && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
12877 : 0 : && CONSTANT_P (XEXP (x, 1)))
12878 : : {
12879 : 0 : rtx constant;
12880 : 0 : rtx other = NULL_RTX;
12881 : :
12882 : 0 : if (CONST_INT_P (XEXP (x, 1)))
12883 : : {
12884 : 0 : constant = XEXP (x, 1);
12885 : 0 : other = XEXP (XEXP (XEXP (x, 0), 1), 1);
12886 : : }
12887 : 0 : else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
12888 : : {
12889 : : constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
12890 : : other = XEXP (x, 1);
12891 : : }
12892 : : else
12893 : : constant = 0;
12894 : :
12895 : 0 : if (constant)
12896 : : {
12897 : 0 : changed = true;
12898 : 0 : x = gen_rtx_PLUS (Pmode,
12899 : : gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
12900 : : XEXP (XEXP (XEXP (x, 0), 1), 0)),
12901 : : plus_constant (Pmode, other,
12902 : : INTVAL (constant)));
12903 : : }
12904 : : }
12905 : :
12906 : 116650 : if (changed && ix86_legitimate_address_p (mode, x, false))
12907 : 9226 : return x;
12908 : :
12909 : 107424 : if (GET_CODE (XEXP (x, 0)) == MULT)
12910 : : {
12911 : 18537 : changed = true;
12912 : 18537 : XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0));
12913 : : }
12914 : :
12915 : 107424 : if (GET_CODE (XEXP (x, 1)) == MULT)
12916 : : {
12917 : 0 : changed = true;
12918 : 0 : XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1));
12919 : : }
12920 : :
12921 : 107424 : if (changed
12922 : 18546 : && REG_P (XEXP (x, 1))
12923 : 15075 : && REG_P (XEXP (x, 0)))
12924 : : return x;
12925 : :
12926 : 92350 : if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
12927 : : {
12928 : 1768 : changed = true;
12929 : 1768 : x = legitimize_pic_address (x, 0);
12930 : : }
12931 : :
12932 : 92350 : if (changed && ix86_legitimate_address_p (mode, x, false))
12933 : 3738 : return x;
12934 : :
12935 : 88612 : if (REG_P (XEXP (x, 0)))
12936 : : {
12937 : 17254 : rtx temp = gen_reg_rtx (Pmode);
12938 : 17254 : rtx val = force_operand (XEXP (x, 1), temp);
12939 : 17254 : if (val != temp)
12940 : : {
12941 : 9390 : val = convert_to_mode (Pmode, val, 1);
12942 : 9390 : emit_move_insn (temp, val);
12943 : : }
12944 : :
12945 : 17254 : XEXP (x, 1) = temp;
12946 : 17254 : return x;
12947 : : }
12948 : :
12949 : 71358 : else if (REG_P (XEXP (x, 1)))
12950 : : {
12951 : 2715 : rtx temp = gen_reg_rtx (Pmode);
12952 : 2715 : rtx val = force_operand (XEXP (x, 0), temp);
12953 : 2715 : if (val != temp)
12954 : : {
12955 : 0 : val = convert_to_mode (Pmode, val, 1);
12956 : 0 : emit_move_insn (temp, val);
12957 : : }
12958 : :
12959 : 2715 : XEXP (x, 0) = temp;
12960 : 2715 : return x;
12961 : : }
12962 : : }
12963 : :
12964 : : return x;
12965 : : }
12966 : :
12967 : : /* Print an integer constant expression in assembler syntax. Addition
12968 : : and subtraction are the only arithmetic that may appear in these
12969 : : expressions. FILE is the stdio stream to write to, X is the rtx, and
12970 : : CODE is the operand print code from the output string. */
12971 : :
12972 : : static void
12973 : 3482968 : output_pic_addr_const (FILE *file, rtx x, int code)
12974 : : {
12975 : 3709778 : char buf[256];
12976 : :
12977 : 3709778 : switch (GET_CODE (x))
12978 : : {
12979 : 0 : case PC:
12980 : 0 : gcc_assert (flag_pic);
12981 : 0 : putc ('.', file);
12982 : 0 : break;
12983 : :
12984 : 842768 : case SYMBOL_REF:
12985 : 842768 : if (TARGET_64BIT || ! TARGET_MACHO_SYMBOL_STUBS)
12986 : 842768 : output_addr_const (file, x);
12987 : : else
12988 : : {
12989 : : const char *name = XSTR (x, 0);
12990 : :
12991 : : /* Mark the decl as referenced so that cgraph will
12992 : : output the function. */
12993 : : if (SYMBOL_REF_DECL (x))
12994 : : mark_decl_referenced (SYMBOL_REF_DECL (x));
12995 : :
12996 : : #if TARGET_MACHO
12997 : : if (MACHOPIC_INDIRECT
12998 : : && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
12999 : : name = machopic_indirection_name (x, /*stub_p=*/true);
13000 : : #endif
13001 : : assemble_name (file, name);
13002 : : }
13003 : 842768 : if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
13004 : 842768 : && code == 'P' && ix86_call_use_plt_p (x))
13005 : 380976 : fputs ("@PLT", file);
13006 : : break;
13007 : :
13008 : 2518 : case LABEL_REF:
13009 : 2518 : x = XEXP (x, 0);
13010 : : /* FALLTHRU */
13011 : 2518 : case CODE_LABEL:
13012 : 2518 : ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
13013 : 2518 : assemble_name (asm_out_file, buf);
13014 : 2518 : break;
13015 : :
13016 : 2438778 : CASE_CONST_SCALAR_INT:
13017 : 2438778 : output_addr_const (file, x);
13018 : 2438778 : break;
13019 : :
13020 : 208236 : case CONST:
13021 : : /* This used to output parentheses around the expression,
13022 : : but that does not work on the 386 (either ATT or BSD assembler). */
13023 : 208236 : output_pic_addr_const (file, XEXP (x, 0), code);
13024 : 208236 : break;
13025 : :
13026 : 0 : case CONST_DOUBLE:
13027 : : /* We can't handle floating point constants;
13028 : : TARGET_PRINT_OPERAND must handle them. */
13029 : 0 : output_operand_lossage ("floating constant misused");
13030 : 0 : break;
13031 : :
13032 : 18574 : case PLUS:
13033 : : /* Some assemblers need integer constants to appear first. */
13034 : 18574 : if (CONST_INT_P (XEXP (x, 0)))
13035 : : {
13036 : 0 : output_pic_addr_const (file, XEXP (x, 0), code);
13037 : 0 : putc ('+', file);
13038 : 0 : output_pic_addr_const (file, XEXP (x, 1), code);
13039 : : }
13040 : : else
13041 : : {
13042 : 18574 : gcc_assert (CONST_INT_P (XEXP (x, 1)));
13043 : 18574 : output_pic_addr_const (file, XEXP (x, 1), code);
13044 : 18574 : putc ('+', file);
13045 : 18574 : output_pic_addr_const (file, XEXP (x, 0), code);
13046 : : }
13047 : : break;
13048 : :
13049 : 0 : case MINUS:
13050 : 0 : if (!TARGET_MACHO)
13051 : 0 : putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
13052 : 0 : output_pic_addr_const (file, XEXP (x, 0), code);
13053 : 0 : putc ('-', file);
13054 : 0 : output_pic_addr_const (file, XEXP (x, 1), code);
13055 : 0 : if (!TARGET_MACHO)
13056 : 0 : putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
13057 : 0 : break;
13058 : :
13059 : 198904 : case UNSPEC:
13060 : 198904 : gcc_assert (XVECLEN (x, 0) == 1);
13061 : 198904 : output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
13062 : 198904 : switch (XINT (x, 1))
13063 : : {
13064 : 43125 : case UNSPEC_GOT:
13065 : 43125 : fputs ("@GOT", file);
13066 : 43125 : break;
13067 : 77917 : case UNSPEC_GOTOFF:
13068 : 77917 : fputs ("@GOTOFF", file);
13069 : 77917 : break;
13070 : 31 : case UNSPEC_PLTOFF:
13071 : 31 : fputs ("@PLTOFF", file);
13072 : 31 : break;
13073 : 0 : case UNSPEC_PCREL:
13074 : 0 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
13075 : : "(%rip)" : "[rip]", file);
13076 : 0 : break;
13077 : 73821 : case UNSPEC_GOTPCREL:
13078 : 73821 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
13079 : : "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
13080 : 73821 : break;
13081 : 0 : case UNSPEC_GOTTPOFF:
13082 : : /* FIXME: This might be @TPOFF in Sun ld too. */
13083 : 0 : fputs ("@gottpoff", file);
13084 : 0 : break;
13085 : 0 : case UNSPEC_TPOFF:
13086 : 0 : fputs ("@tpoff", file);
13087 : 0 : break;
13088 : 1353 : case UNSPEC_NTPOFF:
13089 : 1353 : if (TARGET_64BIT)
13090 : 1353 : fputs ("@tpoff", file);
13091 : : else
13092 : 0 : fputs ("@ntpoff", file);
13093 : : break;
13094 : 330 : case UNSPEC_DTPOFF:
13095 : 330 : fputs ("@dtpoff", file);
13096 : 330 : break;
13097 : 2327 : case UNSPEC_GOTNTPOFF:
13098 : 2327 : if (TARGET_64BIT)
13099 : 2079 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
13100 : : "@gottpoff(%rip)": "@gottpoff[rip]", file);
13101 : : else
13102 : 248 : fputs ("@gotntpoff", file);
13103 : : break;
13104 : 0 : case UNSPEC_INDNTPOFF:
13105 : 0 : fputs ("@indntpoff", file);
13106 : 0 : break;
13107 : 0 : case UNSPEC_SECREL32:
13108 : 0 : fputs ("@secrel32", file);
13109 : 0 : break;
13110 : : #if TARGET_MACHO
13111 : : case UNSPEC_MACHOPIC_OFFSET:
13112 : : putc ('-', file);
13113 : : machopic_output_function_base_name (file);
13114 : : break;
13115 : : #endif
13116 : 0 : default:
13117 : 0 : output_operand_lossage ("invalid UNSPEC as operand");
13118 : 0 : break;
13119 : : }
13120 : : break;
13121 : :
13122 : 0 : default:
13123 : 0 : output_operand_lossage ("invalid expression as operand");
13124 : : }
13125 : 3482968 : }
13126 : :
13127 : : /* This is called from dwarf2out.cc via TARGET_ASM_OUTPUT_DWARF_DTPREL.
13128 : : We need to emit DTP-relative relocations. */
13129 : :
13130 : : static void ATTRIBUTE_UNUSED
13131 : 693 : i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
13132 : : {
13133 : 693 : fputs (ASM_LONG, file);
13134 : 693 : output_addr_const (file, x);
13135 : : #if TARGET_WIN32_TLS
13136 : : fputs ("@secrel32", file);
13137 : : #else
13138 : 693 : fputs ("@dtpoff", file);
13139 : : #endif
13140 : 693 : switch (size)
13141 : : {
13142 : : case 4:
13143 : : break;
13144 : 533 : case 8:
13145 : 533 : fputs (", 0", file);
13146 : 533 : break;
13147 : 0 : default:
13148 : 0 : gcc_unreachable ();
13149 : : }
13150 : 693 : }
13151 : :
13152 : : /* Return true if X is a representation of the PIC register. This copes
13153 : : with calls from ix86_find_base_term, where the register might have
13154 : : been replaced by a cselib value. */
13155 : :
13156 : : static bool
13157 : 25489337 : ix86_pic_register_p (rtx x)
13158 : : {
13159 : 25489337 : if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
13160 : 758191 : return (pic_offset_table_rtx
13161 : 758191 : && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
13162 : 24731146 : else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT)
13163 : : return true;
13164 : 24729790 : else if (!REG_P (x))
13165 : : return false;
13166 : 24119511 : else if (pic_offset_table_rtx)
13167 : : {
13168 : 24106661 : if (REGNO (x) == REGNO (pic_offset_table_rtx))
13169 : : return true;
13170 : 386066 : if (HARD_REGISTER_P (x)
13171 : 365446 : && !HARD_REGISTER_P (pic_offset_table_rtx)
13172 : 751512 : && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
13173 : : return true;
13174 : : return false;
13175 : : }
13176 : : else
13177 : 12850 : return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
13178 : : }
13179 : :
13180 : : /* Helper function for ix86_delegitimize_address.
13181 : : Attempt to delegitimize TLS local-exec accesses. */
13182 : :
13183 : : static rtx
13184 : 3459274295 : ix86_delegitimize_tls_address (rtx orig_x)
13185 : : {
13186 : 3459274295 : rtx x = orig_x, unspec;
13187 : 3459274295 : struct ix86_address addr;
13188 : :
13189 : 3459274295 : if (!TARGET_TLS_DIRECT_SEG_REFS)
13190 : : return orig_x;
13191 : 3459274295 : if (MEM_P (x))
13192 : 42044827 : x = XEXP (x, 0);
13193 : 3459274295 : if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
13194 : : return orig_x;
13195 : 1663716140 : if (ix86_decompose_address (x, &addr) == 0
13196 : 1926189886 : || addr.seg != DEFAULT_TLS_SEG_REG
13197 : 245619 : || addr.disp == NULL_RTX
13198 : 1663914697 : || GET_CODE (addr.disp) != CONST)
13199 : : return orig_x;
13200 : 107257 : unspec = XEXP (addr.disp, 0);
13201 : 107257 : if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
13202 : 65449 : unspec = XEXP (unspec, 0);
13203 : 107257 : if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF)
13204 : : return orig_x;
13205 : 107204 : x = XVECEXP (unspec, 0, 0);
13206 : 107204 : gcc_assert (GET_CODE (x) == SYMBOL_REF);
13207 : 107204 : if (unspec != XEXP (addr.disp, 0))
13208 : 65449 : x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1));
13209 : 107204 : if (addr.index)
13210 : : {
13211 : 187 : rtx idx = addr.index;
13212 : 187 : if (addr.scale != 1)
13213 : 187 : idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
13214 : 187 : x = gen_rtx_PLUS (Pmode, idx, x);
13215 : : }
13216 : 107204 : if (addr.base)
13217 : 2 : x = gen_rtx_PLUS (Pmode, addr.base, x);
13218 : 107204 : if (MEM_P (orig_x))
13219 : 132 : x = replace_equiv_address_nv (orig_x, x);
13220 : : return x;
13221 : : }
13222 : :
13223 : : /* In the name of slightly smaller debug output, and to cater to
13224 : : general assembler lossage, recognize PIC+GOTOFF and turn it back
13225 : : into a direct symbol reference.
13226 : :
13227 : : On Darwin, this is necessary to avoid a crash, because Darwin
13228 : : has a different PIC label for each routine but the DWARF debugging
13229 : : information is not associated with any particular routine, so it's
13230 : : necessary to remove references to the PIC label from RTL stored by
13231 : : the DWARF output code.
13232 : :
13233 : : This helper is used in the normal ix86_delegitimize_address
13234 : : entrypoint (e.g. used in the target delegitimization hook) and
13235 : : in ix86_find_base_term. As compile time memory optimization, we
13236 : : avoid allocating rtxes that will not change anything on the outcome
13237 : : of the callers (find_base_value and find_base_term). */
13238 : :
13239 : : static inline rtx
13240 : 3482736520 : ix86_delegitimize_address_1 (rtx x, bool base_term_p)
13241 : : {
13242 : 3482736520 : rtx orig_x = delegitimize_mem_from_attrs (x);
13243 : : /* addend is NULL or some rtx if x is something+GOTOFF where
13244 : : something doesn't include the PIC register. */
13245 : 3482736520 : rtx addend = NULL_RTX;
13246 : : /* reg_addend is NULL or a multiple of some register. */
13247 : 3482736520 : rtx reg_addend = NULL_RTX;
13248 : : /* const_addend is NULL or a const_int. */
13249 : 3482736520 : rtx const_addend = NULL_RTX;
13250 : : /* This is the result, or NULL. */
13251 : 3482736520 : rtx result = NULL_RTX;
13252 : :
13253 : 3482736520 : x = orig_x;
13254 : :
13255 : 3482736520 : if (MEM_P (x))
13256 : 59921532 : x = XEXP (x, 0);
13257 : :
13258 : 3482736520 : if (TARGET_64BIT)
13259 : : {
13260 : 236226368 : if (GET_CODE (x) == CONST
13261 : 8172599 : && GET_CODE (XEXP (x, 0)) == PLUS
13262 : 6419643 : && GET_MODE (XEXP (x, 0)) == Pmode
13263 : 6419643 : && CONST_INT_P (XEXP (XEXP (x, 0), 1))
13264 : 6419643 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC
13265 : 236230905 : && XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL)
13266 : : {
13267 : : /* find_base_{value,term} only care about MEMs with arg_pointer_rtx
13268 : : base. A CONST can't be arg_pointer_rtx based. */
13269 : 0 : if (base_term_p && MEM_P (orig_x))
13270 : : return orig_x;
13271 : 0 : rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0);
13272 : 0 : x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2);
13273 : 0 : if (MEM_P (orig_x))
13274 : 0 : x = replace_equiv_address_nv (orig_x, x);
13275 : 0 : return x;
13276 : : }
13277 : :
13278 : 236226368 : if (GET_CODE (x) == CONST
13279 : 8172599 : && GET_CODE (XEXP (x, 0)) == UNSPEC
13280 : 1752956 : && (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL
13281 : 569722 : || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)
13282 : 1183234 : && (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL))
13283 : : {
13284 : 257549 : x = XVECEXP (XEXP (x, 0), 0, 0);
13285 : 257549 : if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x))
13286 : : {
13287 : 9 : x = lowpart_subreg (GET_MODE (orig_x), x, GET_MODE (x));
13288 : 9 : if (x == NULL_RTX)
13289 : : return orig_x;
13290 : : }
13291 : 257549 : return x;
13292 : : }
13293 : :
13294 : 235968819 : if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC)
13295 : 235967686 : return ix86_delegitimize_tls_address (orig_x);
13296 : :
13297 : : /* Fall thru into the code shared with -m32 for -mcmodel=large -fpic
13298 : : and -mcmodel=medium -fpic. */
13299 : : }
13300 : :
13301 : 3246511285 : if (GET_CODE (x) != PLUS
13302 : 1541041818 : || GET_CODE (XEXP (x, 1)) != CONST)
13303 : 3221575289 : return ix86_delegitimize_tls_address (orig_x);
13304 : :
13305 : 24935996 : if (ix86_pic_register_p (XEXP (x, 0)))
13306 : : /* %ebx + GOT/GOTOFF */
13307 : : ;
13308 : 1285168 : else if (GET_CODE (XEXP (x, 0)) == PLUS)
13309 : : {
13310 : : /* %ebx + %reg * scale + GOT/GOTOFF */
13311 : 478915 : reg_addend = XEXP (x, 0);
13312 : 478915 : if (ix86_pic_register_p (XEXP (reg_addend, 0)))
13313 : 404489 : reg_addend = XEXP (reg_addend, 1);
13314 : 74426 : else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
13315 : 43332 : reg_addend = XEXP (reg_addend, 0);
13316 : : else
13317 : : {
13318 : 31094 : reg_addend = NULL_RTX;
13319 : 31094 : addend = XEXP (x, 0);
13320 : : }
13321 : : }
13322 : : else
13323 : : addend = XEXP (x, 0);
13324 : :
13325 : 24935996 : x = XEXP (XEXP (x, 1), 0);
13326 : 24935996 : if (GET_CODE (x) == PLUS
13327 : 1447241 : && CONST_INT_P (XEXP (x, 1)))
13328 : : {
13329 : 1447241 : const_addend = XEXP (x, 1);
13330 : 1447241 : x = XEXP (x, 0);
13331 : : }
13332 : :
13333 : 24935996 : if (GET_CODE (x) == UNSPEC
13334 : 24259686 : && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend)
13335 : 6640530 : || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))
13336 : 1055010 : || (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC
13337 : 0 : && !MEM_P (orig_x) && !addend)))
13338 : 23204676 : result = XVECEXP (x, 0, 0);
13339 : :
13340 : 23204676 : if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x)
13341 : : && !MEM_P (orig_x))
13342 : : result = XVECEXP (x, 0, 0);
13343 : :
13344 : 23204676 : if (! result)
13345 : 1731320 : return ix86_delegitimize_tls_address (orig_x);
13346 : :
13347 : : /* For (PLUS something CONST_INT) both find_base_{value,term} just
13348 : : recurse on the first operand. */
13349 : 23204676 : if (const_addend && !base_term_p)
13350 : 114769 : result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
13351 : 23204676 : if (reg_addend)
13352 : 436684 : result = gen_rtx_PLUS (Pmode, reg_addend, result);
13353 : 23204676 : if (addend)
13354 : : {
13355 : : /* If the rest of original X doesn't involve the PIC register, add
13356 : : addend and subtract pic_offset_table_rtx. This can happen e.g.
13357 : : for code like:
13358 : : leal (%ebx, %ecx, 4), %ecx
13359 : : ...
13360 : : movl foo@GOTOFF(%ecx), %edx
13361 : : in which case we return (%ecx - %ebx) + foo
13362 : : or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
13363 : : and reload has completed. Don't do the latter for debug,
13364 : : as _GLOBAL_OFFSET_TABLE_ can't be expressed in the assembly. */
13365 : 133870 : if (pic_offset_table_rtx
13366 : 133870 : && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
13367 : 778 : result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
13368 : : pic_offset_table_rtx),
13369 : : result);
13370 : 133092 : else if (base_term_p
13371 : 127983 : && pic_offset_table_rtx
13372 : : && !TARGET_MACHO
13373 : : && !TARGET_VXWORKS_RTP)
13374 : : {
13375 : 127983 : rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
13376 : 127983 : tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
13377 : 127983 : result = gen_rtx_PLUS (Pmode, tmp, result);
13378 : 127983 : }
13379 : : else
13380 : : return orig_x;
13381 : : }
13382 : 23199567 : if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x))
13383 : : {
13384 : 0 : result = lowpart_subreg (GET_MODE (orig_x), result, Pmode);
13385 : 0 : if (result == NULL_RTX)
13386 : : return orig_x;
13387 : : }
13388 : : return result;
13389 : : }
13390 : :
13391 : : /* The normal instantiation of the above template. */
13392 : :
13393 : : static rtx
13394 : 305261641 : ix86_delegitimize_address (rtx x)
13395 : : {
13396 : 305261641 : return ix86_delegitimize_address_1 (x, false);
13397 : : }
13398 : :
13399 : : /* If X is a machine specific address (i.e. a symbol or label being
13400 : : referenced as a displacement from the GOT implemented using an
13401 : : UNSPEC), then return the base term. Otherwise return X. */
13402 : :
13403 : : rtx
13404 : 6425884046 : ix86_find_base_term (rtx x)
13405 : : {
13406 : 6425884046 : rtx term;
13407 : :
13408 : 6425884046 : if (TARGET_64BIT)
13409 : : {
13410 : 3248409167 : if (GET_CODE (x) != CONST)
13411 : : return x;
13412 : 37911794 : term = XEXP (x, 0);
13413 : 37911794 : if (GET_CODE (term) == PLUS
13414 : 37897347 : && CONST_INT_P (XEXP (term, 1)))
13415 : 37897347 : term = XEXP (term, 0);
13416 : 37911794 : if (GET_CODE (term) != UNSPEC
13417 : 39098 : || (XINT (term, 1) != UNSPEC_GOTPCREL
13418 : 39098 : && XINT (term, 1) != UNSPEC_PCREL))
13419 : : return x;
13420 : :
13421 : 0 : return XVECEXP (term, 0, 0);
13422 : : }
13423 : :
13424 : 3177474879 : return ix86_delegitimize_address_1 (x, true);
13425 : : }
13426 : :
13427 : : /* Return true if X shouldn't be emitted into the debug info.
13428 : : Disallow UNSPECs other than @gotoff - we can't emit _GLOBAL_OFFSET_TABLE_
13429 : : symbol easily into the .debug_info section, so we need not to
13430 : : delegitimize, but instead assemble as @gotoff.
13431 : : Disallow _GLOBAL_OFFSET_TABLE_ SYMBOL_REF - the assembler magically
13432 : : assembles that as _GLOBAL_OFFSET_TABLE_-. expression. */
13433 : :
13434 : : static bool
13435 : 1777265 : ix86_const_not_ok_for_debug_p (rtx x)
13436 : : {
13437 : 1777265 : if (GET_CODE (x) == UNSPEC && XINT (x, 1) != UNSPEC_GOTOFF)
13438 : : return true;
13439 : :
13440 : 1777243 : if (SYMBOL_REF_P (x) && strcmp (XSTR (x, 0), GOT_SYMBOL_NAME) == 0)
13441 : 0 : return true;
13442 : :
13443 : : return false;
13444 : : }
13445 : :
13446 : : static void
13447 : 6924251 : put_condition_code (enum rtx_code code, machine_mode mode, bool reverse,
13448 : : bool fp, FILE *file)
13449 : : {
13450 : 6924251 : const char *suffix;
13451 : :
13452 : 6924251 : if (mode == CCFPmode)
13453 : : {
13454 : 559607 : code = ix86_fp_compare_code_to_integer (code);
13455 : 559607 : mode = CCmode;
13456 : : }
13457 : 6924251 : if (reverse)
13458 : 194136 : code = reverse_condition (code);
13459 : :
13460 : 6924251 : switch (code)
13461 : : {
13462 : 2713403 : case EQ:
13463 : 2713403 : gcc_assert (mode != CCGZmode);
13464 : 2713403 : switch (mode)
13465 : : {
13466 : : case E_CCAmode:
13467 : : suffix = "a";
13468 : : break;
13469 : : case E_CCCmode:
13470 : 26745 : suffix = "c";
13471 : : break;
13472 : : case E_CCOmode:
13473 : 6924251 : suffix = "o";
13474 : : break;
13475 : : case E_CCPmode:
13476 : 232715 : suffix = "p";
13477 : : break;
13478 : : case E_CCSmode:
13479 : 116623 : suffix = "s";
13480 : : break;
13481 : 2693555 : default:
13482 : 2693555 : suffix = "e";
13483 : 2693555 : break;
13484 : : }
13485 : : break;
13486 : 2234465 : case NE:
13487 : 2234465 : gcc_assert (mode != CCGZmode);
13488 : 2234465 : switch (mode)
13489 : : {
13490 : : case E_CCAmode:
13491 : : suffix = "na";
13492 : : break;
13493 : : case E_CCCmode:
13494 : 13713 : suffix = "nc";
13495 : : break;
13496 : 10927 : case E_CCOmode:
13497 : 10927 : suffix = "no";
13498 : 10927 : break;
13499 : : case E_CCPmode:
13500 : 4385 : suffix = "np";
13501 : : break;
13502 : : case E_CCSmode:
13503 : 53177 : suffix = "ns";
13504 : : break;
13505 : 2222662 : default:
13506 : 2222662 : suffix = "ne";
13507 : 2222662 : break;
13508 : : }
13509 : : break;
13510 : 249293 : case GT:
13511 : 249293 : gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
13512 : : suffix = "g";
13513 : : break;
13514 : 163388 : case GTU:
13515 : : /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
13516 : : Those same assemblers have the same but opposite lossage on cmov. */
13517 : 163388 : if (mode == CCmode)
13518 : 163388 : suffix = fp ? "nbe" : "a";
13519 : : else
13520 : 0 : gcc_unreachable ();
13521 : : break;
13522 : 231377 : case LT:
13523 : 231377 : switch (mode)
13524 : : {
13525 : : case E_CCNOmode:
13526 : : case E_CCGOCmode:
13527 : : suffix = "s";
13528 : : break;
13529 : :
13530 : : case E_CCmode:
13531 : : case E_CCGCmode:
13532 : : case E_CCGZmode:
13533 : 6924251 : suffix = "l";
13534 : : break;
13535 : :
13536 : 0 : default:
13537 : 0 : gcc_unreachable ();
13538 : : }
13539 : : break;
13540 : 415807 : case LTU:
13541 : 415807 : if (mode == CCmode || mode == CCGZmode)
13542 : : suffix = "b";
13543 : 25461 : else if (mode == CCCmode)
13544 : 25461 : suffix = fp ? "b" : "c";
13545 : : else
13546 : 0 : gcc_unreachable ();
13547 : : break;
13548 : 143007 : case GE:
13549 : 143007 : switch (mode)
13550 : : {
13551 : : case E_CCNOmode:
13552 : : case E_CCGOCmode:
13553 : : suffix = "ns";
13554 : : break;
13555 : :
13556 : : case E_CCmode:
13557 : : case E_CCGCmode:
13558 : : case E_CCGZmode:
13559 : 6924251 : suffix = "ge";
13560 : : break;
13561 : :
13562 : 0 : default:
13563 : 0 : gcc_unreachable ();
13564 : : }
13565 : : break;
13566 : 187974 : case GEU:
13567 : 187974 : if (mode == CCmode || mode == CCGZmode)
13568 : : suffix = "nb";
13569 : 12857 : else if (mode == CCCmode)
13570 : 12857 : suffix = fp ? "nb" : "nc";
13571 : : else
13572 : 0 : gcc_unreachable ();
13573 : : break;
13574 : 236483 : case LE:
13575 : 236483 : gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
13576 : : suffix = "le";
13577 : : break;
13578 : 111954 : case LEU:
13579 : 111954 : if (mode == CCmode)
13580 : : suffix = "be";
13581 : : else
13582 : 0 : gcc_unreachable ();
13583 : : break;
13584 : 232714 : case UNORDERED:
13585 : 232714 : suffix = fp ? "u" : "p";
13586 : : break;
13587 : 4386 : case ORDERED:
13588 : 4386 : suffix = fp ? "nu" : "np";
13589 : : break;
13590 : 0 : default:
13591 : 0 : gcc_unreachable ();
13592 : : }
13593 : 6924251 : fputs (suffix, file);
13594 : 6924251 : }
13595 : :
13596 : : /* Print the name of register X to FILE based on its machine mode and number.
13597 : : If CODE is 'w', pretend the mode is HImode.
13598 : : If CODE is 'b', pretend the mode is QImode.
13599 : : If CODE is 'k', pretend the mode is SImode.
13600 : : If CODE is 'q', pretend the mode is DImode.
13601 : : If CODE is 'x', pretend the mode is V4SFmode.
13602 : : If CODE is 't', pretend the mode is V8SFmode.
13603 : : If CODE is 'g', pretend the mode is V16SFmode.
13604 : : If CODE is 'h', pretend the reg is the 'high' byte register.
13605 : : If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
13606 : : If CODE is 'd', duplicate the operand for AVX instruction.
13607 : : If CODE is 'V', print naked full integer register name without %.
13608 : : */
13609 : :
13610 : : void
13611 : 120080533 : print_reg (rtx x, int code, FILE *file)
13612 : : {
13613 : 120080533 : const char *reg;
13614 : 120080533 : int msize;
13615 : 120080533 : unsigned int regno;
13616 : 120080533 : bool duplicated;
13617 : :
13618 : 120080533 : if (ASSEMBLER_DIALECT == ASM_ATT && code != 'V')
13619 : 120078552 : putc ('%', file);
13620 : :
13621 : 120080533 : if (x == pc_rtx)
13622 : : {
13623 : 5620659 : gcc_assert (TARGET_64BIT);
13624 : 5620659 : fputs ("rip", file);
13625 : 5620659 : return;
13626 : : }
13627 : :
13628 : 114459874 : if (code == 'y' && STACK_TOP_P (x))
13629 : : {
13630 : 298113 : fputs ("st(0)", file);
13631 : 298113 : return;
13632 : : }
13633 : :
13634 : 114161761 : if (code == 'w')
13635 : : msize = 2;
13636 : : else if (code == 'b')
13637 : : msize = 1;
13638 : : else if (code == 'k')
13639 : : msize = 4;
13640 : : else if (code == 'q')
13641 : : msize = 8;
13642 : : else if (code == 'h')
13643 : : msize = 0;
13644 : : else if (code == 'x')
13645 : : msize = 16;
13646 : : else if (code == 't')
13647 : : msize = 32;
13648 : : else if (code == 'g')
13649 : : msize = 64;
13650 : : else
13651 : 195027494 : msize = GET_MODE_SIZE (GET_MODE (x));
13652 : :
13653 : 114161761 : regno = REGNO (x);
13654 : :
13655 : 114161761 : if (regno == ARG_POINTER_REGNUM
13656 : 114161761 : || regno == FRAME_POINTER_REGNUM
13657 : 114161761 : || regno == FPSR_REG)
13658 : : {
13659 : 0 : output_operand_lossage
13660 : 0 : ("invalid use of register '%s'", reg_names[regno]);
13661 : 0 : return;
13662 : : }
13663 : 114161761 : else if (regno == FLAGS_REG)
13664 : : {
13665 : 1 : output_operand_lossage ("invalid use of asm flag output");
13666 : 1 : return;
13667 : : }
13668 : :
13669 : 114161760 : if (code == 'V')
13670 : : {
13671 : 1 : if (GENERAL_REGNO_P (regno))
13672 : 2 : msize = GET_MODE_SIZE (word_mode);
13673 : : else
13674 : 0 : error ("%<V%> modifier on non-integer register");
13675 : : }
13676 : :
13677 : 114161760 : duplicated = code == 'd' && TARGET_AVX;
13678 : :
13679 : 114161760 : switch (msize)
13680 : : {
13681 : 74930906 : case 16:
13682 : 74930906 : case 12:
13683 : 74930906 : case 8:
13684 : 140171351 : if (GENERAL_REGNO_P (regno) && msize > GET_MODE_SIZE (word_mode))
13685 : 5 : warning (0, "unsupported size for integer register");
13686 : : /* FALLTHRU */
13687 : 110748793 : case 4:
13688 : 110748793 : if (LEGACY_INT_REGNO_P (regno))
13689 : 120429125 : putc (msize > 4 && TARGET_64BIT ? 'r' : 'e', file);
13690 : : /* FALLTHRU */
13691 : 111650396 : case 2:
13692 : 21546843 : normal:
13693 : 111650396 : reg = hi_reg_name[regno];
13694 : 111650396 : break;
13695 : 2279927 : case 1:
13696 : 2279927 : if (regno >= ARRAY_SIZE (qi_reg_name))
13697 : 285952 : goto normal;
13698 : 1993975 : if (!ANY_QI_REGNO_P (regno))
13699 : 0 : error ("unsupported size for integer register");
13700 : 1993975 : reg = qi_reg_name[regno];
13701 : 1993975 : break;
13702 : 27147 : case 0:
13703 : 27147 : if (regno >= ARRAY_SIZE (qi_high_reg_name))
13704 : 0 : goto normal;
13705 : 27147 : reg = qi_high_reg_name[regno];
13706 : 27147 : break;
13707 : 490242 : case 32:
13708 : 490242 : case 64:
13709 : 490242 : if (SSE_REGNO_P (regno))
13710 : : {
13711 : 490242 : gcc_assert (!duplicated);
13712 : 682462 : putc (msize == 32 ? 'y' : 'z', file);
13713 : 490242 : reg = hi_reg_name[regno] + 1;
13714 : 490242 : break;
13715 : : }
13716 : 0 : goto normal;
13717 : 0 : default:
13718 : 0 : gcc_unreachable ();
13719 : : }
13720 : :
13721 : 114161760 : fputs (reg, file);
13722 : :
13723 : : /* Irritatingly, AMD extended registers use
13724 : : different naming convention: "r%d[bwd]" */
13725 : 114161760 : if (REX_INT_REGNO_P (regno) || REX2_INT_REGNO_P (regno))
13726 : : {
13727 : 10056657 : gcc_assert (TARGET_64BIT);
13728 : 10056657 : switch (msize)
13729 : : {
13730 : 0 : case 0:
13731 : 0 : error ("extended registers have no high halves");
13732 : 0 : break;
13733 : 201493 : case 1:
13734 : 201493 : putc ('b', file);
13735 : 201493 : break;
13736 : 28585 : case 2:
13737 : 28585 : putc ('w', file);
13738 : 28585 : break;
13739 : 2560909 : case 4:
13740 : 2560909 : putc ('d', file);
13741 : 2560909 : break;
13742 : : case 8:
13743 : : /* no suffix */
13744 : : break;
13745 : 0 : default:
13746 : 0 : error ("unsupported operand size for extended register");
13747 : 0 : break;
13748 : : }
13749 : 10056657 : return;
13750 : : }
13751 : :
13752 : 104105103 : if (duplicated)
13753 : : {
13754 : 16956 : if (ASSEMBLER_DIALECT == ASM_ATT)
13755 : 16935 : fprintf (file, ", %%%s", reg);
13756 : : else
13757 : 21 : fprintf (file, ", %s", reg);
13758 : : }
13759 : : }
13760 : :
13761 : : /* Meaning of CODE:
13762 : : L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
13763 : : C -- print opcode suffix for set/cmov insn.
13764 : : c -- like C, but print reversed condition
13765 : : F,f -- likewise, but for floating-point.
13766 : : O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
13767 : : otherwise nothing
13768 : : R -- print embedded rounding and sae.
13769 : : r -- print only sae.
13770 : : z -- print the opcode suffix for the size of the current operand.
13771 : : Z -- likewise, with special suffixes for x87 instructions.
13772 : : * -- print a star (in certain assembler syntax)
13773 : : A -- print an absolute memory reference.
13774 : : E -- print address with DImode register names if TARGET_64BIT.
13775 : : w -- print the operand as if it's a "word" (HImode) even if it isn't.
13776 : : s -- print a shift double count, followed by the assemblers argument
13777 : : delimiter.
13778 : : b -- print the QImode name of the register for the indicated operand.
13779 : : %b0 would print %al if operands[0] is reg 0.
13780 : : w -- likewise, print the HImode name of the register.
13781 : : k -- likewise, print the SImode name of the register.
13782 : : q -- likewise, print the DImode name of the register.
13783 : : x -- likewise, print the V4SFmode name of the register.
13784 : : t -- likewise, print the V8SFmode name of the register.
13785 : : g -- likewise, print the V16SFmode name of the register.
13786 : : h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
13787 : : y -- print "st(0)" instead of "st" as a register.
13788 : : d -- print duplicated register operand for AVX instruction.
13789 : : D -- print condition for SSE cmp instruction.
13790 : : P -- if PIC, print an @PLT suffix. For -fno-plt, load function
13791 : : address from GOT.
13792 : : p -- print raw symbol name.
13793 : : X -- don't print any sort of PIC '@' suffix for a symbol.
13794 : : & -- print some in-use local-dynamic symbol name.
13795 : : H -- print a memory address offset by 8; used for sse high-parts
13796 : : Y -- print condition for XOP pcom* instruction.
13797 : : V -- print naked full integer register name without %.
13798 : : v -- print segment override prefix
13799 : : + -- print a branch hint as 'cs' or 'ds' prefix
13800 : : ; -- print a semicolon (after prefixes due to bug in older gas).
13801 : : ~ -- print "i" if TARGET_AVX2, "f" otherwise.
13802 : : ^ -- print addr32 prefix if Pmode != word_mode
13803 : : M -- print addr32 prefix for TARGET_X32 with VSIB address.
13804 : : ! -- print NOTRACK prefix for jxx/call/ret instructions if required.
13805 : : N -- print maskz if it's constant 0 operand.
13806 : : G -- print embedded flag for ccmp/ctest.
13807 : : */
13808 : :
13809 : : void
13810 : 172405717 : ix86_print_operand (FILE *file, rtx x, int code)
13811 : : {
13812 : 172598708 : if (code)
13813 : : {
13814 : 60513109 : switch (code)
13815 : : {
13816 : 192987 : case 'A':
13817 : 192987 : switch (ASSEMBLER_DIALECT)
13818 : : {
13819 : 192987 : case ASM_ATT:
13820 : 192987 : putc ('*', file);
13821 : 192987 : break;
13822 : :
13823 : 0 : case ASM_INTEL:
13824 : : /* Intel syntax. For absolute addresses, registers should not
13825 : : be surrounded by braces. */
13826 : 0 : if (!REG_P (x))
13827 : : {
13828 : 0 : putc ('[', file);
13829 : 0 : ix86_print_operand (file, x, 0);
13830 : 0 : putc (']', file);
13831 : 0 : return;
13832 : : }
13833 : : break;
13834 : :
13835 : 0 : default:
13836 : 0 : gcc_unreachable ();
13837 : : }
13838 : :
13839 : 192987 : ix86_print_operand (file, x, 0);
13840 : 192987 : return;
13841 : :
13842 : 3480281 : case 'E':
13843 : : /* Wrap address in an UNSPEC to declare special handling. */
13844 : 3480281 : if (TARGET_64BIT)
13845 : 2996090 : x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR);
13846 : :
13847 : 3480281 : output_address (VOIDmode, x);
13848 : 3480281 : return;
13849 : :
13850 : 0 : case 'L':
13851 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13852 : 0 : putc ('l', file);
13853 : 0 : return;
13854 : :
13855 : 0 : case 'W':
13856 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13857 : 0 : putc ('w', file);
13858 : 0 : return;
13859 : :
13860 : 0 : case 'B':
13861 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13862 : 0 : putc ('b', file);
13863 : 0 : return;
13864 : :
13865 : 0 : case 'Q':
13866 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13867 : 0 : putc ('l', file);
13868 : 0 : return;
13869 : :
13870 : 0 : case 'S':
13871 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13872 : 0 : putc ('s', file);
13873 : 0 : return;
13874 : :
13875 : 0 : case 'T':
13876 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13877 : 0 : putc ('t', file);
13878 : 0 : return;
13879 : :
13880 : : case 'O':
13881 : : #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
13882 : : if (ASSEMBLER_DIALECT != ASM_ATT)
13883 : : return;
13884 : :
13885 : : switch (GET_MODE_SIZE (GET_MODE (x)))
13886 : : {
13887 : : case 2:
13888 : : putc ('w', file);
13889 : : break;
13890 : :
13891 : : case 4:
13892 : : putc ('l', file);
13893 : : break;
13894 : :
13895 : : case 8:
13896 : : putc ('q', file);
13897 : : break;
13898 : :
13899 : : default:
13900 : : output_operand_lossage ("invalid operand size for operand "
13901 : : "code 'O'");
13902 : : return;
13903 : : }
13904 : :
13905 : : putc ('.', file);
13906 : : #endif
13907 : : return;
13908 : :
13909 : 37240 : case 'z':
13910 : 37240 : if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
13911 : : {
13912 : : /* Opcodes don't get size suffixes if using Intel opcodes. */
13913 : 37238 : if (ASSEMBLER_DIALECT == ASM_INTEL)
13914 : : return;
13915 : :
13916 : 74476 : switch (GET_MODE_SIZE (GET_MODE (x)))
13917 : : {
13918 : 6 : case 1:
13919 : 6 : putc ('b', file);
13920 : 6 : return;
13921 : :
13922 : 6 : case 2:
13923 : 6 : putc ('w', file);
13924 : 6 : return;
13925 : :
13926 : 36760 : case 4:
13927 : 36760 : putc ('l', file);
13928 : 36760 : return;
13929 : :
13930 : 466 : case 8:
13931 : 466 : putc ('q', file);
13932 : 466 : return;
13933 : :
13934 : 0 : default:
13935 : 0 : output_operand_lossage ("invalid operand size for operand "
13936 : : "code 'z'");
13937 : 0 : return;
13938 : : }
13939 : : }
13940 : :
13941 : 2 : if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
13942 : : {
13943 : 1 : if (this_is_asm_operands)
13944 : 1 : warning_for_asm (this_is_asm_operands,
13945 : : "non-integer operand used with operand code %<z%>");
13946 : : else
13947 : 0 : warning (0, "non-integer operand used with operand code %<z%>");
13948 : : }
13949 : : /* FALLTHRU */
13950 : :
13951 : 384782 : case 'Z':
13952 : : /* 387 opcodes don't get size suffixes if using Intel opcodes. */
13953 : 384782 : if (ASSEMBLER_DIALECT == ASM_INTEL)
13954 : : return;
13955 : :
13956 : 384782 : if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
13957 : : {
13958 : 29642 : switch (GET_MODE_SIZE (GET_MODE (x)))
13959 : : {
13960 : 3501 : case 2:
13961 : : #ifdef HAVE_AS_IX86_FILDS
13962 : 3501 : putc ('s', file);
13963 : : #endif
13964 : 3501 : return;
13965 : :
13966 : 3900 : case 4:
13967 : 3900 : putc ('l', file);
13968 : 3900 : return;
13969 : :
13970 : 7420 : case 8:
13971 : : #ifdef HAVE_AS_IX86_FILDQ
13972 : 7420 : putc ('q', file);
13973 : : #else
13974 : : fputs ("ll", file);
13975 : : #endif
13976 : 7420 : return;
13977 : :
13978 : : default:
13979 : : break;
13980 : : }
13981 : : }
13982 : 369961 : else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
13983 : : {
13984 : : /* 387 opcodes don't get size suffixes
13985 : : if the operands are registers. */
13986 : 369959 : if (STACK_REG_P (x))
13987 : : return;
13988 : :
13989 : 693314 : switch (GET_MODE_SIZE (GET_MODE (x)))
13990 : : {
13991 : 23083 : case 4:
13992 : 23083 : putc ('s', file);
13993 : 23083 : return;
13994 : :
13995 : 31938 : case 8:
13996 : 31938 : putc ('l', file);
13997 : 31938 : return;
13998 : :
13999 : 291634 : case 12:
14000 : 291634 : case 16:
14001 : 291634 : putc ('t', file);
14002 : 291634 : return;
14003 : :
14004 : : default:
14005 : : break;
14006 : : }
14007 : : }
14008 : : else
14009 : : {
14010 : 2 : output_operand_lossage ("invalid operand type used with "
14011 : : "operand code '%c'", code);
14012 : 2 : return;
14013 : : }
14014 : :
14015 : 2 : output_operand_lossage ("invalid operand size for operand code '%c'",
14016 : : code);
14017 : 2 : return;
14018 : :
14019 : : case 'd':
14020 : : case 'b':
14021 : : case 'w':
14022 : : case 'k':
14023 : : case 'q':
14024 : : case 'h':
14025 : : case 't':
14026 : : case 'g':
14027 : : case 'y':
14028 : : case 'x':
14029 : : case 'X':
14030 : : case 'P':
14031 : : case 'p':
14032 : : case 'V':
14033 : : break;
14034 : :
14035 : 0 : case 's':
14036 : 0 : if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
14037 : : {
14038 : 0 : ix86_print_operand (file, x, 0);
14039 : 0 : fputs (", ", file);
14040 : : }
14041 : 0 : return;
14042 : :
14043 : 494 : case 'Y':
14044 : 494 : switch (GET_CODE (x))
14045 : : {
14046 : 182 : case NE:
14047 : 182 : fputs ("neq", file);
14048 : 182 : break;
14049 : 32 : case EQ:
14050 : 32 : fputs ("eq", file);
14051 : 32 : break;
14052 : 64 : case GE:
14053 : 64 : case GEU:
14054 : 64 : fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
14055 : 64 : break;
14056 : 40 : case GT:
14057 : 40 : case GTU:
14058 : 40 : fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
14059 : 40 : break;
14060 : 64 : case LE:
14061 : 64 : case LEU:
14062 : 64 : fputs ("le", file);
14063 : 64 : break;
14064 : 112 : case LT:
14065 : 112 : case LTU:
14066 : 112 : fputs ("lt", file);
14067 : 112 : break;
14068 : 0 : case UNORDERED:
14069 : 0 : fputs ("unord", file);
14070 : 0 : break;
14071 : 0 : case ORDERED:
14072 : 0 : fputs ("ord", file);
14073 : 0 : break;
14074 : 0 : case UNEQ:
14075 : 0 : fputs ("ueq", file);
14076 : 0 : break;
14077 : 0 : case UNGE:
14078 : 0 : fputs ("nlt", file);
14079 : 0 : break;
14080 : 0 : case UNGT:
14081 : 0 : fputs ("nle", file);
14082 : 0 : break;
14083 : 0 : case UNLE:
14084 : 0 : fputs ("ule", file);
14085 : 0 : break;
14086 : 0 : case UNLT:
14087 : 0 : fputs ("ult", file);
14088 : 0 : break;
14089 : 0 : case LTGT:
14090 : 0 : fputs ("une", file);
14091 : 0 : break;
14092 : 0 : default:
14093 : 0 : output_operand_lossage ("operand is not a condition code, "
14094 : : "invalid operand code 'Y'");
14095 : 0 : return;
14096 : : }
14097 : 494 : return;
14098 : :
14099 : 9142 : case 'D':
14100 : : /* Little bit of braindamage here. The SSE compare instructions
14101 : : does use completely different names for the comparisons that the
14102 : : fp conditional moves. */
14103 : 9142 : switch (GET_CODE (x))
14104 : : {
14105 : 3 : case UNEQ:
14106 : 3 : if (TARGET_AVX)
14107 : : {
14108 : 3 : fputs ("eq_us", file);
14109 : 3 : break;
14110 : : }
14111 : : /* FALLTHRU */
14112 : 4327 : case EQ:
14113 : 4327 : fputs ("eq", file);
14114 : 4327 : break;
14115 : 0 : case UNLT:
14116 : 0 : if (TARGET_AVX)
14117 : : {
14118 : 0 : fputs ("nge", file);
14119 : 0 : break;
14120 : : }
14121 : : /* FALLTHRU */
14122 : 1785 : case LT:
14123 : 1785 : fputs ("lt", file);
14124 : 1785 : break;
14125 : 0 : case UNLE:
14126 : 0 : if (TARGET_AVX)
14127 : : {
14128 : 0 : fputs ("ngt", file);
14129 : 0 : break;
14130 : : }
14131 : : /* FALLTHRU */
14132 : 684 : case LE:
14133 : 684 : fputs ("le", file);
14134 : 684 : break;
14135 : 92 : case UNORDERED:
14136 : 92 : fputs ("unord", file);
14137 : 92 : break;
14138 : 24 : case LTGT:
14139 : 24 : if (TARGET_AVX)
14140 : : {
14141 : 24 : fputs ("neq_oq", file);
14142 : 24 : break;
14143 : : }
14144 : : /* FALLTHRU */
14145 : 982 : case NE:
14146 : 982 : fputs ("neq", file);
14147 : 982 : break;
14148 : 0 : case GE:
14149 : 0 : if (TARGET_AVX)
14150 : : {
14151 : 0 : fputs ("ge", file);
14152 : 0 : break;
14153 : : }
14154 : : /* FALLTHRU */
14155 : 408 : case UNGE:
14156 : 408 : fputs ("nlt", file);
14157 : 408 : break;
14158 : 0 : case GT:
14159 : 0 : if (TARGET_AVX)
14160 : : {
14161 : 0 : fputs ("gt", file);
14162 : 0 : break;
14163 : : }
14164 : : /* FALLTHRU */
14165 : 754 : case UNGT:
14166 : 754 : fputs ("nle", file);
14167 : 754 : break;
14168 : 83 : case ORDERED:
14169 : 83 : fputs ("ord", file);
14170 : 83 : break;
14171 : 0 : default:
14172 : 0 : output_operand_lossage ("operand is not a condition code, "
14173 : : "invalid operand code 'D'");
14174 : 0 : return;
14175 : : }
14176 : 9142 : return;
14177 : :
14178 : 6924251 : case 'F':
14179 : 6924251 : case 'f':
14180 : : #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
14181 : : if (ASSEMBLER_DIALECT == ASM_ATT)
14182 : : putc ('.', file);
14183 : : gcc_fallthrough ();
14184 : : #endif
14185 : :
14186 : 6924251 : case 'C':
14187 : 6924251 : case 'c':
14188 : 6924251 : if (!COMPARISON_P (x))
14189 : : {
14190 : 0 : output_operand_lossage ("operand is not a condition code, "
14191 : : "invalid operand code '%c'", code);
14192 : 0 : return;
14193 : : }
14194 : 6924251 : put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
14195 : 6924251 : code == 'c' || code == 'f',
14196 : 6924251 : code == 'F' || code == 'f',
14197 : : file);
14198 : 6924251 : return;
14199 : :
14200 : 21 : case 'G':
14201 : 21 : {
14202 : 21 : int dfv = INTVAL (x);
14203 : 21 : const char *dfv_suffix = ix86_ccmp_dfv_mapping[dfv];
14204 : 21 : fputs (dfv_suffix, file);
14205 : : }
14206 : 21 : return;
14207 : :
14208 : 1384 : case 'H':
14209 : 1384 : if (!offsettable_memref_p (x))
14210 : : {
14211 : 1 : output_operand_lossage ("operand is not an offsettable memory "
14212 : : "reference, invalid operand code 'H'");
14213 : 1 : return;
14214 : : }
14215 : : /* It doesn't actually matter what mode we use here, as we're
14216 : : only going to use this for printing. */
14217 : 1383 : x = adjust_address_nv (x, DImode, 8);
14218 : : /* Output 'qword ptr' for intel assembler dialect. */
14219 : 1383 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14220 : 0 : code = 'q';
14221 : : break;
14222 : :
14223 : 76224 : case 'K':
14224 : 76224 : if (!CONST_INT_P (x))
14225 : : {
14226 : 1 : output_operand_lossage ("operand is not an integer, invalid "
14227 : : "operand code 'K'");
14228 : 1 : return;
14229 : : }
14230 : :
14231 : 76223 : if (INTVAL (x) & IX86_HLE_ACQUIRE)
14232 : : #ifdef HAVE_AS_IX86_HLE
14233 : 22 : fputs ("xacquire ", file);
14234 : : #else
14235 : : fputs ("\n" ASM_BYTE "0xf2\n\t", file);
14236 : : #endif
14237 : 76201 : else if (INTVAL (x) & IX86_HLE_RELEASE)
14238 : : #ifdef HAVE_AS_IX86_HLE
14239 : 24 : fputs ("xrelease ", file);
14240 : : #else
14241 : : fputs ("\n" ASM_BYTE "0xf3\n\t", file);
14242 : : #endif
14243 : : /* We do not want to print value of the operand. */
14244 : 76223 : return;
14245 : :
14246 : 41019 : case 'N':
14247 : 41019 : if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
14248 : 14471 : fputs ("{z}", file);
14249 : 41019 : return;
14250 : :
14251 : 3928 : case 'r':
14252 : 3928 : if (!CONST_INT_P (x) || INTVAL (x) != ROUND_SAE)
14253 : : {
14254 : 2 : output_operand_lossage ("operand is not a specific integer, "
14255 : : "invalid operand code 'r'");
14256 : 2 : return;
14257 : : }
14258 : :
14259 : 3926 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14260 : 1 : fputs (", ", file);
14261 : :
14262 : 3926 : fputs ("{sae}", file);
14263 : :
14264 : 3926 : if (ASSEMBLER_DIALECT == ASM_ATT)
14265 : 3925 : fputs (", ", file);
14266 : :
14267 : 3926 : return;
14268 : :
14269 : 5946 : case 'R':
14270 : 5946 : if (!CONST_INT_P (x))
14271 : : {
14272 : 1 : output_operand_lossage ("operand is not an integer, invalid "
14273 : : "operand code 'R'");
14274 : 1 : return;
14275 : : }
14276 : :
14277 : 5945 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14278 : 2 : fputs (", ", file);
14279 : :
14280 : 5945 : switch (INTVAL (x))
14281 : : {
14282 : 5134 : case ROUND_NEAREST_INT | ROUND_SAE:
14283 : 5134 : fputs ("{rn-sae}", file);
14284 : 5134 : break;
14285 : 637 : case ROUND_NEG_INF | ROUND_SAE:
14286 : 637 : fputs ("{rd-sae}", file);
14287 : 637 : break;
14288 : 52 : case ROUND_POS_INF | ROUND_SAE:
14289 : 52 : fputs ("{ru-sae}", file);
14290 : 52 : break;
14291 : 121 : case ROUND_ZERO | ROUND_SAE:
14292 : 121 : fputs ("{rz-sae}", file);
14293 : 121 : break;
14294 : 1 : default:
14295 : 1 : output_operand_lossage ("operand is not a specific integer, "
14296 : : "invalid operand code 'R'");
14297 : : }
14298 : :
14299 : 5945 : if (ASSEMBLER_DIALECT == ASM_ATT)
14300 : 5943 : fputs (", ", file);
14301 : :
14302 : 5945 : return;
14303 : :
14304 : 26048 : case 'v':
14305 : 26048 : if (MEM_P (x))
14306 : : {
14307 : 27102 : switch (MEM_ADDR_SPACE (x))
14308 : : {
14309 : : case ADDR_SPACE_GENERIC:
14310 : : break;
14311 : 0 : case ADDR_SPACE_SEG_FS:
14312 : 0 : fputs ("fs ", file);
14313 : 0 : break;
14314 : 2 : case ADDR_SPACE_SEG_GS:
14315 : 2 : fputs ("gs ", file);
14316 : 2 : break;
14317 : 0 : default:
14318 : 0 : gcc_unreachable ();
14319 : : }
14320 : : }
14321 : : else
14322 : 0 : output_operand_lossage ("operand is not a memory reference, "
14323 : : "invalid operand code 'v'");
14324 : 26048 : return;
14325 : :
14326 : 0 : case '*':
14327 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
14328 : 0 : putc ('*', file);
14329 : 0 : return;
14330 : :
14331 : 269 : case '&':
14332 : 269 : {
14333 : 269 : const char *name = get_some_local_dynamic_name ();
14334 : 269 : if (name == NULL)
14335 : 1 : output_operand_lossage ("'%%&' used without any "
14336 : : "local dynamic TLS references");
14337 : : else
14338 : 268 : assemble_name (file, name);
14339 : 269 : return;
14340 : : }
14341 : :
14342 : 6306358 : case '+':
14343 : 6306358 : {
14344 : 6306358 : rtx x;
14345 : :
14346 : 6306358 : if (!optimize
14347 : 4913772 : || optimize_function_for_size_p (cfun)
14348 : 11038363 : || (!TARGET_BRANCH_PREDICTION_HINTS_NOT_TAKEN
14349 : 4732005 : && !TARGET_BRANCH_PREDICTION_HINTS_TAKEN))
14350 : 6306358 : return;
14351 : :
14352 : 0 : x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
14353 : 0 : if (x)
14354 : : {
14355 : 0 : int pred_val = profile_probability::from_reg_br_prob_note
14356 : 0 : (XINT (x, 0)).to_reg_br_prob_base ();
14357 : :
14358 : 0 : bool taken = pred_val > REG_BR_PROB_BASE / 2;
14359 : : /* We use 3e (DS) prefix for taken branches and
14360 : : 2e (CS) prefix for not taken branches. */
14361 : 0 : if (taken && TARGET_BRANCH_PREDICTION_HINTS_TAKEN)
14362 : 0 : fputs ("ds ; ", file);
14363 : 0 : else if (!taken && TARGET_BRANCH_PREDICTION_HINTS_NOT_TAKEN)
14364 : 0 : fputs ("cs ; ", file);
14365 : : }
14366 : 0 : return;
14367 : : }
14368 : :
14369 : : case ';':
14370 : : #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
14371 : : putc (';', file);
14372 : : #endif
14373 : : return;
14374 : :
14375 : 3470 : case '~':
14376 : 3470 : putc (TARGET_AVX2 ? 'i' : 'f', file);
14377 : 3470 : return;
14378 : :
14379 : 1697 : case 'M':
14380 : 1697 : if (TARGET_X32)
14381 : : {
14382 : : /* NB: 32-bit indices in VSIB address are sign-extended
14383 : : to 64 bits. In x32, if 32-bit address 0xf7fa3010 is
14384 : : sign-extended to 0xfffffffff7fa3010 which is invalid
14385 : : address. Add addr32 prefix if there is no base
14386 : : register nor symbol. */
14387 : 40 : bool ok;
14388 : 40 : struct ix86_address parts;
14389 : 40 : ok = ix86_decompose_address (x, &parts);
14390 : 40 : gcc_assert (ok && parts.index == NULL_RTX);
14391 : 40 : if (parts.base == NULL_RTX
14392 : 40 : && (parts.disp == NULL_RTX
14393 : 34 : || !symbolic_operand (parts.disp,
14394 : 34 : GET_MODE (parts.disp))))
14395 : 34 : fputs ("addr32 ", file);
14396 : : }
14397 : 1697 : return;
14398 : :
14399 : 53266 : case '^':
14400 : 53266 : if (Pmode != word_mode)
14401 : 0 : fputs ("addr32 ", file);
14402 : 53266 : return;
14403 : :
14404 : 14470700 : case '!':
14405 : 14470700 : if (ix86_notrack_prefixed_insn_p (current_output_insn))
14406 : 4882 : fputs ("notrack ", file);
14407 : 14470700 : return;
14408 : :
14409 : 1 : default:
14410 : 1 : output_operand_lossage ("invalid operand code '%c'", code);
14411 : : }
14412 : : }
14413 : :
14414 : 140178551 : if (REG_P (x))
14415 : 84191748 : print_reg (x, code, file);
14416 : :
14417 : 55986803 : else if (MEM_P (x))
14418 : : {
14419 : 31683615 : rtx addr = XEXP (x, 0);
14420 : :
14421 : : /* No `byte ptr' prefix for call instructions ... */
14422 : 31683615 : if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P')
14423 : : {
14424 : 217 : machine_mode mode = GET_MODE (x);
14425 : 217 : const char *size;
14426 : :
14427 : : /* Check for explicit size override codes. */
14428 : 217 : if (code == 'b')
14429 : : size = "BYTE";
14430 : : else if (code == 'w')
14431 : : size = "WORD";
14432 : : else if (code == 'k')
14433 : : size = "DWORD";
14434 : : else if (code == 'q')
14435 : : size = "QWORD";
14436 : : else if (code == 'x')
14437 : : size = "XMMWORD";
14438 : : else if (code == 't')
14439 : : size = "YMMWORD";
14440 : : else if (code == 'g')
14441 : : size = "ZMMWORD";
14442 : 142 : else if (mode == BLKmode)
14443 : : /* ... or BLKmode operands, when not overridden. */
14444 : : size = NULL;
14445 : : else
14446 : 280 : switch (GET_MODE_SIZE (mode))
14447 : : {
14448 : : case 1: size = "BYTE"; break;
14449 : : case 2: size = "WORD"; break;
14450 : : case 4: size = "DWORD"; break;
14451 : : case 8: size = "QWORD"; break;
14452 : : case 12: size = "TBYTE"; break;
14453 : 4 : case 16:
14454 : 4 : if (mode == XFmode)
14455 : : size = "TBYTE";
14456 : : else
14457 : : size = "XMMWORD";
14458 : : break;
14459 : : case 32: size = "YMMWORD"; break;
14460 : : case 64: size = "ZMMWORD"; break;
14461 : 0 : default:
14462 : 0 : gcc_unreachable ();
14463 : : }
14464 : : if (size)
14465 : : {
14466 : 215 : fputs (size, file);
14467 : 215 : fputs (" PTR ", file);
14468 : : }
14469 : : }
14470 : :
14471 : 31683615 : if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
14472 : 0 : output_operand_lossage ("invalid constraints for operand");
14473 : : else
14474 : 31683615 : ix86_print_operand_address_as
14475 : 31983254 : (file, addr, MEM_ADDR_SPACE (x), code == 'p' || code == 'P');
14476 : : }
14477 : :
14478 : 24303188 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == HFmode)
14479 : : {
14480 : 770 : long l = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x),
14481 : 770 : REAL_MODE_FORMAT (HFmode));
14482 : 770 : if (ASSEMBLER_DIALECT == ASM_ATT)
14483 : 770 : putc ('$', file);
14484 : 770 : fprintf (file, "0x%04x", (unsigned int) l);
14485 : : }
14486 : :
14487 : 24302418 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode)
14488 : : {
14489 : 21172 : long l;
14490 : :
14491 : 21172 : REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
14492 : :
14493 : 21172 : if (ASSEMBLER_DIALECT == ASM_ATT)
14494 : 21172 : putc ('$', file);
14495 : : /* Sign extend 32bit SFmode immediate to 8 bytes. */
14496 : 21172 : if (code == 'q')
14497 : 387 : fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x",
14498 : : (unsigned long long) (int) l);
14499 : : else
14500 : 20785 : fprintf (file, "0x%08x", (unsigned int) l);
14501 : : }
14502 : :
14503 : 24281246 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == DFmode)
14504 : : {
14505 : 3535 : long l[2];
14506 : :
14507 : 3535 : REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), l);
14508 : :
14509 : 3535 : if (ASSEMBLER_DIALECT == ASM_ATT)
14510 : 3535 : putc ('$', file);
14511 : 3535 : fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff);
14512 : : }
14513 : :
14514 : : /* These float cases don't actually occur as immediate operands. */
14515 : 24277711 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == XFmode)
14516 : : {
14517 : 0 : char dstr[30];
14518 : :
14519 : 0 : real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
14520 : 0 : fputs (dstr, file);
14521 : : }
14522 : :
14523 : : /* Print bcst_mem_operand. */
14524 : 24277711 : else if (GET_CODE (x) == VEC_DUPLICATE)
14525 : : {
14526 : 313 : machine_mode vmode = GET_MODE (x);
14527 : : /* Must be bcst_memory_operand. */
14528 : 313 : gcc_assert (bcst_mem_operand (x, vmode));
14529 : :
14530 : 313 : rtx mem = XEXP (x,0);
14531 : 313 : ix86_print_operand (file, mem, 0);
14532 : :
14533 : 313 : switch (vmode)
14534 : : {
14535 : 28 : case E_V2DImode:
14536 : 28 : case E_V2DFmode:
14537 : 28 : fputs ("{1to2}", file);
14538 : 28 : break;
14539 : 74 : case E_V4SImode:
14540 : 74 : case E_V4SFmode:
14541 : 74 : case E_V4DImode:
14542 : 74 : case E_V4DFmode:
14543 : 74 : fputs ("{1to4}", file);
14544 : 74 : break;
14545 : 93 : case E_V8SImode:
14546 : 93 : case E_V8SFmode:
14547 : 93 : case E_V8DFmode:
14548 : 93 : case E_V8DImode:
14549 : 93 : case E_V8HFmode:
14550 : 93 : fputs ("{1to8}", file);
14551 : 93 : break;
14552 : 110 : case E_V16SFmode:
14553 : 110 : case E_V16SImode:
14554 : 110 : case E_V16HFmode:
14555 : 110 : fputs ("{1to16}", file);
14556 : 110 : break;
14557 : 8 : case E_V32HFmode:
14558 : 8 : fputs ("{1to32}", file);
14559 : 8 : break;
14560 : 0 : default:
14561 : 0 : gcc_unreachable ();
14562 : : }
14563 : : }
14564 : :
14565 : : else
14566 : : {
14567 : : /* We have patterns that allow zero sets of memory, for instance.
14568 : : In 64-bit mode, we should probably support all 8-byte vectors,
14569 : : since we can in fact encode that into an immediate. */
14570 : 24277398 : if (GET_CODE (x) == CONST_VECTOR)
14571 : : {
14572 : 114 : if (x != CONST0_RTX (GET_MODE (x)))
14573 : 2 : output_operand_lossage ("invalid vector immediate");
14574 : 114 : x = const0_rtx;
14575 : : }
14576 : :
14577 : 24277398 : if (code == 'P')
14578 : : {
14579 : 5821845 : if (ix86_force_load_from_GOT_p (x, true))
14580 : : {
14581 : : /* For inline assembly statement, load function address
14582 : : from GOT with 'P' operand modifier to avoid PLT. */
14583 : 4 : x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
14584 : : (TARGET_64BIT
14585 : : ? UNSPEC_GOTPCREL
14586 : : : UNSPEC_GOT));
14587 : 4 : x = gen_rtx_CONST (Pmode, x);
14588 : 4 : x = gen_const_mem (Pmode, x);
14589 : 4 : ix86_print_operand (file, x, 'A');
14590 : 4 : return;
14591 : : }
14592 : : }
14593 : 18455553 : else if (code != 'p')
14594 : : {
14595 : 18455444 : if (CONST_INT_P (x))
14596 : : {
14597 : 15218457 : if (ASSEMBLER_DIALECT == ASM_ATT)
14598 : 15218254 : putc ('$', file);
14599 : : }
14600 : 3236987 : else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
14601 : 9389 : || GET_CODE (x) == LABEL_REF)
14602 : : {
14603 : 3236985 : if (ASSEMBLER_DIALECT == ASM_ATT)
14604 : 3236979 : putc ('$', file);
14605 : : else
14606 : 6 : fputs ("OFFSET FLAT:", file);
14607 : : }
14608 : : }
14609 : 24277394 : if (CONST_INT_P (x))
14610 : 15218543 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
14611 : 9058851 : else if (flag_pic || MACHOPIC_INDIRECT)
14612 : 508724 : output_pic_addr_const (file, x, code);
14613 : : else
14614 : 8550127 : output_addr_const (file, x);
14615 : : }
14616 : : }
14617 : :
14618 : : static bool
14619 : 20946533 : ix86_print_operand_punct_valid_p (unsigned char code)
14620 : : {
14621 : 20946533 : return (code == '*' || code == '+' || code == '&' || code == ';'
14622 : 14523966 : || code == '~' || code == '^' || code == '!');
14623 : : }
14624 : :
14625 : : /* Print a memory operand whose address is ADDR. */
14626 : :
14627 : : static void
14628 : 35166149 : ix86_print_operand_address_as (FILE *file, rtx addr,
14629 : : addr_space_t as, bool raw)
14630 : : {
14631 : 35166149 : struct ix86_address parts;
14632 : 35166149 : rtx base, index, disp;
14633 : 35166149 : int scale;
14634 : 35166149 : int ok;
14635 : 35166149 : bool vsib = false;
14636 : 35166149 : int code = 0;
14637 : :
14638 : 35166149 : if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR)
14639 : : {
14640 : 1697 : ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
14641 : 1697 : gcc_assert (parts.index == NULL_RTX);
14642 : 1697 : parts.index = XVECEXP (addr, 0, 1);
14643 : 1697 : parts.scale = INTVAL (XVECEXP (addr, 0, 2));
14644 : 1697 : addr = XVECEXP (addr, 0, 0);
14645 : 1697 : vsib = true;
14646 : : }
14647 : 35164452 : else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR)
14648 : : {
14649 : 2996090 : gcc_assert (TARGET_64BIT);
14650 : 2996090 : ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
14651 : 2996090 : code = 'q';
14652 : : }
14653 : : else
14654 : 32168362 : ok = ix86_decompose_address (addr, &parts);
14655 : :
14656 : 35166149 : gcc_assert (ok);
14657 : :
14658 : 35166149 : base = parts.base;
14659 : 35166149 : index = parts.index;
14660 : 35166149 : disp = parts.disp;
14661 : 35166149 : scale = parts.scale;
14662 : :
14663 : 35166149 : if (ADDR_SPACE_GENERIC_P (as))
14664 : 34886756 : as = parts.seg;
14665 : : else
14666 : 279393 : gcc_assert (ADDR_SPACE_GENERIC_P (parts.seg));
14667 : :
14668 : 35166149 : if (!ADDR_SPACE_GENERIC_P (as) && !raw)
14669 : : {
14670 : 279409 : if (ASSEMBLER_DIALECT == ASM_ATT)
14671 : 279407 : putc ('%', file);
14672 : :
14673 : 279409 : switch (as)
14674 : : {
14675 : 179882 : case ADDR_SPACE_SEG_FS:
14676 : 179882 : fputs ("fs:", file);
14677 : 179882 : break;
14678 : 99527 : case ADDR_SPACE_SEG_GS:
14679 : 99527 : fputs ("gs:", file);
14680 : 99527 : break;
14681 : 0 : default:
14682 : 0 : gcc_unreachable ();
14683 : : }
14684 : : }
14685 : :
14686 : : /* Use one byte shorter RIP relative addressing for 64bit mode. */
14687 : 35166149 : if (TARGET_64BIT && !base && !index && !raw)
14688 : : {
14689 : 5878856 : rtx symbol = disp;
14690 : :
14691 : 5878856 : if (GET_CODE (disp) == CONST
14692 : 2109060 : && GET_CODE (XEXP (disp, 0)) == PLUS
14693 : 2027341 : && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
14694 : 2027341 : symbol = XEXP (XEXP (disp, 0), 0);
14695 : :
14696 : 5878856 : if (GET_CODE (symbol) == LABEL_REF
14697 : 5878856 : || (GET_CODE (symbol) == SYMBOL_REF
14698 : 5621579 : && SYMBOL_REF_TLS_MODEL (symbol) == 0))
14699 : 5620659 : base = pc_rtx;
14700 : : }
14701 : :
14702 : 35166149 : if (!base && !index)
14703 : : {
14704 : : /* Displacement only requires special attention. */
14705 : 599318 : if (CONST_INT_P (disp))
14706 : : {
14707 : 268781 : if (ASSEMBLER_DIALECT == ASM_INTEL && ADDR_SPACE_GENERIC_P (as))
14708 : 1 : fputs ("ds:", file);
14709 : 268781 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
14710 : : }
14711 : : /* Load the external function address via the GOT slot to avoid PLT. */
14712 : 330537 : else if (GET_CODE (disp) == CONST
14713 : 108818 : && GET_CODE (XEXP (disp, 0)) == UNSPEC
14714 : 81933 : && (XINT (XEXP (disp, 0), 1) == UNSPEC_GOTPCREL
14715 : 8112 : || XINT (XEXP (disp, 0), 1) == UNSPEC_GOT)
14716 : 404358 : && ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
14717 : 24 : output_pic_addr_const (file, disp, 0);
14718 : 330513 : else if (flag_pic)
14719 : 112565 : output_pic_addr_const (file, disp, 0);
14720 : : else
14721 : 217948 : output_addr_const (file, disp);
14722 : : }
14723 : : else
14724 : : {
14725 : : /* Print SImode register names to force addr32 prefix. */
14726 : 34566831 : if (SImode_address_operand (addr, VOIDmode))
14727 : : {
14728 : 28 : if (flag_checking)
14729 : : {
14730 : 28 : gcc_assert (TARGET_64BIT);
14731 : 28 : switch (GET_CODE (addr))
14732 : : {
14733 : 0 : case SUBREG:
14734 : 0 : gcc_assert (GET_MODE (addr) == SImode);
14735 : 0 : gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode);
14736 : : break;
14737 : 28 : case ZERO_EXTEND:
14738 : 28 : case AND:
14739 : 28 : gcc_assert (GET_MODE (addr) == DImode);
14740 : : break;
14741 : 0 : default:
14742 : 0 : gcc_unreachable ();
14743 : : }
14744 : : }
14745 : 28 : gcc_assert (!code);
14746 : : code = 'k';
14747 : : }
14748 : 34566803 : else if (code == 0
14749 : 31573083 : && TARGET_X32
14750 : 297 : && disp
14751 : 232 : && CONST_INT_P (disp)
14752 : 142 : && INTVAL (disp) < -16*1024*1024)
14753 : : {
14754 : : /* X32 runs in 64-bit mode, where displacement, DISP, in
14755 : : address DISP(%r64), is encoded as 32-bit immediate sign-
14756 : : extended from 32-bit to 64-bit. For -0x40000300(%r64),
14757 : : address is %r64 + 0xffffffffbffffd00. When %r64 <
14758 : : 0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64,
14759 : : which is invalid for x32. The correct address is %r64
14760 : : - 0x40000300 == 0xf7ffdd64. To properly encode
14761 : : -0x40000300(%r64) for x32, we zero-extend negative
14762 : : displacement by forcing addr32 prefix which truncates
14763 : : 0xfffffffff7ffdd64 to 0xf7ffdd64. In theory, we should
14764 : : zero-extend all negative displacements, including -1(%rsp).
14765 : : However, for small negative displacements, sign-extension
14766 : : won't cause overflow. We only zero-extend negative
14767 : : displacements if they < -16*1024*1024, which is also used
14768 : : to check legitimate address displacements for PIC. */
14769 : 29 : code = 'k';
14770 : : }
14771 : :
14772 : : /* Since the upper 32 bits of RSP are always zero for x32,
14773 : : we can encode %esp as %rsp to avoid 0x67 prefix if
14774 : : there is no index register. */
14775 : 381 : if (TARGET_X32 && Pmode == SImode
14776 : 34567045 : && !index && base && REG_P (base) && REGNO (base) == SP_REG)
14777 : : code = 'q';
14778 : :
14779 : 34566831 : if (ASSEMBLER_DIALECT == ASM_ATT)
14780 : : {
14781 : 34566565 : if (disp)
14782 : : {
14783 : 30655562 : if (flag_pic)
14784 : 2644177 : output_pic_addr_const (file, disp, 0);
14785 : 28011385 : else if (GET_CODE (disp) == LABEL_REF)
14786 : 6332 : output_asm_label (disp);
14787 : : else
14788 : 28005053 : output_addr_const (file, disp);
14789 : : }
14790 : :
14791 : 34566565 : putc ('(', file);
14792 : 34566565 : if (base)
14793 : 34160046 : print_reg (base, code, file);
14794 : 34566565 : if (index)
14795 : : {
14796 : 1728420 : putc (',', file);
14797 : 3455191 : print_reg (index, vsib ? 0 : code, file);
14798 : 1728420 : if (scale != 1 || vsib)
14799 : 997320 : fprintf (file, ",%d", scale);
14800 : : }
14801 : 34566565 : putc (')', file);
14802 : : }
14803 : : else
14804 : : {
14805 : 266 : rtx offset = NULL_RTX;
14806 : :
14807 : 266 : if (disp)
14808 : : {
14809 : : /* Pull out the offset of a symbol; print any symbol itself. */
14810 : 207 : if (GET_CODE (disp) == CONST
14811 : 19 : && GET_CODE (XEXP (disp, 0)) == PLUS
14812 : 19 : && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
14813 : : {
14814 : 19 : offset = XEXP (XEXP (disp, 0), 1);
14815 : 19 : disp = gen_rtx_CONST (VOIDmode,
14816 : : XEXP (XEXP (disp, 0), 0));
14817 : : }
14818 : :
14819 : 207 : if (flag_pic)
14820 : 0 : output_pic_addr_const (file, disp, 0);
14821 : 207 : else if (GET_CODE (disp) == LABEL_REF)
14822 : 0 : output_asm_label (disp);
14823 : 207 : else if (CONST_INT_P (disp))
14824 : : offset = disp;
14825 : : else
14826 : 107 : output_addr_const (file, disp);
14827 : : }
14828 : :
14829 : 266 : putc ('[', file);
14830 : 266 : if (base)
14831 : : {
14832 : 223 : print_reg (base, code, file);
14833 : 223 : if (offset)
14834 : : {
14835 : 119 : if (INTVAL (offset) >= 0)
14836 : 19 : putc ('+', file);
14837 : 119 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
14838 : : }
14839 : : }
14840 : 43 : else if (offset)
14841 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
14842 : : else
14843 : 43 : putc ('0', file);
14844 : :
14845 : 266 : if (index)
14846 : : {
14847 : 96 : putc ('+', file);
14848 : 144 : print_reg (index, vsib ? 0 : code, file);
14849 : 96 : if (scale != 1 || vsib)
14850 : 94 : fprintf (file, "*%d", scale);
14851 : : }
14852 : 266 : putc (']', file);
14853 : : }
14854 : : }
14855 : 35166149 : }
14856 : :
14857 : : static void
14858 : 3482535 : ix86_print_operand_address (FILE *file, machine_mode /*mode*/, rtx addr)
14859 : : {
14860 : 3482535 : if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
14861 : 1 : output_operand_lossage ("invalid constraints for operand");
14862 : : else
14863 : 3482534 : ix86_print_operand_address_as (file, addr, ADDR_SPACE_GENERIC, false);
14864 : 3482535 : }
14865 : :
14866 : : /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */
14867 : :
14868 : : static bool
14869 : 13647 : i386_asm_output_addr_const_extra (FILE *file, rtx x)
14870 : : {
14871 : 13647 : rtx op;
14872 : :
14873 : 13647 : if (GET_CODE (x) != UNSPEC)
14874 : : return false;
14875 : :
14876 : 13647 : op = XVECEXP (x, 0, 0);
14877 : 13647 : switch (XINT (x, 1))
14878 : : {
14879 : 1305 : case UNSPEC_GOTOFF:
14880 : 1305 : output_addr_const (file, op);
14881 : 1305 : fputs ("@gotoff", file);
14882 : 1305 : break;
14883 : 0 : case UNSPEC_GOTTPOFF:
14884 : 0 : output_addr_const (file, op);
14885 : : /* FIXME: This might be @TPOFF in Sun ld. */
14886 : 0 : fputs ("@gottpoff", file);
14887 : 0 : break;
14888 : 0 : case UNSPEC_TPOFF:
14889 : 0 : output_addr_const (file, op);
14890 : 0 : fputs ("@tpoff", file);
14891 : 0 : break;
14892 : 10171 : case UNSPEC_NTPOFF:
14893 : 10171 : output_addr_const (file, op);
14894 : 10171 : if (TARGET_64BIT)
14895 : 9452 : fputs ("@tpoff", file);
14896 : : else
14897 : 719 : fputs ("@ntpoff", file);
14898 : : break;
14899 : 30 : case UNSPEC_DTPOFF:
14900 : 30 : output_addr_const (file, op);
14901 : 30 : fputs ("@dtpoff", file);
14902 : 30 : break;
14903 : 2140 : case UNSPEC_GOTNTPOFF:
14904 : 2140 : output_addr_const (file, op);
14905 : 2140 : if (TARGET_64BIT)
14906 : 2140 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14907 : : "@gottpoff(%rip)" : "@gottpoff[rip]", file);
14908 : : else
14909 : 0 : fputs ("@gotntpoff", file);
14910 : : break;
14911 : 1 : case UNSPEC_INDNTPOFF:
14912 : 1 : output_addr_const (file, op);
14913 : 1 : fputs ("@indntpoff", file);
14914 : 1 : break;
14915 : 0 : case UNSPEC_SECREL32:
14916 : 0 : output_addr_const (file, op);
14917 : 0 : fputs ("@secrel32", file);
14918 : 0 : break;
14919 : : #if TARGET_MACHO
14920 : : case UNSPEC_MACHOPIC_OFFSET:
14921 : : output_addr_const (file, op);
14922 : : putc ('-', file);
14923 : : machopic_output_function_base_name (file);
14924 : : break;
14925 : : #endif
14926 : :
14927 : : default:
14928 : : return false;
14929 : : }
14930 : :
14931 : : return true;
14932 : : }
14933 : :
14934 : :
14935 : : /* Output code to perform a 387 binary operation in INSN, one of PLUS,
14936 : : MINUS, MULT or DIV. OPERANDS are the insn operands, where operands[3]
14937 : : is the expression of the binary operation. The output may either be
14938 : : emitted here, or returned to the caller, like all output_* functions.
14939 : :
14940 : : There is no guarantee that the operands are the same mode, as they
14941 : : might be within FLOAT or FLOAT_EXTEND expressions. */
14942 : :
14943 : : #ifndef SYSV386_COMPAT
14944 : : /* Set to 1 for compatibility with brain-damaged assemblers. No-one
14945 : : wants to fix the assemblers because that causes incompatibility
14946 : : with gcc. No-one wants to fix gcc because that causes
14947 : : incompatibility with assemblers... You can use the option of
14948 : : -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way. */
14949 : : #define SYSV386_COMPAT 1
14950 : : #endif
14951 : :
14952 : : const char *
14953 : 606523 : output_387_binary_op (rtx_insn *insn, rtx *operands)
14954 : : {
14955 : 606523 : static char buf[40];
14956 : 606523 : const char *p;
14957 : 606523 : bool is_sse
14958 : 606523 : = (SSE_REG_P (operands[0])
14959 : 661992 : || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]));
14960 : :
14961 : 55469 : if (is_sse)
14962 : : p = "%v";
14963 : 55469 : else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
14964 : 55462 : || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
14965 : : p = "fi";
14966 : : else
14967 : 606523 : p = "f";
14968 : :
14969 : 606523 : strcpy (buf, p);
14970 : :
14971 : 606523 : switch (GET_CODE (operands[3]))
14972 : : {
14973 : : case PLUS:
14974 : : p = "add"; break;
14975 : : case MINUS:
14976 : : p = "sub"; break;
14977 : 95220 : case MULT:
14978 : 95220 : p = "mul"; break;
14979 : 27979 : case DIV:
14980 : 27979 : p = "div"; break;
14981 : 0 : default:
14982 : 0 : gcc_unreachable ();
14983 : : }
14984 : :
14985 : 606523 : strcat (buf, p);
14986 : :
14987 : 606523 : if (is_sse)
14988 : : {
14989 : 551054 : p = GET_MODE (operands[0]) == SFmode ? "ss" : "sd";
14990 : 551054 : strcat (buf, p);
14991 : :
14992 : 551054 : if (TARGET_AVX)
14993 : : p = "\t{%2, %1, %0|%0, %1, %2}";
14994 : : else
14995 : 532607 : p = "\t{%2, %0|%0, %2}";
14996 : :
14997 : 551054 : strcat (buf, p);
14998 : 551054 : return buf;
14999 : : }
15000 : :
15001 : : /* Even if we do not want to check the inputs, this documents input
15002 : : constraints. Which helps in understanding the following code. */
15003 : 55469 : if (flag_checking)
15004 : : {
15005 : 55468 : if (STACK_REG_P (operands[0])
15006 : 55468 : && ((REG_P (operands[1])
15007 : 53841 : && REGNO (operands[0]) == REGNO (operands[1])
15008 : 49722 : && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
15009 : 5746 : || (REG_P (operands[2])
15010 : 5746 : && REGNO (operands[0]) == REGNO (operands[2])
15011 : 5746 : && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
15012 : 110936 : && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
15013 : : ; /* ok */
15014 : : else
15015 : 0 : gcc_unreachable ();
15016 : : }
15017 : :
15018 : 55469 : switch (GET_CODE (operands[3]))
15019 : : {
15020 : 40630 : case MULT:
15021 : 40630 : case PLUS:
15022 : 40630 : if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
15023 : 2031 : std::swap (operands[1], operands[2]);
15024 : :
15025 : : /* know operands[0] == operands[1]. */
15026 : :
15027 : 40630 : if (MEM_P (operands[2]))
15028 : : {
15029 : : p = "%Z2\t%2";
15030 : : break;
15031 : : }
15032 : :
15033 : 36320 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
15034 : : {
15035 : 21233 : if (STACK_TOP_P (operands[0]))
15036 : : /* How is it that we are storing to a dead operand[2]?
15037 : : Well, presumably operands[1] is dead too. We can't
15038 : : store the result to st(0) as st(0) gets popped on this
15039 : : instruction. Instead store to operands[2] (which I
15040 : : think has to be st(1)). st(1) will be popped later.
15041 : : gcc <= 2.8.1 didn't have this check and generated
15042 : : assembly code that the Unixware assembler rejected. */
15043 : : p = "p\t{%0, %2|%2, %0}"; /* st(1) = st(0) op st(1); pop */
15044 : : else
15045 : : p = "p\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0); pop */
15046 : : break;
15047 : : }
15048 : :
15049 : 15087 : if (STACK_TOP_P (operands[0]))
15050 : : p = "\t{%y2, %0|%0, %y2}"; /* st(0) = st(0) op st(r2) */
15051 : : else
15052 : : p = "\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0) */
15053 : : break;
15054 : :
15055 : 14839 : case MINUS:
15056 : 14839 : case DIV:
15057 : 14839 : if (MEM_P (operands[1]))
15058 : : {
15059 : : p = "r%Z1\t%1";
15060 : : break;
15061 : : }
15062 : :
15063 : 14400 : if (MEM_P (operands[2]))
15064 : : {
15065 : : p = "%Z2\t%2";
15066 : : break;
15067 : : }
15068 : :
15069 : 12893 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
15070 : : {
15071 : : #if SYSV386_COMPAT
15072 : : /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
15073 : : derived assemblers, confusingly reverse the direction of
15074 : : the operation for fsub{r} and fdiv{r} when the
15075 : : destination register is not st(0). The Intel assembler
15076 : : doesn't have this brain damage. Read !SYSV386_COMPAT to
15077 : : figure out what the hardware really does. */
15078 : 6085 : if (STACK_TOP_P (operands[0]))
15079 : : p = "{p\t%0, %2|rp\t%2, %0}";
15080 : : else
15081 : : p = "{rp\t%2, %0|p\t%0, %2}";
15082 : : #else
15083 : : if (STACK_TOP_P (operands[0]))
15084 : : /* As above for fmul/fadd, we can't store to st(0). */
15085 : : p = "rp\t{%0, %2|%2, %0}"; /* st(1) = st(0) op st(1); pop */
15086 : : else
15087 : : p = "p\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0); pop */
15088 : : #endif
15089 : : break;
15090 : : }
15091 : :
15092 : 6808 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
15093 : : {
15094 : : #if SYSV386_COMPAT
15095 : 3165 : if (STACK_TOP_P (operands[0]))
15096 : : p = "{rp\t%0, %1|p\t%1, %0}";
15097 : : else
15098 : : p = "{p\t%1, %0|rp\t%0, %1}";
15099 : : #else
15100 : : if (STACK_TOP_P (operands[0]))
15101 : : p = "p\t{%0, %1|%1, %0}"; /* st(1) = st(1) op st(0); pop */
15102 : : else
15103 : : p = "rp\t{%1, %0|%0, %1}"; /* st(r2) = st(0) op st(r2); pop */
15104 : : #endif
15105 : : break;
15106 : : }
15107 : :
15108 : 3643 : if (STACK_TOP_P (operands[0]))
15109 : : {
15110 : 2810 : if (STACK_TOP_P (operands[1]))
15111 : : p = "\t{%y2, %0|%0, %y2}"; /* st(0) = st(0) op st(r2) */
15112 : : else
15113 : : p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
15114 : : break;
15115 : : }
15116 : 833 : else if (STACK_TOP_P (operands[1]))
15117 : : {
15118 : : #if SYSV386_COMPAT
15119 : : p = "{\t%1, %0|r\t%0, %1}";
15120 : : #else
15121 : : p = "r\t{%1, %0|%0, %1}"; /* st(r2) = st(0) op st(r2) */
15122 : : #endif
15123 : : }
15124 : : else
15125 : : {
15126 : : #if SYSV386_COMPAT
15127 : : p = "{r\t%2, %0|\t%0, %2}";
15128 : : #else
15129 : : p = "\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0) */
15130 : : #endif
15131 : : }
15132 : : break;
15133 : :
15134 : 0 : default:
15135 : 0 : gcc_unreachable ();
15136 : : }
15137 : :
15138 : 55469 : strcat (buf, p);
15139 : 55469 : return buf;
15140 : : }
15141 : :
15142 : : /* Return needed mode for entity in optimize_mode_switching pass. */
15143 : :
15144 : : static int
15145 : 1637 : ix86_dirflag_mode_needed (rtx_insn *insn)
15146 : : {
15147 : 1637 : if (CALL_P (insn))
15148 : : {
15149 : 337 : if (cfun->machine->func_type == TYPE_NORMAL)
15150 : : return X86_DIRFLAG_ANY;
15151 : : else
15152 : : /* No need to emit CLD in interrupt handler for TARGET_CLD. */
15153 : 337 : return TARGET_CLD ? X86_DIRFLAG_ANY : X86_DIRFLAG_RESET;
15154 : : }
15155 : :
15156 : 1300 : if (recog_memoized (insn) < 0)
15157 : : return X86_DIRFLAG_ANY;
15158 : :
15159 : 1298 : if (get_attr_type (insn) == TYPE_STR)
15160 : : {
15161 : : /* Emit cld instruction if stringops are used in the function. */
15162 : 1 : if (cfun->machine->func_type == TYPE_NORMAL)
15163 : 0 : return TARGET_CLD ? X86_DIRFLAG_RESET : X86_DIRFLAG_ANY;
15164 : : else
15165 : : return X86_DIRFLAG_RESET;
15166 : : }
15167 : :
15168 : : return X86_DIRFLAG_ANY;
15169 : : }
15170 : :
15171 : : /* Check if a 256bit or 512 bit AVX register is referenced inside of EXP. */
15172 : :
15173 : : static bool
15174 : 2118789 : ix86_check_avx_upper_register (const_rtx exp)
15175 : : {
15176 : : /* construct_container may return a parallel with expr_list
15177 : : which contains the real reg and mode */
15178 : 2118789 : subrtx_iterator::array_type array;
15179 : 8065038 : FOR_EACH_SUBRTX (iter, array, exp, NONCONST)
15180 : : {
15181 : 6099089 : const_rtx x = *iter;
15182 : 2458162 : if (SSE_REG_P (x)
15183 : 800989 : && !EXT_REX_SSE_REG_P (x)
15184 : 7689603 : && GET_MODE_BITSIZE (GET_MODE (x)) > 128)
15185 : 152840 : return true;
15186 : : }
15187 : :
15188 : 1965949 : return false;
15189 : 2118789 : }
15190 : :
15191 : : /* Check if a 256bit or 512bit AVX register is referenced in stores. */
15192 : :
15193 : : static void
15194 : 47728 : ix86_check_avx_upper_stores (rtx dest, const_rtx, void *data)
15195 : : {
15196 : 47728 : if (SSE_REG_P (dest)
15197 : 12509 : && !EXT_REX_SSE_REG_P (dest)
15198 : 72746 : && GET_MODE_BITSIZE (GET_MODE (dest)) > 128)
15199 : : {
15200 : 724 : bool *used = (bool *) data;
15201 : 724 : *used = true;
15202 : : }
15203 : 47728 : }
15204 : :
15205 : : /* Return needed mode for entity in optimize_mode_switching pass. */
15206 : :
15207 : : static int
15208 : 1987568 : ix86_avx_u128_mode_needed (rtx_insn *insn)
15209 : : {
15210 : 1987568 : if (DEBUG_INSN_P (insn))
15211 : : return AVX_U128_ANY;
15212 : :
15213 : 1987568 : if (CALL_P (insn))
15214 : : {
15215 : 46066 : rtx link;
15216 : :
15217 : : /* Needed mode is set to AVX_U128_CLEAN if there are
15218 : : no 256bit or 512bit modes used in function arguments. */
15219 : 46066 : for (link = CALL_INSN_FUNCTION_USAGE (insn);
15220 : 116098 : link;
15221 : 70032 : link = XEXP (link, 1))
15222 : : {
15223 : 71070 : if (GET_CODE (XEXP (link, 0)) == USE)
15224 : : {
15225 : 70127 : rtx arg = XEXP (XEXP (link, 0), 0);
15226 : :
15227 : 70127 : if (ix86_check_avx_upper_register (arg))
15228 : : return AVX_U128_DIRTY;
15229 : : }
15230 : : }
15231 : :
15232 : : /* Needed mode is set to AVX_U128_CLEAN if there are no 256bit
15233 : : nor 512bit registers used in the function return register. */
15234 : 45028 : bool avx_upper_reg_found = false;
15235 : 45028 : note_stores (insn, ix86_check_avx_upper_stores,
15236 : : &avx_upper_reg_found);
15237 : 45028 : if (avx_upper_reg_found)
15238 : : return AVX_U128_DIRTY;
15239 : :
15240 : : /* If the function is known to preserve some SSE registers,
15241 : : RA and previous passes can legitimately rely on that for
15242 : : modes wider than 256 bits. It's only safe to issue a
15243 : : vzeroupper if all SSE registers are clobbered. */
15244 : 44857 : const function_abi &abi = insn_callee_abi (insn);
15245 : 44857 : if (vzeroupper_pattern (PATTERN (insn), VOIDmode)
15246 : : /* Should be safe to issue an vzeroupper before sibling_call_p.
15247 : : Also there not mode_exit for sibling_call, so there could be
15248 : : missing vzeroupper for that. */
15249 : 44857 : || !(SIBLING_CALL_P (insn)
15250 : 43667 : || hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
15251 : 43667 : abi.mode_clobbers (V4DImode))))
15252 : 9150 : return AVX_U128_ANY;
15253 : :
15254 : 35707 : return AVX_U128_CLEAN;
15255 : : }
15256 : :
15257 : 1941502 : rtx set = single_set (insn);
15258 : 1941502 : if (set)
15259 : : {
15260 : 1873457 : rtx dest = SET_DEST (set);
15261 : 1873457 : rtx src = SET_SRC (set);
15262 : 1406841 : if (SSE_REG_P (dest)
15263 : 535235 : && !EXT_REX_SSE_REG_P (dest)
15264 : 2932771 : && GET_MODE_BITSIZE (GET_MODE (dest)) > 128)
15265 : : {
15266 : : /* This is an YMM/ZMM load. Return AVX_U128_DIRTY if the
15267 : : source isn't zero. */
15268 : 163808 : if (standard_sse_constant_p (src, GET_MODE (dest)) != 1)
15269 : : return AVX_U128_DIRTY;
15270 : : else
15271 : : return AVX_U128_ANY;
15272 : : }
15273 : : else
15274 : : {
15275 : 1709649 : if (ix86_check_avx_upper_register (src))
15276 : : return AVX_U128_DIRTY;
15277 : : }
15278 : :
15279 : : /* This isn't YMM/ZMM load/store. */
15280 : : return AVX_U128_ANY;
15281 : : }
15282 : :
15283 : : /* Require DIRTY mode if a 256bit or 512bit AVX register is referenced.
15284 : : Hardware changes state only when a 256bit register is written to,
15285 : : but we need to prevent the compiler from moving optimal insertion
15286 : : point above eventual read from 256bit or 512 bit register. */
15287 : 68045 : if (ix86_check_avx_upper_register (PATTERN (insn)))
15288 : : return AVX_U128_DIRTY;
15289 : :
15290 : : return AVX_U128_ANY;
15291 : : }
15292 : :
15293 : : /* Return mode that i387 must be switched into
15294 : : prior to the execution of insn. */
15295 : :
15296 : : static int
15297 : 465899 : ix86_i387_mode_needed (int entity, rtx_insn *insn)
15298 : : {
15299 : 465899 : enum attr_i387_cw mode;
15300 : :
15301 : : /* The mode UNINITIALIZED is used to store control word after a
15302 : : function call or ASM pattern. The mode ANY specify that function
15303 : : has no requirements on the control word and make no changes in the
15304 : : bits we are interested in. */
15305 : :
15306 : 465899 : if (CALL_P (insn)
15307 : 465899 : || (NONJUMP_INSN_P (insn)
15308 : 382623 : && (asm_noperands (PATTERN (insn)) >= 0
15309 : 382623 : || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
15310 : 17118 : return I387_CW_UNINITIALIZED;
15311 : :
15312 : 448781 : if (recog_memoized (insn) < 0)
15313 : : return I387_CW_ANY;
15314 : :
15315 : 447795 : mode = get_attr_i387_cw (insn);
15316 : :
15317 : 447795 : switch (entity)
15318 : : {
15319 : 0 : case I387_ROUNDEVEN:
15320 : 0 : if (mode == I387_CW_ROUNDEVEN)
15321 : : return mode;
15322 : : break;
15323 : :
15324 : 441818 : case I387_TRUNC:
15325 : 441818 : if (mode == I387_CW_TRUNC)
15326 : : return mode;
15327 : : break;
15328 : :
15329 : 4565 : case I387_FLOOR:
15330 : 4565 : if (mode == I387_CW_FLOOR)
15331 : : return mode;
15332 : : break;
15333 : :
15334 : 1412 : case I387_CEIL:
15335 : 1412 : if (mode == I387_CW_CEIL)
15336 : : return mode;
15337 : : break;
15338 : :
15339 : 0 : default:
15340 : 0 : gcc_unreachable ();
15341 : : }
15342 : :
15343 : : return I387_CW_ANY;
15344 : : }
15345 : :
15346 : : /* Return mode that entity must be switched into
15347 : : prior to the execution of insn. */
15348 : :
15349 : : static int
15350 : 2455104 : ix86_mode_needed (int entity, rtx_insn *insn, HARD_REG_SET)
15351 : : {
15352 : 2455104 : switch (entity)
15353 : : {
15354 : 1637 : case X86_DIRFLAG:
15355 : 1637 : return ix86_dirflag_mode_needed (insn);
15356 : 1987568 : case AVX_U128:
15357 : 1987568 : return ix86_avx_u128_mode_needed (insn);
15358 : 465899 : case I387_ROUNDEVEN:
15359 : 465899 : case I387_TRUNC:
15360 : 465899 : case I387_FLOOR:
15361 : 465899 : case I387_CEIL:
15362 : 465899 : return ix86_i387_mode_needed (entity, insn);
15363 : 0 : default:
15364 : 0 : gcc_unreachable ();
15365 : : }
15366 : : return 0;
15367 : : }
15368 : :
15369 : : /* Calculate mode of upper 128bit AVX registers after the insn. */
15370 : :
15371 : : static int
15372 : 1987568 : ix86_avx_u128_mode_after (int mode, rtx_insn *insn)
15373 : : {
15374 : 1987568 : rtx pat = PATTERN (insn);
15375 : :
15376 : 1987568 : if (vzeroupper_pattern (pat, VOIDmode)
15377 : 1987568 : || vzeroall_pattern (pat, VOIDmode))
15378 : 152 : return AVX_U128_CLEAN;
15379 : :
15380 : : /* We know that state is clean after CALL insn if there are no
15381 : : 256bit or 512bit registers used in the function return register. */
15382 : 1987416 : if (CALL_P (insn))
15383 : : {
15384 : 46020 : bool avx_upper_reg_found = false;
15385 : 46020 : note_stores (insn, ix86_check_avx_upper_stores, &avx_upper_reg_found);
15386 : :
15387 : 46020 : if (avx_upper_reg_found)
15388 : : return AVX_U128_DIRTY;
15389 : :
15390 : : /* If the function desn't clobber any sse registers or only clobber
15391 : : 128-bit part, Then vzeroupper isn't issued before the function exit.
15392 : : the status not CLEAN but ANY after the function. */
15393 : 45467 : const function_abi &abi = insn_callee_abi (insn);
15394 : 45467 : if (!(SIBLING_CALL_P (insn)
15395 : 44282 : || hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
15396 : 44282 : abi.mode_clobbers (V4DImode))))
15397 : 9446 : return AVX_U128_ANY;
15398 : :
15399 : 36021 : return AVX_U128_CLEAN;
15400 : : }
15401 : :
15402 : : /* Otherwise, return current mode. Remember that if insn
15403 : : references AVX 256bit or 512bit registers, the mode was already
15404 : : changed to DIRTY from MODE_NEEDED. */
15405 : : return mode;
15406 : : }
15407 : :
15408 : : /* Return the mode that an insn results in. */
15409 : :
15410 : : static int
15411 : 2454238 : ix86_mode_after (int entity, int mode, rtx_insn *insn, HARD_REG_SET)
15412 : : {
15413 : 2454238 : switch (entity)
15414 : : {
15415 : : case X86_DIRFLAG:
15416 : : return mode;
15417 : 1987568 : case AVX_U128:
15418 : 1987568 : return ix86_avx_u128_mode_after (mode, insn);
15419 : : case I387_ROUNDEVEN:
15420 : : case I387_TRUNC:
15421 : : case I387_FLOOR:
15422 : : case I387_CEIL:
15423 : : return mode;
15424 : 0 : default:
15425 : 0 : gcc_unreachable ();
15426 : : }
15427 : : }
15428 : :
15429 : : static int
15430 : 118 : ix86_dirflag_mode_entry (void)
15431 : : {
15432 : : /* For TARGET_CLD or in the interrupt handler we can't assume
15433 : : direction flag state at function entry. */
15434 : 118 : if (TARGET_CLD
15435 : 116 : || cfun->machine->func_type != TYPE_NORMAL)
15436 : 118 : return X86_DIRFLAG_ANY;
15437 : :
15438 : : return X86_DIRFLAG_RESET;
15439 : : }
15440 : :
15441 : : static int
15442 : 118445 : ix86_avx_u128_mode_entry (void)
15443 : : {
15444 : 118445 : tree arg;
15445 : :
15446 : : /* Entry mode is set to AVX_U128_DIRTY if there are
15447 : : 256bit or 512bit modes used in function arguments. */
15448 : 299029 : for (arg = DECL_ARGUMENTS (current_function_decl); arg;
15449 : 180584 : arg = TREE_CHAIN (arg))
15450 : : {
15451 : 214348 : rtx incoming = DECL_INCOMING_RTL (arg);
15452 : :
15453 : 214348 : if (incoming && ix86_check_avx_upper_register (incoming))
15454 : : return AVX_U128_DIRTY;
15455 : : }
15456 : :
15457 : : return AVX_U128_CLEAN;
15458 : : }
15459 : :
15460 : : /* Return a mode that ENTITY is assumed to be
15461 : : switched to at function entry. */
15462 : :
15463 : : static int
15464 : 73478 : ix86_mode_entry (int entity)
15465 : : {
15466 : 73478 : switch (entity)
15467 : : {
15468 : 118 : case X86_DIRFLAG:
15469 : 118 : return ix86_dirflag_mode_entry ();
15470 : 72188 : case AVX_U128:
15471 : 72188 : return ix86_avx_u128_mode_entry ();
15472 : : case I387_ROUNDEVEN:
15473 : : case I387_TRUNC:
15474 : : case I387_FLOOR:
15475 : : case I387_CEIL:
15476 : : return I387_CW_ANY;
15477 : 0 : default:
15478 : 0 : gcc_unreachable ();
15479 : : }
15480 : : }
15481 : :
15482 : : static int
15483 : 71023 : ix86_avx_u128_mode_exit (void)
15484 : : {
15485 : 71023 : rtx reg = crtl->return_rtx;
15486 : :
15487 : : /* Exit mode is set to AVX_U128_DIRTY if there are 256bit
15488 : : or 512 bit modes used in the function return register. */
15489 : 71023 : if (reg && ix86_check_avx_upper_register (reg))
15490 : : return AVX_U128_DIRTY;
15491 : :
15492 : : /* Exit mode is set to AVX_U128_DIRTY if there are 256bit or 512bit
15493 : : modes used in function arguments, otherwise return AVX_U128_CLEAN.
15494 : : */
15495 : 46257 : return ix86_avx_u128_mode_entry ();
15496 : : }
15497 : :
15498 : : /* Return a mode that ENTITY is assumed to be
15499 : : switched to at function exit. */
15500 : :
15501 : : static int
15502 : 72168 : ix86_mode_exit (int entity)
15503 : : {
15504 : 72168 : switch (entity)
15505 : : {
15506 : : case X86_DIRFLAG:
15507 : : return X86_DIRFLAG_ANY;
15508 : 71023 : case AVX_U128:
15509 : 71023 : return ix86_avx_u128_mode_exit ();
15510 : 1113 : case I387_ROUNDEVEN:
15511 : 1113 : case I387_TRUNC:
15512 : 1113 : case I387_FLOOR:
15513 : 1113 : case I387_CEIL:
15514 : 1113 : return I387_CW_ANY;
15515 : 0 : default:
15516 : 0 : gcc_unreachable ();
15517 : : }
15518 : : }
15519 : :
15520 : : static int
15521 : 2161543 : ix86_mode_priority (int, int n)
15522 : : {
15523 : 2161543 : return n;
15524 : : }
15525 : :
15526 : : /* Output code to initialize control word copies used by trunc?f?i and
15527 : : rounding patterns. CURRENT_MODE is set to current control word,
15528 : : while NEW_MODE is set to new control word. */
15529 : :
15530 : : static void
15531 : 3328 : emit_i387_cw_initialization (int mode)
15532 : : {
15533 : 3328 : rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
15534 : 3328 : rtx new_mode;
15535 : :
15536 : 3328 : enum ix86_stack_slot slot;
15537 : :
15538 : 3328 : rtx reg = gen_reg_rtx (HImode);
15539 : :
15540 : 3328 : emit_insn (gen_x86_fnstcw_1 (stored_mode));
15541 : 3328 : emit_move_insn (reg, copy_rtx (stored_mode));
15542 : :
15543 : 3328 : switch (mode)
15544 : : {
15545 : 0 : case I387_CW_ROUNDEVEN:
15546 : : /* round to nearest */
15547 : 0 : emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
15548 : 0 : slot = SLOT_CW_ROUNDEVEN;
15549 : 0 : break;
15550 : :
15551 : 3108 : case I387_CW_TRUNC:
15552 : : /* round toward zero (truncate) */
15553 : 3108 : emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
15554 : 3108 : slot = SLOT_CW_TRUNC;
15555 : 3108 : break;
15556 : :
15557 : 153 : case I387_CW_FLOOR:
15558 : : /* round down toward -oo */
15559 : 153 : emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
15560 : 153 : emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
15561 : 153 : slot = SLOT_CW_FLOOR;
15562 : 153 : break;
15563 : :
15564 : 67 : case I387_CW_CEIL:
15565 : : /* round up toward +oo */
15566 : 67 : emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
15567 : 67 : emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
15568 : 67 : slot = SLOT_CW_CEIL;
15569 : 67 : break;
15570 : :
15571 : 0 : default:
15572 : 0 : gcc_unreachable ();
15573 : : }
15574 : :
15575 : 3328 : gcc_assert (slot < MAX_386_STACK_LOCALS);
15576 : :
15577 : 3328 : new_mode = assign_386_stack_local (HImode, slot);
15578 : 3328 : emit_move_insn (new_mode, reg);
15579 : 3328 : }
15580 : :
15581 : : /* Generate one or more insns to set ENTITY to MODE. */
15582 : :
15583 : : static void
15584 : 45412 : ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
15585 : : HARD_REG_SET regs_live ATTRIBUTE_UNUSED)
15586 : : {
15587 : 45412 : switch (entity)
15588 : : {
15589 : 263 : case X86_DIRFLAG:
15590 : 263 : if (mode == X86_DIRFLAG_RESET)
15591 : 263 : emit_insn (gen_cld ());
15592 : : break;
15593 : 36361 : case AVX_U128:
15594 : 36361 : if (mode == AVX_U128_CLEAN)
15595 : 17566 : ix86_expand_avx_vzeroupper ();
15596 : : break;
15597 : 8788 : case I387_ROUNDEVEN:
15598 : 8788 : case I387_TRUNC:
15599 : 8788 : case I387_FLOOR:
15600 : 8788 : case I387_CEIL:
15601 : 8788 : if (mode != I387_CW_ANY
15602 : 8788 : && mode != I387_CW_UNINITIALIZED)
15603 : 3328 : emit_i387_cw_initialization (mode);
15604 : : break;
15605 : 0 : default:
15606 : 0 : gcc_unreachable ();
15607 : : }
15608 : 45412 : }
15609 : :
15610 : : /* Output code for INSN to convert a float to a signed int. OPERANDS
15611 : : are the insn operands. The output may be [HSD]Imode and the input
15612 : : operand may be [SDX]Fmode. */
15613 : :
15614 : : const char *
15615 : 7495 : output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp)
15616 : : {
15617 : 7495 : bool stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG);
15618 : 7495 : bool dimode_p = GET_MODE (operands[0]) == DImode;
15619 : 7495 : int round_mode = get_attr_i387_cw (insn);
15620 : :
15621 : 7495 : static char buf[40];
15622 : 7495 : const char *p;
15623 : :
15624 : : /* Jump through a hoop or two for DImode, since the hardware has no
15625 : : non-popping instruction. We used to do this a different way, but
15626 : : that was somewhat fragile and broke with post-reload splitters. */
15627 : 7495 : if ((dimode_p || fisttp) && !stack_top_dies)
15628 : 25 : output_asm_insn ("fld\t%y1", operands);
15629 : :
15630 : 7495 : gcc_assert (STACK_TOP_P (operands[1]));
15631 : 7495 : gcc_assert (MEM_P (operands[0]));
15632 : 7495 : gcc_assert (GET_MODE (operands[1]) != TFmode);
15633 : :
15634 : 7495 : if (fisttp)
15635 : : return "fisttp%Z0\t%0";
15636 : :
15637 : 7494 : strcpy (buf, "fist");
15638 : :
15639 : 7494 : if (round_mode != I387_CW_ANY)
15640 : 7446 : output_asm_insn ("fldcw\t%3", operands);
15641 : :
15642 : 7494 : p = "p%Z0\t%0";
15643 : 7494 : strcat (buf, p + !(stack_top_dies || dimode_p));
15644 : :
15645 : 7494 : output_asm_insn (buf, operands);
15646 : :
15647 : 7494 : if (round_mode != I387_CW_ANY)
15648 : 7446 : output_asm_insn ("fldcw\t%2", operands);
15649 : :
15650 : : return "";
15651 : : }
15652 : :
15653 : : /* Output code for x87 ffreep insn. The OPNO argument, which may only
15654 : : have the values zero or one, indicates the ffreep insn's operand
15655 : : from the OPERANDS array. */
15656 : :
15657 : : static const char *
15658 : 282649 : output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
15659 : : {
15660 : 0 : if (TARGET_USE_FFREEP)
15661 : : #ifdef HAVE_AS_IX86_FFREEP
15662 : 0 : return opno ? "ffreep\t%y1" : "ffreep\t%y0";
15663 : : #else
15664 : : {
15665 : : static char retval[32];
15666 : : int regno = REGNO (operands[opno]);
15667 : :
15668 : : gcc_assert (STACK_REGNO_P (regno));
15669 : :
15670 : : regno -= FIRST_STACK_REG;
15671 : :
15672 : : snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
15673 : : return retval;
15674 : : }
15675 : : #endif
15676 : :
15677 : 0 : return opno ? "fstp\t%y1" : "fstp\t%y0";
15678 : : }
15679 : :
15680 : :
15681 : : /* Output code for INSN to compare OPERANDS. EFLAGS_P is 1 when fcomi
15682 : : should be used. UNORDERED_P is true when fucom should be used. */
15683 : :
15684 : : const char *
15685 : 107851 : output_fp_compare (rtx_insn *insn, rtx *operands,
15686 : : bool eflags_p, bool unordered_p)
15687 : : {
15688 : 107851 : rtx *xops = eflags_p ? &operands[0] : &operands[1];
15689 : 107851 : bool stack_top_dies;
15690 : :
15691 : 107851 : static char buf[40];
15692 : 107851 : const char *p;
15693 : :
15694 : 107851 : gcc_assert (STACK_TOP_P (xops[0]));
15695 : :
15696 : 107851 : stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG);
15697 : :
15698 : 107851 : if (eflags_p)
15699 : : {
15700 : 107851 : p = unordered_p ? "fucomi" : "fcomi";
15701 : 107851 : strcpy (buf, p);
15702 : :
15703 : 107851 : p = "p\t{%y1, %0|%0, %y1}";
15704 : 107851 : strcat (buf, p + !stack_top_dies);
15705 : :
15706 : 107851 : return buf;
15707 : : }
15708 : :
15709 : 0 : if (STACK_REG_P (xops[1])
15710 : 0 : && stack_top_dies
15711 : 0 : && find_regno_note (insn, REG_DEAD, FIRST_STACK_REG + 1))
15712 : : {
15713 : 0 : gcc_assert (REGNO (xops[1]) == FIRST_STACK_REG + 1);
15714 : :
15715 : : /* If both the top of the 387 stack die, and the other operand
15716 : : is also a stack register that dies, then this must be a
15717 : : `fcompp' float compare. */
15718 : 0 : p = unordered_p ? "fucompp" : "fcompp";
15719 : 0 : strcpy (buf, p);
15720 : : }
15721 : 0 : else if (const0_operand (xops[1], VOIDmode))
15722 : : {
15723 : 0 : gcc_assert (!unordered_p);
15724 : 0 : strcpy (buf, "ftst");
15725 : : }
15726 : : else
15727 : : {
15728 : 0 : if (GET_MODE_CLASS (GET_MODE (xops[1])) == MODE_INT)
15729 : : {
15730 : 0 : gcc_assert (!unordered_p);
15731 : : p = "ficom";
15732 : : }
15733 : : else
15734 : 0 : p = unordered_p ? "fucom" : "fcom";
15735 : :
15736 : 0 : strcpy (buf, p);
15737 : :
15738 : 0 : p = "p%Z2\t%y2";
15739 : 0 : strcat (buf, p + !stack_top_dies);
15740 : : }
15741 : :
15742 : 0 : output_asm_insn (buf, operands);
15743 : 0 : return "fnstsw\t%0";
15744 : : }
15745 : :
15746 : : void
15747 : 146174 : ix86_output_addr_vec_elt (FILE *file, int value)
15748 : : {
15749 : 146174 : const char *directive = ASM_LONG;
15750 : :
15751 : : #ifdef ASM_QUAD
15752 : 146174 : if (TARGET_LP64)
15753 : 134416 : directive = ASM_QUAD;
15754 : : #else
15755 : : gcc_assert (!TARGET_64BIT);
15756 : : #endif
15757 : :
15758 : 146174 : fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
15759 : 146174 : }
15760 : :
15761 : : void
15762 : 23290 : ix86_output_addr_diff_elt (FILE *file, int value, int rel)
15763 : : {
15764 : 23290 : const char *directive = ASM_LONG;
15765 : :
15766 : : #ifdef ASM_QUAD
15767 : 34777 : if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
15768 : : directive = ASM_QUAD;
15769 : : #else
15770 : : gcc_assert (!TARGET_64BIT);
15771 : : #endif
15772 : : /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand. */
15773 : 23290 : if (TARGET_64BIT || TARGET_VXWORKS_RTP)
15774 : 11487 : fprintf (file, "%s%s%d-%s%d\n",
15775 : : directive, LPREFIX, value, LPREFIX, rel);
15776 : : #if TARGET_MACHO
15777 : : else if (TARGET_MACHO)
15778 : : {
15779 : : fprintf (file, ASM_LONG "%s%d-", LPREFIX, value);
15780 : : machopic_output_function_base_name (file);
15781 : : putc ('\n', file);
15782 : : }
15783 : : #endif
15784 : 11803 : else if (HAVE_AS_GOTOFF_IN_DATA)
15785 : 11803 : fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
15786 : : else
15787 : : asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
15788 : : GOT_SYMBOL_NAME, LPREFIX, value);
15789 : 23290 : }
15790 : :
15791 : : #define LEA_MAX_STALL (3)
15792 : : #define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1)
15793 : :
15794 : : /* Increase given DISTANCE in half-cycles according to
15795 : : dependencies between PREV and NEXT instructions.
15796 : : Add 1 half-cycle if there is no dependency and
15797 : : go to next cycle if there is some dependecy. */
15798 : :
15799 : : static unsigned int
15800 : 2266 : increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance)
15801 : : {
15802 : 2266 : df_ref def, use;
15803 : :
15804 : 2266 : if (!prev || !next)
15805 : 826 : return distance + (distance & 1) + 2;
15806 : :
15807 : 1440 : if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev))
15808 : 254 : return distance + 1;
15809 : :
15810 : 1974 : FOR_EACH_INSN_USE (use, next)
15811 : 2505 : FOR_EACH_INSN_DEF (def, prev)
15812 : 1717 : if (!DF_REF_IS_ARTIFICIAL (def)
15813 : 1717 : && DF_REF_REGNO (use) == DF_REF_REGNO (def))
15814 : 752 : return distance + (distance & 1) + 2;
15815 : :
15816 : 434 : return distance + 1;
15817 : : }
15818 : :
15819 : : /* Function checks if instruction INSN defines register number
15820 : : REGNO1 or REGNO2. */
15821 : :
15822 : : bool
15823 : 2220 : insn_defines_reg (unsigned int regno1, unsigned int regno2,
15824 : : rtx_insn *insn)
15825 : : {
15826 : 2220 : df_ref def;
15827 : :
15828 : 3978 : FOR_EACH_INSN_DEF (def, insn)
15829 : 2163 : if (DF_REF_REG_DEF_P (def)
15830 : 2163 : && !DF_REF_IS_ARTIFICIAL (def)
15831 : 2163 : && (regno1 == DF_REF_REGNO (def)
15832 : 1774 : || regno2 == DF_REF_REGNO (def)))
15833 : : return true;
15834 : :
15835 : : return false;
15836 : : }
15837 : :
15838 : : /* Function checks if instruction INSN uses register number
15839 : : REGNO as a part of address expression. */
15840 : :
15841 : : static bool
15842 : 1235 : insn_uses_reg_mem (unsigned int regno, rtx insn)
15843 : : {
15844 : 1235 : df_ref use;
15845 : :
15846 : 2620 : FOR_EACH_INSN_USE (use, insn)
15847 : 1466 : if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use))
15848 : : return true;
15849 : :
15850 : : return false;
15851 : : }
15852 : :
15853 : : /* Search backward for non-agu definition of register number REGNO1
15854 : : or register number REGNO2 in basic block starting from instruction
15855 : : START up to head of basic block or instruction INSN.
15856 : :
15857 : : Function puts true value into *FOUND var if definition was found
15858 : : and false otherwise.
15859 : :
15860 : : Distance in half-cycles between START and found instruction or head
15861 : : of BB is added to DISTANCE and returned. */
15862 : :
15863 : : static int
15864 : 658 : distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2,
15865 : : rtx_insn *insn, int distance,
15866 : : rtx_insn *start, bool *found)
15867 : : {
15868 : 658 : basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL;
15869 : 658 : rtx_insn *prev = start;
15870 : 658 : rtx_insn *next = NULL;
15871 : :
15872 : 658 : *found = false;
15873 : :
15874 : 658 : while (prev
15875 : 2013 : && prev != insn
15876 : 2013 : && distance < LEA_SEARCH_THRESHOLD)
15877 : : {
15878 : 1791 : if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev))
15879 : : {
15880 : 1031 : distance = increase_distance (prev, next, distance);
15881 : 1031 : if (insn_defines_reg (regno1, regno2, prev))
15882 : : {
15883 : 242 : if (recog_memoized (prev) < 0
15884 : 242 : || get_attr_type (prev) != TYPE_LEA)
15885 : : {
15886 : 207 : *found = true;
15887 : 207 : return distance;
15888 : : }
15889 : : }
15890 : :
15891 : : next = prev;
15892 : : }
15893 : 1584 : if (prev == BB_HEAD (bb))
15894 : : break;
15895 : :
15896 : 1355 : prev = PREV_INSN (prev);
15897 : : }
15898 : :
15899 : : return distance;
15900 : : }
15901 : :
15902 : : /* Search backward for non-agu definition of register number REGNO1
15903 : : or register number REGNO2 in INSN's basic block until
15904 : : 1. Pass LEA_SEARCH_THRESHOLD instructions, or
15905 : : 2. Reach neighbor BBs boundary, or
15906 : : 3. Reach agu definition.
15907 : : Returns the distance between the non-agu definition point and INSN.
15908 : : If no definition point, returns -1. */
15909 : :
15910 : : static int
15911 : 453 : distance_non_agu_define (unsigned int regno1, unsigned int regno2,
15912 : : rtx_insn *insn)
15913 : : {
15914 : 453 : basic_block bb = BLOCK_FOR_INSN (insn);
15915 : 453 : int distance = 0;
15916 : 453 : bool found = false;
15917 : :
15918 : 453 : if (insn != BB_HEAD (bb))
15919 : 453 : distance = distance_non_agu_define_in_bb (regno1, regno2, insn,
15920 : : distance, PREV_INSN (insn),
15921 : : &found);
15922 : :
15923 : 453 : if (!found && distance < LEA_SEARCH_THRESHOLD)
15924 : : {
15925 : 172 : edge e;
15926 : 172 : edge_iterator ei;
15927 : 172 : bool simple_loop = false;
15928 : :
15929 : 351 : FOR_EACH_EDGE (e, ei, bb->preds)
15930 : 221 : if (e->src == bb)
15931 : : {
15932 : : simple_loop = true;
15933 : : break;
15934 : : }
15935 : :
15936 : 172 : if (simple_loop)
15937 : 42 : distance = distance_non_agu_define_in_bb (regno1, regno2,
15938 : : insn, distance,
15939 : 42 : BB_END (bb), &found);
15940 : : else
15941 : : {
15942 : 130 : int shortest_dist = -1;
15943 : 130 : bool found_in_bb = false;
15944 : :
15945 : 293 : FOR_EACH_EDGE (e, ei, bb->preds)
15946 : : {
15947 : 163 : int bb_dist
15948 : 326 : = distance_non_agu_define_in_bb (regno1, regno2,
15949 : : insn, distance,
15950 : 163 : BB_END (e->src),
15951 : : &found_in_bb);
15952 : 163 : if (found_in_bb)
15953 : : {
15954 : 20 : if (shortest_dist < 0)
15955 : : shortest_dist = bb_dist;
15956 : 0 : else if (bb_dist > 0)
15957 : 0 : shortest_dist = MIN (bb_dist, shortest_dist);
15958 : :
15959 : 20 : found = true;
15960 : : }
15961 : : }
15962 : :
15963 : 130 : distance = shortest_dist;
15964 : : }
15965 : : }
15966 : :
15967 : 453 : if (!found)
15968 : : return -1;
15969 : :
15970 : 207 : return distance >> 1;
15971 : : }
15972 : :
15973 : : /* Return the distance in half-cycles between INSN and the next
15974 : : insn that uses register number REGNO in memory address added
15975 : : to DISTANCE. Return -1 if REGNO0 is set.
15976 : :
15977 : : Put true value into *FOUND if register usage was found and
15978 : : false otherwise.
15979 : : Put true value into *REDEFINED if register redefinition was
15980 : : found and false otherwise. */
15981 : :
15982 : : static int
15983 : 811 : distance_agu_use_in_bb (unsigned int regno,
15984 : : rtx_insn *insn, int distance, rtx_insn *start,
15985 : : bool *found, bool *redefined)
15986 : : {
15987 : 811 : basic_block bb = NULL;
15988 : 811 : rtx_insn *next = start;
15989 : 811 : rtx_insn *prev = NULL;
15990 : :
15991 : 811 : *found = false;
15992 : 811 : *redefined = false;
15993 : :
15994 : 811 : if (start != NULL_RTX)
15995 : : {
15996 : 794 : bb = BLOCK_FOR_INSN (start);
15997 : 794 : if (start != BB_HEAD (bb))
15998 : : /* If insn and start belong to the same bb, set prev to insn,
15999 : : so the call to increase_distance will increase the distance
16000 : : between insns by 1. */
16001 : 424 : prev = insn;
16002 : : }
16003 : :
16004 : 2725 : while (next
16005 : 2725 : && next != insn
16006 : 2725 : && distance < LEA_SEARCH_THRESHOLD)
16007 : : {
16008 : 2517 : if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next))
16009 : : {
16010 : 1235 : distance = increase_distance(prev, next, distance);
16011 : 1235 : if (insn_uses_reg_mem (regno, next))
16012 : : {
16013 : : /* Return DISTANCE if OP0 is used in memory
16014 : : address in NEXT. */
16015 : 81 : *found = true;
16016 : 81 : return distance;
16017 : : }
16018 : :
16019 : 1154 : if (insn_defines_reg (regno, INVALID_REGNUM, next))
16020 : : {
16021 : : /* Return -1 if OP0 is set in NEXT. */
16022 : 158 : *redefined = true;
16023 : 158 : return -1;
16024 : : }
16025 : :
16026 : : prev = next;
16027 : : }
16028 : :
16029 : 2278 : if (next == BB_END (bb))
16030 : : break;
16031 : :
16032 : 1914 : next = NEXT_INSN (next);
16033 : : }
16034 : :
16035 : : return distance;
16036 : : }
16037 : :
16038 : : /* Return the distance between INSN and the next insn that uses
16039 : : register number REGNO0 in memory address. Return -1 if no such
16040 : : a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set. */
16041 : :
16042 : : static int
16043 : 453 : distance_agu_use (unsigned int regno0, rtx_insn *insn)
16044 : : {
16045 : 453 : basic_block bb = BLOCK_FOR_INSN (insn);
16046 : 453 : int distance = 0;
16047 : 453 : bool found = false;
16048 : 453 : bool redefined = false;
16049 : :
16050 : 453 : if (insn != BB_END (bb))
16051 : 424 : distance = distance_agu_use_in_bb (regno0, insn, distance,
16052 : : NEXT_INSN (insn),
16053 : : &found, &redefined);
16054 : :
16055 : 453 : if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD)
16056 : : {
16057 : 276 : edge e;
16058 : 276 : edge_iterator ei;
16059 : 276 : bool simple_loop = false;
16060 : :
16061 : 587 : FOR_EACH_EDGE (e, ei, bb->succs)
16062 : 387 : if (e->dest == bb)
16063 : : {
16064 : : simple_loop = true;
16065 : : break;
16066 : : }
16067 : :
16068 : 276 : if (simple_loop)
16069 : 76 : distance = distance_agu_use_in_bb (regno0, insn,
16070 : : distance, BB_HEAD (bb),
16071 : : &found, &redefined);
16072 : : else
16073 : : {
16074 : 200 : int shortest_dist = -1;
16075 : 200 : bool found_in_bb = false;
16076 : 200 : bool redefined_in_bb = false;
16077 : :
16078 : 511 : FOR_EACH_EDGE (e, ei, bb->succs)
16079 : : {
16080 : 311 : int bb_dist
16081 : 622 : = distance_agu_use_in_bb (regno0, insn,
16082 : 311 : distance, BB_HEAD (e->dest),
16083 : : &found_in_bb, &redefined_in_bb);
16084 : 311 : if (found_in_bb)
16085 : : {
16086 : 16 : if (shortest_dist < 0)
16087 : : shortest_dist = bb_dist;
16088 : 2 : else if (bb_dist > 0)
16089 : 2 : shortest_dist = MIN (bb_dist, shortest_dist);
16090 : :
16091 : 16 : found = true;
16092 : : }
16093 : : }
16094 : :
16095 : 200 : distance = shortest_dist;
16096 : : }
16097 : : }
16098 : :
16099 : 453 : if (!found || redefined)
16100 : : return -1;
16101 : :
16102 : 79 : return distance >> 1;
16103 : : }
16104 : :
16105 : : /* Define this macro to tune LEA priority vs ADD, it take effect when
16106 : : there is a dilemma of choosing LEA or ADD
16107 : : Negative value: ADD is more preferred than LEA
16108 : : Zero: Neutral
16109 : : Positive value: LEA is more preferred than ADD. */
16110 : : #define IX86_LEA_PRIORITY 0
16111 : :
16112 : : /* Return true if usage of lea INSN has performance advantage
16113 : : over a sequence of instructions. Instructions sequence has
16114 : : SPLIT_COST cycles higher latency than lea latency. */
16115 : :
16116 : : static bool
16117 : 1662 : ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
16118 : : unsigned int regno2, int split_cost, bool has_scale)
16119 : : {
16120 : 1662 : int dist_define, dist_use;
16121 : :
16122 : : /* For Atom processors newer than Bonnell, if using a 2-source or
16123 : : 3-source LEA for non-destructive destination purposes, or due to
16124 : : wanting ability to use SCALE, the use of LEA is justified. */
16125 : 1662 : if (!TARGET_CPU_P (BONNELL))
16126 : : {
16127 : 1209 : if (has_scale)
16128 : : return true;
16129 : 1192 : if (split_cost < 1)
16130 : : return false;
16131 : 419 : if (regno0 == regno1 || regno0 == regno2)
16132 : : return false;
16133 : : return true;
16134 : : }
16135 : :
16136 : : /* Remember recog_data content. */
16137 : 453 : struct recog_data_d recog_data_save = recog_data;
16138 : :
16139 : 453 : dist_define = distance_non_agu_define (regno1, regno2, insn);
16140 : 453 : dist_use = distance_agu_use (regno0, insn);
16141 : :
16142 : : /* distance_non_agu_define can call get_attr_type which can call
16143 : : recog_memoized, restore recog_data back to previous content. */
16144 : 453 : recog_data = recog_data_save;
16145 : :
16146 : 453 : if (dist_define < 0 || dist_define >= LEA_MAX_STALL)
16147 : : {
16148 : : /* If there is no non AGU operand definition, no AGU
16149 : : operand usage and split cost is 0 then both lea
16150 : : and non lea variants have same priority. Currently
16151 : : we prefer lea for 64 bit code and non lea on 32 bit
16152 : : code. */
16153 : 251 : if (dist_use < 0 && split_cost == 0)
16154 : 129 : return TARGET_64BIT || IX86_LEA_PRIORITY;
16155 : : else
16156 : : return true;
16157 : : }
16158 : :
16159 : : /* With longer definitions distance lea is more preferable.
16160 : : Here we change it to take into account splitting cost and
16161 : : lea priority. */
16162 : 202 : dist_define += split_cost + IX86_LEA_PRIORITY;
16163 : :
16164 : : /* If there is no use in memory addess then we just check
16165 : : that split cost exceeds AGU stall. */
16166 : 202 : if (dist_use < 0)
16167 : 199 : return dist_define > LEA_MAX_STALL;
16168 : :
16169 : : /* If this insn has both backward non-agu dependence and forward
16170 : : agu dependence, the one with short distance takes effect. */
16171 : 3 : return dist_define >= dist_use;
16172 : : }
16173 : :
16174 : : /* Return true if we need to split op0 = op1 + op2 into a sequence of
16175 : : move and add to avoid AGU stalls. */
16176 : :
16177 : : bool
16178 : 8932836 : ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[])
16179 : : {
16180 : 8932836 : unsigned int regno0, regno1, regno2;
16181 : :
16182 : : /* Check if we need to optimize. */
16183 : 8932836 : if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
16184 : 8931949 : return false;
16185 : :
16186 : 887 : regno0 = true_regnum (operands[0]);
16187 : 887 : regno1 = true_regnum (operands[1]);
16188 : 887 : regno2 = true_regnum (operands[2]);
16189 : :
16190 : : /* We need to split only adds with non destructive
16191 : : destination operand. */
16192 : 887 : if (regno0 == regno1 || regno0 == regno2)
16193 : : return false;
16194 : : else
16195 : 265 : return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false);
16196 : : }
16197 : :
16198 : : /* Return true if we should emit lea instruction instead of mov
16199 : : instruction. */
16200 : :
16201 : : bool
16202 : 28263316 : ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[])
16203 : : {
16204 : 28263316 : unsigned int regno0, regno1;
16205 : :
16206 : : /* Check if we need to optimize. */
16207 : 28263316 : if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
16208 : 28261233 : return false;
16209 : :
16210 : : /* Use lea for reg to reg moves only. */
16211 : 2083 : if (!REG_P (operands[0]) || !REG_P (operands[1]))
16212 : : return false;
16213 : :
16214 : 424 : regno0 = true_regnum (operands[0]);
16215 : 424 : regno1 = true_regnum (operands[1]);
16216 : :
16217 : 424 : return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false);
16218 : : }
16219 : :
16220 : : /* Return true if we need to split lea into a sequence of
16221 : : instructions to avoid AGU stalls during peephole2. */
16222 : :
16223 : : bool
16224 : 11202775 : ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
16225 : : {
16226 : 11202775 : unsigned int regno0, regno1, regno2;
16227 : 11202775 : int split_cost;
16228 : 11202775 : struct ix86_address parts;
16229 : 11202775 : int ok;
16230 : :
16231 : : /* The "at least two components" test below might not catch simple
16232 : : move or zero extension insns if parts.base is non-NULL and parts.disp
16233 : : is const0_rtx as the only components in the address, e.g. if the
16234 : : register is %rbp or %r13. As this test is much cheaper and moves or
16235 : : zero extensions are the common case, do this check first. */
16236 : 11202775 : if (REG_P (operands[1])
16237 : 11202775 : || (SImode_address_operand (operands[1], VOIDmode)
16238 : 100442 : && REG_P (XEXP (operands[1], 0))))
16239 : 4180888 : return false;
16240 : :
16241 : 7021887 : ok = ix86_decompose_address (operands[1], &parts);
16242 : 7021887 : gcc_assert (ok);
16243 : :
16244 : : /* There should be at least two components in the address. */
16245 : 7021887 : if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX)
16246 : 7021887 : + (parts.disp != NULL_RTX) + (parts.scale > 1) < 2)
16247 : : return false;
16248 : :
16249 : : /* We should not split into add if non legitimate pic
16250 : : operand is used as displacement. */
16251 : 2637046 : if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp))
16252 : : return false;
16253 : :
16254 : 2587992 : regno0 = true_regnum (operands[0]) ;
16255 : 2587992 : regno1 = INVALID_REGNUM;
16256 : 2587992 : regno2 = INVALID_REGNUM;
16257 : :
16258 : 2587992 : if (parts.base)
16259 : 2520941 : regno1 = true_regnum (parts.base);
16260 : 2587992 : if (parts.index)
16261 : 452748 : regno2 = true_regnum (parts.index);
16262 : :
16263 : : /* Use add for a = a + b and a = b + a since it is faster and shorter
16264 : : than lea for most processors. For the processors like BONNELL, if
16265 : : the destination register of LEA holds an actual address which will
16266 : : be used soon, LEA is better and otherwise ADD is better. */
16267 : 2587992 : if (!TARGET_CPU_P (BONNELL)
16268 : 2587858 : && parts.scale == 1
16269 : 2356184 : && (!parts.disp || parts.disp == const0_rtx)
16270 : 165413 : && (regno0 == regno1 || regno0 == regno2))
16271 : : return true;
16272 : :
16273 : : /* Split with -Oz if the encoding requires fewer bytes. */
16274 : 2583244 : if (optimize_size > 1
16275 : 27 : && parts.scale > 1
16276 : 4 : && !parts.base
16277 : 4 : && (!parts.disp || parts.disp == const0_rtx))
16278 : : return true;
16279 : :
16280 : : /* Check we need to optimize. */
16281 : 2583240 : if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
16282 : 2582904 : return false;
16283 : :
16284 : 336 : split_cost = 0;
16285 : :
16286 : : /* Compute how many cycles we will add to execution time
16287 : : if split lea into a sequence of instructions. */
16288 : 336 : if (parts.base || parts.index)
16289 : : {
16290 : : /* Have to use mov instruction if non desctructive
16291 : : destination form is used. */
16292 : 336 : if (regno1 != regno0 && regno2 != regno0)
16293 : 247 : split_cost += 1;
16294 : :
16295 : : /* Have to add index to base if both exist. */
16296 : 336 : if (parts.base && parts.index)
16297 : 51 : split_cost += 1;
16298 : :
16299 : : /* Have to use shift and adds if scale is 2 or greater. */
16300 : 336 : if (parts.scale > 1)
16301 : : {
16302 : 24 : if (regno0 != regno1)
16303 : 17 : split_cost += 1;
16304 : 7 : else if (regno2 == regno0)
16305 : 1 : split_cost += 4;
16306 : : else
16307 : 6 : split_cost += parts.scale;
16308 : : }
16309 : :
16310 : : /* Have to use add instruction with immediate if
16311 : : disp is non zero. */
16312 : 336 : if (parts.disp && parts.disp != const0_rtx)
16313 : 283 : split_cost += 1;
16314 : :
16315 : : /* Subtract the price of lea. */
16316 : 336 : split_cost -= 1;
16317 : : }
16318 : :
16319 : 336 : return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost,
16320 : 336 : parts.scale > 1);
16321 : : }
16322 : :
16323 : : /* Return true if it is ok to optimize an ADD operation to LEA
16324 : : operation to avoid flag register consumation. For most processors,
16325 : : ADD is faster than LEA. For the processors like BONNELL, if the
16326 : : destination register of LEA holds an actual address which will be
16327 : : used soon, LEA is better and otherwise ADD is better. */
16328 : :
16329 : : bool
16330 : 8990520 : ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[])
16331 : : {
16332 : 8990520 : unsigned int regno0 = true_regnum (operands[0]);
16333 : 8990520 : unsigned int regno1 = true_regnum (operands[1]);
16334 : 8990520 : unsigned int regno2 = true_regnum (operands[2]);
16335 : :
16336 : : /* If a = b + c, (a!=b && a!=c), must use lea form. */
16337 : 8990520 : if (regno0 != regno1 && regno0 != regno2)
16338 : : return true;
16339 : :
16340 : 6976052 : if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
16341 : 6975415 : return false;
16342 : :
16343 : 637 : return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false);
16344 : : }
16345 : :
16346 : : /* Return true if destination reg of SET_BODY is shift count of
16347 : : USE_BODY. */
16348 : :
16349 : : static bool
16350 : 215 : ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
16351 : : {
16352 : 215 : rtx set_dest;
16353 : 215 : rtx shift_rtx;
16354 : 215 : int i;
16355 : :
16356 : : /* Retrieve destination of SET_BODY. */
16357 : 215 : switch (GET_CODE (set_body))
16358 : : {
16359 : 181 : case SET:
16360 : 181 : set_dest = SET_DEST (set_body);
16361 : 181 : if (!set_dest || !REG_P (set_dest))
16362 : : return false;
16363 : 180 : break;
16364 : 17 : case PARALLEL:
16365 : 51 : for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
16366 : 34 : if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
16367 : : use_body))
16368 : : return true;
16369 : : /* FALLTHROUGH */
16370 : : default:
16371 : : return false;
16372 : : }
16373 : :
16374 : : /* Retrieve shift count of USE_BODY. */
16375 : 180 : switch (GET_CODE (use_body))
16376 : : {
16377 : 60 : case SET:
16378 : 60 : shift_rtx = XEXP (use_body, 1);
16379 : 60 : break;
16380 : 60 : case PARALLEL:
16381 : 180 : for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
16382 : 120 : if (ix86_dep_by_shift_count_body (set_body,
16383 : 120 : XVECEXP (use_body, 0, i)))
16384 : : return true;
16385 : : /* FALLTHROUGH */
16386 : : default:
16387 : : return false;
16388 : : }
16389 : :
16390 : 60 : if (shift_rtx
16391 : 60 : && (GET_CODE (shift_rtx) == ASHIFT
16392 : 45 : || GET_CODE (shift_rtx) == LSHIFTRT
16393 : 23 : || GET_CODE (shift_rtx) == ASHIFTRT
16394 : 12 : || GET_CODE (shift_rtx) == ROTATE
16395 : 12 : || GET_CODE (shift_rtx) == ROTATERT))
16396 : : {
16397 : 48 : rtx shift_count = XEXP (shift_rtx, 1);
16398 : :
16399 : : /* Return true if shift count is dest of SET_BODY. */
16400 : 48 : if (REG_P (shift_count))
16401 : : {
16402 : : /* Add check since it can be invoked before register
16403 : : allocation in pre-reload schedule. */
16404 : 0 : if (reload_completed
16405 : 0 : && true_regnum (set_dest) == true_regnum (shift_count))
16406 : : return true;
16407 : 0 : else if (REGNO(set_dest) == REGNO(shift_count))
16408 : : return true;
16409 : : }
16410 : : }
16411 : :
16412 : : return false;
16413 : : }
16414 : :
16415 : : /* Return true if destination reg of SET_INSN is shift count of
16416 : : USE_INSN. */
16417 : :
16418 : : bool
16419 : 61 : ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
16420 : : {
16421 : 61 : return ix86_dep_by_shift_count_body (PATTERN (set_insn),
16422 : 61 : PATTERN (use_insn));
16423 : : }
16424 : :
16425 : : /* Return TRUE if the operands to a vec_interleave_{high,low}v2df
16426 : : are ok, keeping in mind the possible movddup alternative. */
16427 : :
16428 : : bool
16429 : 87519 : ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high)
16430 : : {
16431 : 87519 : if (MEM_P (operands[0]))
16432 : 2091 : return rtx_equal_p (operands[0], operands[1 + high]);
16433 : 85428 : if (MEM_P (operands[1]) && MEM_P (operands[2]))
16434 : 909 : return false;
16435 : : return true;
16436 : : }
16437 : :
16438 : : /* A subroutine of ix86_build_signbit_mask. If VECT is true,
16439 : : then replicate the value for all elements of the vector
16440 : : register. */
16441 : :
16442 : : rtx
16443 : 74547 : ix86_build_const_vector (machine_mode mode, bool vect, rtx value)
16444 : : {
16445 : 74547 : int i, n_elt;
16446 : 74547 : rtvec v;
16447 : 74547 : machine_mode scalar_mode;
16448 : :
16449 : 74547 : switch (mode)
16450 : : {
16451 : 1043 : case E_V64QImode:
16452 : 1043 : case E_V32QImode:
16453 : 1043 : case E_V16QImode:
16454 : 1043 : case E_V32HImode:
16455 : 1043 : case E_V16HImode:
16456 : 1043 : case E_V8HImode:
16457 : 1043 : case E_V16SImode:
16458 : 1043 : case E_V8SImode:
16459 : 1043 : case E_V4SImode:
16460 : 1043 : case E_V2SImode:
16461 : 1043 : case E_V8DImode:
16462 : 1043 : case E_V4DImode:
16463 : 1043 : case E_V2DImode:
16464 : 1043 : gcc_assert (vect);
16465 : : /* FALLTHRU */
16466 : 74547 : case E_V2HFmode:
16467 : 74547 : case E_V4HFmode:
16468 : 74547 : case E_V8HFmode:
16469 : 74547 : case E_V16HFmode:
16470 : 74547 : case E_V32HFmode:
16471 : 74547 : case E_V16SFmode:
16472 : 74547 : case E_V8SFmode:
16473 : 74547 : case E_V4SFmode:
16474 : 74547 : case E_V2SFmode:
16475 : 74547 : case E_V8DFmode:
16476 : 74547 : case E_V4DFmode:
16477 : 74547 : case E_V2DFmode:
16478 : 74547 : case E_V32BFmode:
16479 : 74547 : case E_V16BFmode:
16480 : 74547 : case E_V8BFmode:
16481 : 74547 : case E_V4BFmode:
16482 : 74547 : case E_V2BFmode:
16483 : 74547 : n_elt = GET_MODE_NUNITS (mode);
16484 : 74547 : v = rtvec_alloc (n_elt);
16485 : 74547 : scalar_mode = GET_MODE_INNER (mode);
16486 : :
16487 : 74547 : RTVEC_ELT (v, 0) = value;
16488 : :
16489 : 230960 : for (i = 1; i < n_elt; ++i)
16490 : 156413 : RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode);
16491 : :
16492 : 74547 : return gen_rtx_CONST_VECTOR (mode, v);
16493 : :
16494 : 0 : default:
16495 : 0 : gcc_unreachable ();
16496 : : }
16497 : : }
16498 : :
16499 : : /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
16500 : : and ix86_expand_int_vcond. Create a mask for the sign bit in MODE
16501 : : for an SSE register. If VECT is true, then replicate the mask for
16502 : : all elements of the vector register. If INVERT is true, then create
16503 : : a mask excluding the sign bit. */
16504 : :
16505 : : rtx
16506 : 53567 : ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert)
16507 : : {
16508 : 53567 : machine_mode vec_mode, imode;
16509 : 53567 : wide_int w;
16510 : 53567 : rtx mask, v;
16511 : :
16512 : 53567 : switch (mode)
16513 : : {
16514 : : case E_V2HFmode:
16515 : : case E_V4HFmode:
16516 : : case E_V8HFmode:
16517 : : case E_V16HFmode:
16518 : : case E_V32HFmode:
16519 : : case E_V32BFmode:
16520 : : case E_V16BFmode:
16521 : : case E_V8BFmode:
16522 : : case E_V4BFmode:
16523 : : case E_V2BFmode:
16524 : : vec_mode = mode;
16525 : : imode = HImode;
16526 : : break;
16527 : :
16528 : 23081 : case E_V16SImode:
16529 : 23081 : case E_V16SFmode:
16530 : 23081 : case E_V8SImode:
16531 : 23081 : case E_V4SImode:
16532 : 23081 : case E_V8SFmode:
16533 : 23081 : case E_V4SFmode:
16534 : 23081 : case E_V2SFmode:
16535 : 23081 : case E_V2SImode:
16536 : 23081 : vec_mode = mode;
16537 : 23081 : imode = SImode;
16538 : 23081 : break;
16539 : :
16540 : 27560 : case E_V8DImode:
16541 : 27560 : case E_V4DImode:
16542 : 27560 : case E_V2DImode:
16543 : 27560 : case E_V8DFmode:
16544 : 27560 : case E_V4DFmode:
16545 : 27560 : case E_V2DFmode:
16546 : 27560 : vec_mode = mode;
16547 : 27560 : imode = DImode;
16548 : 27560 : break;
16549 : :
16550 : 2526 : case E_TImode:
16551 : 2526 : case E_TFmode:
16552 : 2526 : vec_mode = VOIDmode;
16553 : 2526 : imode = TImode;
16554 : 2526 : break;
16555 : :
16556 : 0 : default:
16557 : 0 : gcc_unreachable ();
16558 : : }
16559 : :
16560 : 53567 : machine_mode inner_mode = GET_MODE_INNER (mode);
16561 : 107134 : w = wi::set_bit_in_zero (GET_MODE_BITSIZE (inner_mode) - 1,
16562 : 107134 : GET_MODE_BITSIZE (inner_mode));
16563 : 53567 : if (invert)
16564 : 17377 : w = wi::bit_not (w);
16565 : :
16566 : : /* Force this value into the low part of a fp vector constant. */
16567 : 53567 : mask = immed_wide_int_const (w, imode);
16568 : 53567 : mask = gen_lowpart (inner_mode, mask);
16569 : :
16570 : 53567 : if (vec_mode == VOIDmode)
16571 : 2526 : return force_reg (inner_mode, mask);
16572 : :
16573 : 51041 : v = ix86_build_const_vector (vec_mode, vect, mask);
16574 : 51041 : return force_reg (vec_mode, v);
16575 : 53567 : }
16576 : :
16577 : : /* Return HOST_WIDE_INT for const vector OP in MODE. */
16578 : :
16579 : : HOST_WIDE_INT
16580 : 153474 : ix86_convert_const_vector_to_integer (rtx op, machine_mode mode)
16581 : : {
16582 : 328517 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
16583 : 0 : gcc_unreachable ();
16584 : :
16585 : 153474 : int nunits = GET_MODE_NUNITS (mode);
16586 : 306948 : wide_int val = wi::zero (GET_MODE_BITSIZE (mode));
16587 : 153474 : machine_mode innermode = GET_MODE_INNER (mode);
16588 : 153474 : unsigned int innermode_bits = GET_MODE_BITSIZE (innermode);
16589 : :
16590 : 153474 : switch (mode)
16591 : : {
16592 : : case E_V2QImode:
16593 : : case E_V4QImode:
16594 : : case E_V2HImode:
16595 : : case E_V8QImode:
16596 : : case E_V4HImode:
16597 : : case E_V2SImode:
16598 : 520765 : for (int i = 0; i < nunits; ++i)
16599 : : {
16600 : 369534 : int v = INTVAL (XVECEXP (op, 0, i));
16601 : 369534 : wide_int wv = wi::shwi (v, innermode_bits);
16602 : 369534 : val = wi::insert (val, wv, innermode_bits * i, innermode_bits);
16603 : 369534 : }
16604 : : break;
16605 : : case E_V2HFmode:
16606 : : case E_V2BFmode:
16607 : : case E_V4HFmode:
16608 : : case E_V4BFmode:
16609 : : case E_V2SFmode:
16610 : 6739 : for (int i = 0; i < nunits; ++i)
16611 : : {
16612 : 4496 : rtx x = XVECEXP (op, 0, i);
16613 : 4496 : int v = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x),
16614 : 4496 : REAL_MODE_FORMAT (innermode));
16615 : 4496 : wide_int wv = wi::shwi (v, innermode_bits);
16616 : 4496 : val = wi::insert (val, wv, innermode_bits * i, innermode_bits);
16617 : 4496 : }
16618 : : break;
16619 : 0 : default:
16620 : 0 : gcc_unreachable ();
16621 : : }
16622 : :
16623 : 153474 : return val.to_shwi ();
16624 : 153474 : }
16625 : :
16626 : 32 : int ix86_get_flags_cc (rtx_code code)
16627 : : {
16628 : 32 : switch (code)
16629 : : {
16630 : : case NE: return X86_CCNE;
16631 : : case EQ: return X86_CCE;
16632 : : case GE: return X86_CCNL;
16633 : : case GT: return X86_CCNLE;
16634 : : case LE: return X86_CCLE;
16635 : : case LT: return X86_CCL;
16636 : : case GEU: return X86_CCNB;
16637 : : case GTU: return X86_CCNBE;
16638 : : case LEU: return X86_CCBE;
16639 : : case LTU: return X86_CCB;
16640 : : default: return -1;
16641 : : }
16642 : : }
16643 : :
16644 : : /* Return TRUE or FALSE depending on whether the first SET in INSN
16645 : : has source and destination with matching CC modes, and that the
16646 : : CC mode is at least as constrained as REQ_MODE. */
16647 : :
16648 : : bool
16649 : 52866648 : ix86_match_ccmode (rtx insn, machine_mode req_mode)
16650 : : {
16651 : 52866648 : rtx set;
16652 : 52866648 : machine_mode set_mode;
16653 : :
16654 : 52866648 : set = PATTERN (insn);
16655 : 52866648 : if (GET_CODE (set) == PARALLEL)
16656 : 446067 : set = XVECEXP (set, 0, 0);
16657 : 52866648 : gcc_assert (GET_CODE (set) == SET);
16658 : 52866648 : gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
16659 : :
16660 : 52866648 : set_mode = GET_MODE (SET_DEST (set));
16661 : 52866648 : switch (set_mode)
16662 : : {
16663 : 1339881 : case E_CCNOmode:
16664 : 1339881 : if (req_mode != CCNOmode
16665 : 60755 : && (req_mode != CCmode
16666 : 0 : || XEXP (SET_SRC (set), 1) != const0_rtx))
16667 : : return false;
16668 : : break;
16669 : 5140753 : case E_CCmode:
16670 : 5140753 : if (req_mode == CCGCmode)
16671 : : return false;
16672 : : /* FALLTHRU */
16673 : 8818112 : case E_CCGCmode:
16674 : 8818112 : if (req_mode == CCGOCmode || req_mode == CCNOmode)
16675 : : return false;
16676 : : /* FALLTHRU */
16677 : 9881721 : case E_CCGOCmode:
16678 : 9881721 : if (req_mode == CCZmode)
16679 : : return false;
16680 : : /* FALLTHRU */
16681 : : case E_CCZmode:
16682 : : break;
16683 : :
16684 : 0 : case E_CCGZmode:
16685 : :
16686 : 0 : case E_CCAmode:
16687 : 0 : case E_CCCmode:
16688 : 0 : case E_CCOmode:
16689 : 0 : case E_CCPmode:
16690 : 0 : case E_CCSmode:
16691 : 0 : if (set_mode != req_mode)
16692 : : return false;
16693 : : break;
16694 : :
16695 : 0 : default:
16696 : 0 : gcc_unreachable ();
16697 : : }
16698 : :
16699 : 52797118 : return GET_MODE (SET_SRC (set)) == set_mode;
16700 : : }
16701 : :
16702 : : machine_mode
16703 : 13223186 : ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
16704 : : {
16705 : 13223186 : machine_mode mode = GET_MODE (op0);
16706 : :
16707 : 13223186 : if (SCALAR_FLOAT_MODE_P (mode))
16708 : : {
16709 : 124256 : gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
16710 : : return CCFPmode;
16711 : : }
16712 : :
16713 : 13098930 : switch (code)
16714 : : {
16715 : : /* Only zero flag is needed. */
16716 : : case EQ: /* ZF=0 */
16717 : : case NE: /* ZF!=0 */
16718 : : return CCZmode;
16719 : : /* Codes needing carry flag. */
16720 : 938867 : case GEU: /* CF=0 */
16721 : 938867 : case LTU: /* CF=1 */
16722 : 938867 : rtx geu;
16723 : : /* Detect overflow checks. They need just the carry flag. */
16724 : 938867 : if (GET_CODE (op0) == PLUS
16725 : 938867 : && (rtx_equal_p (op1, XEXP (op0, 0))
16726 : 105402 : || rtx_equal_p (op1, XEXP (op0, 1))))
16727 : 17123 : return CCCmode;
16728 : : /* Similarly for *setcc_qi_addqi3_cconly_overflow_1_* patterns.
16729 : : Match LTU of op0
16730 : : (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))
16731 : : and op1
16732 : : (ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))
16733 : : where CC_CCC is either CC or CCC. */
16734 : 921744 : else if (code == LTU
16735 : 347091 : && GET_CODE (op0) == NEG
16736 : 5023 : && GET_CODE (geu = XEXP (op0, 0)) == GEU
16737 : 3651 : && REG_P (XEXP (geu, 0))
16738 : 3329 : && (GET_MODE (XEXP (geu, 0)) == CCCmode
16739 : 37 : || GET_MODE (XEXP (geu, 0)) == CCmode)
16740 : 3318 : && REGNO (XEXP (geu, 0)) == FLAGS_REG
16741 : 3318 : && XEXP (geu, 1) == const0_rtx
16742 : 3318 : && GET_CODE (op1) == LTU
16743 : 3318 : && REG_P (XEXP (op1, 0))
16744 : 3318 : && GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0))
16745 : 3318 : && REGNO (XEXP (op1, 0)) == FLAGS_REG
16746 : 925062 : && XEXP (op1, 1) == const0_rtx)
16747 : : return CCCmode;
16748 : : /* Similarly for *x86_cmc pattern.
16749 : : Match LTU of op0 (neg:QI (ltu:QI (reg:CCC FLAGS_REG) (const_int 0)))
16750 : : and op1 (geu:QI (reg:CCC FLAGS_REG) (const_int 0)).
16751 : : It is sufficient to test that the operand modes are CCCmode. */
16752 : 918426 : else if (code == LTU
16753 : 343773 : && GET_CODE (op0) == NEG
16754 : 1705 : && GET_CODE (XEXP (op0, 0)) == LTU
16755 : 377 : && GET_MODE (XEXP (XEXP (op0, 0), 0)) == CCCmode
16756 : 3 : && GET_CODE (op1) == GEU
16757 : 3 : && GET_MODE (XEXP (op1, 0)) == CCCmode)
16758 : : return CCCmode;
16759 : : /* Similarly for the comparison of addcarry/subborrow pattern. */
16760 : 343770 : else if (code == LTU
16761 : 343770 : && GET_CODE (op0) == ZERO_EXTEND
16762 : 15156 : && GET_CODE (op1) == PLUS
16763 : 9494 : && ix86_carry_flag_operator (XEXP (op1, 0), VOIDmode)
16764 : 9494 : && GET_CODE (XEXP (op1, 1)) == ZERO_EXTEND)
16765 : : return CCCmode;
16766 : : else
16767 : 908929 : return CCmode;
16768 : : case GTU: /* CF=0 & ZF=0 */
16769 : : case LEU: /* CF=1 | ZF=1 */
16770 : : return CCmode;
16771 : : /* Codes possibly doable only with sign flag when
16772 : : comparing against zero. */
16773 : 775772 : case GE: /* SF=OF or SF=0 */
16774 : 775772 : case LT: /* SF<>OF or SF=1 */
16775 : 775772 : if (op1 == const0_rtx)
16776 : : return CCGOCmode;
16777 : : else
16778 : : /* For other cases Carry flag is not required. */
16779 : 433615 : return CCGCmode;
16780 : : /* Codes doable only with sign flag when comparing
16781 : : against zero, but we miss jump instruction for it
16782 : : so we need to use relational tests against overflow
16783 : : that thus needs to be zero. */
16784 : 904206 : case GT: /* ZF=0 & SF=OF */
16785 : 904206 : case LE: /* ZF=1 | SF<>OF */
16786 : 904206 : if (op1 == const0_rtx)
16787 : : return CCNOmode;
16788 : : else
16789 : 614046 : return CCGCmode;
16790 : : default:
16791 : : /* CCmode should be used in all other cases. */
16792 : : return CCmode;
16793 : : }
16794 : : }
16795 : :
16796 : : /* Return TRUE or FALSE depending on whether the ptest instruction
16797 : : INSN has source and destination with suitable matching CC modes. */
16798 : :
16799 : : bool
16800 : 38793 : ix86_match_ptest_ccmode (rtx insn)
16801 : : {
16802 : 38793 : rtx set, src;
16803 : 38793 : machine_mode set_mode;
16804 : :
16805 : 38793 : set = PATTERN (insn);
16806 : 38793 : gcc_assert (GET_CODE (set) == SET);
16807 : 38793 : src = SET_SRC (set);
16808 : 38793 : gcc_assert (GET_CODE (src) == UNSPEC
16809 : : && XINT (src, 1) == UNSPEC_PTEST);
16810 : :
16811 : 38793 : set_mode = GET_MODE (src);
16812 : 38793 : if (set_mode != CCZmode
16813 : : && set_mode != CCCmode
16814 : : && set_mode != CCmode)
16815 : : return false;
16816 : 38793 : return GET_MODE (SET_DEST (set)) == set_mode;
16817 : : }
16818 : :
16819 : : /* Return the fixed registers used for condition codes. */
16820 : :
16821 : : static bool
16822 : 10023708 : ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
16823 : : {
16824 : 10023708 : *p1 = FLAGS_REG;
16825 : 10023708 : *p2 = INVALID_REGNUM;
16826 : 10023708 : return true;
16827 : : }
16828 : :
16829 : : /* If two condition code modes are compatible, return a condition code
16830 : : mode which is compatible with both. Otherwise, return
16831 : : VOIDmode. */
16832 : :
16833 : : static machine_mode
16834 : 30828 : ix86_cc_modes_compatible (machine_mode m1, machine_mode m2)
16835 : : {
16836 : 30828 : if (m1 == m2)
16837 : : return m1;
16838 : :
16839 : 30342 : if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
16840 : : return VOIDmode;
16841 : :
16842 : 30342 : if ((m1 == CCGCmode && m2 == CCGOCmode)
16843 : 30342 : || (m1 == CCGOCmode && m2 == CCGCmode))
16844 : : return CCGCmode;
16845 : :
16846 : 30342 : if ((m1 == CCNOmode && m2 == CCGOCmode)
16847 : 30152 : || (m1 == CCGOCmode && m2 == CCNOmode))
16848 : : return CCNOmode;
16849 : :
16850 : 30024 : if (m1 == CCZmode
16851 : 18819 : && (m2 == CCGCmode || m2 == CCGOCmode || m2 == CCNOmode))
16852 : : return m2;
16853 : 16406 : else if (m2 == CCZmode
16854 : 10954 : && (m1 == CCGCmode || m1 == CCGOCmode || m1 == CCNOmode))
16855 : : return m1;
16856 : :
16857 : 7136 : switch (m1)
16858 : : {
16859 : 0 : default:
16860 : 0 : gcc_unreachable ();
16861 : :
16862 : 7136 : case E_CCmode:
16863 : 7136 : case E_CCGCmode:
16864 : 7136 : case E_CCGOCmode:
16865 : 7136 : case E_CCNOmode:
16866 : 7136 : case E_CCAmode:
16867 : 7136 : case E_CCCmode:
16868 : 7136 : case E_CCOmode:
16869 : 7136 : case E_CCPmode:
16870 : 7136 : case E_CCSmode:
16871 : 7136 : case E_CCZmode:
16872 : 7136 : switch (m2)
16873 : : {
16874 : : default:
16875 : : return VOIDmode;
16876 : :
16877 : : case E_CCmode:
16878 : : case E_CCGCmode:
16879 : : case E_CCGOCmode:
16880 : : case E_CCNOmode:
16881 : : case E_CCAmode:
16882 : : case E_CCCmode:
16883 : : case E_CCOmode:
16884 : : case E_CCPmode:
16885 : : case E_CCSmode:
16886 : : case E_CCZmode:
16887 : : return CCmode;
16888 : : }
16889 : :
16890 : : case E_CCFPmode:
16891 : : /* These are only compatible with themselves, which we already
16892 : : checked above. */
16893 : : return VOIDmode;
16894 : : }
16895 : : }
16896 : :
16897 : : /* Return strategy to use for floating-point. We assume that fcomi is always
16898 : : preferrable where available, since that is also true when looking at size
16899 : : (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test). */
16900 : :
16901 : : enum ix86_fpcmp_strategy
16902 : 5570815 : ix86_fp_comparison_strategy (enum rtx_code)
16903 : : {
16904 : : /* Do fcomi/sahf based test when profitable. */
16905 : :
16906 : 5570815 : if (TARGET_CMOVE)
16907 : : return IX86_FPCMP_COMI;
16908 : :
16909 : 0 : if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
16910 : 0 : return IX86_FPCMP_SAHF;
16911 : :
16912 : : return IX86_FPCMP_ARITH;
16913 : : }
16914 : :
16915 : : /* Convert comparison codes we use to represent FP comparison to integer
16916 : : code that will result in proper branch. Return UNKNOWN if no such code
16917 : : is available. */
16918 : :
16919 : : enum rtx_code
16920 : 583118 : ix86_fp_compare_code_to_integer (enum rtx_code code)
16921 : : {
16922 : 583118 : switch (code)
16923 : : {
16924 : : case GT:
16925 : : return GTU;
16926 : 18671 : case GE:
16927 : 18671 : return GEU;
16928 : : case ORDERED:
16929 : : case UNORDERED:
16930 : : return code;
16931 : 118501 : case UNEQ:
16932 : 118501 : return EQ;
16933 : 20757 : case UNLT:
16934 : 20757 : return LTU;
16935 : 31536 : case UNLE:
16936 : 31536 : return LEU;
16937 : 112748 : case LTGT:
16938 : 112748 : return NE;
16939 : 19 : case EQ:
16940 : 19 : case NE:
16941 : 19 : if (TARGET_AVX10_2)
16942 : : return code;
16943 : : /* FALLTHRU. */
16944 : 205 : default:
16945 : 205 : return UNKNOWN;
16946 : : }
16947 : : }
16948 : :
16949 : : /* Zero extend possibly SImode EXP to Pmode register. */
16950 : : rtx
16951 : 67247 : ix86_zero_extend_to_Pmode (rtx exp)
16952 : : {
16953 : 67247 : return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
16954 : : }
16955 : :
16956 : : /* Return true if the function is called via PLT. */
16957 : :
16958 : : bool
16959 : 954801 : ix86_call_use_plt_p (rtx call_op)
16960 : : {
16961 : 954801 : if (SYMBOL_REF_LOCAL_P (call_op))
16962 : : {
16963 : 189757 : if (SYMBOL_REF_DECL (call_op)
16964 : 189757 : && TREE_CODE (SYMBOL_REF_DECL (call_op)) == FUNCTION_DECL)
16965 : : {
16966 : : /* NB: All ifunc functions must be called via PLT. */
16967 : 106665 : cgraph_node *node
16968 : 106665 : = cgraph_node::get (SYMBOL_REF_DECL (call_op));
16969 : 106665 : if (node && node->ifunc_resolver)
16970 : : return true;
16971 : : }
16972 : 189737 : return false;
16973 : : }
16974 : : return true;
16975 : : }
16976 : :
16977 : : /* Implement TARGET_IFUNC_REF_LOCAL_OK. If this hook returns true,
16978 : : the PLT entry will be used as the function address for local IFUNC
16979 : : functions. When the PIC register is needed for PLT call, indirect
16980 : : call via the PLT entry will fail since the PIC register may not be
16981 : : set up properly for indirect call. In this case, we should return
16982 : : false. */
16983 : :
16984 : : static bool
16985 : 734480235 : ix86_ifunc_ref_local_ok (void)
16986 : : {
16987 : 734480235 : return !flag_pic || (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC);
16988 : : }
16989 : :
16990 : : /* Return true if the function being called was marked with attribute
16991 : : "noplt" or using -fno-plt and we are compiling for non-PIC. We need
16992 : : to handle the non-PIC case in the backend because there is no easy
16993 : : interface for the front-end to force non-PLT calls to use the GOT.
16994 : : This is currently used only with 64-bit or 32-bit GOT32X ELF targets
16995 : : to call the function marked "noplt" indirectly. */
16996 : :
16997 : : bool
16998 : 5805201 : ix86_nopic_noplt_attribute_p (rtx call_op)
16999 : : {
17000 : 5333786 : if (flag_pic || ix86_cmodel == CM_LARGE
17001 : : || !(TARGET_64BIT || HAVE_AS_IX86_GOT32X)
17002 : : || TARGET_MACHO || TARGET_SEH || TARGET_PECOFF
17003 : 11138987 : || SYMBOL_REF_LOCAL_P (call_op))
17004 : : return false;
17005 : :
17006 : 3709066 : tree symbol_decl = SYMBOL_REF_DECL (call_op);
17007 : :
17008 : 3709066 : if (!flag_plt
17009 : 3709066 : || (symbol_decl != NULL_TREE
17010 : 3709034 : && lookup_attribute ("noplt", DECL_ATTRIBUTES (symbol_decl))))
17011 : 34 : return true;
17012 : :
17013 : : return false;
17014 : : }
17015 : :
17016 : : /* Helper to output the jmp/call. */
17017 : : static void
17018 : 33 : ix86_output_jmp_thunk_or_indirect (const char *thunk_name, const int regno)
17019 : : {
17020 : 33 : if (thunk_name != NULL)
17021 : : {
17022 : 22 : if ((REX_INT_REGNO_P (regno) || REX2_INT_REGNO_P (regno))
17023 : 1 : && ix86_indirect_branch_cs_prefix)
17024 : 1 : fprintf (asm_out_file, "\tcs\n");
17025 : 22 : fprintf (asm_out_file, "\tjmp\t");
17026 : 22 : assemble_name (asm_out_file, thunk_name);
17027 : 22 : putc ('\n', asm_out_file);
17028 : 22 : if ((ix86_harden_sls & harden_sls_indirect_jmp))
17029 : 2 : fputs ("\tint3\n", asm_out_file);
17030 : : }
17031 : : else
17032 : 11 : output_indirect_thunk (regno);
17033 : 33 : }
17034 : :
17035 : : /* Output indirect branch via a call and return thunk. CALL_OP is a
17036 : : register which contains the branch target. XASM is the assembly
17037 : : template for CALL_OP. Branch is a tail call if SIBCALL_P is true.
17038 : : A normal call is converted to:
17039 : :
17040 : : call __x86_indirect_thunk_reg
17041 : :
17042 : : and a tail call is converted to:
17043 : :
17044 : : jmp __x86_indirect_thunk_reg
17045 : : */
17046 : :
17047 : : static void
17048 : 50 : ix86_output_indirect_branch_via_reg (rtx call_op, bool sibcall_p)
17049 : : {
17050 : 50 : char thunk_name_buf[32];
17051 : 50 : char *thunk_name;
17052 : 50 : enum indirect_thunk_prefix need_prefix
17053 : 50 : = indirect_thunk_need_prefix (current_output_insn);
17054 : 50 : int regno = REGNO (call_op);
17055 : :
17056 : 50 : if (cfun->machine->indirect_branch_type
17057 : 50 : != indirect_branch_thunk_inline)
17058 : : {
17059 : 39 : if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
17060 : 16 : SET_HARD_REG_BIT (indirect_thunks_used, regno);
17061 : :
17062 : 39 : indirect_thunk_name (thunk_name_buf, regno, need_prefix, false);
17063 : 39 : thunk_name = thunk_name_buf;
17064 : : }
17065 : : else
17066 : : thunk_name = NULL;
17067 : :
17068 : 50 : if (sibcall_p)
17069 : 27 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17070 : : else
17071 : : {
17072 : 23 : if (thunk_name != NULL)
17073 : : {
17074 : 17 : if ((REX_INT_REGNO_P (regno) || REX_INT_REGNO_P (regno))
17075 : 1 : && ix86_indirect_branch_cs_prefix)
17076 : 1 : fprintf (asm_out_file, "\tcs\n");
17077 : 17 : fprintf (asm_out_file, "\tcall\t");
17078 : 17 : assemble_name (asm_out_file, thunk_name);
17079 : 17 : putc ('\n', asm_out_file);
17080 : 17 : return;
17081 : : }
17082 : :
17083 : 6 : char indirectlabel1[32];
17084 : 6 : char indirectlabel2[32];
17085 : :
17086 : 6 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel1,
17087 : : INDIRECT_LABEL,
17088 : : indirectlabelno++);
17089 : 6 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel2,
17090 : : INDIRECT_LABEL,
17091 : : indirectlabelno++);
17092 : :
17093 : : /* Jump. */
17094 : 6 : fputs ("\tjmp\t", asm_out_file);
17095 : 6 : assemble_name_raw (asm_out_file, indirectlabel2);
17096 : 6 : fputc ('\n', asm_out_file);
17097 : :
17098 : 6 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
17099 : :
17100 : 6 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17101 : :
17102 : 6 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
17103 : :
17104 : : /* Call. */
17105 : 6 : fputs ("\tcall\t", asm_out_file);
17106 : 6 : assemble_name_raw (asm_out_file, indirectlabel1);
17107 : 6 : fputc ('\n', asm_out_file);
17108 : : }
17109 : : }
17110 : :
17111 : : /* Output indirect branch via a call and return thunk. CALL_OP is
17112 : : the branch target. XASM is the assembly template for CALL_OP.
17113 : : Branch is a tail call if SIBCALL_P is true. A normal call is
17114 : : converted to:
17115 : :
17116 : : jmp L2
17117 : : L1:
17118 : : push CALL_OP
17119 : : jmp __x86_indirect_thunk
17120 : : L2:
17121 : : call L1
17122 : :
17123 : : and a tail call is converted to:
17124 : :
17125 : : push CALL_OP
17126 : : jmp __x86_indirect_thunk
17127 : : */
17128 : :
17129 : : static void
17130 : 0 : ix86_output_indirect_branch_via_push (rtx call_op, const char *xasm,
17131 : : bool sibcall_p)
17132 : : {
17133 : 0 : char thunk_name_buf[32];
17134 : 0 : char *thunk_name;
17135 : 0 : char push_buf[64];
17136 : 0 : enum indirect_thunk_prefix need_prefix
17137 : 0 : = indirect_thunk_need_prefix (current_output_insn);
17138 : 0 : int regno = -1;
17139 : :
17140 : 0 : if (cfun->machine->indirect_branch_type
17141 : 0 : != indirect_branch_thunk_inline)
17142 : : {
17143 : 0 : if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
17144 : 0 : indirect_thunk_needed = true;
17145 : 0 : indirect_thunk_name (thunk_name_buf, regno, need_prefix, false);
17146 : 0 : thunk_name = thunk_name_buf;
17147 : : }
17148 : : else
17149 : : thunk_name = NULL;
17150 : :
17151 : 0 : snprintf (push_buf, sizeof (push_buf), "push{%c}\t%s",
17152 : 0 : TARGET_64BIT ? 'q' : 'l', xasm);
17153 : :
17154 : 0 : if (sibcall_p)
17155 : : {
17156 : 0 : output_asm_insn (push_buf, &call_op);
17157 : 0 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17158 : : }
17159 : : else
17160 : : {
17161 : 0 : char indirectlabel1[32];
17162 : 0 : char indirectlabel2[32];
17163 : :
17164 : 0 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel1,
17165 : : INDIRECT_LABEL,
17166 : : indirectlabelno++);
17167 : 0 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel2,
17168 : : INDIRECT_LABEL,
17169 : : indirectlabelno++);
17170 : :
17171 : : /* Jump. */
17172 : 0 : fputs ("\tjmp\t", asm_out_file);
17173 : 0 : assemble_name_raw (asm_out_file, indirectlabel2);
17174 : 0 : fputc ('\n', asm_out_file);
17175 : :
17176 : 0 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
17177 : :
17178 : : /* An external function may be called via GOT, instead of PLT. */
17179 : 0 : if (MEM_P (call_op))
17180 : : {
17181 : 0 : struct ix86_address parts;
17182 : 0 : rtx addr = XEXP (call_op, 0);
17183 : 0 : if (ix86_decompose_address (addr, &parts)
17184 : 0 : && parts.base == stack_pointer_rtx)
17185 : : {
17186 : : /* Since call will adjust stack by -UNITS_PER_WORD,
17187 : : we must convert "disp(stack, index, scale)" to
17188 : : "disp+UNITS_PER_WORD(stack, index, scale)". */
17189 : 0 : if (parts.index)
17190 : : {
17191 : 0 : addr = gen_rtx_MULT (Pmode, parts.index,
17192 : : GEN_INT (parts.scale));
17193 : 0 : addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
17194 : : addr);
17195 : : }
17196 : : else
17197 : : addr = stack_pointer_rtx;
17198 : :
17199 : 0 : rtx disp;
17200 : 0 : if (parts.disp != NULL_RTX)
17201 : 0 : disp = plus_constant (Pmode, parts.disp,
17202 : 0 : UNITS_PER_WORD);
17203 : : else
17204 : 0 : disp = GEN_INT (UNITS_PER_WORD);
17205 : :
17206 : 0 : addr = gen_rtx_PLUS (Pmode, addr, disp);
17207 : 0 : call_op = gen_rtx_MEM (GET_MODE (call_op), addr);
17208 : : }
17209 : : }
17210 : :
17211 : 0 : output_asm_insn (push_buf, &call_op);
17212 : :
17213 : 0 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17214 : :
17215 : 0 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
17216 : :
17217 : : /* Call. */
17218 : 0 : fputs ("\tcall\t", asm_out_file);
17219 : 0 : assemble_name_raw (asm_out_file, indirectlabel1);
17220 : 0 : fputc ('\n', asm_out_file);
17221 : : }
17222 : 0 : }
17223 : :
17224 : : /* Output indirect branch via a call and return thunk. CALL_OP is
17225 : : the branch target. XASM is the assembly template for CALL_OP.
17226 : : Branch is a tail call if SIBCALL_P is true. */
17227 : :
17228 : : static void
17229 : 50 : ix86_output_indirect_branch (rtx call_op, const char *xasm,
17230 : : bool sibcall_p)
17231 : : {
17232 : 50 : if (REG_P (call_op))
17233 : 50 : ix86_output_indirect_branch_via_reg (call_op, sibcall_p);
17234 : : else
17235 : 0 : ix86_output_indirect_branch_via_push (call_op, xasm, sibcall_p);
17236 : 50 : }
17237 : :
17238 : : /* Output indirect jump. CALL_OP is the jump target. */
17239 : :
17240 : : const char *
17241 : 8641 : ix86_output_indirect_jmp (rtx call_op)
17242 : : {
17243 : 8641 : if (cfun->machine->indirect_branch_type != indirect_branch_keep)
17244 : : {
17245 : : /* We can't have red-zone since "call" in the indirect thunk
17246 : : pushes the return address onto stack, destroying red-zone. */
17247 : 4 : if (ix86_red_zone_used)
17248 : 0 : gcc_unreachable ();
17249 : :
17250 : 4 : ix86_output_indirect_branch (call_op, "%0", true);
17251 : : }
17252 : : else
17253 : 8637 : output_asm_insn ("%!jmp\t%A0", &call_op);
17254 : 8641 : return (ix86_harden_sls & harden_sls_indirect_jmp) ? "int3" : "";
17255 : : }
17256 : :
17257 : : /* Output return instrumentation for current function if needed. */
17258 : :
17259 : : static void
17260 : 1681256 : output_return_instrumentation (void)
17261 : : {
17262 : 1681256 : if (ix86_instrument_return != instrument_return_none
17263 : 6 : && flag_fentry
17264 : 1681262 : && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (cfun->decl))
17265 : : {
17266 : 5 : if (ix86_flag_record_return)
17267 : 5 : fprintf (asm_out_file, "1:\n");
17268 : 5 : switch (ix86_instrument_return)
17269 : : {
17270 : 2 : case instrument_return_call:
17271 : 2 : fprintf (asm_out_file, "\tcall\t__return__\n");
17272 : 2 : break;
17273 : 3 : case instrument_return_nop5:
17274 : : /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
17275 : 3 : fprintf (asm_out_file, ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
17276 : 3 : break;
17277 : : case instrument_return_none:
17278 : : break;
17279 : : }
17280 : :
17281 : 5 : if (ix86_flag_record_return)
17282 : : {
17283 : 5 : fprintf (asm_out_file, "\t.section __return_loc, \"a\",@progbits\n");
17284 : 5 : fprintf (asm_out_file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
17285 : 5 : fprintf (asm_out_file, "\t.previous\n");
17286 : : }
17287 : : }
17288 : 1681256 : }
17289 : :
17290 : : /* Output function return. CALL_OP is the jump target. Add a REP
17291 : : prefix to RET if LONG_P is true and function return is kept. */
17292 : :
17293 : : const char *
17294 : 1559378 : ix86_output_function_return (bool long_p)
17295 : : {
17296 : 1559378 : output_return_instrumentation ();
17297 : :
17298 : 1559378 : if (cfun->machine->function_return_type != indirect_branch_keep)
17299 : : {
17300 : 17 : char thunk_name[32];
17301 : 17 : enum indirect_thunk_prefix need_prefix
17302 : 17 : = indirect_thunk_need_prefix (current_output_insn);
17303 : :
17304 : 17 : if (cfun->machine->function_return_type
17305 : 17 : != indirect_branch_thunk_inline)
17306 : : {
17307 : 12 : bool need_thunk = (cfun->machine->function_return_type
17308 : : == indirect_branch_thunk);
17309 : 12 : indirect_thunk_name (thunk_name, INVALID_REGNUM, need_prefix,
17310 : : true);
17311 : 12 : indirect_return_needed |= need_thunk;
17312 : 12 : fprintf (asm_out_file, "\tjmp\t");
17313 : 12 : assemble_name (asm_out_file, thunk_name);
17314 : 12 : putc ('\n', asm_out_file);
17315 : : }
17316 : : else
17317 : 5 : output_indirect_thunk (INVALID_REGNUM);
17318 : :
17319 : 17 : return "";
17320 : : }
17321 : :
17322 : 3118239 : output_asm_insn (long_p ? "rep%; ret" : "ret", nullptr);
17323 : 1559361 : return (ix86_harden_sls & harden_sls_return) ? "int3" : "";
17324 : : }
17325 : :
17326 : : /* Output indirect function return. RET_OP is the function return
17327 : : target. */
17328 : :
17329 : : const char *
17330 : 17 : ix86_output_indirect_function_return (rtx ret_op)
17331 : : {
17332 : 17 : if (cfun->machine->function_return_type != indirect_branch_keep)
17333 : : {
17334 : 0 : char thunk_name[32];
17335 : 0 : enum indirect_thunk_prefix need_prefix
17336 : 0 : = indirect_thunk_need_prefix (current_output_insn);
17337 : 0 : unsigned int regno = REGNO (ret_op);
17338 : 0 : gcc_assert (regno == CX_REG);
17339 : :
17340 : 0 : if (cfun->machine->function_return_type
17341 : 0 : != indirect_branch_thunk_inline)
17342 : : {
17343 : 0 : bool need_thunk = (cfun->machine->function_return_type
17344 : : == indirect_branch_thunk);
17345 : 0 : indirect_thunk_name (thunk_name, regno, need_prefix, true);
17346 : :
17347 : 0 : if (need_thunk)
17348 : : {
17349 : 0 : indirect_return_via_cx = true;
17350 : 0 : SET_HARD_REG_BIT (indirect_thunks_used, CX_REG);
17351 : : }
17352 : 0 : fprintf (asm_out_file, "\tjmp\t");
17353 : 0 : assemble_name (asm_out_file, thunk_name);
17354 : 0 : putc ('\n', asm_out_file);
17355 : : }
17356 : : else
17357 : 0 : output_indirect_thunk (regno);
17358 : : }
17359 : : else
17360 : : {
17361 : 17 : output_asm_insn ("%!jmp\t%A0", &ret_op);
17362 : 17 : if (ix86_harden_sls & harden_sls_indirect_jmp)
17363 : 1 : fputs ("\tint3\n", asm_out_file);
17364 : : }
17365 : 17 : return "";
17366 : : }
17367 : :
17368 : : /* Output the assembly for a call instruction. */
17369 : :
17370 : : const char *
17371 : 5988554 : ix86_output_call_insn (rtx_insn *insn, rtx call_op)
17372 : : {
17373 : 5988554 : bool direct_p = constant_call_address_operand (call_op, VOIDmode);
17374 : 5988554 : bool output_indirect_p
17375 : : = (!TARGET_SEH
17376 : 5988554 : && cfun->machine->indirect_branch_type != indirect_branch_keep);
17377 : 5988554 : bool seh_nop_p = false;
17378 : 5988554 : const char *xasm;
17379 : :
17380 : 5988554 : if (SIBLING_CALL_P (insn))
17381 : : {
17382 : 121878 : output_return_instrumentation ();
17383 : 121878 : if (direct_p)
17384 : : {
17385 : 112911 : if (ix86_nopic_noplt_attribute_p (call_op))
17386 : : {
17387 : 4 : direct_p = false;
17388 : 4 : if (TARGET_64BIT)
17389 : : {
17390 : 4 : if (output_indirect_p)
17391 : : xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17392 : : else
17393 : 4 : xasm = "%!jmp\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17394 : : }
17395 : : else
17396 : : {
17397 : 0 : if (output_indirect_p)
17398 : : xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}";
17399 : : else
17400 : 0 : xasm = "%!jmp\t{*%p0@GOT|[DWORD PTR %p0@GOT]}";
17401 : : }
17402 : : }
17403 : : else
17404 : : xasm = "%!jmp\t%P0";
17405 : : }
17406 : : /* SEH epilogue detection requires the indirect branch case
17407 : : to include REX.W. */
17408 : 8967 : else if (TARGET_SEH)
17409 : : xasm = "%!rex.W jmp\t%A0";
17410 : : else
17411 : : {
17412 : 8967 : if (output_indirect_p)
17413 : : xasm = "%0";
17414 : : else
17415 : 8944 : xasm = "%!jmp\t%A0";
17416 : : }
17417 : :
17418 : 121878 : if (output_indirect_p && !direct_p)
17419 : 23 : ix86_output_indirect_branch (call_op, xasm, true);
17420 : : else
17421 : : {
17422 : 121855 : output_asm_insn (xasm, &call_op);
17423 : 121855 : if (!direct_p
17424 : 8948 : && (ix86_harden_sls & harden_sls_indirect_jmp))
17425 : : return "int3";
17426 : : }
17427 : 121877 : return "";
17428 : : }
17429 : :
17430 : : /* SEH unwinding can require an extra nop to be emitted in several
17431 : : circumstances. Determine if we have one of those. */
17432 : 5866676 : if (TARGET_SEH)
17433 : : {
17434 : : rtx_insn *i;
17435 : :
17436 : : for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
17437 : : {
17438 : : /* Prevent a catch region from being adjacent to a jump that would
17439 : : be interpreted as an epilogue sequence by the unwinder. */
17440 : : if (JUMP_P(i) && CROSSING_JUMP_P (i))
17441 : : {
17442 : : seh_nop_p = true;
17443 : : break;
17444 : : }
17445 : :
17446 : : /* If we get to another real insn, we don't need the nop. */
17447 : : if (INSN_P (i))
17448 : : break;
17449 : :
17450 : : /* If we get to the epilogue note, prevent a catch region from
17451 : : being adjacent to the standard epilogue sequence. Note that,
17452 : : if non-call exceptions are enabled, we already did it during
17453 : : epilogue expansion, or else, if the insn can throw internally,
17454 : : we already did it during the reorg pass. */
17455 : : if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG
17456 : : && !flag_non_call_exceptions
17457 : : && !can_throw_internal (insn))
17458 : : {
17459 : : seh_nop_p = true;
17460 : : break;
17461 : : }
17462 : : }
17463 : :
17464 : : /* If we didn't find a real insn following the call, prevent the
17465 : : unwinder from looking into the next function. */
17466 : : if (i == NULL)
17467 : : seh_nop_p = true;
17468 : : }
17469 : :
17470 : 5866676 : if (direct_p)
17471 : : {
17472 : 5691268 : if (ix86_nopic_noplt_attribute_p (call_op))
17473 : : {
17474 : 6 : direct_p = false;
17475 : 6 : if (TARGET_64BIT)
17476 : : {
17477 : 6 : if (output_indirect_p)
17478 : : xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17479 : : else
17480 : 6 : xasm = "%!call\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17481 : : }
17482 : : else
17483 : : {
17484 : 0 : if (output_indirect_p)
17485 : : xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}";
17486 : : else
17487 : 0 : xasm = "%!call\t{*%p0@GOT|[DWORD PTR %p0@GOT]}";
17488 : : }
17489 : : }
17490 : : else
17491 : : xasm = "%!call\t%P0";
17492 : : }
17493 : : else
17494 : : {
17495 : 175408 : if (output_indirect_p)
17496 : : xasm = "%0";
17497 : : else
17498 : 175385 : xasm = "%!call\t%A0";
17499 : : }
17500 : :
17501 : 5866676 : if (output_indirect_p && !direct_p)
17502 : 23 : ix86_output_indirect_branch (call_op, xasm, false);
17503 : : else
17504 : 5866653 : output_asm_insn (xasm, &call_op);
17505 : :
17506 : : if (seh_nop_p)
17507 : : return "nop";
17508 : :
17509 : : return "";
17510 : : }
17511 : :
17512 : : /* Return a MEM corresponding to a stack slot with mode MODE.
17513 : : Allocate a new slot if necessary.
17514 : :
17515 : : The RTL for a function can have several slots available: N is
17516 : : which slot to use. */
17517 : :
17518 : : rtx
17519 : 22571 : assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n)
17520 : : {
17521 : 22571 : struct stack_local_entry *s;
17522 : :
17523 : 22571 : gcc_assert (n < MAX_386_STACK_LOCALS);
17524 : :
17525 : 34075 : for (s = ix86_stack_locals; s; s = s->next)
17526 : 31404 : if (s->mode == mode && s->n == n)
17527 : 19900 : return validize_mem (copy_rtx (s->rtl));
17528 : :
17529 : 2671 : int align = 0;
17530 : : /* For DImode with SLOT_FLOATxFDI_387 use 32-bit
17531 : : alignment with -m32 -mpreferred-stack-boundary=2. */
17532 : 2671 : if (mode == DImode
17533 : 343 : && !TARGET_64BIT
17534 : 343 : && n == SLOT_FLOATxFDI_387
17535 : 3014 : && ix86_preferred_stack_boundary < GET_MODE_ALIGNMENT (DImode))
17536 : : align = 32;
17537 : 2671 : s = ggc_alloc<stack_local_entry> ();
17538 : 2671 : s->n = n;
17539 : 2671 : s->mode = mode;
17540 : 5342 : s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), align);
17541 : :
17542 : 2671 : s->next = ix86_stack_locals;
17543 : 2671 : ix86_stack_locals = s;
17544 : 2671 : return validize_mem (copy_rtx (s->rtl));
17545 : : }
17546 : :
17547 : : static void
17548 : 1440892 : ix86_instantiate_decls (void)
17549 : : {
17550 : 1440892 : struct stack_local_entry *s;
17551 : :
17552 : 1440892 : for (s = ix86_stack_locals; s; s = s->next)
17553 : 0 : if (s->rtl != NULL_RTX)
17554 : 0 : instantiate_decl_rtl (s->rtl);
17555 : 1440892 : }
17556 : :
17557 : : /* Check whether x86 address PARTS is a pc-relative address. */
17558 : :
17559 : : bool
17560 : 24788112 : ix86_rip_relative_addr_p (struct ix86_address *parts)
17561 : : {
17562 : 24788112 : rtx base, index, disp;
17563 : :
17564 : 24788112 : base = parts->base;
17565 : 24788112 : index = parts->index;
17566 : 24788112 : disp = parts->disp;
17567 : :
17568 : 24788112 : if (disp && !base && !index)
17569 : : {
17570 : 24189130 : if (TARGET_64BIT)
17571 : : {
17572 : 22693793 : rtx symbol = disp;
17573 : :
17574 : 22693793 : if (GET_CODE (disp) == CONST)
17575 : 7054610 : symbol = XEXP (disp, 0);
17576 : 22693793 : if (GET_CODE (symbol) == PLUS
17577 : 6564791 : && CONST_INT_P (XEXP (symbol, 1)))
17578 : 6564791 : symbol = XEXP (symbol, 0);
17579 : :
17580 : 22693793 : if (GET_CODE (symbol) == LABEL_REF
17581 : 22686579 : || (GET_CODE (symbol) == SYMBOL_REF
17582 : 21587640 : && SYMBOL_REF_TLS_MODEL (symbol) == 0)
17583 : 23792732 : || (GET_CODE (symbol) == UNSPEC
17584 : 508091 : && (XINT (symbol, 1) == UNSPEC_GOTPCREL
17585 : : || XINT (symbol, 1) == UNSPEC_PCREL
17586 : : || XINT (symbol, 1) == UNSPEC_GOTNTPOFF)))
17587 : 22077227 : return true;
17588 : : }
17589 : : }
17590 : : return false;
17591 : : }
17592 : :
17593 : : /* Calculate the length of the memory address in the instruction encoding.
17594 : : Includes addr32 prefix, does not include the one-byte modrm, opcode,
17595 : : or other prefixes. We never generate addr32 prefix for LEA insn. */
17596 : :
17597 : : int
17598 : 249560398 : memory_address_length (rtx addr, bool lea)
17599 : : {
17600 : 249560398 : struct ix86_address parts;
17601 : 249560398 : rtx base, index, disp;
17602 : 249560398 : int len;
17603 : 249560398 : int ok;
17604 : :
17605 : 249560398 : if (GET_CODE (addr) == PRE_DEC
17606 : 240529755 : || GET_CODE (addr) == POST_INC
17607 : 235121769 : || GET_CODE (addr) == PRE_MODIFY
17608 : 235121769 : || GET_CODE (addr) == POST_MODIFY)
17609 : : return 0;
17610 : :
17611 : 235121769 : ok = ix86_decompose_address (addr, &parts);
17612 : 235121769 : gcc_assert (ok);
17613 : :
17614 : 235121769 : len = (parts.seg == ADDR_SPACE_GENERIC) ? 0 : 1;
17615 : :
17616 : : /* If this is not LEA instruction, add the length of addr32 prefix. */
17617 : 198111480 : if (TARGET_64BIT && !lea
17618 : 408442604 : && (SImode_address_operand (addr, VOIDmode)
17619 : 173320739 : || (parts.base && GET_MODE (parts.base) == SImode)
17620 : 173320213 : || (parts.index && GET_MODE (parts.index) == SImode)))
17621 : 622 : len++;
17622 : :
17623 : 235121769 : base = parts.base;
17624 : 235121769 : index = parts.index;
17625 : 235121769 : disp = parts.disp;
17626 : :
17627 : 235121769 : if (base && SUBREG_P (base))
17628 : 2 : base = SUBREG_REG (base);
17629 : 235121769 : if (index && SUBREG_P (index))
17630 : 0 : index = SUBREG_REG (index);
17631 : :
17632 : 235121769 : gcc_assert (base == NULL_RTX || REG_P (base));
17633 : 235121769 : gcc_assert (index == NULL_RTX || REG_P (index));
17634 : :
17635 : : /* Rule of thumb:
17636 : : - esp as the base always wants an index,
17637 : : - ebp as the base always wants a displacement,
17638 : : - r12 as the base always wants an index,
17639 : : - r13 as the base always wants a displacement. */
17640 : :
17641 : : /* Register Indirect. */
17642 : 235121769 : if (base && !index && !disp)
17643 : : {
17644 : : /* esp (for its index) and ebp (for its displacement) need
17645 : : the two-byte modrm form. Similarly for r12 and r13 in 64-bit
17646 : : code. */
17647 : 15686823 : if (base == arg_pointer_rtx
17648 : 15686823 : || base == frame_pointer_rtx
17649 : 15686823 : || REGNO (base) == SP_REG
17650 : 9506361 : || REGNO (base) == BP_REG
17651 : 9506361 : || REGNO (base) == R12_REG
17652 : 24760053 : || REGNO (base) == R13_REG)
17653 : 6613593 : len++;
17654 : : }
17655 : :
17656 : : /* Direct Addressing. In 64-bit mode mod 00 r/m 5
17657 : : is not disp32, but disp32(%rip), so for disp32
17658 : : SIB byte is needed, unless print_operand_address
17659 : : optimizes it into disp32(%rip) or (%rip) is implied
17660 : : by UNSPEC. */
17661 : 219434946 : else if (disp && !base && !index)
17662 : : {
17663 : 23879172 : len += 4;
17664 : 23879172 : if (!ix86_rip_relative_addr_p (&parts))
17665 : 1869201 : len++;
17666 : : }
17667 : : else
17668 : : {
17669 : : /* Find the length of the displacement constant. */
17670 : 195555774 : if (disp)
17671 : : {
17672 : 191751177 : if (base && satisfies_constraint_K (disp))
17673 : 110183945 : len += 1;
17674 : : else
17675 : 81567232 : len += 4;
17676 : : }
17677 : : /* ebp always wants a displacement. Similarly r13. */
17678 : 3804597 : else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
17679 : 9332 : len++;
17680 : :
17681 : : /* An index requires the two-byte modrm form.... */
17682 : 195555774 : if (index
17683 : : /* ...like esp (or r12), which always wants an index. */
17684 : 187068606 : || base == arg_pointer_rtx
17685 : 187068606 : || base == frame_pointer_rtx
17686 : 382624380 : || (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
17687 : 138971500 : len++;
17688 : : }
17689 : :
17690 : : return len;
17691 : : }
17692 : :
17693 : : /* Compute default value for "length_immediate" attribute. When SHORTFORM
17694 : : is set, expect that insn have 8bit immediate alternative. */
17695 : : int
17696 : 296511360 : ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform)
17697 : : {
17698 : 296511360 : int len = 0;
17699 : 296511360 : int i;
17700 : 296511360 : extract_insn_cached (insn);
17701 : 926473298 : for (i = recog_data.n_operands - 1; i >= 0; --i)
17702 : 629961938 : if (CONSTANT_P (recog_data.operand[i]))
17703 : : {
17704 : 132515493 : enum attr_mode mode = get_attr_mode (insn);
17705 : :
17706 : 132515493 : gcc_assert (!len);
17707 : 132515493 : if (shortform && CONST_INT_P (recog_data.operand[i]))
17708 : : {
17709 : 34666769 : HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
17710 : 34666769 : switch (mode)
17711 : : {
17712 : 1102859 : case MODE_QI:
17713 : 1102859 : len = 1;
17714 : 1102859 : continue;
17715 : 421609 : case MODE_HI:
17716 : 421609 : ival = trunc_int_for_mode (ival, HImode);
17717 : 421609 : break;
17718 : 15062682 : case MODE_SI:
17719 : 15062682 : ival = trunc_int_for_mode (ival, SImode);
17720 : 15062682 : break;
17721 : : default:
17722 : : break;
17723 : : }
17724 : 33563910 : if (IN_RANGE (ival, -128, 127))
17725 : : {
17726 : 29828157 : len = 1;
17727 : 29828157 : continue;
17728 : : }
17729 : : }
17730 : 101584477 : switch (mode)
17731 : : {
17732 : : case MODE_QI:
17733 : : len = 1;
17734 : : break;
17735 : : case MODE_HI:
17736 : 629961938 : len = 2;
17737 : : break;
17738 : : case MODE_SI:
17739 : 96096320 : len = 4;
17740 : : break;
17741 : : /* Immediates for DImode instructions are encoded
17742 : : as 32bit sign extended values. */
17743 : : case MODE_DI:
17744 : 96096320 : len = 4;
17745 : : break;
17746 : 0 : default:
17747 : 0 : fatal_insn ("unknown insn mode", insn);
17748 : : }
17749 : : }
17750 : 296511360 : return len;
17751 : : }
17752 : :
17753 : : /* Compute default value for "length_address" attribute. */
17754 : : int
17755 : 420036717 : ix86_attr_length_address_default (rtx_insn *insn)
17756 : : {
17757 : 420036717 : int i;
17758 : :
17759 : 420036717 : if (get_attr_type (insn) == TYPE_LEA)
17760 : : {
17761 : 27534306 : rtx set = PATTERN (insn), addr;
17762 : :
17763 : 27534306 : if (GET_CODE (set) == PARALLEL)
17764 : 87479 : set = XVECEXP (set, 0, 0);
17765 : :
17766 : 27534306 : gcc_assert (GET_CODE (set) == SET);
17767 : :
17768 : 27534306 : addr = SET_SRC (set);
17769 : :
17770 : 27534306 : return memory_address_length (addr, true);
17771 : : }
17772 : :
17773 : 392502411 : extract_insn_cached (insn);
17774 : 911350765 : for (i = recog_data.n_operands - 1; i >= 0; --i)
17775 : : {
17776 : 740594693 : rtx op = recog_data.operand[i];
17777 : 740594693 : if (MEM_P (op))
17778 : : {
17779 : 222010428 : constrain_operands_cached (insn, reload_completed);
17780 : 222010428 : if (which_alternative != -1)
17781 : : {
17782 : 222010428 : const char *constraints = recog_data.constraints[i];
17783 : 222010428 : int alt = which_alternative;
17784 : :
17785 : 350368227 : while (*constraints == '=' || *constraints == '+')
17786 : 128357799 : constraints++;
17787 : 999069104 : while (alt-- > 0)
17788 : 1914405245 : while (*constraints++ != ',')
17789 : : ;
17790 : : /* Skip ignored operands. */
17791 : 222010428 : if (*constraints == 'X')
17792 : 264089 : continue;
17793 : : }
17794 : :
17795 : 221746339 : int len = memory_address_length (XEXP (op, 0), false);
17796 : :
17797 : : /* Account for segment prefix for non-default addr spaces. */
17798 : 233330848 : if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (op)))
17799 : 777160 : len++;
17800 : :
17801 : 221746339 : return len;
17802 : : }
17803 : : }
17804 : : return 0;
17805 : : }
17806 : :
17807 : : /* Compute default value for "length_vex" attribute. It includes
17808 : : 2 or 3 byte VEX prefix and 1 opcode byte. */
17809 : :
17810 : : int
17811 : 4822369 : ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode,
17812 : : bool has_vex_w)
17813 : : {
17814 : 4822369 : int i, reg_only = 2 + 1;
17815 : 4822369 : bool has_mem = false;
17816 : :
17817 : : /* Only 0f opcode can use 2 byte VEX prefix and VEX W bit uses 3
17818 : : byte VEX prefix. */
17819 : 4822369 : if (!has_0f_opcode || has_vex_w)
17820 : : return 3 + 1;
17821 : :
17822 : : /* We can always use 2 byte VEX prefix in 32bit. */
17823 : 4426548 : if (!TARGET_64BIT)
17824 : : return 2 + 1;
17825 : :
17826 : 3321853 : extract_insn_cached (insn);
17827 : :
17828 : 10379909 : for (i = recog_data.n_operands - 1; i >= 0; --i)
17829 : 7378629 : if (REG_P (recog_data.operand[i]))
17830 : : {
17831 : : /* REX.W bit uses 3 byte VEX prefix.
17832 : : REX2 with vex use extended EVEX prefix length is 4-byte. */
17833 : 4861187 : if (GET_MODE (recog_data.operand[i]) == DImode
17834 : 4861187 : && GENERAL_REG_P (recog_data.operand[i]))
17835 : : return 3 + 1;
17836 : :
17837 : : /* REX.B bit requires 3-byte VEX. Right here we don't know which
17838 : : operand will be encoded using VEX.B, so be conservative.
17839 : : REX2 with vex use extended EVEX prefix length is 4-byte. */
17840 : 4843067 : if (REX_INT_REGNO_P (recog_data.operand[i])
17841 : 4843067 : || REX2_INT_REGNO_P (recog_data.operand[i])
17842 : 4843067 : || REX_SSE_REGNO_P (recog_data.operand[i]))
17843 : 0 : reg_only = 3 + 1;
17844 : : }
17845 : 2517442 : else if (MEM_P (recog_data.operand[i]))
17846 : : {
17847 : : /* REX2.X or REX2.B bits use 3 byte VEX prefix. */
17848 : 1937012 : if (x86_extended_rex2reg_mentioned_p (recog_data.operand[i]))
17849 : : return 4;
17850 : :
17851 : : /* REX.X or REX.B bits use 3 byte VEX prefix. */
17852 : 1936758 : if (x86_extended_reg_mentioned_p (recog_data.operand[i]))
17853 : : return 3 + 1;
17854 : :
17855 : : has_mem = true;
17856 : : }
17857 : :
17858 : 3001280 : return has_mem ? 2 + 1 : reg_only;
17859 : : }
17860 : :
17861 : :
17862 : : static bool
17863 : : ix86_class_likely_spilled_p (reg_class_t);
17864 : :
17865 : : /* Returns true if lhs of insn is HW function argument register and set up
17866 : : is_spilled to true if it is likely spilled HW register. */
17867 : : static bool
17868 : 1163 : insn_is_function_arg (rtx insn, bool* is_spilled)
17869 : : {
17870 : 1163 : rtx dst;
17871 : :
17872 : 1163 : if (!NONDEBUG_INSN_P (insn))
17873 : : return false;
17874 : : /* Call instructions are not movable, ignore it. */
17875 : 1163 : if (CALL_P (insn))
17876 : : return false;
17877 : 1098 : insn = PATTERN (insn);
17878 : 1098 : if (GET_CODE (insn) == PARALLEL)
17879 : 75 : insn = XVECEXP (insn, 0, 0);
17880 : 1098 : if (GET_CODE (insn) != SET)
17881 : : return false;
17882 : 1098 : dst = SET_DEST (insn);
17883 : 994 : if (REG_P (dst) && HARD_REGISTER_P (dst)
17884 : 1974 : && ix86_function_arg_regno_p (REGNO (dst)))
17885 : : {
17886 : : /* Is it likely spilled HW register? */
17887 : 876 : if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst))
17888 : 876 : && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))))
17889 : 832 : *is_spilled = true;
17890 : 876 : return true;
17891 : : }
17892 : : return false;
17893 : : }
17894 : :
17895 : : /* Add output dependencies for chain of function adjacent arguments if only
17896 : : there is a move to likely spilled HW register. Return first argument
17897 : : if at least one dependence was added or NULL otherwise. */
17898 : : static rtx_insn *
17899 : 422 : add_parameter_dependencies (rtx_insn *call, rtx_insn *head)
17900 : : {
17901 : 422 : rtx_insn *insn;
17902 : 422 : rtx_insn *last = call;
17903 : 422 : rtx_insn *first_arg = NULL;
17904 : 422 : bool is_spilled = false;
17905 : :
17906 : 422 : head = PREV_INSN (head);
17907 : :
17908 : : /* Find nearest to call argument passing instruction. */
17909 : 422 : while (true)
17910 : : {
17911 : 422 : last = PREV_INSN (last);
17912 : 422 : if (last == head)
17913 : : return NULL;
17914 : 422 : if (!NONDEBUG_INSN_P (last))
17915 : 0 : continue;
17916 : 422 : if (insn_is_function_arg (last, &is_spilled))
17917 : : break;
17918 : : return NULL;
17919 : : }
17920 : :
17921 : : first_arg = last;
17922 : 1143 : while (true)
17923 : : {
17924 : 1143 : insn = PREV_INSN (last);
17925 : 1143 : if (!INSN_P (insn))
17926 : : break;
17927 : 1049 : if (insn == head)
17928 : : break;
17929 : 1008 : if (!NONDEBUG_INSN_P (insn))
17930 : : {
17931 : 267 : last = insn;
17932 : 267 : continue;
17933 : : }
17934 : 741 : if (insn_is_function_arg (insn, &is_spilled))
17935 : : {
17936 : : /* Add output depdendence between two function arguments if chain
17937 : : of output arguments contains likely spilled HW registers. */
17938 : 461 : if (is_spilled)
17939 : 461 : add_dependence (first_arg, insn, REG_DEP_OUTPUT);
17940 : : first_arg = last = insn;
17941 : : }
17942 : : else
17943 : : break;
17944 : : }
17945 : 415 : if (!is_spilled)
17946 : : return NULL;
17947 : : return first_arg;
17948 : : }
17949 : :
17950 : : /* Add output or anti dependency from insn to first_arg to restrict its code
17951 : : motion. */
17952 : : static void
17953 : 2457 : avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn)
17954 : : {
17955 : 2457 : rtx set;
17956 : 2457 : rtx tmp;
17957 : :
17958 : 2457 : set = single_set (insn);
17959 : 2457 : if (!set)
17960 : : return;
17961 : 1482 : tmp = SET_DEST (set);
17962 : 1482 : if (REG_P (tmp))
17963 : : {
17964 : : /* Add output dependency to the first function argument. */
17965 : 1272 : add_dependence (first_arg, insn, REG_DEP_OUTPUT);
17966 : 1272 : return;
17967 : : }
17968 : : /* Add anti dependency. */
17969 : 210 : add_dependence (first_arg, insn, REG_DEP_ANTI);
17970 : : }
17971 : :
17972 : : /* Avoid cross block motion of function argument through adding dependency
17973 : : from the first non-jump instruction in bb. */
17974 : : static void
17975 : 68 : add_dependee_for_func_arg (rtx_insn *arg, basic_block bb)
17976 : : {
17977 : 68 : rtx_insn *insn = BB_END (bb);
17978 : :
17979 : 134 : while (insn)
17980 : : {
17981 : 134 : if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn))
17982 : : {
17983 : 67 : rtx set = single_set (insn);
17984 : 67 : if (set)
17985 : : {
17986 : 67 : avoid_func_arg_motion (arg, insn);
17987 : 67 : return;
17988 : : }
17989 : : }
17990 : 67 : if (insn == BB_HEAD (bb))
17991 : : return;
17992 : 66 : insn = PREV_INSN (insn);
17993 : : }
17994 : : }
17995 : :
17996 : : /* Hook for pre-reload schedule - avoid motion of function arguments
17997 : : passed in likely spilled HW registers. */
17998 : : static void
17999 : 9998338 : ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail)
18000 : : {
18001 : 9998338 : rtx_insn *insn;
18002 : 9998338 : rtx_insn *first_arg = NULL;
18003 : 9998338 : if (reload_completed)
18004 : : return;
18005 : 1567 : while (head != tail && DEBUG_INSN_P (head))
18006 : 365 : head = NEXT_INSN (head);
18007 : 9225 : for (insn = tail; insn != head; insn = PREV_INSN (insn))
18008 : 8155 : if (INSN_P (insn) && CALL_P (insn))
18009 : : {
18010 : 422 : first_arg = add_parameter_dependencies (insn, head);
18011 : 422 : if (first_arg)
18012 : : {
18013 : : /* Add dependee for first argument to predecessors if only
18014 : : region contains more than one block. */
18015 : 415 : basic_block bb = BLOCK_FOR_INSN (insn);
18016 : 415 : int rgn = CONTAINING_RGN (bb->index);
18017 : 415 : int nr_blks = RGN_NR_BLOCKS (rgn);
18018 : : /* Skip trivial regions and region head blocks that can have
18019 : : predecessors outside of region. */
18020 : 415 : if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0)
18021 : : {
18022 : 67 : edge e;
18023 : 67 : edge_iterator ei;
18024 : :
18025 : : /* Regions are SCCs with the exception of selective
18026 : : scheduling with pipelining of outer blocks enabled.
18027 : : So also check that immediate predecessors of a non-head
18028 : : block are in the same region. */
18029 : 137 : FOR_EACH_EDGE (e, ei, bb->preds)
18030 : : {
18031 : : /* Avoid creating of loop-carried dependencies through
18032 : : using topological ordering in the region. */
18033 : 70 : if (rgn == CONTAINING_RGN (e->src->index)
18034 : 69 : && BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index))
18035 : 68 : add_dependee_for_func_arg (first_arg, e->src);
18036 : : }
18037 : : }
18038 : 415 : insn = first_arg;
18039 : 415 : if (insn == head)
18040 : : break;
18041 : : }
18042 : : }
18043 : 7733 : else if (first_arg)
18044 : 2390 : avoid_func_arg_motion (first_arg, insn);
18045 : : }
18046 : :
18047 : : /* Hook for pre-reload schedule - set priority of moves from likely spilled
18048 : : HW registers to maximum, to schedule them at soon as possible. These are
18049 : : moves from function argument registers at the top of the function entry
18050 : : and moves from function return value registers after call. */
18051 : : static int
18052 : 104146475 : ix86_adjust_priority (rtx_insn *insn, int priority)
18053 : : {
18054 : 104146475 : rtx set;
18055 : :
18056 : 104146475 : if (reload_completed)
18057 : : return priority;
18058 : :
18059 : 12571 : if (!NONDEBUG_INSN_P (insn))
18060 : : return priority;
18061 : :
18062 : 10849 : set = single_set (insn);
18063 : 10849 : if (set)
18064 : : {
18065 : 10333 : rtx tmp = SET_SRC (set);
18066 : 10333 : if (REG_P (tmp)
18067 : 2308 : && HARD_REGISTER_P (tmp)
18068 : 496 : && !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp))
18069 : 10333 : && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp))))
18070 : 446 : return current_sched_info->sched_max_insns_priority;
18071 : : }
18072 : :
18073 : : return priority;
18074 : : }
18075 : :
18076 : : /* Prepare for scheduling pass. */
18077 : : static void
18078 : 942242 : ix86_sched_init_global (FILE *, int, int)
18079 : : {
18080 : : /* Install scheduling hooks for current CPU. Some of these hooks are used
18081 : : in time-critical parts of the scheduler, so we only set them up when
18082 : : they are actually used. */
18083 : 942242 : switch (ix86_tune)
18084 : : {
18085 : 895854 : case PROCESSOR_CORE2:
18086 : 895854 : case PROCESSOR_NEHALEM:
18087 : 895854 : case PROCESSOR_SANDYBRIDGE:
18088 : 895854 : case PROCESSOR_HASWELL:
18089 : 895854 : case PROCESSOR_TREMONT:
18090 : 895854 : case PROCESSOR_ALDERLAKE:
18091 : 895854 : case PROCESSOR_GENERIC:
18092 : : /* Do not perform multipass scheduling for pre-reload schedule
18093 : : to save compile time. */
18094 : 895854 : if (reload_completed)
18095 : : {
18096 : 895557 : ix86_core2i7_init_hooks ();
18097 : 895557 : break;
18098 : : }
18099 : : /* Fall through. */
18100 : 46685 : default:
18101 : 46685 : targetm.sched.dfa_post_advance_cycle = NULL;
18102 : 46685 : targetm.sched.first_cycle_multipass_init = NULL;
18103 : 46685 : targetm.sched.first_cycle_multipass_begin = NULL;
18104 : 46685 : targetm.sched.first_cycle_multipass_issue = NULL;
18105 : 46685 : targetm.sched.first_cycle_multipass_backtrack = NULL;
18106 : 46685 : targetm.sched.first_cycle_multipass_end = NULL;
18107 : 46685 : targetm.sched.first_cycle_multipass_fini = NULL;
18108 : 46685 : break;
18109 : : }
18110 : 942242 : }
18111 : :
18112 : :
18113 : : /* Implement TARGET_STATIC_RTX_ALIGNMENT. */
18114 : :
18115 : : static HOST_WIDE_INT
18116 : 707283 : ix86_static_rtx_alignment (machine_mode mode)
18117 : : {
18118 : 707283 : if (mode == DFmode)
18119 : : return 64;
18120 : : if (ALIGN_MODE_128 (mode))
18121 : 152056 : return MAX (128, GET_MODE_ALIGNMENT (mode));
18122 : 471324 : return GET_MODE_ALIGNMENT (mode);
18123 : : }
18124 : :
18125 : : /* Implement TARGET_CONSTANT_ALIGNMENT. */
18126 : :
18127 : : static HOST_WIDE_INT
18128 : 6753825 : ix86_constant_alignment (const_tree exp, HOST_WIDE_INT align)
18129 : : {
18130 : 6753825 : if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
18131 : : || TREE_CODE (exp) == INTEGER_CST)
18132 : : {
18133 : 358314 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
18134 : 358314 : HOST_WIDE_INT mode_align = ix86_static_rtx_alignment (mode);
18135 : 358314 : return MAX (mode_align, align);
18136 : : }
18137 : 6256208 : else if (!optimize_size && TREE_CODE (exp) == STRING_CST
18138 : 9418356 : && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
18139 : : return BITS_PER_WORD;
18140 : :
18141 : : return align;
18142 : : }
18143 : :
18144 : : /* Implement TARGET_EMPTY_RECORD_P. */
18145 : :
18146 : : static bool
18147 : 1246506280 : ix86_is_empty_record (const_tree type)
18148 : : {
18149 : 1246506280 : if (!TARGET_64BIT)
18150 : : return false;
18151 : 1216845909 : return default_is_empty_record (type);
18152 : : }
18153 : :
18154 : : /* Implement TARGET_WARN_PARAMETER_PASSING_ABI. */
18155 : :
18156 : : static void
18157 : 15085030 : ix86_warn_parameter_passing_abi (cumulative_args_t cum_v, tree type)
18158 : : {
18159 : 15085030 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
18160 : :
18161 : 15085030 : if (!cum->warn_empty)
18162 : : return;
18163 : :
18164 : 14964179 : if (!TYPE_EMPTY_P (type))
18165 : : return;
18166 : :
18167 : : /* Don't warn if the function isn't visible outside of the TU. */
18168 : 16696 : if (cum->decl && !TREE_PUBLIC (cum->decl))
18169 : : return;
18170 : :
18171 : 15072 : tree decl = cum->decl;
18172 : 15072 : if (!decl)
18173 : : /* If we don't know the target, look at the current TU. */
18174 : 54 : decl = current_function_decl;
18175 : :
18176 : 15072 : const_tree ctx = get_ultimate_context (decl);
18177 : 15072 : if (ctx == NULL_TREE
18178 : 30109 : || !TRANSLATION_UNIT_WARN_EMPTY_P (ctx))
18179 : : return;
18180 : :
18181 : : /* If the actual size of the type is zero, then there is no change
18182 : : in how objects of this size are passed. */
18183 : 72 : if (int_size_in_bytes (type) == 0)
18184 : : return;
18185 : :
18186 : 66 : warning (OPT_Wabi, "empty class %qT parameter passing ABI "
18187 : : "changes in %<-fabi-version=12%> (GCC 8)", type);
18188 : :
18189 : : /* Only warn once. */
18190 : 66 : cum->warn_empty = false;
18191 : : }
18192 : :
18193 : : /* This hook returns name of multilib ABI. */
18194 : :
18195 : : static const char *
18196 : 3294219 : ix86_get_multilib_abi_name (void)
18197 : : {
18198 : 3294219 : if (!(TARGET_64BIT_P (ix86_isa_flags)))
18199 : : return "i386";
18200 : 3250263 : else if (TARGET_X32_P (ix86_isa_flags))
18201 : : return "x32";
18202 : : else
18203 : 3250263 : return "x86_64";
18204 : : }
18205 : :
18206 : : /* Compute the alignment for a variable for Intel MCU psABI. TYPE is
18207 : : the data type, and ALIGN is the alignment that the object would
18208 : : ordinarily have. */
18209 : :
18210 : : static int
18211 : 0 : iamcu_alignment (tree type, int align)
18212 : : {
18213 : 0 : machine_mode mode;
18214 : :
18215 : 0 : if (align < 32 || TYPE_USER_ALIGN (type))
18216 : : return align;
18217 : :
18218 : : /* Intel MCU psABI specifies scalar types > 4 bytes aligned to 4
18219 : : bytes. */
18220 : 0 : type = strip_array_types (type);
18221 : 0 : if (TYPE_ATOMIC (type))
18222 : : return align;
18223 : :
18224 : 0 : mode = TYPE_MODE (type);
18225 : 0 : switch (GET_MODE_CLASS (mode))
18226 : : {
18227 : : case MODE_INT:
18228 : : case MODE_COMPLEX_INT:
18229 : : case MODE_COMPLEX_FLOAT:
18230 : : case MODE_FLOAT:
18231 : : case MODE_DECIMAL_FLOAT:
18232 : : return 32;
18233 : : default:
18234 : : return align;
18235 : : }
18236 : : }
18237 : :
18238 : : /* Compute the alignment for a static variable.
18239 : : TYPE is the data type, and ALIGN is the alignment that
18240 : : the object would ordinarily have. The value of this function is used
18241 : : instead of that alignment to align the object. */
18242 : :
18243 : : int
18244 : 11856408 : ix86_data_alignment (tree type, unsigned int align, bool opt)
18245 : : {
18246 : : /* GCC 4.8 and earlier used to incorrectly assume this alignment even
18247 : : for symbols from other compilation units or symbols that don't need
18248 : : to bind locally. In order to preserve some ABI compatibility with
18249 : : those compilers, ensure we don't decrease alignment from what we
18250 : : used to assume. */
18251 : :
18252 : 11856408 : unsigned int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT);
18253 : :
18254 : : /* A data structure, equal or greater than the size of a cache line
18255 : : (64 bytes in the Pentium 4 and other recent Intel processors, including
18256 : : processors based on Intel Core microarchitecture) should be aligned
18257 : : so that its base address is a multiple of a cache line size. */
18258 : :
18259 : 23712816 : unsigned int max_align
18260 : 11856408 : = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
18261 : :
18262 : 14436338 : if (max_align < BITS_PER_WORD)
18263 : 0 : max_align = BITS_PER_WORD;
18264 : :
18265 : 11856408 : switch (ix86_align_data_type)
18266 : : {
18267 : 11856408 : case ix86_align_data_type_abi: opt = false; break;
18268 : 11856388 : case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break;
18269 : : case ix86_align_data_type_cacheline: break;
18270 : : }
18271 : :
18272 : 11856408 : if (TARGET_IAMCU)
18273 : 0 : align = iamcu_alignment (type, align);
18274 : :
18275 : 11856408 : if (opt
18276 : 5730088 : && AGGREGATE_TYPE_P (type)
18277 : 3672817 : && TYPE_SIZE (type)
18278 : 15529193 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
18279 : : {
18280 : 6651331 : if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align_compat)
18281 : 3672785 : && align < max_align_compat)
18282 : 694239 : align = max_align_compat;
18283 : 7285159 : if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align)
18284 : 3672785 : && align < max_align)
18285 : 60411 : align = max_align;
18286 : : }
18287 : :
18288 : : /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18289 : : to 16byte boundary. */
18290 : 11856408 : if (TARGET_64BIT)
18291 : : {
18292 : 4835699 : if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
18293 : 3209325 : && TYPE_SIZE (type)
18294 : 3209283 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18295 : 10688359 : && wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128)
18296 : 11292748 : && align < 128)
18297 : 604389 : return 128;
18298 : : }
18299 : :
18300 : 11252019 : if (!opt)
18301 : 5935761 : return align;
18302 : :
18303 : 5316258 : if (TREE_CODE (type) == ARRAY_TYPE)
18304 : : {
18305 : 1085152 : if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18306 : : return 64;
18307 : 1085152 : if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18308 : : return 128;
18309 : : }
18310 : 4231106 : else if (TREE_CODE (type) == COMPLEX_TYPE)
18311 : : {
18312 : :
18313 : 12861 : if (TYPE_MODE (type) == DCmode && align < 64)
18314 : : return 64;
18315 : 12861 : if ((TYPE_MODE (type) == XCmode
18316 : 12861 : || TYPE_MODE (type) == TCmode) && align < 128)
18317 : : return 128;
18318 : : }
18319 : 4218245 : else if (RECORD_OR_UNION_TYPE_P (type)
18320 : 4218245 : && TYPE_FIELDS (type))
18321 : : {
18322 : 2172159 : if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18323 : : return 64;
18324 : 2172159 : if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18325 : : return 128;
18326 : : }
18327 : 2046086 : else if (SCALAR_FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type)
18328 : : || TREE_CODE (type) == INTEGER_TYPE)
18329 : : {
18330 : 1906296 : if (TYPE_MODE (type) == DFmode && align < 64)
18331 : : return 64;
18332 : 1906296 : if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18333 : : return 128;
18334 : : }
18335 : :
18336 : 5316145 : return align;
18337 : : }
18338 : :
18339 : : /* Implememnt TARGET_LOWER_LOCAL_DECL_ALIGNMENT. */
18340 : : static void
18341 : 29723349 : ix86_lower_local_decl_alignment (tree decl)
18342 : : {
18343 : 29723349 : unsigned int new_align = ix86_local_alignment (decl, VOIDmode,
18344 : 29723349 : DECL_ALIGN (decl), true);
18345 : 29723349 : if (new_align < DECL_ALIGN (decl))
18346 : 0 : SET_DECL_ALIGN (decl, new_align);
18347 : 29723349 : }
18348 : :
18349 : : /* Compute the alignment for a local variable or a stack slot. EXP is
18350 : : the data type or decl itself, MODE is the widest mode available and
18351 : : ALIGN is the alignment that the object would ordinarily have. The
18352 : : value of this macro is used instead of that alignment to align the
18353 : : object. */
18354 : :
18355 : : unsigned int
18356 : 46735855 : ix86_local_alignment (tree exp, machine_mode mode,
18357 : : unsigned int align, bool may_lower)
18358 : : {
18359 : 46735855 : tree type, decl;
18360 : :
18361 : 46735855 : if (exp && DECL_P (exp))
18362 : : {
18363 : 44660557 : type = TREE_TYPE (exp);
18364 : 44660557 : decl = exp;
18365 : : }
18366 : : else
18367 : : {
18368 : : type = exp;
18369 : : decl = NULL;
18370 : : }
18371 : :
18372 : : /* Don't do dynamic stack realignment for long long objects with
18373 : : -mpreferred-stack-boundary=2. */
18374 : 46735855 : if (may_lower
18375 : 29723349 : && !TARGET_64BIT
18376 : 236626 : && align == 64
18377 : 37806 : && ix86_preferred_stack_boundary < 64
18378 : 0 : && (mode == DImode || (type && TYPE_MODE (type) == DImode))
18379 : 0 : && (!type || (!TYPE_USER_ALIGN (type)
18380 : 0 : && !TYPE_ATOMIC (strip_array_types (type))))
18381 : 46735855 : && (!decl || !DECL_USER_ALIGN (decl)))
18382 : : align = 32;
18383 : :
18384 : : /* If TYPE is NULL, we are allocating a stack slot for caller-save
18385 : : register in MODE. We will return the largest alignment of XF
18386 : : and DF. */
18387 : 46735855 : if (!type)
18388 : : {
18389 : 1339952 : if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
18390 : 1491 : align = GET_MODE_ALIGNMENT (DFmode);
18391 : 1339952 : return align;
18392 : : }
18393 : :
18394 : : /* Don't increase alignment for Intel MCU psABI. */
18395 : 45395903 : if (TARGET_IAMCU)
18396 : : return align;
18397 : :
18398 : : /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18399 : : to 16byte boundary. Exact wording is:
18400 : :
18401 : : An array uses the same alignment as its elements, except that a local or
18402 : : global array variable of length at least 16 bytes or
18403 : : a C99 variable-length array variable always has alignment of at least 16 bytes.
18404 : :
18405 : : This was added to allow use of aligned SSE instructions at arrays. This
18406 : : rule is meant for static storage (where compiler cannot do the analysis
18407 : : by itself). We follow it for automatic variables only when convenient.
18408 : : We fully control everything in the function compiled and functions from
18409 : : other unit cannot rely on the alignment.
18410 : :
18411 : : Exclude va_list type. It is the common case of local array where
18412 : : we cannot benefit from the alignment.
18413 : :
18414 : : TODO: Probably one should optimize for size only when var is not escaping. */
18415 : 42555984 : if (TARGET_64BIT && optimize_function_for_speed_p (cfun)
18416 : 87620674 : && TARGET_SSE)
18417 : : {
18418 : 42186116 : if (AGGREGATE_TYPE_P (type)
18419 : 8726228 : && (va_list_type_node == NULL_TREE
18420 : 8726228 : || (TYPE_MAIN_VARIANT (type)
18421 : 8726228 : != TYPE_MAIN_VARIANT (va_list_type_node)))
18422 : 8629574 : && TYPE_SIZE (type)
18423 : 8629574 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18424 : 43170236 : && wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128)
18425 : 48607198 : && align < 128)
18426 : 5436962 : return 128;
18427 : : }
18428 : 39958941 : if (TREE_CODE (type) == ARRAY_TYPE)
18429 : : {
18430 : 771898 : if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18431 : : return 64;
18432 : 771898 : if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18433 : : return 128;
18434 : : }
18435 : 39187043 : else if (TREE_CODE (type) == COMPLEX_TYPE)
18436 : : {
18437 : 152981 : if (TYPE_MODE (type) == DCmode && align < 64)
18438 : : return 64;
18439 : 152981 : if ((TYPE_MODE (type) == XCmode
18440 : 152981 : || TYPE_MODE (type) == TCmode) && align < 128)
18441 : : return 128;
18442 : : }
18443 : 39034062 : else if (RECORD_OR_UNION_TYPE_P (type)
18444 : 39034062 : && TYPE_FIELDS (type))
18445 : : {
18446 : 4477722 : if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18447 : : return 64;
18448 : 4474617 : if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18449 : : return 128;
18450 : : }
18451 : 34556340 : else if (SCALAR_FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type)
18452 : : || TREE_CODE (type) == INTEGER_TYPE)
18453 : : {
18454 : :
18455 : 28641995 : if (TYPE_MODE (type) == DFmode && align < 64)
18456 : : return 64;
18457 : 28641995 : if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18458 : : return 128;
18459 : : }
18460 : : return align;
18461 : : }
18462 : :
18463 : : /* Compute the minimum required alignment for dynamic stack realignment
18464 : : purposes for a local variable, parameter or a stack slot. EXP is
18465 : : the data type or decl itself, MODE is its mode and ALIGN is the
18466 : : alignment that the object would ordinarily have. */
18467 : :
18468 : : unsigned int
18469 : 47076077 : ix86_minimum_alignment (tree exp, machine_mode mode,
18470 : : unsigned int align)
18471 : : {
18472 : 47076077 : tree type, decl;
18473 : :
18474 : 47076077 : if (exp && DECL_P (exp))
18475 : : {
18476 : 15101855 : type = TREE_TYPE (exp);
18477 : 15101855 : decl = exp;
18478 : : }
18479 : : else
18480 : : {
18481 : : type = exp;
18482 : : decl = NULL;
18483 : : }
18484 : :
18485 : 47076077 : if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
18486 : : return align;
18487 : :
18488 : : /* Don't do dynamic stack realignment for long long objects with
18489 : : -mpreferred-stack-boundary=2. */
18490 : 0 : if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
18491 : 0 : && (!type || (!TYPE_USER_ALIGN (type)
18492 : 0 : && !TYPE_ATOMIC (strip_array_types (type))))
18493 : 0 : && (!decl || !DECL_USER_ALIGN (decl)))
18494 : : {
18495 : 0 : gcc_checking_assert (!TARGET_STV);
18496 : : return 32;
18497 : : }
18498 : :
18499 : : return align;
18500 : : }
18501 : :
18502 : : /* Find a location for the static chain incoming to a nested function.
18503 : : This is a register, unless all free registers are used by arguments. */
18504 : :
18505 : : static rtx
18506 : 266910 : ix86_static_chain (const_tree fndecl_or_type, bool incoming_p)
18507 : : {
18508 : 266910 : unsigned regno;
18509 : :
18510 : 266910 : if (TARGET_64BIT)
18511 : : {
18512 : : /* We always use R10 in 64-bit mode. */
18513 : : regno = R10_REG;
18514 : : }
18515 : : else
18516 : : {
18517 : 88418 : const_tree fntype, fndecl;
18518 : 88418 : unsigned int ccvt;
18519 : :
18520 : : /* By default in 32-bit mode we use ECX to pass the static chain. */
18521 : 88418 : regno = CX_REG;
18522 : :
18523 : 88418 : if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL)
18524 : : {
18525 : 78513 : fntype = TREE_TYPE (fndecl_or_type);
18526 : 78513 : fndecl = fndecl_or_type;
18527 : : }
18528 : : else
18529 : : {
18530 : : fntype = fndecl_or_type;
18531 : : fndecl = NULL;
18532 : : }
18533 : :
18534 : 88418 : ccvt = ix86_get_callcvt (fntype);
18535 : 88418 : if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
18536 : : {
18537 : : /* Fastcall functions use ecx/edx for arguments, which leaves
18538 : : us with EAX for the static chain.
18539 : : Thiscall functions use ecx for arguments, which also
18540 : : leaves us with EAX for the static chain. */
18541 : : regno = AX_REG;
18542 : : }
18543 : 88418 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
18544 : : {
18545 : : /* Thiscall functions use ecx for arguments, which leaves
18546 : : us with EAX and EDX for the static chain.
18547 : : We are using for abi-compatibility EAX. */
18548 : : regno = AX_REG;
18549 : : }
18550 : 88418 : else if (ix86_function_regparm (fntype, fndecl) == 3)
18551 : : {
18552 : : /* For regparm 3, we have no free call-clobbered registers in
18553 : : which to store the static chain. In order to implement this,
18554 : : we have the trampoline push the static chain to the stack.
18555 : : However, we can't push a value below the return address when
18556 : : we call the nested function directly, so we have to use an
18557 : : alternate entry point. For this we use ESI, and have the
18558 : : alternate entry point push ESI, so that things appear the
18559 : : same once we're executing the nested function. */
18560 : 0 : if (incoming_p)
18561 : : {
18562 : 0 : if (fndecl == current_function_decl
18563 : 0 : && !ix86_static_chain_on_stack)
18564 : : {
18565 : 0 : gcc_assert (!reload_completed);
18566 : 0 : ix86_static_chain_on_stack = true;
18567 : : }
18568 : 0 : return gen_frame_mem (SImode,
18569 : 0 : plus_constant (Pmode,
18570 : 0 : arg_pointer_rtx, -8));
18571 : : }
18572 : : regno = SI_REG;
18573 : : }
18574 : : }
18575 : :
18576 : 266910 : return gen_rtx_REG (Pmode, regno);
18577 : : }
18578 : :
18579 : : /* Emit RTL insns to initialize the variable parts of a trampoline.
18580 : : FNDECL is the decl of the target address; M_TRAMP is a MEM for
18581 : : the trampoline, and CHAIN_VALUE is an RTX for the static chain
18582 : : to be passed to the target function. */
18583 : :
18584 : : static void
18585 : 290 : ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
18586 : : {
18587 : 290 : rtx mem, fnaddr;
18588 : 290 : int opcode;
18589 : 290 : int offset = 0;
18590 : 290 : bool need_endbr = (flag_cf_protection & CF_BRANCH);
18591 : :
18592 : 290 : fnaddr = XEXP (DECL_RTL (fndecl), 0);
18593 : :
18594 : 290 : if (TARGET_64BIT)
18595 : : {
18596 : 290 : int size;
18597 : :
18598 : 290 : if (need_endbr)
18599 : : {
18600 : : /* Insert ENDBR64. */
18601 : 1 : mem = adjust_address (m_tramp, SImode, offset);
18602 : 1 : emit_move_insn (mem, gen_int_mode (0xfa1e0ff3, SImode));
18603 : 1 : offset += 4;
18604 : : }
18605 : :
18606 : : /* Load the function address to r11. Try to load address using
18607 : : the shorter movl instead of movabs. We may want to support
18608 : : movq for kernel mode, but kernel does not use trampolines at
18609 : : the moment. FNADDR is a 32bit address and may not be in
18610 : : DImode when ptr_mode == SImode. Always use movl in this
18611 : : case. */
18612 : 290 : if (ptr_mode == SImode
18613 : 290 : || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
18614 : : {
18615 : 258 : fnaddr = copy_addr_to_reg (fnaddr);
18616 : :
18617 : 258 : mem = adjust_address (m_tramp, HImode, offset);
18618 : 258 : emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
18619 : :
18620 : 258 : mem = adjust_address (m_tramp, SImode, offset + 2);
18621 : 258 : emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
18622 : 258 : offset += 6;
18623 : : }
18624 : : else
18625 : : {
18626 : 32 : mem = adjust_address (m_tramp, HImode, offset);
18627 : 32 : emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
18628 : :
18629 : 32 : mem = adjust_address (m_tramp, DImode, offset + 2);
18630 : 32 : emit_move_insn (mem, fnaddr);
18631 : 32 : offset += 10;
18632 : : }
18633 : :
18634 : : /* Load static chain using movabs to r10. Use the shorter movl
18635 : : instead of movabs when ptr_mode == SImode. */
18636 : 290 : if (ptr_mode == SImode)
18637 : : {
18638 : : opcode = 0xba41;
18639 : : size = 6;
18640 : : }
18641 : : else
18642 : : {
18643 : 290 : opcode = 0xba49;
18644 : 290 : size = 10;
18645 : : }
18646 : :
18647 : 290 : mem = adjust_address (m_tramp, HImode, offset);
18648 : 290 : emit_move_insn (mem, gen_int_mode (opcode, HImode));
18649 : :
18650 : 290 : mem = adjust_address (m_tramp, ptr_mode, offset + 2);
18651 : 290 : emit_move_insn (mem, chain_value);
18652 : 290 : offset += size;
18653 : :
18654 : : /* Jump to r11; the last (unused) byte is a nop, only there to
18655 : : pad the write out to a single 32-bit store. */
18656 : 290 : mem = adjust_address (m_tramp, SImode, offset);
18657 : 290 : emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
18658 : 290 : offset += 4;
18659 : : }
18660 : : else
18661 : : {
18662 : 0 : rtx disp, chain;
18663 : :
18664 : : /* Depending on the static chain location, either load a register
18665 : : with a constant, or push the constant to the stack. All of the
18666 : : instructions are the same size. */
18667 : 0 : chain = ix86_static_chain (fndecl, true);
18668 : 0 : if (REG_P (chain))
18669 : : {
18670 : 0 : switch (REGNO (chain))
18671 : : {
18672 : : case AX_REG:
18673 : : opcode = 0xb8; break;
18674 : 0 : case CX_REG:
18675 : 0 : opcode = 0xb9; break;
18676 : 0 : default:
18677 : 0 : gcc_unreachable ();
18678 : : }
18679 : : }
18680 : : else
18681 : : opcode = 0x68;
18682 : :
18683 : 0 : if (need_endbr)
18684 : : {
18685 : : /* Insert ENDBR32. */
18686 : 0 : mem = adjust_address (m_tramp, SImode, offset);
18687 : 0 : emit_move_insn (mem, gen_int_mode (0xfb1e0ff3, SImode));
18688 : 0 : offset += 4;
18689 : : }
18690 : :
18691 : 0 : mem = adjust_address (m_tramp, QImode, offset);
18692 : 0 : emit_move_insn (mem, gen_int_mode (opcode, QImode));
18693 : :
18694 : 0 : mem = adjust_address (m_tramp, SImode, offset + 1);
18695 : 0 : emit_move_insn (mem, chain_value);
18696 : 0 : offset += 5;
18697 : :
18698 : 0 : mem = adjust_address (m_tramp, QImode, offset);
18699 : 0 : emit_move_insn (mem, gen_int_mode (0xe9, QImode));
18700 : :
18701 : 0 : mem = adjust_address (m_tramp, SImode, offset + 1);
18702 : :
18703 : : /* Compute offset from the end of the jmp to the target function.
18704 : : In the case in which the trampoline stores the static chain on
18705 : : the stack, we need to skip the first insn which pushes the
18706 : : (call-saved) register static chain; this push is 1 byte. */
18707 : 0 : offset += 5;
18708 : 0 : int skip = MEM_P (chain) ? 1 : 0;
18709 : : /* Skip ENDBR32 at the entry of the target function. */
18710 : 0 : if (need_endbr
18711 : 0 : && !cgraph_node::get (fndecl)->only_called_directly_p ())
18712 : 0 : skip += 4;
18713 : 0 : disp = expand_binop (SImode, sub_optab, fnaddr,
18714 : 0 : plus_constant (Pmode, XEXP (m_tramp, 0),
18715 : 0 : offset - skip),
18716 : : NULL_RTX, 1, OPTAB_DIRECT);
18717 : 0 : emit_move_insn (mem, disp);
18718 : : }
18719 : :
18720 : 290 : gcc_assert (offset <= TRAMPOLINE_SIZE);
18721 : :
18722 : : #ifdef HAVE_ENABLE_EXECUTE_STACK
18723 : : #ifdef CHECK_EXECUTE_STACK_ENABLED
18724 : : if (CHECK_EXECUTE_STACK_ENABLED)
18725 : : #endif
18726 : : emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
18727 : : LCT_NORMAL, VOIDmode, XEXP (m_tramp, 0), Pmode);
18728 : : #endif
18729 : 290 : }
18730 : :
18731 : : static bool
18732 : 53738958 : ix86_allocate_stack_slots_for_args (void)
18733 : : {
18734 : : /* Naked functions should not allocate stack slots for arguments. */
18735 : 53738958 : return !ix86_function_naked (current_function_decl);
18736 : : }
18737 : :
18738 : : static bool
18739 : 31857937 : ix86_warn_func_return (tree decl)
18740 : : {
18741 : : /* Naked functions are implemented entirely in assembly, including the
18742 : : return sequence, so suppress warnings about this. */
18743 : 31857937 : return !ix86_function_naked (decl);
18744 : : }
18745 : :
18746 : : /* Return the shift count of a vector by scalar shift builtin second argument
18747 : : ARG1. */
18748 : : static tree
18749 : 14122 : ix86_vector_shift_count (tree arg1)
18750 : : {
18751 : 14122 : if (tree_fits_uhwi_p (arg1))
18752 : : return arg1;
18753 : 8296 : else if (TREE_CODE (arg1) == VECTOR_CST && CHAR_BIT == 8)
18754 : : {
18755 : : /* The count argument is weird, passed in as various 128-bit
18756 : : (or 64-bit) vectors, the low 64 bits from it are the count. */
18757 : 162 : unsigned char buf[16];
18758 : 162 : int len = native_encode_expr (arg1, buf, 16);
18759 : 162 : if (len == 0)
18760 : 162 : return NULL_TREE;
18761 : 162 : tree t = native_interpret_expr (uint64_type_node, buf, len);
18762 : 162 : if (t && tree_fits_uhwi_p (t))
18763 : : return t;
18764 : : }
18765 : : return NULL_TREE;
18766 : : }
18767 : :
18768 : : /* Return true if arg_mask is all ones, ELEMS is elements number of
18769 : : corresponding vector. */
18770 : : static bool
18771 : 25032 : ix86_masked_all_ones (unsigned HOST_WIDE_INT elems, tree arg_mask)
18772 : : {
18773 : 25032 : if (TREE_CODE (arg_mask) != INTEGER_CST)
18774 : : return false;
18775 : :
18776 : 7452 : unsigned HOST_WIDE_INT mask = TREE_INT_CST_LOW (arg_mask);
18777 : 7452 : if (elems == HOST_BITS_PER_WIDE_INT)
18778 : 33 : return mask == HOST_WIDE_INT_M1U;
18779 : 7419 : if ((mask | (HOST_WIDE_INT_M1U << elems)) != HOST_WIDE_INT_M1U)
18780 : 2671 : return false;
18781 : :
18782 : : return true;
18783 : : }
18784 : :
18785 : : static tree
18786 : 66066236 : ix86_fold_builtin (tree fndecl, int n_args,
18787 : : tree *args, bool ignore ATTRIBUTE_UNUSED)
18788 : : {
18789 : 66066236 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
18790 : : {
18791 : 66066236 : enum ix86_builtins fn_code
18792 : 66066236 : = (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
18793 : 66066236 : enum rtx_code rcode;
18794 : 66066236 : bool is_vshift;
18795 : 66066236 : enum tree_code tcode;
18796 : 66066236 : bool is_scalar;
18797 : 66066236 : unsigned HOST_WIDE_INT mask;
18798 : :
18799 : 66066236 : switch (fn_code)
18800 : : {
18801 : 8364 : case IX86_BUILTIN_CPU_IS:
18802 : 8364 : case IX86_BUILTIN_CPU_SUPPORTS:
18803 : 8364 : gcc_assert (n_args == 1);
18804 : 8364 : return fold_builtin_cpu (fndecl, args);
18805 : :
18806 : 20513 : case IX86_BUILTIN_NANQ:
18807 : 20513 : case IX86_BUILTIN_NANSQ:
18808 : 20513 : {
18809 : 20513 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18810 : 20513 : const char *str = c_getstr (*args);
18811 : 20513 : int quiet = fn_code == IX86_BUILTIN_NANQ;
18812 : 20513 : REAL_VALUE_TYPE real;
18813 : :
18814 : 20513 : if (str && real_nan (&real, str, quiet, TYPE_MODE (type)))
18815 : 20513 : return build_real (type, real);
18816 : 0 : return NULL_TREE;
18817 : : }
18818 : :
18819 : 108 : case IX86_BUILTIN_INFQ:
18820 : 108 : case IX86_BUILTIN_HUGE_VALQ:
18821 : 108 : {
18822 : 108 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18823 : 108 : REAL_VALUE_TYPE inf;
18824 : 108 : real_inf (&inf);
18825 : 108 : return build_real (type, inf);
18826 : : }
18827 : :
18828 : 60533 : case IX86_BUILTIN_TZCNT16:
18829 : 60533 : case IX86_BUILTIN_CTZS:
18830 : 60533 : case IX86_BUILTIN_TZCNT32:
18831 : 60533 : case IX86_BUILTIN_TZCNT64:
18832 : 60533 : gcc_assert (n_args == 1);
18833 : 60533 : if (TREE_CODE (args[0]) == INTEGER_CST)
18834 : : {
18835 : 45 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18836 : 45 : tree arg = args[0];
18837 : 45 : if (fn_code == IX86_BUILTIN_TZCNT16
18838 : 45 : || fn_code == IX86_BUILTIN_CTZS)
18839 : 3 : arg = fold_convert (short_unsigned_type_node, arg);
18840 : 45 : if (integer_zerop (arg))
18841 : 6 : return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
18842 : : else
18843 : 39 : return fold_const_call (CFN_CTZ, type, arg);
18844 : : }
18845 : : break;
18846 : :
18847 : 50399 : case IX86_BUILTIN_LZCNT16:
18848 : 50399 : case IX86_BUILTIN_CLZS:
18849 : 50399 : case IX86_BUILTIN_LZCNT32:
18850 : 50399 : case IX86_BUILTIN_LZCNT64:
18851 : 50399 : gcc_assert (n_args == 1);
18852 : 50399 : if (TREE_CODE (args[0]) == INTEGER_CST)
18853 : : {
18854 : 54 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18855 : 54 : tree arg = args[0];
18856 : 54 : if (fn_code == IX86_BUILTIN_LZCNT16
18857 : 54 : || fn_code == IX86_BUILTIN_CLZS)
18858 : 18 : arg = fold_convert (short_unsigned_type_node, arg);
18859 : 54 : if (integer_zerop (arg))
18860 : 3 : return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
18861 : : else
18862 : 51 : return fold_const_call (CFN_CLZ, type, arg);
18863 : : }
18864 : : break;
18865 : :
18866 : 59485 : case IX86_BUILTIN_BEXTR32:
18867 : 59485 : case IX86_BUILTIN_BEXTR64:
18868 : 59485 : case IX86_BUILTIN_BEXTRI32:
18869 : 59485 : case IX86_BUILTIN_BEXTRI64:
18870 : 59485 : gcc_assert (n_args == 2);
18871 : 59485 : if (tree_fits_uhwi_p (args[1]))
18872 : : {
18873 : 152 : unsigned HOST_WIDE_INT res = 0;
18874 : 152 : unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0]));
18875 : 152 : unsigned int start = tree_to_uhwi (args[1]);
18876 : 152 : unsigned int len = (start & 0xff00) >> 8;
18877 : 152 : tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
18878 : 152 : start &= 0xff;
18879 : 152 : if (start >= prec || len == 0)
18880 : 111 : return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
18881 : : args[0]);
18882 : 41 : else if (!tree_fits_uhwi_p (args[0]))
18883 : : break;
18884 : : else
18885 : 24 : res = tree_to_uhwi (args[0]) >> start;
18886 : 24 : if (len > prec)
18887 : : len = prec;
18888 : 24 : if (len < HOST_BITS_PER_WIDE_INT)
18889 : 15 : res &= (HOST_WIDE_INT_1U << len) - 1;
18890 : 24 : return build_int_cstu (lhs_type, res);
18891 : : }
18892 : : break;
18893 : :
18894 : 20404 : case IX86_BUILTIN_BZHI32:
18895 : 20404 : case IX86_BUILTIN_BZHI64:
18896 : 20404 : gcc_assert (n_args == 2);
18897 : 20404 : if (tree_fits_uhwi_p (args[1]))
18898 : : {
18899 : 190 : unsigned int idx = tree_to_uhwi (args[1]) & 0xff;
18900 : 190 : tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
18901 : 190 : if (idx >= TYPE_PRECISION (TREE_TYPE (args[0])))
18902 : : return args[0];
18903 : 190 : if (idx == 0)
18904 : 52 : return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
18905 : : args[0]);
18906 : 138 : if (!tree_fits_uhwi_p (args[0]))
18907 : : break;
18908 : 12 : unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]);
18909 : 12 : res &= ~(HOST_WIDE_INT_M1U << idx);
18910 : 12 : return build_int_cstu (lhs_type, res);
18911 : : }
18912 : : break;
18913 : :
18914 : 20162 : case IX86_BUILTIN_PDEP32:
18915 : 20162 : case IX86_BUILTIN_PDEP64:
18916 : 20162 : gcc_assert (n_args == 2);
18917 : 20162 : if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1]))
18918 : : {
18919 : 46 : unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]);
18920 : 46 : unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]);
18921 : 46 : unsigned HOST_WIDE_INT res = 0;
18922 : 46 : unsigned HOST_WIDE_INT m, k = 1;
18923 : 2990 : for (m = 1; m; m <<= 1)
18924 : 2944 : if ((mask & m) != 0)
18925 : : {
18926 : 1440 : if ((src & k) != 0)
18927 : 789 : res |= m;
18928 : 1440 : k <<= 1;
18929 : : }
18930 : 46 : return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
18931 : : }
18932 : : break;
18933 : :
18934 : 20164 : case IX86_BUILTIN_PEXT32:
18935 : 20164 : case IX86_BUILTIN_PEXT64:
18936 : 20164 : gcc_assert (n_args == 2);
18937 : 20164 : if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1]))
18938 : : {
18939 : 46 : unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]);
18940 : 46 : unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]);
18941 : 46 : unsigned HOST_WIDE_INT res = 0;
18942 : 46 : unsigned HOST_WIDE_INT m, k = 1;
18943 : 2990 : for (m = 1; m; m <<= 1)
18944 : 2944 : if ((mask & m) != 0)
18945 : : {
18946 : 2016 : if ((src & m) != 0)
18947 : 1063 : res |= k;
18948 : 2016 : k <<= 1;
18949 : : }
18950 : 46 : return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
18951 : : }
18952 : : break;
18953 : :
18954 : 79040 : case IX86_BUILTIN_MOVMSKPS:
18955 : 79040 : case IX86_BUILTIN_PMOVMSKB:
18956 : 79040 : case IX86_BUILTIN_MOVMSKPD:
18957 : 79040 : case IX86_BUILTIN_PMOVMSKB128:
18958 : 79040 : case IX86_BUILTIN_MOVMSKPD256:
18959 : 79040 : case IX86_BUILTIN_MOVMSKPS256:
18960 : 79040 : case IX86_BUILTIN_PMOVMSKB256:
18961 : 79040 : gcc_assert (n_args == 1);
18962 : 79040 : if (TREE_CODE (args[0]) == VECTOR_CST)
18963 : : {
18964 : : HOST_WIDE_INT res = 0;
18965 : 139 : for (unsigned i = 0; i < VECTOR_CST_NELTS (args[0]); ++i)
18966 : : {
18967 : 124 : tree e = VECTOR_CST_ELT (args[0], i);
18968 : 124 : if (TREE_CODE (e) == INTEGER_CST && !TREE_OVERFLOW (e))
18969 : : {
18970 : 80 : if (wi::neg_p (wi::to_wide (e)))
18971 : 31 : res |= HOST_WIDE_INT_1 << i;
18972 : : }
18973 : 44 : else if (TREE_CODE (e) == REAL_CST && !TREE_OVERFLOW (e))
18974 : : {
18975 : 44 : if (TREE_REAL_CST (e).sign)
18976 : 19 : res |= HOST_WIDE_INT_1 << i;
18977 : : }
18978 : : else
18979 : : return NULL_TREE;
18980 : : }
18981 : 15 : return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), res);
18982 : : }
18983 : : break;
18984 : :
18985 : 641700 : case IX86_BUILTIN_PSLLD:
18986 : 641700 : case IX86_BUILTIN_PSLLD128:
18987 : 641700 : case IX86_BUILTIN_PSLLD128_MASK:
18988 : 641700 : case IX86_BUILTIN_PSLLD256:
18989 : 641700 : case IX86_BUILTIN_PSLLD256_MASK:
18990 : 641700 : case IX86_BUILTIN_PSLLD512:
18991 : 641700 : case IX86_BUILTIN_PSLLDI:
18992 : 641700 : case IX86_BUILTIN_PSLLDI128:
18993 : 641700 : case IX86_BUILTIN_PSLLDI128_MASK:
18994 : 641700 : case IX86_BUILTIN_PSLLDI256:
18995 : 641700 : case IX86_BUILTIN_PSLLDI256_MASK:
18996 : 641700 : case IX86_BUILTIN_PSLLDI512:
18997 : 641700 : case IX86_BUILTIN_PSLLQ:
18998 : 641700 : case IX86_BUILTIN_PSLLQ128:
18999 : 641700 : case IX86_BUILTIN_PSLLQ128_MASK:
19000 : 641700 : case IX86_BUILTIN_PSLLQ256:
19001 : 641700 : case IX86_BUILTIN_PSLLQ256_MASK:
19002 : 641700 : case IX86_BUILTIN_PSLLQ512:
19003 : 641700 : case IX86_BUILTIN_PSLLQI:
19004 : 641700 : case IX86_BUILTIN_PSLLQI128:
19005 : 641700 : case IX86_BUILTIN_PSLLQI128_MASK:
19006 : 641700 : case IX86_BUILTIN_PSLLQI256:
19007 : 641700 : case IX86_BUILTIN_PSLLQI256_MASK:
19008 : 641700 : case IX86_BUILTIN_PSLLQI512:
19009 : 641700 : case IX86_BUILTIN_PSLLW:
19010 : 641700 : case IX86_BUILTIN_PSLLW128:
19011 : 641700 : case IX86_BUILTIN_PSLLW128_MASK:
19012 : 641700 : case IX86_BUILTIN_PSLLW256:
19013 : 641700 : case IX86_BUILTIN_PSLLW256_MASK:
19014 : 641700 : case IX86_BUILTIN_PSLLW512_MASK:
19015 : 641700 : case IX86_BUILTIN_PSLLWI:
19016 : 641700 : case IX86_BUILTIN_PSLLWI128:
19017 : 641700 : case IX86_BUILTIN_PSLLWI128_MASK:
19018 : 641700 : case IX86_BUILTIN_PSLLWI256:
19019 : 641700 : case IX86_BUILTIN_PSLLWI256_MASK:
19020 : 641700 : case IX86_BUILTIN_PSLLWI512_MASK:
19021 : 641700 : rcode = ASHIFT;
19022 : 641700 : is_vshift = false;
19023 : 641700 : goto do_shift;
19024 : 585439 : case IX86_BUILTIN_PSRAD:
19025 : 585439 : case IX86_BUILTIN_PSRAD128:
19026 : 585439 : case IX86_BUILTIN_PSRAD128_MASK:
19027 : 585439 : case IX86_BUILTIN_PSRAD256:
19028 : 585439 : case IX86_BUILTIN_PSRAD256_MASK:
19029 : 585439 : case IX86_BUILTIN_PSRAD512:
19030 : 585439 : case IX86_BUILTIN_PSRADI:
19031 : 585439 : case IX86_BUILTIN_PSRADI128:
19032 : 585439 : case IX86_BUILTIN_PSRADI128_MASK:
19033 : 585439 : case IX86_BUILTIN_PSRADI256:
19034 : 585439 : case IX86_BUILTIN_PSRADI256_MASK:
19035 : 585439 : case IX86_BUILTIN_PSRADI512:
19036 : 585439 : case IX86_BUILTIN_PSRAQ128_MASK:
19037 : 585439 : case IX86_BUILTIN_PSRAQ256_MASK:
19038 : 585439 : case IX86_BUILTIN_PSRAQ512:
19039 : 585439 : case IX86_BUILTIN_PSRAQI128_MASK:
19040 : 585439 : case IX86_BUILTIN_PSRAQI256_MASK:
19041 : 585439 : case IX86_BUILTIN_PSRAQI512:
19042 : 585439 : case IX86_BUILTIN_PSRAW:
19043 : 585439 : case IX86_BUILTIN_PSRAW128:
19044 : 585439 : case IX86_BUILTIN_PSRAW128_MASK:
19045 : 585439 : case IX86_BUILTIN_PSRAW256:
19046 : 585439 : case IX86_BUILTIN_PSRAW256_MASK:
19047 : 585439 : case IX86_BUILTIN_PSRAW512:
19048 : 585439 : case IX86_BUILTIN_PSRAWI:
19049 : 585439 : case IX86_BUILTIN_PSRAWI128:
19050 : 585439 : case IX86_BUILTIN_PSRAWI128_MASK:
19051 : 585439 : case IX86_BUILTIN_PSRAWI256:
19052 : 585439 : case IX86_BUILTIN_PSRAWI256_MASK:
19053 : 585439 : case IX86_BUILTIN_PSRAWI512:
19054 : 585439 : rcode = ASHIFTRT;
19055 : 585439 : is_vshift = false;
19056 : 585439 : goto do_shift;
19057 : 616849 : case IX86_BUILTIN_PSRLD:
19058 : 616849 : case IX86_BUILTIN_PSRLD128:
19059 : 616849 : case IX86_BUILTIN_PSRLD128_MASK:
19060 : 616849 : case IX86_BUILTIN_PSRLD256:
19061 : 616849 : case IX86_BUILTIN_PSRLD256_MASK:
19062 : 616849 : case IX86_BUILTIN_PSRLD512:
19063 : 616849 : case IX86_BUILTIN_PSRLDI:
19064 : 616849 : case IX86_BUILTIN_PSRLDI128:
19065 : 616849 : case IX86_BUILTIN_PSRLDI128_MASK:
19066 : 616849 : case IX86_BUILTIN_PSRLDI256:
19067 : 616849 : case IX86_BUILTIN_PSRLDI256_MASK:
19068 : 616849 : case IX86_BUILTIN_PSRLDI512:
19069 : 616849 : case IX86_BUILTIN_PSRLQ:
19070 : 616849 : case IX86_BUILTIN_PSRLQ128:
19071 : 616849 : case IX86_BUILTIN_PSRLQ128_MASK:
19072 : 616849 : case IX86_BUILTIN_PSRLQ256:
19073 : 616849 : case IX86_BUILTIN_PSRLQ256_MASK:
19074 : 616849 : case IX86_BUILTIN_PSRLQ512:
19075 : 616849 : case IX86_BUILTIN_PSRLQI:
19076 : 616849 : case IX86_BUILTIN_PSRLQI128:
19077 : 616849 : case IX86_BUILTIN_PSRLQI128_MASK:
19078 : 616849 : case IX86_BUILTIN_PSRLQI256:
19079 : 616849 : case IX86_BUILTIN_PSRLQI256_MASK:
19080 : 616849 : case IX86_BUILTIN_PSRLQI512:
19081 : 616849 : case IX86_BUILTIN_PSRLW:
19082 : 616849 : case IX86_BUILTIN_PSRLW128:
19083 : 616849 : case IX86_BUILTIN_PSRLW128_MASK:
19084 : 616849 : case IX86_BUILTIN_PSRLW256:
19085 : 616849 : case IX86_BUILTIN_PSRLW256_MASK:
19086 : 616849 : case IX86_BUILTIN_PSRLW512:
19087 : 616849 : case IX86_BUILTIN_PSRLWI:
19088 : 616849 : case IX86_BUILTIN_PSRLWI128:
19089 : 616849 : case IX86_BUILTIN_PSRLWI128_MASK:
19090 : 616849 : case IX86_BUILTIN_PSRLWI256:
19091 : 616849 : case IX86_BUILTIN_PSRLWI256_MASK:
19092 : 616849 : case IX86_BUILTIN_PSRLWI512:
19093 : 616849 : rcode = LSHIFTRT;
19094 : 616849 : is_vshift = false;
19095 : 616849 : goto do_shift;
19096 : 267880 : case IX86_BUILTIN_PSLLVV16HI:
19097 : 267880 : case IX86_BUILTIN_PSLLVV16SI:
19098 : 267880 : case IX86_BUILTIN_PSLLVV2DI:
19099 : 267880 : case IX86_BUILTIN_PSLLVV2DI_MASK:
19100 : 267880 : case IX86_BUILTIN_PSLLVV32HI:
19101 : 267880 : case IX86_BUILTIN_PSLLVV4DI:
19102 : 267880 : case IX86_BUILTIN_PSLLVV4DI_MASK:
19103 : 267880 : case IX86_BUILTIN_PSLLVV4SI:
19104 : 267880 : case IX86_BUILTIN_PSLLVV4SI_MASK:
19105 : 267880 : case IX86_BUILTIN_PSLLVV8DI:
19106 : 267880 : case IX86_BUILTIN_PSLLVV8HI:
19107 : 267880 : case IX86_BUILTIN_PSLLVV8SI:
19108 : 267880 : case IX86_BUILTIN_PSLLVV8SI_MASK:
19109 : 267880 : rcode = ASHIFT;
19110 : 267880 : is_vshift = true;
19111 : 267880 : goto do_shift;
19112 : 267505 : case IX86_BUILTIN_PSRAVQ128:
19113 : 267505 : case IX86_BUILTIN_PSRAVQ256:
19114 : 267505 : case IX86_BUILTIN_PSRAVV16HI:
19115 : 267505 : case IX86_BUILTIN_PSRAVV16SI:
19116 : 267505 : case IX86_BUILTIN_PSRAVV32HI:
19117 : 267505 : case IX86_BUILTIN_PSRAVV4SI:
19118 : 267505 : case IX86_BUILTIN_PSRAVV4SI_MASK:
19119 : 267505 : case IX86_BUILTIN_PSRAVV8DI:
19120 : 267505 : case IX86_BUILTIN_PSRAVV8HI:
19121 : 267505 : case IX86_BUILTIN_PSRAVV8SI:
19122 : 267505 : case IX86_BUILTIN_PSRAVV8SI_MASK:
19123 : 267505 : rcode = ASHIFTRT;
19124 : 267505 : is_vshift = true;
19125 : 267505 : goto do_shift;
19126 : 267871 : case IX86_BUILTIN_PSRLVV16HI:
19127 : 267871 : case IX86_BUILTIN_PSRLVV16SI:
19128 : 267871 : case IX86_BUILTIN_PSRLVV2DI:
19129 : 267871 : case IX86_BUILTIN_PSRLVV2DI_MASK:
19130 : 267871 : case IX86_BUILTIN_PSRLVV32HI:
19131 : 267871 : case IX86_BUILTIN_PSRLVV4DI:
19132 : 267871 : case IX86_BUILTIN_PSRLVV4DI_MASK:
19133 : 267871 : case IX86_BUILTIN_PSRLVV4SI:
19134 : 267871 : case IX86_BUILTIN_PSRLVV4SI_MASK:
19135 : 267871 : case IX86_BUILTIN_PSRLVV8DI:
19136 : 267871 : case IX86_BUILTIN_PSRLVV8HI:
19137 : 267871 : case IX86_BUILTIN_PSRLVV8SI:
19138 : 267871 : case IX86_BUILTIN_PSRLVV8SI_MASK:
19139 : 267871 : rcode = LSHIFTRT;
19140 : 267871 : is_vshift = true;
19141 : 267871 : goto do_shift;
19142 : :
19143 : 2647244 : do_shift:
19144 : 2647244 : gcc_assert (n_args >= 2);
19145 : 2647244 : if (TREE_CODE (args[0]) != VECTOR_CST)
19146 : : break;
19147 : 916 : mask = HOST_WIDE_INT_M1U;
19148 : 916 : if (n_args > 2)
19149 : : {
19150 : : /* This is masked shift. */
19151 : 667 : if (!tree_fits_uhwi_p (args[n_args - 1])
19152 : 667 : || TREE_SIDE_EFFECTS (args[n_args - 2]))
19153 : : break;
19154 : 667 : mask = tree_to_uhwi (args[n_args - 1]);
19155 : 667 : unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19156 : 667 : mask |= HOST_WIDE_INT_M1U << elems;
19157 : 667 : if (mask != HOST_WIDE_INT_M1U
19158 : 556 : && TREE_CODE (args[n_args - 2]) != VECTOR_CST)
19159 : : break;
19160 : 633 : if (mask == (HOST_WIDE_INT_M1U << elems))
19161 : : return args[n_args - 2];
19162 : : }
19163 : 879 : if (is_vshift && TREE_CODE (args[1]) != VECTOR_CST)
19164 : : break;
19165 : 178 : if (tree tem = (is_vshift ? integer_one_node
19166 : 879 : : ix86_vector_shift_count (args[1])))
19167 : : {
19168 : 558 : unsigned HOST_WIDE_INT count = tree_to_uhwi (tem);
19169 : 558 : unsigned HOST_WIDE_INT prec
19170 : 558 : = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0])));
19171 : 558 : if (count == 0 && mask == HOST_WIDE_INT_M1U)
19172 : : return args[0];
19173 : 558 : if (count >= prec)
19174 : : {
19175 : 72 : if (rcode == ASHIFTRT)
19176 : 27 : count = prec - 1;
19177 : 45 : else if (mask == HOST_WIDE_INT_M1U)
19178 : 3 : return build_zero_cst (TREE_TYPE (args[0]));
19179 : : }
19180 : 555 : tree countt = NULL_TREE;
19181 : 555 : if (!is_vshift)
19182 : : {
19183 : 377 : if (count >= prec)
19184 : 42 : countt = integer_zero_node;
19185 : : else
19186 : 335 : countt = build_int_cst (integer_type_node, count);
19187 : : }
19188 : 555 : tree_vector_builder builder;
19189 : 555 : if (mask != HOST_WIDE_INT_M1U || is_vshift)
19190 : 392 : builder.new_vector (TREE_TYPE (args[0]),
19191 : 784 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])),
19192 : : 1);
19193 : : else
19194 : 163 : builder.new_unary_operation (TREE_TYPE (args[0]), args[0],
19195 : : false);
19196 : 555 : unsigned int cnt = builder.encoded_nelts ();
19197 : 5967 : for (unsigned int i = 0; i < cnt; ++i)
19198 : : {
19199 : 5412 : tree elt = VECTOR_CST_ELT (args[0], i);
19200 : 5412 : if (TREE_CODE (elt) != INTEGER_CST || TREE_OVERFLOW (elt))
19201 : 0 : return NULL_TREE;
19202 : 5412 : tree type = TREE_TYPE (elt);
19203 : 5412 : if (rcode == LSHIFTRT)
19204 : 2040 : elt = fold_convert (unsigned_type_for (type), elt);
19205 : 5412 : if (is_vshift)
19206 : : {
19207 : 1846 : countt = VECTOR_CST_ELT (args[1], i);
19208 : 1846 : if (TREE_CODE (countt) != INTEGER_CST
19209 : 1846 : || TREE_OVERFLOW (countt))
19210 : : return NULL_TREE;
19211 : 1846 : if (wi::neg_p (wi::to_wide (countt))
19212 : 3610 : || wi::to_widest (countt) >= prec)
19213 : : {
19214 : 325 : if (rcode == ASHIFTRT)
19215 : 108 : countt = build_int_cst (TREE_TYPE (countt),
19216 : 108 : prec - 1);
19217 : : else
19218 : : {
19219 : 217 : elt = build_zero_cst (TREE_TYPE (elt));
19220 : 217 : countt = build_zero_cst (TREE_TYPE (countt));
19221 : : }
19222 : : }
19223 : : }
19224 : 3566 : else if (count >= prec)
19225 : 504 : elt = build_zero_cst (TREE_TYPE (elt));
19226 : 8950 : elt = const_binop (rcode == ASHIFT
19227 : : ? LSHIFT_EXPR : RSHIFT_EXPR,
19228 : 5412 : TREE_TYPE (elt), elt, countt);
19229 : 5412 : if (!elt || TREE_CODE (elt) != INTEGER_CST)
19230 : : return NULL_TREE;
19231 : 5412 : if (rcode == LSHIFTRT)
19232 : 2040 : elt = fold_convert (type, elt);
19233 : 5412 : if ((mask & (HOST_WIDE_INT_1U << i)) == 0)
19234 : : {
19235 : 1566 : elt = VECTOR_CST_ELT (args[n_args - 2], i);
19236 : 1566 : if (TREE_CODE (elt) != INTEGER_CST
19237 : 1566 : || TREE_OVERFLOW (elt))
19238 : : return NULL_TREE;
19239 : : }
19240 : 5412 : builder.quick_push (elt);
19241 : : }
19242 : 555 : return builder.build ();
19243 : 555 : }
19244 : : break;
19245 : :
19246 : 31802 : case IX86_BUILTIN_MINSS:
19247 : 31802 : case IX86_BUILTIN_MINSH_MASK:
19248 : 31802 : tcode = LT_EXPR;
19249 : 31802 : is_scalar = true;
19250 : 31802 : goto do_minmax;
19251 : :
19252 : 31802 : case IX86_BUILTIN_MAXSS:
19253 : 31802 : case IX86_BUILTIN_MAXSH_MASK:
19254 : 31802 : tcode = GT_EXPR;
19255 : 31802 : is_scalar = true;
19256 : 31802 : goto do_minmax;
19257 : :
19258 : 340172 : case IX86_BUILTIN_MINPS:
19259 : 340172 : case IX86_BUILTIN_MINPD:
19260 : 340172 : case IX86_BUILTIN_MINPS256:
19261 : 340172 : case IX86_BUILTIN_MINPD256:
19262 : 340172 : case IX86_BUILTIN_MINPS512:
19263 : 340172 : case IX86_BUILTIN_MINPD512:
19264 : 340172 : case IX86_BUILTIN_MINPS128_MASK:
19265 : 340172 : case IX86_BUILTIN_MINPD128_MASK:
19266 : 340172 : case IX86_BUILTIN_MINPS256_MASK:
19267 : 340172 : case IX86_BUILTIN_MINPD256_MASK:
19268 : 340172 : case IX86_BUILTIN_MINPH128_MASK:
19269 : 340172 : case IX86_BUILTIN_MINPH256_MASK:
19270 : 340172 : case IX86_BUILTIN_MINPH512_MASK:
19271 : 340172 : tcode = LT_EXPR;
19272 : 340172 : is_scalar = false;
19273 : 340172 : goto do_minmax;
19274 : :
19275 : : case IX86_BUILTIN_MAXPS:
19276 : : case IX86_BUILTIN_MAXPD:
19277 : : case IX86_BUILTIN_MAXPS256:
19278 : : case IX86_BUILTIN_MAXPD256:
19279 : : case IX86_BUILTIN_MAXPS512:
19280 : : case IX86_BUILTIN_MAXPD512:
19281 : : case IX86_BUILTIN_MAXPS128_MASK:
19282 : : case IX86_BUILTIN_MAXPD128_MASK:
19283 : : case IX86_BUILTIN_MAXPS256_MASK:
19284 : : case IX86_BUILTIN_MAXPD256_MASK:
19285 : : case IX86_BUILTIN_MAXPH128_MASK:
19286 : : case IX86_BUILTIN_MAXPH256_MASK:
19287 : : case IX86_BUILTIN_MAXPH512_MASK:
19288 : : tcode = GT_EXPR;
19289 : : is_scalar = false;
19290 : 743968 : do_minmax:
19291 : 743968 : gcc_assert (n_args >= 2);
19292 : 743968 : if (TREE_CODE (args[0]) != VECTOR_CST
19293 : 76 : || TREE_CODE (args[1]) != VECTOR_CST)
19294 : : break;
19295 : 76 : mask = HOST_WIDE_INT_M1U;
19296 : 76 : if (n_args > 2)
19297 : : {
19298 : 36 : gcc_assert (n_args >= 4);
19299 : : /* This is masked minmax. */
19300 : 36 : if (TREE_CODE (args[3]) != INTEGER_CST
19301 : 36 : || TREE_SIDE_EFFECTS (args[2]))
19302 : : break;
19303 : 36 : mask = TREE_INT_CST_LOW (args[3]);
19304 : 36 : unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19305 : 36 : mask |= HOST_WIDE_INT_M1U << elems;
19306 : 36 : if (mask != HOST_WIDE_INT_M1U
19307 : 32 : && TREE_CODE (args[2]) != VECTOR_CST)
19308 : : break;
19309 : 36 : if (n_args >= 5)
19310 : : {
19311 : 20 : if (!tree_fits_uhwi_p (args[4]))
19312 : : break;
19313 : 20 : if (tree_to_uhwi (args[4]) != 4
19314 : 0 : && tree_to_uhwi (args[4]) != 8)
19315 : : break;
19316 : : }
19317 : 36 : if (mask == (HOST_WIDE_INT_M1U << elems))
19318 : : return args[2];
19319 : : }
19320 : : /* Punt on NaNs, unless exceptions are disabled. */
19321 : 76 : if (HONOR_NANS (args[0])
19322 : 76 : && (n_args < 5 || tree_to_uhwi (args[4]) != 8))
19323 : 184 : for (int i = 0; i < 2; ++i)
19324 : : {
19325 : 134 : unsigned count = vector_cst_encoded_nelts (args[i]);
19326 : 957 : for (unsigned j = 0; j < count; ++j)
19327 : 849 : if (tree_expr_nan_p (VECTOR_CST_ENCODED_ELT (args[i], j)))
19328 : : return NULL_TREE;
19329 : : }
19330 : 50 : {
19331 : 50 : tree res = const_binop (tcode,
19332 : 50 : truth_type_for (TREE_TYPE (args[0])),
19333 : : args[0], args[1]);
19334 : 50 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19335 : : break;
19336 : 50 : res = fold_ternary (VEC_COND_EXPR, TREE_TYPE (args[0]), res,
19337 : : args[0], args[1]);
19338 : 50 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19339 : : break;
19340 : 50 : if (mask != HOST_WIDE_INT_M1U)
19341 : : {
19342 : 32 : unsigned nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19343 : 32 : vec_perm_builder sel (nelts, nelts, 1);
19344 : 328 : for (unsigned int i = 0; i < nelts; i++)
19345 : 296 : if (mask & (HOST_WIDE_INT_1U << i))
19346 : 160 : sel.quick_push (i);
19347 : : else
19348 : 136 : sel.quick_push (nelts + i);
19349 : 32 : vec_perm_indices indices (sel, 2, nelts);
19350 : 32 : res = fold_vec_perm (TREE_TYPE (args[0]), res, args[2],
19351 : : indices);
19352 : 32 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19353 : : break;
19354 : 32 : }
19355 : 50 : if (is_scalar)
19356 : : {
19357 : 10 : unsigned nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19358 : 10 : vec_perm_builder sel (nelts, nelts, 1);
19359 : 10 : sel.quick_push (0);
19360 : 40 : for (unsigned int i = 1; i < nelts; i++)
19361 : 30 : sel.quick_push (nelts + i);
19362 : 10 : vec_perm_indices indices (sel, 2, nelts);
19363 : 10 : res = fold_vec_perm (TREE_TYPE (args[0]), res, args[0],
19364 : : indices);
19365 : 10 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19366 : : break;
19367 : 10 : }
19368 : 50 : return res;
19369 : : }
19370 : :
19371 : : default:
19372 : : break;
19373 : : }
19374 : : }
19375 : :
19376 : : #ifdef SUBTARGET_FOLD_BUILTIN
19377 : : return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore);
19378 : : #endif
19379 : :
19380 : : return NULL_TREE;
19381 : : }
19382 : :
19383 : : /* Fold a MD builtin (use ix86_fold_builtin for folding into
19384 : : constant) in GIMPLE. */
19385 : :
19386 : : bool
19387 : 1074400 : ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
19388 : : {
19389 : 1074400 : gimple *stmt = gsi_stmt (*gsi), *g;
19390 : 1074400 : gimple_seq stmts = NULL;
19391 : 1074400 : tree fndecl = gimple_call_fndecl (stmt);
19392 : 1074400 : gcc_checking_assert (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_MD));
19393 : 1074400 : int n_args = gimple_call_num_args (stmt);
19394 : 1074400 : enum ix86_builtins fn_code
19395 : 1074400 : = (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
19396 : 1074400 : tree decl = NULL_TREE;
19397 : 1074400 : tree arg0, arg1, arg2;
19398 : 1074400 : enum rtx_code rcode;
19399 : 1074400 : enum tree_code tcode;
19400 : 1074400 : unsigned HOST_WIDE_INT count;
19401 : 1074400 : bool is_vshift;
19402 : 1074400 : unsigned HOST_WIDE_INT elems;
19403 : 1074400 : location_t loc;
19404 : :
19405 : : /* Don't fold when there's isa mismatch. */
19406 : 1074400 : if (!ix86_check_builtin_isa_match (fn_code, NULL, NULL))
19407 : : return false;
19408 : :
19409 : 1074273 : switch (fn_code)
19410 : : {
19411 : 278 : case IX86_BUILTIN_TZCNT32:
19412 : 278 : decl = builtin_decl_implicit (BUILT_IN_CTZ);
19413 : 278 : goto fold_tzcnt_lzcnt;
19414 : :
19415 : 237 : case IX86_BUILTIN_TZCNT64:
19416 : 237 : decl = builtin_decl_implicit (BUILT_IN_CTZLL);
19417 : 237 : goto fold_tzcnt_lzcnt;
19418 : :
19419 : 215 : case IX86_BUILTIN_LZCNT32:
19420 : 215 : decl = builtin_decl_implicit (BUILT_IN_CLZ);
19421 : 215 : goto fold_tzcnt_lzcnt;
19422 : :
19423 : 224 : case IX86_BUILTIN_LZCNT64:
19424 : 224 : decl = builtin_decl_implicit (BUILT_IN_CLZLL);
19425 : 224 : goto fold_tzcnt_lzcnt;
19426 : :
19427 : 954 : fold_tzcnt_lzcnt:
19428 : 954 : gcc_assert (n_args == 1);
19429 : 954 : arg0 = gimple_call_arg (stmt, 0);
19430 : 954 : if (TREE_CODE (arg0) == SSA_NAME && decl && gimple_call_lhs (stmt))
19431 : : {
19432 : 790 : int prec = TYPE_PRECISION (TREE_TYPE (arg0));
19433 : : /* If arg0 is provably non-zero, optimize into generic
19434 : : __builtin_c[tl]z{,ll} function the middle-end handles
19435 : : better. */
19436 : 790 : if (!expr_not_equal_to (arg0, wi::zero (prec)))
19437 : : return false;
19438 : :
19439 : 8 : loc = gimple_location (stmt);
19440 : 8 : g = gimple_build_call (decl, 1, arg0);
19441 : 8 : gimple_set_location (g, loc);
19442 : 8 : tree lhs = make_ssa_name (integer_type_node);
19443 : 8 : gimple_call_set_lhs (g, lhs);
19444 : 8 : gsi_insert_before (gsi, g, GSI_SAME_STMT);
19445 : 8 : g = gimple_build_assign (gimple_call_lhs (stmt), NOP_EXPR, lhs);
19446 : 8 : gimple_set_location (g, loc);
19447 : 8 : gsi_replace (gsi, g, false);
19448 : 8 : return true;
19449 : : }
19450 : : break;
19451 : :
19452 : 491 : case IX86_BUILTIN_BZHI32:
19453 : 491 : case IX86_BUILTIN_BZHI64:
19454 : 491 : gcc_assert (n_args == 2);
19455 : 491 : arg1 = gimple_call_arg (stmt, 1);
19456 : 491 : if (tree_fits_uhwi_p (arg1) && gimple_call_lhs (stmt))
19457 : : {
19458 : 195 : unsigned int idx = tree_to_uhwi (arg1) & 0xff;
19459 : 195 : arg0 = gimple_call_arg (stmt, 0);
19460 : 195 : if (idx < TYPE_PRECISION (TREE_TYPE (arg0)))
19461 : : break;
19462 : 31 : loc = gimple_location (stmt);
19463 : 31 : g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
19464 : 31 : gimple_set_location (g, loc);
19465 : 31 : gsi_replace (gsi, g, false);
19466 : 31 : return true;
19467 : : }
19468 : : break;
19469 : :
19470 : 502 : case IX86_BUILTIN_PDEP32:
19471 : 502 : case IX86_BUILTIN_PDEP64:
19472 : 502 : case IX86_BUILTIN_PEXT32:
19473 : 502 : case IX86_BUILTIN_PEXT64:
19474 : 502 : gcc_assert (n_args == 2);
19475 : 502 : arg1 = gimple_call_arg (stmt, 1);
19476 : 502 : if (integer_all_onesp (arg1) && gimple_call_lhs (stmt))
19477 : : {
19478 : 4 : loc = gimple_location (stmt);
19479 : 4 : arg0 = gimple_call_arg (stmt, 0);
19480 : 4 : g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
19481 : 4 : gimple_set_location (g, loc);
19482 : 4 : gsi_replace (gsi, g, false);
19483 : 4 : return true;
19484 : : }
19485 : : break;
19486 : :
19487 : 145 : case IX86_BUILTIN_PBLENDVB256:
19488 : 145 : case IX86_BUILTIN_BLENDVPS256:
19489 : 145 : case IX86_BUILTIN_BLENDVPD256:
19490 : : /* pcmpeqb/d/q is under avx2, w/o avx2, it's veclower
19491 : : to scalar operations and not combined back. */
19492 : 145 : if (!TARGET_AVX2)
19493 : : break;
19494 : :
19495 : : /* FALLTHRU. */
19496 : 112 : case IX86_BUILTIN_BLENDVPD:
19497 : : /* blendvpd is under sse4.1 but pcmpgtq is under sse4.2,
19498 : : w/o sse4.2, it's veclowered to scalar operations and
19499 : : not combined back. */
19500 : 112 : if (!TARGET_SSE4_2)
19501 : : break;
19502 : : /* FALLTHRU. */
19503 : 149 : case IX86_BUILTIN_PBLENDVB128:
19504 : 149 : case IX86_BUILTIN_BLENDVPS:
19505 : 149 : gcc_assert (n_args == 3);
19506 : 149 : arg0 = gimple_call_arg (stmt, 0);
19507 : 149 : arg1 = gimple_call_arg (stmt, 1);
19508 : 149 : arg2 = gimple_call_arg (stmt, 2);
19509 : 149 : if (gimple_call_lhs (stmt))
19510 : : {
19511 : 149 : loc = gimple_location (stmt);
19512 : 149 : tree type = TREE_TYPE (arg2);
19513 : 149 : if (VECTOR_FLOAT_TYPE_P (type))
19514 : : {
19515 : 71 : tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode
19516 : 71 : ? intSI_type_node : intDI_type_node;
19517 : 71 : type = get_same_sized_vectype (itype, type);
19518 : : }
19519 : : else
19520 : 78 : type = signed_type_for (type);
19521 : 149 : arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2);
19522 : 149 : tree zero_vec = build_zero_cst (type);
19523 : 149 : tree cmp_type = truth_type_for (type);
19524 : 149 : tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec);
19525 : 149 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
19526 : 149 : g = gimple_build_assign (gimple_call_lhs (stmt),
19527 : : VEC_COND_EXPR, cmp,
19528 : : arg1, arg0);
19529 : 149 : gimple_set_location (g, loc);
19530 : 149 : gsi_replace (gsi, g, false);
19531 : : }
19532 : : else
19533 : 0 : gsi_replace (gsi, gimple_build_nop (), false);
19534 : : return true;
19535 : :
19536 : :
19537 : 16 : case IX86_BUILTIN_PCMPEQB128:
19538 : 16 : case IX86_BUILTIN_PCMPEQW128:
19539 : 16 : case IX86_BUILTIN_PCMPEQD128:
19540 : 16 : case IX86_BUILTIN_PCMPEQQ:
19541 : 16 : case IX86_BUILTIN_PCMPEQB256:
19542 : 16 : case IX86_BUILTIN_PCMPEQW256:
19543 : 16 : case IX86_BUILTIN_PCMPEQD256:
19544 : 16 : case IX86_BUILTIN_PCMPEQQ256:
19545 : 16 : tcode = EQ_EXPR;
19546 : 16 : goto do_cmp;
19547 : :
19548 : : case IX86_BUILTIN_PCMPGTB128:
19549 : : case IX86_BUILTIN_PCMPGTW128:
19550 : : case IX86_BUILTIN_PCMPGTD128:
19551 : : case IX86_BUILTIN_PCMPGTQ:
19552 : : case IX86_BUILTIN_PCMPGTB256:
19553 : : case IX86_BUILTIN_PCMPGTW256:
19554 : : case IX86_BUILTIN_PCMPGTD256:
19555 : : case IX86_BUILTIN_PCMPGTQ256:
19556 : : tcode = GT_EXPR;
19557 : :
19558 : 33 : do_cmp:
19559 : 33 : gcc_assert (n_args == 2);
19560 : 33 : arg0 = gimple_call_arg (stmt, 0);
19561 : 33 : arg1 = gimple_call_arg (stmt, 1);
19562 : 33 : if (gimple_call_lhs (stmt))
19563 : : {
19564 : 32 : loc = gimple_location (stmt);
19565 : 32 : tree type = TREE_TYPE (arg0);
19566 : 32 : tree zero_vec = build_zero_cst (type);
19567 : 32 : tree minus_one_vec = build_minus_one_cst (type);
19568 : 32 : tree cmp_type = truth_type_for (type);
19569 : 32 : tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1);
19570 : 32 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
19571 : 32 : g = gimple_build_assign (gimple_call_lhs (stmt),
19572 : : VEC_COND_EXPR, cmp,
19573 : : minus_one_vec, zero_vec);
19574 : 32 : gimple_set_location (g, loc);
19575 : 32 : gsi_replace (gsi, g, false);
19576 : : }
19577 : : else
19578 : 1 : gsi_replace (gsi, gimple_build_nop (), false);
19579 : : return true;
19580 : :
19581 : 9277 : case IX86_BUILTIN_PSLLD:
19582 : 9277 : case IX86_BUILTIN_PSLLD128:
19583 : 9277 : case IX86_BUILTIN_PSLLD128_MASK:
19584 : 9277 : case IX86_BUILTIN_PSLLD256:
19585 : 9277 : case IX86_BUILTIN_PSLLD256_MASK:
19586 : 9277 : case IX86_BUILTIN_PSLLD512:
19587 : 9277 : case IX86_BUILTIN_PSLLDI:
19588 : 9277 : case IX86_BUILTIN_PSLLDI128:
19589 : 9277 : case IX86_BUILTIN_PSLLDI128_MASK:
19590 : 9277 : case IX86_BUILTIN_PSLLDI256:
19591 : 9277 : case IX86_BUILTIN_PSLLDI256_MASK:
19592 : 9277 : case IX86_BUILTIN_PSLLDI512:
19593 : 9277 : case IX86_BUILTIN_PSLLQ:
19594 : 9277 : case IX86_BUILTIN_PSLLQ128:
19595 : 9277 : case IX86_BUILTIN_PSLLQ128_MASK:
19596 : 9277 : case IX86_BUILTIN_PSLLQ256:
19597 : 9277 : case IX86_BUILTIN_PSLLQ256_MASK:
19598 : 9277 : case IX86_BUILTIN_PSLLQ512:
19599 : 9277 : case IX86_BUILTIN_PSLLQI:
19600 : 9277 : case IX86_BUILTIN_PSLLQI128:
19601 : 9277 : case IX86_BUILTIN_PSLLQI128_MASK:
19602 : 9277 : case IX86_BUILTIN_PSLLQI256:
19603 : 9277 : case IX86_BUILTIN_PSLLQI256_MASK:
19604 : 9277 : case IX86_BUILTIN_PSLLQI512:
19605 : 9277 : case IX86_BUILTIN_PSLLW:
19606 : 9277 : case IX86_BUILTIN_PSLLW128:
19607 : 9277 : case IX86_BUILTIN_PSLLW128_MASK:
19608 : 9277 : case IX86_BUILTIN_PSLLW256:
19609 : 9277 : case IX86_BUILTIN_PSLLW256_MASK:
19610 : 9277 : case IX86_BUILTIN_PSLLW512_MASK:
19611 : 9277 : case IX86_BUILTIN_PSLLWI:
19612 : 9277 : case IX86_BUILTIN_PSLLWI128:
19613 : 9277 : case IX86_BUILTIN_PSLLWI128_MASK:
19614 : 9277 : case IX86_BUILTIN_PSLLWI256:
19615 : 9277 : case IX86_BUILTIN_PSLLWI256_MASK:
19616 : 9277 : case IX86_BUILTIN_PSLLWI512_MASK:
19617 : 9277 : rcode = ASHIFT;
19618 : 9277 : is_vshift = false;
19619 : 9277 : goto do_shift;
19620 : 6495 : case IX86_BUILTIN_PSRAD:
19621 : 6495 : case IX86_BUILTIN_PSRAD128:
19622 : 6495 : case IX86_BUILTIN_PSRAD128_MASK:
19623 : 6495 : case IX86_BUILTIN_PSRAD256:
19624 : 6495 : case IX86_BUILTIN_PSRAD256_MASK:
19625 : 6495 : case IX86_BUILTIN_PSRAD512:
19626 : 6495 : case IX86_BUILTIN_PSRADI:
19627 : 6495 : case IX86_BUILTIN_PSRADI128:
19628 : 6495 : case IX86_BUILTIN_PSRADI128_MASK:
19629 : 6495 : case IX86_BUILTIN_PSRADI256:
19630 : 6495 : case IX86_BUILTIN_PSRADI256_MASK:
19631 : 6495 : case IX86_BUILTIN_PSRADI512:
19632 : 6495 : case IX86_BUILTIN_PSRAQ128_MASK:
19633 : 6495 : case IX86_BUILTIN_PSRAQ256_MASK:
19634 : 6495 : case IX86_BUILTIN_PSRAQ512:
19635 : 6495 : case IX86_BUILTIN_PSRAQI128_MASK:
19636 : 6495 : case IX86_BUILTIN_PSRAQI256_MASK:
19637 : 6495 : case IX86_BUILTIN_PSRAQI512:
19638 : 6495 : case IX86_BUILTIN_PSRAW:
19639 : 6495 : case IX86_BUILTIN_PSRAW128:
19640 : 6495 : case IX86_BUILTIN_PSRAW128_MASK:
19641 : 6495 : case IX86_BUILTIN_PSRAW256:
19642 : 6495 : case IX86_BUILTIN_PSRAW256_MASK:
19643 : 6495 : case IX86_BUILTIN_PSRAW512:
19644 : 6495 : case IX86_BUILTIN_PSRAWI:
19645 : 6495 : case IX86_BUILTIN_PSRAWI128:
19646 : 6495 : case IX86_BUILTIN_PSRAWI128_MASK:
19647 : 6495 : case IX86_BUILTIN_PSRAWI256:
19648 : 6495 : case IX86_BUILTIN_PSRAWI256_MASK:
19649 : 6495 : case IX86_BUILTIN_PSRAWI512:
19650 : 6495 : rcode = ASHIFTRT;
19651 : 6495 : is_vshift = false;
19652 : 6495 : goto do_shift;
19653 : 7950 : case IX86_BUILTIN_PSRLD:
19654 : 7950 : case IX86_BUILTIN_PSRLD128:
19655 : 7950 : case IX86_BUILTIN_PSRLD128_MASK:
19656 : 7950 : case IX86_BUILTIN_PSRLD256:
19657 : 7950 : case IX86_BUILTIN_PSRLD256_MASK:
19658 : 7950 : case IX86_BUILTIN_PSRLD512:
19659 : 7950 : case IX86_BUILTIN_PSRLDI:
19660 : 7950 : case IX86_BUILTIN_PSRLDI128:
19661 : 7950 : case IX86_BUILTIN_PSRLDI128_MASK:
19662 : 7950 : case IX86_BUILTIN_PSRLDI256:
19663 : 7950 : case IX86_BUILTIN_PSRLDI256_MASK:
19664 : 7950 : case IX86_BUILTIN_PSRLDI512:
19665 : 7950 : case IX86_BUILTIN_PSRLQ:
19666 : 7950 : case IX86_BUILTIN_PSRLQ128:
19667 : 7950 : case IX86_BUILTIN_PSRLQ128_MASK:
19668 : 7950 : case IX86_BUILTIN_PSRLQ256:
19669 : 7950 : case IX86_BUILTIN_PSRLQ256_MASK:
19670 : 7950 : case IX86_BUILTIN_PSRLQ512:
19671 : 7950 : case IX86_BUILTIN_PSRLQI:
19672 : 7950 : case IX86_BUILTIN_PSRLQI128:
19673 : 7950 : case IX86_BUILTIN_PSRLQI128_MASK:
19674 : 7950 : case IX86_BUILTIN_PSRLQI256:
19675 : 7950 : case IX86_BUILTIN_PSRLQI256_MASK:
19676 : 7950 : case IX86_BUILTIN_PSRLQI512:
19677 : 7950 : case IX86_BUILTIN_PSRLW:
19678 : 7950 : case IX86_BUILTIN_PSRLW128:
19679 : 7950 : case IX86_BUILTIN_PSRLW128_MASK:
19680 : 7950 : case IX86_BUILTIN_PSRLW256:
19681 : 7950 : case IX86_BUILTIN_PSRLW256_MASK:
19682 : 7950 : case IX86_BUILTIN_PSRLW512:
19683 : 7950 : case IX86_BUILTIN_PSRLWI:
19684 : 7950 : case IX86_BUILTIN_PSRLWI128:
19685 : 7950 : case IX86_BUILTIN_PSRLWI128_MASK:
19686 : 7950 : case IX86_BUILTIN_PSRLWI256:
19687 : 7950 : case IX86_BUILTIN_PSRLWI256_MASK:
19688 : 7950 : case IX86_BUILTIN_PSRLWI512:
19689 : 7950 : rcode = LSHIFTRT;
19690 : 7950 : is_vshift = false;
19691 : 7950 : goto do_shift;
19692 : 2384 : case IX86_BUILTIN_PSLLVV16HI:
19693 : 2384 : case IX86_BUILTIN_PSLLVV16SI:
19694 : 2384 : case IX86_BUILTIN_PSLLVV2DI:
19695 : 2384 : case IX86_BUILTIN_PSLLVV2DI_MASK:
19696 : 2384 : case IX86_BUILTIN_PSLLVV32HI:
19697 : 2384 : case IX86_BUILTIN_PSLLVV4DI:
19698 : 2384 : case IX86_BUILTIN_PSLLVV4DI_MASK:
19699 : 2384 : case IX86_BUILTIN_PSLLVV4SI:
19700 : 2384 : case IX86_BUILTIN_PSLLVV4SI_MASK:
19701 : 2384 : case IX86_BUILTIN_PSLLVV8DI:
19702 : 2384 : case IX86_BUILTIN_PSLLVV8HI:
19703 : 2384 : case IX86_BUILTIN_PSLLVV8SI:
19704 : 2384 : case IX86_BUILTIN_PSLLVV8SI_MASK:
19705 : 2384 : rcode = ASHIFT;
19706 : 2384 : is_vshift = true;
19707 : 2384 : goto do_shift;
19708 : 2341 : case IX86_BUILTIN_PSRAVQ128:
19709 : 2341 : case IX86_BUILTIN_PSRAVQ256:
19710 : 2341 : case IX86_BUILTIN_PSRAVV16HI:
19711 : 2341 : case IX86_BUILTIN_PSRAVV16SI:
19712 : 2341 : case IX86_BUILTIN_PSRAVV32HI:
19713 : 2341 : case IX86_BUILTIN_PSRAVV4SI:
19714 : 2341 : case IX86_BUILTIN_PSRAVV4SI_MASK:
19715 : 2341 : case IX86_BUILTIN_PSRAVV8DI:
19716 : 2341 : case IX86_BUILTIN_PSRAVV8HI:
19717 : 2341 : case IX86_BUILTIN_PSRAVV8SI:
19718 : 2341 : case IX86_BUILTIN_PSRAVV8SI_MASK:
19719 : 2341 : rcode = ASHIFTRT;
19720 : 2341 : is_vshift = true;
19721 : 2341 : goto do_shift;
19722 : 2380 : case IX86_BUILTIN_PSRLVV16HI:
19723 : 2380 : case IX86_BUILTIN_PSRLVV16SI:
19724 : 2380 : case IX86_BUILTIN_PSRLVV2DI:
19725 : 2380 : case IX86_BUILTIN_PSRLVV2DI_MASK:
19726 : 2380 : case IX86_BUILTIN_PSRLVV32HI:
19727 : 2380 : case IX86_BUILTIN_PSRLVV4DI:
19728 : 2380 : case IX86_BUILTIN_PSRLVV4DI_MASK:
19729 : 2380 : case IX86_BUILTIN_PSRLVV4SI:
19730 : 2380 : case IX86_BUILTIN_PSRLVV4SI_MASK:
19731 : 2380 : case IX86_BUILTIN_PSRLVV8DI:
19732 : 2380 : case IX86_BUILTIN_PSRLVV8HI:
19733 : 2380 : case IX86_BUILTIN_PSRLVV8SI:
19734 : 2380 : case IX86_BUILTIN_PSRLVV8SI_MASK:
19735 : 2380 : rcode = LSHIFTRT;
19736 : 2380 : is_vshift = true;
19737 : 2380 : goto do_shift;
19738 : :
19739 : 30827 : do_shift:
19740 : 30827 : gcc_assert (n_args >= 2);
19741 : 30827 : if (!gimple_call_lhs (stmt))
19742 : : {
19743 : 1 : gsi_replace (gsi, gimple_build_nop (), false);
19744 : 1 : return true;
19745 : : }
19746 : 30826 : arg0 = gimple_call_arg (stmt, 0);
19747 : 30826 : arg1 = gimple_call_arg (stmt, 1);
19748 : 30826 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
19749 : : /* For masked shift, only optimize if the mask is all ones. */
19750 : 30826 : if (n_args > 2
19751 : 30826 : && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1)))
19752 : : break;
19753 : 16061 : if (is_vshift)
19754 : : {
19755 : 2640 : if (TREE_CODE (arg1) != VECTOR_CST)
19756 : : break;
19757 : 69 : count = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0)));
19758 : 69 : if (integer_zerop (arg1))
19759 : 27 : count = 0;
19760 : 42 : else if (rcode == ASHIFTRT)
19761 : : break;
19762 : : else
19763 : 230 : for (unsigned int i = 0; i < VECTOR_CST_NELTS (arg1); ++i)
19764 : : {
19765 : 212 : tree elt = VECTOR_CST_ELT (arg1, i);
19766 : 212 : if (!wi::neg_p (wi::to_wide (elt))
19767 : 375 : && wi::to_widest (elt) < count)
19768 : 16 : return false;
19769 : : }
19770 : : }
19771 : : else
19772 : : {
19773 : 13421 : arg1 = ix86_vector_shift_count (arg1);
19774 : 13421 : if (!arg1)
19775 : : break;
19776 : 5608 : count = tree_to_uhwi (arg1);
19777 : : }
19778 : 5653 : if (count == 0)
19779 : : {
19780 : : /* Just return the first argument for shift by 0. */
19781 : 93 : loc = gimple_location (stmt);
19782 : 93 : g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
19783 : 93 : gimple_set_location (g, loc);
19784 : 93 : gsi_replace (gsi, g, false);
19785 : 93 : return true;
19786 : : }
19787 : 5560 : if (rcode != ASHIFTRT
19788 : 5560 : && count >= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0))))
19789 : : {
19790 : : /* For shift counts equal or greater than precision, except for
19791 : : arithmetic right shift the result is zero. */
19792 : 78 : loc = gimple_location (stmt);
19793 : 78 : g = gimple_build_assign (gimple_call_lhs (stmt),
19794 : 78 : build_zero_cst (TREE_TYPE (arg0)));
19795 : 78 : gimple_set_location (g, loc);
19796 : 78 : gsi_replace (gsi, g, false);
19797 : 78 : return true;
19798 : : }
19799 : : break;
19800 : :
19801 : 531 : case IX86_BUILTIN_SHUFPD512:
19802 : 531 : case IX86_BUILTIN_SHUFPS512:
19803 : 531 : case IX86_BUILTIN_SHUFPD:
19804 : 531 : case IX86_BUILTIN_SHUFPD256:
19805 : 531 : case IX86_BUILTIN_SHUFPS:
19806 : 531 : case IX86_BUILTIN_SHUFPS256:
19807 : 531 : arg0 = gimple_call_arg (stmt, 0);
19808 : 531 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
19809 : : /* This is masked shuffle. Only optimize if the mask is all ones. */
19810 : 531 : if (n_args > 3
19811 : 895 : && !ix86_masked_all_ones (elems,
19812 : 364 : gimple_call_arg (stmt, n_args - 1)))
19813 : : break;
19814 : 203 : arg2 = gimple_call_arg (stmt, 2);
19815 : 203 : if (TREE_CODE (arg2) == INTEGER_CST && gimple_call_lhs (stmt))
19816 : : {
19817 : 146 : unsigned HOST_WIDE_INT shuffle_mask = TREE_INT_CST_LOW (arg2);
19818 : : /* Check valid imm, refer to gcc.target/i386/testimm-10.c. */
19819 : 146 : if (shuffle_mask > 255)
19820 : : return false;
19821 : :
19822 : 144 : machine_mode imode = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (arg0)));
19823 : 144 : loc = gimple_location (stmt);
19824 : 288 : tree itype = (imode == E_DFmode
19825 : 144 : ? long_long_integer_type_node : integer_type_node);
19826 : 144 : tree vtype = build_vector_type (itype, elems);
19827 : 144 : tree_vector_builder elts (vtype, elems, 1);
19828 : :
19829 : :
19830 : : /* Transform integer shuffle_mask to vector perm_mask which
19831 : : is used by vec_perm_expr, refer to shuflp[sd]256/512 in sse.md. */
19832 : 840 : for (unsigned i = 0; i != elems; i++)
19833 : : {
19834 : 696 : unsigned sel_idx;
19835 : : /* Imm[1:0](if VL > 128, then use Imm[3:2],Imm[5:4],Imm[7:6])
19836 : : provide 2 select constrols for each element of the
19837 : : destination. */
19838 : 696 : if (imode == E_DFmode)
19839 : 240 : sel_idx = (i & 1) * elems + (i & ~1)
19840 : 240 : + ((shuffle_mask >> i) & 1);
19841 : : else
19842 : : {
19843 : : /* Imm[7:0](if VL > 128, also use Imm[7:0]) provide 4 select
19844 : : controls for each element of the destination. */
19845 : 456 : unsigned j = i % 4;
19846 : 456 : sel_idx = ((i >> 1) & 1) * elems + (i & ~3)
19847 : 456 : + ((shuffle_mask >> 2 * j) & 3);
19848 : : }
19849 : 696 : elts.quick_push (build_int_cst (itype, sel_idx));
19850 : : }
19851 : :
19852 : 144 : tree perm_mask = elts.build ();
19853 : 144 : arg1 = gimple_call_arg (stmt, 1);
19854 : 144 : g = gimple_build_assign (gimple_call_lhs (stmt),
19855 : : VEC_PERM_EXPR,
19856 : : arg0, arg1, perm_mask);
19857 : 144 : gimple_set_location (g, loc);
19858 : 144 : gsi_replace (gsi, g, false);
19859 : 144 : return true;
19860 : 144 : }
19861 : : // Do not error yet, the constant could be propagated later?
19862 : : break;
19863 : :
19864 : 48 : case IX86_BUILTIN_PABSB:
19865 : 48 : case IX86_BUILTIN_PABSW:
19866 : 48 : case IX86_BUILTIN_PABSD:
19867 : : /* 64-bit vector abs<mode>2 is only supported under TARGET_MMX_WITH_SSE. */
19868 : 48 : if (!TARGET_MMX_WITH_SSE)
19869 : : break;
19870 : : /* FALLTHRU. */
19871 : 2188 : case IX86_BUILTIN_PABSB128:
19872 : 2188 : case IX86_BUILTIN_PABSB256:
19873 : 2188 : case IX86_BUILTIN_PABSB512:
19874 : 2188 : case IX86_BUILTIN_PABSW128:
19875 : 2188 : case IX86_BUILTIN_PABSW256:
19876 : 2188 : case IX86_BUILTIN_PABSW512:
19877 : 2188 : case IX86_BUILTIN_PABSD128:
19878 : 2188 : case IX86_BUILTIN_PABSD256:
19879 : 2188 : case IX86_BUILTIN_PABSD512:
19880 : 2188 : case IX86_BUILTIN_PABSQ128:
19881 : 2188 : case IX86_BUILTIN_PABSQ256:
19882 : 2188 : case IX86_BUILTIN_PABSQ512:
19883 : 2188 : case IX86_BUILTIN_PABSB128_MASK:
19884 : 2188 : case IX86_BUILTIN_PABSB256_MASK:
19885 : 2188 : case IX86_BUILTIN_PABSW128_MASK:
19886 : 2188 : case IX86_BUILTIN_PABSW256_MASK:
19887 : 2188 : case IX86_BUILTIN_PABSD128_MASK:
19888 : 2188 : case IX86_BUILTIN_PABSD256_MASK:
19889 : 2188 : gcc_assert (n_args >= 1);
19890 : 2188 : if (!gimple_call_lhs (stmt))
19891 : : {
19892 : 1 : gsi_replace (gsi, gimple_build_nop (), false);
19893 : 1 : return true;
19894 : : }
19895 : 2187 : arg0 = gimple_call_arg (stmt, 0);
19896 : 2187 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
19897 : : /* For masked ABS, only optimize if the mask is all ones. */
19898 : 2187 : if (n_args > 1
19899 : 2187 : && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1)))
19900 : : break;
19901 : 227 : {
19902 : 227 : tree utype, ures, vce;
19903 : 227 : utype = unsigned_type_for (TREE_TYPE (arg0));
19904 : : /* PABSB/W/D/Q store the unsigned result in dst, use ABSU_EXPR
19905 : : instead of ABS_EXPR to hanlde overflow case(TYPE_MIN). */
19906 : 227 : ures = gimple_build (&stmts, ABSU_EXPR, utype, arg0);
19907 : 227 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
19908 : 227 : loc = gimple_location (stmt);
19909 : 227 : vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg0), ures);
19910 : 227 : g = gimple_build_assign (gimple_call_lhs (stmt),
19911 : : VIEW_CONVERT_EXPR, vce);
19912 : 227 : gsi_replace (gsi, g, false);
19913 : : }
19914 : 227 : return true;
19915 : :
19916 : 2225 : case IX86_BUILTIN_MINPS:
19917 : 2225 : case IX86_BUILTIN_MINPD:
19918 : 2225 : case IX86_BUILTIN_MINPS256:
19919 : 2225 : case IX86_BUILTIN_MINPD256:
19920 : 2225 : case IX86_BUILTIN_MINPS512:
19921 : 2225 : case IX86_BUILTIN_MINPD512:
19922 : 2225 : case IX86_BUILTIN_MINPS128_MASK:
19923 : 2225 : case IX86_BUILTIN_MINPD128_MASK:
19924 : 2225 : case IX86_BUILTIN_MINPS256_MASK:
19925 : 2225 : case IX86_BUILTIN_MINPD256_MASK:
19926 : 2225 : case IX86_BUILTIN_MINPH128_MASK:
19927 : 2225 : case IX86_BUILTIN_MINPH256_MASK:
19928 : 2225 : case IX86_BUILTIN_MINPH512_MASK:
19929 : 2225 : tcode = LT_EXPR;
19930 : 2225 : goto do_minmax;
19931 : :
19932 : : case IX86_BUILTIN_MAXPS:
19933 : : case IX86_BUILTIN_MAXPD:
19934 : : case IX86_BUILTIN_MAXPS256:
19935 : : case IX86_BUILTIN_MAXPD256:
19936 : : case IX86_BUILTIN_MAXPS512:
19937 : : case IX86_BUILTIN_MAXPD512:
19938 : : case IX86_BUILTIN_MAXPS128_MASK:
19939 : : case IX86_BUILTIN_MAXPD128_MASK:
19940 : : case IX86_BUILTIN_MAXPS256_MASK:
19941 : : case IX86_BUILTIN_MAXPD256_MASK:
19942 : : case IX86_BUILTIN_MAXPH128_MASK:
19943 : : case IX86_BUILTIN_MAXPH256_MASK:
19944 : : case IX86_BUILTIN_MAXPH512_MASK:
19945 : : tcode = GT_EXPR;
19946 : 4435 : do_minmax:
19947 : 4435 : gcc_assert (n_args >= 2);
19948 : : /* Without SSE4.1 we often aren't able to pattern match it back to the
19949 : : desired instruction. */
19950 : 4435 : if (!gimple_call_lhs (stmt) || !optimize || !TARGET_SSE4_1)
19951 : : break;
19952 : 3865 : arg0 = gimple_call_arg (stmt, 0);
19953 : 3865 : arg1 = gimple_call_arg (stmt, 1);
19954 : 3865 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
19955 : : /* For masked minmax, only optimize if the mask is all ones. */
19956 : 3865 : if (n_args > 2
19957 : 3865 : && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, 3)))
19958 : : break;
19959 : 647 : if (n_args >= 5)
19960 : : {
19961 : 436 : tree arg4 = gimple_call_arg (stmt, 4);
19962 : 436 : if (!tree_fits_uhwi_p (arg4))
19963 : : break;
19964 : 424 : if (tree_to_uhwi (arg4) == 4)
19965 : : /* Ok. */;
19966 : 416 : else if (tree_to_uhwi (arg4) != 8)
19967 : : /* Invalid round argument. */
19968 : : break;
19969 : 416 : else if (HONOR_NANS (arg0))
19970 : : /* Lowering to comparison would raise exceptions which
19971 : : shouldn't be raised. */
19972 : : break;
19973 : : }
19974 : 219 : {
19975 : 219 : tree type = truth_type_for (TREE_TYPE (arg0));
19976 : 219 : tree cmpres = gimple_build (&stmts, tcode, type, arg0, arg1);
19977 : 219 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
19978 : 219 : g = gimple_build_assign (gimple_call_lhs (stmt),
19979 : : VEC_COND_EXPR, cmpres, arg0, arg1);
19980 : 219 : gsi_replace (gsi, g, false);
19981 : : }
19982 : 219 : return true;
19983 : :
19984 : : default:
19985 : : break;
19986 : : }
19987 : :
19988 : : return false;
19989 : : }
19990 : :
19991 : : /* Handler for an SVML-style interface to
19992 : : a library with vectorized intrinsics. */
19993 : :
19994 : : tree
19995 : 12 : ix86_veclibabi_svml (combined_fn fn, tree type_out, tree type_in)
19996 : : {
19997 : 12 : char name[20];
19998 : 12 : tree fntype, new_fndecl, args;
19999 : 12 : unsigned arity;
20000 : 12 : const char *bname;
20001 : 12 : machine_mode el_mode, in_mode;
20002 : 12 : int n, in_n;
20003 : :
20004 : : /* The SVML is suitable for unsafe math only. */
20005 : 12 : if (!flag_unsafe_math_optimizations)
20006 : : return NULL_TREE;
20007 : :
20008 : 12 : el_mode = TYPE_MODE (TREE_TYPE (type_out));
20009 : 12 : n = TYPE_VECTOR_SUBPARTS (type_out);
20010 : 12 : in_mode = TYPE_MODE (TREE_TYPE (type_in));
20011 : 12 : in_n = TYPE_VECTOR_SUBPARTS (type_in);
20012 : 12 : if (el_mode != in_mode
20013 : 12 : || n != in_n)
20014 : : return NULL_TREE;
20015 : :
20016 : 12 : switch (fn)
20017 : : {
20018 : 12 : CASE_CFN_EXP:
20019 : 12 : CASE_CFN_LOG:
20020 : 12 : CASE_CFN_LOG10:
20021 : 12 : CASE_CFN_POW:
20022 : 12 : CASE_CFN_TANH:
20023 : 12 : CASE_CFN_TAN:
20024 : 12 : CASE_CFN_ATAN:
20025 : 12 : CASE_CFN_ATAN2:
20026 : 12 : CASE_CFN_ATANH:
20027 : 12 : CASE_CFN_CBRT:
20028 : 12 : CASE_CFN_SINH:
20029 : 12 : CASE_CFN_SIN:
20030 : 12 : CASE_CFN_ASINH:
20031 : 12 : CASE_CFN_ASIN:
20032 : 12 : CASE_CFN_COSH:
20033 : 12 : CASE_CFN_COS:
20034 : 12 : CASE_CFN_ACOSH:
20035 : 12 : CASE_CFN_ACOS:
20036 : 12 : if ((el_mode != DFmode || n != 2)
20037 : 10 : && (el_mode != SFmode || n != 4))
20038 : : return NULL_TREE;
20039 : 6 : break;
20040 : :
20041 : : default:
20042 : : return NULL_TREE;
20043 : : }
20044 : :
20045 : 6 : tree fndecl = mathfn_built_in (el_mode == DFmode
20046 : : ? double_type_node : float_type_node, fn);
20047 : 6 : bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
20048 : :
20049 : 6 : if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOGF)
20050 : 2 : strcpy (name, "vmlsLn4");
20051 : 4 : else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOG)
20052 : 0 : strcpy (name, "vmldLn2");
20053 : 4 : else if (n == 4)
20054 : : {
20055 : 2 : sprintf (name, "vmls%s", bname+10);
20056 : 2 : name[strlen (name)-1] = '4';
20057 : : }
20058 : : else
20059 : 2 : sprintf (name, "vmld%s2", bname+10);
20060 : :
20061 : : /* Convert to uppercase. */
20062 : 6 : name[4] &= ~0x20;
20063 : :
20064 : 6 : arity = 0;
20065 : 6 : for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
20066 : 0 : arity++;
20067 : :
20068 : 6 : if (arity == 1)
20069 : 0 : fntype = build_function_type_list (type_out, type_in, NULL);
20070 : : else
20071 : 6 : fntype = build_function_type_list (type_out, type_in, type_in, NULL);
20072 : :
20073 : : /* Build a function declaration for the vectorized function. */
20074 : 6 : new_fndecl = build_decl (BUILTINS_LOCATION,
20075 : : FUNCTION_DECL, get_identifier (name), fntype);
20076 : 6 : TREE_PUBLIC (new_fndecl) = 1;
20077 : 6 : DECL_EXTERNAL (new_fndecl) = 1;
20078 : 6 : DECL_IS_NOVOPS (new_fndecl) = 1;
20079 : 6 : TREE_READONLY (new_fndecl) = 1;
20080 : :
20081 : 6 : return new_fndecl;
20082 : : }
20083 : :
20084 : : /* Handler for an ACML-style interface to
20085 : : a library with vectorized intrinsics. */
20086 : :
20087 : : tree
20088 : 3 : ix86_veclibabi_acml (combined_fn fn, tree type_out, tree type_in)
20089 : : {
20090 : 3 : char name[20] = "__vr.._";
20091 : 3 : tree fntype, new_fndecl, args;
20092 : 3 : unsigned arity;
20093 : 3 : const char *bname;
20094 : 3 : machine_mode el_mode, in_mode;
20095 : 3 : int n, in_n;
20096 : :
20097 : : /* The ACML is 64bits only and suitable for unsafe math only as
20098 : : it does not correctly support parts of IEEE with the required
20099 : : precision such as denormals. */
20100 : 3 : if (!TARGET_64BIT
20101 : 3 : || !flag_unsafe_math_optimizations)
20102 : : return NULL_TREE;
20103 : :
20104 : 3 : el_mode = TYPE_MODE (TREE_TYPE (type_out));
20105 : 3 : n = TYPE_VECTOR_SUBPARTS (type_out);
20106 : 3 : in_mode = TYPE_MODE (TREE_TYPE (type_in));
20107 : 3 : in_n = TYPE_VECTOR_SUBPARTS (type_in);
20108 : 3 : if (el_mode != in_mode
20109 : 3 : || n != in_n)
20110 : : return NULL_TREE;
20111 : :
20112 : 3 : switch (fn)
20113 : : {
20114 : 3 : CASE_CFN_SIN:
20115 : 3 : CASE_CFN_COS:
20116 : 3 : CASE_CFN_EXP:
20117 : 3 : CASE_CFN_LOG:
20118 : 3 : CASE_CFN_LOG2:
20119 : 3 : CASE_CFN_LOG10:
20120 : 3 : if (el_mode == DFmode && n == 2)
20121 : : {
20122 : 3 : name[4] = 'd';
20123 : 3 : name[5] = '2';
20124 : : }
20125 : 0 : else if (el_mode == SFmode && n == 4)
20126 : : {
20127 : 0 : name[4] = 's';
20128 : 0 : name[5] = '4';
20129 : : }
20130 : : else
20131 : : return NULL_TREE;
20132 : 3 : break;
20133 : :
20134 : : default:
20135 : : return NULL_TREE;
20136 : : }
20137 : :
20138 : 3 : tree fndecl = mathfn_built_in (el_mode == DFmode
20139 : : ? double_type_node : float_type_node, fn);
20140 : 3 : bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
20141 : 3 : sprintf (name + 7, "%s", bname+10);
20142 : :
20143 : 3 : arity = 0;
20144 : 3 : for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
20145 : 0 : arity++;
20146 : :
20147 : 3 : if (arity == 1)
20148 : 0 : fntype = build_function_type_list (type_out, type_in, NULL);
20149 : : else
20150 : 3 : fntype = build_function_type_list (type_out, type_in, type_in, NULL);
20151 : :
20152 : : /* Build a function declaration for the vectorized function. */
20153 : 3 : new_fndecl = build_decl (BUILTINS_LOCATION,
20154 : : FUNCTION_DECL, get_identifier (name), fntype);
20155 : 3 : TREE_PUBLIC (new_fndecl) = 1;
20156 : 3 : DECL_EXTERNAL (new_fndecl) = 1;
20157 : 3 : DECL_IS_NOVOPS (new_fndecl) = 1;
20158 : 3 : TREE_READONLY (new_fndecl) = 1;
20159 : :
20160 : 3 : return new_fndecl;
20161 : : }
20162 : :
20163 : : /* Handler for an AOCL-LibM-style interface to
20164 : : a library with vectorized intrinsics. */
20165 : :
20166 : : tree
20167 : 220 : ix86_veclibabi_aocl (combined_fn fn, tree type_out, tree type_in)
20168 : : {
20169 : 220 : char name[20] = "amd_vr";
20170 : 220 : int name_len = 6;
20171 : 220 : tree fntype, new_fndecl, args;
20172 : 220 : unsigned arity;
20173 : 220 : const char *bname;
20174 : 220 : machine_mode el_mode, in_mode;
20175 : 220 : int n, in_n;
20176 : :
20177 : : /* AOCL-LibM is 64bits only. It is also only suitable for unsafe math only
20178 : : as it trades off some accuracy for increased performance. */
20179 : 220 : if (!TARGET_64BIT
20180 : 220 : || !flag_unsafe_math_optimizations)
20181 : : return NULL_TREE;
20182 : :
20183 : 220 : el_mode = TYPE_MODE (TREE_TYPE (type_out));
20184 : 220 : n = TYPE_VECTOR_SUBPARTS (type_out);
20185 : 220 : in_mode = TYPE_MODE (TREE_TYPE (type_in));
20186 : 220 : in_n = TYPE_VECTOR_SUBPARTS (type_in);
20187 : 220 : if (el_mode != in_mode
20188 : 220 : || n != in_n)
20189 : : return NULL_TREE;
20190 : :
20191 : 220 : gcc_checking_assert (n > 0);
20192 : :
20193 : : /* Decide whether there exists a function for the combination of FN, the mode
20194 : : and the vector width. Return early if it doesn't. */
20195 : :
20196 : 220 : if (el_mode != DFmode && el_mode != SFmode)
20197 : : return NULL_TREE;
20198 : :
20199 : : /* Supported vector widths for given FN and single/double precision. Zeros
20200 : : are used to fill out unused positions in the arrays. */
20201 : 220 : static const int supported_n[][2][3] = {
20202 : : /* Single prec. , Double prec. */
20203 : : { { 16, 0, 0 }, { 2, 4, 8 } }, /* TAN. */
20204 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* EXP. */
20205 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* EXP2. */
20206 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* LOG. */
20207 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* LOG2. */
20208 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* COS. */
20209 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* SIN. */
20210 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* POW. */
20211 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* ERF. */
20212 : : { { 4, 8, 16 }, { 2, 8, 0 } }, /* ATAN. */
20213 : : { { 4, 8, 16 }, { 2, 0, 0 } }, /* LOG10. */
20214 : : { { 4, 0, 0 }, { 2, 0, 0 } }, /* EXP10. */
20215 : : { { 4, 0, 0 }, { 2, 0, 0 } }, /* LOG1P. */
20216 : : { { 4, 8, 16 }, { 8, 0, 0 } }, /* ASIN. */
20217 : : { { 4, 16, 0 }, { 0, 0, 0 } }, /* ACOS. */
20218 : : { { 4, 8, 16 }, { 0, 0, 0 } }, /* TANH. */
20219 : : { { 4, 0, 0 }, { 0, 0, 0 } }, /* EXPM1. */
20220 : : { { 4, 8, 0 }, { 0, 0, 0 } }, /* COSH. */
20221 : : };
20222 : :
20223 : : /* We cannot simply index the supported_n array with FN since multiple FNs
20224 : : may correspond to a single operation (see the definitions of these
20225 : : CASE_CFN_* macros). */
20226 : 220 : int i;
20227 : 220 : switch (fn)
20228 : : {
20229 : : CASE_CFN_TAN : i = 0; break;
20230 : 16 : CASE_CFN_EXP : i = 1; break;
20231 : 16 : CASE_CFN_EXP2 : i = 2; break;
20232 : 16 : CASE_CFN_LOG : i = 3; break;
20233 : 16 : CASE_CFN_LOG2 : i = 4; break;
20234 : 16 : CASE_CFN_COS : i = 5; break;
20235 : 16 : CASE_CFN_SIN : i = 6; break;
20236 : 16 : CASE_CFN_POW : i = 7; break;
20237 : 16 : CASE_CFN_ERF : i = 8; break;
20238 : 13 : CASE_CFN_ATAN : i = 9; break;
20239 : 11 : CASE_CFN_LOG10 : i = 10; break;
20240 : 8 : CASE_CFN_EXP10 : i = 11; break;
20241 : 8 : CASE_CFN_LOG1P : i = 12; break;
20242 : 11 : CASE_CFN_ASIN : i = 13; break;
20243 : 7 : CASE_CFN_ACOS : i = 14; break;
20244 : 9 : CASE_CFN_TANH : i = 15; break;
20245 : 7 : CASE_CFN_EXPM1 : i = 16; break;
20246 : 9 : CASE_CFN_COSH : i = 17; break;
20247 : : default: return NULL_TREE;
20248 : : }
20249 : :
20250 : 220 : int j = el_mode == DFmode;
20251 : 220 : bool n_is_supported = false;
20252 : 489 : for (unsigned k = 0; k < 3; k++)
20253 : 470 : if (supported_n[i][j][k] == n)
20254 : : {
20255 : : n_is_supported = true;
20256 : : break;
20257 : : }
20258 : 220 : if (!n_is_supported)
20259 : : return NULL_TREE;
20260 : :
20261 : : /* Append the precision and the vector width to the function name we are
20262 : : constructing. */
20263 : 201 : name[name_len++] = el_mode == DFmode ? 'd' : 's';
20264 : 201 : switch (n)
20265 : : {
20266 : 148 : case 2:
20267 : 148 : case 4:
20268 : 148 : case 8:
20269 : 148 : name[name_len++] = '0' + n;
20270 : 148 : break;
20271 : 53 : case 16:
20272 : 53 : name[name_len++] = '1';
20273 : 53 : name[name_len++] = '6';
20274 : 53 : break;
20275 : 0 : default:
20276 : 0 : gcc_unreachable ();
20277 : : }
20278 : 201 : name[name_len++] = '_';
20279 : :
20280 : : /* Append the operation name (steal it from the name of a builtin). */
20281 : 201 : tree fndecl = mathfn_built_in (el_mode == DFmode
20282 : : ? double_type_node : float_type_node, fn);
20283 : 201 : bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
20284 : 201 : sprintf (name + name_len, "%s", bname + 10);
20285 : :
20286 : 201 : arity = 0;
20287 : 201 : for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
20288 : 0 : arity++;
20289 : :
20290 : 201 : if (arity == 1)
20291 : 0 : fntype = build_function_type_list (type_out, type_in, NULL);
20292 : : else
20293 : 201 : fntype = build_function_type_list (type_out, type_in, type_in, NULL);
20294 : :
20295 : : /* Build a function declaration for the vectorized function. */
20296 : 201 : new_fndecl = build_decl (BUILTINS_LOCATION,
20297 : : FUNCTION_DECL, get_identifier (name), fntype);
20298 : 201 : TREE_PUBLIC (new_fndecl) = 1;
20299 : 201 : DECL_EXTERNAL (new_fndecl) = 1;
20300 : 201 : TREE_READONLY (new_fndecl) = 1;
20301 : :
20302 : 201 : return new_fndecl;
20303 : : }
20304 : :
20305 : : /* Returns a decl of a function that implements scatter store with
20306 : : register type VECTYPE and index type INDEX_TYPE and SCALE.
20307 : : Return NULL_TREE if it is not available. */
20308 : :
20309 : : static tree
20310 : 97560 : ix86_vectorize_builtin_scatter (const_tree vectype,
20311 : : const_tree index_type, int scale)
20312 : : {
20313 : 97560 : bool si;
20314 : 97560 : enum ix86_builtins code;
20315 : 97560 : const machine_mode mode = TYPE_MODE (TREE_TYPE (vectype));
20316 : :
20317 : 97560 : if (!TARGET_AVX512F)
20318 : : return NULL_TREE;
20319 : :
20320 : 3909 : if (!TARGET_EVEX512 && GET_MODE_SIZE (mode) == 64)
20321 : : return NULL_TREE;
20322 : :
20323 : 3909 : if (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 2u)
20324 : 7068 : ? !TARGET_USE_SCATTER_2PARTS
20325 : 7068 : : (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 4u)
20326 : 3159 : ? !TARGET_USE_SCATTER_4PARTS
20327 : 2183 : : !TARGET_USE_SCATTER_8PARTS))
20328 : : return NULL_TREE;
20329 : :
20330 : 3909 : if ((TREE_CODE (index_type) != INTEGER_TYPE
20331 : 486 : && !POINTER_TYPE_P (index_type))
20332 : 4395 : || (TYPE_MODE (index_type) != SImode
20333 : 1586 : && TYPE_MODE (index_type) != DImode))
20334 : 0 : return NULL_TREE;
20335 : :
20336 : 4131 : if (TYPE_PRECISION (index_type) > POINTER_SIZE)
20337 : : return NULL_TREE;
20338 : :
20339 : : /* v*scatter* insn sign extends index to pointer mode. */
20340 : 3909 : if (TYPE_PRECISION (index_type) < POINTER_SIZE
20341 : 3909 : && TYPE_UNSIGNED (index_type))
20342 : : return NULL_TREE;
20343 : :
20344 : : /* Scale can be 1, 2, 4 or 8. */
20345 : 3909 : if (scale <= 0
20346 : 3909 : || scale > 8
20347 : 3877 : || (scale & (scale - 1)) != 0)
20348 : : return NULL_TREE;
20349 : :
20350 : 3877 : si = TYPE_MODE (index_type) == SImode;
20351 : 3877 : switch (TYPE_MODE (vectype))
20352 : : {
20353 : 245 : case E_V8DFmode:
20354 : 245 : code = si ? IX86_BUILTIN_SCATTERALTSIV8DF : IX86_BUILTIN_SCATTERDIV8DF;
20355 : : break;
20356 : 159 : case E_V8DImode:
20357 : 159 : code = si ? IX86_BUILTIN_SCATTERALTSIV8DI : IX86_BUILTIN_SCATTERDIV8DI;
20358 : : break;
20359 : 250 : case E_V16SFmode:
20360 : 250 : code = si ? IX86_BUILTIN_SCATTERSIV16SF : IX86_BUILTIN_SCATTERALTDIV16SF;
20361 : : break;
20362 : 282 : case E_V16SImode:
20363 : 282 : code = si ? IX86_BUILTIN_SCATTERSIV16SI : IX86_BUILTIN_SCATTERALTDIV16SI;
20364 : : break;
20365 : 171 : case E_V4DFmode:
20366 : 171 : if (TARGET_AVX512VL)
20367 : 72 : code = si ? IX86_BUILTIN_SCATTERALTSIV4DF : IX86_BUILTIN_SCATTERDIV4DF;
20368 : : else
20369 : : return NULL_TREE;
20370 : : break;
20371 : 157 : case E_V4DImode:
20372 : 157 : if (TARGET_AVX512VL)
20373 : 72 : code = si ? IX86_BUILTIN_SCATTERALTSIV4DI : IX86_BUILTIN_SCATTERDIV4DI;
20374 : : else
20375 : : return NULL_TREE;
20376 : : break;
20377 : 178 : case E_V8SFmode:
20378 : 178 : if (TARGET_AVX512VL)
20379 : 78 : code = si ? IX86_BUILTIN_SCATTERSIV8SF : IX86_BUILTIN_SCATTERALTDIV8SF;
20380 : : else
20381 : : return NULL_TREE;
20382 : : break;
20383 : 286 : case E_V8SImode:
20384 : 286 : if (TARGET_AVX512VL)
20385 : 158 : code = si ? IX86_BUILTIN_SCATTERSIV8SI : IX86_BUILTIN_SCATTERALTDIV8SI;
20386 : : else
20387 : : return NULL_TREE;
20388 : : break;
20389 : 203 : case E_V2DFmode:
20390 : 203 : if (TARGET_AVX512VL)
20391 : 110 : code = si ? IX86_BUILTIN_SCATTERALTSIV2DF : IX86_BUILTIN_SCATTERDIV2DF;
20392 : : else
20393 : : return NULL_TREE;
20394 : : break;
20395 : 189 : case E_V2DImode:
20396 : 189 : if (TARGET_AVX512VL)
20397 : 110 : code = si ? IX86_BUILTIN_SCATTERALTSIV2DI : IX86_BUILTIN_SCATTERDIV2DI;
20398 : : else
20399 : : return NULL_TREE;
20400 : : break;
20401 : 206 : case E_V4SFmode:
20402 : 206 : if (TARGET_AVX512VL)
20403 : 114 : code = si ? IX86_BUILTIN_SCATTERSIV4SF : IX86_BUILTIN_SCATTERALTDIV4SF;
20404 : : else
20405 : : return NULL_TREE;
20406 : : break;
20407 : 290 : case E_V4SImode:
20408 : 290 : if (TARGET_AVX512VL)
20409 : 166 : code = si ? IX86_BUILTIN_SCATTERSIV4SI : IX86_BUILTIN_SCATTERALTDIV4SI;
20410 : : else
20411 : : return NULL_TREE;
20412 : : break;
20413 : : default:
20414 : : return NULL_TREE;
20415 : : }
20416 : :
20417 : 1816 : return get_ix86_builtin (code);
20418 : : }
20419 : :
20420 : : /* Return true if it is safe to use the rsqrt optabs to optimize
20421 : : 1.0/sqrt. */
20422 : :
20423 : : static bool
20424 : 82 : use_rsqrt_p (machine_mode mode)
20425 : : {
20426 : 82 : return ((mode == HFmode
20427 : 34 : || (TARGET_SSE && TARGET_SSE_MATH))
20428 : 82 : && flag_finite_math_only
20429 : 81 : && !flag_trapping_math
20430 : 145 : && flag_unsafe_math_optimizations);
20431 : : }
20432 : :
20433 : : /* Helper for avx_vpermilps256_operand et al. This is also used by
20434 : : the expansion functions to turn the parallel back into a mask.
20435 : : The return value is 0 for no match and the imm8+1 for a match. */
20436 : :
20437 : : int
20438 : 29568 : avx_vpermilp_parallel (rtx par, machine_mode mode)
20439 : : {
20440 : 29568 : unsigned i, nelt = GET_MODE_NUNITS (mode);
20441 : 29568 : unsigned mask = 0;
20442 : 29568 : unsigned char ipar[16] = {}; /* Silence -Wuninitialized warning. */
20443 : :
20444 : 29568 : if (XVECLEN (par, 0) != (int) nelt)
20445 : : return 0;
20446 : :
20447 : : /* Validate that all of the elements are constants, and not totally
20448 : : out of range. Copy the data into an integral array to make the
20449 : : subsequent checks easier. */
20450 : 178786 : for (i = 0; i < nelt; ++i)
20451 : : {
20452 : 149218 : rtx er = XVECEXP (par, 0, i);
20453 : 149218 : unsigned HOST_WIDE_INT ei;
20454 : :
20455 : 149218 : if (!CONST_INT_P (er))
20456 : : return 0;
20457 : 149218 : ei = INTVAL (er);
20458 : 149218 : if (ei >= nelt)
20459 : : return 0;
20460 : 149218 : ipar[i] = ei;
20461 : : }
20462 : :
20463 : 29568 : switch (mode)
20464 : : {
20465 : : case E_V8DFmode:
20466 : : /* In the 512-bit DFmode case, we can only move elements within
20467 : : a 128-bit lane. First fill the second part of the mask,
20468 : : then fallthru. */
20469 : 2070 : for (i = 4; i < 6; ++i)
20470 : : {
20471 : 1438 : if (ipar[i] < 4 || ipar[i] >= 6)
20472 : : return 0;
20473 : 1332 : mask |= (ipar[i] - 4) << i;
20474 : : }
20475 : 1470 : for (i = 6; i < 8; ++i)
20476 : : {
20477 : 1051 : if (ipar[i] < 6)
20478 : : return 0;
20479 : 838 : mask |= (ipar[i] - 6) << i;
20480 : : }
20481 : : /* FALLTHRU */
20482 : :
20483 : : case E_V4DFmode:
20484 : : /* In the 256-bit DFmode case, we can only move elements within
20485 : : a 128-bit lane. */
20486 : 20414 : for (i = 0; i < 2; ++i)
20487 : : {
20488 : 17333 : if (ipar[i] >= 2)
20489 : : return 0;
20490 : 11572 : mask |= ipar[i] << i;
20491 : : }
20492 : 7801 : for (i = 2; i < 4; ++i)
20493 : : {
20494 : 5441 : if (ipar[i] < 2)
20495 : : return 0;
20496 : 4720 : mask |= (ipar[i] - 2) << i;
20497 : : }
20498 : : break;
20499 : :
20500 : : case E_V16SFmode:
20501 : : /* In 512 bit SFmode case, permutation in the upper 256 bits
20502 : : must mirror the permutation in the lower 256-bits. */
20503 : 3705 : for (i = 0; i < 8; ++i)
20504 : 3295 : if (ipar[i] + 8 != ipar[i + 8])
20505 : : return 0;
20506 : : /* FALLTHRU */
20507 : :
20508 : : case E_V8SFmode:
20509 : : /* In 256 bit SFmode case, we have full freedom of
20510 : : movement within the low 128-bit lane, but the high 128-bit
20511 : : lane must mirror the exact same pattern. */
20512 : 30212 : for (i = 0; i < 4; ++i)
20513 : 26499 : if (ipar[i] + 4 != ipar[i + 4])
20514 : : return 0;
20515 : : nelt = 4;
20516 : : /* FALLTHRU */
20517 : :
20518 : 14466 : case E_V2DFmode:
20519 : 14466 : case E_V4SFmode:
20520 : : /* In the 128-bit case, we've full freedom in the placement of
20521 : : the elements from the source operand. */
20522 : 58308 : for (i = 0; i < nelt; ++i)
20523 : 43842 : mask |= ipar[i] << (i * (nelt / 2));
20524 : : break;
20525 : :
20526 : 0 : default:
20527 : 0 : gcc_unreachable ();
20528 : : }
20529 : :
20530 : : /* Make sure success has a non-zero value by adding one. */
20531 : 16826 : return mask + 1;
20532 : : }
20533 : :
20534 : : /* Helper for avx_vperm2f128_v4df_operand et al. This is also used by
20535 : : the expansion functions to turn the parallel back into a mask.
20536 : : The return value is 0 for no match and the imm8+1 for a match. */
20537 : :
20538 : : int
20539 : 56341 : avx_vperm2f128_parallel (rtx par, machine_mode mode)
20540 : : {
20541 : 56341 : unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2;
20542 : 56341 : unsigned mask = 0;
20543 : 56341 : unsigned char ipar[8] = {}; /* Silence -Wuninitialized warning. */
20544 : :
20545 : 56341 : if (XVECLEN (par, 0) != (int) nelt)
20546 : : return 0;
20547 : :
20548 : : /* Validate that all of the elements are constants, and not totally
20549 : : out of range. Copy the data into an integral array to make the
20550 : : subsequent checks easier. */
20551 : 455625 : for (i = 0; i < nelt; ++i)
20552 : : {
20553 : 399284 : rtx er = XVECEXP (par, 0, i);
20554 : 399284 : unsigned HOST_WIDE_INT ei;
20555 : :
20556 : 399284 : if (!CONST_INT_P (er))
20557 : : return 0;
20558 : 399284 : ei = INTVAL (er);
20559 : 399284 : if (ei >= 2 * nelt)
20560 : : return 0;
20561 : 399284 : ipar[i] = ei;
20562 : : }
20563 : :
20564 : : /* Validate that the halves of the permute are halves. */
20565 : 104558 : for (i = 0; i < nelt2 - 1; ++i)
20566 : 86233 : if (ipar[i] + 1 != ipar[i + 1])
20567 : : return 0;
20568 : 54897 : for (i = nelt2; i < nelt - 1; ++i)
20569 : 38340 : if (ipar[i] + 1 != ipar[i + 1])
20570 : : return 0;
20571 : :
20572 : : /* Reconstruct the mask. */
20573 : 49629 : for (i = 0; i < 2; ++i)
20574 : : {
20575 : 33095 : unsigned e = ipar[i * nelt2];
20576 : 33095 : if (e % nelt2)
20577 : : return 0;
20578 : 33072 : e /= nelt2;
20579 : 33072 : mask |= e << (i * 4);
20580 : : }
20581 : :
20582 : : /* Make sure success has a non-zero value by adding one. */
20583 : 16534 : return mask + 1;
20584 : : }
20585 : :
20586 : : /* Return a mask of VPTERNLOG operands that do not affect output. */
20587 : :
20588 : : int
20589 : 2422 : vpternlog_redundant_operand_mask (rtx pternlog_imm)
20590 : : {
20591 : 2422 : int mask = 0;
20592 : 2422 : int imm8 = INTVAL (pternlog_imm);
20593 : :
20594 : 2422 : if (((imm8 >> 4) & 0x0F) == (imm8 & 0x0F))
20595 : 6 : mask |= 1;
20596 : 2422 : if (((imm8 >> 2) & 0x33) == (imm8 & 0x33))
20597 : 6 : mask |= 2;
20598 : 2422 : if (((imm8 >> 1) & 0x55) == (imm8 & 0x55))
20599 : 147 : mask |= 4;
20600 : :
20601 : 2422 : return mask;
20602 : : }
20603 : :
20604 : : /* Eliminate false dependencies on operands that do not affect output
20605 : : by substituting other operands of a VPTERNLOG. */
20606 : :
20607 : : void
20608 : 77 : substitute_vpternlog_operands (rtx *operands)
20609 : : {
20610 : 77 : int mask = vpternlog_redundant_operand_mask (operands[4]);
20611 : :
20612 : 77 : if (mask & 1) /* The first operand is redundant. */
20613 : 2 : operands[1] = operands[2];
20614 : :
20615 : 77 : if (mask & 2) /* The second operand is redundant. */
20616 : 2 : operands[2] = operands[1];
20617 : :
20618 : 77 : if (mask & 4) /* The third operand is redundant. */
20619 : 73 : operands[3] = operands[1];
20620 : 4 : else if (REG_P (operands[3]))
20621 : : {
20622 : 0 : if (mask & 1)
20623 : 0 : operands[1] = operands[3];
20624 : 0 : if (mask & 2)
20625 : 0 : operands[2] = operands[3];
20626 : : }
20627 : 77 : }
20628 : :
20629 : : /* Return a register priority for hard reg REGNO. */
20630 : : static int
20631 : 57183220 : ix86_register_priority (int hard_regno)
20632 : : {
20633 : : /* ebp and r13 as the base always wants a displacement, r12 as the
20634 : : base always wants an index. So discourage their usage in an
20635 : : address. */
20636 : 57183220 : if (hard_regno == R12_REG || hard_regno == R13_REG)
20637 : : return 0;
20638 : 52811796 : if (hard_regno == BP_REG)
20639 : : return 1;
20640 : : /* New x86-64 int registers result in bigger code size. Discourage them. */
20641 : 50962139 : if (REX_INT_REGNO_P (hard_regno))
20642 : : return 2;
20643 : 34772609 : if (REX2_INT_REGNO_P (hard_regno))
20644 : : return 2;
20645 : : /* New x86-64 SSE registers result in bigger code size. Discourage them. */
20646 : 34770464 : if (REX_SSE_REGNO_P (hard_regno))
20647 : : return 2;
20648 : 28759199 : if (EXT_REX_SSE_REGNO_P (hard_regno))
20649 : : return 1;
20650 : : /* Usage of AX register results in smaller code. Prefer it. */
20651 : 28533785 : if (hard_regno == AX_REG)
20652 : 3724406 : return 4;
20653 : : return 3;
20654 : : }
20655 : :
20656 : : /* Implement TARGET_PREFERRED_RELOAD_CLASS.
20657 : :
20658 : : Put float CONST_DOUBLE in the constant pool instead of fp regs.
20659 : : QImode must go into class Q_REGS.
20660 : : Narrow ALL_REGS to GENERAL_REGS. This supports allowing movsf and
20661 : : movdf to do mem-to-mem moves through integer regs. */
20662 : :
20663 : : static reg_class_t
20664 : 535638863 : ix86_preferred_reload_class (rtx x, reg_class_t regclass)
20665 : : {
20666 : 535638863 : machine_mode mode = GET_MODE (x);
20667 : :
20668 : : /* We're only allowed to return a subclass of CLASS. Many of the
20669 : : following checks fail for NO_REGS, so eliminate that early. */
20670 : 535638863 : if (regclass == NO_REGS)
20671 : : return NO_REGS;
20672 : :
20673 : : /* All classes can load zeros. */
20674 : 534817026 : if (x == CONST0_RTX (mode))
20675 : : return regclass;
20676 : :
20677 : : /* Force constants into memory if we are loading a (nonzero) constant into
20678 : : an MMX, SSE or MASK register. This is because there are no MMX/SSE/MASK
20679 : : instructions to load from a constant. */
20680 : 510437560 : if (CONSTANT_P (x)
20681 : 510437560 : && (MAYBE_MMX_CLASS_P (regclass)
20682 : 150523169 : || MAYBE_SSE_CLASS_P (regclass)
20683 : 120891518 : || MAYBE_MASK_CLASS_P (regclass)))
20684 : 29780729 : return NO_REGS;
20685 : :
20686 : : /* Floating-point constants need more complex checks. */
20687 : 480656831 : if (CONST_DOUBLE_P (x))
20688 : : {
20689 : : /* General regs can load everything. */
20690 : 287523 : if (INTEGER_CLASS_P (regclass))
20691 : : return regclass;
20692 : :
20693 : : /* Floats can load 0 and 1 plus some others. Note that we eliminated
20694 : : zero above. We only want to wind up preferring 80387 registers if
20695 : : we plan on doing computation with them. */
20696 : 176473 : if (IS_STACK_MODE (mode)
20697 : 234309 : && standard_80387_constant_p (x) > 0)
20698 : : {
20699 : : /* Limit class to FP regs. */
20700 : 40658 : if (FLOAT_CLASS_P (regclass))
20701 : : return FLOAT_REGS;
20702 : : }
20703 : :
20704 : 135815 : return NO_REGS;
20705 : : }
20706 : :
20707 : : /* Prefer SSE if we can use them for math. Also allow integer regs
20708 : : when moves between register units are cheap. */
20709 : 480369308 : if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
20710 : : {
20711 : 31486454 : if (TARGET_INTER_UNIT_MOVES_FROM_VEC
20712 : 31471561 : && TARGET_INTER_UNIT_MOVES_TO_VEC
20713 : 94418488 : && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (word_mode))
20714 : 31246464 : return INT_SSE_CLASS_P (regclass) ? regclass : NO_REGS;
20715 : : else
20716 : 239990 : return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
20717 : : }
20718 : :
20719 : : /* Generally when we see PLUS here, it's the function invariant
20720 : : (plus soft-fp const_int). Which can only be computed into general
20721 : : regs. */
20722 : 448882854 : if (GET_CODE (x) == PLUS)
20723 : 1843914 : return INTEGER_CLASS_P (regclass) ? regclass : NO_REGS;
20724 : :
20725 : : /* QImode constants are easy to load, but non-constant QImode data
20726 : : must go into Q_REGS or ALL_MASK_REGS. */
20727 : 447038940 : if (GET_MODE (x) == QImode && !CONSTANT_P (x))
20728 : : {
20729 : 23922498 : if (Q_CLASS_P (regclass))
20730 : : return regclass;
20731 : 19289413 : else if (reg_class_subset_p (Q_REGS, regclass))
20732 : : return Q_REGS;
20733 : 54378 : else if (MASK_CLASS_P (regclass))
20734 : : return regclass;
20735 : : else
20736 : : return NO_REGS;
20737 : : }
20738 : :
20739 : : return regclass;
20740 : : }
20741 : :
20742 : : /* Discourage putting floating-point values in SSE registers unless
20743 : : SSE math is being used, and likewise for the 387 registers. */
20744 : : static reg_class_t
20745 : 72582639 : ix86_preferred_output_reload_class (rtx x, reg_class_t regclass)
20746 : : {
20747 : : /* Restrict the output reload class to the register bank that we are doing
20748 : : math on. If we would like not to return a subset of CLASS, reject this
20749 : : alternative: if reload cannot do this, it will still use its choice. */
20750 : 72582639 : machine_mode mode = GET_MODE (x);
20751 : 72582639 : if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
20752 : 7212295 : return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS;
20753 : :
20754 : 65370344 : if (IS_STACK_MODE (mode))
20755 : 203226 : return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
20756 : :
20757 : : return regclass;
20758 : : }
20759 : :
20760 : : static reg_class_t
20761 : 376346421 : ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
20762 : : machine_mode mode, secondary_reload_info *sri)
20763 : : {
20764 : : /* Double-word spills from general registers to non-offsettable memory
20765 : : references (zero-extended addresses) require special handling. */
20766 : 376346421 : if (TARGET_64BIT
20767 : 323890478 : && MEM_P (x)
20768 : 173864254 : && GET_MODE_SIZE (mode) > UNITS_PER_WORD
20769 : 17196448 : && INTEGER_CLASS_P (rclass)
20770 : 379020335 : && !offsettable_memref_p (x))
20771 : : {
20772 : 2442304 : sri->icode = (in_p
20773 : 1221152 : ? CODE_FOR_reload_noff_load
20774 : : : CODE_FOR_reload_noff_store);
20775 : : /* Add the cost of moving address to a temporary. */
20776 : 1221152 : sri->extra_cost = 1;
20777 : :
20778 : 1221152 : return NO_REGS;
20779 : : }
20780 : :
20781 : : /* QImode spills from non-QI registers require
20782 : : intermediate register on 32bit targets. */
20783 : 375125269 : if (mode == QImode
20784 : 375125269 : && ((!TARGET_64BIT && !in_p
20785 : 560033 : && INTEGER_CLASS_P (rclass)
20786 : 559989 : && MAYBE_NON_Q_CLASS_P (rclass))
20787 : 21750513 : || (!TARGET_AVX512DQ
20788 : 21558229 : && MAYBE_MASK_CLASS_P (rclass))))
20789 : : {
20790 : 6334 : int regno = true_regnum (x);
20791 : :
20792 : : /* Return Q_REGS if the operand is in memory. */
20793 : 6334 : if (regno == -1)
20794 : : return Q_REGS;
20795 : :
20796 : : return NO_REGS;
20797 : : }
20798 : :
20799 : : /* Require movement to gpr, and then store to memory. */
20800 : 375118935 : if ((mode == HFmode || mode == HImode || mode == V2QImode
20801 : : || mode == BFmode)
20802 : 3560681 : && !TARGET_SSE4_1
20803 : 2979574 : && SSE_CLASS_P (rclass)
20804 : 178271 : && !in_p && MEM_P (x))
20805 : : {
20806 : 82744 : sri->extra_cost = 1;
20807 : 82744 : return GENERAL_REGS;
20808 : : }
20809 : :
20810 : : /* This condition handles corner case where an expression involving
20811 : : pointers gets vectorized. We're trying to use the address of a
20812 : : stack slot as a vector initializer.
20813 : :
20814 : : (set (reg:V2DI 74 [ vect_cst_.2 ])
20815 : : (vec_duplicate:V2DI (reg/f:DI 20 frame)))
20816 : :
20817 : : Eventually frame gets turned into sp+offset like this:
20818 : :
20819 : : (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20820 : : (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
20821 : : (const_int 392 [0x188]))))
20822 : :
20823 : : That later gets turned into:
20824 : :
20825 : : (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20826 : : (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
20827 : : (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))))
20828 : :
20829 : : We'll have the following reload recorded:
20830 : :
20831 : : Reload 0: reload_in (DI) =
20832 : : (plus:DI (reg/f:DI 7 sp)
20833 : : (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))
20834 : : reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20835 : : SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine
20836 : : reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188]))
20837 : : reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20838 : : reload_reg_rtx: (reg:V2DI 22 xmm1)
20839 : :
20840 : : Which isn't going to work since SSE instructions can't handle scalar
20841 : : additions. Returning GENERAL_REGS forces the addition into integer
20842 : : register and reload can handle subsequent reloads without problems. */
20843 : :
20844 : 219289952 : if (in_p && GET_CODE (x) == PLUS
20845 : 2 : && SSE_CLASS_P (rclass)
20846 : 375036191 : && SCALAR_INT_MODE_P (mode))
20847 : : return GENERAL_REGS;
20848 : :
20849 : : return NO_REGS;
20850 : : }
20851 : :
20852 : : /* Implement TARGET_CLASS_LIKELY_SPILLED_P. */
20853 : :
20854 : : static bool
20855 : 703656363 : ix86_class_likely_spilled_p (reg_class_t rclass)
20856 : : {
20857 : 693833275 : switch (rclass)
20858 : : {
20859 : : case AREG:
20860 : : case DREG:
20861 : : case CREG:
20862 : : case BREG:
20863 : : case AD_REGS:
20864 : : case SIREG:
20865 : : case DIREG:
20866 : : case SSE_FIRST_REG:
20867 : : case FP_TOP_REG:
20868 : : case FP_SECOND_REG:
20869 : : return true;
20870 : :
20871 : 672212379 : default:
20872 : 672212379 : break;
20873 : : }
20874 : :
20875 : 672212379 : return false;
20876 : : }
20877 : :
20878 : : /* Implement TARGET_CALLEE_SAVE_COST. */
20879 : :
20880 : : static int
20881 : 82442116 : ix86_callee_save_cost (spill_cost_type, unsigned int hard_regno, machine_mode,
20882 : : unsigned int, int mem_cost, const HARD_REG_SET &, bool)
20883 : : {
20884 : : /* Account for the fact that push and pop are shorter and do their
20885 : : own allocation and deallocation. */
20886 : 82442116 : if (GENERAL_REGNO_P (hard_regno))
20887 : : {
20888 : : /* push is 1 byte while typical spill is 4-5 bytes.
20889 : : ??? We probably should adjust size costs accordingly.
20890 : : Costs are relative to reg-reg move that has 2 bytes for 32bit
20891 : : and 3 bytes otherwise. Be sure that no cost table sets cost
20892 : : to 2, so we end up with 0. */
20893 : 82432838 : if (mem_cost <= 2 || optimize_function_for_size_p (cfun))
20894 : 3560544 : return 1;
20895 : 78872294 : return mem_cost - 2;
20896 : : }
20897 : : return mem_cost;
20898 : : }
20899 : :
20900 : : /* Return true if a set of DST by the expression SRC should be allowed.
20901 : : This prevents complex sets of likely_spilled hard regs before split1. */
20902 : :
20903 : : bool
20904 : 604471558 : ix86_hardreg_mov_ok (rtx dst, rtx src)
20905 : : {
20906 : : /* Avoid complex sets of likely_spilled hard registers before reload. */
20907 : 495461664 : if (REG_P (dst) && HARD_REGISTER_P (dst)
20908 : 287788794 : && !REG_P (src) && !MEM_P (src)
20909 : 95540809 : && !(VECTOR_MODE_P (GET_MODE (dst))
20910 : 95540809 : ? standard_sse_constant_p (src, GET_MODE (dst))
20911 : 47539514 : : x86_64_immediate_operand (src, GET_MODE (dst)))
20912 : 9823088 : && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst)))
20913 : 613051676 : && ix86_pre_reload_split ())
20914 : : return false;
20915 : : return true;
20916 : : }
20917 : :
20918 : : /* If we are copying between registers from different register sets
20919 : : (e.g. FP and integer), we may need a memory location.
20920 : :
20921 : : The function can't work reliably when one of the CLASSES is a class
20922 : : containing registers from multiple sets. We avoid this by never combining
20923 : : different sets in a single alternative in the machine description.
20924 : : Ensure that this constraint holds to avoid unexpected surprises.
20925 : :
20926 : : When STRICT is false, we are being called from REGISTER_MOVE_COST,
20927 : : so do not enforce these sanity checks.
20928 : :
20929 : : To optimize register_move_cost performance, define inline variant. */
20930 : :
20931 : : static inline bool
20932 : 5468160445 : inline_secondary_memory_needed (machine_mode mode, reg_class_t class1,
20933 : : reg_class_t class2, int strict)
20934 : : {
20935 : 5468160445 : if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
20936 : : return false;
20937 : :
20938 : 5436881026 : if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
20939 : 4633687365 : || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
20940 : 3957440807 : || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
20941 : 3775975063 : || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
20942 : 3604243612 : || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
20943 : 3604243612 : || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2)
20944 : 3604243612 : || MAYBE_MASK_CLASS_P (class1) != MASK_CLASS_P (class1)
20945 : 8877477902 : || MAYBE_MASK_CLASS_P (class2) != MASK_CLASS_P (class2))
20946 : : {
20947 : 2152221233 : gcc_assert (!strict || lra_in_progress);
20948 : : return true;
20949 : : }
20950 : :
20951 : 3284659793 : if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
20952 : : return true;
20953 : :
20954 : : /* ??? This is a lie. We do have moves between mmx/general, and for
20955 : : mmx/sse2. But by saying we need secondary memory we discourage the
20956 : : register allocator from using the mmx registers unless needed. */
20957 : 3140988455 : if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
20958 : : return true;
20959 : :
20960 : : /* Between mask and general, we have moves no larger than word size. */
20961 : 3047469379 : if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2))
20962 : : {
20963 : 2498394 : if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2))
20964 : 3273834 : || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
20965 : 181767 : return true;
20966 : : }
20967 : :
20968 : 3047287612 : if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
20969 : : {
20970 : : /* SSE1 doesn't have any direct moves from other classes. */
20971 : 662846524 : if (!TARGET_SSE2)
20972 : : return true;
20973 : :
20974 : 660307928 : if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2)))
20975 : : return true;
20976 : :
20977 : : /* If the target says that inter-unit moves are more expensive
20978 : : than moving through memory, then don't generate them. */
20979 : 989561965 : if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC)
20980 : 988883812 : || (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC))
20981 : 1705769 : return true;
20982 : :
20983 : : /* With SSE4.1, *mov{ti,di}_internal supports moves between
20984 : : SSE_REGS and GENERAL_REGS using pinsr{q,d} or pextr{q,d}. */
20985 : 658602159 : if (TARGET_SSE4_1
20986 : 34674895 : && (TARGET_64BIT ? mode == TImode : mode == DImode))
20987 : : return false;
20988 : :
20989 : 657097569 : int msize = GET_MODE_SIZE (mode);
20990 : :
20991 : : /* Between SSE and general, we have moves no larger than word size. */
20992 : 673522922 : if (msize > UNITS_PER_WORD)
20993 : : return true;
20994 : :
20995 : : /* In addition to SImode moves, HImode moves are supported for SSE2 and above,
20996 : : Use vmovw with AVX512FP16, or pinsrw/pextrw without AVX512FP16. */
20997 : 568316586 : int minsize = GET_MODE_SIZE (TARGET_SSE2 ? HImode : SImode);
20998 : :
20999 : 568316586 : if (msize < minsize)
21000 : : return true;
21001 : : }
21002 : :
21003 : : return false;
21004 : : }
21005 : :
21006 : : /* Implement TARGET_SECONDARY_MEMORY_NEEDED. */
21007 : :
21008 : : static bool
21009 : 71602875 : ix86_secondary_memory_needed (machine_mode mode, reg_class_t class1,
21010 : : reg_class_t class2)
21011 : : {
21012 : 71602875 : return inline_secondary_memory_needed (mode, class1, class2, true);
21013 : : }
21014 : :
21015 : : /* Implement TARGET_SECONDARY_MEMORY_NEEDED_MODE.
21016 : :
21017 : : get_secondary_mem widens integral modes to BITS_PER_WORD.
21018 : : There is no need to emit full 64 bit move on 64 bit targets
21019 : : for integral modes that can be moved using 32 bit move. */
21020 : :
21021 : : static machine_mode
21022 : 13391 : ix86_secondary_memory_needed_mode (machine_mode mode)
21023 : : {
21024 : 26782 : if (GET_MODE_BITSIZE (mode) < 32 && INTEGRAL_MODE_P (mode))
21025 : 16 : return mode_for_size (32, GET_MODE_CLASS (mode), 0).require ();
21026 : : return mode;
21027 : : }
21028 : :
21029 : : /* Implement the TARGET_CLASS_MAX_NREGS hook.
21030 : :
21031 : : On the 80386, this is the size of MODE in words,
21032 : : except in the FP regs, where a single reg is always enough. */
21033 : :
21034 : : static unsigned char
21035 : 6225043700 : ix86_class_max_nregs (reg_class_t rclass, machine_mode mode)
21036 : : {
21037 : 6225043700 : if (MAYBE_INTEGER_CLASS_P (rclass))
21038 : : {
21039 : 4174933295 : if (mode == XFmode)
21040 : 141790075 : return (TARGET_64BIT ? 2 : 3);
21041 : 4033143220 : else if (mode == XCmode)
21042 : 141789706 : return (TARGET_64BIT ? 4 : 6);
21043 : : else
21044 : 7891346832 : return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
21045 : : }
21046 : : else
21047 : : {
21048 : 2050110405 : if (COMPLEX_MODE_P (mode))
21049 : : return 2;
21050 : : else
21051 : 1763897272 : return 1;
21052 : : }
21053 : : }
21054 : :
21055 : : /* Implement TARGET_CAN_CHANGE_MODE_CLASS. */
21056 : :
21057 : : static bool
21058 : 39904409 : ix86_can_change_mode_class (machine_mode from, machine_mode to,
21059 : : reg_class_t regclass)
21060 : : {
21061 : 39904409 : if (from == to)
21062 : : return true;
21063 : :
21064 : : /* x87 registers can't do subreg at all, as all values are reformatted
21065 : : to extended precision.
21066 : :
21067 : : ??? middle-end queries mode changes for ALL_REGS and this makes
21068 : : vec_series_lowpart_p to always return false. We probably should
21069 : : restrict this to modes supported by i387 and check if it is enabled. */
21070 : 38419120 : if (MAYBE_FLOAT_CLASS_P (regclass))
21071 : : return false;
21072 : :
21073 : 33997654 : if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
21074 : : {
21075 : : /* Vector registers do not support QI or HImode loads. If we don't
21076 : : disallow a change to these modes, reload will assume it's ok to
21077 : : drop the subreg from (subreg:SI (reg:HI 100) 0). This affects
21078 : : the vec_dupv4hi pattern.
21079 : : NB: SSE2 can load 16bit data to sse register via pinsrw. */
21080 : 16542418 : int mov_size = MAYBE_SSE_CLASS_P (regclass) && TARGET_SSE2 ? 2 : 4;
21081 : 16542418 : if (GET_MODE_SIZE (from) < mov_size
21082 : 33084515 : || GET_MODE_SIZE (to) < mov_size)
21083 : : return false;
21084 : : }
21085 : :
21086 : : return true;
21087 : : }
21088 : :
21089 : : /* Return index of MODE in the sse load/store tables. */
21090 : :
21091 : : static inline int
21092 : 754761496 : sse_store_index (machine_mode mode)
21093 : : {
21094 : : /* NB: Use SFmode cost for HFmode instead of adding HFmode load/store
21095 : : costs to processor_costs, which requires changes to all entries in
21096 : : processor cost table. */
21097 : 754761496 : if (mode == E_HFmode)
21098 : 131929348 : mode = E_SFmode;
21099 : :
21100 : 1509522992 : switch (GET_MODE_SIZE (mode))
21101 : : {
21102 : : case 4:
21103 : : return 0;
21104 : 146645810 : case 8:
21105 : 146645810 : return 1;
21106 : 205204110 : case 16:
21107 : 205204110 : return 2;
21108 : 28035848 : case 32:
21109 : 28035848 : return 3;
21110 : 23399047 : case 64:
21111 : 23399047 : return 4;
21112 : 91120183 : default:
21113 : 91120183 : return -1;
21114 : : }
21115 : : }
21116 : :
21117 : : /* Return the cost of moving data of mode M between a
21118 : : register and memory. A value of 2 is the default; this cost is
21119 : : relative to those in `REGISTER_MOVE_COST'.
21120 : :
21121 : : This function is used extensively by register_move_cost that is used to
21122 : : build tables at startup. Make it inline in this case.
21123 : : When IN is 2, return maximum of in and out move cost.
21124 : :
21125 : : If moving between registers and memory is more expensive than
21126 : : between two registers, you should define this macro to express the
21127 : : relative cost.
21128 : :
21129 : : Model also increased moving costs of QImode registers in non
21130 : : Q_REGS classes.
21131 : : */
21132 : : static inline int
21133 : 6734533105 : inline_memory_move_cost (machine_mode mode, enum reg_class regclass, int in)
21134 : : {
21135 : 6734533105 : int cost;
21136 : :
21137 : 6734533105 : if (FLOAT_CLASS_P (regclass))
21138 : : {
21139 : 347197137 : int index;
21140 : 347197137 : switch (mode)
21141 : : {
21142 : : case E_SFmode:
21143 : : index = 0;
21144 : : break;
21145 : : case E_DFmode:
21146 : : index = 1;
21147 : : break;
21148 : : case E_XFmode:
21149 : : index = 2;
21150 : : break;
21151 : : default:
21152 : : return 100;
21153 : : }
21154 : 101535427 : if (in == 2)
21155 : 97744727 : return MAX (ix86_cost->hard_register.fp_load [index],
21156 : : ix86_cost->hard_register.fp_store [index]);
21157 : 3790700 : return in ? ix86_cost->hard_register.fp_load [index]
21158 : 3790700 : : ix86_cost->hard_register.fp_store [index];
21159 : : }
21160 : 6387335968 : if (SSE_CLASS_P (regclass))
21161 : : {
21162 : 630731476 : int index = sse_store_index (mode);
21163 : 630731476 : if (index == -1)
21164 : : return 100;
21165 : 539811186 : if (in == 2)
21166 : 382668082 : return MAX (ix86_cost->hard_register.sse_load [index],
21167 : : ix86_cost->hard_register.sse_store [index]);
21168 : 157143104 : return in ? ix86_cost->hard_register.sse_load [index]
21169 : 157143104 : : ix86_cost->hard_register.sse_store [index];
21170 : : }
21171 : 5756604492 : if (MASK_CLASS_P (regclass))
21172 : : {
21173 : 109163159 : int index;
21174 : 218326318 : switch (GET_MODE_SIZE (mode))
21175 : : {
21176 : : case 1:
21177 : : index = 0;
21178 : : break;
21179 : 8593633 : case 2:
21180 : 8593633 : index = 1;
21181 : 8593633 : break;
21182 : : /* DImode loads and stores assumed to cost the same as SImode. */
21183 : 38649810 : case 4:
21184 : 38649810 : case 8:
21185 : 38649810 : index = 2;
21186 : 38649810 : break;
21187 : : default:
21188 : : return 100;
21189 : : }
21190 : :
21191 : 50684879 : if (in == 2)
21192 : 560600 : return MAX (ix86_cost->hard_register.mask_load[index],
21193 : : ix86_cost->hard_register.mask_store[index]);
21194 : 50124279 : return in ? ix86_cost->hard_register.mask_load[2]
21195 : 50124279 : : ix86_cost->hard_register.mask_store[2];
21196 : : }
21197 : 5647441333 : if (MMX_CLASS_P (regclass))
21198 : : {
21199 : 168350545 : int index;
21200 : 336701090 : switch (GET_MODE_SIZE (mode))
21201 : : {
21202 : : case 4:
21203 : : index = 0;
21204 : : break;
21205 : 97332965 : case 8:
21206 : 97332965 : index = 1;
21207 : 97332965 : break;
21208 : : default:
21209 : : return 100;
21210 : : }
21211 : 133263577 : if (in == 2)
21212 : 114049263 : return MAX (ix86_cost->hard_register.mmx_load [index],
21213 : : ix86_cost->hard_register.mmx_store [index]);
21214 : 19214314 : return in ? ix86_cost->hard_register.mmx_load [index]
21215 : 19214314 : : ix86_cost->hard_register.mmx_store [index];
21216 : : }
21217 : 10958181576 : switch (GET_MODE_SIZE (mode))
21218 : : {
21219 : 120013458 : case 1:
21220 : 120013458 : if (Q_CLASS_P (regclass) || TARGET_64BIT)
21221 : : {
21222 : 117416279 : if (!in)
21223 : 18835396 : return ix86_cost->hard_register.int_store[0];
21224 : 98580883 : if (TARGET_PARTIAL_REG_DEPENDENCY
21225 : 98580883 : && optimize_function_for_speed_p (cfun))
21226 : 91889233 : cost = ix86_cost->hard_register.movzbl_load;
21227 : : else
21228 : 6691650 : cost = ix86_cost->hard_register.int_load[0];
21229 : 98580883 : if (in == 2)
21230 : 79712450 : return MAX (cost, ix86_cost->hard_register.int_store[0]);
21231 : : return cost;
21232 : : }
21233 : : else
21234 : : {
21235 : 2597179 : if (in == 2)
21236 : 1839260 : return MAX (ix86_cost->hard_register.movzbl_load,
21237 : : ix86_cost->hard_register.int_store[0] + 4);
21238 : 757919 : if (in)
21239 : 379023 : return ix86_cost->hard_register.movzbl_load;
21240 : : else
21241 : 378896 : return ix86_cost->hard_register.int_store[0] + 4;
21242 : : }
21243 : 619540352 : break;
21244 : 619540352 : case 2:
21245 : 619540352 : {
21246 : 619540352 : int cost;
21247 : 619540352 : if (in == 2)
21248 : 523447162 : cost = MAX (ix86_cost->hard_register.int_load[1],
21249 : : ix86_cost->hard_register.int_store[1]);
21250 : : else
21251 : 96093190 : cost = in ? ix86_cost->hard_register.int_load[1]
21252 : : : ix86_cost->hard_register.int_store[1];
21253 : :
21254 : 619540352 : if (mode == E_HFmode)
21255 : : {
21256 : : /* Prefer SSE over GPR for HFmode. */
21257 : 120056112 : int sse_cost;
21258 : 120056112 : int index = sse_store_index (mode);
21259 : 120056112 : if (in == 2)
21260 : 110448904 : sse_cost = MAX (ix86_cost->hard_register.sse_load[index],
21261 : : ix86_cost->hard_register.sse_store[index]);
21262 : : else
21263 : 9607208 : sse_cost = (in
21264 : 9607208 : ? ix86_cost->hard_register.sse_load [index]
21265 : : : ix86_cost->hard_register.sse_store [index]);
21266 : 120056112 : if (sse_cost >= cost)
21267 : 120056112 : cost = sse_cost + 1;
21268 : : }
21269 : : return cost;
21270 : : }
21271 : 4739536978 : default:
21272 : 4739536978 : if (in == 2)
21273 : 3624726452 : cost = MAX (ix86_cost->hard_register.int_load[2],
21274 : : ix86_cost->hard_register.int_store[2]);
21275 : 1114810526 : else if (in)
21276 : 557596058 : cost = ix86_cost->hard_register.int_load[2];
21277 : : else
21278 : 557214468 : cost = ix86_cost->hard_register.int_store[2];
21279 : : /* Multiply with the number of GPR moves needed. */
21280 : 9598138056 : return cost * CEIL ((int) GET_MODE_SIZE (mode), UNITS_PER_WORD);
21281 : : }
21282 : : }
21283 : :
21284 : : static int
21285 : 1792586717 : ix86_memory_move_cost (machine_mode mode, reg_class_t regclass, bool in)
21286 : : {
21287 : 2688557507 : return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0);
21288 : : }
21289 : :
21290 : :
21291 : : /* Return the cost of moving data from a register in class CLASS1 to
21292 : : one in class CLASS2.
21293 : :
21294 : : It is not required that the cost always equal 2 when FROM is the same as TO;
21295 : : on some machines it is expensive to move between registers if they are not
21296 : : general registers. */
21297 : :
21298 : : static int
21299 : 5396557570 : ix86_register_move_cost (machine_mode mode, reg_class_t class1_i,
21300 : : reg_class_t class2_i)
21301 : : {
21302 : 5396557570 : enum reg_class class1 = (enum reg_class) class1_i;
21303 : 5396557570 : enum reg_class class2 = (enum reg_class) class2_i;
21304 : :
21305 : : /* In case we require secondary memory, compute cost of the store followed
21306 : : by load. In order to avoid bad register allocation choices, we need
21307 : : for this to be *at least* as high as the symmetric MEMORY_MOVE_COST. */
21308 : :
21309 : 5396557570 : if (inline_secondary_memory_needed (mode, class1, class2, false))
21310 : : {
21311 : 2470973194 : int cost = 1;
21312 : :
21313 : 2470973194 : cost += inline_memory_move_cost (mode, class1, 2);
21314 : 2470973194 : cost += inline_memory_move_cost (mode, class2, 2);
21315 : :
21316 : : /* In case of copying from general_purpose_register we may emit multiple
21317 : : stores followed by single load causing memory size mismatch stall.
21318 : : Count this as arbitrarily high cost of 20. */
21319 : 4941946388 : if (GET_MODE_BITSIZE (mode) > BITS_PER_WORD
21320 : 740158744 : && TARGET_MEMORY_MISMATCH_STALL
21321 : 3951290682 : && targetm.class_max_nregs (class1, mode)
21322 : 740158744 : > targetm.class_max_nregs (class2, mode))
21323 : 140888146 : cost += 20;
21324 : :
21325 : : /* In the case of FP/MMX moves, the registers actually overlap, and we
21326 : : have to switch modes in order to treat them differently. */
21327 : 57024668 : if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
21328 : 2519017269 : || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
21329 : 17961186 : cost += 20;
21330 : :
21331 : 2470973194 : return cost;
21332 : : }
21333 : :
21334 : : /* Moves between MMX and non-MMX units require secondary memory. */
21335 : 2925584376 : if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
21336 : 0 : gcc_unreachable ();
21337 : :
21338 : 2925584376 : if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
21339 : 559555279 : return (SSE_CLASS_P (class1)
21340 : 559555279 : ? ix86_cost->hard_register.sse_to_integer
21341 : : : ix86_cost->hard_register.integer_to_sse);
21342 : :
21343 : : /* Moves between mask register and GPR. */
21344 : 2366029097 : if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2))
21345 : : {
21346 : 1013967 : return (MASK_CLASS_P (class1)
21347 : 1013967 : ? ix86_cost->hard_register.mask_to_integer
21348 : : : ix86_cost->hard_register.integer_to_mask);
21349 : : }
21350 : : /* Moving between mask registers. */
21351 : 2365015130 : if (MASK_CLASS_P (class1) && MASK_CLASS_P (class2))
21352 : 97500 : return ix86_cost->hard_register.mask_move;
21353 : :
21354 : 2364917630 : if (MAYBE_FLOAT_CLASS_P (class1))
21355 : 11354916 : return ix86_cost->hard_register.fp_move;
21356 : 2353562714 : if (MAYBE_SSE_CLASS_P (class1))
21357 : : {
21358 : 220951158 : if (GET_MODE_BITSIZE (mode) <= 128)
21359 : 108107852 : return ix86_cost->hard_register.xmm_move;
21360 : 4735454 : if (GET_MODE_BITSIZE (mode) <= 256)
21361 : 1505763 : return ix86_cost->hard_register.ymm_move;
21362 : 861964 : return ix86_cost->hard_register.zmm_move;
21363 : : }
21364 : 2243087135 : if (MAYBE_MMX_CLASS_P (class1))
21365 : 2088563 : return ix86_cost->hard_register.mmx_move;
21366 : : return 2;
21367 : : }
21368 : :
21369 : : /* Implement TARGET_HARD_REGNO_NREGS. This is ordinarily the length in
21370 : : words of a value of mode MODE but can be less for certain modes in
21371 : : special long registers.
21372 : :
21373 : : Actually there are no two word move instructions for consecutive
21374 : : registers. And only registers 0-3 may have mov byte instructions
21375 : : applied to them. */
21376 : :
21377 : : static unsigned int
21378 : 9776570440 : ix86_hard_regno_nregs (unsigned int regno, machine_mode mode)
21379 : : {
21380 : 9776570440 : if (GENERAL_REGNO_P (regno))
21381 : : {
21382 : 3400546240 : if (mode == XFmode)
21383 : 26645280 : return TARGET_64BIT ? 2 : 3;
21384 : 3374388192 : if (mode == XCmode)
21385 : 26645280 : return TARGET_64BIT ? 4 : 6;
21386 : 6758825984 : return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
21387 : : }
21388 : 6376024200 : if (COMPLEX_MODE_P (mode))
21389 : : return 2;
21390 : : /* Register pair for mask registers. */
21391 : 5591282760 : if (mode == P2QImode || mode == P2HImode)
21392 : : return 2;
21393 : 5493190080 : if (mode == V64SFmode || mode == V64SImode)
21394 : 98092680 : return 4;
21395 : : return 1;
21396 : : }
21397 : :
21398 : : /* Implement REGMODE_NATURAL_SIZE(MODE). */
21399 : : unsigned int
21400 : 107166647 : ix86_regmode_natural_size (machine_mode mode)
21401 : : {
21402 : 107166647 : if (mode == P2HImode || mode == P2QImode)
21403 : 2450 : return GET_MODE_SIZE (mode) / 2;
21404 : 107165422 : return UNITS_PER_WORD;
21405 : : }
21406 : :
21407 : : /* Implement TARGET_HARD_REGNO_MODE_OK. */
21408 : :
21409 : : static bool
21410 : 57917786831 : ix86_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
21411 : : {
21412 : : /* Flags and only flags can only hold CCmode values. */
21413 : 57917786831 : if (CC_REGNO_P (regno))
21414 : 465682193 : return GET_MODE_CLASS (mode) == MODE_CC;
21415 : 57452104638 : if (GET_MODE_CLASS (mode) == MODE_CC
21416 : : || GET_MODE_CLASS (mode) == MODE_RANDOM)
21417 : : return false;
21418 : 51817633802 : if (STACK_REGNO_P (regno))
21419 : 5044245462 : return VALID_FP_MODE_P (mode);
21420 : 46773388340 : if (MASK_REGNO_P (regno))
21421 : : {
21422 : : /* Register pair only starts at even register number. */
21423 : 4000274513 : if ((mode == P2QImode || mode == P2HImode))
21424 : 53245458 : return MASK_PAIR_REGNO_P(regno);
21425 : :
21426 : 1251890847 : return ((TARGET_AVX512F && VALID_MASK_REG_MODE (mode))
21427 : 5174897561 : || (TARGET_AVX512BW && VALID_MASK_AVX512BW_MODE (mode)));
21428 : : }
21429 : :
21430 : 42773113827 : if (GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
21431 : : return false;
21432 : :
21433 : 41777502363 : if (SSE_REGNO_P (regno))
21434 : : {
21435 : : /* We implement the move patterns for all vector modes into and
21436 : : out of SSE registers, even when no operation instructions
21437 : : are available. */
21438 : :
21439 : : /* For AVX-512 we allow, regardless of regno:
21440 : : - XI mode
21441 : : - any of 512-bit wide vector mode
21442 : : - any scalar mode. */
21443 : 18177452041 : if (TARGET_AVX512F
21444 : 5002642778 : && ((VALID_AVX512F_REG_OR_XI_MODE (mode) && TARGET_EVEX512)
21445 : 4654539623 : || VALID_AVX512F_SCALAR_MODE (mode)))
21446 : : return true;
21447 : :
21448 : : /* TODO check for QI/HI scalars. */
21449 : : /* AVX512VL allows sse regs16+ for 128/256 bit modes. */
21450 : 17489241055 : if (TARGET_AVX512VL
21451 : 2277620937 : && (VALID_AVX256_REG_OR_OI_MODE (mode)
21452 : 2030349626 : || VALID_AVX512VL_128_REG_MODE (mode)))
21453 : : return true;
21454 : :
21455 : : /* xmm16-xmm31 are only available for AVX-512. */
21456 : 16969206368 : if (EXT_REX_SSE_REGNO_P (regno))
21457 : : return false;
21458 : :
21459 : : /* OImode and AVX modes are available only when AVX is enabled. */
21460 : 9733012091 : return ((TARGET_AVX
21461 : 2464231964 : && VALID_AVX256_REG_OR_OI_MODE (mode))
21462 : : || VALID_SSE_REG_MODE (mode)
21463 : : || VALID_SSE2_REG_MODE (mode)
21464 : : || VALID_MMX_REG_MODE (mode)
21465 : 9733012091 : || VALID_MMX_REG_MODE_3DNOW (mode));
21466 : : }
21467 : 23600050322 : if (MMX_REGNO_P (regno))
21468 : : {
21469 : : /* We implement the move patterns for 3DNOW modes even in MMX mode,
21470 : : so if the register is available at all, then we can move data of
21471 : : the given mode into or out of it. */
21472 : 4271592520 : return (VALID_MMX_REG_MODE (mode)
21473 : : || VALID_MMX_REG_MODE_3DNOW (mode));
21474 : : }
21475 : :
21476 : 19328457802 : if (mode == QImode)
21477 : : {
21478 : : /* Take care for QImode values - they can be in non-QI regs,
21479 : : but then they do cause partial register stalls. */
21480 : 208591324 : if (ANY_QI_REGNO_P (regno))
21481 : : return true;
21482 : 14686563 : if (!TARGET_PARTIAL_REG_STALL)
21483 : : return true;
21484 : : /* LRA checks if the hard register is OK for the given mode.
21485 : : QImode values can live in non-QI regs, so we allow all
21486 : : registers here. */
21487 : 0 : if (lra_in_progress)
21488 : : return true;
21489 : 0 : return !can_create_pseudo_p ();
21490 : : }
21491 : : /* We handle both integer and floats in the general purpose registers. */
21492 : 19119866478 : else if (VALID_INT_MODE_P (mode)
21493 : 14250309103 : || VALID_FP_MODE_P (mode))
21494 : : return true;
21495 : : /* Lots of MMX code casts 8 byte vector modes to DImode. If we then go
21496 : : on to use that value in smaller contexts, this can easily force a
21497 : : pseudo to be allocated to GENERAL_REGS. Since this is no worse than
21498 : : supporting DImode, allow it. */
21499 : 13179875856 : else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
21500 : : return true;
21501 : :
21502 : : return false;
21503 : : }
21504 : :
21505 : : /* Implement TARGET_INSN_CALLEE_ABI. */
21506 : :
21507 : : const predefined_function_abi &
21508 : 246055640 : ix86_insn_callee_abi (const rtx_insn *insn)
21509 : : {
21510 : 246055640 : unsigned int abi_id = 0;
21511 : 246055640 : rtx pat = PATTERN (insn);
21512 : 246055640 : if (vzeroupper_pattern (pat, VOIDmode))
21513 : 250735 : abi_id = ABI_VZEROUPPER;
21514 : :
21515 : 246055640 : return function_abis[abi_id];
21516 : : }
21517 : :
21518 : : /* Initialize function_abis with corresponding abi_id,
21519 : : currently only handle vzeroupper. */
21520 : : void
21521 : 17618 : ix86_initialize_callee_abi (unsigned int abi_id)
21522 : : {
21523 : 17618 : gcc_assert (abi_id == ABI_VZEROUPPER);
21524 : 17618 : predefined_function_abi &vzeroupper_abi = function_abis[abi_id];
21525 : 17618 : if (!vzeroupper_abi.initialized_p ())
21526 : : {
21527 : : HARD_REG_SET full_reg_clobbers;
21528 : 4011 : CLEAR_HARD_REG_SET (full_reg_clobbers);
21529 : 4011 : vzeroupper_abi.initialize (ABI_VZEROUPPER, full_reg_clobbers);
21530 : : }
21531 : 17618 : }
21532 : :
21533 : : void
21534 : 17618 : ix86_expand_avx_vzeroupper (void)
21535 : : {
21536 : : /* Initialize vzeroupper_abi here. */
21537 : 17618 : ix86_initialize_callee_abi (ABI_VZEROUPPER);
21538 : 17618 : rtx_insn *insn = emit_call_insn (gen_avx_vzeroupper_callee_abi ());
21539 : : /* Return false for non-local goto in can_nonlocal_goto. */
21540 : 17618 : make_reg_eh_region_note (insn, 0, INT_MIN);
21541 : : /* Flag used for call_insn indicates it's a fake call. */
21542 : 17618 : RTX_FLAG (insn, used) = 1;
21543 : 17618 : }
21544 : :
21545 : :
21546 : : /* Implement TARGET_HARD_REGNO_CALL_PART_CLOBBERED. The only ABI that
21547 : : saves SSE registers across calls is Win64 (thus no need to check the
21548 : : current ABI here), and with AVX enabled Win64 only guarantees that
21549 : : the low 16 bytes are saved. */
21550 : :
21551 : : static bool
21552 : 2121787105 : ix86_hard_regno_call_part_clobbered (unsigned int abi_id, unsigned int regno,
21553 : : machine_mode mode)
21554 : : {
21555 : : /* Special ABI for vzeroupper which only clobber higher part of sse regs. */
21556 : 2121787105 : if (abi_id == ABI_VZEROUPPER)
21557 : 28934739 : return (GET_MODE_SIZE (mode) > 16
21558 : 28934739 : && ((TARGET_64BIT && REX_SSE_REGNO_P (regno))
21559 : 4410366 : || LEGACY_SSE_REGNO_P (regno)));
21560 : :
21561 : 2754928526 : return SSE_REGNO_P (regno) && GET_MODE_SIZE (mode) > 16;
21562 : : }
21563 : :
21564 : : /* A subroutine of ix86_modes_tieable_p. Return true if MODE is a
21565 : : tieable integer mode. */
21566 : :
21567 : : static bool
21568 : 50000340 : ix86_tieable_integer_mode_p (machine_mode mode)
21569 : : {
21570 : 50000340 : switch (mode)
21571 : : {
21572 : : case E_HImode:
21573 : : case E_SImode:
21574 : : return true;
21575 : :
21576 : 5153597 : case E_QImode:
21577 : 5153597 : return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
21578 : :
21579 : 9765954 : case E_DImode:
21580 : 9765954 : return TARGET_64BIT;
21581 : :
21582 : : default:
21583 : : return false;
21584 : : }
21585 : : }
21586 : :
21587 : : /* Implement TARGET_MODES_TIEABLE_P.
21588 : :
21589 : : Return true if MODE1 is accessible in a register that can hold MODE2
21590 : : without copying. That is, all register classes that can hold MODE2
21591 : : can also hold MODE1. */
21592 : :
21593 : : static bool
21594 : 32316334 : ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2)
21595 : : {
21596 : 32316334 : if (mode1 == mode2)
21597 : : return true;
21598 : :
21599 : 32226732 : if (ix86_tieable_integer_mode_p (mode1)
21600 : 32226732 : && ix86_tieable_integer_mode_p (mode2))
21601 : : return true;
21602 : :
21603 : : /* MODE2 being XFmode implies fp stack or general regs, which means we
21604 : : can tie any smaller floating point modes to it. Note that we do not
21605 : : tie this with TFmode. */
21606 : 23780211 : if (mode2 == XFmode)
21607 : 4370 : return mode1 == SFmode || mode1 == DFmode;
21608 : :
21609 : : /* MODE2 being DFmode implies fp stack, general or sse regs, which means
21610 : : that we can tie it with SFmode. */
21611 : 23775841 : if (mode2 == DFmode)
21612 : 257195 : return mode1 == SFmode;
21613 : :
21614 : : /* If MODE2 is only appropriate for an SSE register, then tie with
21615 : : any vector modes or scalar floating point modes acceptable to SSE
21616 : : registers, excluding scalar integer modes with SUBREG:
21617 : : (subreg:QI (reg:TI 99) 0))
21618 : : (subreg:HI (reg:TI 99) 0))
21619 : : (subreg:SI (reg:TI 99) 0))
21620 : : (subreg:DI (reg:TI 99) 0))
21621 : : to avoid unnecessary move from SSE register to integer register.
21622 : : */
21623 : 23518646 : if (GET_MODE_SIZE (mode2) >= 16
21624 : 36526758 : && (GET_MODE_SIZE (mode1) == GET_MODE_SIZE (mode2)
21625 : 13163572 : || ((VECTOR_MODE_P (mode1) || SCALAR_FLOAT_MODE_P (mode1))
21626 : 449096 : && GET_MODE_SIZE (mode1) <= GET_MODE_SIZE (mode2)))
21627 : 28842412 : && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
21628 : 4906236 : return ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1);
21629 : :
21630 : : /* If MODE2 is appropriate for an MMX register, then tie
21631 : : with any other mode acceptable to MMX registers. */
21632 : 18612410 : if (GET_MODE_SIZE (mode2) == 8
21633 : 18612410 : && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
21634 : 3290887 : return (GET_MODE_SIZE (mode1) == 8
21635 : 3290887 : && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
21636 : :
21637 : : /* SCmode and DImode can be tied. */
21638 : 15321523 : if ((mode1 == E_SCmode && mode2 == E_DImode)
21639 : 15321523 : || (mode1 == E_DImode && mode2 == E_SCmode))
21640 : 108 : return TARGET_64BIT;
21641 : :
21642 : : /* [SD]Cmode and V2[SD]Fmode modes can be tied. */
21643 : 15321415 : if ((mode1 == E_SCmode && mode2 == E_V2SFmode)
21644 : 15321415 : || (mode1 == E_V2SFmode && mode2 == E_SCmode)
21645 : 15321415 : || (mode1 == E_DCmode && mode2 == E_V2DFmode)
21646 : 15321415 : || (mode1 == E_V2DFmode && mode2 == E_DCmode))
21647 : 0 : return true;
21648 : :
21649 : : return false;
21650 : : }
21651 : :
21652 : : /* Return the cost of moving between two registers of mode MODE. */
21653 : :
21654 : : static int
21655 : 30727586 : ix86_set_reg_reg_cost (machine_mode mode)
21656 : : {
21657 : 30727586 : unsigned int units = UNITS_PER_WORD;
21658 : :
21659 : 30727586 : switch (GET_MODE_CLASS (mode))
21660 : : {
21661 : : default:
21662 : : break;
21663 : :
21664 : : case MODE_CC:
21665 : 30727586 : units = GET_MODE_SIZE (CCmode);
21666 : : break;
21667 : :
21668 : 1131872 : case MODE_FLOAT:
21669 : 1131872 : if ((TARGET_SSE && mode == TFmode)
21670 : 664648 : || (TARGET_80387 && mode == XFmode)
21671 : 208336 : || ((TARGET_80387 || TARGET_SSE2) && mode == DFmode)
21672 : 141301 : || ((TARGET_80387 || TARGET_SSE) && mode == SFmode))
21673 : 2234296 : units = GET_MODE_SIZE (mode);
21674 : : break;
21675 : :
21676 : 1257812 : case MODE_COMPLEX_FLOAT:
21677 : 1257812 : if ((TARGET_SSE && mode == TCmode)
21678 : 843380 : || (TARGET_80387 && mode == XCmode)
21679 : 428842 : || ((TARGET_80387 || TARGET_SSE2) && mode == DCmode)
21680 : 14290 : || ((TARGET_80387 || TARGET_SSE) && mode == SCmode))
21681 : 2509332 : units = GET_MODE_SIZE (mode);
21682 : : break;
21683 : :
21684 : 20494554 : case MODE_VECTOR_INT:
21685 : 20494554 : case MODE_VECTOR_FLOAT:
21686 : 20494554 : if ((TARGET_AVX512F && TARGET_EVEX512 && VALID_AVX512F_REG_MODE (mode))
21687 : 20402740 : || (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
21688 : 20236651 : || (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
21689 : 17706920 : || (TARGET_SSE && VALID_SSE_REG_MODE (mode))
21690 : 16449039 : || ((TARGET_MMX || TARGET_MMX_WITH_SSE)
21691 : 16398259 : && VALID_MMX_REG_MODE (mode)))
21692 : 8195688 : units = GET_MODE_SIZE (mode);
21693 : : }
21694 : :
21695 : : /* Return the cost of moving between two registers of mode MODE,
21696 : : assuming that the move will be in pieces of at most UNITS bytes. */
21697 : 30727586 : return COSTS_N_INSNS (CEIL (GET_MODE_SIZE (mode), units));
21698 : : }
21699 : :
21700 : : /* Return cost of vector operation in MODE given that scalar version has
21701 : : COST. */
21702 : :
21703 : : static int
21704 : 2815101794 : ix86_vec_cost (machine_mode mode, int cost)
21705 : : {
21706 : 2815101794 : if (!VECTOR_MODE_P (mode))
21707 : : return cost;
21708 : :
21709 : 2814675716 : if (GET_MODE_BITSIZE (mode) == 128
21710 : 2814675716 : && TARGET_SSE_SPLIT_REGS)
21711 : 3486394 : return cost * GET_MODE_BITSIZE (mode) / 64;
21712 : 2812932519 : else if (GET_MODE_BITSIZE (mode) > 128
21713 : 2812932519 : && TARGET_AVX256_SPLIT_REGS)
21714 : 1724294 : return cost * GET_MODE_BITSIZE (mode) / 128;
21715 : 2812070372 : else if (GET_MODE_BITSIZE (mode) > 256
21716 : 2812070372 : && TARGET_AVX512_SPLIT_REGS)
21717 : 165870 : return cost * GET_MODE_BITSIZE (mode) / 256;
21718 : : return cost;
21719 : : }
21720 : :
21721 : : /* Return cost of vec_widen_<s>mult_hi/lo_<mode>,
21722 : : vec_widen_<s>mul_hi/lo_<mode> is only available for VI124_AVX2. */
21723 : : static int
21724 : 1873 : ix86_widen_mult_cost (const struct processor_costs *cost,
21725 : : enum machine_mode mode, bool uns_p)
21726 : : {
21727 : 1873 : gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT);
21728 : 1873 : int extra_cost = 0;
21729 : 1873 : int basic_cost = 0;
21730 : 1873 : switch (mode)
21731 : : {
21732 : 207 : case V8HImode:
21733 : 207 : case V16HImode:
21734 : 207 : if (!uns_p || mode == V16HImode)
21735 : 47 : extra_cost = cost->sse_op * 2;
21736 : 207 : basic_cost = cost->mulss * 2 + cost->sse_op * 4;
21737 : 207 : break;
21738 : 336 : case V4SImode:
21739 : 336 : case V8SImode:
21740 : : /* pmulhw/pmullw can be used. */
21741 : 336 : basic_cost = cost->mulss * 2 + cost->sse_op * 2;
21742 : 336 : break;
21743 : 1224 : case V2DImode:
21744 : : /* pmuludq under sse2, pmuldq under sse4.1, for sign_extend,
21745 : : require extra 4 mul, 4 add, 4 cmp and 2 shift. */
21746 : 1224 : if (!TARGET_SSE4_1 && !uns_p)
21747 : 742 : extra_cost = (cost->mulss + cost->addss + cost->sse_op) * 4
21748 : 742 : + cost->sse_op * 2;
21749 : : /* Fallthru. */
21750 : 1318 : case V4DImode:
21751 : 1318 : basic_cost = cost->mulss * 2 + cost->sse_op * 4;
21752 : 1318 : break;
21753 : : default:
21754 : : /* Not implemented. */
21755 : : return 100;
21756 : : }
21757 : 1861 : return ix86_vec_cost (mode, basic_cost + extra_cost);
21758 : : }
21759 : :
21760 : : /* Return cost of multiplication in MODE. */
21761 : :
21762 : : static int
21763 : 1201539941 : ix86_multiplication_cost (const struct processor_costs *cost,
21764 : : enum machine_mode mode)
21765 : : {
21766 : 1201539941 : machine_mode inner_mode = mode;
21767 : 1201539941 : if (VECTOR_MODE_P (mode))
21768 : 1200564946 : inner_mode = GET_MODE_INNER (mode);
21769 : :
21770 : 1201539941 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
21771 : 732662 : return inner_mode == DFmode ? cost->mulsd : cost->mulss;
21772 : 1200807279 : else if (X87_FLOAT_MODE_P (mode))
21773 : 164770 : return cost->fmul;
21774 : 1200642509 : else if (FLOAT_MODE_P (mode))
21775 : 197256 : return ix86_vec_cost (mode,
21776 : 197256 : inner_mode == DFmode ? cost->mulsd : cost->mulss);
21777 : 1200445253 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
21778 : : {
21779 : 1200391916 : int nmults, nops;
21780 : : /* Cost of reading the memory. */
21781 : 1200391916 : int extra;
21782 : :
21783 : 1200391916 : switch (mode)
21784 : : {
21785 : 18286689 : case V4QImode:
21786 : 18286689 : case V8QImode:
21787 : : /* Partial V*QImode is emulated with 4-6 insns. */
21788 : 18286689 : nmults = 1;
21789 : 18286689 : nops = 3;
21790 : 18286689 : extra = 0;
21791 : :
21792 : 18286689 : if (TARGET_AVX512BW && TARGET_AVX512VL)
21793 : : ;
21794 : 18183788 : else if (TARGET_AVX2)
21795 : : nops += 2;
21796 : 17699151 : else if (TARGET_XOP)
21797 : 9416 : extra += cost->sse_load[2];
21798 : : else
21799 : : {
21800 : 17689735 : nops += 1;
21801 : 17689735 : extra += cost->sse_load[2];
21802 : : }
21803 : 18286689 : goto do_qimode;
21804 : :
21805 : 9144883 : case V16QImode:
21806 : : /* V*QImode is emulated with 4-11 insns. */
21807 : 9144883 : nmults = 1;
21808 : 9144883 : nops = 3;
21809 : 9144883 : extra = 0;
21810 : :
21811 : 9144883 : if (TARGET_AVX2 && !TARGET_PREFER_AVX128)
21812 : : {
21813 : 292129 : if (!(TARGET_AVX512BW && TARGET_AVX512VL))
21814 : 240905 : nops += 3;
21815 : : }
21816 : 8852754 : else if (TARGET_XOP)
21817 : : {
21818 : 5156 : nmults += 1;
21819 : 5156 : nops += 2;
21820 : 5156 : extra += cost->sse_load[2];
21821 : : }
21822 : : else
21823 : : {
21824 : 8847598 : nmults += 1;
21825 : 8847598 : nops += 4;
21826 : 8847598 : extra += cost->sse_load[2];
21827 : : }
21828 : 9144883 : goto do_qimode;
21829 : :
21830 : 9143328 : case V32QImode:
21831 : 9143328 : nmults = 1;
21832 : 9143328 : nops = 3;
21833 : 9143328 : extra = 0;
21834 : :
21835 : 9143328 : if (!TARGET_AVX512BW || TARGET_PREFER_AVX256)
21836 : : {
21837 : 9065207 : nmults += 1;
21838 : 9065207 : nops += 4;
21839 : 9065207 : extra += cost->sse_load[3] * 2;
21840 : : }
21841 : 9143328 : goto do_qimode;
21842 : :
21843 : 9142600 : case V64QImode:
21844 : 9142600 : nmults = 2;
21845 : 9142600 : nops = 9;
21846 : 9142600 : extra = cost->sse_load[3] * 2 + cost->sse_load[4] * 2;
21847 : :
21848 : 45717500 : do_qimode:
21849 : 45717500 : return ix86_vec_cost (mode, cost->mulss * nmults
21850 : 45717500 : + cost->sse_op * nops) + extra;
21851 : :
21852 : 39098372 : case V4SImode:
21853 : : /* pmulld is used in this case. No emulation is needed. */
21854 : 39098372 : if (TARGET_SSE4_1)
21855 : 2143203 : goto do_native;
21856 : : /* V4SImode is emulated with 7 insns. */
21857 : : else
21858 : 36955169 : return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5);
21859 : :
21860 : 158030630 : case V2DImode:
21861 : 158030630 : case V4DImode:
21862 : : /* vpmullq is used in this case. No emulation is needed. */
21863 : 158030630 : if (TARGET_AVX512DQ && TARGET_AVX512VL)
21864 : 560236 : goto do_native;
21865 : : /* V*DImode is emulated with 6-8 insns. */
21866 : 157470394 : else if (TARGET_XOP && mode == V2DImode)
21867 : 52150 : return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 4);
21868 : : /* FALLTHRU */
21869 : 236378717 : case V8DImode:
21870 : : /* vpmullq is used in this case. No emulation is needed. */
21871 : 236378717 : if (TARGET_AVX512DQ && mode == V8DImode)
21872 : 371714 : goto do_native;
21873 : : else
21874 : 236007003 : return ix86_vec_cost (mode, cost->mulss * 3 + cost->sse_op * 5);
21875 : :
21876 : 881660094 : default:
21877 : 881660094 : do_native:
21878 : 881660094 : return ix86_vec_cost (mode, cost->mulss);
21879 : : }
21880 : : }
21881 : : else
21882 : 106673 : return (cost->mult_init[MODE_INDEX (mode)] + cost->mult_bit * 7);
21883 : : }
21884 : :
21885 : : /* Return cost of multiplication in MODE. */
21886 : :
21887 : : static int
21888 : 71498931 : ix86_division_cost (const struct processor_costs *cost,
21889 : : enum machine_mode mode)
21890 : : {
21891 : 71498931 : machine_mode inner_mode = mode;
21892 : 71498931 : if (VECTOR_MODE_P (mode))
21893 : 53206363 : inner_mode = GET_MODE_INNER (mode);
21894 : :
21895 : 71498931 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
21896 : 249104 : return inner_mode == DFmode ? cost->divsd : cost->divss;
21897 : 71249827 : else if (X87_FLOAT_MODE_P (mode))
21898 : 46700 : return cost->fdiv;
21899 : 71203127 : else if (FLOAT_MODE_P (mode))
21900 : 16805 : return ix86_vec_cost (mode,
21901 : 16805 : inner_mode == DFmode ? cost->divsd : cost->divss);
21902 : : else
21903 : 79207846 : return cost->divide[MODE_INDEX (mode)];
21904 : : }
21905 : :
21906 : : /* Return cost of shift in MODE.
21907 : : If CONSTANT_OP1 is true, the op1 value is known and set in OP1_VAL.
21908 : : AND_IN_OP1 specify in op1 is result of AND and SHIFT_AND_TRUNCATE
21909 : : if op1 is a result of subreg.
21910 : :
21911 : : SKIP_OP0/1 is set to true if cost of OP0/1 should be ignored. */
21912 : :
21913 : : static int
21914 : 759451384 : ix86_shift_rotate_cost (const struct processor_costs *cost,
21915 : : enum rtx_code code,
21916 : : enum machine_mode mode, bool constant_op1,
21917 : : HOST_WIDE_INT op1_val,
21918 : : bool and_in_op1,
21919 : : bool shift_and_truncate,
21920 : : bool *skip_op0, bool *skip_op1)
21921 : : {
21922 : 759451384 : if (skip_op0)
21923 : 759409773 : *skip_op0 = *skip_op1 = false;
21924 : :
21925 : 759451384 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
21926 : : {
21927 : 396241083 : int count;
21928 : : /* Cost of reading the memory. */
21929 : 396241083 : int extra;
21930 : :
21931 : 396241083 : switch (mode)
21932 : : {
21933 : 5817968 : case V4QImode:
21934 : 5817968 : case V8QImode:
21935 : 5817968 : if (TARGET_AVX2)
21936 : : /* Use vpbroadcast. */
21937 : 186768 : extra = cost->sse_op;
21938 : : else
21939 : 5631200 : extra = cost->sse_load[2];
21940 : :
21941 : 5817968 : if (constant_op1)
21942 : : {
21943 : 5817940 : if (code == ASHIFTRT)
21944 : : {
21945 : 20 : count = 4;
21946 : 20 : extra *= 2;
21947 : : }
21948 : : else
21949 : : count = 2;
21950 : : }
21951 : 28 : else if (TARGET_AVX512BW && TARGET_AVX512VL)
21952 : 28 : return ix86_vec_cost (mode, cost->sse_op * 4);
21953 : 0 : else if (TARGET_SSE4_1)
21954 : : count = 5;
21955 : 0 : else if (code == ASHIFTRT)
21956 : : count = 6;
21957 : : else
21958 : 0 : count = 5;
21959 : 5817940 : return ix86_vec_cost (mode, cost->sse_op * count) + extra;
21960 : :
21961 : 2911199 : case V16QImode:
21962 : 2911199 : if (TARGET_XOP)
21963 : : {
21964 : : /* For XOP we use vpshab, which requires a broadcast of the
21965 : : value to the variable shift insn. For constants this
21966 : : means a V16Q const in mem; even when we can perform the
21967 : : shift with one insn set the cost to prefer paddb. */
21968 : 4620 : if (constant_op1)
21969 : : {
21970 : 3688 : extra = cost->sse_load[2];
21971 : 3688 : return ix86_vec_cost (mode, cost->sse_op) + extra;
21972 : : }
21973 : : else
21974 : : {
21975 : 932 : count = (code == ASHIFT) ? 3 : 4;
21976 : 932 : return ix86_vec_cost (mode, cost->sse_op * count);
21977 : : }
21978 : : }
21979 : : /* FALLTHRU */
21980 : 5815569 : case V32QImode:
21981 : 5815569 : if (TARGET_AVX2)
21982 : : /* Use vpbroadcast. */
21983 : 184978 : extra = cost->sse_op;
21984 : : else
21985 : 5630591 : extra = (mode == V16QImode) ? cost->sse_load[2] : cost->sse_load[3];
21986 : :
21987 : 5815569 : if (constant_op1)
21988 : : {
21989 : 5815466 : if (code == ASHIFTRT)
21990 : : {
21991 : 110 : count = 4;
21992 : 110 : extra *= 2;
21993 : : }
21994 : : else
21995 : : count = 2;
21996 : : }
21997 : 103 : else if (TARGET_AVX512BW
21998 : 75 : && ((mode == V32QImode && !TARGET_PREFER_AVX256)
21999 : 37 : || (mode == V16QImode && TARGET_AVX512VL
22000 : 37 : && !TARGET_PREFER_AVX128)))
22001 : 75 : return ix86_vec_cost (mode, cost->sse_op * 4);
22002 : 28 : else if (TARGET_AVX2
22003 : 0 : && mode == V16QImode && !TARGET_PREFER_AVX128)
22004 : : count = 6;
22005 : 28 : else if (TARGET_SSE4_1)
22006 : : count = 9;
22007 : 28 : else if (code == ASHIFTRT)
22008 : : count = 10;
22009 : : else
22010 : 28 : count = 9;
22011 : 5815494 : return ix86_vec_cost (mode, cost->sse_op * count) + extra;
22012 : :
22013 : 52445907 : case V2DImode:
22014 : 52445907 : case V4DImode:
22015 : : /* V*DImode arithmetic right shift is emulated. */
22016 : 52445907 : if (code == ASHIFTRT && !TARGET_AVX512VL)
22017 : : {
22018 : 1189 : if (constant_op1)
22019 : : {
22020 : 498 : if (op1_val == 63)
22021 : 103 : count = TARGET_SSE4_2 ? 1 : 2;
22022 : 395 : else if (TARGET_XOP)
22023 : : count = 2;
22024 : 96 : else if (TARGET_SSE4_1)
22025 : : count = 3;
22026 : : else
22027 : 93 : count = 4;
22028 : : }
22029 : 691 : else if (TARGET_XOP)
22030 : : count = 3;
22031 : 10 : else if (TARGET_SSE4_2)
22032 : : count = 4;
22033 : : else
22034 : 1189 : count = 5;
22035 : :
22036 : 1189 : return ix86_vec_cost (mode, cost->sse_op * count);
22037 : : }
22038 : : /* FALLTHRU */
22039 : 384601737 : default:
22040 : 384601737 : return ix86_vec_cost (mode, cost->sse_op);
22041 : : }
22042 : : }
22043 : :
22044 : 735077236 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22045 : : {
22046 : 185751067 : if (constant_op1)
22047 : : {
22048 : 185716306 : if (op1_val > 32)
22049 : 131925856 : return cost->shift_const + COSTS_N_INSNS (2);
22050 : : else
22051 : 53790450 : return cost->shift_const * 2;
22052 : : }
22053 : : else
22054 : : {
22055 : 34761 : if (and_in_op1)
22056 : 63 : return cost->shift_var * 2;
22057 : : else
22058 : 34698 : return cost->shift_var * 6 + COSTS_N_INSNS (2);
22059 : : }
22060 : : }
22061 : : else
22062 : : {
22063 : 177459234 : if (constant_op1)
22064 : 176728971 : return cost->shift_const;
22065 : 730263 : else if (shift_and_truncate)
22066 : : {
22067 : 22622 : if (skip_op0)
22068 : 22622 : *skip_op0 = *skip_op1 = true;
22069 : : /* Return the cost after shift-and truncation. */
22070 : 22622 : return cost->shift_var;
22071 : : }
22072 : : else
22073 : 707641 : return cost->shift_var;
22074 : : }
22075 : : }
22076 : :
22077 : : static int
22078 : 143684537 : ix86_insn_cost (rtx_insn *insn, bool speed)
22079 : : {
22080 : 143684537 : int insn_cost = 0;
22081 : : /* Add extra cost to avoid post_reload late_combine revert
22082 : : the optimization did in pass_rpad. */
22083 : 143684537 : if (reload_completed
22084 : 4371257 : && ix86_rpad_gate ()
22085 : 266759 : && recog_memoized (insn) >= 0
22086 : 143951147 : && get_attr_avx_partial_xmm_update (insn)
22087 : : == AVX_PARTIAL_XMM_UPDATE_TRUE)
22088 : : insn_cost += COSTS_N_INSNS (3);
22089 : :
22090 : 143684537 : return insn_cost + pattern_cost (PATTERN (insn), speed);
22091 : : }
22092 : :
22093 : : /* Return cost of SSE/AVX FP->FP conversion (extensions and truncates). */
22094 : :
22095 : : static int
22096 : 735667 : vec_fp_conversion_cost (const struct processor_costs *cost, int size)
22097 : : {
22098 : 735667 : if (size < 128)
22099 : 732444 : return cost->cvtss2sd;
22100 : 3223 : else if (size < 256)
22101 : : {
22102 : 1436 : if (TARGET_SSE_SPLIT_REGS)
22103 : 0 : return cost->cvtss2sd * size / 64;
22104 : 1436 : return cost->cvtss2sd;
22105 : : }
22106 : 1787 : if (size < 512)
22107 : 653 : return cost->vcvtps2pd256;
22108 : : else
22109 : 1134 : return cost->vcvtps2pd512;
22110 : : }
22111 : :
22112 : : /* Return true of X is UNSPEC with UNSPEC_PCMP or UNSPEC_UNSIGNED_PCMP. */
22113 : :
22114 : : static bool
22115 : 176021 : unspec_pcmp_p (rtx x)
22116 : : {
22117 : 176021 : return GET_CODE (x) == UNSPEC
22118 : 176021 : && (XINT (x, 1) == UNSPEC_PCMP || XINT (x, 1) == UNSPEC_UNSIGNED_PCMP);
22119 : : }
22120 : :
22121 : : /* Compute a (partial) cost for rtx X. Return true if the complete
22122 : : cost has been computed, and false if subexpressions should be
22123 : : scanned. In either case, *TOTAL contains the cost result. */
22124 : :
22125 : : static bool
22126 : 7564423911 : ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno,
22127 : : int *total, bool speed)
22128 : : {
22129 : 7564423911 : rtx mask;
22130 : 7564423911 : enum rtx_code code = GET_CODE (x);
22131 : 7564423911 : enum rtx_code outer_code = (enum rtx_code) outer_code_i;
22132 : 15128847822 : const struct processor_costs *cost
22133 : 7564423911 : = speed ? ix86_tune_cost : &ix86_size_cost;
22134 : 7564423911 : int src_cost;
22135 : :
22136 : : /* Handling different vternlog variants. */
22137 : 7564423911 : if ((GET_MODE_SIZE (mode) == 64
22138 : 28390829 : ? (TARGET_AVX512F && TARGET_EVEX512)
22139 : 6424736673 : : (TARGET_AVX512VL
22140 : 6364995485 : || (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)))
22141 : 173775450 : && GET_MODE_SIZE (mode) >= 16
22142 : 119426478 : && outer_code_i == SET
22143 : 7610439077 : && ternlog_operand (x, mode))
22144 : : {
22145 : 32699 : rtx args[3];
22146 : :
22147 : 32699 : args[0] = NULL_RTX;
22148 : 32699 : args[1] = NULL_RTX;
22149 : 32699 : args[2] = NULL_RTX;
22150 : 32699 : int idx = ix86_ternlog_idx (x, args);
22151 : 32699 : gcc_assert (idx >= 0);
22152 : :
22153 : 32699 : *total = cost->sse_op;
22154 : 130796 : for (int i = 0; i != 3; i++)
22155 : 98097 : if (args[i])
22156 : 69615 : *total += rtx_cost (args[i], GET_MODE (args[i]), UNSPEC, i, speed);
22157 : 32699 : return true;
22158 : : }
22159 : :
22160 : :
22161 : 7564391212 : switch (code)
22162 : : {
22163 : 48791575 : case SET:
22164 : 48791575 : if (register_operand (SET_DEST (x), VOIDmode)
22165 : 48791575 : && register_operand (SET_SRC (x), VOIDmode))
22166 : : {
22167 : 30727586 : *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
22168 : 30727586 : return true;
22169 : : }
22170 : :
22171 : 18063989 : if (register_operand (SET_SRC (x), VOIDmode))
22172 : : /* Avoid potentially incorrect high cost from rtx_costs
22173 : : for non-tieable SUBREGs. */
22174 : : src_cost = 0;
22175 : : else
22176 : : {
22177 : 15650512 : src_cost = rtx_cost (SET_SRC (x), mode, SET, 1, speed);
22178 : :
22179 : 15650512 : if (CONSTANT_P (SET_SRC (x)))
22180 : : /* Constant costs assume a base value of COSTS_N_INSNS (1) and add
22181 : : a small value, possibly zero for cheap constants. */
22182 : 6970021 : src_cost += COSTS_N_INSNS (1);
22183 : : }
22184 : :
22185 : 18063989 : *total = src_cost + rtx_cost (SET_DEST (x), mode, SET, 0, speed);
22186 : 18063989 : return true;
22187 : :
22188 : 2785502560 : case CONST_INT:
22189 : 2785502560 : case CONST:
22190 : 2785502560 : case LABEL_REF:
22191 : 2785502560 : case SYMBOL_REF:
22192 : 2785502560 : if (x86_64_immediate_operand (x, VOIDmode))
22193 : 2202530073 : *total = 0;
22194 : 582972487 : else if (TARGET_64BIT && x86_64_zext_immediate_operand (x, VOIDmode))
22195 : : /* Consider the zext constants slightly more expensive, as they
22196 : : can't appear in most instructions. */
22197 : 28187474 : *total = 1;
22198 : : else
22199 : : /* movabsq is slightly more expensive than a simple instruction. */
22200 : 554785013 : *total = COSTS_N_INSNS (1) + 1;
22201 : : return true;
22202 : :
22203 : 7530588 : case CONST_DOUBLE:
22204 : 7530588 : if (IS_STACK_MODE (mode))
22205 : 1319165 : switch (standard_80387_constant_p (x))
22206 : : {
22207 : : case -1:
22208 : : case 0:
22209 : : break;
22210 : 284248 : case 1: /* 0.0 */
22211 : 284248 : *total = 1;
22212 : 284248 : return true;
22213 : 486222 : default: /* Other constants */
22214 : 486222 : *total = 2;
22215 : 486222 : return true;
22216 : : }
22217 : : /* FALLTHRU */
22218 : :
22219 : 13742640 : case CONST_VECTOR:
22220 : 13742640 : switch (standard_sse_constant_p (x, mode))
22221 : : {
22222 : : case 0:
22223 : : break;
22224 : 3751505 : case 1: /* 0: xor eliminates false dependency */
22225 : 3751505 : *total = 0;
22226 : 3751505 : return true;
22227 : 154482 : default: /* -1: cmp contains false dependency */
22228 : 154482 : *total = 1;
22229 : 154482 : return true;
22230 : : }
22231 : : /* FALLTHRU */
22232 : :
22233 : 10862425 : case CONST_WIDE_INT:
22234 : : /* Fall back to (MEM (SYMBOL_REF)), since that's where
22235 : : it'll probably end up. Add a penalty for size. */
22236 : 21724850 : *total = (COSTS_N_INSNS (1)
22237 : 21499344 : + (!TARGET_64BIT && flag_pic)
22238 : 21724850 : + (GET_MODE_SIZE (mode) <= 4
22239 : 18969619 : ? 0 : GET_MODE_SIZE (mode) <= 8 ? 1 : 2));
22240 : 10862425 : return true;
22241 : :
22242 : 21173375 : case ZERO_EXTEND:
22243 : : /* The zero extensions is often completely free on x86_64, so make
22244 : : it as cheap as possible. */
22245 : 21173375 : if (TARGET_64BIT && mode == DImode
22246 : 4096515 : && GET_MODE (XEXP (x, 0)) == SImode)
22247 : 2214007 : *total = 1;
22248 : 18959368 : else if (TARGET_ZERO_EXTEND_WITH_AND)
22249 : 0 : *total = cost->add;
22250 : : else
22251 : 18959368 : *total = cost->movzx;
22252 : : return false;
22253 : :
22254 : 3280988 : case SIGN_EXTEND:
22255 : 3280988 : *total = cost->movsx;
22256 : 3280988 : return false;
22257 : :
22258 : 626955040 : case ASHIFT:
22259 : 626955040 : if (SCALAR_INT_MODE_P (mode)
22260 : 237615020 : && GET_MODE_SIZE (mode) < UNITS_PER_WORD
22261 : 668458440 : && CONST_INT_P (XEXP (x, 1)))
22262 : : {
22263 : 41341001 : HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
22264 : 41341001 : if (value == 1)
22265 : : {
22266 : 2392730 : *total = cost->add;
22267 : 2392730 : return false;
22268 : : }
22269 : 38948271 : if ((value == 2 || value == 3)
22270 : 4351771 : && cost->lea <= cost->shift_const)
22271 : : {
22272 : 2066137 : *total = cost->lea;
22273 : 2066137 : return false;
22274 : : }
22275 : : }
22276 : : /* FALLTHRU */
22277 : :
22278 : 759409773 : case ROTATE:
22279 : 759409773 : case ASHIFTRT:
22280 : 759409773 : case LSHIFTRT:
22281 : 759409773 : case ROTATERT:
22282 : 759409773 : bool skip_op0, skip_op1;
22283 : 759409773 : *total = ix86_shift_rotate_cost (cost, code, mode,
22284 : 759409773 : CONSTANT_P (XEXP (x, 1)),
22285 : : CONST_INT_P (XEXP (x, 1))
22286 : : ? INTVAL (XEXP (x, 1)) : -1,
22287 : : GET_CODE (XEXP (x, 1)) == AND,
22288 : 759409773 : SUBREG_P (XEXP (x, 1))
22289 : 759409773 : && GET_CODE (XEXP (XEXP (x, 1),
22290 : : 0)) == AND,
22291 : : &skip_op0, &skip_op1);
22292 : 759409773 : if (skip_op0 || skip_op1)
22293 : : {
22294 : 22622 : if (!skip_op0)
22295 : 0 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
22296 : 22622 : if (!skip_op1)
22297 : 0 : *total += rtx_cost (XEXP (x, 1), mode, code, 0, speed);
22298 : 22622 : return true;
22299 : : }
22300 : : return false;
22301 : :
22302 : 219064 : case FMA:
22303 : 219064 : {
22304 : 219064 : rtx sub;
22305 : :
22306 : 219064 : gcc_assert (FLOAT_MODE_P (mode));
22307 : 219064 : gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F);
22308 : :
22309 : 438128 : *total = ix86_vec_cost (mode,
22310 : 219064 : GET_MODE_INNER (mode) == SFmode
22311 : : ? cost->fmass : cost->fmasd);
22312 : 219064 : *total += rtx_cost (XEXP (x, 1), mode, FMA, 1, speed);
22313 : :
22314 : : /* Negate in op0 or op2 is free: FMS, FNMA, FNMS. */
22315 : 219064 : sub = XEXP (x, 0);
22316 : 219064 : if (GET_CODE (sub) == NEG)
22317 : 53224 : sub = XEXP (sub, 0);
22318 : 219064 : *total += rtx_cost (sub, mode, FMA, 0, speed);
22319 : :
22320 : 219064 : sub = XEXP (x, 2);
22321 : 219064 : if (GET_CODE (sub) == NEG)
22322 : 40050 : sub = XEXP (sub, 0);
22323 : 219064 : *total += rtx_cost (sub, mode, FMA, 2, speed);
22324 : 219064 : return true;
22325 : : }
22326 : :
22327 : 1732233423 : case MULT:
22328 : 1732233423 : if (!FLOAT_MODE_P (mode) && !VECTOR_MODE_P (mode))
22329 : : {
22330 : 530870900 : rtx op0 = XEXP (x, 0);
22331 : 530870900 : rtx op1 = XEXP (x, 1);
22332 : 530870900 : int nbits;
22333 : 530870900 : if (CONST_INT_P (XEXP (x, 1)))
22334 : : {
22335 : 513586890 : unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
22336 : 1044579781 : for (nbits = 0; value != 0; value &= value - 1)
22337 : 530992891 : nbits++;
22338 : : }
22339 : : else
22340 : : /* This is arbitrary. */
22341 : : nbits = 7;
22342 : :
22343 : : /* Compute costs correctly for widening multiplication. */
22344 : 530870900 : if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
22345 : 536193441 : && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
22346 : 5322541 : == GET_MODE_SIZE (mode))
22347 : : {
22348 : 5318448 : int is_mulwiden = 0;
22349 : 5318448 : machine_mode inner_mode = GET_MODE (op0);
22350 : :
22351 : 5318448 : if (GET_CODE (op0) == GET_CODE (op1))
22352 : 5232680 : is_mulwiden = 1, op1 = XEXP (op1, 0);
22353 : 85768 : else if (CONST_INT_P (op1))
22354 : : {
22355 : 75646 : if (GET_CODE (op0) == SIGN_EXTEND)
22356 : 23181 : is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
22357 : 23181 : == INTVAL (op1);
22358 : : else
22359 : 52465 : is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
22360 : : }
22361 : :
22362 : 5308326 : if (is_mulwiden)
22363 : 5308326 : op0 = XEXP (op0, 0), mode = GET_MODE (op0);
22364 : : }
22365 : :
22366 : 530870900 : int mult_init;
22367 : : // Double word multiplication requires 3 mults and 2 adds.
22368 : 1077198056 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22369 : : {
22370 : 319661265 : mult_init = 3 * cost->mult_init[MODE_INDEX (word_mode)]
22371 : 319661265 : + 2 * cost->add;
22372 : 319661265 : nbits *= 3;
22373 : : }
22374 : 364241430 : else mult_init = cost->mult_init[MODE_INDEX (mode)];
22375 : :
22376 : 1061741800 : *total = (mult_init
22377 : 530870900 : + nbits * cost->mult_bit
22378 : 530870900 : + rtx_cost (op0, mode, outer_code, opno, speed)
22379 : 530870900 : + rtx_cost (op1, mode, outer_code, opno, speed));
22380 : :
22381 : 530870900 : return true;
22382 : : }
22383 : 1201362523 : *total = ix86_multiplication_cost (cost, mode);
22384 : 1201362523 : return false;
22385 : :
22386 : 71489858 : case DIV:
22387 : 71489858 : case UDIV:
22388 : 71489858 : case MOD:
22389 : 71489858 : case UMOD:
22390 : 71489858 : *total = ix86_division_cost (cost, mode);
22391 : 71489858 : return false;
22392 : :
22393 : 676196177 : case PLUS:
22394 : 676196177 : if (GET_MODE_CLASS (mode) == MODE_INT
22395 : 922568953 : && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
22396 : : {
22397 : 136311145 : if (GET_CODE (XEXP (x, 0)) == PLUS
22398 : 2723712 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
22399 : 832142 : && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
22400 : 832133 : && CONSTANT_P (XEXP (x, 1)))
22401 : : {
22402 : 832092 : HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
22403 : 832092 : if (val == 2 || val == 4 || val == 8)
22404 : : {
22405 : 831988 : *total = cost->lea;
22406 : 831988 : *total += rtx_cost (XEXP (XEXP (x, 0), 1), mode,
22407 : : outer_code, opno, speed);
22408 : 831988 : *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), mode,
22409 : : outer_code, opno, speed);
22410 : 831988 : *total += rtx_cost (XEXP (x, 1), mode,
22411 : : outer_code, opno, speed);
22412 : 831988 : return true;
22413 : : }
22414 : : }
22415 : 135479053 : else if (GET_CODE (XEXP (x, 0)) == MULT
22416 : 50449822 : && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
22417 : : {
22418 : 50395985 : HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
22419 : 50395985 : if (val == 2 || val == 4 || val == 8)
22420 : : {
22421 : 7724235 : *total = cost->lea;
22422 : 7724235 : *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22423 : : outer_code, opno, speed);
22424 : 7724235 : *total += rtx_cost (XEXP (x, 1), mode,
22425 : : outer_code, opno, speed);
22426 : 7724235 : return true;
22427 : : }
22428 : : }
22429 : 85083068 : else if (GET_CODE (XEXP (x, 0)) == PLUS)
22430 : : {
22431 : 1891620 : rtx op = XEXP (XEXP (x, 0), 0);
22432 : :
22433 : : /* Add with carry, ignore the cost of adding a carry flag. */
22434 : 1891620 : if (ix86_carry_flag_operator (op, mode)
22435 : 1891620 : || ix86_carry_flag_unset_operator (op, mode))
22436 : 76970 : *total = cost->add;
22437 : : else
22438 : : {
22439 : 1814650 : *total = cost->lea;
22440 : 1814650 : *total += rtx_cost (op, mode,
22441 : : outer_code, opno, speed);
22442 : : }
22443 : :
22444 : 1891620 : *total += rtx_cost (XEXP (XEXP (x, 0), 1), mode,
22445 : : outer_code, opno, speed);
22446 : 1891620 : *total += rtx_cost (XEXP (x, 1), mode,
22447 : : outer_code, opno, speed);
22448 : 1891620 : return true;
22449 : : }
22450 : : }
22451 : : /* FALLTHRU */
22452 : :
22453 : 1807228554 : case MINUS:
22454 : : /* Subtract with borrow, ignore the cost of subtracting a carry flag. */
22455 : 1807228554 : if (GET_MODE_CLASS (mode) == MODE_INT
22456 : 501328036 : && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
22457 : 226227845 : && GET_CODE (XEXP (x, 0)) == MINUS
22458 : 1807270836 : && (ix86_carry_flag_operator (XEXP (XEXP (x, 0), 1), mode)
22459 : 13335 : || ix86_carry_flag_unset_operator (XEXP (XEXP (x, 0), 1), mode)))
22460 : : {
22461 : 28947 : *total = cost->add;
22462 : 28947 : *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22463 : : outer_code, opno, speed);
22464 : 28947 : *total += rtx_cost (XEXP (x, 1), mode,
22465 : : outer_code, opno, speed);
22466 : 28947 : return true;
22467 : : }
22468 : :
22469 : 1807199607 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22470 : 2411311 : *total = cost->addss;
22471 : 1804788296 : else if (X87_FLOAT_MODE_P (mode))
22472 : 219172 : *total = cost->fadd;
22473 : 1804569124 : else if (FLOAT_MODE_P (mode))
22474 : 394041 : *total = ix86_vec_cost (mode, cost->addss);
22475 : 1804175083 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22476 : 1200985836 : *total = ix86_vec_cost (mode, cost->sse_op);
22477 : 1245317134 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22478 : 318812509 : *total = cost->add * 2;
22479 : : else
22480 : 284376738 : *total = cost->add;
22481 : : return false;
22482 : :
22483 : 4448703 : case IOR:
22484 : 4448703 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
22485 : 4211063 : || SSE_FLOAT_MODE_P (mode))
22486 : : {
22487 : : /* (ior (not ...) ...) can be a single insn in AVX512. */
22488 : 0 : if (GET_CODE (XEXP (x, 0)) == NOT && TARGET_AVX512F
22489 : 247414 : && ((TARGET_EVEX512
22490 : 0 : && GET_MODE_SIZE (mode) == 64)
22491 : 0 : || (TARGET_AVX512VL
22492 : 0 : && (GET_MODE_SIZE (mode) == 32
22493 : 0 : || GET_MODE_SIZE (mode) == 16))))
22494 : : {
22495 : 0 : rtx right = GET_CODE (XEXP (x, 1)) != NOT
22496 : 0 : ? XEXP (x, 1) : XEXP (XEXP (x, 1), 0);
22497 : :
22498 : 0 : *total = ix86_vec_cost (mode, cost->sse_op)
22499 : 0 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22500 : : outer_code, opno, speed)
22501 : 0 : + rtx_cost (right, mode, outer_code, opno, speed);
22502 : 0 : return true;
22503 : : }
22504 : 247414 : *total = ix86_vec_cost (mode, cost->sse_op);
22505 : 247414 : }
22506 : 4201289 : else if (TARGET_64BIT
22507 : 3907133 : && mode == TImode
22508 : 1897389 : && GET_CODE (XEXP (x, 0)) == ASHIFT
22509 : 285254 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND
22510 : 283268 : && GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == DImode
22511 : 283267 : && CONST_INT_P (XEXP (XEXP (x, 0), 1))
22512 : 283267 : && INTVAL (XEXP (XEXP (x, 0), 1)) == 64
22513 : 283267 : && GET_CODE (XEXP (x, 1)) == ZERO_EXTEND
22514 : 250432 : && GET_MODE (XEXP (XEXP (x, 1), 0)) == DImode)
22515 : : {
22516 : : /* *concatditi3 is cheap. */
22517 : 250432 : rtx op0 = XEXP (XEXP (XEXP (x, 0), 0), 0);
22518 : 250432 : rtx op1 = XEXP (XEXP (x, 1), 0);
22519 : 1344 : *total = (SUBREG_P (op0) && GET_MODE (SUBREG_REG (op0)) == DFmode)
22520 : 250432 : ? COSTS_N_INSNS (1) /* movq. */
22521 : 249088 : : set_src_cost (op0, DImode, speed);
22522 : 2252 : *total += (SUBREG_P (op1) && GET_MODE (SUBREG_REG (op1)) == DFmode)
22523 : 250432 : ? COSTS_N_INSNS (1) /* movq. */
22524 : 248193 : : set_src_cost (op1, DImode, speed);
22525 : 250432 : return true;
22526 : : }
22527 : 3950857 : else if (TARGET_64BIT
22528 : 3656701 : && mode == TImode
22529 : 1646957 : && GET_CODE (XEXP (x, 0)) == AND
22530 : 1591107 : && REG_P (XEXP (XEXP (x, 0), 0))
22531 : 1585445 : && CONST_WIDE_INT_P (XEXP (XEXP (x, 0), 1))
22532 : 1585445 : && CONST_WIDE_INT_NUNITS (XEXP (XEXP (x, 0), 1)) == 2
22533 : 1585445 : && CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 0) == -1
22534 : 1058792 : && CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 1) == 0
22535 : 1058792 : && GET_CODE (XEXP (x, 1)) == ASHIFT
22536 : 1057063 : && GET_CODE (XEXP (XEXP (x, 1), 0)) == ZERO_EXTEND
22537 : 1057063 : && GET_MODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == DImode
22538 : 1057055 : && CONST_INT_P (XEXP (XEXP (x, 1), 1))
22539 : 5007912 : && INTVAL (XEXP (XEXP (x, 1), 1)) == 64)
22540 : : {
22541 : : /* *insvti_highpart is cheap. */
22542 : 1057055 : rtx op = XEXP (XEXP (XEXP (x, 1), 0), 0);
22543 : 1057055 : *total = COSTS_N_INSNS (1) + 1;
22544 : 1266 : *total += (SUBREG_P (op) && GET_MODE (SUBREG_REG (op)) == DFmode)
22545 : 1057055 : ? COSTS_N_INSNS (1) /* movq. */
22546 : 1056224 : : set_src_cost (op, DImode, speed);
22547 : 1057055 : return true;
22548 : : }
22549 : 6081760 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22550 : 913720 : *total = cost->add * 2;
22551 : : else
22552 : 1980082 : *total = cost->add;
22553 : : return false;
22554 : :
22555 : 524302 : case XOR:
22556 : 524302 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
22557 : 445884 : || SSE_FLOAT_MODE_P (mode))
22558 : 78418 : *total = ix86_vec_cost (mode, cost->sse_op);
22559 : 955207 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22560 : 16367 : *total = cost->add * 2;
22561 : : else
22562 : 429517 : *total = cost->add;
22563 : : return false;
22564 : :
22565 : 7093744 : case AND:
22566 : 7093744 : if (address_no_seg_operand (x, mode))
22567 : : {
22568 : 10030 : *total = cost->lea;
22569 : 10030 : return true;
22570 : : }
22571 : 7083714 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
22572 : 6733650 : || SSE_FLOAT_MODE_P (mode))
22573 : : {
22574 : : /* pandn is a single instruction. */
22575 : 384204 : if (GET_CODE (XEXP (x, 0)) == NOT)
22576 : : {
22577 : 48075 : rtx right = XEXP (x, 1);
22578 : :
22579 : : /* (and (not ...) (not ...)) can be a single insn in AVX512. */
22580 : 372 : if (GET_CODE (right) == NOT && TARGET_AVX512F
22581 : 48075 : && ((TARGET_EVEX512
22582 : 0 : && GET_MODE_SIZE (mode) == 64)
22583 : 0 : || (TARGET_AVX512VL
22584 : 0 : && (GET_MODE_SIZE (mode) == 32
22585 : 0 : || GET_MODE_SIZE (mode) == 16))))
22586 : 0 : right = XEXP (right, 0);
22587 : :
22588 : 48075 : *total = ix86_vec_cost (mode, cost->sse_op)
22589 : 48075 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22590 : : outer_code, opno, speed)
22591 : 48075 : + rtx_cost (right, mode, outer_code, opno, speed);
22592 : 48075 : return true;
22593 : : }
22594 : 336129 : else if (GET_CODE (XEXP (x, 1)) == NOT)
22595 : : {
22596 : 746 : *total = ix86_vec_cost (mode, cost->sse_op)
22597 : 746 : + rtx_cost (XEXP (x, 0), mode,
22598 : : outer_code, opno, speed)
22599 : 746 : + rtx_cost (XEXP (XEXP (x, 1), 0), mode,
22600 : : outer_code, opno, speed);
22601 : 746 : return true;
22602 : : }
22603 : 335383 : *total = ix86_vec_cost (mode, cost->sse_op);
22604 : 335383 : }
22605 : 14084265 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22606 : : {
22607 : 1047737 : if (TARGET_BMI && GET_CODE (XEXP (x,0)) == NOT)
22608 : : {
22609 : 1556 : *total = cost->add * 2
22610 : 778 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22611 : : outer_code, opno, speed)
22612 : 778 : + rtx_cost (XEXP (x, 1), mode,
22613 : : outer_code, opno, speed);
22614 : 778 : return true;
22615 : : }
22616 : 1046959 : else if (TARGET_BMI && GET_CODE (XEXP (x, 1)) == NOT)
22617 : : {
22618 : 0 : *total = cost->add * 2
22619 : 0 : + rtx_cost (XEXP (x, 0), mode,
22620 : : outer_code, opno, speed)
22621 : 0 : + rtx_cost (XEXP (XEXP (x, 1), 0), mode,
22622 : : outer_code, opno, speed);
22623 : 0 : return true;
22624 : : }
22625 : 1046959 : *total = cost->add * 2;
22626 : : }
22627 : 5651773 : else if (TARGET_BMI && GET_CODE (XEXP (x,0)) == NOT)
22628 : : {
22629 : 746 : *total = cost->add
22630 : 373 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22631 : : outer_code, opno, speed)
22632 : 373 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
22633 : 373 : return true;
22634 : : }
22635 : 5651400 : else if (TARGET_BMI && GET_CODE (XEXP (x,1)) == NOT)
22636 : : {
22637 : 112 : *total = cost->add
22638 : 56 : + rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
22639 : 56 : + rtx_cost (XEXP (XEXP (x, 1), 0), mode,
22640 : : outer_code, opno, speed);
22641 : 56 : return true;
22642 : : }
22643 : : else
22644 : 5651344 : *total = cost->add;
22645 : : return false;
22646 : :
22647 : 514813 : case NOT:
22648 : 514813 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22649 : : {
22650 : : /* (not (xor ...)) can be a single insn in AVX512. */
22651 : 0 : if (GET_CODE (XEXP (x, 0)) == XOR && TARGET_AVX512F
22652 : 5643 : && ((TARGET_EVEX512
22653 : 0 : && GET_MODE_SIZE (mode) == 64)
22654 : 0 : || (TARGET_AVX512VL
22655 : 0 : && (GET_MODE_SIZE (mode) == 32
22656 : 0 : || GET_MODE_SIZE (mode) == 16))))
22657 : : {
22658 : 0 : *total = ix86_vec_cost (mode, cost->sse_op)
22659 : 0 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22660 : : outer_code, opno, speed)
22661 : 0 : + rtx_cost (XEXP (XEXP (x, 0), 1), mode,
22662 : : outer_code, opno, speed);
22663 : 0 : return true;
22664 : : }
22665 : :
22666 : : // vnot is pxor -1.
22667 : 5643 : *total = ix86_vec_cost (mode, cost->sse_op) + 1;
22668 : : }
22669 : 1164305 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22670 : 66703 : *total = cost->add * 2;
22671 : : else
22672 : 442467 : *total = cost->add;
22673 : : return false;
22674 : :
22675 : 17920427 : case NEG:
22676 : 17920427 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22677 : 52535 : *total = cost->sse_op;
22678 : 17867892 : else if (X87_FLOAT_MODE_P (mode))
22679 : 15198 : *total = cost->fchs;
22680 : 17852694 : else if (FLOAT_MODE_P (mode))
22681 : 26488 : *total = ix86_vec_cost (mode, cost->sse_op);
22682 : 17826206 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22683 : 13309492 : *total = ix86_vec_cost (mode, cost->sse_op);
22684 : 9178795 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22685 : 1697909 : *total = cost->add * 3;
22686 : : else
22687 : 2818805 : *total = cost->add;
22688 : : return false;
22689 : :
22690 : 53110954 : case COMPARE:
22691 : 53110954 : rtx op0, op1;
22692 : 53110954 : op0 = XEXP (x, 0);
22693 : 53110954 : op1 = XEXP (x, 1);
22694 : 53110954 : if (GET_CODE (op0) == ZERO_EXTRACT
22695 : 172904 : && XEXP (op0, 1) == const1_rtx
22696 : 145668 : && CONST_INT_P (XEXP (op0, 2))
22697 : 145566 : && op1 == const0_rtx)
22698 : : {
22699 : : /* This kind of construct is implemented using test[bwl].
22700 : : Treat it as if we had an AND. */
22701 : 145566 : mode = GET_MODE (XEXP (op0, 0));
22702 : 291132 : *total = (cost->add
22703 : 145566 : + rtx_cost (XEXP (op0, 0), mode, outer_code,
22704 : : opno, speed)
22705 : 145566 : + rtx_cost (const1_rtx, mode, outer_code, opno, speed));
22706 : 145566 : return true;
22707 : : }
22708 : :
22709 : 52965388 : if (GET_CODE (op0) == PLUS && rtx_equal_p (XEXP (op0, 0), op1))
22710 : : {
22711 : : /* This is an overflow detection, count it as a normal compare. */
22712 : 138809 : *total = rtx_cost (op0, GET_MODE (op0), COMPARE, 0, speed);
22713 : 138809 : return true;
22714 : : }
22715 : :
22716 : 52826579 : rtx geu;
22717 : : /* Match x
22718 : : (compare:CCC (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))
22719 : : (ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))) */
22720 : 52826579 : if (mode == CCCmode
22721 : 388039 : && GET_CODE (op0) == NEG
22722 : 7946 : && GET_CODE (geu = XEXP (op0, 0)) == GEU
22723 : 7943 : && REG_P (XEXP (geu, 0))
22724 : 7943 : && (GET_MODE (XEXP (geu, 0)) == CCCmode
22725 : 751 : || GET_MODE (XEXP (geu, 0)) == CCmode)
22726 : 7943 : && REGNO (XEXP (geu, 0)) == FLAGS_REG
22727 : 7943 : && XEXP (geu, 1) == const0_rtx
22728 : 7943 : && GET_CODE (op1) == LTU
22729 : 7943 : && REG_P (XEXP (op1, 0))
22730 : 7943 : && GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0))
22731 : 7943 : && REGNO (XEXP (op1, 0)) == FLAGS_REG
22732 : 52834522 : && XEXP (op1, 1) == const0_rtx)
22733 : : {
22734 : : /* This is *setcc_qi_addqi3_cconly_overflow_1_* patterns, a nop. */
22735 : 7943 : *total = 0;
22736 : 7943 : return true;
22737 : : }
22738 : : /* Match x
22739 : : (compare:CCC (neg:QI (ltu:QI (reg:CCC FLAGS_REG) (const_int 0)))
22740 : : (geu:QI (reg:CCC FLAGS_REG) (const_int 0))) */
22741 : 52818636 : if (mode == CCCmode
22742 : 380096 : && GET_CODE (op0) == NEG
22743 : 3 : && GET_CODE (XEXP (op0, 0)) == LTU
22744 : 3 : && REG_P (XEXP (XEXP (op0, 0), 0))
22745 : 3 : && GET_MODE (XEXP (XEXP (op0, 0), 0)) == CCCmode
22746 : 3 : && REGNO (XEXP (XEXP (op0, 0), 0)) == FLAGS_REG
22747 : 3 : && XEXP (XEXP (op0, 0), 1) == const0_rtx
22748 : 3 : && GET_CODE (op1) == GEU
22749 : 3 : && REG_P (XEXP (op1, 0))
22750 : 3 : && GET_MODE (XEXP (op1, 0)) == CCCmode
22751 : 3 : && REGNO (XEXP (op1, 0)) == FLAGS_REG
22752 : 52818639 : && XEXP (op1, 1) == const0_rtx)
22753 : : {
22754 : : /* This is *x86_cmc. */
22755 : 3 : if (!speed)
22756 : 0 : *total = COSTS_N_BYTES (1);
22757 : 3 : else if (TARGET_SLOW_STC)
22758 : 0 : *total = COSTS_N_INSNS (2);
22759 : : else
22760 : 3 : *total = COSTS_N_INSNS (1);
22761 : 3 : return true;
22762 : : }
22763 : :
22764 : 52818633 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
22765 : 110023546 : && GET_MODE_SIZE (GET_MODE (op0)) > UNITS_PER_WORD)
22766 : : {
22767 : 773272 : if (op1 == const0_rtx)
22768 : 242062 : *total = cost->add
22769 : 121031 : + rtx_cost (op0, GET_MODE (op0), outer_code, opno, speed);
22770 : : else
22771 : 1304482 : *total = 3*cost->add
22772 : 652241 : + rtx_cost (op0, GET_MODE (op0), outer_code, opno, speed)
22773 : 652241 : + rtx_cost (op1, GET_MODE (op0), outer_code, opno, speed);
22774 : 773272 : return true;
22775 : : }
22776 : :
22777 : : /* The embedded comparison operand is completely free. */
22778 : 52045361 : if (!general_operand (op0, GET_MODE (op0)) && op1 == const0_rtx)
22779 : 375507 : *total = 0;
22780 : :
22781 : : return false;
22782 : :
22783 : 1361070 : case FLOAT_EXTEND:
22784 : : /* x87 represents all values extended to 80bit. */
22785 : 1361070 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22786 : 667223 : *total = 0;
22787 : : else
22788 : 1387694 : *total = vec_fp_conversion_cost (cost, GET_MODE_BITSIZE (mode));
22789 : : return false;
22790 : :
22791 : 82576 : case FLOAT_TRUNCATE:
22792 : 82576 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22793 : 58523 : *total = cost->fadd;
22794 : : else
22795 : 48106 : *total = vec_fp_conversion_cost (cost, GET_MODE_BITSIZE (mode));
22796 : : return false;
22797 : 682987 : case FLOAT:
22798 : 682987 : case UNSIGNED_FLOAT:
22799 : 682987 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22800 : : /* TODO: We do not have cost tables for x87. */
22801 : 94413 : *total = cost->fadd;
22802 : 588574 : else if (VECTOR_MODE_P (mode))
22803 : 0 : *total = ix86_vec_cost (mode, cost->cvtpi2ps);
22804 : : else
22805 : 588574 : *total = cost->cvtsi2ss;
22806 : : return false;
22807 : :
22808 : 274709 : case FIX:
22809 : 274709 : case UNSIGNED_FIX:
22810 : 274709 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22811 : : /* TODO: We do not have cost tables for x87. */
22812 : 274709 : *total = cost->fadd;
22813 : 0 : else if (VECTOR_MODE_P (mode))
22814 : 0 : *total = ix86_vec_cost (mode, cost->cvtps2pi);
22815 : : else
22816 : 0 : *total = cost->cvtss2si;
22817 : : return false;
22818 : :
22819 : 375557 : case ABS:
22820 : : /* SSE requires memory load for the constant operand. It may make
22821 : : sense to account for this. Of course the constant operand may or
22822 : : may not be reused. */
22823 : 375557 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22824 : 262684 : *total = cost->sse_op;
22825 : 112873 : else if (X87_FLOAT_MODE_P (mode))
22826 : 35833 : *total = cost->fabs;
22827 : 77040 : else if (FLOAT_MODE_P (mode))
22828 : 32312 : *total = ix86_vec_cost (mode, cost->sse_op);
22829 : 44728 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22830 : 5395 : *total = cost->sse_op;
22831 : : return false;
22832 : :
22833 : 28387 : case SQRT:
22834 : 28387 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22835 : 18301 : *total = mode == SFmode ? cost->sqrtss : cost->sqrtsd;
22836 : 10086 : else if (X87_FLOAT_MODE_P (mode))
22837 : 4227 : *total = cost->fsqrt;
22838 : 5859 : else if (FLOAT_MODE_P (mode))
22839 : 5859 : *total = ix86_vec_cost (mode,
22840 : : mode == SFmode ? cost->sqrtss : cost->sqrtsd);
22841 : : return false;
22842 : :
22843 : 3776639 : case UNSPEC:
22844 : 3776639 : if (XINT (x, 1) == UNSPEC_TP)
22845 : 116016 : *total = 0;
22846 : 3660623 : else if (XINT (x, 1) == UNSPEC_VTERNLOG)
22847 : : {
22848 : 5228 : *total = cost->sse_op;
22849 : 5228 : *total += rtx_cost (XVECEXP (x, 0, 0), mode, code, 0, speed);
22850 : 5228 : *total += rtx_cost (XVECEXP (x, 0, 1), mode, code, 1, speed);
22851 : 5228 : *total += rtx_cost (XVECEXP (x, 0, 2), mode, code, 2, speed);
22852 : 5228 : return true;
22853 : : }
22854 : 3655395 : else if (XINT (x, 1) == UNSPEC_PTEST)
22855 : : {
22856 : 42414 : *total = cost->sse_op;
22857 : 42414 : rtx test_op0 = XVECEXP (x, 0, 0);
22858 : 42414 : if (!rtx_equal_p (test_op0, XVECEXP (x, 0, 1)))
22859 : : return false;
22860 : 41737 : if (GET_CODE (test_op0) == AND)
22861 : : {
22862 : 23 : rtx and_op0 = XEXP (test_op0, 0);
22863 : 23 : if (GET_CODE (and_op0) == NOT)
22864 : 0 : and_op0 = XEXP (and_op0, 0);
22865 : 23 : *total += rtx_cost (and_op0, GET_MODE (and_op0),
22866 : : AND, 0, speed)
22867 : 23 : + rtx_cost (XEXP (test_op0, 1), GET_MODE (and_op0),
22868 : : AND, 1, speed);
22869 : : }
22870 : : else
22871 : 41714 : *total = rtx_cost (test_op0, GET_MODE (test_op0),
22872 : : UNSPEC, 0, speed);
22873 : 41737 : return true;
22874 : : }
22875 : : return false;
22876 : :
22877 : 2514845 : case VEC_CONCAT:
22878 : : /* ??? Assume all of these vector manipulation patterns are
22879 : : recognizable. In which case they all pretty much have the
22880 : : same cost.
22881 : : ??? We should still recruse when computing cost. */
22882 : 2514845 : *total = cost->sse_op;
22883 : 2514845 : return true;
22884 : :
22885 : 2307490 : case VEC_SELECT:
22886 : : /* Special case extracting lower part from the vector.
22887 : : This by itself needs to code and most of SSE/AVX instructions have
22888 : : packed and single forms where the single form may be represented
22889 : : by such VEC_SELECT.
22890 : :
22891 : : Use cost 1 (despite the fact that functionally equivalent SUBREG has
22892 : : cost 0). Making VEC_SELECT completely free, for example instructs CSE
22893 : : to forward propagate VEC_SELECT into
22894 : :
22895 : : (set (reg eax) (reg src))
22896 : :
22897 : : which then prevents fwprop and combining. See i.e.
22898 : : gcc.target/i386/pr91103-1.c.
22899 : :
22900 : : ??? rtvec_series_p test should be, for valid patterns, equivalent to
22901 : : vec_series_lowpart_p but is not, since the latter calls
22902 : : can_cange_mode_class on ALL_REGS and this return false since x87 does
22903 : : not support subregs at all. */
22904 : 2307490 : if (rtvec_series_p (XVEC (XEXP (x, 1), 0), 0))
22905 : 741414 : *total = rtx_cost (XEXP (x, 0), GET_MODE (XEXP (x, 0)),
22906 : 741414 : outer_code, opno, speed) + 1;
22907 : : else
22908 : : /* ??? We should still recruse when computing cost. */
22909 : 1566076 : *total = cost->sse_op;
22910 : : return true;
22911 : :
22912 : 1263251 : case VEC_DUPLICATE:
22913 : 2526502 : *total = rtx_cost (XEXP (x, 0),
22914 : 1263251 : GET_MODE (XEXP (x, 0)),
22915 : : VEC_DUPLICATE, 0, speed);
22916 : : /* It's broadcast instruction, not embedded broadcasting. */
22917 : 1263251 : if (outer_code == SET)
22918 : 1218123 : *total += cost->sse_op;
22919 : :
22920 : : return true;
22921 : :
22922 : 591698 : case VEC_MERGE:
22923 : 591698 : mask = XEXP (x, 2);
22924 : : /* Scalar versions of SSE instructions may be represented as:
22925 : :
22926 : : (vec_merge (vec_duplicate (operation ....))
22927 : : (register or memory)
22928 : : (const_int 1))
22929 : :
22930 : : In this case vec_merge and vec_duplicate is for free.
22931 : : Just recurse into operation and second operand. */
22932 : 591698 : if (mask == const1_rtx
22933 : 128606 : && GET_CODE (XEXP (x, 0)) == VEC_DUPLICATE)
22934 : : {
22935 : 68424 : *total = rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22936 : : outer_code, opno, speed)
22937 : 68424 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
22938 : 68424 : return true;
22939 : : }
22940 : : /* This is masked instruction, assume the same cost,
22941 : : as nonmasked variant. */
22942 : 523274 : else if (TARGET_AVX512F && register_operand (mask, GET_MODE (mask)))
22943 : : {
22944 : 345039 : *total = rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
22945 : 345039 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
22946 : 345039 : return true;
22947 : : }
22948 : : /* Combination of the two above:
22949 : :
22950 : : (vec_merge (vec_merge (vec_duplicate (operation ...))
22951 : : (register or memory)
22952 : : (reg:QI mask))
22953 : : (register or memory)
22954 : : (const_int 1))
22955 : :
22956 : : i.e. avx512fp16_vcvtss2sh_mask. */
22957 : 178235 : else if (TARGET_AVX512F
22958 : 106121 : && mask == const1_rtx
22959 : 43211 : && GET_CODE (XEXP (x, 0)) == VEC_MERGE
22960 : 26723 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == VEC_DUPLICATE
22961 : 180461 : && register_operand (XEXP (XEXP (x, 0), 2),
22962 : 2226 : GET_MODE (XEXP (XEXP (x, 0), 2))))
22963 : : {
22964 : 2214 : *total = rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
22965 : : mode, outer_code, opno, speed)
22966 : 2214 : + rtx_cost (XEXP (XEXP (x, 0), 1),
22967 : : mode, outer_code, opno, speed)
22968 : 2214 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
22969 : 2214 : return true;
22970 : : }
22971 : : /* vcmp. */
22972 : 176021 : else if (unspec_pcmp_p (mask)
22973 : 176021 : || (GET_CODE (mask) == NOT
22974 : 0 : && unspec_pcmp_p (XEXP (mask, 0))))
22975 : : {
22976 : 1895 : rtx uns = GET_CODE (mask) == NOT ? XEXP (mask, 0) : mask;
22977 : 1895 : rtx unsop0 = XVECEXP (uns, 0, 0);
22978 : : /* Make (subreg:V4SI (not:V16QI (reg:V16QI ..)) 0)
22979 : : cost the same as register.
22980 : : This is used by avx_cmp<mode>3_ltint_not. */
22981 : 1895 : if (GET_CODE (unsop0) == SUBREG)
22982 : 417 : unsop0 = XEXP (unsop0, 0);
22983 : 1895 : if (GET_CODE (unsop0) == NOT)
22984 : 18 : unsop0 = XEXP (unsop0, 0);
22985 : 1895 : *total = rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
22986 : 1895 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed)
22987 : 1895 : + rtx_cost (unsop0, mode, UNSPEC, opno, speed)
22988 : 1895 : + rtx_cost (XVECEXP (uns, 0, 1), mode, UNSPEC, opno, speed)
22989 : 1895 : + cost->sse_op;
22990 : 1895 : return true;
22991 : : }
22992 : : else
22993 : 174126 : *total = cost->sse_op;
22994 : 174126 : return false;
22995 : :
22996 : 103311057 : case MEM:
22997 : : /* CONST_VECTOR_DUPLICATE_P in constant_pool is just broadcast.
22998 : : or variants in ix86_vector_duplicate_simode_const. */
22999 : :
23000 : 103311057 : if (GET_MODE_SIZE (mode) >= 16
23001 : 15448792 : && VECTOR_MODE_P (mode)
23002 : 9615308 : && SYMBOL_REF_P (XEXP (x, 0))
23003 : 2031709 : && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))
23004 : 105153549 : && ix86_broadcast_from_constant (mode, x))
23005 : : {
23006 : 339979 : *total = COSTS_N_INSNS (2) + speed;
23007 : 339979 : return true;
23008 : : }
23009 : :
23010 : : /* An insn that accesses memory is slightly more expensive
23011 : : than one that does not. */
23012 : 102971078 : if (speed)
23013 : : {
23014 : 92065315 : *total += 1;
23015 : 92065315 : rtx addr = XEXP (x, 0);
23016 : : /* For MEM, rtx_cost iterates each subrtx, and adds up the costs,
23017 : : so for MEM (reg) and MEM (reg + 4), the former costs 5,
23018 : : the latter costs 9, it is not accurate for x86. Ideally
23019 : : address_cost should be used, but it reduce cost too much.
23020 : : So current solution is make constant disp as cheap as possible. */
23021 : 92065315 : if (GET_CODE (addr) == PLUS
23022 : 60883502 : && x86_64_immediate_operand (XEXP (addr, 1), Pmode)
23023 : : /* Only hanlde (reg + disp) since other forms of addr are mostly LEA,
23024 : : there's no additional cost for the plus of disp. */
23025 : 148697533 : && register_operand (XEXP (addr, 0), Pmode))
23026 : : {
23027 : 54633771 : *total += 1;
23028 : 54633771 : *total += rtx_cost (XEXP (addr, 0), Pmode, PLUS, 0, speed);
23029 : 54633771 : return true;
23030 : : }
23031 : : }
23032 : :
23033 : : return false;
23034 : :
23035 : 66711 : case ZERO_EXTRACT:
23036 : 66711 : if (XEXP (x, 1) == const1_rtx
23037 : 12574 : && GET_CODE (XEXP (x, 2)) == ZERO_EXTEND
23038 : 12574 : && GET_MODE (XEXP (x, 2)) == SImode
23039 : 0 : && GET_MODE (XEXP (XEXP (x, 2), 0)) == QImode)
23040 : : {
23041 : : /* Ignore cost of zero extension and masking of last argument. */
23042 : 0 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
23043 : 0 : *total += rtx_cost (XEXP (x, 1), mode, code, 1, speed);
23044 : 0 : *total += rtx_cost (XEXP (XEXP (x, 2), 0), mode, code, 2, speed);
23045 : 0 : return true;
23046 : : }
23047 : : return false;
23048 : :
23049 : 26740359 : case IF_THEN_ELSE:
23050 : 26740359 : if (TARGET_XOP
23051 : 17111 : && VECTOR_MODE_P (mode)
23052 : 26746053 : && (GET_MODE_SIZE (mode) == 16 || GET_MODE_SIZE (mode) == 32))
23053 : : {
23054 : : /* vpcmov. */
23055 : 5018 : *total = speed ? COSTS_N_INSNS (2) : COSTS_N_BYTES (6);
23056 : 5018 : if (!REG_P (XEXP (x, 0)))
23057 : 4840 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
23058 : 5018 : if (!REG_P (XEXP (x, 1)))
23059 : 4804 : *total += rtx_cost (XEXP (x, 1), mode, code, 1, speed);
23060 : 5018 : if (!REG_P (XEXP (x, 2)))
23061 : 4806 : *total += rtx_cost (XEXP (x, 2), mode, code, 2, speed);
23062 : 5018 : return true;
23063 : : }
23064 : 0 : else if (TARGET_CMOVE
23065 : 26735341 : && SCALAR_INT_MODE_P (mode)
23066 : 29133013 : && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
23067 : : {
23068 : : /* cmov. */
23069 : 2217459 : *total = COSTS_N_INSNS (1);
23070 : 2217459 : if (!COMPARISON_P (XEXP (x, 0)) && !REG_P (XEXP (x, 0)))
23071 : 0 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
23072 : 2217459 : if (!REG_P (XEXP (x, 1)))
23073 : 121927 : *total += rtx_cost (XEXP (x, 1), mode, code, 1, speed);
23074 : 2217459 : if (!REG_P (XEXP (x, 2)))
23075 : 665437 : *total += rtx_cost (XEXP (x, 2), mode, code, 2, speed);
23076 : 2217459 : return true;
23077 : : }
23078 : : return false;
23079 : :
23080 : : default:
23081 : : return false;
23082 : : }
23083 : : }
23084 : :
23085 : : #if TARGET_MACHO
23086 : :
23087 : : static int current_machopic_label_num;
23088 : :
23089 : : /* Given a symbol name and its associated stub, write out the
23090 : : definition of the stub. */
23091 : :
23092 : : void
23093 : : machopic_output_stub (FILE *file, const char *symb, const char *stub)
23094 : : {
23095 : : unsigned int length;
23096 : : char *binder_name, *symbol_name, lazy_ptr_name[32];
23097 : : int label = ++current_machopic_label_num;
23098 : :
23099 : : /* For 64-bit we shouldn't get here. */
23100 : : gcc_assert (!TARGET_64BIT);
23101 : :
23102 : : /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
23103 : : symb = targetm.strip_name_encoding (symb);
23104 : :
23105 : : length = strlen (stub);
23106 : : binder_name = XALLOCAVEC (char, length + 32);
23107 : : GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
23108 : :
23109 : : length = strlen (symb);
23110 : : symbol_name = XALLOCAVEC (char, length + 32);
23111 : : GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
23112 : :
23113 : : sprintf (lazy_ptr_name, "L%d$lz", label);
23114 : :
23115 : : if (MACHOPIC_ATT_STUB)
23116 : : switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]);
23117 : : else if (MACHOPIC_PURE)
23118 : : switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]);
23119 : : else
23120 : : switch_to_section (darwin_sections[machopic_symbol_stub_section]);
23121 : :
23122 : : fprintf (file, "%s:\n", stub);
23123 : : fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
23124 : :
23125 : : if (MACHOPIC_ATT_STUB)
23126 : : {
23127 : : fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n");
23128 : : }
23129 : : else if (MACHOPIC_PURE)
23130 : : {
23131 : : /* PIC stub. */
23132 : : /* 25-byte PIC stub using "CALL get_pc_thunk". */
23133 : : rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */);
23134 : : output_set_got (tmp, NULL_RTX); /* "CALL ___<cpu>.get_pc_thunk.cx". */
23135 : : fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n",
23136 : : label, lazy_ptr_name, label);
23137 : : fprintf (file, "\tjmp\t*%%ecx\n");
23138 : : }
23139 : : else
23140 : : fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
23141 : :
23142 : : /* The AT&T-style ("self-modifying") stub is not lazily bound, thus
23143 : : it needs no stub-binding-helper. */
23144 : : if (MACHOPIC_ATT_STUB)
23145 : : return;
23146 : :
23147 : : fprintf (file, "%s:\n", binder_name);
23148 : :
23149 : : if (MACHOPIC_PURE)
23150 : : {
23151 : : fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name);
23152 : : fprintf (file, "\tpushl\t%%ecx\n");
23153 : : }
23154 : : else
23155 : : fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
23156 : :
23157 : : fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
23158 : :
23159 : : /* N.B. Keep the correspondence of these
23160 : : 'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the
23161 : : old-pic/new-pic/non-pic stubs; altering this will break
23162 : : compatibility with existing dylibs. */
23163 : : if (MACHOPIC_PURE)
23164 : : {
23165 : : /* 25-byte PIC stub using "CALL get_pc_thunk". */
23166 : : switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]);
23167 : : }
23168 : : else
23169 : : /* 16-byte -mdynamic-no-pic stub. */
23170 : : switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]);
23171 : :
23172 : : fprintf (file, "%s:\n", lazy_ptr_name);
23173 : : fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
23174 : : fprintf (file, ASM_LONG "%s\n", binder_name);
23175 : : }
23176 : : #endif /* TARGET_MACHO */
23177 : :
23178 : : /* Order the registers for register allocator. */
23179 : :
23180 : : void
23181 : 208851 : x86_order_regs_for_local_alloc (void)
23182 : : {
23183 : 208851 : int pos = 0;
23184 : 208851 : int i;
23185 : :
23186 : : /* First allocate the local general purpose registers. */
23187 : 19423143 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
23188 : 25897524 : if (GENERAL_REGNO_P (i) && call_used_or_fixed_reg_p (i))
23189 : 5439542 : reg_alloc_order [pos++] = i;
23190 : :
23191 : : /* Global general purpose registers. */
23192 : 19423143 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
23193 : 22303341 : if (GENERAL_REGNO_P (i) && !call_used_or_fixed_reg_p (i))
23194 : 1243690 : reg_alloc_order [pos++] = i;
23195 : :
23196 : : /* x87 registers come first in case we are doing FP math
23197 : : using them. */
23198 : 208851 : if (!TARGET_SSE_MATH)
23199 : 56727 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
23200 : 50424 : reg_alloc_order [pos++] = i;
23201 : :
23202 : : /* SSE registers. */
23203 : 1879659 : for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
23204 : 1670808 : reg_alloc_order [pos++] = i;
23205 : 1879659 : for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
23206 : 1670808 : reg_alloc_order [pos++] = i;
23207 : :
23208 : : /* Extended REX SSE registers. */
23209 : 3550467 : for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
23210 : 3341616 : reg_alloc_order [pos++] = i;
23211 : :
23212 : : /* Mask register. */
23213 : 1879659 : for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
23214 : 1670808 : reg_alloc_order [pos++] = i;
23215 : :
23216 : : /* x87 registers. */
23217 : 208851 : if (TARGET_SSE_MATH)
23218 : 1822932 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
23219 : 1620384 : reg_alloc_order [pos++] = i;
23220 : :
23221 : 1879659 : for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
23222 : 1670808 : reg_alloc_order [pos++] = i;
23223 : :
23224 : : /* Initialize the rest of array as we do not allocate some registers
23225 : : at all. */
23226 : 1044255 : while (pos < FIRST_PSEUDO_REGISTER)
23227 : 835404 : reg_alloc_order [pos++] = 0;
23228 : 208851 : }
23229 : :
23230 : : static bool
23231 : 202570734 : ix86_ms_bitfield_layout_p (const_tree record_type)
23232 : : {
23233 : 202570734 : return ((TARGET_MS_BITFIELD_LAYOUT
23234 : 215 : && !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
23235 : 202570734 : || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type)));
23236 : : }
23237 : :
23238 : : /* Returns an expression indicating where the this parameter is
23239 : : located on entry to the FUNCTION. */
23240 : :
23241 : : static rtx
23242 : 1755 : x86_this_parameter (tree function)
23243 : : {
23244 : 1755 : tree type = TREE_TYPE (function);
23245 : 1755 : bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
23246 : 1755 : int nregs;
23247 : :
23248 : 1755 : if (TARGET_64BIT)
23249 : : {
23250 : 1753 : const int *parm_regs;
23251 : :
23252 : 1753 : if (ix86_function_type_abi (type) == MS_ABI)
23253 : : parm_regs = x86_64_ms_abi_int_parameter_registers;
23254 : : else
23255 : 1753 : parm_regs = x86_64_int_parameter_registers;
23256 : 1753 : return gen_rtx_REG (Pmode, parm_regs[aggr]);
23257 : : }
23258 : :
23259 : 2 : nregs = ix86_function_regparm (type, function);
23260 : :
23261 : 2 : if (nregs > 0 && !stdarg_p (type))
23262 : : {
23263 : 0 : int regno;
23264 : 0 : unsigned int ccvt = ix86_get_callcvt (type);
23265 : :
23266 : 0 : if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
23267 : 0 : regno = aggr ? DX_REG : CX_REG;
23268 : 0 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
23269 : : {
23270 : 0 : regno = CX_REG;
23271 : 0 : if (aggr)
23272 : 0 : return gen_rtx_MEM (SImode,
23273 : 0 : plus_constant (Pmode, stack_pointer_rtx, 4));
23274 : : }
23275 : : else
23276 : : {
23277 : 0 : regno = AX_REG;
23278 : 0 : if (aggr)
23279 : : {
23280 : 0 : regno = DX_REG;
23281 : 0 : if (nregs == 1)
23282 : 0 : return gen_rtx_MEM (SImode,
23283 : 0 : plus_constant (Pmode,
23284 : 0 : stack_pointer_rtx, 4));
23285 : : }
23286 : : }
23287 : 0 : return gen_rtx_REG (SImode, regno);
23288 : : }
23289 : :
23290 : 2 : return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx,
23291 : 4 : aggr ? 8 : 4));
23292 : : }
23293 : :
23294 : : /* Determine whether x86_output_mi_thunk can succeed. */
23295 : :
23296 : : static bool
23297 : 4899 : x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset,
23298 : : const_tree function)
23299 : : {
23300 : : /* 64-bit can handle anything. */
23301 : 4899 : if (TARGET_64BIT)
23302 : : return true;
23303 : :
23304 : : /* For 32-bit, everything's fine if we have one free register. */
23305 : 76 : if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
23306 : : return true;
23307 : :
23308 : : /* Need a free register for vcall_offset. */
23309 : 0 : if (vcall_offset)
23310 : : return false;
23311 : :
23312 : : /* Need a free register for GOT references. */
23313 : 0 : if (flag_pic && !targetm.binds_local_p (function))
23314 : : return false;
23315 : :
23316 : : /* Otherwise ok. */
23317 : : return true;
23318 : : }
23319 : :
23320 : : /* Output the assembler code for a thunk function. THUNK_DECL is the
23321 : : declaration for the thunk function itself, FUNCTION is the decl for
23322 : : the target function. DELTA is an immediate constant offset to be
23323 : : added to THIS. If VCALL_OFFSET is nonzero, the word at
23324 : : *(*this + vcall_offset) should be added to THIS. */
23325 : :
23326 : : static void
23327 : 1755 : x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
23328 : : HOST_WIDE_INT vcall_offset, tree function)
23329 : : {
23330 : 1755 : const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
23331 : 1755 : rtx this_param = x86_this_parameter (function);
23332 : 1755 : rtx this_reg, tmp, fnaddr;
23333 : 1755 : unsigned int tmp_regno;
23334 : 1755 : rtx_insn *insn;
23335 : 1755 : int saved_flag_force_indirect_call = flag_force_indirect_call;
23336 : :
23337 : 1755 : if (TARGET_64BIT)
23338 : : tmp_regno = R10_REG;
23339 : : else
23340 : : {
23341 : 2 : unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
23342 : 2 : if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
23343 : : tmp_regno = AX_REG;
23344 : 2 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
23345 : : tmp_regno = DX_REG;
23346 : : else
23347 : 2 : tmp_regno = CX_REG;
23348 : :
23349 : 2 : if (flag_pic)
23350 : 2 : flag_force_indirect_call = 0;
23351 : : }
23352 : :
23353 : 1755 : emit_note (NOTE_INSN_PROLOGUE_END);
23354 : :
23355 : : /* CET is enabled, insert EB instruction. */
23356 : 1755 : if ((flag_cf_protection & CF_BRANCH))
23357 : 20 : emit_insn (gen_nop_endbr ());
23358 : :
23359 : : /* If VCALL_OFFSET, we'll need THIS in a register. Might as well
23360 : : pull it in now and let DELTA benefit. */
23361 : 1755 : if (REG_P (this_param))
23362 : : this_reg = this_param;
23363 : 2 : else if (vcall_offset)
23364 : : {
23365 : : /* Put the this parameter into %eax. */
23366 : 1 : this_reg = gen_rtx_REG (Pmode, AX_REG);
23367 : 1 : emit_move_insn (this_reg, this_param);
23368 : : }
23369 : : else
23370 : : this_reg = NULL_RTX;
23371 : :
23372 : : /* Adjust the this parameter by a fixed constant. */
23373 : 1755 : if (delta)
23374 : : {
23375 : 824 : rtx delta_rtx = GEN_INT (delta);
23376 : 824 : rtx delta_dst = this_reg ? this_reg : this_param;
23377 : :
23378 : 824 : if (TARGET_64BIT)
23379 : : {
23380 : 823 : if (!x86_64_general_operand (delta_rtx, Pmode))
23381 : : {
23382 : 0 : tmp = gen_rtx_REG (Pmode, tmp_regno);
23383 : 0 : emit_move_insn (tmp, delta_rtx);
23384 : 0 : delta_rtx = tmp;
23385 : : }
23386 : : }
23387 : :
23388 : 824 : ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx);
23389 : : }
23390 : :
23391 : : /* Adjust the this parameter by a value stored in the vtable. */
23392 : 1755 : if (vcall_offset)
23393 : : {
23394 : 982 : rtx vcall_addr, vcall_mem, this_mem;
23395 : :
23396 : 982 : tmp = gen_rtx_REG (Pmode, tmp_regno);
23397 : :
23398 : 982 : this_mem = gen_rtx_MEM (ptr_mode, this_reg);
23399 : 982 : if (Pmode != ptr_mode)
23400 : 0 : this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem);
23401 : 982 : emit_move_insn (tmp, this_mem);
23402 : :
23403 : : /* Adjust the this parameter. */
23404 : 982 : vcall_addr = plus_constant (Pmode, tmp, vcall_offset);
23405 : 982 : if (TARGET_64BIT
23406 : 982 : && !ix86_legitimate_address_p (ptr_mode, vcall_addr, true))
23407 : : {
23408 : 0 : rtx tmp2 = gen_rtx_REG (Pmode, R11_REG);
23409 : 0 : emit_move_insn (tmp2, GEN_INT (vcall_offset));
23410 : 0 : vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2);
23411 : : }
23412 : :
23413 : 982 : vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr);
23414 : 982 : if (Pmode != ptr_mode)
23415 : 0 : emit_insn (gen_addsi_1_zext (this_reg,
23416 : : gen_rtx_REG (ptr_mode,
23417 : : REGNO (this_reg)),
23418 : : vcall_mem));
23419 : : else
23420 : 982 : ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem);
23421 : : }
23422 : :
23423 : : /* If necessary, drop THIS back to its stack slot. */
23424 : 1755 : if (this_reg && this_reg != this_param)
23425 : 1 : emit_move_insn (this_param, this_reg);
23426 : :
23427 : 1755 : fnaddr = XEXP (DECL_RTL (function), 0);
23428 : 1755 : if (TARGET_64BIT)
23429 : : {
23430 : 25 : if (!flag_pic || targetm.binds_local_p (function)
23431 : 1778 : || TARGET_PECOFF)
23432 : : ;
23433 : : else
23434 : : {
23435 : 0 : tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL);
23436 : 0 : tmp = gen_rtx_CONST (Pmode, tmp);
23437 : 0 : fnaddr = gen_const_mem (Pmode, tmp);
23438 : : }
23439 : : }
23440 : : else
23441 : : {
23442 : 2 : if (!flag_pic || targetm.binds_local_p (function))
23443 : : ;
23444 : : #if TARGET_MACHO
23445 : : else if (TARGET_MACHO)
23446 : : {
23447 : : fnaddr = machopic_indirect_call_target (DECL_RTL (function));
23448 : : fnaddr = XEXP (fnaddr, 0);
23449 : : }
23450 : : #endif /* TARGET_MACHO */
23451 : : else
23452 : : {
23453 : 0 : tmp = gen_rtx_REG (Pmode, CX_REG);
23454 : 0 : output_set_got (tmp, NULL_RTX);
23455 : :
23456 : 0 : fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT);
23457 : 0 : fnaddr = gen_rtx_CONST (Pmode, fnaddr);
23458 : 0 : fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr);
23459 : 0 : fnaddr = gen_const_mem (Pmode, fnaddr);
23460 : : }
23461 : : }
23462 : :
23463 : : /* Our sibling call patterns do not allow memories, because we have no
23464 : : predicate that can distinguish between frame and non-frame memory.
23465 : : For our purposes here, we can get away with (ab)using a jump pattern,
23466 : : because we're going to do no optimization. */
23467 : 1755 : if (MEM_P (fnaddr))
23468 : : {
23469 : 0 : if (sibcall_insn_operand (fnaddr, word_mode))
23470 : : {
23471 : 0 : fnaddr = XEXP (DECL_RTL (function), 0);
23472 : 0 : tmp = gen_rtx_MEM (QImode, fnaddr);
23473 : 0 : tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
23474 : 0 : tmp = emit_call_insn (tmp);
23475 : 0 : SIBLING_CALL_P (tmp) = 1;
23476 : : }
23477 : : else
23478 : 0 : emit_jump_insn (gen_indirect_jump (fnaddr));
23479 : : }
23480 : : else
23481 : : {
23482 : 1755 : if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr))
23483 : : {
23484 : : // CM_LARGE_PIC always uses pseudo PIC register which is
23485 : : // uninitialized. Since FUNCTION is local and calling it
23486 : : // doesn't go through PLT, we use scratch register %r11 as
23487 : : // PIC register and initialize it here.
23488 : 3 : pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG);
23489 : 3 : ix86_init_large_pic_reg (tmp_regno);
23490 : 3 : fnaddr = legitimize_pic_address (fnaddr,
23491 : 3 : gen_rtx_REG (Pmode, tmp_regno));
23492 : : }
23493 : :
23494 : 1755 : if (!sibcall_insn_operand (fnaddr, word_mode))
23495 : : {
23496 : 9 : tmp = gen_rtx_REG (word_mode, tmp_regno);
23497 : 9 : if (GET_MODE (fnaddr) != word_mode)
23498 : 0 : fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr);
23499 : 9 : emit_move_insn (tmp, fnaddr);
23500 : 9 : fnaddr = tmp;
23501 : : }
23502 : :
23503 : 1755 : tmp = gen_rtx_MEM (QImode, fnaddr);
23504 : 1755 : tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
23505 : 1755 : tmp = emit_call_insn (tmp);
23506 : 1755 : SIBLING_CALL_P (tmp) = 1;
23507 : : }
23508 : 1755 : emit_barrier ();
23509 : :
23510 : : /* Emit just enough of rest_of_compilation to get the insns emitted. */
23511 : 1755 : insn = get_insns ();
23512 : 1755 : shorten_branches (insn);
23513 : 1755 : assemble_start_function (thunk_fndecl, fnname);
23514 : 1755 : final_start_function (insn, file, 1);
23515 : 1755 : final (insn, file, 1);
23516 : 1755 : final_end_function ();
23517 : 1755 : assemble_end_function (thunk_fndecl, fnname);
23518 : :
23519 : 1755 : flag_force_indirect_call = saved_flag_force_indirect_call;
23520 : 1755 : }
23521 : :
23522 : : static void
23523 : 263283 : x86_file_start (void)
23524 : : {
23525 : 263283 : default_file_start ();
23526 : 263283 : if (TARGET_16BIT)
23527 : 5 : fputs ("\t.code16gcc\n", asm_out_file);
23528 : : #if TARGET_MACHO
23529 : : darwin_file_start ();
23530 : : #endif
23531 : 263283 : if (X86_FILE_START_VERSION_DIRECTIVE)
23532 : : fputs ("\t.version\t\"01.01\"\n", asm_out_file);
23533 : 263283 : if (X86_FILE_START_FLTUSED)
23534 : : fputs ("\t.global\t__fltused\n", asm_out_file);
23535 : 263283 : if (ix86_asm_dialect == ASM_INTEL)
23536 : 51 : fputs ("\t.intel_syntax noprefix\n", asm_out_file);
23537 : 263283 : }
23538 : :
23539 : : int
23540 : 88620941 : x86_field_alignment (tree type, int computed)
23541 : : {
23542 : 88620941 : machine_mode mode;
23543 : :
23544 : 88620941 : if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
23545 : : return computed;
23546 : 8745774 : if (TARGET_IAMCU)
23547 : 0 : return iamcu_alignment (type, computed);
23548 : 8745774 : type = strip_array_types (type);
23549 : 8745774 : mode = TYPE_MODE (type);
23550 : 8745774 : if (mode == DFmode || mode == DCmode
23551 : 8641406 : || GET_MODE_CLASS (mode) == MODE_INT
23552 : 2904393 : || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
23553 : : {
23554 : 5841381 : if (TYPE_ATOMIC (type) && computed > 32)
23555 : : {
23556 : 0 : static bool warned;
23557 : :
23558 : 0 : if (!warned && warn_psabi)
23559 : : {
23560 : 0 : const char *url
23561 : : = CHANGES_ROOT_URL "gcc-11/changes.html#ia32_atomic";
23562 : :
23563 : 0 : warned = true;
23564 : 0 : inform (input_location, "the alignment of %<_Atomic %T%> "
23565 : : "fields changed in %{GCC 11.1%}",
23566 : 0 : TYPE_MAIN_VARIANT (type), url);
23567 : : }
23568 : : }
23569 : : else
23570 : 5841381 : return MIN (32, computed);
23571 : : }
23572 : : return computed;
23573 : : }
23574 : :
23575 : : /* Print call to TARGET to FILE. */
23576 : :
23577 : : static void
23578 : 286 : x86_print_call_or_nop (FILE *file, const char *target)
23579 : : {
23580 : 286 : if (flag_nop_mcount || !strcmp (target, "nop"))
23581 : : /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
23582 : 6 : fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
23583 : 280 : else if (!TARGET_PECOFF && flag_pic)
23584 : : {
23585 : 6 : gcc_assert (flag_plt);
23586 : :
23587 : 6 : fprintf (file, "1:\tcall\t%s@PLT\n", target);
23588 : : }
23589 : : else
23590 : 274 : fprintf (file, "1:\tcall\t%s\n", target);
23591 : 286 : }
23592 : :
23593 : : static bool
23594 : 300 : current_fentry_name (const char **name)
23595 : : {
23596 : 300 : tree attr = lookup_attribute ("fentry_name",
23597 : 300 : DECL_ATTRIBUTES (current_function_decl));
23598 : 300 : if (!attr)
23599 : : return false;
23600 : 2 : *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
23601 : 2 : return true;
23602 : : }
23603 : :
23604 : : static bool
23605 : 10 : current_fentry_section (const char **name)
23606 : : {
23607 : 10 : tree attr = lookup_attribute ("fentry_section",
23608 : 10 : DECL_ATTRIBUTES (current_function_decl));
23609 : 10 : if (!attr)
23610 : : return false;
23611 : 2 : *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
23612 : 2 : return true;
23613 : : }
23614 : :
23615 : : /* Return a caller-saved register which isn't live or a callee-saved
23616 : : register which has been saved on stack in the prologue at entry for
23617 : : profile. */
23618 : :
23619 : : static int
23620 : 13 : x86_64_select_profile_regnum (bool r11_ok ATTRIBUTE_UNUSED)
23621 : : {
23622 : : /* Use %r10 if the profiler is emitted before the prologue or it isn't
23623 : : used by DRAP. */
23624 : 13 : if (ix86_profile_before_prologue ()
23625 : 9 : || !crtl->drap_reg
23626 : 16 : || REGNO (crtl->drap_reg) != R10_REG)
23627 : : return R10_REG;
23628 : :
23629 : : /* The profiler is emitted after the prologue. If there is a
23630 : : caller-saved register which isn't live or a callee-saved
23631 : : register saved on stack in the prologue, use it. */
23632 : :
23633 : 3 : bitmap reg_live = df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun));
23634 : :
23635 : 3 : int i;
23636 : 88 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
23637 : 56 : if (GENERAL_REGNO_P (i)
23638 : 29 : && i != R10_REG
23639 : : #ifdef NO_PROFILE_COUNTERS
23640 : 27 : && (r11_ok || i != R11_REG)
23641 : : #else
23642 : : && i != R11_REG
23643 : : #endif
23644 : 26 : && TEST_HARD_REG_BIT (accessible_reg_set, i)
23645 : 111 : && (ix86_save_reg (i, true, true)
23646 : 25 : || (call_used_regs[i]
23647 : 18 : && !fixed_regs[i]
23648 : 16 : && !REGNO_REG_SET_P (reg_live, i))))
23649 : 3 : return i;
23650 : :
23651 : 0 : sorry ("no register available for profiling %<-mcmodel=large%s%>",
23652 : 0 : ix86_cmodel == CM_LARGE_PIC ? " -fPIC" : "");
23653 : :
23654 : 0 : return R10_REG;
23655 : : }
23656 : :
23657 : : /* Output assembler code to FILE to increment profiler label # LABELNO
23658 : : for profiling a function entry. */
23659 : : void
23660 : 300 : x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
23661 : : {
23662 : 300 : if (cfun->machine->insn_queued_at_entrance)
23663 : : {
23664 : 5 : if (cfun->machine->insn_queued_at_entrance == TYPE_ENDBR)
23665 : 4 : fprintf (file, "\t%s\n", TARGET_64BIT ? "endbr64" : "endbr32");
23666 : 5 : unsigned int patch_area_size
23667 : 5 : = crtl->patch_area_size - crtl->patch_area_entry;
23668 : 5 : if (patch_area_size)
23669 : 2 : ix86_output_patchable_area (patch_area_size,
23670 : : crtl->patch_area_entry == 0);
23671 : : }
23672 : :
23673 : 300 : const char *mcount_name = MCOUNT_NAME;
23674 : :
23675 : 300 : if (current_fentry_name (&mcount_name))
23676 : : ;
23677 : 298 : else if (fentry_name)
23678 : 1 : mcount_name = fentry_name;
23679 : 297 : else if (flag_fentry)
23680 : 21 : mcount_name = MCOUNT_NAME_BEFORE_PROLOGUE;
23681 : :
23682 : 300 : if (TARGET_64BIT)
23683 : : {
23684 : : #ifndef NO_PROFILE_COUNTERS
23685 : : if (ASSEMBLER_DIALECT == ASM_INTEL)
23686 : : fprintf (file, "\tlea\tr11, %sP%d[rip]\n", LPREFIX, labelno);
23687 : : else
23688 : : fprintf (file, "\tleaq\t%sP%d(%%rip), %%r11\n", LPREFIX, labelno);
23689 : : #endif
23690 : :
23691 : 300 : int scratch;
23692 : 300 : const char *reg;
23693 : 300 : char legacy_reg[4] = { 0 };
23694 : :
23695 : 300 : if (!TARGET_PECOFF)
23696 : : {
23697 : 300 : switch (ix86_cmodel)
23698 : : {
23699 : 5 : case CM_LARGE:
23700 : 5 : scratch = x86_64_select_profile_regnum (true);
23701 : 5 : reg = hi_reg_name[scratch];
23702 : 5 : if (LEGACY_INT_REGNO_P (scratch))
23703 : : {
23704 : 0 : legacy_reg[0] = 'r';
23705 : 0 : legacy_reg[1] = reg[0];
23706 : 0 : legacy_reg[2] = reg[1];
23707 : 0 : reg = legacy_reg;
23708 : : }
23709 : 5 : if (ASSEMBLER_DIALECT == ASM_INTEL)
23710 : 1 : fprintf (file, "1:\tmovabs\t%s, OFFSET FLAT:%s\n"
23711 : : "\tcall\t%s\n", reg, mcount_name, reg);
23712 : : else
23713 : 4 : fprintf (file, "1:\tmovabsq\t$%s, %%%s\n\tcall\t*%%%s\n",
23714 : : mcount_name, reg, reg);
23715 : : break;
23716 : 8 : case CM_LARGE_PIC:
23717 : : #ifdef NO_PROFILE_COUNTERS
23718 : 8 : scratch = x86_64_select_profile_regnum (false);
23719 : 8 : reg = hi_reg_name[scratch];
23720 : 8 : if (LEGACY_INT_REGNO_P (scratch))
23721 : : {
23722 : 1 : legacy_reg[0] = 'r';
23723 : 1 : legacy_reg[1] = reg[0];
23724 : 1 : legacy_reg[2] = reg[1];
23725 : 1 : reg = legacy_reg;
23726 : : }
23727 : 8 : if (ASSEMBLER_DIALECT == ASM_INTEL)
23728 : : {
23729 : 1 : fprintf (file, "1:movabs\tr11, "
23730 : : "OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-1b\n");
23731 : 1 : fprintf (file, "\tlea\t%s, 1b[rip]\n", reg);
23732 : 1 : fprintf (file, "\tadd\t%s, r11\n", reg);
23733 : 1 : fprintf (file, "\tmovabs\tr11, OFFSET FLAT:%s@PLTOFF\n",
23734 : : mcount_name);
23735 : 1 : fprintf (file, "\tadd\t%s, r11\n", reg);
23736 : 1 : fprintf (file, "\tcall\t%s\n", reg);
23737 : 1 : break;
23738 : : }
23739 : 7 : fprintf (file,
23740 : : "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
23741 : 7 : fprintf (file, "\tleaq\t1b(%%rip), %%%s\n", reg);
23742 : 7 : fprintf (file, "\taddq\t%%r11, %%%s\n", reg);
23743 : 7 : fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n", mcount_name);
23744 : 7 : fprintf (file, "\taddq\t%%r11, %%%s\n", reg);
23745 : 7 : fprintf (file, "\tcall\t*%%%s\n", reg);
23746 : : #else
23747 : : sorry ("profiling %<-mcmodel=large%> with PIC is not supported");
23748 : : #endif
23749 : 7 : break;
23750 : 8 : case CM_SMALL_PIC:
23751 : 8 : case CM_MEDIUM_PIC:
23752 : 8 : if (!flag_plt)
23753 : : {
23754 : 1 : if (ASSEMBLER_DIALECT == ASM_INTEL)
23755 : 0 : fprintf (file, "1:\tcall\t[QWORD PTR %s@GOTPCREL[rip]]\n",
23756 : : mcount_name);
23757 : : else
23758 : 1 : fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n",
23759 : : mcount_name);
23760 : : break;
23761 : : }
23762 : : /* fall through */
23763 : 286 : default:
23764 : 286 : x86_print_call_or_nop (file, mcount_name);
23765 : 286 : break;
23766 : : }
23767 : : }
23768 : : else
23769 : : x86_print_call_or_nop (file, mcount_name);
23770 : : }
23771 : 0 : else if (flag_pic)
23772 : : {
23773 : : #ifndef NO_PROFILE_COUNTERS
23774 : : if (ASSEMBLER_DIALECT == ASM_INTEL)
23775 : : fprintf (file,
23776 : : "\tlea\t" PROFILE_COUNT_REGISTER ", %sP%d@GOTOFF[ebx]\n",
23777 : : LPREFIX, labelno);
23778 : : else
23779 : : fprintf (file,
23780 : : "\tleal\t%sP%d@GOTOFF(%%ebx), %%" PROFILE_COUNT_REGISTER "\n",
23781 : : LPREFIX, labelno);
23782 : : #endif
23783 : 0 : if (flag_plt)
23784 : 0 : x86_print_call_or_nop (file, mcount_name);
23785 : 0 : else if (ASSEMBLER_DIALECT == ASM_INTEL)
23786 : 0 : fprintf (file, "1:\tcall\t[DWORD PTR %s@GOT[ebx]]\n", mcount_name);
23787 : : else
23788 : 0 : fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
23789 : : }
23790 : : else
23791 : : {
23792 : : #ifndef NO_PROFILE_COUNTERS
23793 : : if (ASSEMBLER_DIALECT == ASM_INTEL)
23794 : : fprintf (file,
23795 : : "\tmov\t" PROFILE_COUNT_REGISTER ", OFFSET FLAT:%sP%d\n",
23796 : : LPREFIX, labelno);
23797 : : else
23798 : : fprintf (file, "\tmovl\t$%sP%d, %%" PROFILE_COUNT_REGISTER "\n",
23799 : : LPREFIX, labelno);
23800 : : #endif
23801 : 0 : x86_print_call_or_nop (file, mcount_name);
23802 : : }
23803 : :
23804 : 300 : if (flag_record_mcount
23805 : 591 : || lookup_attribute ("fentry_section",
23806 : 291 : DECL_ATTRIBUTES (current_function_decl)))
23807 : : {
23808 : 10 : const char *sname = "__mcount_loc";
23809 : :
23810 : 10 : if (current_fentry_section (&sname))
23811 : : ;
23812 : 8 : else if (fentry_section)
23813 : 1 : sname = fentry_section;
23814 : :
23815 : 10 : fprintf (file, "\t.section %s, \"a\",@progbits\n", sname);
23816 : 10 : fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
23817 : 10 : fprintf (file, "\t.previous\n");
23818 : : }
23819 : 300 : }
23820 : :
23821 : : /* We don't have exact information about the insn sizes, but we may assume
23822 : : quite safely that we are informed about all 1 byte insns and memory
23823 : : address sizes. This is enough to eliminate unnecessary padding in
23824 : : 99% of cases. */
23825 : :
23826 : : int
23827 : 360422857 : ix86_min_insn_size (rtx_insn *insn)
23828 : : {
23829 : 360422857 : int l = 0, len;
23830 : :
23831 : 360422857 : if (!INSN_P (insn) || !active_insn_p (insn))
23832 : 499326 : return 0;
23833 : :
23834 : : /* Discard alignments we've emit and jump instructions. */
23835 : 359923531 : if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
23836 : 359923531 : && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
23837 : : return 0;
23838 : :
23839 : : /* Important case - calls are always 5 bytes.
23840 : : It is common to have many calls in the row. */
23841 : 359923524 : if (CALL_P (insn)
23842 : 8968750 : && symbolic_reference_mentioned_p (PATTERN (insn))
23843 : 368553003 : && !SIBLING_CALL_P (insn))
23844 : : return 5;
23845 : 351517912 : len = get_attr_length (insn);
23846 : 351517912 : if (len <= 1)
23847 : : return 1;
23848 : :
23849 : : /* For normal instructions we rely on get_attr_length being exact,
23850 : : with a few exceptions. */
23851 : 342501678 : if (!JUMP_P (insn))
23852 : : {
23853 : 337368570 : enum attr_type type = get_attr_type (insn);
23854 : :
23855 : 337368570 : switch (type)
23856 : : {
23857 : 91438 : case TYPE_MULTI:
23858 : 91438 : if (GET_CODE (PATTERN (insn)) == ASM_INPUT
23859 : 91438 : || asm_noperands (PATTERN (insn)) >= 0)
23860 : 502 : return 0;
23861 : : break;
23862 : : case TYPE_OTHER:
23863 : : case TYPE_FCMP:
23864 : : break;
23865 : : default:
23866 : : /* Otherwise trust get_attr_length. */
23867 : : return len;
23868 : : }
23869 : :
23870 : 465492 : l = get_attr_length_address (insn);
23871 : 465492 : if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
23872 : : l = 4;
23873 : : }
23874 : 375219 : if (l)
23875 : 90273 : return 1+l;
23876 : : else
23877 : 5508327 : return 2;
23878 : : }
23879 : :
23880 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
23881 : :
23882 : : /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
23883 : : window. */
23884 : :
23885 : : static void
23886 : 45348 : ix86_avoid_jump_mispredicts (void)
23887 : : {
23888 : 45348 : rtx_insn *insn, *start = get_insns ();
23889 : 45348 : int nbytes = 0, njumps = 0;
23890 : 45348 : bool isjump = false;
23891 : :
23892 : : /* Look for all minimal intervals of instructions containing 4 jumps.
23893 : : The intervals are bounded by START and INSN. NBYTES is the total
23894 : : size of instructions in the interval including INSN and not including
23895 : : START. When the NBYTES is smaller than 16 bytes, it is possible
23896 : : that the end of START and INSN ends up in the same 16byte page.
23897 : :
23898 : : The smallest offset in the page INSN can start is the case where START
23899 : : ends on the offset 0. Offset of INSN is then NBYTES - sizeof (INSN).
23900 : : We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
23901 : :
23902 : : Don't consider asm goto as jump, while it can contain a jump, it doesn't
23903 : : have to, control transfer to label(s) can be performed through other
23904 : : means, and also we estimate minimum length of all asm stmts as 0. */
23905 : 699819 : for (insn = start; insn; insn = NEXT_INSN (insn))
23906 : : {
23907 : 654471 : int min_size;
23908 : :
23909 : 654471 : if (LABEL_P (insn))
23910 : : {
23911 : 967 : align_flags alignment = label_to_alignment (insn);
23912 : 967 : int align = alignment.levels[0].log;
23913 : 967 : int max_skip = alignment.levels[0].maxskip;
23914 : :
23915 : 967 : if (max_skip > 15)
23916 : : max_skip = 15;
23917 : : /* If align > 3, only up to 16 - max_skip - 1 bytes can be
23918 : : already in the current 16 byte page, because otherwise
23919 : : ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
23920 : : bytes to reach 16 byte boundary. */
23921 : 967 : if (align <= 0
23922 : 322 : || (align <= 3 && max_skip != (1 << align) - 1))
23923 : 967 : max_skip = 0;
23924 : 967 : if (dump_file)
23925 : 0 : fprintf (dump_file, "Label %i with max_skip %i\n",
23926 : 0 : INSN_UID (insn), max_skip);
23927 : 967 : if (max_skip)
23928 : : {
23929 : 6163 : while (nbytes + max_skip >= 16)
23930 : : {
23931 : 5841 : start = NEXT_INSN (start);
23932 : 316 : if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
23933 : 5856 : || CALL_P (start))
23934 : 346 : njumps--, isjump = true;
23935 : : else
23936 : : isjump = false;
23937 : 5841 : nbytes -= ix86_min_insn_size (start);
23938 : : }
23939 : : }
23940 : 967 : continue;
23941 : 967 : }
23942 : :
23943 : 653504 : min_size = ix86_min_insn_size (insn);
23944 : 653504 : nbytes += min_size;
23945 : 653504 : if (dump_file)
23946 : 0 : fprintf (dump_file, "Insn %i estimated to %i bytes\n",
23947 : 0 : INSN_UID (insn), min_size);
23948 : 46537 : if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0)
23949 : 653524 : || CALL_P (insn))
23950 : 47551 : njumps++;
23951 : : else
23952 : 605953 : continue;
23953 : :
23954 : 56276 : while (njumps > 3)
23955 : : {
23956 : 8725 : start = NEXT_INSN (start);
23957 : 570 : if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
23958 : 8725 : || CALL_P (start))
23959 : 1275 : njumps--, isjump = true;
23960 : : else
23961 : : isjump = false;
23962 : 8725 : nbytes -= ix86_min_insn_size (start);
23963 : : }
23964 : 47551 : gcc_assert (njumps >= 0);
23965 : 47551 : if (dump_file)
23966 : 0 : fprintf (dump_file, "Interval %i to %i has %i bytes\n",
23967 : 0 : INSN_UID (start), INSN_UID (insn), nbytes);
23968 : :
23969 : 47551 : if (njumps == 3 && isjump && nbytes < 16)
23970 : : {
23971 : 48 : int padsize = 15 - nbytes + ix86_min_insn_size (insn);
23972 : :
23973 : 48 : if (dump_file)
23974 : 0 : fprintf (dump_file, "Padding insn %i by %i bytes!\n",
23975 : 0 : INSN_UID (insn), padsize);
23976 : 48 : emit_insn_before (gen_max_skip_align (GEN_INT (4), GEN_INT (padsize)), insn);
23977 : : }
23978 : : }
23979 : 45348 : }
23980 : : #endif
23981 : :
23982 : : /* AMD Athlon works faster
23983 : : when RET is not destination of conditional jump or directly preceded
23984 : : by other jump instruction. We avoid the penalty by inserting NOP just
23985 : : before the RET instructions in such cases. */
23986 : : static void
23987 : 45066 : ix86_pad_returns (void)
23988 : : {
23989 : 45066 : edge e;
23990 : 45066 : edge_iterator ei;
23991 : :
23992 : 90156 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
23993 : : {
23994 : 45090 : basic_block bb = e->src;
23995 : 45090 : rtx_insn *ret = BB_END (bb);
23996 : 45090 : rtx_insn *prev;
23997 : 45090 : bool replace = false;
23998 : :
23999 : 45080 : if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret))
24000 : 90170 : || optimize_bb_for_size_p (bb))
24001 : 23 : continue;
24002 : 179362 : for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
24003 : 133883 : if (active_insn_p (prev) || LABEL_P (prev))
24004 : : break;
24005 : 45067 : if (prev && LABEL_P (prev))
24006 : : {
24007 : 43 : edge e;
24008 : 43 : edge_iterator ei;
24009 : :
24010 : 56 : FOR_EACH_EDGE (e, ei, bb->preds)
24011 : 146 : if (EDGE_FREQUENCY (e) && e->src->index >= 0
24012 : 97 : && !(e->flags & EDGE_FALLTHRU))
24013 : : {
24014 : : replace = true;
24015 : : break;
24016 : : }
24017 : : }
24018 : 43 : if (!replace)
24019 : : {
24020 : 45031 : prev = prev_active_insn (ret);
24021 : 45031 : if (prev
24022 : 45031 : && ((JUMP_P (prev) && any_condjump_p (prev))
24023 : 44601 : || CALL_P (prev)))
24024 : : replace = true;
24025 : : /* Empty functions get branch mispredict even when
24026 : : the jump destination is not visible to us. */
24027 : 45031 : if (!prev && !optimize_function_for_size_p (cfun))
24028 : : replace = true;
24029 : : }
24030 : 44619 : if (replace)
24031 : : {
24032 : 483 : emit_jump_insn_before (gen_simple_return_internal_long (), ret);
24033 : 483 : delete_insn (ret);
24034 : : }
24035 : : }
24036 : 45066 : }
24037 : :
24038 : : /* Count the minimum number of instructions in BB. Return 4 if the
24039 : : number of instructions >= 4. */
24040 : :
24041 : : static int
24042 : 42 : ix86_count_insn_bb (basic_block bb)
24043 : : {
24044 : 42 : rtx_insn *insn;
24045 : 42 : int insn_count = 0;
24046 : :
24047 : : /* Count number of instructions in this block. Return 4 if the number
24048 : : of instructions >= 4. */
24049 : 308 : FOR_BB_INSNS (bb, insn)
24050 : : {
24051 : : /* Only happen in exit blocks. */
24052 : 302 : if (JUMP_P (insn)
24053 : 302 : && ANY_RETURN_P (PATTERN (insn)))
24054 : : break;
24055 : :
24056 : 278 : if (NONDEBUG_INSN_P (insn)
24057 : 102 : && GET_CODE (PATTERN (insn)) != USE
24058 : 362 : && GET_CODE (PATTERN (insn)) != CLOBBER)
24059 : : {
24060 : 84 : insn_count++;
24061 : 84 : if (insn_count >= 4)
24062 : : return insn_count;
24063 : : }
24064 : : }
24065 : :
24066 : : return insn_count;
24067 : : }
24068 : :
24069 : :
24070 : : /* Count the minimum number of instructions in code path in BB.
24071 : : Return 4 if the number of instructions >= 4. */
24072 : :
24073 : : static int
24074 : 64 : ix86_count_insn (basic_block bb)
24075 : : {
24076 : 64 : edge e;
24077 : 64 : edge_iterator ei;
24078 : 64 : int min_prev_count;
24079 : :
24080 : : /* Only bother counting instructions along paths with no
24081 : : more than 2 basic blocks between entry and exit. Given
24082 : : that BB has an edge to exit, determine if a predecessor
24083 : : of BB has an edge from entry. If so, compute the number
24084 : : of instructions in the predecessor block. If there
24085 : : happen to be multiple such blocks, compute the minimum. */
24086 : 64 : min_prev_count = 4;
24087 : 148 : FOR_EACH_EDGE (e, ei, bb->preds)
24088 : : {
24089 : 110 : edge prev_e;
24090 : 110 : edge_iterator prev_ei;
24091 : :
24092 : 110 : if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
24093 : : {
24094 : 26 : min_prev_count = 0;
24095 : 26 : break;
24096 : : }
24097 : 186 : FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds)
24098 : : {
24099 : 112 : if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
24100 : : {
24101 : 10 : int count = ix86_count_insn_bb (e->src);
24102 : 10 : if (count < min_prev_count)
24103 : 84 : min_prev_count = count;
24104 : : break;
24105 : : }
24106 : : }
24107 : : }
24108 : :
24109 : 64 : if (min_prev_count < 4)
24110 : 32 : min_prev_count += ix86_count_insn_bb (bb);
24111 : :
24112 : 64 : return min_prev_count;
24113 : : }
24114 : :
24115 : : /* Pad short function to 4 instructions. */
24116 : :
24117 : : static void
24118 : 65 : ix86_pad_short_function (void)
24119 : : {
24120 : 65 : edge e;
24121 : 65 : edge_iterator ei;
24122 : :
24123 : 132 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
24124 : : {
24125 : 67 : rtx_insn *ret = BB_END (e->src);
24126 : 67 : if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret)))
24127 : : {
24128 : 64 : int insn_count = ix86_count_insn (e->src);
24129 : :
24130 : : /* Pad short function. */
24131 : 64 : if (insn_count < 4)
24132 : : {
24133 : : rtx_insn *insn = ret;
24134 : :
24135 : : /* Find epilogue. */
24136 : : while (insn
24137 : 54 : && (!NOTE_P (insn)
24138 : 25 : || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG))
24139 : 31 : insn = PREV_INSN (insn);
24140 : :
24141 : 23 : if (!insn)
24142 : 0 : insn = ret;
24143 : :
24144 : : /* Two NOPs count as one instruction. */
24145 : 23 : insn_count = 2 * (4 - insn_count);
24146 : 23 : emit_insn_before (gen_nops (GEN_INT (insn_count)), insn);
24147 : : }
24148 : : }
24149 : : }
24150 : 65 : }
24151 : :
24152 : : /* Fix up a Windows system unwinder issue. If an EH region falls through into
24153 : : the epilogue, the Windows system unwinder will apply epilogue logic and
24154 : : produce incorrect offsets. This can be avoided by adding a nop between
24155 : : the last insn that can throw and the first insn of the epilogue. */
24156 : :
24157 : : static void
24158 : 0 : ix86_seh_fixup_eh_fallthru (void)
24159 : : {
24160 : 0 : edge e;
24161 : 0 : edge_iterator ei;
24162 : :
24163 : 0 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
24164 : : {
24165 : 0 : rtx_insn *insn, *next;
24166 : :
24167 : : /* Find the beginning of the epilogue. */
24168 : 0 : for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn))
24169 : 0 : if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
24170 : : break;
24171 : 0 : if (insn == NULL)
24172 : 0 : continue;
24173 : :
24174 : : /* We only care about preceding insns that can throw. */
24175 : 0 : insn = prev_active_insn (insn);
24176 : 0 : if (insn == NULL || !can_throw_internal (insn))
24177 : 0 : continue;
24178 : :
24179 : : /* Do not separate calls from their debug information. */
24180 : 0 : for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next))
24181 : 0 : if (NOTE_P (next) && NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION)
24182 : 0 : insn = next;
24183 : : else
24184 : : break;
24185 : :
24186 : 0 : emit_insn_after (gen_nops (const1_rtx), insn);
24187 : : }
24188 : 0 : }
24189 : : /* Split vector load from parm_decl to elemental loads to avoid STLF
24190 : : stalls. */
24191 : : static void
24192 : 953131 : ix86_split_stlf_stall_load ()
24193 : : {
24194 : 953131 : rtx_insn* insn, *start = get_insns ();
24195 : 953131 : unsigned window = 0;
24196 : :
24197 : 27043308 : for (insn = start; insn; insn = NEXT_INSN (insn))
24198 : : {
24199 : 27042474 : if (!NONDEBUG_INSN_P (insn))
24200 : 15365110 : continue;
24201 : 11677364 : window++;
24202 : : /* Insert 64 vaddps %xmm18, %xmm19, %xmm20(no dependence between each
24203 : : other, just emulate for pipeline) before stalled load, stlf stall
24204 : : case is as fast as no stall cases on CLX.
24205 : : Since CFG is freed before machine_reorg, just do a rough
24206 : : calculation of the window according to the layout. */
24207 : 11677364 : if (window > (unsigned) x86_stlf_window_ninsns)
24208 : : return;
24209 : :
24210 : 11659126 : if (any_uncondjump_p (insn)
24211 : 11622705 : || ANY_RETURN_P (PATTERN (insn))
24212 : 22919054 : || CALL_P (insn))
24213 : : return;
24214 : :
24215 : 10725067 : rtx set = single_set (insn);
24216 : 10725067 : if (!set)
24217 : 386243 : continue;
24218 : 10338824 : rtx src = SET_SRC (set);
24219 : 20677486 : if (!MEM_P (src)
24220 : : /* Only handle V2DFmode load since it doesn't need any scratch
24221 : : register. */
24222 : 10338824 : || GET_MODE (src) != E_V2DFmode
24223 : 5381 : || !MEM_EXPR (src)
24224 : 10342736 : || TREE_CODE (get_base_address (MEM_EXPR (src))) != PARM_DECL)
24225 : 10338662 : continue;
24226 : :
24227 : 162 : rtx zero = CONST0_RTX (V2DFmode);
24228 : 162 : rtx dest = SET_DEST (set);
24229 : 162 : rtx m = adjust_address (src, DFmode, 0);
24230 : 162 : rtx loadlpd = gen_sse2_loadlpd (dest, zero, m);
24231 : 162 : emit_insn_before (loadlpd, insn);
24232 : 162 : m = adjust_address (src, DFmode, 8);
24233 : 162 : rtx loadhpd = gen_sse2_loadhpd (dest, dest, m);
24234 : 162 : if (dump_file && (dump_flags & TDF_DETAILS))
24235 : : {
24236 : 0 : fputs ("Due to potential STLF stall, split instruction:\n",
24237 : : dump_file);
24238 : 0 : print_rtl_single (dump_file, insn);
24239 : 0 : fputs ("To:\n", dump_file);
24240 : 0 : print_rtl_single (dump_file, loadlpd);
24241 : 0 : print_rtl_single (dump_file, loadhpd);
24242 : : }
24243 : 162 : PATTERN (insn) = loadhpd;
24244 : 162 : INSN_CODE (insn) = -1;
24245 : 162 : gcc_assert (recog_memoized (insn) != -1);
24246 : : }
24247 : : }
24248 : :
24249 : : /* Implement machine specific optimizations. We implement padding of returns
24250 : : for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window. */
24251 : : static void
24252 : 1440898 : ix86_reorg (void)
24253 : : {
24254 : : /* We are freeing block_for_insn in the toplev to keep compatibility
24255 : : with old MDEP_REORGS that are not CFG based. Recompute it now. */
24256 : 1440898 : compute_bb_for_insn ();
24257 : :
24258 : 1440898 : if (TARGET_SEH && current_function_has_exception_handlers ())
24259 : : ix86_seh_fixup_eh_fallthru ();
24260 : :
24261 : 1440898 : if (optimize && optimize_function_for_speed_p (cfun))
24262 : : {
24263 : 955405 : if (TARGET_SSE2)
24264 : 953131 : ix86_split_stlf_stall_load ();
24265 : 955405 : if (TARGET_PAD_SHORT_FUNCTION)
24266 : 65 : ix86_pad_short_function ();
24267 : 955340 : else if (TARGET_PAD_RETURNS)
24268 : 45066 : ix86_pad_returns ();
24269 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
24270 : 955405 : if (TARGET_FOUR_JUMP_LIMIT)
24271 : 45348 : ix86_avoid_jump_mispredicts ();
24272 : : #endif
24273 : : }
24274 : 1440898 : }
24275 : :
24276 : : /* Return nonzero when QImode register that must be represented via REX prefix
24277 : : is used. */
24278 : : bool
24279 : 9036793 : x86_extended_QIreg_mentioned_p (rtx_insn *insn)
24280 : : {
24281 : 9036793 : int i;
24282 : 9036793 : extract_insn_cached (insn);
24283 : 34076285 : for (i = 0; i < recog_data.n_operands; i++)
24284 : 4828575 : if (GENERAL_REG_P (recog_data.operand[i])
24285 : 22533491 : && !QI_REGNO_P (REGNO (recog_data.operand[i])))
24286 : : return true;
24287 : : return false;
24288 : : }
24289 : :
24290 : : /* Return true when INSN mentions register that must be encoded using REX
24291 : : prefix. */
24292 : : bool
24293 : 189417802 : x86_extended_reg_mentioned_p (rtx insn)
24294 : : {
24295 : 189417802 : subrtx_iterator::array_type array;
24296 : 982836969 : FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
24297 : : {
24298 : 840964046 : const_rtx x = *iter;
24299 : 840964046 : if (REG_P (x)
24300 : 840964046 : && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x))
24301 : 241231226 : || REX2_INT_REGNO_P (REGNO (x))))
24302 : 47544879 : return true;
24303 : : }
24304 : 141872923 : return false;
24305 : 189417802 : }
24306 : :
24307 : : /* Return true when INSN mentions register that must be encoded using REX2
24308 : : prefix. */
24309 : : bool
24310 : 1939613 : x86_extended_rex2reg_mentioned_p (rtx insn)
24311 : : {
24312 : 1939613 : subrtx_iterator::array_type array;
24313 : 9166162 : FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
24314 : : {
24315 : 7227217 : const_rtx x = *iter;
24316 : 7227217 : if (REG_P (x) && REX2_INT_REGNO_P (REGNO (x)))
24317 : 668 : return true;
24318 : : }
24319 : 1938945 : return false;
24320 : 1939613 : }
24321 : :
24322 : : /* Return true when rtx operands mentions register that must be encoded using
24323 : : evex prefix. */
24324 : : bool
24325 : 8 : x86_evex_reg_mentioned_p (rtx operands[], int nops)
24326 : : {
24327 : 8 : int i;
24328 : 20 : for (i = 0; i < nops; i++)
24329 : 16 : if (EXT_REX_SSE_REG_P (operands[i])
24330 : 28 : || x86_extended_rex2reg_mentioned_p (operands[i]))
24331 : 4 : return true;
24332 : : return false;
24333 : : }
24334 : :
24335 : : /* If profitable, negate (without causing overflow) integer constant
24336 : : of mode MODE at location LOC. Return true in this case. */
24337 : : bool
24338 : 5744988 : x86_maybe_negate_const_int (rtx *loc, machine_mode mode)
24339 : : {
24340 : 5744988 : HOST_WIDE_INT val;
24341 : :
24342 : 5744988 : if (!CONST_INT_P (*loc))
24343 : : return false;
24344 : :
24345 : 4870224 : switch (mode)
24346 : : {
24347 : 2751419 : case E_DImode:
24348 : : /* DImode x86_64 constants must fit in 32 bits. */
24349 : 2751419 : gcc_assert (x86_64_immediate_operand (*loc, mode));
24350 : :
24351 : : mode = SImode;
24352 : : break;
24353 : :
24354 : : case E_SImode:
24355 : : case E_HImode:
24356 : : case E_QImode:
24357 : : break;
24358 : :
24359 : 0 : default:
24360 : 0 : gcc_unreachable ();
24361 : : }
24362 : :
24363 : : /* Avoid overflows. */
24364 : 4870224 : if (mode_signbit_p (mode, *loc))
24365 : : return false;
24366 : :
24367 : 4869837 : val = INTVAL (*loc);
24368 : :
24369 : : /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
24370 : : Exceptions: -128 encodes smaller than 128, so swap sign and op. */
24371 : 4869837 : if ((val < 0 && val != -128)
24372 : 3200436 : || val == 128)
24373 : : {
24374 : 1680654 : *loc = GEN_INT (-val);
24375 : 1680654 : return true;
24376 : : }
24377 : :
24378 : : return false;
24379 : : }
24380 : :
24381 : : /* Generate an unsigned DImode/SImode to FP conversion. This is the same code
24382 : : optabs would emit if we didn't have TFmode patterns. */
24383 : :
24384 : : void
24385 : 4630 : x86_emit_floatuns (rtx operands[2])
24386 : : {
24387 : 4630 : rtx_code_label *neglab, *donelab;
24388 : 4630 : rtx i0, i1, f0, in, out;
24389 : 4630 : machine_mode mode, inmode;
24390 : :
24391 : 4630 : inmode = GET_MODE (operands[1]);
24392 : 4630 : gcc_assert (inmode == SImode || inmode == DImode);
24393 : :
24394 : 4630 : out = operands[0];
24395 : 4630 : in = force_reg (inmode, operands[1]);
24396 : 4630 : mode = GET_MODE (out);
24397 : 4630 : neglab = gen_label_rtx ();
24398 : 4630 : donelab = gen_label_rtx ();
24399 : 4630 : f0 = gen_reg_rtx (mode);
24400 : :
24401 : 4630 : emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
24402 : :
24403 : 4630 : expand_float (out, in, 0);
24404 : :
24405 : 4630 : emit_jump_insn (gen_jump (donelab));
24406 : 4630 : emit_barrier ();
24407 : :
24408 : 4630 : emit_label (neglab);
24409 : :
24410 : 4630 : i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
24411 : : 1, OPTAB_DIRECT);
24412 : 4630 : i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
24413 : : 1, OPTAB_DIRECT);
24414 : 4630 : i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
24415 : :
24416 : 4630 : expand_float (f0, i0, 0);
24417 : :
24418 : 4630 : emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0)));
24419 : :
24420 : 4630 : emit_label (donelab);
24421 : 4630 : }
24422 : :
24423 : : /* Return the diagnostic message string if conversion from FROMTYPE to
24424 : : TOTYPE is not allowed, NULL otherwise. */
24425 : :
24426 : : static const char *
24427 : 936271690 : ix86_invalid_conversion (const_tree fromtype, const_tree totype)
24428 : : {
24429 : 936271690 : machine_mode from_mode = element_mode (fromtype);
24430 : 936271690 : machine_mode to_mode = element_mode (totype);
24431 : :
24432 : 936271690 : if (!TARGET_SSE2 && from_mode != to_mode)
24433 : : {
24434 : : /* Do no allow conversions to/from BFmode/HFmode scalar types
24435 : : when TARGET_SSE2 is not available. */
24436 : 453977 : if (from_mode == BFmode)
24437 : : return N_("invalid conversion from type %<__bf16%> "
24438 : : "without option %<-msse2%>");
24439 : 453976 : if (from_mode == HFmode)
24440 : : return N_("invalid conversion from type %<_Float16%> "
24441 : : "without option %<-msse2%>");
24442 : 453976 : if (to_mode == BFmode)
24443 : : return N_("invalid conversion to type %<__bf16%> "
24444 : : "without option %<-msse2%>");
24445 : 453976 : if (to_mode == HFmode)
24446 : : return N_("invalid conversion to type %<_Float16%> "
24447 : : "without option %<-msse2%>");
24448 : : }
24449 : :
24450 : : /* Warn for silent implicit conversion between __bf16 and short,
24451 : : since __bfloat16 is refined as real __bf16 instead of short
24452 : : since GCC13. */
24453 : 936271688 : if (element_mode (fromtype) != element_mode (totype)
24454 : 936271688 : && (TARGET_AVX512BF16 || TARGET_AVXNECONVERT))
24455 : : {
24456 : : /* Warn for silent implicit conversion where user may expect
24457 : : a bitcast. */
24458 : 6823792 : if ((TYPE_MODE (fromtype) == BFmode
24459 : 13 : && TYPE_MODE (totype) == HImode)
24460 : 6823804 : || (TYPE_MODE (totype) == BFmode
24461 : 39 : && TYPE_MODE (fromtype) == HImode))
24462 : 1 : warning (0, "%<__bfloat16%> is redefined from typedef %<short%> "
24463 : : "to real %<__bf16%> since GCC 13.1, be careful of "
24464 : : "implicit conversion between %<__bf16%> and %<short%>; "
24465 : : "an explicit bitcast may be needed here");
24466 : : }
24467 : :
24468 : : /* Conversion allowed. */
24469 : : return NULL;
24470 : : }
24471 : :
24472 : : /* Return the diagnostic message string if the unary operation OP is
24473 : : not permitted on TYPE, NULL otherwise. */
24474 : :
24475 : : static const char *
24476 : 85869438 : ix86_invalid_unary_op (int op, const_tree type)
24477 : : {
24478 : 85869438 : machine_mode mmode = element_mode (type);
24479 : : /* Reject all single-operand operations on BFmode/HFmode except for &
24480 : : when TARGET_SSE2 is not available. */
24481 : 85869438 : if (!TARGET_SSE2 && op != ADDR_EXPR)
24482 : : {
24483 : 107884 : if (mmode == BFmode)
24484 : : return N_("operation not permitted on type %<__bf16%> "
24485 : : "without option %<-msse2%>");
24486 : 107884 : if (mmode == HFmode)
24487 : 0 : return N_("operation not permitted on type %<_Float16%> "
24488 : : "without option %<-msse2%>");
24489 : : }
24490 : :
24491 : : /* Operation allowed. */
24492 : : return NULL;
24493 : : }
24494 : :
24495 : : /* Return the diagnostic message string if the binary operation OP is
24496 : : not permitted on TYPE1 and TYPE2, NULL otherwise. */
24497 : :
24498 : : static const char *
24499 : 134917493 : ix86_invalid_binary_op (int op ATTRIBUTE_UNUSED, const_tree type1,
24500 : : const_tree type2)
24501 : : {
24502 : 134917493 : machine_mode type1_mode = element_mode (type1);
24503 : 134917493 : machine_mode type2_mode = element_mode (type2);
24504 : : /* Reject all 2-operand operations on BFmode or HFmode
24505 : : when TARGET_SSE2 is not available. */
24506 : 134917493 : if (!TARGET_SSE2)
24507 : : {
24508 : 981048 : if (type1_mode == BFmode || type2_mode == BFmode)
24509 : : return N_("operation not permitted on type %<__bf16%> "
24510 : : "without option %<-msse2%>");
24511 : :
24512 : 981048 : if (type1_mode == HFmode || type2_mode == HFmode)
24513 : 0 : return N_("operation not permitted on type %<_Float16%> "
24514 : : "without option %<-msse2%>");
24515 : : }
24516 : :
24517 : : /* Operation allowed. */
24518 : : return NULL;
24519 : : }
24520 : :
24521 : :
24522 : : /* Target hook for scalar_mode_supported_p. */
24523 : : static bool
24524 : 4195255 : ix86_scalar_mode_supported_p (scalar_mode mode)
24525 : : {
24526 : 4195255 : if (DECIMAL_FLOAT_MODE_P (mode))
24527 : 603222 : return default_decimal_float_supported_p ();
24528 : 3592033 : else if (mode == TFmode)
24529 : : return true;
24530 : 3282113 : else if (mode == HFmode || mode == BFmode)
24531 : : return true;
24532 : : else
24533 : 2664256 : return default_scalar_mode_supported_p (mode);
24534 : : }
24535 : :
24536 : : /* Implement TARGET_LIBGCC_FLOATING_POINT_MODE_SUPPORTED_P - return TRUE
24537 : : if MODE is HFmode, and punt to the generic implementation otherwise. */
24538 : :
24539 : : static bool
24540 : 2127661 : ix86_libgcc_floating_mode_supported_p (scalar_float_mode mode)
24541 : : {
24542 : : /* NB: Always return TRUE for HFmode so that the _Float16 type will
24543 : : be defined by the C front-end for AVX512FP16 intrinsics. We will
24544 : : issue an error in ix86_expand_move for HFmode if AVX512FP16 isn't
24545 : : enabled. */
24546 : 1819208 : return ((mode == HFmode || mode == BFmode)
24547 : 3638416 : ? true
24548 : 1510755 : : default_libgcc_floating_mode_supported_p (mode));
24549 : : }
24550 : :
24551 : : /* Implements target hook vector_mode_supported_p. */
24552 : : static bool
24553 : 1288760346 : ix86_vector_mode_supported_p (machine_mode mode)
24554 : : {
24555 : : /* For ia32, scalar TImode isn't supported and so V1TImode shouldn't be
24556 : : either. */
24557 : 1427817565 : if (!TARGET_64BIT && GET_MODE_INNER (mode) == TImode)
24558 : : return false;
24559 : 1288760178 : if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
24560 : : return true;
24561 : 1084878795 : if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
24562 : : return true;
24563 : 472238930 : if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
24564 : : return true;
24565 : 338040939 : if (TARGET_AVX512F && TARGET_EVEX512 && VALID_AVX512F_REG_MODE (mode))
24566 : : return true;
24567 : 211929418 : if ((TARGET_MMX || TARGET_MMX_WITH_SSE)
24568 : 211873267 : && VALID_MMX_REG_MODE (mode))
24569 : : return true;
24570 : 26914215 : if ((TARGET_3DNOW || TARGET_MMX_WITH_SSE)
24571 : 26302193 : && VALID_MMX_REG_MODE_3DNOW (mode))
24572 : : return true;
24573 : 18045590 : if (mode == V2QImode)
24574 : 22878 : return true;
24575 : : return false;
24576 : : }
24577 : :
24578 : : /* Target hook for c_mode_for_suffix. */
24579 : : static machine_mode
24580 : 79629 : ix86_c_mode_for_suffix (char suffix)
24581 : : {
24582 : 79629 : if (suffix == 'q')
24583 : : return TFmode;
24584 : 37 : if (suffix == 'w')
24585 : : return XFmode;
24586 : :
24587 : 0 : return VOIDmode;
24588 : : }
24589 : :
24590 : : /* Helper function to map common constraints to non-EGPR ones.
24591 : : All related constraints have h prefix, and h plus Upper letter
24592 : : means the constraint is strictly EGPR enabled, while h plus
24593 : : lower letter indicates the constraint is strictly gpr16 only.
24594 : :
24595 : : Specially for "g" constraint, split it to rmi as there is
24596 : : no corresponding general constraint define for backend.
24597 : :
24598 : : Here is the full list to map constraints that may involve
24599 : : gpr to h prefixed.
24600 : :
24601 : : "g" -> "jrjmi"
24602 : : "r" -> "jr"
24603 : : "m" -> "jm"
24604 : : "<" -> "j<"
24605 : : ">" -> "j>"
24606 : : "o" -> "jo"
24607 : : "V" -> "jV"
24608 : : "p" -> "jp"
24609 : : "Bm" -> "ja"
24610 : : */
24611 : :
24612 : 45 : static void map_egpr_constraints (vec<const char *> &constraints)
24613 : : {
24614 : 55 : for (size_t i = 0; i < constraints.length(); i++)
24615 : : {
24616 : 10 : const char *cur = constraints[i];
24617 : :
24618 : 10 : if (startswith (cur, "=@cc"))
24619 : 0 : continue;
24620 : :
24621 : 10 : int len = strlen (cur);
24622 : 10 : auto_vec<char> buf;
24623 : :
24624 : 24 : for (int j = 0; j < len; j++)
24625 : : {
24626 : 14 : switch (cur[j])
24627 : : {
24628 : 2 : case 'g':
24629 : 2 : buf.safe_push ('j');
24630 : 2 : buf.safe_push ('r');
24631 : 2 : buf.safe_push ('j');
24632 : 2 : buf.safe_push ('m');
24633 : 2 : buf.safe_push ('i');
24634 : 2 : break;
24635 : 8 : case 'r':
24636 : 8 : case 'm':
24637 : 8 : case '<':
24638 : 8 : case '>':
24639 : 8 : case 'o':
24640 : 8 : case 'V':
24641 : 8 : case 'p':
24642 : 8 : buf.safe_push ('j');
24643 : 8 : buf.safe_push (cur[j]);
24644 : 8 : break;
24645 : 0 : case 'B':
24646 : 0 : if (cur[j + 1] == 'm')
24647 : : {
24648 : 0 : buf.safe_push ('j');
24649 : 0 : buf.safe_push ('a');
24650 : 0 : j++;
24651 : : }
24652 : : else
24653 : : {
24654 : 0 : buf.safe_push (cur[j]);
24655 : 0 : buf.safe_push (cur[j + 1]);
24656 : 0 : j++;
24657 : : }
24658 : : break;
24659 : 0 : case 'T':
24660 : 0 : case 'Y':
24661 : 0 : case 'W':
24662 : 0 : case 'j':
24663 : 0 : buf.safe_push (cur[j]);
24664 : 0 : buf.safe_push (cur[j + 1]);
24665 : 0 : j++;
24666 : 0 : break;
24667 : 4 : default:
24668 : 4 : buf.safe_push (cur[j]);
24669 : 4 : break;
24670 : : }
24671 : : }
24672 : 10 : buf.safe_push ('\0');
24673 : 20 : constraints[i] = xstrdup (buf.address ());
24674 : 10 : }
24675 : 45 : }
24676 : :
24677 : : /* Worker function for TARGET_MD_ASM_ADJUST.
24678 : :
24679 : : We implement asm flag outputs, and maintain source compatibility
24680 : : with the old cc0-based compiler. */
24681 : :
24682 : : static rtx_insn *
24683 : 104320 : ix86_md_asm_adjust (vec<rtx> &outputs, vec<rtx> & /*inputs*/,
24684 : : vec<machine_mode> & /*input_modes*/,
24685 : : vec<const char *> &constraints, vec<rtx> &/*uses*/,
24686 : : vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs,
24687 : : location_t loc)
24688 : : {
24689 : 104320 : bool saw_asm_flag = false;
24690 : :
24691 : 104320 : start_sequence ();
24692 : :
24693 : 104320 : if (TARGET_APX_EGPR && !ix86_apx_inline_asm_use_gpr32)
24694 : 45 : map_egpr_constraints (constraints);
24695 : :
24696 : 278593 : for (unsigned i = 0, n = outputs.length (); i < n; ++i)
24697 : : {
24698 : 70745 : const char *con = constraints[i];
24699 : 70745 : if (!startswith (con, "=@cc"))
24700 : 70658 : continue;
24701 : 87 : con += 4;
24702 : 87 : if (strchr (con, ',') != NULL)
24703 : : {
24704 : 1 : error_at (loc, "alternatives not allowed in %<asm%> flag output");
24705 : 1 : continue;
24706 : : }
24707 : :
24708 : 86 : bool invert = false;
24709 : 86 : if (con[0] == 'n')
24710 : 19 : invert = true, con++;
24711 : :
24712 : 86 : machine_mode mode = CCmode;
24713 : 86 : rtx_code code = UNKNOWN;
24714 : :
24715 : 86 : switch (con[0])
24716 : : {
24717 : 15 : case 'a':
24718 : 15 : if (con[1] == 0)
24719 : : mode = CCAmode, code = EQ;
24720 : 4 : else if (con[1] == 'e' && con[2] == 0)
24721 : : mode = CCCmode, code = NE;
24722 : : break;
24723 : 11 : case 'b':
24724 : 11 : if (con[1] == 0)
24725 : : mode = CCCmode, code = EQ;
24726 : 6 : else if (con[1] == 'e' && con[2] == 0)
24727 : : mode = CCAmode, code = NE;
24728 : : break;
24729 : 14 : case 'c':
24730 : 14 : if (con[1] == 0)
24731 : : mode = CCCmode, code = EQ;
24732 : : break;
24733 : 8 : case 'e':
24734 : 8 : if (con[1] == 0)
24735 : : mode = CCZmode, code = EQ;
24736 : : break;
24737 : 11 : case 'g':
24738 : 11 : if (con[1] == 0)
24739 : : mode = CCGCmode, code = GT;
24740 : 5 : else if (con[1] == 'e' && con[2] == 0)
24741 : : mode = CCGCmode, code = GE;
24742 : : break;
24743 : 10 : case 'l':
24744 : 10 : if (con[1] == 0)
24745 : : mode = CCGCmode, code = LT;
24746 : 5 : else if (con[1] == 'e' && con[2] == 0)
24747 : : mode = CCGCmode, code = LE;
24748 : : break;
24749 : 4 : case 'o':
24750 : 4 : if (con[1] == 0)
24751 : : mode = CCOmode, code = EQ;
24752 : : break;
24753 : 4 : case 'p':
24754 : 4 : if (con[1] == 0)
24755 : : mode = CCPmode, code = EQ;
24756 : : break;
24757 : 4 : case 's':
24758 : 4 : if (con[1] == 0)
24759 : : mode = CCSmode, code = EQ;
24760 : : break;
24761 : 5 : case 'z':
24762 : 5 : if (con[1] == 0)
24763 : : mode = CCZmode, code = EQ;
24764 : : break;
24765 : : }
24766 : 1 : if (code == UNKNOWN)
24767 : : {
24768 : 1 : error_at (loc, "unknown %<asm%> flag output %qs", constraints[i]);
24769 : 1 : continue;
24770 : : }
24771 : 85 : if (invert)
24772 : 19 : code = reverse_condition (code);
24773 : :
24774 : 85 : rtx dest = outputs[i];
24775 : 85 : if (!saw_asm_flag)
24776 : : {
24777 : : /* This is the first asm flag output. Here we put the flags
24778 : : register in as the real output and adjust the condition to
24779 : : allow it. */
24780 : 74 : constraints[i] = "=Bf";
24781 : 74 : outputs[i] = gen_rtx_REG (CCmode, FLAGS_REG);
24782 : 74 : saw_asm_flag = true;
24783 : : }
24784 : : else
24785 : : {
24786 : : /* We don't need the flags register as output twice. */
24787 : 11 : constraints[i] = "=X";
24788 : 11 : outputs[i] = gen_rtx_SCRATCH (SImode);
24789 : : }
24790 : :
24791 : 85 : rtx x = gen_rtx_REG (mode, FLAGS_REG);
24792 : 85 : x = gen_rtx_fmt_ee (code, QImode, x, const0_rtx);
24793 : :
24794 : 85 : machine_mode dest_mode = GET_MODE (dest);
24795 : 85 : if (!SCALAR_INT_MODE_P (dest_mode))
24796 : : {
24797 : 3 : error_at (loc, "invalid type for %<asm%> flag output");
24798 : 3 : continue;
24799 : : }
24800 : :
24801 : 82 : if (dest_mode == QImode)
24802 : 72 : emit_insn (gen_rtx_SET (dest, x));
24803 : : else
24804 : : {
24805 : 10 : rtx reg = gen_reg_rtx (QImode);
24806 : 10 : emit_insn (gen_rtx_SET (reg, x));
24807 : :
24808 : 10 : reg = convert_to_mode (dest_mode, reg, 1);
24809 : 10 : emit_move_insn (dest, reg);
24810 : : }
24811 : : }
24812 : :
24813 : 104320 : rtx_insn *seq = get_insns ();
24814 : 104320 : end_sequence ();
24815 : :
24816 : 104320 : if (saw_asm_flag)
24817 : : return seq;
24818 : : else
24819 : : {
24820 : : /* If we had no asm flag outputs, clobber the flags. */
24821 : 104246 : clobbers.safe_push (gen_rtx_REG (CCmode, FLAGS_REG));
24822 : 104246 : SET_HARD_REG_BIT (clobbered_regs, FLAGS_REG);
24823 : 104246 : return NULL;
24824 : : }
24825 : : }
24826 : :
24827 : : /* Implements target vector targetm.asm.encode_section_info. */
24828 : :
24829 : : static void ATTRIBUTE_UNUSED
24830 : 9691489 : ix86_encode_section_info (tree decl, rtx rtl, int first)
24831 : : {
24832 : 9691489 : default_encode_section_info (decl, rtl, first);
24833 : :
24834 : 9691489 : if (ix86_in_large_data_p (decl))
24835 : 32 : SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
24836 : 9691489 : }
24837 : :
24838 : : /* Worker function for REVERSE_CONDITION. */
24839 : :
24840 : : enum rtx_code
24841 : 30480496 : ix86_reverse_condition (enum rtx_code code, machine_mode mode)
24842 : : {
24843 : 30480496 : return (mode == CCFPmode
24844 : 30480496 : ? reverse_condition_maybe_unordered (code)
24845 : 26211885 : : reverse_condition (code));
24846 : : }
24847 : :
24848 : : /* Output code to perform an x87 FP register move, from OPERANDS[1]
24849 : : to OPERANDS[0]. */
24850 : :
24851 : : const char *
24852 : 660880 : output_387_reg_move (rtx_insn *insn, rtx *operands)
24853 : : {
24854 : 660880 : if (REG_P (operands[0]))
24855 : : {
24856 : 553086 : if (REG_P (operands[1])
24857 : 553086 : && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
24858 : : {
24859 : 303371 : if (REGNO (operands[0]) == FIRST_STACK_REG)
24860 : 282649 : return output_387_ffreep (operands, 0);
24861 : : return "fstp\t%y0";
24862 : : }
24863 : 249715 : if (STACK_TOP_P (operands[0]))
24864 : 249715 : return "fld%Z1\t%y1";
24865 : : return "fst\t%y0";
24866 : : }
24867 : 107794 : else if (MEM_P (operands[0]))
24868 : : {
24869 : 107794 : gcc_assert (REG_P (operands[1]));
24870 : 107794 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
24871 : : return "fstp%Z0\t%y0";
24872 : : else
24873 : : {
24874 : : /* There is no non-popping store to memory for XFmode.
24875 : : So if we need one, follow the store with a load. */
24876 : 7934 : if (GET_MODE (operands[0]) == XFmode)
24877 : : return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
24878 : : else
24879 : 1735 : return "fst%Z0\t%y0";
24880 : : }
24881 : : }
24882 : : else
24883 : 0 : gcc_unreachable();
24884 : : }
24885 : : #ifdef TARGET_SOLARIS
24886 : : /* Solaris implementation of TARGET_ASM_NAMED_SECTION. */
24887 : :
24888 : : static void
24889 : : i386_solaris_elf_named_section (const char *name, unsigned int flags,
24890 : : tree decl)
24891 : : {
24892 : : /* With Binutils 2.15, the "@unwind" marker must be specified on
24893 : : every occurrence of the ".eh_frame" section, not just the first
24894 : : one. */
24895 : : if (TARGET_64BIT
24896 : : && strcmp (name, ".eh_frame") == 0)
24897 : : {
24898 : : fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
24899 : : flags & SECTION_WRITE ? "aw" : "a");
24900 : : return;
24901 : : }
24902 : :
24903 : : #ifndef USE_GAS
24904 : : if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
24905 : : {
24906 : : solaris_elf_asm_comdat_section (name, flags, decl);
24907 : : return;
24908 : : }
24909 : :
24910 : : /* Solaris/x86 as uses the same syntax for the SHF_EXCLUDE flags as the
24911 : : SPARC assembler. One cannot mix single-letter flags and #exclude, so
24912 : : only emit the latter here. */
24913 : : if (flags & SECTION_EXCLUDE)
24914 : : {
24915 : : fprintf (asm_out_file, "\t.section\t%s,#exclude\n", name);
24916 : : return;
24917 : : }
24918 : : #endif
24919 : :
24920 : : default_elf_asm_named_section (name, flags, decl);
24921 : : }
24922 : : #endif /* TARGET_SOLARIS */
24923 : :
24924 : : /* Return the mangling of TYPE if it is an extended fundamental type. */
24925 : :
24926 : : static const char *
24927 : 609179465 : ix86_mangle_type (const_tree type)
24928 : : {
24929 : 609179465 : type = TYPE_MAIN_VARIANT (type);
24930 : :
24931 : 609179465 : if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
24932 : : && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
24933 : : return NULL;
24934 : :
24935 : 323663211 : if (type == float128_type_node || type == float64x_type_node)
24936 : : return NULL;
24937 : :
24938 : 322811746 : switch (TYPE_MODE (type))
24939 : : {
24940 : : case E_BFmode:
24941 : : return "DF16b";
24942 : 339756 : case E_HFmode:
24943 : : /* _Float16 is "DF16_".
24944 : : Align with clang's decision in https://reviews.llvm.org/D33719. */
24945 : 339756 : return "DF16_";
24946 : 387477 : case E_TFmode:
24947 : : /* __float128 is "g". */
24948 : 387477 : return "g";
24949 : 5667404 : case E_XFmode:
24950 : : /* "long double" or __float80 is "e". */
24951 : 5667404 : return "e";
24952 : : default:
24953 : : return NULL;
24954 : : }
24955 : : }
24956 : :
24957 : : /* Create C++ tinfo symbols for only conditionally available fundamental
24958 : : types. */
24959 : :
24960 : : static void
24961 : 5 : ix86_emit_support_tinfos (emit_support_tinfos_callback callback)
24962 : : {
24963 : 5 : extern tree ix86_float16_type_node;
24964 : 5 : extern tree ix86_bf16_type_node;
24965 : :
24966 : 5 : if (!TARGET_SSE2)
24967 : : {
24968 : 0 : if (!float16_type_node)
24969 : 0 : float16_type_node = ix86_float16_type_node;
24970 : 0 : if (!bfloat16_type_node)
24971 : 0 : bfloat16_type_node = ix86_bf16_type_node;
24972 : 0 : callback (float16_type_node);
24973 : 0 : callback (bfloat16_type_node);
24974 : 0 : float16_type_node = NULL_TREE;
24975 : 0 : bfloat16_type_node = NULL_TREE;
24976 : : }
24977 : 5 : }
24978 : :
24979 : : static GTY(()) tree ix86_tls_stack_chk_guard_decl;
24980 : :
24981 : : static tree
24982 : 236 : ix86_stack_protect_guard (void)
24983 : : {
24984 : 236 : if (TARGET_SSP_TLS_GUARD)
24985 : : {
24986 : 233 : tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1);
24987 : 233 : int qual = ENCODE_QUAL_ADDR_SPACE (ix86_stack_protector_guard_reg);
24988 : 233 : tree type = build_qualified_type (type_node, qual);
24989 : 233 : tree t;
24990 : :
24991 : 233 : if (OPTION_SET_P (ix86_stack_protector_guard_symbol_str))
24992 : : {
24993 : 1 : t = ix86_tls_stack_chk_guard_decl;
24994 : :
24995 : 1 : if (t == NULL)
24996 : : {
24997 : 1 : rtx x;
24998 : :
24999 : 1 : t = build_decl
25000 : 1 : (UNKNOWN_LOCATION, VAR_DECL,
25001 : : get_identifier (ix86_stack_protector_guard_symbol_str),
25002 : : type);
25003 : 1 : TREE_STATIC (t) = 1;
25004 : 1 : TREE_PUBLIC (t) = 1;
25005 : 1 : DECL_EXTERNAL (t) = 1;
25006 : 1 : TREE_USED (t) = 1;
25007 : 1 : TREE_THIS_VOLATILE (t) = 1;
25008 : 1 : DECL_ARTIFICIAL (t) = 1;
25009 : 1 : DECL_IGNORED_P (t) = 1;
25010 : :
25011 : : /* Do not share RTL as the declaration is visible outside of
25012 : : current function. */
25013 : 1 : x = DECL_RTL (t);
25014 : 1 : RTX_FLAG (x, used) = 1;
25015 : :
25016 : 1 : ix86_tls_stack_chk_guard_decl = t;
25017 : : }
25018 : : }
25019 : : else
25020 : : {
25021 : 232 : tree asptrtype = build_pointer_type (type);
25022 : :
25023 : 232 : t = build_int_cst (asptrtype, ix86_stack_protector_guard_offset);
25024 : 232 : t = build2 (MEM_REF, asptrtype, t,
25025 : 232 : build_int_cst (asptrtype, 0));
25026 : 232 : TREE_THIS_VOLATILE (t) = 1;
25027 : : }
25028 : :
25029 : 233 : return t;
25030 : : }
25031 : :
25032 : 3 : return default_stack_protect_guard ();
25033 : : }
25034 : :
25035 : : static bool
25036 : 737 : ix86_stack_protect_runtime_enabled_p (void)
25037 : : {
25038 : : /* Naked functions should not enable stack protector. */
25039 : 737 : return !ix86_function_naked (current_function_decl);
25040 : : }
25041 : :
25042 : : /* For 32-bit code we can save PIC register setup by using
25043 : : __stack_chk_fail_local hidden function instead of calling
25044 : : __stack_chk_fail directly. 64-bit code doesn't need to setup any PIC
25045 : : register, so it is better to call __stack_chk_fail directly. */
25046 : :
25047 : : static tree ATTRIBUTE_UNUSED
25048 : 262 : ix86_stack_protect_fail (void)
25049 : : {
25050 : 262 : return TARGET_64BIT
25051 : 262 : ? default_external_stack_protect_fail ()
25052 : 1 : : default_hidden_stack_protect_fail ();
25053 : : }
25054 : :
25055 : : /* Select a format to encode pointers in exception handling data. CODE
25056 : : is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
25057 : : true if the symbol may be affected by dynamic relocations.
25058 : :
25059 : : ??? All x86 object file formats are capable of representing this.
25060 : : After all, the relocation needed is the same as for the call insn.
25061 : : Whether or not a particular assembler allows us to enter such, I
25062 : : guess we'll have to see. */
25063 : :
25064 : : int
25065 : 766412 : asm_preferred_eh_data_format (int code, int global)
25066 : : {
25067 : : /* PE-COFF is effectively always -fPIC because of the .reloc section. */
25068 : 766412 : if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access)
25069 : : {
25070 : 36789 : int type = DW_EH_PE_sdata8;
25071 : 36789 : if (ptr_mode == SImode
25072 : 23058 : || ix86_cmodel == CM_SMALL_PIC
25073 : 36855 : || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
25074 : : type = DW_EH_PE_sdata4;
25075 : 51602 : return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
25076 : : }
25077 : :
25078 : 729623 : if (ix86_cmodel == CM_SMALL
25079 : 18730 : || (ix86_cmodel == CM_MEDIUM && code))
25080 : 710904 : return DW_EH_PE_udata4;
25081 : :
25082 : : return DW_EH_PE_absptr;
25083 : : }
25084 : :
25085 : : /* Implement targetm.vectorize.builtin_vectorization_cost. */
25086 : : static int
25087 : 15596602 : ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
25088 : : tree vectype, int)
25089 : : {
25090 : 15596602 : bool fp = false;
25091 : 15596602 : machine_mode mode = TImode;
25092 : 15596602 : int index;
25093 : 15596602 : if (vectype != NULL)
25094 : : {
25095 : 14631440 : fp = FLOAT_TYPE_P (vectype);
25096 : 14631440 : mode = TYPE_MODE (vectype);
25097 : : }
25098 : :
25099 : 15596602 : switch (type_of_cost)
25100 : : {
25101 : 2721376 : case scalar_stmt:
25102 : 2721376 : return fp ? ix86_cost->addss : COSTS_N_INSNS (1);
25103 : :
25104 : 1896740 : case scalar_load:
25105 : : /* load/store costs are relative to register move which is 2. Recompute
25106 : : it to COSTS_N_INSNS so everything have same base. */
25107 : 3793480 : return COSTS_N_INSNS (fp ? ix86_cost->sse_load[0]
25108 : 1896740 : : ix86_cost->int_load [2]) / 2;
25109 : :
25110 : 3813239 : case scalar_store:
25111 : 7626478 : return COSTS_N_INSNS (fp ? ix86_cost->sse_store[0]
25112 : 3813239 : : ix86_cost->int_store [2]) / 2;
25113 : :
25114 : 981928 : case vector_stmt:
25115 : 1963856 : return ix86_vec_cost (mode,
25116 : 1963856 : fp ? ix86_cost->addss : ix86_cost->sse_op);
25117 : :
25118 : 1767348 : case vector_load:
25119 : 1767348 : index = sse_store_index (mode);
25120 : : /* See PR82713 - we may end up being called on non-vector type. */
25121 : 1767348 : if (index < 0)
25122 : 93788 : index = 2;
25123 : 1767348 : return COSTS_N_INSNS (ix86_cost->sse_load[index]) / 2;
25124 : :
25125 : 1016596 : case vector_store:
25126 : 1016596 : index = sse_store_index (mode);
25127 : : /* See PR82713 - we may end up being called on non-vector type. */
25128 : 1016596 : if (index < 0)
25129 : 89863 : index = 2;
25130 : 1016596 : return COSTS_N_INSNS (ix86_cost->sse_store[index]) / 2;
25131 : :
25132 : 956800 : case vec_to_scalar:
25133 : 956800 : case scalar_to_vec:
25134 : 956800 : return ix86_vec_cost (mode, ix86_cost->sse_op);
25135 : :
25136 : : /* We should have separate costs for unaligned loads and gather/scatter.
25137 : : Do that incrementally. */
25138 : 405544 : case unaligned_load:
25139 : 405544 : index = sse_store_index (mode);
25140 : : /* See PR82713 - we may end up being called on non-vector type. */
25141 : 405544 : if (index < 0)
25142 : 2528 : index = 2;
25143 : 405544 : return COSTS_N_INSNS (ix86_cost->sse_unaligned_load[index]) / 2;
25144 : :
25145 : 784420 : case unaligned_store:
25146 : 784420 : index = sse_store_index (mode);
25147 : : /* See PR82713 - we may end up being called on non-vector type. */
25148 : 784420 : if (index < 0)
25149 : 13714 : index = 2;
25150 : 784420 : return COSTS_N_INSNS (ix86_cost->sse_unaligned_store[index]) / 2;
25151 : :
25152 : 0 : case vector_gather_load:
25153 : 0 : return ix86_vec_cost (mode,
25154 : 0 : COSTS_N_INSNS
25155 : : (ix86_cost->gather_static
25156 : : + ix86_cost->gather_per_elt
25157 : 0 : * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
25158 : :
25159 : 0 : case vector_scatter_store:
25160 : 0 : return ix86_vec_cost (mode,
25161 : 0 : COSTS_N_INSNS
25162 : : (ix86_cost->scatter_static
25163 : : + ix86_cost->scatter_per_elt
25164 : 0 : * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
25165 : :
25166 : 236300 : case cond_branch_taken:
25167 : 236300 : return ix86_cost->cond_taken_branch_cost;
25168 : :
25169 : 4795 : case cond_branch_not_taken:
25170 : 4795 : return ix86_cost->cond_not_taken_branch_cost;
25171 : :
25172 : 248658 : case vec_perm:
25173 : 248658 : return ix86_vec_cost (mode, ix86_cost->sse_op);
25174 : :
25175 : 70576 : case vec_promote_demote:
25176 : 70576 : if (fp)
25177 : 7899 : return vec_fp_conversion_cost (ix86_tune_cost, mode);
25178 : 62677 : return ix86_vec_cost (mode, ix86_cost->sse_op);
25179 : :
25180 : 692282 : case vec_construct:
25181 : 692282 : {
25182 : 692282 : int n = TYPE_VECTOR_SUBPARTS (vectype);
25183 : : /* N - 1 element inserts into an SSE vector, the possible
25184 : : GPR -> XMM move is accounted for in add_stmt_cost. */
25185 : 1384564 : if (GET_MODE_BITSIZE (mode) <= 128)
25186 : 683718 : return (n - 1) * ix86_cost->sse_op;
25187 : : /* One vinserti128 for combining two SSE vectors for AVX256. */
25188 : 17128 : else if (GET_MODE_BITSIZE (mode) == 256)
25189 : 6568 : return ((n - 2) * ix86_cost->sse_op
25190 : 6568 : + ix86_vec_cost (mode, ix86_cost->addss));
25191 : : /* One vinserti64x4 and two vinserti128 for combining SSE
25192 : : and AVX256 vectors to AVX512. */
25193 : 3992 : else if (GET_MODE_BITSIZE (mode) == 512)
25194 : 1996 : return ((n - 4) * ix86_cost->sse_op
25195 : 1996 : + 3 * ix86_vec_cost (mode, ix86_cost->addss));
25196 : 0 : gcc_unreachable ();
25197 : : }
25198 : :
25199 : 0 : default:
25200 : 0 : gcc_unreachable ();
25201 : : }
25202 : : }
25203 : :
25204 : :
25205 : : /* This function returns the calling abi specific va_list type node.
25206 : : It returns the FNDECL specific va_list type. */
25207 : :
25208 : : static tree
25209 : 47056 : ix86_fn_abi_va_list (tree fndecl)
25210 : : {
25211 : 47056 : if (!TARGET_64BIT)
25212 : 698 : return va_list_type_node;
25213 : 46358 : gcc_assert (fndecl != NULL_TREE);
25214 : :
25215 : 46358 : if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
25216 : 12868 : return ms_va_list_type_node;
25217 : : else
25218 : 33490 : return sysv_va_list_type_node;
25219 : : }
25220 : :
25221 : : /* Returns the canonical va_list type specified by TYPE. If there
25222 : : is no valid TYPE provided, it return NULL_TREE. */
25223 : :
25224 : : static tree
25225 : 245500 : ix86_canonical_va_list_type (tree type)
25226 : : {
25227 : 245500 : if (TARGET_64BIT)
25228 : : {
25229 : 244998 : if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type)))
25230 : 5944 : return ms_va_list_type_node;
25231 : :
25232 : 239054 : if ((TREE_CODE (type) == ARRAY_TYPE
25233 : 49752 : && integer_zerop (array_type_nelts_minus_one (type)))
25234 : 239054 : || POINTER_TYPE_P (type))
25235 : : {
25236 : 187394 : tree elem_type = TREE_TYPE (type);
25237 : 187394 : if (TREE_CODE (elem_type) == RECORD_TYPE
25238 : 338270 : && lookup_attribute ("sysv_abi va_list",
25239 : 150876 : TYPE_ATTRIBUTES (elem_type)))
25240 : 150876 : return sysv_va_list_type_node;
25241 : : }
25242 : :
25243 : 88178 : return NULL_TREE;
25244 : : }
25245 : :
25246 : 502 : return std_canonical_va_list_type (type);
25247 : : }
25248 : :
25249 : : /* Iterate through the target-specific builtin types for va_list.
25250 : : IDX denotes the iterator, *PTREE is set to the result type of
25251 : : the va_list builtin, and *PNAME to its internal type.
25252 : : Returns zero if there is no element for this index, otherwise
25253 : : IDX should be increased upon the next call.
25254 : : Note, do not iterate a base builtin's name like __builtin_va_list.
25255 : : Used from c_common_nodes_and_builtins. */
25256 : :
25257 : : static int
25258 : 591558 : ix86_enum_va_list (int idx, const char **pname, tree *ptree)
25259 : : {
25260 : 591558 : if (TARGET_64BIT)
25261 : : {
25262 : 586251 : switch (idx)
25263 : : {
25264 : : default:
25265 : : break;
25266 : :
25267 : 195417 : case 0:
25268 : 195417 : *ptree = ms_va_list_type_node;
25269 : 195417 : *pname = "__builtin_ms_va_list";
25270 : 195417 : return 1;
25271 : :
25272 : 195417 : case 1:
25273 : 195417 : *ptree = sysv_va_list_type_node;
25274 : 195417 : *pname = "__builtin_sysv_va_list";
25275 : 195417 : return 1;
25276 : : }
25277 : : }
25278 : :
25279 : : return 0;
25280 : : }
25281 : :
25282 : : #undef TARGET_SCHED_DISPATCH
25283 : : #define TARGET_SCHED_DISPATCH ix86_bd_has_dispatch
25284 : : #undef TARGET_SCHED_DISPATCH_DO
25285 : : #define TARGET_SCHED_DISPATCH_DO ix86_bd_do_dispatch
25286 : : #undef TARGET_SCHED_REASSOCIATION_WIDTH
25287 : : #define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width
25288 : : #undef TARGET_SCHED_REORDER
25289 : : #define TARGET_SCHED_REORDER ix86_atom_sched_reorder
25290 : : #undef TARGET_SCHED_ADJUST_PRIORITY
25291 : : #define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority
25292 : : #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
25293 : : #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
25294 : : ix86_dependencies_evaluation_hook
25295 : :
25296 : :
25297 : : /* Implementation of reassociation_width target hook used by
25298 : : reassoc phase to identify parallelism level in reassociated
25299 : : tree. Statements tree_code is passed in OPC. Arguments type
25300 : : is passed in MODE. */
25301 : :
25302 : : static int
25303 : 31818 : ix86_reassociation_width (unsigned int op, machine_mode mode)
25304 : : {
25305 : 31818 : int width = 1;
25306 : : /* Vector part. */
25307 : 31818 : if (VECTOR_MODE_P (mode))
25308 : : {
25309 : 7477 : int div = 1;
25310 : 7477 : if (INTEGRAL_MODE_P (mode))
25311 : 2296 : width = ix86_cost->reassoc_vec_int;
25312 : 5181 : else if (FLOAT_MODE_P (mode))
25313 : 5181 : width = ix86_cost->reassoc_vec_fp;
25314 : :
25315 : 7477 : if (width == 1)
25316 : : return 1;
25317 : :
25318 : : /* Znver1-4 Integer vector instructions execute in FP unit
25319 : : and can execute 3 additions and one multiplication per cycle. */
25320 : 7472 : if ((ix86_tune == PROCESSOR_ZNVER1 || ix86_tune == PROCESSOR_ZNVER2
25321 : 7472 : || ix86_tune == PROCESSOR_ZNVER3 || ix86_tune == PROCESSOR_ZNVER4)
25322 : 0 : && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
25323 : : return 1;
25324 : : /* Znver5 can do 2 integer multiplications per cycle with latency
25325 : : of 3. */
25326 : 7472 : if (ix86_tune == PROCESSOR_ZNVER5
25327 : 0 : && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
25328 : 7472 : width = 6;
25329 : :
25330 : : /* Account for targets that splits wide vectors into multiple parts. */
25331 : 7472 : if (TARGET_AVX512_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 256)
25332 : 0 : div = GET_MODE_BITSIZE (mode) / 256;
25333 : 7472 : else if (TARGET_AVX256_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 128)
25334 : 0 : div = GET_MODE_BITSIZE (mode) / 128;
25335 : 7472 : else if (TARGET_SSE_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 64)
25336 : 0 : div = GET_MODE_BITSIZE (mode) / 64;
25337 : 7472 : width = (width + div - 1) / div;
25338 : 7472 : }
25339 : : /* Scalar part. */
25340 : : else if (INTEGRAL_MODE_P (mode))
25341 : 14696 : width = ix86_cost->reassoc_int;
25342 : : else if (FLOAT_MODE_P (mode))
25343 : 9645 : width = ix86_cost->reassoc_fp;
25344 : :
25345 : : /* Avoid using too many registers in 32bit mode. */
25346 : 31813 : if (!TARGET_64BIT && width > 2)
25347 : 31818 : width = 2;
25348 : : return width;
25349 : : }
25350 : :
25351 : : /* ??? No autovectorization into MMX or 3DNOW until we can reliably
25352 : : place emms and femms instructions. */
25353 : :
25354 : : static machine_mode
25355 : 4977657 : ix86_preferred_simd_mode (scalar_mode mode)
25356 : : {
25357 : 4977657 : if (!TARGET_SSE)
25358 : 856 : return word_mode;
25359 : :
25360 : 4976801 : switch (mode)
25361 : : {
25362 : 386475 : case E_QImode:
25363 : 386475 : if (TARGET_AVX512BW && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25364 : : return V64QImode;
25365 : 379558 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25366 : : return V32QImode;
25367 : : else
25368 : 359809 : return V16QImode;
25369 : :
25370 : 181032 : case E_HImode:
25371 : 181032 : if (TARGET_AVX512BW && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25372 : : return V32HImode;
25373 : 172286 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25374 : : return V16HImode;
25375 : : else
25376 : 156065 : return V8HImode;
25377 : :
25378 : 1503043 : case E_SImode:
25379 : 1503043 : if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25380 : : return V16SImode;
25381 : 1437940 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25382 : : return V8SImode;
25383 : : else
25384 : 1287118 : return V4SImode;
25385 : :
25386 : 1841384 : case E_DImode:
25387 : 1841384 : if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25388 : : return V8DImode;
25389 : 1481073 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25390 : : return V4DImode;
25391 : : else
25392 : 1387818 : return V2DImode;
25393 : :
25394 : 138018 : case E_HFmode:
25395 : 138018 : if (TARGET_AVX512FP16)
25396 : : {
25397 : 137484 : if (TARGET_AVX512VL)
25398 : : {
25399 : 64704 : if (TARGET_PREFER_AVX128)
25400 : : return V8HFmode;
25401 : 64474 : else if (TARGET_PREFER_AVX256 || !TARGET_EVEX512)
25402 : : return V16HFmode;
25403 : : }
25404 : 130074 : if (TARGET_EVEX512)
25405 : : return V32HFmode;
25406 : : }
25407 : 4400 : return word_mode;
25408 : :
25409 : 57045 : case E_BFmode:
25410 : 57045 : if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25411 : : return V32BFmode;
25412 : 26671 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25413 : : return V16BFmode;
25414 : : else
25415 : 13490 : return V8BFmode;
25416 : :
25417 : 587569 : case E_SFmode:
25418 : 587569 : if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25419 : : return V16SFmode;
25420 : 406720 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25421 : : return V8SFmode;
25422 : : else
25423 : 336951 : return V4SFmode;
25424 : :
25425 : 259300 : case E_DFmode:
25426 : 259300 : if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25427 : : return V8DFmode;
25428 : 150877 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25429 : : return V4DFmode;
25430 : 93653 : else if (TARGET_SSE2)
25431 : : return V2DFmode;
25432 : : /* FALLTHRU */
25433 : :
25434 : 22991 : default:
25435 : 22991 : return word_mode;
25436 : : }
25437 : : }
25438 : :
25439 : : /* If AVX is enabled then try vectorizing with both 256bit and 128bit
25440 : : vectors. If AVX512F is enabled then try vectorizing with 512bit,
25441 : : 256bit and 128bit vectors. */
25442 : :
25443 : : static unsigned int
25444 : 2337981 : ix86_autovectorize_vector_modes (vector_modes *modes, bool all)
25445 : : {
25446 : 2337981 : if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256)
25447 : : {
25448 : 68812 : modes->safe_push (V64QImode);
25449 : 68812 : modes->safe_push (V32QImode);
25450 : 68812 : modes->safe_push (V16QImode);
25451 : : }
25452 : 2269169 : else if (TARGET_AVX512F && TARGET_EVEX512 && all)
25453 : : {
25454 : 551 : modes->safe_push (V32QImode);
25455 : 551 : modes->safe_push (V16QImode);
25456 : 551 : modes->safe_push (V64QImode);
25457 : : }
25458 : 2268618 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25459 : : {
25460 : 31075 : modes->safe_push (V32QImode);
25461 : 31075 : modes->safe_push (V16QImode);
25462 : : }
25463 : 2237543 : else if (TARGET_AVX && all)
25464 : : {
25465 : 24 : modes->safe_push (V16QImode);
25466 : 24 : modes->safe_push (V32QImode);
25467 : : }
25468 : 2237519 : else if (TARGET_SSE2)
25469 : 2235276 : modes->safe_push (V16QImode);
25470 : :
25471 : 2337981 : if (TARGET_MMX_WITH_SSE)
25472 : 1867814 : modes->safe_push (V8QImode);
25473 : :
25474 : 2337981 : if (TARGET_SSE2)
25475 : 2335738 : modes->safe_push (V4QImode);
25476 : :
25477 : 2337981 : return 0;
25478 : : }
25479 : :
25480 : : /* Implemenation of targetm.vectorize.get_mask_mode. */
25481 : :
25482 : : static opt_machine_mode
25483 : 1901693 : ix86_get_mask_mode (machine_mode data_mode)
25484 : : {
25485 : 1901693 : unsigned vector_size = GET_MODE_SIZE (data_mode);
25486 : 1901693 : unsigned nunits = GET_MODE_NUNITS (data_mode);
25487 : 1901693 : unsigned elem_size = vector_size / nunits;
25488 : :
25489 : : /* Scalar mask case. */
25490 : 133255 : if ((TARGET_AVX512F && TARGET_EVEX512 && vector_size == 64)
25491 : 1876466 : || (TARGET_AVX512VL && (vector_size == 32 || vector_size == 16))
25492 : : /* AVX512FP16 only supports vector comparison
25493 : : to kmask for _Float16. */
25494 : 1830578 : || (TARGET_AVX512VL && TARGET_AVX512FP16
25495 : 360 : && GET_MODE_INNER (data_mode) == E_HFmode)
25496 : 3732263 : || (TARGET_AVX10_2 && GET_MODE_INNER (data_mode) == E_BFmode))
25497 : : {
25498 : 71212 : if (elem_size == 4
25499 : 71212 : || elem_size == 8
25500 : 24517 : || (TARGET_AVX512BW && (elem_size == 1 || elem_size == 2)))
25501 : 62992 : return smallest_int_mode_for_size (nunits).require ();
25502 : : }
25503 : :
25504 : 1838701 : scalar_int_mode elem_mode
25505 : 1838701 : = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT).require ();
25506 : :
25507 : 1838701 : gcc_assert (elem_size * nunits == vector_size);
25508 : :
25509 : 1838701 : return mode_for_vector (elem_mode, nunits);
25510 : : }
25511 : :
25512 : :
25513 : :
25514 : : /* Return class of registers which could be used for pseudo of MODE
25515 : : and of class RCLASS for spilling instead of memory. Return NO_REGS
25516 : : if it is not possible or non-profitable. */
25517 : :
25518 : : /* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657. */
25519 : :
25520 : : static reg_class_t
25521 : 6369182107 : ix86_spill_class (reg_class_t rclass, machine_mode mode)
25522 : : {
25523 : 6369182107 : if (0 && TARGET_GENERAL_REGS_SSE_SPILL
25524 : : && TARGET_SSE2
25525 : : && TARGET_INTER_UNIT_MOVES_TO_VEC
25526 : : && TARGET_INTER_UNIT_MOVES_FROM_VEC
25527 : : && (mode == SImode || (TARGET_64BIT && mode == DImode))
25528 : : && INTEGER_CLASS_P (rclass))
25529 : : return ALL_SSE_REGS;
25530 : 6369182107 : return NO_REGS;
25531 : : }
25532 : :
25533 : : /* Implement TARGET_MAX_NOCE_IFCVT_SEQ_COST. Like the default implementation,
25534 : : but returns a lower bound. */
25535 : :
25536 : : static unsigned int
25537 : 1841689 : ix86_max_noce_ifcvt_seq_cost (edge e)
25538 : : {
25539 : 1841689 : bool predictable_p = predictable_edge_p (e);
25540 : 1841689 : if (predictable_p)
25541 : : {
25542 : 138803 : if (OPTION_SET_P (param_max_rtl_if_conversion_predictable_cost))
25543 : 0 : return param_max_rtl_if_conversion_predictable_cost;
25544 : : }
25545 : : else
25546 : : {
25547 : 1702886 : if (OPTION_SET_P (param_max_rtl_if_conversion_unpredictable_cost))
25548 : 83 : return param_max_rtl_if_conversion_unpredictable_cost;
25549 : : }
25550 : :
25551 : : /* For modern machines with deeper pipeline, the penalty for branch
25552 : : misprediction could be higher than before to reset the pipeline
25553 : : slots. Add parameter br_mispredict_scale as a factor to describe
25554 : : the impact of reseting the pipeline. */
25555 : :
25556 : 1841606 : return BRANCH_COST (true, predictable_p)
25557 : 1841606 : * ix86_tune_cost->br_mispredict_scale;
25558 : : }
25559 : :
25560 : : /* Return true if SEQ is a good candidate as a replacement for the
25561 : : if-convertible sequence described in IF_INFO. */
25562 : :
25563 : : static bool
25564 : 229441 : ix86_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info)
25565 : : {
25566 : 229441 : if (TARGET_ONE_IF_CONV_INSN && if_info->speed_p)
25567 : : {
25568 : : int cmov_cnt = 0;
25569 : : /* Punt if SEQ contains more than one CMOV or FCMOV instruction.
25570 : : Maybe we should allow even more conditional moves as long as they
25571 : : are used far enough not to stall the CPU, or also consider
25572 : : IF_INFO->TEST_BB succ edge probabilities. */
25573 : 314 : for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn))
25574 : : {
25575 : 259 : rtx set = single_set (insn);
25576 : 259 : if (!set)
25577 : 0 : continue;
25578 : 259 : if (GET_CODE (SET_SRC (set)) != IF_THEN_ELSE)
25579 : 210 : continue;
25580 : 49 : rtx src = SET_SRC (set);
25581 : 49 : machine_mode mode = GET_MODE (src);
25582 : 49 : if (GET_MODE_CLASS (mode) != MODE_INT
25583 : 0 : && GET_MODE_CLASS (mode) != MODE_FLOAT)
25584 : 0 : continue;
25585 : 49 : if ((!REG_P (XEXP (src, 1)) && !MEM_P (XEXP (src, 1)))
25586 : 48 : || (!REG_P (XEXP (src, 2)) && !MEM_P (XEXP (src, 2))))
25587 : 1 : continue;
25588 : : /* insn is CMOV or FCMOV. */
25589 : 48 : if (++cmov_cnt > 1)
25590 : : return false;
25591 : : }
25592 : : }
25593 : :
25594 : : /* W/o TARGET_SSE4_1, it takes 3 instructions (pand, pandn and por)
25595 : : for movdfcc/movsfcc, and could possibly fail cost comparison.
25596 : : Increase branch cost will hurt performance for other modes, so
25597 : : specially add some preference for floating point ifcvt. */
25598 : 229433 : if (!TARGET_SSE4_1 && if_info->x
25599 : 174857 : && GET_MODE_CLASS (GET_MODE (if_info->x)) == MODE_FLOAT
25600 : 34297 : && if_info->speed_p)
25601 : : {
25602 : 27205 : unsigned cost = seq_cost (seq, true);
25603 : :
25604 : 27205 : if (cost <= if_info->original_cost)
25605 : : return true;
25606 : :
25607 : 26086 : return cost <= (if_info->max_seq_cost + COSTS_N_INSNS (2));
25608 : : }
25609 : :
25610 : 202228 : return default_noce_conversion_profitable_p (seq, if_info);
25611 : : }
25612 : :
25613 : : /* x86-specific vector costs. */
25614 : : class ix86_vector_costs : public vector_costs
25615 : : {
25616 : : public:
25617 : : ix86_vector_costs (vec_info *, bool);
25618 : :
25619 : : unsigned int add_stmt_cost (int count, vect_cost_for_stmt kind,
25620 : : stmt_vec_info stmt_info, slp_tree node,
25621 : : tree vectype, int misalign,
25622 : : vect_cost_model_location where) override;
25623 : : void finish_cost (const vector_costs *) override;
25624 : :
25625 : : private:
25626 : :
25627 : : /* Estimate register pressure of the vectorized code. */
25628 : : void ix86_vect_estimate_reg_pressure ();
25629 : : /* Number of GENERAL_REGS/SSE_REGS used in the vectorizer, it's used for
25630 : : estimation of register pressure.
25631 : : ??? Currently it's only used by vec_construct/scalar_to_vec
25632 : : where we know it's not loaded from memory. */
25633 : : unsigned m_num_gpr_needed[3];
25634 : : unsigned m_num_sse_needed[3];
25635 : : /* Number of 256-bit vector permutation. */
25636 : : unsigned m_num_avx256_vec_perm[3];
25637 : : };
25638 : :
25639 : 2008164 : ix86_vector_costs::ix86_vector_costs (vec_info* vinfo, bool costing_for_scalar)
25640 : : : vector_costs (vinfo, costing_for_scalar),
25641 : 8032656 : m_num_gpr_needed (),
25642 : 8032656 : m_num_sse_needed (),
25643 : 12048984 : m_num_avx256_vec_perm ()
25644 : : {
25645 : 2008164 : }
25646 : :
25647 : : /* Implement targetm.vectorize.create_costs. */
25648 : :
25649 : : static vector_costs *
25650 : 2008164 : ix86_vectorize_create_costs (vec_info *vinfo, bool costing_for_scalar)
25651 : : {
25652 : 2008164 : return new ix86_vector_costs (vinfo, costing_for_scalar);
25653 : : }
25654 : :
25655 : : unsigned
25656 : 6865638 : ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
25657 : : stmt_vec_info stmt_info, slp_tree node,
25658 : : tree vectype, int misalign,
25659 : : vect_cost_model_location where)
25660 : : {
25661 : 6865638 : unsigned retval = 0;
25662 : 6865638 : bool scalar_p
25663 : : = (kind == scalar_stmt || kind == scalar_load || kind == scalar_store);
25664 : 6865638 : int stmt_cost = - 1;
25665 : :
25666 : 6865638 : bool fp = false;
25667 : 6865638 : machine_mode mode = scalar_p ? SImode : TImode;
25668 : :
25669 : 6865638 : if (vectype != NULL)
25670 : : {
25671 : 6534622 : fp = FLOAT_TYPE_P (vectype);
25672 : 6534622 : mode = TYPE_MODE (vectype);
25673 : 6534622 : if (scalar_p)
25674 : 3740816 : mode = TYPE_MODE (TREE_TYPE (vectype));
25675 : : }
25676 : :
25677 : 6865638 : if ((kind == vector_stmt || kind == scalar_stmt)
25678 : 1772011 : && stmt_info
25679 : 8631958 : && stmt_info->stmt && gimple_code (stmt_info->stmt) == GIMPLE_ASSIGN)
25680 : : {
25681 : 1447869 : tree_code subcode = gimple_assign_rhs_code (stmt_info->stmt);
25682 : : /*machine_mode inner_mode = mode;
25683 : : if (VECTOR_MODE_P (mode))
25684 : : inner_mode = GET_MODE_INNER (mode);*/
25685 : :
25686 : 1447869 : switch (subcode)
25687 : : {
25688 : 609702 : case PLUS_EXPR:
25689 : 609702 : case POINTER_PLUS_EXPR:
25690 : 609702 : case MINUS_EXPR:
25691 : 609702 : if (kind == scalar_stmt)
25692 : : {
25693 : 426147 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25694 : 77355 : stmt_cost = ix86_cost->addss;
25695 : 348792 : else if (X87_FLOAT_MODE_P (mode))
25696 : 80 : stmt_cost = ix86_cost->fadd;
25697 : : else
25698 : 348712 : stmt_cost = ix86_cost->add;
25699 : : }
25700 : : else
25701 : 183555 : stmt_cost = ix86_vec_cost (mode, fp ? ix86_cost->addss
25702 : : : ix86_cost->sse_op);
25703 : : break;
25704 : :
25705 : 177394 : case MULT_EXPR:
25706 : : /* For MULT_HIGHPART_EXPR, x86 only supports pmulhw,
25707 : : take it as MULT_EXPR. */
25708 : 177394 : case MULT_HIGHPART_EXPR:
25709 : 177394 : stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
25710 : 177394 : break;
25711 : : /* There's no direct instruction for WIDEN_MULT_EXPR,
25712 : : take emulation into account. */
25713 : 1873 : case WIDEN_MULT_EXPR:
25714 : 3746 : stmt_cost = ix86_widen_mult_cost (ix86_cost, mode,
25715 : 1873 : TYPE_UNSIGNED (vectype));
25716 : 1873 : break;
25717 : :
25718 : 6383 : case NEGATE_EXPR:
25719 : 6383 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25720 : 1884 : stmt_cost = ix86_cost->sse_op;
25721 : 4499 : else if (X87_FLOAT_MODE_P (mode))
25722 : 0 : stmt_cost = ix86_cost->fchs;
25723 : 4499 : else if (VECTOR_MODE_P (mode))
25724 : 1963 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25725 : : else
25726 : 2536 : stmt_cost = ix86_cost->add;
25727 : : break;
25728 : 9073 : case TRUNC_DIV_EXPR:
25729 : 9073 : case CEIL_DIV_EXPR:
25730 : 9073 : case FLOOR_DIV_EXPR:
25731 : 9073 : case ROUND_DIV_EXPR:
25732 : 9073 : case TRUNC_MOD_EXPR:
25733 : 9073 : case CEIL_MOD_EXPR:
25734 : 9073 : case FLOOR_MOD_EXPR:
25735 : 9073 : case RDIV_EXPR:
25736 : 9073 : case ROUND_MOD_EXPR:
25737 : 9073 : case EXACT_DIV_EXPR:
25738 : 9073 : stmt_cost = ix86_division_cost (ix86_cost, mode);
25739 : 9073 : break;
25740 : :
25741 : 41611 : case RSHIFT_EXPR:
25742 : 41611 : case LSHIFT_EXPR:
25743 : 41611 : case LROTATE_EXPR:
25744 : 41611 : case RROTATE_EXPR:
25745 : 41611 : {
25746 : 41611 : tree op1 = gimple_assign_rhs1 (stmt_info->stmt);
25747 : 41611 : tree op2 = gimple_assign_rhs2 (stmt_info->stmt);
25748 : 41611 : stmt_cost = ix86_shift_rotate_cost
25749 : 41611 : (ix86_cost,
25750 : : (subcode == RSHIFT_EXPR
25751 : 26276 : && !TYPE_UNSIGNED (TREE_TYPE (op1)))
25752 : : ? ASHIFTRT : LSHIFTRT, mode,
25753 : 41611 : TREE_CODE (op2) == INTEGER_CST,
25754 : 41611 : cst_and_fits_in_hwi (op2)
25755 : 26549 : ? int_cst_value (op2) : -1,
25756 : : false, false, NULL, NULL);
25757 : : }
25758 : 41611 : break;
25759 : 81735 : case NOP_EXPR:
25760 : : /* Only sign-conversions are free. */
25761 : 81735 : if (tree_nop_conversion_p
25762 : 81735 : (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt)),
25763 : 81735 : TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt))))
25764 : : stmt_cost = 0;
25765 : 81735 : else if (fp)
25766 : 6715 : stmt_cost = vec_fp_conversion_cost
25767 : 6715 : (ix86_tune_cost, GET_MODE_BITSIZE (mode));
25768 : : break;
25769 : :
25770 : 15046 : case FLOAT_EXPR:
25771 : 15046 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25772 : 11317 : stmt_cost = ix86_cost->cvtsi2ss;
25773 : 3729 : else if (X87_FLOAT_MODE_P (mode))
25774 : : /* TODO: We do not have cost tables for x87. */
25775 : 1 : stmt_cost = ix86_cost->fadd;
25776 : : else
25777 : 3728 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtpi2ps);
25778 : : break;
25779 : :
25780 : 2136 : case FIX_TRUNC_EXPR:
25781 : 2136 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25782 : 0 : stmt_cost = ix86_cost->cvtss2si;
25783 : 2136 : else if (X87_FLOAT_MODE_P (mode))
25784 : : /* TODO: We do not have cost tables for x87. */
25785 : 0 : stmt_cost = ix86_cost->fadd;
25786 : : else
25787 : 2136 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtps2pi);
25788 : : break;
25789 : :
25790 : 36632 : case COND_EXPR:
25791 : 36632 : {
25792 : : /* SSE2 conditinal move sequence is:
25793 : : pcmpgtd %xmm5, %xmm0 (accounted separately)
25794 : : pand %xmm0, %xmm2
25795 : : pandn %xmm1, %xmm0
25796 : : por %xmm2, %xmm0
25797 : : while SSE4 uses cmp + blend
25798 : : and AVX512 masked moves.
25799 : :
25800 : : The condition is accounted separately since we usually have
25801 : : p = a < b
25802 : : c = p ? x : y
25803 : : and we will account first statement as setcc. Exception is when
25804 : : p is loaded from memory as bool and then we will not acocunt
25805 : : the compare, but there is no way to check for this. */
25806 : :
25807 : 36632 : int ninsns = TARGET_SSE4_1 ? 1 : 3;
25808 : :
25809 : : /* If one of parameters is 0 or -1 the sequence will be simplified:
25810 : : (if_true & mask) | (if_false & ~mask) -> if_true & mask */
25811 : 19582 : if (ninsns > 1
25812 : 19582 : && (zerop (gimple_assign_rhs2 (stmt_info->stmt))
25813 : 19257 : || zerop (gimple_assign_rhs3 (stmt_info->stmt))
25814 : 10353 : || integer_minus_onep
25815 : 10353 : (gimple_assign_rhs2 (stmt_info->stmt))
25816 : 9948 : || integer_minus_onep
25817 : 9948 : (gimple_assign_rhs3 (stmt_info->stmt))))
25818 : : ninsns = 1;
25819 : :
25820 : 36632 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25821 : 2506 : stmt_cost = ninsns * ix86_cost->sse_op;
25822 : 34126 : else if (X87_FLOAT_MODE_P (mode))
25823 : : /* x87 requires conditional branch. We don't have cost for
25824 : : that. */
25825 : : ;
25826 : 34126 : else if (VECTOR_MODE_P (mode))
25827 : 12201 : stmt_cost = ix86_vec_cost (mode, ninsns * ix86_cost->sse_op);
25828 : : else
25829 : : /* compare (accounted separately) + cmov. */
25830 : 21925 : stmt_cost = ix86_cost->add;
25831 : : }
25832 : : break;
25833 : :
25834 : 18757 : case MIN_EXPR:
25835 : 18757 : case MAX_EXPR:
25836 : 18757 : if (fp)
25837 : : {
25838 : 1181 : if (X87_FLOAT_MODE_P (mode)
25839 : 450 : && !SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25840 : : /* x87 requires conditional branch. We don't have cost for
25841 : : that. */
25842 : : ;
25843 : : else
25844 : : /* minss */
25845 : 1181 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25846 : : }
25847 : : else
25848 : : {
25849 : 17576 : if (VECTOR_MODE_P (mode))
25850 : : {
25851 : 4252 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25852 : : /* vpmin was introduced in SSE3.
25853 : : SSE2 needs pcmpgtd + pand + pandn + pxor.
25854 : : If one of parameters is 0 or -1 the sequence is simplified
25855 : : to pcmpgtd + pand. */
25856 : 4252 : if (!TARGET_SSSE3)
25857 : : {
25858 : 3194 : if (zerop (gimple_assign_rhs2 (stmt_info->stmt))
25859 : 4622 : || integer_minus_onep
25860 : 1428 : (gimple_assign_rhs2 (stmt_info->stmt)))
25861 : 1766 : stmt_cost *= 2;
25862 : : else
25863 : 1428 : stmt_cost *= 4;
25864 : : }
25865 : : }
25866 : : else
25867 : : /* cmp + cmov. */
25868 : 13324 : stmt_cost = ix86_cost->add * 2;
25869 : : }
25870 : : break;
25871 : :
25872 : 2417 : case ABS_EXPR:
25873 : 2417 : case ABSU_EXPR:
25874 : 2417 : if (fp)
25875 : : {
25876 : 2015 : if (X87_FLOAT_MODE_P (mode)
25877 : 1841 : && !SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25878 : : /* fabs. */
25879 : 0 : stmt_cost = ix86_cost->fabs;
25880 : : else
25881 : : /* andss of sign bit. */
25882 : 2015 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25883 : : }
25884 : : else
25885 : : {
25886 : 402 : if (VECTOR_MODE_P (mode))
25887 : : {
25888 : 79 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25889 : : /* vabs was introduced in SSE3.
25890 : : SSE3 uses psrat + pxor + psub. */
25891 : 79 : if (!TARGET_SSSE3)
25892 : 70 : stmt_cost *= 3;
25893 : : }
25894 : : else
25895 : : /* neg + cmov. */
25896 : 323 : stmt_cost = ix86_cost->add * 2;
25897 : : }
25898 : : break;
25899 : :
25900 : 97526 : case BIT_IOR_EXPR:
25901 : 97526 : case BIT_XOR_EXPR:
25902 : 97526 : case BIT_AND_EXPR:
25903 : 97526 : case BIT_NOT_EXPR:
25904 : 97526 : gcc_assert (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)
25905 : : && !X87_FLOAT_MODE_P (mode));
25906 : 97526 : if (VECTOR_MODE_P (mode))
25907 : 29493 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25908 : : else
25909 : 68033 : stmt_cost = ix86_cost->add;
25910 : : break;
25911 : :
25912 : 347584 : default:
25913 : 347584 : if (truth_value_p (subcode))
25914 : : {
25915 : 68421 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25916 : : /* CMPccS? insructions are cheap, so use sse_op. While they
25917 : : produce a mask which may need to be turned to 0/1 by and,
25918 : : expect that this will be optimized away in a common case. */
25919 : 0 : stmt_cost = ix86_cost->sse_op;
25920 : 68421 : else if (X87_FLOAT_MODE_P (mode))
25921 : : /* fcmp + setcc. */
25922 : 0 : stmt_cost = ix86_cost->fadd + ix86_cost->add;
25923 : 68421 : else if (VECTOR_MODE_P (mode))
25924 : 12170 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25925 : : else
25926 : : /* setcc. */
25927 : 56251 : stmt_cost = ix86_cost->add;
25928 : : break;
25929 : : }
25930 : : break;
25931 : : }
25932 : : }
25933 : :
25934 : 6865638 : combined_fn cfn;
25935 : 6865638 : if ((kind == vector_stmt || kind == scalar_stmt)
25936 : 1772011 : && stmt_info
25937 : 1766320 : && stmt_info->stmt
25938 : 8631958 : && (cfn = gimple_call_combined_fn (stmt_info->stmt)) != CFN_LAST)
25939 : 16518 : switch (cfn)
25940 : : {
25941 : 28 : case CFN_FMA:
25942 : 28 : stmt_cost = ix86_vec_cost (mode,
25943 : 28 : mode == SFmode ? ix86_cost->fmass
25944 : : : ix86_cost->fmasd);
25945 : 28 : break;
25946 : 24 : case CFN_MULH:
25947 : 24 : stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
25948 : 24 : break;
25949 : : default:
25950 : : break;
25951 : : }
25952 : :
25953 : 6865638 : if (kind == vec_promote_demote)
25954 : : {
25955 : 37501 : int outer_size
25956 : : = tree_to_uhwi
25957 : 37501 : (TYPE_SIZE
25958 : 37501 : (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt))));
25959 : 37501 : int inner_size
25960 : : = tree_to_uhwi
25961 : 37501 : (TYPE_SIZE
25962 : 37501 : (TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt))));
25963 : 37501 : bool inner_fp = FLOAT_TYPE_P
25964 : : (TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt)));
25965 : :
25966 : 3617 : if (fp && inner_fp)
25967 : 3153 : stmt_cost = vec_fp_conversion_cost
25968 : 3153 : (ix86_tune_cost, GET_MODE_BITSIZE (mode));
25969 : 34348 : else if (fp && !inner_fp)
25970 : 3837 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtpi2ps);
25971 : 30511 : else if (!fp && inner_fp)
25972 : 464 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtps2pi);
25973 : : else
25974 : 30047 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25975 : : /* VEC_PACK_TRUNC_EXPR and similar demote operations: If outer size is
25976 : : greater than inner size we will end up doing two conversions and
25977 : : packing them. We always pack pairs; if the size difference is greater
25978 : : it is split into multiple demote operations. */
25979 : 37501 : if (inner_size > outer_size)
25980 : 18326 : stmt_cost = stmt_cost * 2
25981 : 18326 : + ix86_vec_cost (mode, ix86_cost->sse_op);
25982 : : }
25983 : :
25984 : : /* If we do elementwise loads into a vector then we are bound by
25985 : : latency and execution resources for the many scalar loads
25986 : : (AGU and load ports). Try to account for this by scaling the
25987 : : construction cost by the number of elements involved. */
25988 : 6865638 : if ((kind == vec_construct || kind == vec_to_scalar)
25989 : 480685 : && ((stmt_info
25990 : 201471 : && (STMT_VINFO_TYPE (stmt_info) == load_vec_info_type
25991 : 201471 : || STMT_VINFO_TYPE (stmt_info) == store_vec_info_type)
25992 : 74809 : && ((STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) == VMAT_ELEMENTWISE
25993 : 0 : && (TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF (stmt_info)))
25994 : : != INTEGER_CST))
25995 : 74809 : || (STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info)
25996 : : == VMAT_GATHER_SCATTER)))
25997 : 476015 : || (node
25998 : 299439 : && (((SLP_TREE_MEMORY_ACCESS_TYPE (node) == VMAT_ELEMENTWISE
25999 : 298466 : || (SLP_TREE_MEMORY_ACCESS_TYPE (node) == VMAT_STRIDED_SLP
26000 : 39350 : && SLP_TREE_LANES (node) == 1))
26001 : 37679 : && (TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF
26002 : : (SLP_TREE_REPRESENTATIVE (node))))
26003 : : != INTEGER_CST))
26004 : 272941 : || (SLP_TREE_MEMORY_ACCESS_TYPE (node)
26005 : : == VMAT_GATHER_SCATTER)))))
26006 : : {
26007 : 35772 : stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
26008 : 35772 : stmt_cost *= (TYPE_VECTOR_SUBPARTS (vectype) + 1);
26009 : : }
26010 : 6829866 : else if ((kind == vec_construct || kind == scalar_to_vec)
26011 : 522641 : && node
26012 : 351244 : && SLP_TREE_DEF_TYPE (node) == vect_external_def)
26013 : : {
26014 : 347126 : stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
26015 : 347126 : unsigned i;
26016 : 347126 : tree op;
26017 : 1474364 : FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
26018 : 780112 : if (TREE_CODE (op) == SSA_NAME)
26019 : 528711 : TREE_VISITED (op) = 0;
26020 : 1127238 : FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
26021 : : {
26022 : 1065563 : if (TREE_CODE (op) != SSA_NAME
26023 : 780112 : || TREE_VISITED (op))
26024 : 285451 : continue;
26025 : 494661 : TREE_VISITED (op) = 1;
26026 : 494661 : gimple *def = SSA_NAME_DEF_STMT (op);
26027 : 494661 : tree tem;
26028 : 494661 : if (is_gimple_assign (def)
26029 : 267368 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
26030 : 30313 : && ((tem = gimple_assign_rhs1 (def)), true)
26031 : 30313 : && TREE_CODE (tem) == SSA_NAME
26032 : : /* A sign-change expands to nothing. */
26033 : 524789 : && tree_nop_conversion_p (TREE_TYPE (gimple_assign_lhs (def)),
26034 : 30128 : TREE_TYPE (tem)))
26035 : 9020 : def = SSA_NAME_DEF_STMT (tem);
26036 : : /* When the component is loaded from memory we can directly
26037 : : move it to a vector register, otherwise we have to go
26038 : : via a GPR or via vpinsr which involves similar cost.
26039 : : Likewise with a BIT_FIELD_REF extracting from a vector
26040 : : register we can hope to avoid using a GPR. */
26041 : 494661 : if (!is_gimple_assign (def)
26042 : 494661 : || ((!gimple_assign_load_p (def)
26043 : 137758 : || (!TARGET_SSE4_1
26044 : 267070 : && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op))) == 1))
26045 : 131987 : && (gimple_assign_rhs_code (def) != BIT_FIELD_REF
26046 : 3226 : || !VECTOR_TYPE_P (TREE_TYPE
26047 : : (TREE_OPERAND (gimple_assign_rhs1 (def), 0))))))
26048 : : {
26049 : 357827 : if (fp)
26050 : 15975 : m_num_sse_needed[where]++;
26051 : : else
26052 : : {
26053 : 341852 : m_num_gpr_needed[where]++;
26054 : 341852 : stmt_cost += ix86_cost->sse_to_integer;
26055 : : }
26056 : : }
26057 : : }
26058 : 1127238 : FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
26059 : 780112 : if (TREE_CODE (op) == SSA_NAME)
26060 : 528711 : TREE_VISITED (op) = 0;
26061 : : }
26062 : 6865638 : if (stmt_cost == -1)
26063 : 5351501 : stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
26064 : :
26065 : 6865638 : if (kind == vec_perm && vectype
26066 : 6952632 : && GET_MODE_SIZE (TYPE_MODE (vectype)) == 32)
26067 : 4290 : m_num_avx256_vec_perm[where]++;
26068 : :
26069 : : /* Penalize DFmode vector operations for Bonnell. */
26070 : 6865638 : if (TARGET_CPU_P (BONNELL) && kind == vector_stmt
26071 : 6865715 : && vectype && GET_MODE_INNER (TYPE_MODE (vectype)) == DFmode)
26072 : 12 : stmt_cost *= 5; /* FIXME: The value here is arbitrary. */
26073 : :
26074 : : /* Statements in an inner loop relative to the loop being
26075 : : vectorized are weighted more heavily. The value here is
26076 : : arbitrary and could potentially be improved with analysis. */
26077 : 6865638 : retval = adjust_cost_for_freq (stmt_info, where, count * stmt_cost);
26078 : :
26079 : : /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
26080 : : for Silvermont as it has out of order integer pipeline and can execute
26081 : : 2 scalar instruction per tick, but has in order SIMD pipeline. */
26082 : 6865638 : if ((TARGET_CPU_P (SILVERMONT) || TARGET_CPU_P (GOLDMONT)
26083 : 6865638 : || TARGET_CPU_P (GOLDMONT_PLUS) || TARGET_CPU_P (INTEL))
26084 : 1774 : && stmt_info && stmt_info->stmt)
26085 : : {
26086 : 1543 : tree lhs_op = gimple_get_lhs (stmt_info->stmt);
26087 : 1543 : if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE)
26088 : 1109 : retval = (retval * 17) / 10;
26089 : : }
26090 : :
26091 : 6865638 : m_costs[where] += retval;
26092 : :
26093 : 6865638 : return retval;
26094 : : }
26095 : :
26096 : : void
26097 : 1723676 : ix86_vector_costs::ix86_vect_estimate_reg_pressure ()
26098 : : {
26099 : 1723676 : unsigned gpr_spill_cost = COSTS_N_INSNS (ix86_cost->int_store [2]) / 2;
26100 : 1723676 : unsigned sse_spill_cost = COSTS_N_INSNS (ix86_cost->sse_store[0]) / 2;
26101 : :
26102 : : /* Any better way to have target available fp registers, currently use SSE_REGS. */
26103 : 1723676 : unsigned target_avail_sse = TARGET_64BIT ? (TARGET_AVX512F ? 32 : 16) : 8;
26104 : 6894704 : for (unsigned i = 0; i != 3; i++)
26105 : : {
26106 : 5171028 : if (m_num_gpr_needed[i] > target_avail_regs)
26107 : 704 : m_costs[i] += gpr_spill_cost * (m_num_gpr_needed[i] - target_avail_regs);
26108 : : /* Only measure sse registers pressure. */
26109 : 5171028 : if (TARGET_SSE && (m_num_sse_needed[i] > target_avail_sse))
26110 : 136 : m_costs[i] += sse_spill_cost * (m_num_sse_needed[i] - target_avail_sse);
26111 : : }
26112 : 1723676 : }
26113 : :
26114 : : void
26115 : 1723676 : ix86_vector_costs::finish_cost (const vector_costs *scalar_costs)
26116 : : {
26117 : 1723676 : loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo);
26118 : 307038 : if (loop_vinfo && !m_costing_for_scalar)
26119 : : {
26120 : : /* We are currently not asking the vectorizer to compare costs
26121 : : between different vector mode sizes. When using predication
26122 : : that will end up always choosing the prefered mode size even
26123 : : if there's a smaller mode covering all lanes. Test for this
26124 : : situation and artificially reject the larger mode attempt.
26125 : : ??? We currently lack masked ops for sub-SSE sized modes,
26126 : : so we could restrict this rejection to AVX and AVX512 modes
26127 : : but error on the safe side for now. */
26128 : 76691 : if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)
26129 : 13 : && !LOOP_VINFO_EPILOGUE_P (loop_vinfo)
26130 : 13 : && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
26131 : 76699 : && (exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant ())
26132 : 16 : > ceil_log2 (LOOP_VINFO_INT_NITERS (loop_vinfo))))
26133 : 6 : m_costs[vect_body] = INT_MAX;
26134 : : }
26135 : :
26136 : 1723676 : ix86_vect_estimate_reg_pressure ();
26137 : :
26138 : 6894704 : for (int i = 0; i != 3; i++)
26139 : 5171028 : if (m_num_avx256_vec_perm[i]
26140 : 488 : && TARGET_AVX256_AVOID_VEC_PERM)
26141 : 2 : m_costs[i] = INT_MAX;
26142 : :
26143 : : /* When X86_TUNE_AVX512_TWO_EPILOGUES is enabled arrange for both
26144 : : a AVX2 and a SSE epilogue for AVX512 vectorized loops. */
26145 : 1723676 : if (loop_vinfo
26146 : 307038 : && ix86_tune_features[X86_TUNE_AVX512_TWO_EPILOGUES])
26147 : : {
26148 : 528 : if (GET_MODE_SIZE (loop_vinfo->vector_mode) == 64)
26149 : 112 : m_suggested_epilogue_mode = V32QImode;
26150 : 152 : else if (LOOP_VINFO_EPILOGUE_P (loop_vinfo)
26151 : 173 : && GET_MODE_SIZE (loop_vinfo->vector_mode) == 32)
26152 : 11 : m_suggested_epilogue_mode = V16QImode;
26153 : : }
26154 : : /* When a 128bit SSE vectorized epilogue still has a VF of 16 or larger
26155 : : enable a 64bit SSE epilogue. */
26156 : 307038 : if (loop_vinfo
26157 : 307038 : && LOOP_VINFO_EPILOGUE_P (loop_vinfo)
26158 : 60138 : && GET_MODE_SIZE (loop_vinfo->vector_mode) == 16
26159 : 11724 : && LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant () >= 16)
26160 : 1444 : m_suggested_epilogue_mode = V8QImode;
26161 : :
26162 : 1723676 : vector_costs::finish_cost (scalar_costs);
26163 : 1723676 : }
26164 : :
26165 : : /* Validate target specific memory model bits in VAL. */
26166 : :
26167 : : static unsigned HOST_WIDE_INT
26168 : 515143 : ix86_memmodel_check (unsigned HOST_WIDE_INT val)
26169 : : {
26170 : 515143 : enum memmodel model = memmodel_from_int (val);
26171 : 515143 : bool strong;
26172 : :
26173 : 515143 : if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE
26174 : : |MEMMODEL_MASK)
26175 : 515139 : || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE)))
26176 : : {
26177 : 4 : warning (OPT_Winvalid_memory_model,
26178 : : "unknown architecture specific memory model");
26179 : 4 : return MEMMODEL_SEQ_CST;
26180 : : }
26181 : 515139 : strong = (is_mm_acq_rel (model) || is_mm_seq_cst (model));
26182 : 515139 : if (val & IX86_HLE_ACQUIRE && !(is_mm_acquire (model) || strong))
26183 : : {
26184 : 0 : warning (OPT_Winvalid_memory_model,
26185 : : "%<HLE_ACQUIRE%> not used with %<ACQUIRE%> or stronger "
26186 : : "memory model");
26187 : 0 : return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE;
26188 : : }
26189 : 515139 : if (val & IX86_HLE_RELEASE && !(is_mm_release (model) || strong))
26190 : : {
26191 : 0 : warning (OPT_Winvalid_memory_model,
26192 : : "%<HLE_RELEASE%> not used with %<RELEASE%> or stronger "
26193 : : "memory model");
26194 : 0 : return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE;
26195 : : }
26196 : : return val;
26197 : : }
26198 : :
26199 : : /* Set CLONEI->vecsize_mangle, CLONEI->mask_mode, CLONEI->vecsize_int,
26200 : : CLONEI->vecsize_float and if CLONEI->simdlen is 0, also
26201 : : CLONEI->simdlen. Return 0 if SIMD clones shouldn't be emitted,
26202 : : or number of vecsize_mangle variants that should be emitted. */
26203 : :
26204 : : static int
26205 : 7497 : ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node,
26206 : : struct cgraph_simd_clone *clonei,
26207 : : tree base_type, int num,
26208 : : bool explicit_p)
26209 : : {
26210 : 7497 : int ret = 1;
26211 : :
26212 : 7497 : if (clonei->simdlen
26213 : 7497 : && (clonei->simdlen < 2
26214 : 1289 : || clonei->simdlen > 1024
26215 : 8786 : || (clonei->simdlen & (clonei->simdlen - 1)) != 0))
26216 : : {
26217 : 0 : if (explicit_p)
26218 : 0 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26219 : : "unsupported simdlen %wd", clonei->simdlen.to_constant ());
26220 : 0 : return 0;
26221 : : }
26222 : :
26223 : 7497 : tree ret_type = TREE_TYPE (TREE_TYPE (node->decl));
26224 : 7497 : if (TREE_CODE (ret_type) != VOID_TYPE)
26225 : 6705 : switch (TYPE_MODE (ret_type))
26226 : : {
26227 : 6705 : case E_QImode:
26228 : 6705 : case E_HImode:
26229 : 6705 : case E_SImode:
26230 : 6705 : case E_DImode:
26231 : 6705 : case E_SFmode:
26232 : 6705 : case E_DFmode:
26233 : : /* case E_SCmode: */
26234 : : /* case E_DCmode: */
26235 : 6705 : if (!AGGREGATE_TYPE_P (ret_type))
26236 : : break;
26237 : : /* FALLTHRU */
26238 : 2 : default:
26239 : 2 : if (explicit_p)
26240 : 2 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26241 : : "unsupported return type %qT for simd", ret_type);
26242 : 2 : return 0;
26243 : : }
26244 : :
26245 : 7495 : tree t;
26246 : 7495 : int i;
26247 : 7495 : tree type_arg_types = TYPE_ARG_TYPES (TREE_TYPE (node->decl));
26248 : 7495 : bool decl_arg_p = (node->definition || type_arg_types == NULL_TREE);
26249 : :
26250 : 7495 : for (t = (decl_arg_p ? DECL_ARGUMENTS (node->decl) : type_arg_types), i = 0;
26251 : 20222 : t && t != void_list_node; t = TREE_CHAIN (t), i++)
26252 : : {
26253 : 16470 : tree arg_type = decl_arg_p ? TREE_TYPE (t) : TREE_VALUE (t);
26254 : 12732 : switch (TYPE_MODE (arg_type))
26255 : : {
26256 : 12713 : case E_QImode:
26257 : 12713 : case E_HImode:
26258 : 12713 : case E_SImode:
26259 : 12713 : case E_DImode:
26260 : 12713 : case E_SFmode:
26261 : 12713 : case E_DFmode:
26262 : : /* case E_SCmode: */
26263 : : /* case E_DCmode: */
26264 : 12713 : if (!AGGREGATE_TYPE_P (arg_type))
26265 : : break;
26266 : : /* FALLTHRU */
26267 : 41 : default:
26268 : 41 : if (clonei->args[i].arg_type == SIMD_CLONE_ARG_TYPE_UNIFORM)
26269 : : break;
26270 : 5 : if (explicit_p)
26271 : 5 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26272 : : "unsupported argument type %qT for simd", arg_type);
26273 : : return 0;
26274 : : }
26275 : : }
26276 : :
26277 : 7490 : if (!TREE_PUBLIC (node->decl) || !explicit_p)
26278 : : {
26279 : : /* If the function isn't exported, we can pick up just one ISA
26280 : : for the clones. */
26281 : 114 : if (TARGET_AVX512F && TARGET_EVEX512)
26282 : 0 : clonei->vecsize_mangle = 'e';
26283 : 114 : else if (TARGET_AVX2)
26284 : 1 : clonei->vecsize_mangle = 'd';
26285 : 113 : else if (TARGET_AVX)
26286 : 88 : clonei->vecsize_mangle = 'c';
26287 : : else
26288 : 25 : clonei->vecsize_mangle = 'b';
26289 : : ret = 1;
26290 : : }
26291 : : else
26292 : : {
26293 : 7376 : clonei->vecsize_mangle = "bcde"[num];
26294 : 7376 : ret = 4;
26295 : : }
26296 : 7490 : clonei->mask_mode = VOIDmode;
26297 : 7490 : switch (clonei->vecsize_mangle)
26298 : : {
26299 : 1869 : case 'b':
26300 : 1869 : clonei->vecsize_int = 128;
26301 : 1869 : clonei->vecsize_float = 128;
26302 : 1869 : break;
26303 : 1932 : case 'c':
26304 : 1932 : clonei->vecsize_int = 128;
26305 : 1932 : clonei->vecsize_float = 256;
26306 : 1932 : break;
26307 : 1845 : case 'd':
26308 : 1845 : clonei->vecsize_int = 256;
26309 : 1845 : clonei->vecsize_float = 256;
26310 : 1845 : break;
26311 : 1844 : case 'e':
26312 : 1844 : clonei->vecsize_int = 512;
26313 : 1844 : clonei->vecsize_float = 512;
26314 : 1844 : if (TYPE_MODE (base_type) == QImode)
26315 : 15 : clonei->mask_mode = DImode;
26316 : : else
26317 : 1829 : clonei->mask_mode = SImode;
26318 : : break;
26319 : : }
26320 : 7490 : if (clonei->simdlen == 0)
26321 : : {
26322 : 6201 : if (SCALAR_INT_MODE_P (TYPE_MODE (base_type)))
26323 : 3265 : clonei->simdlen = clonei->vecsize_int;
26324 : : else
26325 : 2936 : clonei->simdlen = clonei->vecsize_float;
26326 : 6201 : clonei->simdlen = clonei->simdlen
26327 : 12402 : / GET_MODE_BITSIZE (TYPE_MODE (base_type));
26328 : : }
26329 : 1289 : else if (clonei->simdlen > 16)
26330 : : {
26331 : : /* For compatibility with ICC, use the same upper bounds
26332 : : for simdlen. In particular, for CTYPE below, use the return type,
26333 : : unless the function returns void, in that case use the characteristic
26334 : : type. If it is possible for given SIMDLEN to pass CTYPE value
26335 : : in registers (8 [XYZ]MM* regs for 32-bit code, 16 [XYZ]MM* regs
26336 : : for 64-bit code), accept that SIMDLEN, otherwise warn and don't
26337 : : emit corresponding clone. */
26338 : 4 : tree ctype = ret_type;
26339 : 4 : if (VOID_TYPE_P (ret_type))
26340 : 0 : ctype = base_type;
26341 : 8 : int cnt = GET_MODE_BITSIZE (TYPE_MODE (ctype)) * clonei->simdlen;
26342 : 4 : if (SCALAR_INT_MODE_P (TYPE_MODE (ctype)))
26343 : 0 : cnt /= clonei->vecsize_int;
26344 : : else
26345 : 4 : cnt /= clonei->vecsize_float;
26346 : 4 : if (cnt > (TARGET_64BIT ? 16 : 8))
26347 : : {
26348 : 0 : if (explicit_p)
26349 : 0 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26350 : : "unsupported simdlen %wd",
26351 : : clonei->simdlen.to_constant ());
26352 : 0 : return 0;
26353 : : }
26354 : : }
26355 : : return ret;
26356 : : }
26357 : :
26358 : : /* If SIMD clone NODE can't be used in a vectorized loop
26359 : : in current function, return -1, otherwise return a badness of using it
26360 : : (0 if it is most desirable from vecsize_mangle point of view, 1
26361 : : slightly less desirable, etc.). */
26362 : :
26363 : : static int
26364 : 1792 : ix86_simd_clone_usable (struct cgraph_node *node, machine_mode)
26365 : : {
26366 : 1792 : switch (node->simdclone->vecsize_mangle)
26367 : : {
26368 : 632 : case 'b':
26369 : 632 : if (!TARGET_SSE2)
26370 : : return -1;
26371 : 632 : if (!TARGET_AVX)
26372 : : return 0;
26373 : 521 : return (TARGET_AVX512F && TARGET_EVEX512) ? 3 : TARGET_AVX2 ? 2 : 1;
26374 : 627 : case 'c':
26375 : 627 : if (!TARGET_AVX)
26376 : : return -1;
26377 : 593 : return (TARGET_AVX512F && TARGET_EVEX512) ? 2 : TARGET_AVX2 ? 1 : 0;
26378 : 341 : case 'd':
26379 : 341 : if (!TARGET_AVX2)
26380 : : return -1;
26381 : 126 : return (TARGET_AVX512F && TARGET_EVEX512) ? 1 : 0;
26382 : 192 : case 'e':
26383 : 192 : if (!TARGET_AVX512F || !TARGET_EVEX512)
26384 : 154 : return -1;
26385 : : return 0;
26386 : 0 : default:
26387 : 0 : gcc_unreachable ();
26388 : : }
26389 : : }
26390 : :
26391 : : /* This function adjusts the unroll factor based on
26392 : : the hardware capabilities. For ex, bdver3 has
26393 : : a loop buffer which makes unrolling of smaller
26394 : : loops less important. This function decides the
26395 : : unroll factor using number of memory references
26396 : : (value 32 is used) as a heuristic. */
26397 : :
26398 : : static unsigned
26399 : 771189 : ix86_loop_unroll_adjust (unsigned nunroll, class loop *loop)
26400 : : {
26401 : 771189 : basic_block *bbs;
26402 : 771189 : rtx_insn *insn;
26403 : 771189 : unsigned i;
26404 : 771189 : unsigned mem_count = 0;
26405 : :
26406 : : /* Unroll small size loop when unroll factor is not explicitly
26407 : : specified. */
26408 : 771189 : if (ix86_unroll_only_small_loops && !loop->unroll)
26409 : : {
26410 : 729651 : if (loop->ninsns <= ix86_cost->small_unroll_ninsns)
26411 : 69093 : return MIN (nunroll, ix86_cost->small_unroll_factor);
26412 : : else
26413 : : return 1;
26414 : : }
26415 : :
26416 : 41538 : if (!TARGET_ADJUST_UNROLL)
26417 : : return nunroll;
26418 : :
26419 : : /* Count the number of memory references within the loop body.
26420 : : This value determines the unrolling factor for bdver3 and bdver4
26421 : : architectures. */
26422 : 7 : subrtx_iterator::array_type array;
26423 : 7 : bbs = get_loop_body (loop);
26424 : 21 : for (i = 0; i < loop->num_nodes; i++)
26425 : 102 : FOR_BB_INSNS (bbs[i], insn)
26426 : 88 : if (NONDEBUG_INSN_P (insn))
26427 : 464 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
26428 : 404 : if (const_rtx x = *iter)
26429 : 404 : if (MEM_P (x))
26430 : : {
26431 : 25 : machine_mode mode = GET_MODE (x);
26432 : 50 : unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
26433 : 25 : if (n_words > 4)
26434 : 0 : mem_count += 2;
26435 : : else
26436 : 25 : mem_count += 1;
26437 : : }
26438 : 7 : free (bbs);
26439 : :
26440 : 7 : if (mem_count && mem_count <=32)
26441 : 7 : return MIN (nunroll, 32 / mem_count);
26442 : :
26443 : : return nunroll;
26444 : 7 : }
26445 : :
26446 : :
26447 : : /* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P. */
26448 : :
26449 : : static bool
26450 : 400408 : ix86_float_exceptions_rounding_supported_p (void)
26451 : : {
26452 : : /* For x87 floating point with standard excess precision handling,
26453 : : there is no adddf3 pattern (since x87 floating point only has
26454 : : XFmode operations) so the default hook implementation gets this
26455 : : wrong. */
26456 : 400408 : return TARGET_80387 || (TARGET_SSE && TARGET_SSE_MATH);
26457 : : }
26458 : :
26459 : : /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */
26460 : :
26461 : : static void
26462 : 7054 : ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
26463 : : {
26464 : 7054 : if (!TARGET_80387 && !(TARGET_SSE && TARGET_SSE_MATH))
26465 : : return;
26466 : 7054 : tree exceptions_var = create_tmp_var_raw (integer_type_node);
26467 : 7054 : if (TARGET_80387)
26468 : : {
26469 : 7054 : tree fenv_index_type = build_index_type (size_int (6));
26470 : 7054 : tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
26471 : 7054 : tree fenv_var = create_tmp_var_raw (fenv_type);
26472 : 7054 : TREE_ADDRESSABLE (fenv_var) = 1;
26473 : 7054 : tree fenv_ptr = build_pointer_type (fenv_type);
26474 : 7054 : tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
26475 : 7054 : fenv_addr = fold_convert (ptr_type_node, fenv_addr);
26476 : 7054 : tree fnstenv = get_ix86_builtin (IX86_BUILTIN_FNSTENV);
26477 : 7054 : tree fldenv = get_ix86_builtin (IX86_BUILTIN_FLDENV);
26478 : 7054 : tree fnstsw = get_ix86_builtin (IX86_BUILTIN_FNSTSW);
26479 : 7054 : tree fnclex = get_ix86_builtin (IX86_BUILTIN_FNCLEX);
26480 : 7054 : tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
26481 : 7054 : tree hold_fnclex = build_call_expr (fnclex, 0);
26482 : 7054 : fenv_var = build4 (TARGET_EXPR, fenv_type, fenv_var, hold_fnstenv,
26483 : : NULL_TREE, NULL_TREE);
26484 : 7054 : *hold = build2 (COMPOUND_EXPR, void_type_node, fenv_var,
26485 : : hold_fnclex);
26486 : 7054 : *clear = build_call_expr (fnclex, 0);
26487 : 7054 : tree sw_var = create_tmp_var_raw (short_unsigned_type_node);
26488 : 7054 : tree fnstsw_call = build_call_expr (fnstsw, 0);
26489 : 7054 : tree sw_mod = build4 (TARGET_EXPR, short_unsigned_type_node, sw_var,
26490 : : fnstsw_call, NULL_TREE, NULL_TREE);
26491 : 7054 : tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
26492 : 7054 : tree update_mod = build4 (TARGET_EXPR, integer_type_node,
26493 : : exceptions_var, exceptions_x87,
26494 : : NULL_TREE, NULL_TREE);
26495 : 7054 : *update = build2 (COMPOUND_EXPR, integer_type_node,
26496 : : sw_mod, update_mod);
26497 : 7054 : tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
26498 : 7054 : *update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv);
26499 : : }
26500 : 7054 : if (TARGET_SSE && TARGET_SSE_MATH)
26501 : : {
26502 : 7054 : tree mxcsr_orig_var = create_tmp_var_raw (unsigned_type_node);
26503 : 7054 : tree mxcsr_mod_var = create_tmp_var_raw (unsigned_type_node);
26504 : 7054 : tree stmxcsr = get_ix86_builtin (IX86_BUILTIN_STMXCSR);
26505 : 7054 : tree ldmxcsr = get_ix86_builtin (IX86_BUILTIN_LDMXCSR);
26506 : 7054 : tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
26507 : 7054 : tree hold_assign_orig = build4 (TARGET_EXPR, unsigned_type_node,
26508 : : mxcsr_orig_var, stmxcsr_hold_call,
26509 : : NULL_TREE, NULL_TREE);
26510 : 7054 : tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
26511 : : mxcsr_orig_var,
26512 : 7054 : build_int_cst (unsigned_type_node, 0x1f80));
26513 : 7054 : hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
26514 : 7054 : build_int_cst (unsigned_type_node, 0xffffffc0));
26515 : 7054 : tree hold_assign_mod = build4 (TARGET_EXPR, unsigned_type_node,
26516 : : mxcsr_mod_var, hold_mod_val,
26517 : : NULL_TREE, NULL_TREE);
26518 : 7054 : tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
26519 : 7054 : tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
26520 : : hold_assign_orig, hold_assign_mod);
26521 : 7054 : hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all,
26522 : : ldmxcsr_hold_call);
26523 : 7054 : if (*hold)
26524 : 7054 : *hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all);
26525 : : else
26526 : 0 : *hold = hold_all;
26527 : 7054 : tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
26528 : 7054 : if (*clear)
26529 : 7054 : *clear = build2 (COMPOUND_EXPR, void_type_node, *clear,
26530 : : ldmxcsr_clear_call);
26531 : : else
26532 : 0 : *clear = ldmxcsr_clear_call;
26533 : 7054 : tree stxmcsr_update_call = build_call_expr (stmxcsr, 0);
26534 : 7054 : tree exceptions_sse = fold_convert (integer_type_node,
26535 : : stxmcsr_update_call);
26536 : 7054 : if (*update)
26537 : : {
26538 : 7054 : tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node,
26539 : : exceptions_var, exceptions_sse);
26540 : 7054 : tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node,
26541 : : exceptions_var, exceptions_mod);
26542 : 7054 : *update = build2 (COMPOUND_EXPR, integer_type_node, *update,
26543 : : exceptions_assign);
26544 : : }
26545 : : else
26546 : 0 : *update = build4 (TARGET_EXPR, integer_type_node, exceptions_var,
26547 : : exceptions_sse, NULL_TREE, NULL_TREE);
26548 : 7054 : tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
26549 : 7054 : *update = build2 (COMPOUND_EXPR, void_type_node, *update,
26550 : : ldmxcsr_update_call);
26551 : : }
26552 : 7054 : tree atomic_feraiseexcept
26553 : 7054 : = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
26554 : 7054 : tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
26555 : : 1, exceptions_var);
26556 : 7054 : *update = build2 (COMPOUND_EXPR, void_type_node, *update,
26557 : : atomic_feraiseexcept_call);
26558 : : }
26559 : :
26560 : : #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
26561 : : /* For i386, common symbol is local only for non-PIE binaries. For
26562 : : x86-64, common symbol is local only for non-PIE binaries or linker
26563 : : supports copy reloc in PIE binaries. */
26564 : :
26565 : : static bool
26566 : 737964330 : ix86_binds_local_p (const_tree exp)
26567 : : {
26568 : 737964330 : bool direct_extern_access
26569 : 737964330 : = (ix86_direct_extern_access
26570 : 1472450195 : && !(VAR_OR_FUNCTION_DECL_P (exp)
26571 : 734485865 : && lookup_attribute ("nodirect_extern_access",
26572 : 734485865 : DECL_ATTRIBUTES (exp))));
26573 : 737964330 : if (!direct_extern_access)
26574 : 1003 : ix86_has_no_direct_extern_access = true;
26575 : 737964330 : return default_binds_local_p_3 (exp, flag_shlib != 0, true,
26576 : : direct_extern_access,
26577 : : (direct_extern_access
26578 : 737963327 : && (!flag_pic
26579 : 128802504 : || (TARGET_64BIT
26580 : 737964330 : && HAVE_LD_PIE_COPYRELOC != 0))));
26581 : : }
26582 : :
26583 : : /* If flag_pic or ix86_direct_extern_access is false, then neither
26584 : : local nor global relocs should be placed in readonly memory. */
26585 : :
26586 : : static int
26587 : 5125658 : ix86_reloc_rw_mask (void)
26588 : : {
26589 : 5125658 : return (flag_pic || !ix86_direct_extern_access) ? 3 : 0;
26590 : : }
26591 : : #endif
26592 : :
26593 : : /* Return true iff ADDR can be used as a symbolic base address. */
26594 : :
26595 : : static bool
26596 : 3705 : symbolic_base_address_p (rtx addr)
26597 : : {
26598 : 0 : if (GET_CODE (addr) == SYMBOL_REF)
26599 : : return true;
26600 : :
26601 : 3634 : if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_GOTOFF)
26602 : 0 : return true;
26603 : :
26604 : : return false;
26605 : : }
26606 : :
26607 : : /* Return true iff ADDR can be used as a base address. */
26608 : :
26609 : : static bool
26610 : 5676 : base_address_p (rtx addr)
26611 : : {
26612 : 0 : if (REG_P (addr))
26613 : : return true;
26614 : :
26615 : 3444 : if (symbolic_base_address_p (addr))
26616 : 0 : return true;
26617 : :
26618 : : return false;
26619 : : }
26620 : :
26621 : : /* If MEM is in the form of [(base+symbase)+offset], extract the three
26622 : : parts of address and set to BASE, SYMBASE and OFFSET, otherwise
26623 : : return false. */
26624 : :
26625 : : static bool
26626 : 3507 : extract_base_offset_in_addr (rtx mem, rtx *base, rtx *symbase, rtx *offset)
26627 : : {
26628 : 3507 : rtx addr;
26629 : :
26630 : 3507 : gcc_assert (MEM_P (mem));
26631 : :
26632 : 3507 : addr = XEXP (mem, 0);
26633 : :
26634 : 3507 : if (GET_CODE (addr) == CONST)
26635 : 52 : addr = XEXP (addr, 0);
26636 : :
26637 : 3507 : if (base_address_p (addr))
26638 : : {
26639 : 1338 : *base = addr;
26640 : 1338 : *symbase = const0_rtx;
26641 : 1338 : *offset = const0_rtx;
26642 : 1338 : return true;
26643 : : }
26644 : :
26645 : 2169 : if (GET_CODE (addr) == PLUS
26646 : 2169 : && base_address_p (XEXP (addr, 0)))
26647 : : {
26648 : 965 : rtx addend = XEXP (addr, 1);
26649 : :
26650 : 965 : if (GET_CODE (addend) == CONST)
26651 : 0 : addend = XEXP (addend, 0);
26652 : :
26653 : 965 : if (CONST_INT_P (addend))
26654 : : {
26655 : 704 : *base = XEXP (addr, 0);
26656 : 704 : *symbase = const0_rtx;
26657 : 704 : *offset = addend;
26658 : 704 : return true;
26659 : : }
26660 : :
26661 : : /* Also accept REG + symbolic ref, with or without a CONST_INT
26662 : : offset. */
26663 : 261 : if (REG_P (XEXP (addr, 0)))
26664 : : {
26665 : 261 : if (symbolic_base_address_p (addend))
26666 : : {
26667 : 0 : *base = XEXP (addr, 0);
26668 : 0 : *symbase = addend;
26669 : 0 : *offset = const0_rtx;
26670 : 0 : return true;
26671 : : }
26672 : :
26673 : 261 : if (GET_CODE (addend) == PLUS
26674 : 0 : && symbolic_base_address_p (XEXP (addend, 0))
26675 : 261 : && CONST_INT_P (XEXP (addend, 1)))
26676 : : {
26677 : 0 : *base = XEXP (addr, 0);
26678 : 0 : *symbase = XEXP (addend, 0);
26679 : 0 : *offset = XEXP (addend, 1);
26680 : 0 : return true;
26681 : : }
26682 : : }
26683 : : }
26684 : :
26685 : : return false;
26686 : : }
26687 : :
26688 : : /* Given OPERANDS of consecutive load/store, check if we can merge
26689 : : them into move multiple. LOAD is true if they are load instructions.
26690 : : MODE is the mode of memory operands. */
26691 : :
26692 : : bool
26693 : 1944 : ix86_operands_ok_for_move_multiple (rtx *operands, bool load,
26694 : : machine_mode mode)
26695 : : {
26696 : 1944 : HOST_WIDE_INT offval_1, offval_2, msize;
26697 : 1944 : rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2,
26698 : : symbase_1, symbase_2, offset_1, offset_2;
26699 : :
26700 : 1944 : if (load)
26701 : : {
26702 : 1609 : mem_1 = operands[1];
26703 : 1609 : mem_2 = operands[3];
26704 : 1609 : reg_1 = operands[0];
26705 : 1609 : reg_2 = operands[2];
26706 : : }
26707 : : else
26708 : : {
26709 : 335 : mem_1 = operands[0];
26710 : 335 : mem_2 = operands[2];
26711 : 335 : reg_1 = operands[1];
26712 : 335 : reg_2 = operands[3];
26713 : : }
26714 : :
26715 : 1944 : gcc_assert (REG_P (reg_1) && REG_P (reg_2));
26716 : :
26717 : 1944 : if (REGNO (reg_1) != REGNO (reg_2))
26718 : : return false;
26719 : :
26720 : : /* Check if the addresses are in the form of [base+offset]. */
26721 : 1944 : if (!extract_base_offset_in_addr (mem_1, &base_1, &symbase_1, &offset_1))
26722 : : return false;
26723 : 1563 : if (!extract_base_offset_in_addr (mem_2, &base_2, &symbase_2, &offset_2))
26724 : : return false;
26725 : :
26726 : : /* Check if the bases are the same. */
26727 : 479 : if (!rtx_equal_p (base_1, base_2) || !rtx_equal_p (symbase_1, symbase_2))
26728 : 102 : return false;
26729 : :
26730 : 377 : offval_1 = INTVAL (offset_1);
26731 : 377 : offval_2 = INTVAL (offset_2);
26732 : 377 : msize = GET_MODE_SIZE (mode);
26733 : : /* Check if mem_1 is adjacent to mem_2 and mem_1 has lower address. */
26734 : 377 : if (offval_1 + msize != offval_2)
26735 : : return false;
26736 : :
26737 : : return true;
26738 : : }
26739 : :
26740 : : /* Implement the TARGET_OPTAB_SUPPORTED_P hook. */
26741 : :
26742 : : static bool
26743 : 324203 : ix86_optab_supported_p (int op, machine_mode mode1, machine_mode,
26744 : : optimization_type opt_type)
26745 : : {
26746 : 324203 : switch (op)
26747 : : {
26748 : 220 : case asin_optab:
26749 : 220 : case acos_optab:
26750 : 220 : case log1p_optab:
26751 : 220 : case exp_optab:
26752 : 220 : case exp10_optab:
26753 : 220 : case exp2_optab:
26754 : 220 : case expm1_optab:
26755 : 220 : case ldexp_optab:
26756 : 220 : case scalb_optab:
26757 : 220 : case round_optab:
26758 : 220 : case lround_optab:
26759 : 220 : return opt_type == OPTIMIZE_FOR_SPEED;
26760 : :
26761 : 267 : case rint_optab:
26762 : 267 : if (SSE_FLOAT_MODE_P (mode1)
26763 : 144 : && TARGET_SSE_MATH
26764 : 128 : && !flag_trapping_math
26765 : 21 : && !TARGET_SSE4_1
26766 : : && mode1 != HFmode)
26767 : 21 : return opt_type == OPTIMIZE_FOR_SPEED;
26768 : : return true;
26769 : :
26770 : 1815 : case floor_optab:
26771 : 1815 : case ceil_optab:
26772 : 1815 : case btrunc_optab:
26773 : 1815 : if (((SSE_FLOAT_MODE_P (mode1)
26774 : 1509 : && TARGET_SSE_MATH
26775 : 1430 : && TARGET_SSE4_1)
26776 : 1766 : || mode1 == HFmode)
26777 : 118 : && !flag_trapping_math)
26778 : : return true;
26779 : 1755 : return opt_type == OPTIMIZE_FOR_SPEED;
26780 : :
26781 : 82 : case rsqrt_optab:
26782 : 82 : return opt_type == OPTIMIZE_FOR_SPEED && use_rsqrt_p (mode1);
26783 : :
26784 : : default:
26785 : : return true;
26786 : : }
26787 : : }
26788 : :
26789 : : /* Address space support.
26790 : :
26791 : : This is not "far pointers" in the 16-bit sense, but an easy way
26792 : : to use %fs and %gs segment prefixes. Therefore:
26793 : :
26794 : : (a) All address spaces have the same modes,
26795 : : (b) All address spaces have the same addresss forms,
26796 : : (c) While %fs and %gs are technically subsets of the generic
26797 : : address space, they are probably not subsets of each other.
26798 : : (d) Since we have no access to the segment base register values
26799 : : without resorting to a system call, we cannot convert a
26800 : : non-default address space to a default address space.
26801 : : Therefore we do not claim %fs or %gs are subsets of generic.
26802 : :
26803 : : Therefore we can (mostly) use the default hooks. */
26804 : :
26805 : : /* All use of segmentation is assumed to make address 0 valid. */
26806 : :
26807 : : static bool
26808 : 66774301 : ix86_addr_space_zero_address_valid (addr_space_t as)
26809 : : {
26810 : 66774301 : return as != ADDR_SPACE_GENERIC;
26811 : : }
26812 : :
26813 : : static void
26814 : 817436 : ix86_init_libfuncs (void)
26815 : : {
26816 : 817436 : if (TARGET_64BIT)
26817 : : {
26818 : 802210 : set_optab_libfunc (sdivmod_optab, TImode, "__divmodti4");
26819 : 802210 : set_optab_libfunc (udivmod_optab, TImode, "__udivmodti4");
26820 : : }
26821 : : else
26822 : : {
26823 : 15226 : set_optab_libfunc (sdivmod_optab, DImode, "__divmoddi4");
26824 : 15226 : set_optab_libfunc (udivmod_optab, DImode, "__udivmoddi4");
26825 : : }
26826 : :
26827 : : #if TARGET_MACHO
26828 : : darwin_rename_builtins ();
26829 : : #endif
26830 : 817436 : }
26831 : :
26832 : : /* Set the value of FLT_EVAL_METHOD in float.h. When using only the
26833 : : FPU, assume that the fpcw is set to extended precision; when using
26834 : : only SSE, rounding is correct; when using both SSE and the FPU,
26835 : : the rounding precision is indeterminate, since either may be chosen
26836 : : apparently at random. */
26837 : :
26838 : : static enum flt_eval_method
26839 : 90117667 : ix86_get_excess_precision (enum excess_precision_type type)
26840 : : {
26841 : 90117667 : switch (type)
26842 : : {
26843 : 86344039 : case EXCESS_PRECISION_TYPE_FAST:
26844 : : /* The fastest type to promote to will always be the native type,
26845 : : whether that occurs with implicit excess precision or
26846 : : otherwise. */
26847 : 86344039 : return TARGET_AVX512FP16
26848 : 86344039 : ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
26849 : 86344039 : : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
26850 : 3773547 : case EXCESS_PRECISION_TYPE_STANDARD:
26851 : 3773547 : case EXCESS_PRECISION_TYPE_IMPLICIT:
26852 : : /* Otherwise, the excess precision we want when we are
26853 : : in a standards compliant mode, and the implicit precision we
26854 : : provide would be identical were it not for the unpredictable
26855 : : cases. */
26856 : 3773547 : if (TARGET_AVX512FP16 && TARGET_SSE_MATH)
26857 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16;
26858 : 3767980 : else if (!TARGET_80387)
26859 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
26860 : 3761884 : else if (!TARGET_MIX_SSE_I387)
26861 : : {
26862 : 3761712 : if (!(TARGET_SSE && TARGET_SSE_MATH))
26863 : : return FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE;
26864 : 2775188 : else if (TARGET_SSE2)
26865 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
26866 : : }
26867 : :
26868 : : /* If we are in standards compliant mode, but we know we will
26869 : : calculate in unpredictable precision, return
26870 : : FLT_EVAL_METHOD_FLOAT. There is no reason to introduce explicit
26871 : : excess precision if the target can't guarantee it will honor
26872 : : it. */
26873 : 318 : return (type == EXCESS_PRECISION_TYPE_STANDARD
26874 : 318 : ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
26875 : : : FLT_EVAL_METHOD_UNPREDICTABLE);
26876 : 81 : case EXCESS_PRECISION_TYPE_FLOAT16:
26877 : 81 : if (TARGET_80387
26878 : 75 : && !(TARGET_SSE_MATH && TARGET_SSE))
26879 : 4 : error ("%<-fexcess-precision=16%> is not compatible with %<-mfpmath=387%>");
26880 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16;
26881 : 0 : default:
26882 : 0 : gcc_unreachable ();
26883 : : }
26884 : :
26885 : : return FLT_EVAL_METHOD_UNPREDICTABLE;
26886 : : }
26887 : :
26888 : : /* Return true if _BitInt(N) is supported and fill its details into *INFO. */
26889 : : bool
26890 : 1697435 : ix86_bitint_type_info (int n, struct bitint_info *info)
26891 : : {
26892 : 1697435 : if (n <= 8)
26893 : 3695 : info->limb_mode = QImode;
26894 : 1693740 : else if (n <= 16)
26895 : 886 : info->limb_mode = HImode;
26896 : 1692854 : else if (n <= 32 || (!TARGET_64BIT && n > 64))
26897 : 18690 : info->limb_mode = SImode;
26898 : : else
26899 : 1674164 : info->limb_mode = DImode;
26900 : 1697435 : info->abi_limb_mode = info->limb_mode;
26901 : 1697435 : info->big_endian = false;
26902 : 1697435 : info->extended = false;
26903 : 1697435 : return true;
26904 : : }
26905 : :
26906 : : /* Implement TARGET_C_MODE_FOR_FLOATING_TYPE. Return DFmode, TFmode
26907 : : or XFmode for TI_LONG_DOUBLE_TYPE which is for long double type,
26908 : : based on long double bits, go with the default one for the others. */
26909 : :
26910 : : static machine_mode
26911 : 3513107 : ix86_c_mode_for_floating_type (enum tree_index ti)
26912 : : {
26913 : 3513107 : if (ti == TI_LONG_DOUBLE_TYPE)
26914 : 1172526 : return (TARGET_LONG_DOUBLE_64 ? DFmode
26915 : 586253 : : (TARGET_LONG_DOUBLE_128 ? TFmode : XFmode));
26916 : 2926822 : return default_mode_for_floating_type (ti);
26917 : : }
26918 : :
26919 : : /* Returns modified FUNCTION_TYPE for cdtor callabi. */
26920 : : tree
26921 : 13333 : ix86_cxx_adjust_cdtor_callabi_fntype (tree fntype)
26922 : : {
26923 : 13333 : if (TARGET_64BIT
26924 : 65 : || TARGET_RTD
26925 : 13398 : || ix86_function_type_abi (fntype) != MS_ABI)
26926 : 13333 : return fntype;
26927 : : /* For 32-bit MS ABI add thiscall attribute. */
26928 : 0 : tree attribs = tree_cons (get_identifier ("thiscall"), NULL_TREE,
26929 : 0 : TYPE_ATTRIBUTES (fntype));
26930 : 0 : return build_type_attribute_variant (fntype, attribs);
26931 : : }
26932 : :
26933 : : /* Implement PUSH_ROUNDING. On 386, we have pushw instruction that
26934 : : decrements by exactly 2 no matter what the position was, there is no pushb.
26935 : :
26936 : : But as CIE data alignment factor on this arch is -4 for 32bit targets
26937 : : and -8 for 64bit targets, we need to make sure all stack pointer adjustments
26938 : : are in multiple of 4 for 32bit targets and 8 for 64bit targets. */
26939 : :
26940 : : poly_int64
26941 : 261341757 : ix86_push_rounding (poly_int64 bytes)
26942 : : {
26943 : 339552891 : return ROUND_UP (bytes, UNITS_PER_WORD);
26944 : : }
26945 : :
26946 : : /* Use 8 bits metadata start from bit48 for LAM_U48,
26947 : : 6 bits metadat start from bit57 for LAM_U57. */
26948 : : #define IX86_HWASAN_SHIFT (ix86_lam_type == lam_u48 \
26949 : : ? 48 \
26950 : : : (ix86_lam_type == lam_u57 ? 57 : 0))
26951 : : #define IX86_HWASAN_TAG_SIZE (ix86_lam_type == lam_u48 \
26952 : : ? 8 \
26953 : : : (ix86_lam_type == lam_u57 ? 6 : 0))
26954 : :
26955 : : /* Implement TARGET_MEMTAG_CAN_TAG_ADDRESSES. */
26956 : : bool
26957 : 6132665 : ix86_memtag_can_tag_addresses ()
26958 : : {
26959 : 6132665 : return ix86_lam_type != lam_none && TARGET_LP64;
26960 : : }
26961 : :
26962 : : /* Implement TARGET_MEMTAG_TAG_SIZE. */
26963 : : unsigned char
26964 : 430 : ix86_memtag_tag_size ()
26965 : : {
26966 : 430 : return IX86_HWASAN_TAG_SIZE;
26967 : : }
26968 : :
26969 : : /* Implement TARGET_MEMTAG_SET_TAG. */
26970 : : rtx
26971 : 102 : ix86_memtag_set_tag (rtx untagged, rtx tag, rtx target)
26972 : : {
26973 : : /* default_memtag_insert_random_tag may
26974 : : generate tag with value more than 6 bits. */
26975 : 102 : if (ix86_lam_type == lam_u57)
26976 : : {
26977 : 102 : unsigned HOST_WIDE_INT and_imm
26978 : : = (HOST_WIDE_INT_1U << IX86_HWASAN_TAG_SIZE) - 1;
26979 : :
26980 : 102 : emit_insn (gen_andqi3 (tag, tag, GEN_INT (and_imm)));
26981 : : }
26982 : 102 : tag = expand_simple_binop (Pmode, ASHIFT, tag,
26983 : 102 : GEN_INT (IX86_HWASAN_SHIFT), NULL_RTX,
26984 : : /* unsignedp = */1, OPTAB_WIDEN);
26985 : 102 : rtx ret = expand_simple_binop (Pmode, IOR, untagged, tag, target,
26986 : : /* unsignedp = */1, OPTAB_DIRECT);
26987 : 102 : return ret;
26988 : : }
26989 : :
26990 : : /* Implement TARGET_MEMTAG_EXTRACT_TAG. */
26991 : : rtx
26992 : 172 : ix86_memtag_extract_tag (rtx tagged_pointer, rtx target)
26993 : : {
26994 : 172 : rtx tag = expand_simple_binop (Pmode, LSHIFTRT, tagged_pointer,
26995 : 172 : GEN_INT (IX86_HWASAN_SHIFT), target,
26996 : : /* unsignedp = */0,
26997 : : OPTAB_DIRECT);
26998 : 172 : rtx ret = gen_reg_rtx (QImode);
26999 : : /* Mask off bit63 when LAM_U57. */
27000 : 172 : if (ix86_lam_type == lam_u57)
27001 : : {
27002 : 172 : unsigned HOST_WIDE_INT and_imm
27003 : : = (HOST_WIDE_INT_1U << IX86_HWASAN_TAG_SIZE) - 1;
27004 : 172 : emit_insn (gen_andqi3 (ret, gen_lowpart (QImode, tag),
27005 : 172 : gen_int_mode (and_imm, QImode)));
27006 : : }
27007 : : else
27008 : 0 : emit_move_insn (ret, gen_lowpart (QImode, tag));
27009 : 172 : return ret;
27010 : : }
27011 : :
27012 : : /* The default implementation of TARGET_MEMTAG_UNTAGGED_POINTER. */
27013 : : rtx
27014 : 110 : ix86_memtag_untagged_pointer (rtx tagged_pointer, rtx target)
27015 : : {
27016 : : /* Leave bit63 alone. */
27017 : 110 : rtx tag_mask = gen_int_mode (((HOST_WIDE_INT_1U << IX86_HWASAN_SHIFT)
27018 : 110 : + (HOST_WIDE_INT_1U << 63) - 1),
27019 : 110 : Pmode);
27020 : 110 : rtx untagged_base = expand_simple_binop (Pmode, AND, tagged_pointer,
27021 : : tag_mask, target, true,
27022 : : OPTAB_DIRECT);
27023 : 110 : gcc_assert (untagged_base);
27024 : 110 : return untagged_base;
27025 : : }
27026 : :
27027 : : /* Implement TARGET_MEMTAG_ADD_TAG. */
27028 : : rtx
27029 : 86 : ix86_memtag_add_tag (rtx base, poly_int64 offset, unsigned char tag_offset)
27030 : : {
27031 : 86 : rtx base_tag = gen_reg_rtx (QImode);
27032 : 86 : rtx base_addr = gen_reg_rtx (Pmode);
27033 : 86 : rtx tagged_addr = gen_reg_rtx (Pmode);
27034 : 86 : rtx new_tag = gen_reg_rtx (QImode);
27035 : 172 : unsigned HOST_WIDE_INT and_imm
27036 : 86 : = (HOST_WIDE_INT_1U << IX86_HWASAN_SHIFT) - 1;
27037 : :
27038 : : /* When there's "overflow" in tag adding,
27039 : : need to mask the most significant bit off. */
27040 : 86 : emit_move_insn (base_tag, ix86_memtag_extract_tag (base, NULL_RTX));
27041 : 86 : emit_move_insn (base_addr,
27042 : : ix86_memtag_untagged_pointer (base, NULL_RTX));
27043 : 86 : emit_insn (gen_add2_insn (base_tag, gen_int_mode (tag_offset, QImode)));
27044 : 86 : emit_move_insn (new_tag, base_tag);
27045 : 86 : emit_insn (gen_andqi3 (new_tag, new_tag, gen_int_mode (and_imm, QImode)));
27046 : 86 : emit_move_insn (tagged_addr,
27047 : : ix86_memtag_set_tag (base_addr, new_tag, NULL_RTX));
27048 : 86 : return plus_constant (Pmode, tagged_addr, offset);
27049 : : }
27050 : :
27051 : : /* Implement TARGET_HAVE_CCMP. */
27052 : : static bool
27053 : 7770669 : ix86_have_ccmp ()
27054 : : {
27055 : 7770669 : return (bool) TARGET_APX_CCMP;
27056 : : }
27057 : :
27058 : : /* Implement TARGET_MODE_CAN_TRANSFER_BITS. */
27059 : : static bool
27060 : 4722446 : ix86_mode_can_transfer_bits (machine_mode mode)
27061 : : {
27062 : 4722446 : if (GET_MODE_CLASS (mode) == MODE_FLOAT
27063 : 4680689 : || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
27064 : 101954 : switch (GET_MODE_INNER (mode))
27065 : : {
27066 : 48682 : case E_SFmode:
27067 : 48682 : case E_DFmode:
27068 : : /* These suffer from normalization upon load when not using SSE. */
27069 : 48682 : return !(ix86_fpmath & FPMATH_387);
27070 : : default:
27071 : : return true;
27072 : : }
27073 : :
27074 : : return true;
27075 : : }
27076 : :
27077 : : /* Implement TARGET_REDZONE_CLOBBER. */
27078 : : static rtx
27079 : 2 : ix86_redzone_clobber ()
27080 : : {
27081 : 2 : cfun->machine->asm_redzone_clobber_seen = true;
27082 : 2 : if (ix86_using_red_zone ())
27083 : : {
27084 : 2 : rtx base = plus_constant (Pmode, stack_pointer_rtx, -RED_ZONE_SIZE);
27085 : 2 : rtx mem = gen_rtx_MEM (BLKmode, base);
27086 : 2 : set_mem_size (mem, RED_ZONE_SIZE);
27087 : 2 : return mem;
27088 : : }
27089 : : return NULL_RTX;
27090 : : }
27091 : :
27092 : : /* Target-specific selftests. */
27093 : :
27094 : : #if CHECKING_P
27095 : :
27096 : : namespace selftest {
27097 : :
27098 : : /* Verify that hard regs are dumped as expected (in compact mode). */
27099 : :
27100 : : static void
27101 : 4 : ix86_test_dumping_hard_regs ()
27102 : : {
27103 : 4 : ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
27104 : 4 : ASSERT_RTL_DUMP_EQ ("(reg:SI dx)", gen_raw_REG (SImode, 1));
27105 : 4 : }
27106 : :
27107 : : /* Test dumping an insn with repeated references to the same SCRATCH,
27108 : : to verify the rtx_reuse code. */
27109 : :
27110 : : static void
27111 : 4 : ix86_test_dumping_memory_blockage ()
27112 : : {
27113 : 4 : set_new_first_and_last_insn (NULL, NULL);
27114 : :
27115 : 4 : rtx pat = gen_memory_blockage ();
27116 : 4 : rtx_reuse_manager r;
27117 : 4 : r.preprocess (pat);
27118 : :
27119 : : /* Verify that the repeated references to the SCRATCH show use
27120 : : reuse IDS. The first should be prefixed with a reuse ID,
27121 : : and the second should be dumped as a "reuse_rtx" of that ID.
27122 : : The expected string assumes Pmode == DImode. */
27123 : 4 : if (Pmode == DImode)
27124 : 4 : ASSERT_RTL_DUMP_EQ_WITH_REUSE
27125 : : ("(cinsn 1 (set (mem/v:BLK (0|scratch:DI) [0 A8])\n"
27126 : : " (unspec:BLK [\n"
27127 : : " (mem/v:BLK (reuse_rtx 0) [0 A8])\n"
27128 : : " ] UNSPEC_MEMORY_BLOCKAGE)))\n", pat, &r);
27129 : 4 : }
27130 : :
27131 : : /* Verify loading an RTL dump; specifically a dump of copying
27132 : : a param on x86_64 from a hard reg into the frame.
27133 : : This test is target-specific since the dump contains target-specific
27134 : : hard reg names. */
27135 : :
27136 : : static void
27137 : 4 : ix86_test_loading_dump_fragment_1 ()
27138 : : {
27139 : 4 : rtl_dump_test t (SELFTEST_LOCATION,
27140 : 4 : locate_file ("x86_64/copy-hard-reg-into-frame.rtl"));
27141 : :
27142 : 4 : rtx_insn *insn = get_insn_by_uid (1);
27143 : :
27144 : : /* The block structure and indentation here is purely for
27145 : : readability; it mirrors the structure of the rtx. */
27146 : 4 : tree mem_expr;
27147 : 4 : {
27148 : 4 : rtx pat = PATTERN (insn);
27149 : 4 : ASSERT_EQ (SET, GET_CODE (pat));
27150 : 4 : {
27151 : 4 : rtx dest = SET_DEST (pat);
27152 : 4 : ASSERT_EQ (MEM, GET_CODE (dest));
27153 : : /* Verify the "/c" was parsed. */
27154 : 4 : ASSERT_TRUE (RTX_FLAG (dest, call));
27155 : 4 : ASSERT_EQ (SImode, GET_MODE (dest));
27156 : 4 : {
27157 : 4 : rtx addr = XEXP (dest, 0);
27158 : 4 : ASSERT_EQ (PLUS, GET_CODE (addr));
27159 : 4 : ASSERT_EQ (DImode, GET_MODE (addr));
27160 : 4 : {
27161 : 4 : rtx lhs = XEXP (addr, 0);
27162 : : /* Verify that the "frame" REG was consolidated. */
27163 : 4 : ASSERT_RTX_PTR_EQ (frame_pointer_rtx, lhs);
27164 : : }
27165 : 4 : {
27166 : 4 : rtx rhs = XEXP (addr, 1);
27167 : 4 : ASSERT_EQ (CONST_INT, GET_CODE (rhs));
27168 : 4 : ASSERT_EQ (-4, INTVAL (rhs));
27169 : : }
27170 : : }
27171 : : /* Verify the "[1 i+0 S4 A32]" was parsed. */
27172 : 4 : ASSERT_EQ (1, MEM_ALIAS_SET (dest));
27173 : : /* "i" should have been handled by synthesizing a global int
27174 : : variable named "i". */
27175 : 4 : mem_expr = MEM_EXPR (dest);
27176 : 4 : ASSERT_NE (mem_expr, NULL);
27177 : 4 : ASSERT_EQ (VAR_DECL, TREE_CODE (mem_expr));
27178 : 4 : ASSERT_EQ (integer_type_node, TREE_TYPE (mem_expr));
27179 : 4 : ASSERT_EQ (IDENTIFIER_NODE, TREE_CODE (DECL_NAME (mem_expr)));
27180 : 4 : ASSERT_STREQ ("i", IDENTIFIER_POINTER (DECL_NAME (mem_expr)));
27181 : : /* "+0". */
27182 : 4 : ASSERT_TRUE (MEM_OFFSET_KNOWN_P (dest));
27183 : 4 : ASSERT_EQ (0, MEM_OFFSET (dest));
27184 : : /* "S4". */
27185 : 4 : ASSERT_EQ (4, MEM_SIZE (dest));
27186 : : /* "A32. */
27187 : 4 : ASSERT_EQ (32, MEM_ALIGN (dest));
27188 : : }
27189 : 4 : {
27190 : 4 : rtx src = SET_SRC (pat);
27191 : 4 : ASSERT_EQ (REG, GET_CODE (src));
27192 : 4 : ASSERT_EQ (SImode, GET_MODE (src));
27193 : 4 : ASSERT_EQ (5, REGNO (src));
27194 : 4 : tree reg_expr = REG_EXPR (src);
27195 : : /* "i" here should point to the same var as for the MEM_EXPR. */
27196 : 4 : ASSERT_EQ (reg_expr, mem_expr);
27197 : : }
27198 : : }
27199 : 4 : }
27200 : :
27201 : : /* Verify that the RTL loader copes with a call_insn dump.
27202 : : This test is target-specific since the dump contains a target-specific
27203 : : hard reg name. */
27204 : :
27205 : : static void
27206 : 4 : ix86_test_loading_call_insn ()
27207 : : {
27208 : : /* The test dump includes register "xmm0", where requires TARGET_SSE
27209 : : to exist. */
27210 : 4 : if (!TARGET_SSE)
27211 : 0 : return;
27212 : :
27213 : 4 : rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/call-insn.rtl"));
27214 : :
27215 : 4 : rtx_insn *insn = get_insns ();
27216 : 4 : ASSERT_EQ (CALL_INSN, GET_CODE (insn));
27217 : :
27218 : : /* "/j". */
27219 : 4 : ASSERT_TRUE (RTX_FLAG (insn, jump));
27220 : :
27221 : 4 : rtx pat = PATTERN (insn);
27222 : 4 : ASSERT_EQ (CALL, GET_CODE (SET_SRC (pat)));
27223 : :
27224 : : /* Verify REG_NOTES. */
27225 : 4 : {
27226 : : /* "(expr_list:REG_CALL_DECL". */
27227 : 4 : ASSERT_EQ (EXPR_LIST, GET_CODE (REG_NOTES (insn)));
27228 : 4 : rtx_expr_list *note0 = as_a <rtx_expr_list *> (REG_NOTES (insn));
27229 : 4 : ASSERT_EQ (REG_CALL_DECL, REG_NOTE_KIND (note0));
27230 : :
27231 : : /* "(expr_list:REG_EH_REGION (const_int 0 [0])". */
27232 : 4 : rtx_expr_list *note1 = note0->next ();
27233 : 4 : ASSERT_EQ (REG_EH_REGION, REG_NOTE_KIND (note1));
27234 : :
27235 : 4 : ASSERT_EQ (NULL, note1->next ());
27236 : : }
27237 : :
27238 : : /* Verify CALL_INSN_FUNCTION_USAGE. */
27239 : 4 : {
27240 : : /* "(expr_list:DF (use (reg:DF 21 xmm0))". */
27241 : 4 : rtx_expr_list *usage
27242 : 4 : = as_a <rtx_expr_list *> (CALL_INSN_FUNCTION_USAGE (insn));
27243 : 4 : ASSERT_EQ (EXPR_LIST, GET_CODE (usage));
27244 : 4 : ASSERT_EQ (DFmode, GET_MODE (usage));
27245 : 4 : ASSERT_EQ (USE, GET_CODE (usage->element ()));
27246 : 4 : ASSERT_EQ (NULL, usage->next ());
27247 : : }
27248 : 4 : }
27249 : :
27250 : : /* Verify that the RTL loader copes a dump from print_rtx_function.
27251 : : This test is target-specific since the dump contains target-specific
27252 : : hard reg names. */
27253 : :
27254 : : static void
27255 : 4 : ix86_test_loading_full_dump ()
27256 : : {
27257 : 4 : rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/times-two.rtl"));
27258 : :
27259 : 4 : ASSERT_STREQ ("times_two", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
27260 : :
27261 : 4 : rtx_insn *insn_1 = get_insn_by_uid (1);
27262 : 4 : ASSERT_EQ (NOTE, GET_CODE (insn_1));
27263 : :
27264 : 4 : rtx_insn *insn_7 = get_insn_by_uid (7);
27265 : 4 : ASSERT_EQ (INSN, GET_CODE (insn_7));
27266 : 4 : ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_7)));
27267 : :
27268 : 4 : rtx_insn *insn_15 = get_insn_by_uid (15);
27269 : 4 : ASSERT_EQ (INSN, GET_CODE (insn_15));
27270 : 4 : ASSERT_EQ (USE, GET_CODE (PATTERN (insn_15)));
27271 : :
27272 : : /* Verify crtl->return_rtx. */
27273 : 4 : ASSERT_EQ (REG, GET_CODE (crtl->return_rtx));
27274 : 4 : ASSERT_EQ (0, REGNO (crtl->return_rtx));
27275 : 4 : ASSERT_EQ (SImode, GET_MODE (crtl->return_rtx));
27276 : 4 : }
27277 : :
27278 : : /* Verify that the RTL loader copes with UNSPEC and UNSPEC_VOLATILE insns.
27279 : : In particular, verify that it correctly loads the 2nd operand.
27280 : : This test is target-specific since these are machine-specific
27281 : : operands (and enums). */
27282 : :
27283 : : static void
27284 : 4 : ix86_test_loading_unspec ()
27285 : : {
27286 : 4 : rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/unspec.rtl"));
27287 : :
27288 : 4 : ASSERT_STREQ ("test_unspec", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
27289 : :
27290 : 4 : ASSERT_TRUE (cfun);
27291 : :
27292 : : /* Test of an UNSPEC. */
27293 : 4 : rtx_insn *insn = get_insns ();
27294 : 4 : ASSERT_EQ (INSN, GET_CODE (insn));
27295 : 4 : rtx set = single_set (insn);
27296 : 4 : ASSERT_NE (NULL, set);
27297 : 4 : rtx dst = SET_DEST (set);
27298 : 4 : ASSERT_EQ (MEM, GET_CODE (dst));
27299 : 4 : rtx src = SET_SRC (set);
27300 : 4 : ASSERT_EQ (UNSPEC, GET_CODE (src));
27301 : 4 : ASSERT_EQ (BLKmode, GET_MODE (src));
27302 : 4 : ASSERT_EQ (UNSPEC_MEMORY_BLOCKAGE, XINT (src, 1));
27303 : :
27304 : 4 : rtx v0 = XVECEXP (src, 0, 0);
27305 : :
27306 : : /* Verify that the two uses of the first SCRATCH have pointer
27307 : : equality. */
27308 : 4 : rtx scratch_a = XEXP (dst, 0);
27309 : 4 : ASSERT_EQ (SCRATCH, GET_CODE (scratch_a));
27310 : :
27311 : 4 : rtx scratch_b = XEXP (v0, 0);
27312 : 4 : ASSERT_EQ (SCRATCH, GET_CODE (scratch_b));
27313 : :
27314 : 4 : ASSERT_EQ (scratch_a, scratch_b);
27315 : :
27316 : : /* Verify that the two mems are thus treated as equal. */
27317 : 4 : ASSERT_TRUE (rtx_equal_p (dst, v0));
27318 : :
27319 : : /* Verify that the insn is recognized. */
27320 : 4 : ASSERT_NE(-1, recog_memoized (insn));
27321 : :
27322 : : /* Test of an UNSPEC_VOLATILE, which has its own enum values. */
27323 : 4 : insn = NEXT_INSN (insn);
27324 : 4 : ASSERT_EQ (INSN, GET_CODE (insn));
27325 : :
27326 : 4 : set = single_set (insn);
27327 : 4 : ASSERT_NE (NULL, set);
27328 : :
27329 : 4 : src = SET_SRC (set);
27330 : 4 : ASSERT_EQ (UNSPEC_VOLATILE, GET_CODE (src));
27331 : 4 : ASSERT_EQ (UNSPECV_RDTSCP, XINT (src, 1));
27332 : 4 : }
27333 : :
27334 : : /* Run all target-specific selftests. */
27335 : :
27336 : : static void
27337 : 4 : ix86_run_selftests (void)
27338 : : {
27339 : 4 : ix86_test_dumping_hard_regs ();
27340 : 4 : ix86_test_dumping_memory_blockage ();
27341 : :
27342 : : /* Various tests of loading RTL dumps, here because they contain
27343 : : ix86-isms (e.g. names of hard regs). */
27344 : 4 : ix86_test_loading_dump_fragment_1 ();
27345 : 4 : ix86_test_loading_call_insn ();
27346 : 4 : ix86_test_loading_full_dump ();
27347 : 4 : ix86_test_loading_unspec ();
27348 : 4 : }
27349 : :
27350 : : } // namespace selftest
27351 : :
27352 : : #endif /* CHECKING_P */
27353 : :
27354 : : static const scoped_attribute_specs *const ix86_attribute_table[] =
27355 : : {
27356 : : &ix86_gnu_attribute_table
27357 : : };
27358 : :
27359 : : /* Initialize the GCC target structure. */
27360 : : #undef TARGET_RETURN_IN_MEMORY
27361 : : #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
27362 : :
27363 : : #undef TARGET_LEGITIMIZE_ADDRESS
27364 : : #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
27365 : :
27366 : : #undef TARGET_ATTRIBUTE_TABLE
27367 : : #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
27368 : : #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
27369 : : #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
27370 : : #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27371 : : # undef TARGET_MERGE_DECL_ATTRIBUTES
27372 : : # define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
27373 : : #endif
27374 : :
27375 : : #undef TARGET_INVALID_CONVERSION
27376 : : #define TARGET_INVALID_CONVERSION ix86_invalid_conversion
27377 : :
27378 : : #undef TARGET_INVALID_UNARY_OP
27379 : : #define TARGET_INVALID_UNARY_OP ix86_invalid_unary_op
27380 : :
27381 : : #undef TARGET_INVALID_BINARY_OP
27382 : : #define TARGET_INVALID_BINARY_OP ix86_invalid_binary_op
27383 : :
27384 : : #undef TARGET_COMP_TYPE_ATTRIBUTES
27385 : : #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
27386 : :
27387 : : #undef TARGET_INIT_BUILTINS
27388 : : #define TARGET_INIT_BUILTINS ix86_init_builtins
27389 : : #undef TARGET_BUILTIN_DECL
27390 : : #define TARGET_BUILTIN_DECL ix86_builtin_decl
27391 : : #undef TARGET_EXPAND_BUILTIN
27392 : : #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
27393 : :
27394 : : #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
27395 : : #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
27396 : : ix86_builtin_vectorized_function
27397 : :
27398 : : #undef TARGET_VECTORIZE_BUILTIN_GATHER
27399 : : #define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather
27400 : :
27401 : : #undef TARGET_VECTORIZE_BUILTIN_SCATTER
27402 : : #define TARGET_VECTORIZE_BUILTIN_SCATTER ix86_vectorize_builtin_scatter
27403 : :
27404 : : #undef TARGET_BUILTIN_RECIPROCAL
27405 : : #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
27406 : :
27407 : : #undef TARGET_ASM_FUNCTION_EPILOGUE
27408 : : #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
27409 : :
27410 : : #undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
27411 : : #define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY \
27412 : : ix86_print_patchable_function_entry
27413 : :
27414 : : #undef TARGET_ENCODE_SECTION_INFO
27415 : : #ifndef SUBTARGET_ENCODE_SECTION_INFO
27416 : : #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
27417 : : #else
27418 : : #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
27419 : : #endif
27420 : :
27421 : : #undef TARGET_ASM_OPEN_PAREN
27422 : : #define TARGET_ASM_OPEN_PAREN ""
27423 : : #undef TARGET_ASM_CLOSE_PAREN
27424 : : #define TARGET_ASM_CLOSE_PAREN ""
27425 : :
27426 : : #undef TARGET_ASM_BYTE_OP
27427 : : #define TARGET_ASM_BYTE_OP ASM_BYTE
27428 : :
27429 : : #undef TARGET_ASM_ALIGNED_HI_OP
27430 : : #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
27431 : : #undef TARGET_ASM_ALIGNED_SI_OP
27432 : : #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
27433 : : #ifdef ASM_QUAD
27434 : : #undef TARGET_ASM_ALIGNED_DI_OP
27435 : : #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
27436 : : #endif
27437 : :
27438 : : #undef TARGET_PROFILE_BEFORE_PROLOGUE
27439 : : #define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
27440 : :
27441 : : #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
27442 : : #define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name
27443 : :
27444 : : #undef TARGET_ASM_UNALIGNED_HI_OP
27445 : : #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
27446 : : #undef TARGET_ASM_UNALIGNED_SI_OP
27447 : : #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
27448 : : #undef TARGET_ASM_UNALIGNED_DI_OP
27449 : : #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
27450 : :
27451 : : #undef TARGET_PRINT_OPERAND
27452 : : #define TARGET_PRINT_OPERAND ix86_print_operand
27453 : : #undef TARGET_PRINT_OPERAND_ADDRESS
27454 : : #define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address
27455 : : #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
27456 : : #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p
27457 : : #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
27458 : : #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra
27459 : :
27460 : : #undef TARGET_SCHED_INIT_GLOBAL
27461 : : #define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global
27462 : : #undef TARGET_SCHED_ADJUST_COST
27463 : : #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
27464 : : #undef TARGET_SCHED_ISSUE_RATE
27465 : : #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
27466 : : #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
27467 : : #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
27468 : : ia32_multipass_dfa_lookahead
27469 : : #undef TARGET_SCHED_MACRO_FUSION_P
27470 : : #define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p
27471 : : #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
27472 : : #define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p
27473 : :
27474 : : #undef TARGET_FUNCTION_OK_FOR_SIBCALL
27475 : : #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
27476 : :
27477 : : #undef TARGET_MEMMODEL_CHECK
27478 : : #define TARGET_MEMMODEL_CHECK ix86_memmodel_check
27479 : :
27480 : : #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
27481 : : #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv
27482 : :
27483 : : #ifdef HAVE_AS_TLS
27484 : : #undef TARGET_HAVE_TLS
27485 : : #define TARGET_HAVE_TLS true
27486 : : #endif
27487 : : #undef TARGET_CANNOT_FORCE_CONST_MEM
27488 : : #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
27489 : : #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
27490 : : #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
27491 : :
27492 : : #undef TARGET_DELEGITIMIZE_ADDRESS
27493 : : #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
27494 : :
27495 : : #undef TARGET_CONST_NOT_OK_FOR_DEBUG_P
27496 : : #define TARGET_CONST_NOT_OK_FOR_DEBUG_P ix86_const_not_ok_for_debug_p
27497 : :
27498 : : #undef TARGET_MS_BITFIELD_LAYOUT_P
27499 : : #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
27500 : :
27501 : : #if TARGET_MACHO
27502 : : #undef TARGET_BINDS_LOCAL_P
27503 : : #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
27504 : : #else
27505 : : #undef TARGET_BINDS_LOCAL_P
27506 : : #define TARGET_BINDS_LOCAL_P ix86_binds_local_p
27507 : : #endif
27508 : : #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27509 : : #undef TARGET_BINDS_LOCAL_P
27510 : : #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
27511 : : #endif
27512 : :
27513 : : #undef TARGET_ASM_OUTPUT_MI_THUNK
27514 : : #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
27515 : : #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
27516 : : #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
27517 : :
27518 : : #undef TARGET_ASM_FILE_START
27519 : : #define TARGET_ASM_FILE_START x86_file_start
27520 : :
27521 : : #undef TARGET_OPTION_OVERRIDE
27522 : : #define TARGET_OPTION_OVERRIDE ix86_option_override
27523 : :
27524 : : #undef TARGET_REGISTER_MOVE_COST
27525 : : #define TARGET_REGISTER_MOVE_COST ix86_register_move_cost
27526 : : #undef TARGET_MEMORY_MOVE_COST
27527 : : #define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost
27528 : : #undef TARGET_RTX_COSTS
27529 : : #define TARGET_RTX_COSTS ix86_rtx_costs
27530 : : #undef TARGET_INSN_COST
27531 : : #define TARGET_INSN_COST ix86_insn_cost
27532 : : #undef TARGET_ADDRESS_COST
27533 : : #define TARGET_ADDRESS_COST ix86_address_cost
27534 : :
27535 : : #undef TARGET_OVERLAP_OP_BY_PIECES_P
27536 : : #define TARGET_OVERLAP_OP_BY_PIECES_P hook_bool_void_true
27537 : :
27538 : : #undef TARGET_FLAGS_REGNUM
27539 : : #define TARGET_FLAGS_REGNUM FLAGS_REG
27540 : : #undef TARGET_FIXED_CONDITION_CODE_REGS
27541 : : #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
27542 : : #undef TARGET_CC_MODES_COMPATIBLE
27543 : : #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
27544 : :
27545 : : #undef TARGET_MACHINE_DEPENDENT_REORG
27546 : : #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
27547 : :
27548 : : #undef TARGET_BUILD_BUILTIN_VA_LIST
27549 : : #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
27550 : :
27551 : : #undef TARGET_FOLD_BUILTIN
27552 : : #define TARGET_FOLD_BUILTIN ix86_fold_builtin
27553 : :
27554 : : #undef TARGET_GIMPLE_FOLD_BUILTIN
27555 : : #define TARGET_GIMPLE_FOLD_BUILTIN ix86_gimple_fold_builtin
27556 : :
27557 : : #undef TARGET_COMPARE_VERSION_PRIORITY
27558 : : #define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority
27559 : :
27560 : : #undef TARGET_GENERATE_VERSION_DISPATCHER_BODY
27561 : : #define TARGET_GENERATE_VERSION_DISPATCHER_BODY \
27562 : : ix86_generate_version_dispatcher_body
27563 : :
27564 : : #undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
27565 : : #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
27566 : : ix86_get_function_versions_dispatcher
27567 : :
27568 : : #undef TARGET_ENUM_VA_LIST_P
27569 : : #define TARGET_ENUM_VA_LIST_P ix86_enum_va_list
27570 : :
27571 : : #undef TARGET_FN_ABI_VA_LIST
27572 : : #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
27573 : :
27574 : : #undef TARGET_CANONICAL_VA_LIST_TYPE
27575 : : #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
27576 : :
27577 : : #undef TARGET_EXPAND_BUILTIN_VA_START
27578 : : #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
27579 : :
27580 : : #undef TARGET_MD_ASM_ADJUST
27581 : : #define TARGET_MD_ASM_ADJUST ix86_md_asm_adjust
27582 : :
27583 : : #undef TARGET_C_EXCESS_PRECISION
27584 : : #define TARGET_C_EXCESS_PRECISION ix86_get_excess_precision
27585 : : #undef TARGET_C_BITINT_TYPE_INFO
27586 : : #define TARGET_C_BITINT_TYPE_INFO ix86_bitint_type_info
27587 : : #undef TARGET_C_MODE_FOR_FLOATING_TYPE
27588 : : #define TARGET_C_MODE_FOR_FLOATING_TYPE ix86_c_mode_for_floating_type
27589 : : #undef TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE
27590 : : #define TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE ix86_cxx_adjust_cdtor_callabi_fntype
27591 : : #undef TARGET_PROMOTE_PROTOTYPES
27592 : : #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
27593 : : #undef TARGET_PUSH_ARGUMENT
27594 : : #define TARGET_PUSH_ARGUMENT ix86_push_argument
27595 : : #undef TARGET_SETUP_INCOMING_VARARGS
27596 : : #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
27597 : : #undef TARGET_MUST_PASS_IN_STACK
27598 : : #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
27599 : : #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
27600 : : #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS ix86_allocate_stack_slots_for_args
27601 : : #undef TARGET_FUNCTION_ARG_ADVANCE
27602 : : #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance
27603 : : #undef TARGET_FUNCTION_ARG
27604 : : #define TARGET_FUNCTION_ARG ix86_function_arg
27605 : : #undef TARGET_INIT_PIC_REG
27606 : : #define TARGET_INIT_PIC_REG ix86_init_pic_reg
27607 : : #undef TARGET_USE_PSEUDO_PIC_REG
27608 : : #define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg
27609 : : #undef TARGET_FUNCTION_ARG_BOUNDARY
27610 : : #define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary
27611 : : #undef TARGET_PASS_BY_REFERENCE
27612 : : #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
27613 : : #undef TARGET_INTERNAL_ARG_POINTER
27614 : : #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
27615 : : #undef TARGET_UPDATE_STACK_BOUNDARY
27616 : : #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
27617 : : #undef TARGET_GET_DRAP_RTX
27618 : : #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
27619 : : #undef TARGET_STRICT_ARGUMENT_NAMING
27620 : : #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
27621 : : #undef TARGET_STATIC_CHAIN
27622 : : #define TARGET_STATIC_CHAIN ix86_static_chain
27623 : : #undef TARGET_TRAMPOLINE_INIT
27624 : : #define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
27625 : : #undef TARGET_RETURN_POPS_ARGS
27626 : : #define TARGET_RETURN_POPS_ARGS ix86_return_pops_args
27627 : :
27628 : : #undef TARGET_WARN_FUNC_RETURN
27629 : : #define TARGET_WARN_FUNC_RETURN ix86_warn_func_return
27630 : :
27631 : : #undef TARGET_LEGITIMATE_COMBINED_INSN
27632 : : #define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn
27633 : :
27634 : : #undef TARGET_ASAN_SHADOW_OFFSET
27635 : : #define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset
27636 : :
27637 : : #undef TARGET_GIMPLIFY_VA_ARG_EXPR
27638 : : #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
27639 : :
27640 : : #undef TARGET_SCALAR_MODE_SUPPORTED_P
27641 : : #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
27642 : :
27643 : : #undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
27644 : : #define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \
27645 : : ix86_libgcc_floating_mode_supported_p
27646 : :
27647 : : #undef TARGET_VECTOR_MODE_SUPPORTED_P
27648 : : #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
27649 : :
27650 : : #undef TARGET_C_MODE_FOR_SUFFIX
27651 : : #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
27652 : :
27653 : : #ifdef HAVE_AS_TLS
27654 : : #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
27655 : : #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
27656 : : #endif
27657 : :
27658 : : #ifdef SUBTARGET_INSERT_ATTRIBUTES
27659 : : #undef TARGET_INSERT_ATTRIBUTES
27660 : : #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
27661 : : #endif
27662 : :
27663 : : #undef TARGET_MANGLE_TYPE
27664 : : #define TARGET_MANGLE_TYPE ix86_mangle_type
27665 : :
27666 : : #undef TARGET_EMIT_SUPPORT_TINFOS
27667 : : #define TARGET_EMIT_SUPPORT_TINFOS ix86_emit_support_tinfos
27668 : :
27669 : : #undef TARGET_STACK_PROTECT_GUARD
27670 : : #define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
27671 : :
27672 : : #undef TARGET_STACK_PROTECT_RUNTIME_ENABLED_P
27673 : : #define TARGET_STACK_PROTECT_RUNTIME_ENABLED_P \
27674 : : ix86_stack_protect_runtime_enabled_p
27675 : :
27676 : : #if !TARGET_MACHO
27677 : : #undef TARGET_STACK_PROTECT_FAIL
27678 : : #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
27679 : : #endif
27680 : :
27681 : : #undef TARGET_FUNCTION_VALUE
27682 : : #define TARGET_FUNCTION_VALUE ix86_function_value
27683 : :
27684 : : #undef TARGET_FUNCTION_VALUE_REGNO_P
27685 : : #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
27686 : :
27687 : : #undef TARGET_ZERO_CALL_USED_REGS
27688 : : #define TARGET_ZERO_CALL_USED_REGS ix86_zero_call_used_regs
27689 : :
27690 : : #undef TARGET_PROMOTE_FUNCTION_MODE
27691 : : #define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
27692 : :
27693 : : #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
27694 : : #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE ix86_override_options_after_change
27695 : :
27696 : : #undef TARGET_MEMBER_TYPE_FORCES_BLK
27697 : : #define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk
27698 : :
27699 : : #undef TARGET_INSTANTIATE_DECLS
27700 : : #define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls
27701 : :
27702 : : #undef TARGET_SECONDARY_RELOAD
27703 : : #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
27704 : : #undef TARGET_SECONDARY_MEMORY_NEEDED
27705 : : #define TARGET_SECONDARY_MEMORY_NEEDED ix86_secondary_memory_needed
27706 : : #undef TARGET_SECONDARY_MEMORY_NEEDED_MODE
27707 : : #define TARGET_SECONDARY_MEMORY_NEEDED_MODE ix86_secondary_memory_needed_mode
27708 : :
27709 : : #undef TARGET_CLASS_MAX_NREGS
27710 : : #define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs
27711 : :
27712 : : #undef TARGET_PREFERRED_RELOAD_CLASS
27713 : : #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
27714 : : #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
27715 : : #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
27716 : : /* When this hook returns true for MODE, the compiler allows
27717 : : registers explicitly used in the rtl to be used as spill registers
27718 : : but prevents the compiler from extending the lifetime of these
27719 : : registers. */
27720 : : #undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P
27721 : : #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true
27722 : : #undef TARGET_CLASS_LIKELY_SPILLED_P
27723 : : #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
27724 : : #undef TARGET_CALLEE_SAVE_COST
27725 : : #define TARGET_CALLEE_SAVE_COST ix86_callee_save_cost
27726 : :
27727 : : #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
27728 : : #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
27729 : : ix86_builtin_vectorization_cost
27730 : : #undef TARGET_VECTORIZE_VEC_PERM_CONST
27731 : : #define TARGET_VECTORIZE_VEC_PERM_CONST ix86_vectorize_vec_perm_const
27732 : : #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
27733 : : #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
27734 : : ix86_preferred_simd_mode
27735 : : #undef TARGET_VECTORIZE_SPLIT_REDUCTION
27736 : : #define TARGET_VECTORIZE_SPLIT_REDUCTION \
27737 : : ix86_split_reduction
27738 : : #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES
27739 : : #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES \
27740 : : ix86_autovectorize_vector_modes
27741 : : #undef TARGET_VECTORIZE_GET_MASK_MODE
27742 : : #define TARGET_VECTORIZE_GET_MASK_MODE ix86_get_mask_mode
27743 : : #undef TARGET_VECTORIZE_CREATE_COSTS
27744 : : #define TARGET_VECTORIZE_CREATE_COSTS ix86_vectorize_create_costs
27745 : :
27746 : : #undef TARGET_SET_CURRENT_FUNCTION
27747 : : #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
27748 : :
27749 : : #undef TARGET_OPTION_VALID_ATTRIBUTE_P
27750 : : #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
27751 : :
27752 : : #undef TARGET_OPTION_SAVE
27753 : : #define TARGET_OPTION_SAVE ix86_function_specific_save
27754 : :
27755 : : #undef TARGET_OPTION_RESTORE
27756 : : #define TARGET_OPTION_RESTORE ix86_function_specific_restore
27757 : :
27758 : : #undef TARGET_OPTION_POST_STREAM_IN
27759 : : #define TARGET_OPTION_POST_STREAM_IN ix86_function_specific_post_stream_in
27760 : :
27761 : : #undef TARGET_OPTION_PRINT
27762 : : #define TARGET_OPTION_PRINT ix86_function_specific_print
27763 : :
27764 : : #undef TARGET_OPTION_FUNCTION_VERSIONS
27765 : : #define TARGET_OPTION_FUNCTION_VERSIONS common_function_versions
27766 : :
27767 : : #undef TARGET_CAN_INLINE_P
27768 : : #define TARGET_CAN_INLINE_P ix86_can_inline_p
27769 : :
27770 : : #undef TARGET_LEGITIMATE_ADDRESS_P
27771 : : #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
27772 : :
27773 : : #undef TARGET_REGISTER_PRIORITY
27774 : : #define TARGET_REGISTER_PRIORITY ix86_register_priority
27775 : :
27776 : : #undef TARGET_REGISTER_USAGE_LEVELING_P
27777 : : #define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true
27778 : :
27779 : : #undef TARGET_LEGITIMATE_CONSTANT_P
27780 : : #define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p
27781 : :
27782 : : #undef TARGET_COMPUTE_FRAME_LAYOUT
27783 : : #define TARGET_COMPUTE_FRAME_LAYOUT ix86_compute_frame_layout
27784 : :
27785 : : #undef TARGET_FRAME_POINTER_REQUIRED
27786 : : #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
27787 : :
27788 : : #undef TARGET_CAN_ELIMINATE
27789 : : #define TARGET_CAN_ELIMINATE ix86_can_eliminate
27790 : :
27791 : : #undef TARGET_EXTRA_LIVE_ON_ENTRY
27792 : : #define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry
27793 : :
27794 : : #undef TARGET_ASM_CODE_END
27795 : : #define TARGET_ASM_CODE_END ix86_code_end
27796 : :
27797 : : #undef TARGET_CONDITIONAL_REGISTER_USAGE
27798 : : #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
27799 : :
27800 : : #undef TARGET_CANONICALIZE_COMPARISON
27801 : : #define TARGET_CANONICALIZE_COMPARISON ix86_canonicalize_comparison
27802 : :
27803 : : #undef TARGET_LOOP_UNROLL_ADJUST
27804 : : #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust
27805 : :
27806 : : /* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657. */
27807 : : #undef TARGET_SPILL_CLASS
27808 : : #define TARGET_SPILL_CLASS ix86_spill_class
27809 : :
27810 : : #undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
27811 : : #define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
27812 : : ix86_simd_clone_compute_vecsize_and_simdlen
27813 : :
27814 : : #undef TARGET_SIMD_CLONE_ADJUST
27815 : : #define TARGET_SIMD_CLONE_ADJUST ix86_simd_clone_adjust
27816 : :
27817 : : #undef TARGET_SIMD_CLONE_USABLE
27818 : : #define TARGET_SIMD_CLONE_USABLE ix86_simd_clone_usable
27819 : :
27820 : : #undef TARGET_OMP_DEVICE_KIND_ARCH_ISA
27821 : : #define TARGET_OMP_DEVICE_KIND_ARCH_ISA ix86_omp_device_kind_arch_isa
27822 : :
27823 : : #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
27824 : : #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
27825 : : ix86_float_exceptions_rounding_supported_p
27826 : :
27827 : : #undef TARGET_MODE_EMIT
27828 : : #define TARGET_MODE_EMIT ix86_emit_mode_set
27829 : :
27830 : : #undef TARGET_MODE_NEEDED
27831 : : #define TARGET_MODE_NEEDED ix86_mode_needed
27832 : :
27833 : : #undef TARGET_MODE_AFTER
27834 : : #define TARGET_MODE_AFTER ix86_mode_after
27835 : :
27836 : : #undef TARGET_MODE_ENTRY
27837 : : #define TARGET_MODE_ENTRY ix86_mode_entry
27838 : :
27839 : : #undef TARGET_MODE_EXIT
27840 : : #define TARGET_MODE_EXIT ix86_mode_exit
27841 : :
27842 : : #undef TARGET_MODE_PRIORITY
27843 : : #define TARGET_MODE_PRIORITY ix86_mode_priority
27844 : :
27845 : : #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
27846 : : #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
27847 : :
27848 : : #undef TARGET_OFFLOAD_OPTIONS
27849 : : #define TARGET_OFFLOAD_OPTIONS \
27850 : : ix86_offload_options
27851 : :
27852 : : #undef TARGET_ABSOLUTE_BIGGEST_ALIGNMENT
27853 : : #define TARGET_ABSOLUTE_BIGGEST_ALIGNMENT 512
27854 : :
27855 : : #undef TARGET_OPTAB_SUPPORTED_P
27856 : : #define TARGET_OPTAB_SUPPORTED_P ix86_optab_supported_p
27857 : :
27858 : : #undef TARGET_HARD_REGNO_SCRATCH_OK
27859 : : #define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok
27860 : :
27861 : : #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
27862 : : #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS X86_CUSTOM_FUNCTION_TEST
27863 : :
27864 : : #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
27865 : : #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid
27866 : :
27867 : : #undef TARGET_INIT_LIBFUNCS
27868 : : #define TARGET_INIT_LIBFUNCS ix86_init_libfuncs
27869 : :
27870 : : #undef TARGET_EXPAND_DIVMOD_LIBFUNC
27871 : : #define TARGET_EXPAND_DIVMOD_LIBFUNC ix86_expand_divmod_libfunc
27872 : :
27873 : : #undef TARGET_MAX_NOCE_IFCVT_SEQ_COST
27874 : : #define TARGET_MAX_NOCE_IFCVT_SEQ_COST ix86_max_noce_ifcvt_seq_cost
27875 : :
27876 : : #undef TARGET_NOCE_CONVERSION_PROFITABLE_P
27877 : : #define TARGET_NOCE_CONVERSION_PROFITABLE_P ix86_noce_conversion_profitable_p
27878 : :
27879 : : #undef TARGET_HARD_REGNO_NREGS
27880 : : #define TARGET_HARD_REGNO_NREGS ix86_hard_regno_nregs
27881 : : #undef TARGET_HARD_REGNO_MODE_OK
27882 : : #define TARGET_HARD_REGNO_MODE_OK ix86_hard_regno_mode_ok
27883 : :
27884 : : #undef TARGET_MODES_TIEABLE_P
27885 : : #define TARGET_MODES_TIEABLE_P ix86_modes_tieable_p
27886 : :
27887 : : #undef TARGET_HARD_REGNO_CALL_PART_CLOBBERED
27888 : : #define TARGET_HARD_REGNO_CALL_PART_CLOBBERED \
27889 : : ix86_hard_regno_call_part_clobbered
27890 : :
27891 : : #undef TARGET_INSN_CALLEE_ABI
27892 : : #define TARGET_INSN_CALLEE_ABI ix86_insn_callee_abi
27893 : :
27894 : : #undef TARGET_CAN_CHANGE_MODE_CLASS
27895 : : #define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class
27896 : :
27897 : : #undef TARGET_LOWER_LOCAL_DECL_ALIGNMENT
27898 : : #define TARGET_LOWER_LOCAL_DECL_ALIGNMENT ix86_lower_local_decl_alignment
27899 : :
27900 : : #undef TARGET_STATIC_RTX_ALIGNMENT
27901 : : #define TARGET_STATIC_RTX_ALIGNMENT ix86_static_rtx_alignment
27902 : : #undef TARGET_CONSTANT_ALIGNMENT
27903 : : #define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment
27904 : :
27905 : : #undef TARGET_EMPTY_RECORD_P
27906 : : #define TARGET_EMPTY_RECORD_P ix86_is_empty_record
27907 : :
27908 : : #undef TARGET_WARN_PARAMETER_PASSING_ABI
27909 : : #define TARGET_WARN_PARAMETER_PASSING_ABI ix86_warn_parameter_passing_abi
27910 : :
27911 : : #undef TARGET_GET_MULTILIB_ABI_NAME
27912 : : #define TARGET_GET_MULTILIB_ABI_NAME \
27913 : : ix86_get_multilib_abi_name
27914 : :
27915 : : #undef TARGET_IFUNC_REF_LOCAL_OK
27916 : : #define TARGET_IFUNC_REF_LOCAL_OK ix86_ifunc_ref_local_ok
27917 : :
27918 : : #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
27919 : : # undef TARGET_ASM_RELOC_RW_MASK
27920 : : # define TARGET_ASM_RELOC_RW_MASK ix86_reloc_rw_mask
27921 : : #endif
27922 : :
27923 : : #undef TARGET_MEMTAG_CAN_TAG_ADDRESSES
27924 : : #define TARGET_MEMTAG_CAN_TAG_ADDRESSES ix86_memtag_can_tag_addresses
27925 : :
27926 : : #undef TARGET_MEMTAG_ADD_TAG
27927 : : #define TARGET_MEMTAG_ADD_TAG ix86_memtag_add_tag
27928 : :
27929 : : #undef TARGET_MEMTAG_SET_TAG
27930 : : #define TARGET_MEMTAG_SET_TAG ix86_memtag_set_tag
27931 : :
27932 : : #undef TARGET_MEMTAG_EXTRACT_TAG
27933 : : #define TARGET_MEMTAG_EXTRACT_TAG ix86_memtag_extract_tag
27934 : :
27935 : : #undef TARGET_MEMTAG_UNTAGGED_POINTER
27936 : : #define TARGET_MEMTAG_UNTAGGED_POINTER ix86_memtag_untagged_pointer
27937 : :
27938 : : #undef TARGET_MEMTAG_TAG_SIZE
27939 : : #define TARGET_MEMTAG_TAG_SIZE ix86_memtag_tag_size
27940 : :
27941 : : #undef TARGET_GEN_CCMP_FIRST
27942 : : #define TARGET_GEN_CCMP_FIRST ix86_gen_ccmp_first
27943 : :
27944 : : #undef TARGET_GEN_CCMP_NEXT
27945 : : #define TARGET_GEN_CCMP_NEXT ix86_gen_ccmp_next
27946 : :
27947 : : #undef TARGET_HAVE_CCMP
27948 : : #define TARGET_HAVE_CCMP ix86_have_ccmp
27949 : :
27950 : : #undef TARGET_MODE_CAN_TRANSFER_BITS
27951 : : #define TARGET_MODE_CAN_TRANSFER_BITS ix86_mode_can_transfer_bits
27952 : :
27953 : : #undef TARGET_REDZONE_CLOBBER
27954 : : #define TARGET_REDZONE_CLOBBER ix86_redzone_clobber
27955 : :
27956 : : static bool
27957 : 77706 : ix86_libc_has_fast_function (int fcode ATTRIBUTE_UNUSED)
27958 : : {
27959 : : #ifdef OPTION_GLIBC
27960 : 77706 : if (OPTION_GLIBC)
27961 : 77706 : return (built_in_function)fcode == BUILT_IN_MEMPCPY;
27962 : : else
27963 : : return false;
27964 : : #else
27965 : : return false;
27966 : : #endif
27967 : : }
27968 : :
27969 : : #undef TARGET_LIBC_HAS_FAST_FUNCTION
27970 : : #define TARGET_LIBC_HAS_FAST_FUNCTION ix86_libc_has_fast_function
27971 : :
27972 : : static unsigned
27973 : 70517 : ix86_libm_function_max_error (unsigned cfn, machine_mode mode,
27974 : : bool boundary_p)
27975 : : {
27976 : : #ifdef OPTION_GLIBC
27977 : 70517 : bool glibc_p = OPTION_GLIBC;
27978 : : #else
27979 : : bool glibc_p = false;
27980 : : #endif
27981 : 70517 : if (glibc_p)
27982 : : {
27983 : : /* If __FAST_MATH__ is defined, glibc provides libmvec. */
27984 : 70517 : unsigned int libmvec_ret = 0;
27985 : 70517 : if (!flag_trapping_math
27986 : 7963 : && flag_unsafe_math_optimizations
27987 : 3330 : && flag_finite_math_only
27988 : 3304 : && !flag_signed_zeros
27989 : 3304 : && !flag_errno_math)
27990 : 3304 : switch (cfn)
27991 : : {
27992 : 1388 : CASE_CFN_COS:
27993 : 1388 : CASE_CFN_COS_FN:
27994 : 1388 : CASE_CFN_SIN:
27995 : 1388 : CASE_CFN_SIN_FN:
27996 : 1388 : if (!boundary_p)
27997 : : {
27998 : : /* With non-default rounding modes, libmvec provides
27999 : : complete garbage in results. E.g.
28000 : : _ZGVcN8v_sinf for 1.40129846e-45f in FE_UPWARD
28001 : : returns 0.00333309174f rather than 1.40129846e-45f. */
28002 : 583 : if (flag_rounding_math)
28003 : : return ~0U;
28004 : : /* https://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html
28005 : : claims libmvec maximum error is 4ulps.
28006 : : My own random testing indicates 2ulps for SFmode and
28007 : : 0.5ulps for DFmode, but let's go with the 4ulps. */
28008 : : libmvec_ret = 4;
28009 : : }
28010 : : break;
28011 : : default:
28012 : : break;
28013 : : }
28014 : 70517 : unsigned int ret = glibc_linux_libm_function_max_error (cfn, mode,
28015 : : boundary_p);
28016 : 70517 : return MAX (ret, libmvec_ret);
28017 : : }
28018 : 0 : return default_libm_function_max_error (cfn, mode, boundary_p);
28019 : : }
28020 : :
28021 : : #undef TARGET_LIBM_FUNCTION_MAX_ERROR
28022 : : #define TARGET_LIBM_FUNCTION_MAX_ERROR ix86_libm_function_max_error
28023 : :
28024 : : #if TARGET_MACHO
28025 : : static bool
28026 : : ix86_cannot_copy_insn_p (rtx_insn *insn)
28027 : : {
28028 : : if (TARGET_64BIT)
28029 : : return false;
28030 : :
28031 : : rtx set = single_set (insn);
28032 : : if (set)
28033 : : {
28034 : : rtx src = SET_SRC (set);
28035 : : if (GET_CODE (src) == UNSPEC
28036 : : && XINT (src, 1) == UNSPEC_SET_GOT)
28037 : : return true;
28038 : : }
28039 : : return false;
28040 : : }
28041 : :
28042 : : #undef TARGET_CANNOT_COPY_INSN_P
28043 : : #define TARGET_CANNOT_COPY_INSN_P ix86_cannot_copy_insn_p
28044 : :
28045 : : #endif
28046 : :
28047 : : #if CHECKING_P
28048 : : #undef TARGET_RUN_TARGET_SELFTESTS
28049 : : #define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
28050 : : #endif /* #if CHECKING_P */
28051 : :
28052 : : #undef TARGET_DOCUMENTATION_NAME
28053 : : #define TARGET_DOCUMENTATION_NAME "x86"
28054 : :
28055 : : struct gcc_target targetm = TARGET_INITIALIZER;
28056 : :
28057 : : #include "gt-i386.h"
|